diff --git a/hawkbit-rest/hawkbit-ddi-api/src/test/java/org/eclipse/hawkbit/ddi/json/model/DdiConfirmationBaseTest.java b/hawkbit-rest/hawkbit-ddi-api/src/test/java/org/eclipse/hawkbit/ddi/json/model/DdiConfirmationBaseTest.java index b76fe810b..1ce740a88 100644 --- a/hawkbit-rest/hawkbit-ddi-api/src/test/java/org/eclipse/hawkbit/ddi/json/model/DdiConfirmationBaseTest.java +++ b/hawkbit-rest/hawkbit-ddi-api/src/test/java/org/eclipse/hawkbit/ddi/json/model/DdiConfirmationBaseTest.java @@ -34,7 +34,7 @@ import org.junit.jupiter.api.Test; @Story("CHeck JSON serialization of DDI api confirmation models") class DdiConfirmationBaseTest { - private final ObjectMapper mapper = new ObjectMapper(); + private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper(); @Test @Description("Verify the correct serialization and deserialization of the model") @@ -49,8 +49,8 @@ class DdiConfirmationBaseTest { ddiActionHistory); // Test - String serializedDdiConfirmationBase = mapper.writeValueAsString(ddiConfirmationBaseAction); - final DdiConfirmationBaseAction deserializedDdiConfigurationBase = mapper + String serializedDdiConfirmationBase = OBJECT_MAPPER.writeValueAsString(ddiConfirmationBaseAction); + final DdiConfirmationBaseAction deserializedDdiConfigurationBase = OBJECT_MAPPER .readValue(serializedDdiConfirmationBase, DdiConfirmationBaseAction.class); assertThat(serializedDdiConfirmationBase).contains(id, FORCED.getName(), ATTEMPT.getName(), @@ -68,13 +68,15 @@ class DdiConfirmationBaseTest { @Description("Verify the correct deserialization of a model with a additional unknown property") void shouldDeserializeObjectWithUnknownProperty() throws IOException { // Setup - String serializedDdiConfirmationBase = "{\"id\":\"1234\",\"confirmation\":{\"download\":\"forced\"," - + "\"update\":\"attempt\",\"maintenanceWindow\":\"available\",\"chunks\":[]}," - + "\"actionHistory\":{\"status\":\"TestAction\",\"messages\":[\"Action status message 1\"," - + "\"Action status message 2\"]},\"links\":[],\"unknownProperty\":\"test\"}"; + final String serializedDdiConfirmationBase = "{" + + "\"id\":\"1234\",\"confirmation\":{\"download\":\"forced\"," + + "\"update\":\"attempt\",\"maintenanceWindow\":\"available\",\"chunks\":[]}," + + "\"actionHistory\":{\"status\":\"TestAction\",\"messages\":[\"Action status message 1\"," + + "\"Action status message 2\"]},\"links\":[],\"unknownProperty\":\"test\"" + + "}"; // Test - DdiConfirmationBaseAction ddiConfirmationBaseAction = mapper.readValue(serializedDdiConfirmationBase, + final DdiConfirmationBaseAction ddiConfirmationBaseAction = OBJECT_MAPPER.readValue(serializedDdiConfirmationBase, DdiConfirmationBaseAction.class); assertThat(ddiConfirmationBaseAction.getConfirmation().getDownload().getName()).isEqualTo(FORCED.getName()); @@ -87,13 +89,15 @@ class DdiConfirmationBaseTest { @Description("Verify that deserialization fails for known properties with a wrong datatype") void shouldFailForObjectWithWrongDataTypes() throws IOException { // Setup - String serializedDdiConfirmationBase = "{\"id\":[\"1234\"],\"confirmation\":{\"download\":\"forced\"," - + "\"update\":\"attempt\",\"maintenanceWindow\":\"available\",\"chunks\":[]}," - + "\"actionHistory\":{\"status\":\"TestAction\",\"messages\":[\"Action status message 1\"," - + "\"Action status message 2\"]},\"links\":[]}"; + final String serializedDdiConfirmationBase = "{" + + "\"id\":[\"1234\"],\"confirmation\":{\"download\":\"forced\"," + + "\"update\":\"attempt\",\"maintenanceWindow\":\"available\",\"chunks\":[]}," + + "\"actionHistory\":{\"status\":\"TestAction\",\"messages\":[\"Action status message 1\"," + + "\"Action status message 2\"]},\"links\":[]" + + "}"; // Test assertThatExceptionOfType(MismatchedInputException.class) - .isThrownBy(() -> mapper.readValue(serializedDdiConfirmationBase, DdiConfirmationBaseAction.class)); + .isThrownBy(() -> OBJECT_MAPPER.readValue(serializedDdiConfirmationBase, DdiConfirmationBaseAction.class)); } } \ No newline at end of file diff --git a/hawkbit-rest/hawkbit-ddi-resource/src/test/java/org/eclipse/hawkbit/ddi/rest/resource/DdiConfirmationBaseTest.java b/hawkbit-rest/hawkbit-ddi-resource/src/test/java/org/eclipse/hawkbit/ddi/rest/resource/DdiConfirmationBaseTest.java index bc410d438..17c377211 100644 --- a/hawkbit-rest/hawkbit-ddi-resource/src/test/java/org/eclipse/hawkbit/ddi/rest/resource/DdiConfirmationBaseTest.java +++ b/hawkbit-rest/hawkbit-ddi-resource/src/test/java/org/eclipse/hawkbit/ddi/rest/resource/DdiConfirmationBaseTest.java @@ -69,14 +69,13 @@ import org.springframework.test.web.servlet.ResultActions; */ @Feature("Component Tests - Direct Device Integration API") @Story("Confirmation Action Resource") -public class DdiConfirmationBaseTest extends AbstractDDiApiIntegrationTest { +class DdiConfirmationBaseTest extends AbstractDDiApiIntegrationTest { private static final String DEFAULT_CONTROLLER_ID = "4747"; @Test - @Description("Forced deployment to a controller. Checks if the confirmation resource response payload for a given" - + " deployment is as expected.") - public void verifyConfirmationReferencesInControllerBase(@Autowired ActionStatusRepository actionStatusRepository) throws Exception { + @Description("Forced deployment to a controller. Checks if the confirmation resource response payload for a given deployment is as expected.") + void verifyConfirmationReferencesInControllerBase(@Autowired ActionStatusRepository actionStatusRepository) throws Exception { enableConfirmationFlow(); // Prepare test data final DistributionSet ds = testdataFactory.createDistributionSet("", true); @@ -142,7 +141,7 @@ public class DdiConfirmationBaseTest extends AbstractDDiApiIntegrationTest { @Test @Description("Ensure that the deployment resource is available as CBOR") - public void confirmationResourceCbor() throws Exception { + void confirmationResourceCbor() throws Exception { enableConfirmationFlow(); final Target target = testdataFactory.createTarget(); final DistributionSet distributionSet = testdataFactory.createDistributionSet(""); @@ -156,19 +155,23 @@ public class DdiConfirmationBaseTest extends AbstractDDiApiIntegrationTest { .getContent().get(0); // get confirmation base - performGet(CONFIRMATION_BASE_ACTION, MediaType.parseMediaType(DdiRestConstants.MEDIA_TYPE_CBOR), - status().isOk(), tenantAware.getCurrentTenant(), target.getControllerId(), action.getId().toString()); + assertThat( + performGet( + CONFIRMATION_BASE_ACTION, MediaType.parseMediaType(DdiRestConstants.MEDIA_TYPE_CBOR), + status().isOk(), tenantAware.getCurrentTenant(), target.getControllerId(), action.getId().toString())) + .isNotNull(); // get artifacts - performGet(SOFTWARE_MODULE_ARTIFACTS, MediaType.parseMediaType(DdiRestConstants.MEDIA_TYPE_CBOR), - status().isOk(), tenantAware.getCurrentTenant(), target.getControllerId(), - String.valueOf(softwareModuleId)); - + assertThat( + performGet(SOFTWARE_MODULE_ARTIFACTS, MediaType.parseMediaType(DdiRestConstants.MEDIA_TYPE_CBOR), + status().isOk(), tenantAware.getCurrentTenant(), target.getControllerId(), + String.valueOf(softwareModuleId))) + .isNotNull(); } @Test @Description("Ensure that the confirmation endpoint is not available.") - public void confirmationEndpointNotExposed() throws Exception { + void confirmationEndpointNotExposed() throws Exception { final DistributionSet ds = testdataFactory.createDistributionSet(""); Target savedTarget = testdataFactory.createTarget("988"); savedTarget = getFirstAssignedTarget(assignDistributionSet(ds.getId(), savedTarget.getControllerId())); @@ -190,7 +193,7 @@ public class DdiConfirmationBaseTest extends AbstractDDiApiIntegrationTest { @Test @Description("Ensure that the deploymentBase endpoint is not available for action ins WFC state.") - public void deploymentEndpointNotAccessibleForActionsWFC() throws Exception { + void deploymentEndpointNotAccessibleForActionsWFC() throws Exception { enableConfirmationFlow(); final DistributionSet ds = testdataFactory.createDistributionSet(""); @@ -218,7 +221,7 @@ public class DdiConfirmationBaseTest extends AbstractDDiApiIntegrationTest { @Test @Description("Ensure that the confirmation endpoints are still available after deactivating the confirmation flow.") - public void verifyConfirmationBaseEndpointsArePresentAfterDisablingConfirmationFlow() throws Exception { + void verifyConfirmationBaseEndpointsArePresentAfterDisablingConfirmationFlow() throws Exception { enableConfirmationFlow(); final DistributionSet ds = testdataFactory.createDistributionSet("");