diff --git a/hawkbit-ddi/hawkbit-ddi-resource/src/test/java/org/eclipse/hawkbit/ddi/rest/resource/DdiConfirmationBaseTest.java b/hawkbit-ddi/hawkbit-ddi-resource/src/test/java/org/eclipse/hawkbit/ddi/rest/resource/DdiConfirmationBaseTest.java index 76cf999a2..9e789df84 100644 --- a/hawkbit-ddi/hawkbit-ddi-resource/src/test/java/org/eclipse/hawkbit/ddi/rest/resource/DdiConfirmationBaseTest.java +++ b/hawkbit-ddi/hawkbit-ddi-resource/src/test/java/org/eclipse/hawkbit/ddi/rest/resource/DdiConfirmationBaseTest.java @@ -255,9 +255,11 @@ class DdiConfirmationBaseTest extends AbstractDDiApiIntegrationTest { @Expect(type = DistributionSetUpdatedEvent.class, count = 1), // implicit lock @Expect(type = SoftwareModuleUpdatedEvent.class, count = 3), // implicit lock @Expect(type = TargetAssignDistributionSetEvent.class, count = 1), - @Expect(type = ActionCreatedEvent.class, count = 1), @Expect(type = ActionUpdatedEvent.class, count = 2), + @Expect(type = ActionCreatedEvent.class, count = 1), + @Expect(type = ActionUpdatedEvent.class, count = 2), @Expect(type = TargetUpdatedEvent.class, count = 1), - @Expect(type = TargetUpdatedEvent.class, count = 1), @Expect(type = TargetPollEvent.class, count = 1), + @Expect(type = TargetUpdatedEvent.class, count = 1), + @Expect(type = TargetPollEvent.class, count = 1), @Expect(type = TenantConfigurationCreatedEvent.class, count = 1) }) void sendConfirmedActionStateFeedbackTest() throws Exception { enableConfirmationFlow(); @@ -419,7 +421,8 @@ class DdiConfirmationBaseTest extends AbstractDDiApiIntegrationTest { @Expect(type = DistributionSetUpdatedEvent.class, count = 1), // implicit lock @Expect(type = SoftwareModuleUpdatedEvent.class, count = 3), // implicit lock @Expect(type = TargetAssignDistributionSetEvent.class, count = 1), - @Expect(type = ActionCreatedEvent.class, count = 1), @Expect(type = ActionUpdatedEvent.class, count = 2), + @Expect(type = ActionCreatedEvent.class, count = 1), + @Expect(type = ActionUpdatedEvent.class, count = 2), @Expect(type = TargetUpdatedEvent.class, count = 1), @Expect(type = TenantConfigurationCreatedEvent.class, count = 1) }) void testActionHistoryCount() throws Exception { diff --git a/hawkbit-ddi/hawkbit-ddi-resource/src/test/java/org/eclipse/hawkbit/ddi/rest/resource/DdiRootControllerTest.java b/hawkbit-ddi/hawkbit-ddi-resource/src/test/java/org/eclipse/hawkbit/ddi/rest/resource/DdiRootControllerTest.java index 2b5aebdbd..da81bc76a 100644 --- a/hawkbit-ddi/hawkbit-ddi-resource/src/test/java/org/eclipse/hawkbit/ddi/rest/resource/DdiRootControllerTest.java +++ b/hawkbit-ddi/hawkbit-ddi-resource/src/test/java/org/eclipse/hawkbit/ddi/rest/resource/DdiRootControllerTest.java @@ -112,35 +112,6 @@ class DdiRootControllerTest extends AbstractDDiApiIntegrationTest { assertThat(result.getRequest().getHeader("Accept")).isNull(); } - @Test - @Description("Ensures that targets cannot be created e.g. in plug'n play scenarios when tenant does not exists but can be created if the tenant exists.") - @WithUser(tenantId = "tenantDoesNotExists", allSpPermissions = true, - authorities = { CONTROLLER_ROLE, SYSTEM_ROLE }, autoCreateTenant = false) - @ExpectEvents({ - @Expect(type = TargetCreatedEvent.class, count = 1), - @Expect(type = TargetPollEvent.class, count = 1), - @Expect(type = DistributionSetTypeCreatedEvent.class, count = 3), - @Expect(type = SoftwareModuleTypeCreatedEvent.class, count = 2) }) - void targetCannotBeRegisteredIfTenantDoesNotExistsButWhenExists() throws Exception { - mvc.perform(get("/default-tenant/", tenantAware.getCurrentTenant())) - .andDo(MockMvcResultPrinter.print()) - .andExpect(status().isNotFound()); - - // create tenant -- creates software module types and distribution set types - systemManagement.createTenantMetadata("tenantDoesNotExists"); - - mvc.perform(get(CONTROLLER_BASE, tenantAware.getCurrentTenant(), "aControllerId")) - .andDo(MockMvcResultPrinter.print()) - .andExpect(status().isOk()); - - // delete tenant again, will also deleted target aControllerId - systemManagement.deleteTenant("tenantDoesNotExists"); - - mvc.perform(get(CONTROLLER_BASE, tenantAware.getCurrentTenant(), "aControllerId")) - .andDo(MockMvcResultPrinter.print()) - .andExpect(status().isBadRequest()); - } - @Test @Description("Ensures that target poll request does not change audit data on the entity.") @WithUser(principal = "knownPrincipal", authorities = { SpPermission.READ_TARGET, SpPermission.UPDATE_TARGET, SpPermission.CREATE_TARGET }) @@ -175,7 +146,8 @@ class DdiRootControllerTest extends AbstractDDiApiIntegrationTest { @Test @Description("Ensures that server returns a not found response in case of empty controller ID.") - @ExpectEvents({ @Expect(type = TargetCreatedEvent.class, count = 0) }) + @ExpectEvents({ + @Expect(type = TargetCreatedEvent.class, count = 0) }) void rootRsWithoutId() throws Exception { mvc.perform(get("/controller/v1/")) .andDo(MockMvcResultPrinter.print()) @@ -341,8 +313,10 @@ class DdiRootControllerTest extends AbstractDDiApiIntegrationTest { @Test @Description("Ensures that the target state machine of a precomissioned target switches from " + "UNKNOWN to REGISTERED when the target polls for the first time.") - @ExpectEvents({ @Expect(type = TargetCreatedEvent.class, count = 1), - @Expect(type = TargetUpdatedEvent.class, count = 1), @Expect(type = TargetPollEvent.class, count = 1) }) + @ExpectEvents({ + @Expect(type = TargetCreatedEvent.class, count = 1), + @Expect(type = TargetUpdatedEvent.class, count = 1), + @Expect(type = TargetPollEvent.class, count = 1) }) void rootRsPreCommissioned() throws Exception { final String controllerId = "4711"; testdataFactory.createTarget(controllerId); @@ -572,7 +546,8 @@ class DdiRootControllerTest extends AbstractDDiApiIntegrationTest { @Expect(type = DistributionSetUpdatedEvent.class, count = 1), // implicit lock @Expect(type = SoftwareModuleUpdatedEvent.class, count = 3), // implicit lock @Expect(type = TargetAssignDistributionSetEvent.class, count = 1), - @Expect(type = ActionCreatedEvent.class, count = 1), @Expect(type = ActionUpdatedEvent.class, count = 2), + @Expect(type = ActionCreatedEvent.class, count = 1), + @Expect(type = ActionUpdatedEvent.class, count = 2), @Expect(type = TargetUpdatedEvent.class, count = 2), @Expect(type = TargetAttributesRequestedEvent.class, count = 1) }) void testActionHistoryNegativeInput() throws Exception { diff --git a/hawkbit-dmf/hawkbit-dmf-amqp/src/test/java/org/eclipse/hawkbit/amqp/AmqpMessageDispatcherServiceTest.java b/hawkbit-dmf/hawkbit-dmf-amqp/src/test/java/org/eclipse/hawkbit/amqp/AmqpMessageDispatcherServiceTest.java index 4a9822fa9..e1b72b87d 100644 --- a/hawkbit-dmf/hawkbit-dmf-amqp/src/test/java/org/eclipse/hawkbit/amqp/AmqpMessageDispatcherServiceTest.java +++ b/hawkbit-dmf/hawkbit-dmf-amqp/src/test/java/org/eclipse/hawkbit/amqp/AmqpMessageDispatcherServiceTest.java @@ -70,7 +70,7 @@ import org.springframework.test.context.ActiveProfiles; @SpringBootTest(classes = { RepositoryApplicationConfiguration.class }, webEnvironment = SpringBootTest.WebEnvironment.NONE) class AmqpMessageDispatcherServiceTest extends AbstractIntegrationTest { - private static final String TENANT = "default"; + private static final String TENANT = "DEFAULT"; private static final Long TENANT_ID = 4711L; private static final URI AMQP_URI = IpUtil.createAmqpUri("vHost", "mytest"); diff --git a/hawkbit-dmf/hawkbit-dmf-amqp/src/test/java/org/eclipse/hawkbit/amqp/BaseAmqpServiceTest.java b/hawkbit-dmf/hawkbit-dmf-amqp/src/test/java/org/eclipse/hawkbit/amqp/BaseAmqpServiceTest.java index 189ede489..3f08cfe3d 100644 --- a/hawkbit-dmf/hawkbit-dmf-amqp/src/test/java/org/eclipse/hawkbit/amqp/BaseAmqpServiceTest.java +++ b/hawkbit-dmf/hawkbit-dmf-amqp/src/test/java/org/eclipse/hawkbit/amqp/BaseAmqpServiceTest.java @@ -63,7 +63,8 @@ public class BaseAmqpServiceTest { @Test @Description("Tests invalid null message content") - @ExpectEvents({ @Expect(type = TargetCreatedEvent.class, count = 0) }) + @ExpectEvents({ + @Expect(type = TargetCreatedEvent.class, count = 0) }) public void convertMessageWithNullContent() { final Message message = createMessage("".getBytes()); assertThatExceptionOfType(MessageConversionException.class) @@ -73,7 +74,8 @@ public class BaseAmqpServiceTest { @Test @Description("Tests invalid empty message content") - @ExpectEvents({ @Expect(type = TargetCreatedEvent.class, count = 0) }) + @ExpectEvents({ + @Expect(type = TargetCreatedEvent.class, count = 0) }) public void updateActionStatusWithEmptyContent() { final Message message = createMessage("".getBytes()); assertThatExceptionOfType(MessageConversionException.class) @@ -83,7 +85,8 @@ public class BaseAmqpServiceTest { @Test @Description("Tests invalid json message content") - @ExpectEvents({ @Expect(type = TargetCreatedEvent.class, count = 0) }) + @ExpectEvents({ + @Expect(type = TargetCreatedEvent.class, count = 0) }) public void updateActionStatusWithInvalidJsonContent() { final Message message = createMessage("Invalid Json".getBytes()); when(rabbitTemplate.getMessageConverter()).thenReturn(new Jackson2JsonMessageConverter()); diff --git a/hawkbit-dmf/hawkbit-dmf-amqp/src/test/java/org/eclipse/hawkbit/integration/AmqpMessageDispatcherServiceIntegrationTest.java b/hawkbit-dmf/hawkbit-dmf-amqp/src/test/java/org/eclipse/hawkbit/integration/AmqpMessageDispatcherServiceIntegrationTest.java index 8686b49b0..ccc2fc5e8 100644 --- a/hawkbit-dmf/hawkbit-dmf-amqp/src/test/java/org/eclipse/hawkbit/integration/AmqpMessageDispatcherServiceIntegrationTest.java +++ b/hawkbit-dmf/hawkbit-dmf-amqp/src/test/java/org/eclipse/hawkbit/integration/AmqpMessageDispatcherServiceIntegrationTest.java @@ -91,14 +91,16 @@ public class AmqpMessageDispatcherServiceIntegrationTest extends AbstractAmqpSer @Test @Description("Verify that a distribution assignment send a download and install message.") - @ExpectEvents({ @Expect(type = TargetCreatedEvent.class, count = 1), + @ExpectEvents({ + @Expect(type = TargetCreatedEvent.class, count = 1), @Expect(type = TargetAssignDistributionSetEvent.class, count = 1), @Expect(type = ActionCreatedEvent.class, count = 1), @Expect(type = DistributionSetCreatedEvent.class, count = 1), @Expect(type = SoftwareModuleCreatedEvent.class, count = 3), @Expect(type = DistributionSetUpdatedEvent.class, count = 1), // implicit lock @Expect(type = SoftwareModuleUpdatedEvent.class, count = 9), // implicit lock - @Expect(type = TargetUpdatedEvent.class, count = 1), @Expect(type = TargetPollEvent.class, count = 1) }) + @Expect(type = TargetUpdatedEvent.class, count = 1), + @Expect(type = TargetPollEvent.class, count = 1) }) public void sendDownloadAndInstallStatus() { final String controllerId = TARGET_PREFIX + "sendDownloadAndInstallStatus"; registerTargetAndAssignDistributionSet(controllerId); @@ -109,14 +111,16 @@ public class AmqpMessageDispatcherServiceIntegrationTest extends AbstractAmqpSer @Test @Description("Verify that a distribution assignment sends a download message with window configured but before maintenance window start time.") - @ExpectEvents({ @Expect(type = TargetCreatedEvent.class, count = 1), + @ExpectEvents({ + @Expect(type = TargetCreatedEvent.class, count = 1), @Expect(type = TargetAssignDistributionSetEvent.class, count = 1), @Expect(type = ActionCreatedEvent.class, count = 1), @Expect(type = DistributionSetCreatedEvent.class, count = 1), @Expect(type = SoftwareModuleCreatedEvent.class, count = 3), @Expect(type = DistributionSetUpdatedEvent.class, count = 1), // implicit lock @Expect(type = SoftwareModuleUpdatedEvent.class, count = 9), // implicit lock - @Expect(type = TargetUpdatedEvent.class, count = 1), @Expect(type = TargetPollEvent.class, count = 1) }) + @Expect(type = TargetUpdatedEvent.class, count = 1), + @Expect(type = TargetPollEvent.class, count = 1) }) public void sendDownloadStatusBeforeMaintenanceWindowStartTime() { final String controllerId = TARGET_PREFIX + "sendDownloadStatusBeforeWindowStartTime"; @@ -132,14 +136,16 @@ public class AmqpMessageDispatcherServiceIntegrationTest extends AbstractAmqpSer @Test @Description("Verify that a distribution assignment sends a download and install message with window configured and during maintenance window start time.") - @ExpectEvents({ @Expect(type = TargetCreatedEvent.class, count = 1), + @ExpectEvents({ + @Expect(type = TargetCreatedEvent.class, count = 1), @Expect(type = TargetAssignDistributionSetEvent.class, count = 1), @Expect(type = ActionCreatedEvent.class, count = 1), @Expect(type = DistributionSetCreatedEvent.class, count = 1), @Expect(type = SoftwareModuleCreatedEvent.class, count = 3), @Expect(type = DistributionSetUpdatedEvent.class, count = 1), // implicit lock @Expect(type = SoftwareModuleUpdatedEvent.class, count = 9), // implicit lock - @Expect(type = TargetUpdatedEvent.class, count = 1), @Expect(type = TargetPollEvent.class, count = 1) }) + @Expect(type = TargetUpdatedEvent.class, count = 1), + @Expect(type = TargetPollEvent.class, count = 1) }) public void sendDownloadAndInstallStatusMessageDuringMaintenanceWindow() { final String controllerId = TARGET_PREFIX + "sendDAndIStatusMessageDuringWindow"; @@ -155,15 +161,18 @@ public class AmqpMessageDispatcherServiceIntegrationTest extends AbstractAmqpSer @Test @Description("Verify that a distribution assignment multiple times send cancel and assign events with right softwaremodules") - @ExpectEvents({ @Expect(type = TargetCreatedEvent.class, count = 1), + @ExpectEvents({ + @Expect(type = TargetCreatedEvent.class, count = 1), @Expect(type = TargetAssignDistributionSetEvent.class, count = 2), @Expect(type = CancelTargetAssignmentEvent.class, count = 1), - @Expect(type = ActionCreatedEvent.class, count = 2), @Expect(type = ActionUpdatedEvent.class, count = 2), + @Expect(type = ActionCreatedEvent.class, count = 2), + @Expect(type = ActionUpdatedEvent.class, count = 2), @Expect(type = DistributionSetCreatedEvent.class, count = 2), @Expect(type = SoftwareModuleCreatedEvent.class, count = 6), @Expect(type = DistributionSetUpdatedEvent.class, count = 2), // implicit lock @Expect(type = SoftwareModuleUpdatedEvent.class, count = 18), // implicit lock - @Expect(type = TargetUpdatedEvent.class, count = 2), @Expect(type = TargetPollEvent.class, count = 3) }) + @Expect(type = TargetUpdatedEvent.class, count = 2), + @Expect(type = TargetPollEvent.class, count = 3) }) public void assignDistributionSetMultipleTimes() { final String controllerId = TARGET_PREFIX + "assignDistributionSetMultipleTimes"; @@ -198,16 +207,19 @@ public class AmqpMessageDispatcherServiceIntegrationTest extends AbstractAmqpSer @Test @Description("If multi assignment is enabled multi-action messages are sent.") - @ExpectEvents({ @Expect(type = TargetCreatedEvent.class, count = 1), + @ExpectEvents({ + @Expect(type = TargetCreatedEvent.class, count = 1), @Expect(type = MultiActionAssignEvent.class, count = 2), @Expect(type = TargetAssignDistributionSetEvent.class, count = 0), @Expect(type = CancelTargetAssignmentEvent.class, count = 0), - @Expect(type = ActionCreatedEvent.class, count = 2), @Expect(type = ActionUpdatedEvent.class, count = 0), + @Expect(type = ActionCreatedEvent.class, count = 2), + @Expect(type = ActionUpdatedEvent.class, count = 0), @Expect(type = DistributionSetCreatedEvent.class, count = 2), @Expect(type = SoftwareModuleCreatedEvent.class, count = 6), @Expect(type = DistributionSetUpdatedEvent.class, count = 2), // implicit lock @Expect(type = SoftwareModuleUpdatedEvent.class, count = 6), // implicit lock - @Expect(type = TargetUpdatedEvent.class, count = 2), @Expect(type = TargetPollEvent.class, count = 1), + @Expect(type = TargetUpdatedEvent.class, count = 2), + @Expect(type = TargetPollEvent.class, count = 1), @Expect(type = TenantConfigurationCreatedEvent.class, count = 1) }) public void assignMultipleDsInMultiAssignMode() { enableMultiAssignments(); @@ -276,17 +288,20 @@ public class AmqpMessageDispatcherServiceIntegrationTest extends AbstractAmqpSer @Test @Description("Handle cancelation process of an action in multi assignment mode.") - @ExpectEvents({ @Expect(type = TargetCreatedEvent.class, count = 1), + @ExpectEvents({ + @Expect(type = TargetCreatedEvent.class, count = 1), @Expect(type = MultiActionCancelEvent.class, count = 1), @Expect(type = MultiActionAssignEvent.class, count = 2), @Expect(type = TargetAssignDistributionSetEvent.class, count = 0), @Expect(type = CancelTargetAssignmentEvent.class, count = 0), - @Expect(type = ActionCreatedEvent.class, count = 2), @Expect(type = ActionUpdatedEvent.class, count = 2), + @Expect(type = ActionCreatedEvent.class, count = 2), + @Expect(type = ActionUpdatedEvent.class, count = 2), @Expect(type = DistributionSetCreatedEvent.class, count = 2), @Expect(type = SoftwareModuleCreatedEvent.class, count = 6), @Expect(type = DistributionSetUpdatedEvent.class, count = 2), // implicit lock @Expect(type = SoftwareModuleUpdatedEvent.class, count = 6), // implicit lock - @Expect(type = TargetUpdatedEvent.class, count = 2), @Expect(type = TargetPollEvent.class, count = 1), + @Expect(type = TargetUpdatedEvent.class, count = 2), + @Expect(type = TargetPollEvent.class, count = 1), @Expect(type = TenantConfigurationCreatedEvent.class, count = 1) }) public void cancelActionInMultiAssignMode() { enableMultiAssignments(); @@ -311,17 +326,20 @@ public class AmqpMessageDispatcherServiceIntegrationTest extends AbstractAmqpSer @Test @Description("Handle finishing an action in multi assignment mode.") - @ExpectEvents({ @Expect(type = TargetCreatedEvent.class, count = 1), + @ExpectEvents({ + @Expect(type = TargetCreatedEvent.class, count = 1), @Expect(type = MultiActionAssignEvent.class, count = 2), @Expect(type = TargetAttributesRequestedEvent.class, count = 1), @Expect(type = TargetAssignDistributionSetEvent.class, count = 0), @Expect(type = CancelTargetAssignmentEvent.class, count = 0), - @Expect(type = ActionCreatedEvent.class, count = 2), @Expect(type = ActionUpdatedEvent.class, count = 1), + @Expect(type = ActionCreatedEvent.class, count = 2), + @Expect(type = ActionUpdatedEvent.class, count = 1), @Expect(type = DistributionSetCreatedEvent.class, count = 2), @Expect(type = SoftwareModuleCreatedEvent.class, count = 6), @Expect(type = DistributionSetUpdatedEvent.class, count = 2), // implicit lock @Expect(type = SoftwareModuleUpdatedEvent.class, count = 6), // implicit lock - @Expect(type = TargetUpdatedEvent.class, count = 3), @Expect(type = TargetPollEvent.class, count = 1), + @Expect(type = TargetUpdatedEvent.class, count = 3), + @Expect(type = TargetPollEvent.class, count = 1), @Expect(type = TenantConfigurationCreatedEvent.class, count = 1) }) public void finishActionInMultiAssignMode() { enableMultiAssignments(); @@ -341,16 +359,19 @@ public class AmqpMessageDispatcherServiceIntegrationTest extends AbstractAmqpSer @Test @Description("If multi assignment is enabled assigning a DS multiple times creates a new action every time.") - @ExpectEvents({ @Expect(type = TargetCreatedEvent.class, count = 1), + @ExpectEvents({ + @Expect(type = TargetCreatedEvent.class, count = 1), @Expect(type = MultiActionAssignEvent.class, count = 2), @Expect(type = TargetAssignDistributionSetEvent.class, count = 0), @Expect(type = CancelTargetAssignmentEvent.class, count = 0), - @Expect(type = ActionCreatedEvent.class, count = 2), @Expect(type = ActionUpdatedEvent.class, count = 0), + @Expect(type = ActionCreatedEvent.class, count = 2), + @Expect(type = ActionUpdatedEvent.class, count = 0), @Expect(type = DistributionSetCreatedEvent.class, count = 1), @Expect(type = SoftwareModuleCreatedEvent.class, count = 3), @Expect(type = DistributionSetUpdatedEvent.class, count = 1), // implicit lock @Expect(type = SoftwareModuleUpdatedEvent.class, count = 3), // implicit lock - @Expect(type = TargetUpdatedEvent.class, count = 2), @Expect(type = TargetPollEvent.class, count = 1), + @Expect(type = TargetUpdatedEvent.class, count = 2), + @Expect(type = TargetPollEvent.class, count = 1), @Expect(type = TenantConfigurationCreatedEvent.class, count = 1) }) public void assignDsMultipleTimesInMultiAssignMode() { enableMultiAssignments(); @@ -370,17 +391,21 @@ public class AmqpMessageDispatcherServiceIntegrationTest extends AbstractAmqpSer @Test @Description("If multi assignment is enabled multiple rollouts with the same DS lead to multiple actions.") - @ExpectEvents({ @Expect(type = TargetCreatedEvent.class, count = 1), + @ExpectEvents({ + @Expect(type = TargetCreatedEvent.class, count = 1), @Expect(type = MultiActionAssignEvent.class, count = 2), @Expect(type = TargetAssignDistributionSetEvent.class, count = 0), @Expect(type = CancelTargetAssignmentEvent.class, count = 0), - @Expect(type = ActionCreatedEvent.class, count = 2), @Expect(type = ActionUpdatedEvent.class, count = 2), + @Expect(type = ActionCreatedEvent.class, count = 2), + @Expect(type = ActionUpdatedEvent.class, count = 2), @Expect(type = DistributionSetCreatedEvent.class, count = 1), @Expect(type = SoftwareModuleCreatedEvent.class, count = 3), @Expect(type = DistributionSetUpdatedEvent.class, count = 1), // implicit lock @Expect(type = SoftwareModuleUpdatedEvent.class, count = 3), // implicit lock - @Expect(type = TargetUpdatedEvent.class, count = 1), @Expect(type = TargetPollEvent.class, count = 1), - @Expect(type = RolloutCreatedEvent.class, count = 2), @Expect(type = RolloutUpdatedEvent.class, count = 6), + @Expect(type = TargetUpdatedEvent.class, count = 1), + @Expect(type = TargetPollEvent.class, count = 1), + @Expect(type = RolloutCreatedEvent.class, count = 2), + @Expect(type = RolloutUpdatedEvent.class, count = 6), @Expect(type = RolloutGroupCreatedEvent.class, count = 2), @Expect(type = RolloutGroupUpdatedEvent.class, count = 4), @Expect(type = TenantConfigurationCreatedEvent.class, count = 1) }) @@ -404,16 +429,20 @@ public class AmqpMessageDispatcherServiceIntegrationTest extends AbstractAmqpSer @Test @Description("If multi assignment is enabled finishing one rollout does not affect other rollouts of the target.") - @ExpectEvents({ @Expect(type = TargetCreatedEvent.class, count = 1), + @ExpectEvents({ + @Expect(type = TargetCreatedEvent.class, count = 1), @Expect(type = MultiActionAssignEvent.class, count = 3), - @Expect(type = ActionCreatedEvent.class, count = 3), @Expect(type = ActionUpdatedEvent.class, count = 5), + @Expect(type = ActionCreatedEvent.class, count = 3), + @Expect(type = ActionUpdatedEvent.class, count = 5), @Expect(type = DistributionSetCreatedEvent.class, count = 2), @Expect(type = SoftwareModuleCreatedEvent.class, count = 6), @Expect(type = DistributionSetUpdatedEvent.class, count = 2), // implicit lock @Expect(type = SoftwareModuleUpdatedEvent.class, count = 6), // implicit lock - @Expect(type = TargetUpdatedEvent.class, count = 5), @Expect(type = TargetPollEvent.class, count = 1), + @Expect(type = TargetUpdatedEvent.class, count = 5), + @Expect(type = TargetPollEvent.class, count = 1), @Expect(type = TargetAttributesRequestedEvent.class, count = 2), - @Expect(type = RolloutCreatedEvent.class, count = 3), @Expect(type = RolloutUpdatedEvent.class, count = 9), + @Expect(type = RolloutCreatedEvent.class, count = 3), + @Expect(type = RolloutUpdatedEvent.class, count = 9), @Expect(type = RolloutGroupCreatedEvent.class, count = 3), @Expect(type = RolloutGroupUpdatedEvent.class, count = 6), @Expect(type = TenantConfigurationCreatedEvent.class, count = 1) }) @@ -450,15 +479,18 @@ public class AmqpMessageDispatcherServiceIntegrationTest extends AbstractAmqpSer @Test @Description("Verify that a cancel assignment send a cancel message.") - @ExpectEvents({ @Expect(type = TargetCreatedEvent.class, count = 1), + @ExpectEvents({ + @Expect(type = TargetCreatedEvent.class, count = 1), @Expect(type = TargetAssignDistributionSetEvent.class, count = 1), @Expect(type = CancelTargetAssignmentEvent.class, count = 1), - @Expect(type = ActionUpdatedEvent.class, count = 1), @Expect(type = ActionCreatedEvent.class, count = 1), + @Expect(type = ActionUpdatedEvent.class, count = 1), + @Expect(type = ActionCreatedEvent.class, count = 1), @Expect(type = DistributionSetCreatedEvent.class, count = 1), @Expect(type = SoftwareModuleCreatedEvent.class, count = 3), @Expect(type = DistributionSetUpdatedEvent.class, count = 1), // implicit lock @Expect(type = SoftwareModuleUpdatedEvent.class, count = 9), // implicit lock - @Expect(type = TargetUpdatedEvent.class, count = 1), @Expect(type = TargetPollEvent.class, count = 2) }) + @Expect(type = TargetUpdatedEvent.class, count = 1), + @Expect(type = TargetPollEvent.class, count = 2) }) public void sendCancelStatus() { final String controllerId = TARGET_PREFIX + "sendCancelStatus"; @@ -471,8 +503,10 @@ public class AmqpMessageDispatcherServiceIntegrationTest extends AbstractAmqpSer @Test @Description("Verify that when a target is deleted a target delete message is send.") - @ExpectEvents({ @Expect(type = TargetCreatedEvent.class, count = 1), - @Expect(type = TargetPollEvent.class, count = 1), @Expect(type = TargetDeletedEvent.class, count = 1) }) + @ExpectEvents({ + @Expect(type = TargetCreatedEvent.class, count = 1), + @Expect(type = TargetPollEvent.class, count = 1), + @Expect(type = TargetDeletedEvent.class, count = 1) }) public void sendDeleteMessage() { final String controllerId = TARGET_PREFIX + "sendDeleteMessage"; @@ -483,9 +517,11 @@ public class AmqpMessageDispatcherServiceIntegrationTest extends AbstractAmqpSer @Test @Description("Verify that attribute update is requested after device successfully closed software update.") - @ExpectEvents({ @Expect(type = TargetCreatedEvent.class, count = 1), + @ExpectEvents({ + @Expect(type = TargetCreatedEvent.class, count = 1), @Expect(type = TargetAssignDistributionSetEvent.class, count = 2), - @Expect(type = ActionUpdatedEvent.class, count = 2), @Expect(type = ActionCreatedEvent.class, count = 2), + @Expect(type = ActionUpdatedEvent.class, count = 2), + @Expect(type = ActionCreatedEvent.class, count = 2), @Expect(type = DistributionSetCreatedEvent.class, count = 2), @Expect(type = SoftwareModuleCreatedEvent.class, count = 6), @Expect(type = DistributionSetUpdatedEvent.class, count = 2), // implicit lock @@ -510,14 +546,16 @@ public class AmqpMessageDispatcherServiceIntegrationTest extends AbstractAmqpSer @Test @Description("Tests the download_only assignment: asserts correct dmf Message topic, and assigned DS") - @ExpectEvents({ @Expect(type = TargetCreatedEvent.class, count = 1), + @ExpectEvents({ + @Expect(type = TargetCreatedEvent.class, count = 1), @Expect(type = TargetAssignDistributionSetEvent.class, count = 1), @Expect(type = ActionCreatedEvent.class, count = 1), @Expect(type = DistributionSetCreatedEvent.class, count = 1), @Expect(type = SoftwareModuleCreatedEvent.class, count = 3), @Expect(type = DistributionSetUpdatedEvent.class, count = 1), // implicit lock @Expect(type = SoftwareModuleUpdatedEvent.class, count = 9), // implicit lock - @Expect(type = TargetUpdatedEvent.class, count = 1), @Expect(type = TargetPollEvent.class, count = 1) }) + @Expect(type = TargetUpdatedEvent.class, count = 1), + @Expect(type = TargetPollEvent.class, count = 1) }) public void downloadOnlyAssignmentSendsDownloadMessageTopic() { final String controllerId = TARGET_PREFIX + "registerTargets_1"; final DistributionSet distributionSet = createTargetAndDistributionSetAndAssign(controllerId, DOWNLOAD_ONLY); @@ -591,14 +629,17 @@ public class AmqpMessageDispatcherServiceIntegrationTest extends AbstractAmqpSer @ParameterizedTest @EnumSource(names = { "BATCH_DOWNLOAD_AND_INSTALL", "BATCH_DOWNLOAD" }) @Description("Verify payload of batch assignments.") - @ExpectEvents({ @Expect(type = TargetCreatedEvent.class, count = 3), + @ExpectEvents({ + @Expect(type = TargetCreatedEvent.class, count = 3), @Expect(type = TargetAssignDistributionSetEvent.class, count = 1), - @Expect(type = ActionCreatedEvent.class, count = 3), @Expect(type = ActionUpdatedEvent.class, count = 0), + @Expect(type = ActionCreatedEvent.class, count = 3), + @Expect(type = ActionUpdatedEvent.class, count = 0), @Expect(type = DistributionSetCreatedEvent.class, count = 1), @Expect(type = SoftwareModuleCreatedEvent.class, count = 3), @Expect(type = DistributionSetUpdatedEvent.class, count = 1), // implicit lock @Expect(type = SoftwareModuleUpdatedEvent.class, count = 9), // implicit lock - @Expect(type = TargetUpdatedEvent.class, count = 3), @Expect(type = TargetPollEvent.class, count = 3), + @Expect(type = TargetUpdatedEvent.class, count = 3), + @Expect(type = TargetPollEvent.class, count = 3), @Expect(type = TenantConfigurationCreatedEvent.class, count = 1) }) void assertBatchAssignmentsMessagePayload(final EventTopic topic) { enableBatchAssignments(); @@ -629,7 +670,8 @@ public class AmqpMessageDispatcherServiceIntegrationTest extends AbstractAmqpSer @Test @Description("Verify that a distribution assignment send a confirm message.") - @ExpectEvents({ @Expect(type = TargetCreatedEvent.class, count = 1), + @ExpectEvents({ + @Expect(type = TargetCreatedEvent.class, count = 1), @Expect(type = TargetAssignDistributionSetEvent.class, count = 1), @Expect(type = ActionCreatedEvent.class, count = 1), @Expect(type = DistributionSetCreatedEvent.class, count = 1), diff --git a/hawkbit-dmf/hawkbit-dmf-amqp/src/test/java/org/eclipse/hawkbit/integration/AmqpMessageHandlerServiceIntegrationTest.java b/hawkbit-dmf/hawkbit-dmf-amqp/src/test/java/org/eclipse/hawkbit/integration/AmqpMessageHandlerServiceIntegrationTest.java index 0e917ab93..0073933ef 100644 --- a/hawkbit-dmf/hawkbit-dmf-amqp/src/test/java/org/eclipse/hawkbit/integration/AmqpMessageHandlerServiceIntegrationTest.java +++ b/hawkbit-dmf/hawkbit-dmf-amqp/src/test/java/org/eclipse/hawkbit/integration/AmqpMessageHandlerServiceIntegrationTest.java @@ -107,7 +107,8 @@ class AmqpMessageHandlerServiceIntegrationTest extends AbstractAmqpServiceIntegr @Test @Description("Tests register target") - @ExpectEvents({ @Expect(type = TargetCreatedEvent.class, count = 2), + @ExpectEvents({ + @Expect(type = TargetCreatedEvent.class, count = 2), @Expect(type = TargetPollEvent.class, count = 3) }) void registerTargets() { final String controllerId = TARGET_PREFIX + "registerTargets"; @@ -122,8 +123,10 @@ class AmqpMessageHandlerServiceIntegrationTest extends AbstractAmqpServiceIntegr @Test @Description("Tests register target with name") - @ExpectEvents({ @Expect(type = TargetCreatedEvent.class, count = 1), - @Expect(type = TargetUpdatedEvent.class, count = 1), @Expect(type = TargetPollEvent.class, count = 2) }) + @ExpectEvents({ + @Expect(type = TargetCreatedEvent.class, count = 1), + @Expect(type = TargetUpdatedEvent.class, count = 1), + @Expect(type = TargetPollEvent.class, count = 2) }) void registerTargetWithName() { final String controllerId = TARGET_PREFIX + "registerTargetWithName"; final String name = "NonDefaultTargetName"; @@ -138,8 +141,10 @@ class AmqpMessageHandlerServiceIntegrationTest extends AbstractAmqpServiceIntegr @Test @Description("Tests register target with attributes") - @ExpectEvents({ @Expect(type = TargetCreatedEvent.class, count = 1), - @Expect(type = TargetUpdatedEvent.class, count = 2), @Expect(type = TargetPollEvent.class, count = 2) }) + @ExpectEvents({ + @Expect(type = TargetCreatedEvent.class, count = 1), + @Expect(type = TargetUpdatedEvent.class, count = 2), + @Expect(type = TargetPollEvent.class, count = 2) }) void registerTargetWithAttributes() { final String controllerId = TARGET_PREFIX + "registerTargetWithAttributes"; final Map attributes = new HashMap<>(); @@ -157,8 +162,10 @@ class AmqpMessageHandlerServiceIntegrationTest extends AbstractAmqpServiceIntegr @Test @Description("Tests register target with name and attributes") - @ExpectEvents({ @Expect(type = TargetCreatedEvent.class, count = 1), - @Expect(type = TargetUpdatedEvent.class, count = 3), @Expect(type = TargetPollEvent.class, count = 2) }) + @ExpectEvents({ + @Expect(type = TargetCreatedEvent.class, count = 1), + @Expect(type = TargetUpdatedEvent.class, count = 3), + @Expect(type = TargetPollEvent.class, count = 2) }) void registerTargetWithNameAndAttributes() { final String controllerId = TARGET_PREFIX + "registerTargetWithAttributes"; final String name = "NonDefaultTargetName"; @@ -180,7 +187,8 @@ class AmqpMessageHandlerServiceIntegrationTest extends AbstractAmqpServiceIntegr @ValueSource(strings = { "", "Invalid Invalid" }) @NullSource @Description("Tests register invalid target with empty controller id.") - @ExpectEvents({ @Expect(type = TargetCreatedEvent.class) }) + @ExpectEvents({ + @Expect(type = TargetCreatedEvent.class) }) void shouldNotRegisterTargetsWithInvalidControllerIds(String controllerId) { createAndSendThingCreated(controllerId); assertAllTargetsCount(0); @@ -189,7 +197,8 @@ class AmqpMessageHandlerServiceIntegrationTest extends AbstractAmqpServiceIntegr @Test @Description("Tests register invalid target with too long controller id") - @ExpectEvents({ @Expect(type = TargetCreatedEvent.class) }) + @ExpectEvents({ + @Expect(type = TargetCreatedEvent.class) }) void registerInvalidTargetWithTooLongControllerId() { createAndSendThingCreated(RandomStringUtils.randomAlphabetic(Target.CONTROLLER_ID_MAX_SIZE + 1)); assertAllTargetsCount(0); @@ -198,7 +207,8 @@ class AmqpMessageHandlerServiceIntegrationTest extends AbstractAmqpServiceIntegr @Test @Description("Tests null reply to property in message header. This message should forwarded to the deadletter queue") - @ExpectEvents({ @Expect(type = TargetCreatedEvent.class) }) + @ExpectEvents({ + @Expect(type = TargetCreatedEvent.class) }) void missingReplyToProperty() { final String controllerId = TARGET_PREFIX + "missingReplyToProperty"; final Message createTargetMessage = createTargetMessage(controllerId, TENANT_EXIST); @@ -211,7 +221,8 @@ class AmqpMessageHandlerServiceIntegrationTest extends AbstractAmqpServiceIntegr @Test @Description("Tests missing reply to property in message header. This message should forwarded to the deadletter queue") - @ExpectEvents({ @Expect(type = TargetCreatedEvent.class) }) + @ExpectEvents({ + @Expect(type = TargetCreatedEvent.class) }) void emptyReplyToProperty() { final String controllerId = TARGET_PREFIX + "emptyReplyToProperty"; final Message createTargetMessage = createTargetMessage(controllerId, TENANT_EXIST); @@ -224,7 +235,8 @@ class AmqpMessageHandlerServiceIntegrationTest extends AbstractAmqpServiceIntegr @Test @Description("Tests missing thing id property in message. This message should forwarded to the deadletter queue") - @ExpectEvents({ @Expect(type = TargetCreatedEvent.class) }) + @ExpectEvents({ + @Expect(type = TargetCreatedEvent.class) }) void missingThingIdProperty() { final Message createTargetMessage = createTargetMessage(null, TENANT_EXIST); createTargetMessage.getMessageProperties().getHeaders().remove(MessageHeaderKey.THING_ID); @@ -236,7 +248,8 @@ class AmqpMessageHandlerServiceIntegrationTest extends AbstractAmqpServiceIntegr @Test @Description("Tests null thing id property in message. This message should forwarded to the deadletter queue") - @ExpectEvents({ @Expect(type = TargetCreatedEvent.class) }) + @ExpectEvents({ + @Expect(type = TargetCreatedEvent.class) }) void nullThingIdProperty() { final Message createTargetMessage = createTargetMessage(null, TENANT_EXIST); getDmfClient().send(createTargetMessage); @@ -247,7 +260,8 @@ class AmqpMessageHandlerServiceIntegrationTest extends AbstractAmqpServiceIntegr @Test @Description("Tests missing tenant message header. This message should forwarded to the deadletter queue") - @ExpectEvents({ @Expect(type = TargetCreatedEvent.class) }) + @ExpectEvents({ + @Expect(type = TargetCreatedEvent.class) }) void missingTenantHeader() { final String controllerId = TARGET_PREFIX + "missingTenantHeader"; final Message createTargetMessage = createTargetMessage(controllerId, TENANT_EXIST); @@ -260,7 +274,8 @@ class AmqpMessageHandlerServiceIntegrationTest extends AbstractAmqpServiceIntegr @Test @Description("Tests null tenant message header. This message should forwarded to the deadletter queue") - @ExpectEvents({ @Expect(type = TargetCreatedEvent.class) }) + @ExpectEvents({ + @Expect(type = TargetCreatedEvent.class) }) void nullTenantHeader() { final String controllerId = TARGET_PREFIX + "nullTenantHeader"; final Message createTargetMessage = createTargetMessage(controllerId, null); @@ -272,7 +287,8 @@ class AmqpMessageHandlerServiceIntegrationTest extends AbstractAmqpServiceIntegr @Test @Description("Tests empty tenant message header. This message should forwarded to the deadletter queue") - @ExpectEvents({ @Expect(type = TargetCreatedEvent.class) }) + @ExpectEvents({ + @Expect(type = TargetCreatedEvent.class) }) void emptyTenantHeader() { final String controllerId = TARGET_PREFIX + "emptyTenantHeader"; final Message createTargetMessage = createTargetMessage(controllerId, ""); @@ -282,21 +298,10 @@ class AmqpMessageHandlerServiceIntegrationTest extends AbstractAmqpServiceIntegr assertAllTargetsCount(0); } - @Test - @Description("Tests tenant not exist. This message should forwarded to the deadletter queue") - @ExpectEvents({ @Expect(type = TargetCreatedEvent.class) }) - void tenantNotExist() { - final String controllerId = TARGET_PREFIX + "tenantNotExist"; - final Message createTargetMessage = createTargetMessage(controllerId, "TenantNotExist"); - getDmfClient().send(createTargetMessage); - - verifyOneDeadLetterMessage(); - assertThat(systemManagement.findTenants(PAGE)).hasSize(1); - } - @Test @Description("Tests missing type message header. This message should forwarded to the deadletter queue") - @ExpectEvents({ @Expect(type = TargetCreatedEvent.class) }) + @ExpectEvents({ + @Expect(type = TargetCreatedEvent.class) }) void missingTypeHeader() { final Message createTargetMessage = createTargetMessage(null, TENANT_EXIST); createTargetMessage.getMessageProperties().getHeaders().remove(MessageHeaderKey.TYPE); @@ -310,7 +315,8 @@ class AmqpMessageHandlerServiceIntegrationTest extends AbstractAmqpServiceIntegr @ValueSource(strings = { "", "NotExist" }) @NullSource @Description("Tests null type message header. This message should forwarded to the deadletter queue") - @ExpectEvents({ @Expect(type = TargetCreatedEvent.class) }) + @ExpectEvents({ + @Expect(type = TargetCreatedEvent.class) }) void shouldNotCreateTargetsWithInvalidTypeInHeader(String type) { final Message createTargetMessage = createTargetMessage(null, TENANT_EXIST); createTargetMessage.getMessageProperties().getHeaders().put(MessageHeaderKey.TYPE, type); @@ -324,7 +330,8 @@ class AmqpMessageHandlerServiceIntegrationTest extends AbstractAmqpServiceIntegr @ValueSource(strings = { "", "NotExist" }) @NullSource @Description("Tests null topic message header. This message should forwarded to the deadletter queue") - @ExpectEvents({ @Expect(type = TargetCreatedEvent.class) }) + @ExpectEvents({ + @Expect(type = TargetCreatedEvent.class) }) void shouldNotSendMessagesWithInvalidTopic(String topic) { final Message eventMessage = createUpdateActionEventMessage(""); eventMessage.getMessageProperties().getHeaders().put(MessageHeaderKey.TOPIC, topic); @@ -335,7 +342,8 @@ class AmqpMessageHandlerServiceIntegrationTest extends AbstractAmqpServiceIntegr @Test @Description("Tests missing topic message header. This message should forwarded to the deadletter queue") - @ExpectEvents({ @Expect(type = TargetCreatedEvent.class) }) + @ExpectEvents({ + @Expect(type = TargetCreatedEvent.class) }) void missingTopicHeader() { final Message eventMessage = createUpdateActionEventMessage(""); eventMessage.getMessageProperties().getHeaders().remove(MessageHeaderKey.TOPIC); @@ -348,7 +356,8 @@ class AmqpMessageHandlerServiceIntegrationTest extends AbstractAmqpServiceIntegr @ValueSource(strings = { "", "Invalid Content" }) @NullSource @Description("Tests invalid null message content. This message should forwarded to the deadletter queue") - @ExpectEvents({ @Expect(type = TargetCreatedEvent.class) }) + @ExpectEvents({ + @Expect(type = TargetCreatedEvent.class) }) void shouldMoveUpdateActionStatusWithInvalidPayloadIntoDeadLetter(String payload) { final Message eventMessage = createUpdateActionEventMessage(payload); getDmfClient().send(eventMessage); @@ -357,7 +366,8 @@ class AmqpMessageHandlerServiceIntegrationTest extends AbstractAmqpServiceIntegr @Test @Description("Tests invalid topic message header. This message should forwarded to the deadletter queue") - @ExpectEvents({ @Expect(type = TargetCreatedEvent.class) }) + @ExpectEvents({ + @Expect(type = TargetCreatedEvent.class) }) void updateActionStatusWithInvalidActionId() { final DmfActionUpdateStatus actionUpdateStatus = new DmfActionUpdateStatus(1L, DmfActionStatus.RUNNING); final Message eventMessage = createUpdateActionEventMessage(actionUpdateStatus); @@ -367,15 +377,18 @@ class AmqpMessageHandlerServiceIntegrationTest extends AbstractAmqpServiceIntegr @Test @Description("Tests register target and send finished message") - @ExpectEvents({ @Expect(type = TargetCreatedEvent.class, count = 1), + @ExpectEvents({ + @Expect(type = TargetCreatedEvent.class, count = 1), @Expect(type = TargetAssignDistributionSetEvent.class, count = 1), - @Expect(type = ActionUpdatedEvent.class, count = 1), @Expect(type = ActionCreatedEvent.class, count = 1), + @Expect(type = ActionUpdatedEvent.class, count = 1), + @Expect(type = ActionCreatedEvent.class, count = 1), @Expect(type = DistributionSetCreatedEvent.class, count = 1), @Expect(type = SoftwareModuleCreatedEvent.class, count = 3), @Expect(type = DistributionSetUpdatedEvent.class, count = 1), // implicit lock @Expect(type = SoftwareModuleUpdatedEvent.class, count = 9), // implicit lock @Expect(type = TargetAttributesRequestedEvent.class, count = 1), - @Expect(type = TargetUpdatedEvent.class, count = 2), @Expect(type = TargetPollEvent.class, count = 1) }) + @Expect(type = TargetUpdatedEvent.class, count = 2), + @Expect(type = TargetPollEvent.class, count = 1) }) void finishActionStatus() { final String controllerId = TARGET_PREFIX + "finishActionStatus"; registerTargetAndSendAndAssertUpdateActionStatus(DmfActionStatus.FINISHED, Status.FINISHED, controllerId); @@ -383,14 +396,17 @@ class AmqpMessageHandlerServiceIntegrationTest extends AbstractAmqpServiceIntegr @Test @Description("Register a target and send a update action status (running). Verify if the updated action status is correct.") - @ExpectEvents({ @Expect(type = TargetCreatedEvent.class, count = 1), + @ExpectEvents({ + @Expect(type = TargetCreatedEvent.class, count = 1), @Expect(type = TargetAssignDistributionSetEvent.class, count = 1), - @Expect(type = ActionUpdatedEvent.class), @Expect(type = ActionCreatedEvent.class, count = 1), + @Expect(type = ActionUpdatedEvent.class), + @Expect(type = ActionCreatedEvent.class, count = 1), @Expect(type = DistributionSetCreatedEvent.class, count = 1), @Expect(type = SoftwareModuleCreatedEvent.class, count = 3), @Expect(type = DistributionSetUpdatedEvent.class, count = 1), // implicit lock @Expect(type = SoftwareModuleUpdatedEvent.class, count = 9), // implicit lock - @Expect(type = TargetUpdatedEvent.class, count = 1), @Expect(type = TargetPollEvent.class, count = 1) }) + @Expect(type = TargetUpdatedEvent.class, count = 1), + @Expect(type = TargetPollEvent.class, count = 1) }) void runningActionStatus() { final String controllerId = TARGET_PREFIX + "runningActionStatus"; registerTargetAndSendAndAssertUpdateActionStatus(DmfActionStatus.RUNNING, Status.RUNNING, controllerId); @@ -398,14 +414,17 @@ class AmqpMessageHandlerServiceIntegrationTest extends AbstractAmqpServiceIntegr @Test @Description("Register a target and send an update action status (downloaded). Verify if the updated action status is correct.") - @ExpectEvents({ @Expect(type = TargetCreatedEvent.class, count = 1), + @ExpectEvents({ + @Expect(type = TargetCreatedEvent.class, count = 1), @Expect(type = TargetAssignDistributionSetEvent.class, count = 1), - @Expect(type = ActionUpdatedEvent.class), @Expect(type = ActionCreatedEvent.class, count = 1), + @Expect(type = ActionUpdatedEvent.class), + @Expect(type = ActionCreatedEvent.class, count = 1), @Expect(type = DistributionSetCreatedEvent.class, count = 1), @Expect(type = SoftwareModuleCreatedEvent.class, count = 3), @Expect(type = DistributionSetUpdatedEvent.class, count = 1), // implicit lock @Expect(type = SoftwareModuleUpdatedEvent.class, count = 9), // implicit lock - @Expect(type = TargetUpdatedEvent.class, count = 1), @Expect(type = TargetPollEvent.class, count = 1) }) + @Expect(type = TargetUpdatedEvent.class, count = 1), + @Expect(type = TargetPollEvent.class, count = 1) }) void downloadedActionStatus() { final String controllerId = TARGET_PREFIX + "downloadedActionStatus"; registerTargetAndSendAndAssertUpdateActionStatus(DmfActionStatus.DOWNLOADED, Status.DOWNLOADED, controllerId); @@ -413,14 +432,16 @@ class AmqpMessageHandlerServiceIntegrationTest extends AbstractAmqpServiceIntegr @Test @Description("Register a target and send a update action status (download). Verify if the updated action status is correct.") - @ExpectEvents({ @Expect(type = TargetCreatedEvent.class, count = 1), + @ExpectEvents({ + @Expect(type = TargetCreatedEvent.class, count = 1), @Expect(type = TargetAssignDistributionSetEvent.class, count = 1), @Expect(type = ActionCreatedEvent.class, count = 1), @Expect(type = DistributionSetCreatedEvent.class, count = 1), @Expect(type = SoftwareModuleCreatedEvent.class, count = 3), @Expect(type = DistributionSetUpdatedEvent.class, count = 1), // implicit lock @Expect(type = SoftwareModuleUpdatedEvent.class, count = 9), // implicit lock - @Expect(type = TargetUpdatedEvent.class, count = 1), @Expect(type = TargetPollEvent.class, count = 1) }) + @Expect(type = TargetUpdatedEvent.class, count = 1), + @Expect(type = TargetPollEvent.class, count = 1) }) void downloadActionStatus() { final String controllerId = TARGET_PREFIX + "downloadActionStatus"; registerTargetAndSendAndAssertUpdateActionStatus(DmfActionStatus.DOWNLOAD, Status.DOWNLOAD, controllerId); @@ -428,14 +449,17 @@ class AmqpMessageHandlerServiceIntegrationTest extends AbstractAmqpServiceIntegr @Test @Description("Register a target and send a update action status (error). Verify if the updated action status is correct.") - @ExpectEvents({ @Expect(type = TargetCreatedEvent.class, count = 1), + @ExpectEvents({ + @Expect(type = TargetCreatedEvent.class, count = 1), @Expect(type = TargetAssignDistributionSetEvent.class, count = 1), - @Expect(type = ActionUpdatedEvent.class, count = 1), @Expect(type = ActionCreatedEvent.class, count = 1), + @Expect(type = ActionUpdatedEvent.class, count = 1), + @Expect(type = ActionCreatedEvent.class, count = 1), @Expect(type = DistributionSetCreatedEvent.class, count = 1), @Expect(type = SoftwareModuleCreatedEvent.class, count = 3), @Expect(type = DistributionSetUpdatedEvent.class, count = 1), // implicit lock @Expect(type = SoftwareModuleUpdatedEvent.class, count = 9), // implicit lock - @Expect(type = TargetUpdatedEvent.class, count = 2), @Expect(type = TargetPollEvent.class, count = 1) }) + @Expect(type = TargetUpdatedEvent.class, count = 2), + @Expect(type = TargetPollEvent.class, count = 1) }) void errorActionStatus() { final String controllerId = TARGET_PREFIX + "errorActionStatus"; registerTargetAndSendAndAssertUpdateActionStatus(DmfActionStatus.ERROR, Status.ERROR, controllerId); @@ -443,14 +467,16 @@ class AmqpMessageHandlerServiceIntegrationTest extends AbstractAmqpServiceIntegr @Test @Description("Register a target and send a update action status (warning). Verify if the updated action status is correct.") - @ExpectEvents({ @Expect(type = TargetCreatedEvent.class, count = 1), + @ExpectEvents({ + @Expect(type = TargetCreatedEvent.class, count = 1), @Expect(type = TargetAssignDistributionSetEvent.class, count = 1), @Expect(type = ActionCreatedEvent.class, count = 1), @Expect(type = DistributionSetCreatedEvent.class, count = 1), @Expect(type = SoftwareModuleCreatedEvent.class, count = 3), @Expect(type = DistributionSetUpdatedEvent.class, count = 1), // implicit lock @Expect(type = SoftwareModuleUpdatedEvent.class, count = 9), // implicit lock - @Expect(type = TargetUpdatedEvent.class, count = 1), @Expect(type = TargetPollEvent.class, count = 1) }) + @Expect(type = TargetUpdatedEvent.class, count = 1), + @Expect(type = TargetPollEvent.class, count = 1) }) void warningActionStatus() { final String controllerId = TARGET_PREFIX + "warningActionStatus"; registerTargetAndSendAndAssertUpdateActionStatus(DmfActionStatus.WARNING, Status.WARNING, controllerId); @@ -458,14 +484,16 @@ class AmqpMessageHandlerServiceIntegrationTest extends AbstractAmqpServiceIntegr @Test @Description("Register a target and send a update action status (retrieved). Verify if the updated action status is correct.") - @ExpectEvents({ @Expect(type = TargetCreatedEvent.class, count = 1), + @ExpectEvents({ + @Expect(type = TargetCreatedEvent.class, count = 1), @Expect(type = TargetAssignDistributionSetEvent.class, count = 1), @Expect(type = ActionCreatedEvent.class, count = 1), @Expect(type = DistributionSetCreatedEvent.class, count = 1), @Expect(type = SoftwareModuleCreatedEvent.class, count = 3), @Expect(type = DistributionSetUpdatedEvent.class, count = 1), // implicit lock @Expect(type = SoftwareModuleUpdatedEvent.class, count = 9), // implicit lock - @Expect(type = TargetUpdatedEvent.class, count = 1), @Expect(type = TargetPollEvent.class, count = 1) }) + @Expect(type = TargetUpdatedEvent.class, count = 1), + @Expect(type = TargetPollEvent.class, count = 1) }) void retrievedActionStatus() { final String controllerId = TARGET_PREFIX + "retrievedActionStatus"; registerTargetAndSendAndAssertUpdateActionStatus(DmfActionStatus.RETRIEVED, Status.RETRIEVED, controllerId); @@ -473,14 +501,16 @@ class AmqpMessageHandlerServiceIntegrationTest extends AbstractAmqpServiceIntegr @Test @Description("Register a target and send a invalid update action status (cancel). This message should forwarded to the deadletter queue") - @ExpectEvents({ @Expect(type = TargetCreatedEvent.class, count = 1), + @ExpectEvents({ + @Expect(type = TargetCreatedEvent.class, count = 1), @Expect(type = TargetAssignDistributionSetEvent.class, count = 1), @Expect(type = ActionCreatedEvent.class, count = 1), @Expect(type = DistributionSetCreatedEvent.class, count = 1), @Expect(type = SoftwareModuleCreatedEvent.class, count = 3), @Expect(type = DistributionSetUpdatedEvent.class, count = 1), // implicit lock @Expect(type = SoftwareModuleUpdatedEvent.class, count = 9), // implicit lock - @Expect(type = TargetUpdatedEvent.class, count = 1), @Expect(type = TargetPollEvent.class, count = 1) }) + @Expect(type = TargetUpdatedEvent.class, count = 1), + @Expect(type = TargetPollEvent.class, count = 1) }) void cancelNotAllowActionStatus() { final String controllerId = TARGET_PREFIX + "cancelNotAllowActionStatus"; registerTargetAndSendActionStatus(DmfActionStatus.CANCELED, controllerId); @@ -489,14 +519,16 @@ class AmqpMessageHandlerServiceIntegrationTest extends AbstractAmqpServiceIntegr @Test @Description("Verify receiving a download and install message if a deployment is done before the target has polled the first time.") - @ExpectEvents({ @Expect(type = TargetCreatedEvent.class, count = 1), + @ExpectEvents({ + @Expect(type = TargetCreatedEvent.class, count = 1), @Expect(type = TargetAssignDistributionSetEvent.class, count = 1), @Expect(type = ActionCreatedEvent.class, count = 1), @Expect(type = DistributionSetCreatedEvent.class, count = 1), @Expect(type = SoftwareModuleCreatedEvent.class, count = 3), @Expect(type = DistributionSetUpdatedEvent.class, count = 1), // implicit lock @Expect(type = SoftwareModuleUpdatedEvent.class, count = 9), // implicit lock - @Expect(type = TargetUpdatedEvent.class, count = 1), @Expect(type = TargetPollEvent.class, count = 2) }) + @Expect(type = TargetUpdatedEvent.class, count = 1), + @Expect(type = TargetPollEvent.class, count = 2) }) void receiveDownloadAndInstallMessageAfterAssignment() { final String controllerId = TARGET_PREFIX + "receiveDownLoadAndInstallMessageAfterAssignment"; @@ -516,14 +548,16 @@ class AmqpMessageHandlerServiceIntegrationTest extends AbstractAmqpServiceIntegr @Test @Description("Verify receiving a download message if a deployment is done with window configured but before maintenance window start time.") - @ExpectEvents({ @Expect(type = TargetCreatedEvent.class, count = 1), + @ExpectEvents({ + @Expect(type = TargetCreatedEvent.class, count = 1), @Expect(type = TargetAssignDistributionSetEvent.class, count = 1), @Expect(type = ActionCreatedEvent.class, count = 1), @Expect(type = DistributionSetCreatedEvent.class, count = 1), @Expect(type = SoftwareModuleCreatedEvent.class, count = 3), @Expect(type = DistributionSetUpdatedEvent.class, count = 1), // implicit lock @Expect(type = SoftwareModuleUpdatedEvent.class, count = 9), // implicit lock - @Expect(type = TargetUpdatedEvent.class, count = 1), @Expect(type = TargetPollEvent.class, count = 2) }) + @Expect(type = TargetUpdatedEvent.class, count = 1), + @Expect(type = TargetPollEvent.class, count = 2) }) void receiveDownloadMessageBeforeMaintenanceWindowStartTime() { final String controllerId = TARGET_PREFIX + "receiveDownLoadMessageBeforeMaintenanceWindowStartTime"; @@ -544,14 +578,16 @@ class AmqpMessageHandlerServiceIntegrationTest extends AbstractAmqpServiceIntegr @Test @Description("Verify receiving a download_and_install message if a deployment is done with window configured and during maintenance window start time.") - @ExpectEvents({ @Expect(type = TargetCreatedEvent.class, count = 1), + @ExpectEvents({ + @Expect(type = TargetCreatedEvent.class, count = 1), @Expect(type = TargetAssignDistributionSetEvent.class, count = 1), @Expect(type = ActionCreatedEvent.class, count = 1), @Expect(type = DistributionSetCreatedEvent.class, count = 1), @Expect(type = SoftwareModuleCreatedEvent.class, count = 3), @Expect(type = DistributionSetUpdatedEvent.class, count = 1), // implicit lock @Expect(type = SoftwareModuleUpdatedEvent.class, count = 9), // implicit lock - @Expect(type = TargetUpdatedEvent.class, count = 1), @Expect(type = TargetPollEvent.class, count = 2) }) + @Expect(type = TargetUpdatedEvent.class, count = 1), + @Expect(type = TargetPollEvent.class, count = 2) }) void receiveDownloadAndInstallMessageDuringMaintenanceWindow() { final String controllerId = TARGET_PREFIX + "receiveDownLoadAndInstallMessageDuringMaintenanceWindow"; @@ -572,7 +608,8 @@ class AmqpMessageHandlerServiceIntegrationTest extends AbstractAmqpServiceIntegr @Test @Description("Verify receiving a cancel update message if a deployment is canceled before the target has polled the first time.") - @ExpectEvents({ @Expect(type = TargetCreatedEvent.class, count = 1), + @ExpectEvents({ + @Expect(type = TargetCreatedEvent.class, count = 1), @Expect(type = TargetAssignDistributionSetEvent.class, count = 1), @Expect(type = ActionCreatedEvent.class, count = 1), @Expect(type = DistributionSetCreatedEvent.class, count = 1), @@ -580,7 +617,8 @@ class AmqpMessageHandlerServiceIntegrationTest extends AbstractAmqpServiceIntegr @Expect(type = DistributionSetUpdatedEvent.class, count = 1), // implicit lock @Expect(type = SoftwareModuleUpdatedEvent.class, count = 3), // implicit lock @Expect(type = CancelTargetAssignmentEvent.class, count = 1), - @Expect(type = ActionUpdatedEvent.class, count = 1), @Expect(type = TargetUpdatedEvent.class, count = 1), + @Expect(type = ActionUpdatedEvent.class, count = 1), + @Expect(type = TargetUpdatedEvent.class, count = 1), @Expect(type = TargetPollEvent.class, count = 2) }) void receiveCancelUpdateMessageAfterAssignmentWasCanceled() { final String controllerId = TARGET_PREFIX + "receiveCancelUpdateMessageAfterAssignmentWasCanceled"; @@ -602,15 +640,18 @@ class AmqpMessageHandlerServiceIntegrationTest extends AbstractAmqpServiceIntegr @Test @Description("Register a target and send a invalid update action status (canceled). The current status (pending) is not a canceling state. This message should forwarded to the deadletter queue") - @ExpectEvents({ @Expect(type = TargetCreatedEvent.class, count = 1), + @ExpectEvents({ + @Expect(type = TargetCreatedEvent.class, count = 1), @Expect(type = TargetAssignDistributionSetEvent.class, count = 1), - @Expect(type = ActionUpdatedEvent.class, count = 1), @Expect(type = ActionCreatedEvent.class, count = 1), + @Expect(type = ActionUpdatedEvent.class, count = 1), + @Expect(type = ActionCreatedEvent.class, count = 1), @Expect(type = DistributionSetCreatedEvent.class, count = 1), @Expect(type = SoftwareModuleCreatedEvent.class, count = 3), @Expect(type = DistributionSetUpdatedEvent.class, count = 1), // implicit lock @Expect(type = SoftwareModuleUpdatedEvent.class, count = 9), // implicit lock @Expect(type = CancelTargetAssignmentEvent.class, count = 1), - @Expect(type = TargetUpdatedEvent.class, count = 1), @Expect(type = TargetPollEvent.class, count = 1) }) + @Expect(type = TargetUpdatedEvent.class, count = 1), + @Expect(type = TargetPollEvent.class, count = 1) }) void actionNotExists() { final String controllerId = TARGET_PREFIX + "actionNotExists"; @@ -623,14 +664,16 @@ class AmqpMessageHandlerServiceIntegrationTest extends AbstractAmqpServiceIntegr @Test @Description("Register a target and send a invalid update action status (cancel_rejected). This message should forwarded to the deadletter queue") - @ExpectEvents({ @Expect(type = TargetCreatedEvent.class, count = 1), + @ExpectEvents({ + @Expect(type = TargetCreatedEvent.class, count = 1), @Expect(type = TargetAssignDistributionSetEvent.class, count = 1), @Expect(type = ActionCreatedEvent.class, count = 1), @Expect(type = DistributionSetCreatedEvent.class, count = 1), @Expect(type = SoftwareModuleCreatedEvent.class, count = 3), @Expect(type = DistributionSetUpdatedEvent.class, count = 1), // implicit lock @Expect(type = SoftwareModuleUpdatedEvent.class, count = 9), // implicit lock - @Expect(type = TargetUpdatedEvent.class, count = 1), @Expect(type = TargetPollEvent.class, count = 1) }) + @Expect(type = TargetUpdatedEvent.class, count = 1), + @Expect(type = TargetPollEvent.class, count = 1) }) void canceledRejectedNotAllowActionStatus() { final String controllerId = TARGET_PREFIX + "canceledRejectedNotAllowActionStatus"; registerTargetAndSendActionStatus(DmfActionStatus.CANCEL_REJECTED, controllerId); @@ -639,15 +682,18 @@ class AmqpMessageHandlerServiceIntegrationTest extends AbstractAmqpServiceIntegr @Test @Description("Register a target and send a valid update action status (cancel_rejected). Verify if the updated action status is correct.") - @ExpectEvents({ @Expect(type = TargetCreatedEvent.class, count = 1), + @ExpectEvents({ + @Expect(type = TargetCreatedEvent.class, count = 1), @Expect(type = TargetAssignDistributionSetEvent.class, count = 1), @Expect(type = CancelTargetAssignmentEvent.class, count = 1), - @Expect(type = ActionUpdatedEvent.class, count = 2), @Expect(type = ActionCreatedEvent.class, count = 1), + @Expect(type = ActionUpdatedEvent.class, count = 2), + @Expect(type = ActionCreatedEvent.class, count = 1), @Expect(type = DistributionSetCreatedEvent.class, count = 1), @Expect(type = SoftwareModuleCreatedEvent.class, count = 3), @Expect(type = DistributionSetUpdatedEvent.class, count = 1), // implicit lock @Expect(type = SoftwareModuleUpdatedEvent.class, count = 9), // implicit lock - @Expect(type = TargetUpdatedEvent.class, count = 1), @Expect(type = TargetPollEvent.class, count = 1) }) + @Expect(type = TargetUpdatedEvent.class, count = 1), + @Expect(type = TargetPollEvent.class, count = 1) }) void canceledRejectedActionStatus() { final String controllerId = TARGET_PREFIX + "canceledRejectedActionStatus"; @@ -664,8 +710,10 @@ class AmqpMessageHandlerServiceIntegrationTest extends AbstractAmqpServiceIntegr @Test @Description("Verify that sending an update controller attribute message to an existing target works. Verify that different update modes (merge, replace, remove) can be used.") - @ExpectEvents({ @Expect(type = TargetCreatedEvent.class, count = 1), - @Expect(type = TargetUpdatedEvent.class, count = 4), @Expect(type = TargetPollEvent.class, count = 1) }) + @ExpectEvents({ + @Expect(type = TargetCreatedEvent.class, count = 1), + @Expect(type = TargetUpdatedEvent.class, count = 4), + @Expect(type = TargetPollEvent.class, count = 1) }) void updateAttributesWithDifferentUpdateModes() { final String controllerId = TARGET_PREFIX + "updateAttributes"; @@ -688,8 +736,10 @@ class AmqpMessageHandlerServiceIntegrationTest extends AbstractAmqpServiceIntegr @Test @Description("Verify that sending an update controller attribute message with no thingid header to an existing target does not work.") - @ExpectEvents({ @Expect(type = TargetCreatedEvent.class, count = 1), - @Expect(type = TargetUpdatedEvent.class), @Expect(type = TargetPollEvent.class, count = 1) }) + @ExpectEvents({ + @Expect(type = TargetCreatedEvent.class, count = 1), + @Expect(type = TargetUpdatedEvent.class), + @Expect(type = TargetPollEvent.class, count = 1) }) void updateAttributesWithNoThingId() { final String controllerId = TARGET_PREFIX + "updateAttributesWithNoThingId"; @@ -713,8 +763,10 @@ class AmqpMessageHandlerServiceIntegrationTest extends AbstractAmqpServiceIntegr @Test @Description("Verify that sending an update controller attribute message with invalid body to an existing target does not work.") - @ExpectEvents({ @Expect(type = TargetCreatedEvent.class, count = 1), - @Expect(type = TargetUpdatedEvent.class), @Expect(type = TargetPollEvent.class, count = 1) }) + @ExpectEvents({ + @Expect(type = TargetCreatedEvent.class, count = 1), + @Expect(type = TargetUpdatedEvent.class), + @Expect(type = TargetPollEvent.class, count = 1) }) void updateAttributesWithWrongBody() { // setup registerAndAssertTargetWithExistingTenant(UPDATE_ATTR_TEST_CONTROLLER_ID); @@ -745,15 +797,18 @@ class AmqpMessageHandlerServiceIntegrationTest extends AbstractAmqpServiceIntegr @Test @Description("Tests the download_only assignment: tests the handling of a target reporting DOWNLOADED") - @ExpectEvents({ @Expect(type = TargetCreatedEvent.class, count = 1), + @ExpectEvents({ + @Expect(type = TargetCreatedEvent.class, count = 1), @Expect(type = TargetAssignDistributionSetEvent.class, count = 1), - @Expect(type = ActionUpdatedEvent.class, count = 1), @Expect(type = ActionCreatedEvent.class, count = 1), + @Expect(type = ActionUpdatedEvent.class, count = 1), + @Expect(type = ActionCreatedEvent.class, count = 1), @Expect(type = DistributionSetCreatedEvent.class, count = 1), @Expect(type = SoftwareModuleCreatedEvent.class, count = 3), @Expect(type = DistributionSetUpdatedEvent.class, count = 1), // implicit lock @Expect(type = SoftwareModuleUpdatedEvent.class, count = 9), // implicit lock @Expect(type = TargetAttributesRequestedEvent.class, count = 1), - @Expect(type = TargetUpdatedEvent.class, count = 2), @Expect(type = TargetPollEvent.class, count = 1) }) + @Expect(type = TargetUpdatedEvent.class, count = 2), + @Expect(type = TargetPollEvent.class, count = 1) }) void downloadOnlyAssignmentFinishesActionWhenTargetReportsDownloaded() throws IOException { // create target final String controllerId = TARGET_PREFIX + "registerTargets_1"; @@ -776,15 +831,18 @@ class AmqpMessageHandlerServiceIntegrationTest extends AbstractAmqpServiceIntegr @Test @Description("Tests the download_only assignment: tests the handling of a target reporting FINISHED") - @ExpectEvents({ @Expect(type = TargetCreatedEvent.class, count = 1), + @ExpectEvents({ + @Expect(type = TargetCreatedEvent.class, count = 1), @Expect(type = TargetAssignDistributionSetEvent.class, count = 1), - @Expect(type = ActionUpdatedEvent.class, count = 2), @Expect(type = ActionCreatedEvent.class, count = 1), + @Expect(type = ActionUpdatedEvent.class, count = 2), + @Expect(type = ActionCreatedEvent.class, count = 1), @Expect(type = DistributionSetCreatedEvent.class, count = 1), @Expect(type = SoftwareModuleCreatedEvent.class, count = 3), @Expect(type = DistributionSetUpdatedEvent.class, count = 1), // implicit lock @Expect(type = SoftwareModuleUpdatedEvent.class, count = 9), // implicit lock @Expect(type = TargetAttributesRequestedEvent.class, count = 2), - @Expect(type = TargetUpdatedEvent.class, count = 3), @Expect(type = TargetPollEvent.class, count = 1) }) + @Expect(type = TargetUpdatedEvent.class, count = 3), + @Expect(type = TargetPollEvent.class, count = 1) }) void downloadOnlyAssignmentAllowsActionStatusUpdatesWhenTargetReportsFinishedAndUpdatesInstalledDS() throws IOException { // create target @@ -815,7 +873,8 @@ class AmqpMessageHandlerServiceIntegrationTest extends AbstractAmqpServiceIntegr @Test @Description("Messages that result into certain exceptions being raised should not be requeued. This message should forwarded to the deadletter queue") - @ExpectEvents({ @Expect(type = TargetCreatedEvent.class) }) + @ExpectEvents({ + @Expect(type = TargetCreatedEvent.class) }) void ignoredExceptionTypesShouldNotBeRequeued() { final ControllerManagement mockedControllerManagement = Mockito.mock(ControllerManagement.class); final List> exceptionsThatShouldNotBeRequeued = Arrays @@ -839,7 +898,8 @@ class AmqpMessageHandlerServiceIntegrationTest extends AbstractAmqpServiceIntegr @Test @Description("Register a target and send a update action status (confirmed). Verify if the updated action status is correct.") - @ExpectEvents({ @Expect(type = TargetCreatedEvent.class, count = 1), + @ExpectEvents({ + @Expect(type = TargetCreatedEvent.class, count = 1), @Expect(type = TargetAssignDistributionSetEvent.class, count = 1), @Expect(type = ActionUpdatedEvent.class, count = 1), @Expect(type = ActionCreatedEvent.class, count = 1), @@ -866,7 +926,8 @@ class AmqpMessageHandlerServiceIntegrationTest extends AbstractAmqpServiceIntegr @Test @Description("Verify the DMF confirmed feedback can be provided if confirmation flow is disabled") - @ExpectEvents({ @Expect(type = TargetCreatedEvent.class, count = 1), + @ExpectEvents({ + @Expect(type = TargetCreatedEvent.class, count = 1), @Expect(type = TargetAssignDistributionSetEvent.class, count = 1), @Expect(type = ActionUpdatedEvent.class, count = 1), @Expect(type = ActionCreatedEvent.class, count = 1), @@ -899,7 +960,8 @@ class AmqpMessageHandlerServiceIntegrationTest extends AbstractAmqpServiceIntegr @Test @Description("Verify the DMF confirmed feedback can be provided if confirmation flow is disabled") - @ExpectEvents({ @Expect(type = TargetCreatedEvent.class, count = 1), + @ExpectEvents({ + @Expect(type = TargetCreatedEvent.class, count = 1), @Expect(type = TargetAssignDistributionSetEvent.class, count = 1), @Expect(type = ActionUpdatedEvent.class, count = 0), @Expect(type = ActionCreatedEvent.class, count = 1), @@ -928,7 +990,8 @@ class AmqpMessageHandlerServiceIntegrationTest extends AbstractAmqpServiceIntegr @Test @Description("Verify the DMF download and install message is send directly if auto-confirmation is active") - @ExpectEvents({ @Expect(type = TargetCreatedEvent.class, count = 1), + @ExpectEvents({ + @Expect(type = TargetCreatedEvent.class, count = 1), @Expect(type = TargetAssignDistributionSetEvent.class, count = 1), @Expect(type = ActionUpdatedEvent.class, count = 0), @Expect(type = ActionCreatedEvent.class, count = 1), @@ -960,9 +1023,11 @@ class AmqpMessageHandlerServiceIntegrationTest extends AbstractAmqpServiceIntegr @Test @Description("Register a target and send a update action status (denied). Verify if the updated action status is correct.") - @ExpectEvents({ @Expect(type = TargetCreatedEvent.class, count = 1), + @ExpectEvents({ + @Expect(type = TargetCreatedEvent.class, count = 1), @Expect(type = TargetAssignDistributionSetEvent.class, count = 1), - @Expect(type = ActionUpdatedEvent.class), @Expect(type = ActionCreatedEvent.class, count = 1), + @Expect(type = ActionUpdatedEvent.class), + @Expect(type = ActionCreatedEvent.class, count = 1), @Expect(type = DistributionSetCreatedEvent.class, count = 1), @Expect(type = SoftwareModuleCreatedEvent.class, count = 3), @Expect(type = DistributionSetUpdatedEvent.class, count = 1), // implicit lock diff --git a/hawkbit-mgmt/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtBasicAuthResourceTest.java b/hawkbit-mgmt/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtBasicAuthResourceTest.java index 6bafafe86..87876627e 100644 --- a/hawkbit-mgmt/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtBasicAuthResourceTest.java +++ b/hawkbit-mgmt/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtBasicAuthResourceTest.java @@ -80,7 +80,7 @@ public class MgmtBasicAuthResourceTest { @Autowired MockMvc defaultMock; private static final String TEST_USER = "testUser"; - private static final String DEFAULT = "default"; + private static final String DEFAULT_TENANT = "DEFAULT"; @Test @Description("Test of userinfo api with basic auth validation") @@ -92,7 +92,7 @@ public class MgmtBasicAuthResourceTest { .andExpect(status().isOk()) .andExpect(content().contentType(MediaTypes.HAL_JSON_VALUE)) .andExpect(jsonPath("$.username", equalTo(TEST_USER))) - .andExpect(jsonPath("$.tenant", equalTo(DEFAULT))); + .andExpect(jsonPath("$.tenant", equalTo(DEFAULT_TENANT))); } @Test diff --git a/hawkbit-mgmt/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDistributionSetTagResourceTest.java b/hawkbit-mgmt/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDistributionSetTagResourceTest.java index 3f4cb805d..69616e376 100644 --- a/hawkbit-mgmt/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDistributionSetTagResourceTest.java +++ b/hawkbit-mgmt/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDistributionSetTagResourceTest.java @@ -61,7 +61,8 @@ public class MgmtDistributionSetTagResourceTest extends AbstractManagementApiInt @Test @Description("Verfies that a paged result list of DS tags reflects the content on the repository side.") - @ExpectEvents({ @Expect(type = DistributionSetTagCreatedEvent.class, count = 2) }) + @ExpectEvents({ + @Expect(type = DistributionSetTagCreatedEvent.class, count = 2) }) public void getDistributionSetTags() throws Exception { final List tags = testdataFactory.createDistributionSetTags(2); final DistributionSetTag assigned = tags.get(0); @@ -161,7 +162,8 @@ public class MgmtDistributionSetTagResourceTest extends AbstractManagementApiInt @Test @Description("Verfies that a single result of a DS tag reflects the content on the repository side.") - @ExpectEvents({ @Expect(type = DistributionSetTagCreatedEvent.class, count = 2) }) + @ExpectEvents({ + @Expect(type = DistributionSetTagCreatedEvent.class, count = 2) }) public void getDistributionSetTag() throws Exception { final List tags = testdataFactory.createDistributionSetTags(2); final DistributionSetTag assigned = tags.get(0); @@ -179,7 +181,8 @@ public class MgmtDistributionSetTagResourceTest extends AbstractManagementApiInt @Test @Description("Verifies that created DS tags are stored in the repository as send to the API.") - @ExpectEvents({ @Expect(type = DistributionSetTagCreatedEvent.class, count = 2) }) + @ExpectEvents({ + @Expect(type = DistributionSetTagCreatedEvent.class, count = 2) }) public void createDistributionSetTags() throws Exception { final Tag tagOne = entityFactory.tag().create().colour("testcol1").description("its a test1").name("thetest1") .build(); @@ -209,7 +212,8 @@ public class MgmtDistributionSetTagResourceTest extends AbstractManagementApiInt @Test @Description("Verifies that an updated DS tag is stored in the repository as send to the API.") - @ExpectEvents({ @Expect(type = DistributionSetTagCreatedEvent.class, count = 1), + @ExpectEvents({ + @Expect(type = DistributionSetTagCreatedEvent.class, count = 1), @Expect(type = DistributionSetTagUpdatedEvent.class, count = 1) }) public void updateDistributionSetTag() throws Exception { final List tags = testdataFactory.createDistributionSetTags(1); @@ -237,7 +241,8 @@ public class MgmtDistributionSetTagResourceTest extends AbstractManagementApiInt @Test @Description("Verfies that the delete call is reflected by the repository.") - @ExpectEvents({ @Expect(type = DistributionSetTagCreatedEvent.class, count = 1), + @ExpectEvents({ + @Expect(type = DistributionSetTagCreatedEvent.class, count = 1), @Expect(type = DistributionSetTagDeletedEvent.class, count = 1) }) public void deleteDistributionSetTag() throws Exception { final List tags = testdataFactory.createDistributionSetTags(1); @@ -252,7 +257,8 @@ public class MgmtDistributionSetTagResourceTest extends AbstractManagementApiInt @Test @Description("Ensures that assigned DS to tag in repository are listed with proper paging results.") - @ExpectEvents({ @Expect(type = DistributionSetTagCreatedEvent.class, count = 1), + @ExpectEvents({ + @Expect(type = DistributionSetTagCreatedEvent.class, count = 1), @Expect(type = DistributionSetCreatedEvent.class, count = 5), @Expect(type = DistributionSetUpdatedEvent.class, count = 5) }) public void getAssignedDistributionSets() throws Exception { @@ -271,7 +277,8 @@ public class MgmtDistributionSetTagResourceTest extends AbstractManagementApiInt @Test @Description("Ensures that assigned DS to tag in repository are listed with proper paging results with paging limit parameter.") - @ExpectEvents({ @Expect(type = DistributionSetTagCreatedEvent.class, count = 1), + @ExpectEvents({ + @Expect(type = DistributionSetTagCreatedEvent.class, count = 1), @Expect(type = DistributionSetCreatedEvent.class, count = 5), @Expect(type = DistributionSetUpdatedEvent.class, count = 5) }) public void getAssignedDistributionSetsWithPagingLimitRequestParameter() throws Exception { @@ -292,7 +299,8 @@ public class MgmtDistributionSetTagResourceTest extends AbstractManagementApiInt @Test @Description("Ensures that assigned DS to tag in repository are listed with proper paging results with paging limit and offset parameter.") - @ExpectEvents({ @Expect(type = DistributionSetTagCreatedEvent.class, count = 1), + @ExpectEvents({ + @Expect(type = DistributionSetTagCreatedEvent.class, count = 1), @Expect(type = DistributionSetCreatedEvent.class, count = 5), @Expect(type = DistributionSetUpdatedEvent.class, count = 5) }) public void getAssignedDistributionSetsWithPagingLimitAndOffsetRequestParameter() throws Exception { @@ -316,7 +324,8 @@ public class MgmtDistributionSetTagResourceTest extends AbstractManagementApiInt @Test @Description("Verfies that tag assignments done through toggle API command are correctly assigned or unassigned.") - @ExpectEvents({ @Expect(type = DistributionSetTagCreatedEvent.class, count = 1), + @ExpectEvents({ + @Expect(type = DistributionSetTagCreatedEvent.class, count = 1), @Expect(type = DistributionSetCreatedEvent.class, count = 2), @Expect(type = DistributionSetUpdatedEvent.class, count = 4) }) public void toggleTagAssignment() throws Exception { @@ -390,7 +399,8 @@ public class MgmtDistributionSetTagResourceTest extends AbstractManagementApiInt @Test @Description("Verifies that tag unassignments done through tag API command are correctly stored in the repository.") - @ExpectEvents({ @Expect(type = DistributionSetTagCreatedEvent.class, count = 1), + @ExpectEvents({ + @Expect(type = DistributionSetTagCreatedEvent.class, count = 1), @Expect(type = DistributionSetCreatedEvent.class, count = 2), @Expect(type = DistributionSetUpdatedEvent.class, count = 3) }) public void unassignDistributionSet() throws Exception { diff --git a/hawkbit-mgmt/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtTargetTagResourceTest.java b/hawkbit-mgmt/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtTargetTagResourceTest.java index 4ad392a8b..06a2b7339 100644 --- a/hawkbit-mgmt/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtTargetTagResourceTest.java +++ b/hawkbit-mgmt/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtTargetTagResourceTest.java @@ -68,7 +68,8 @@ public class MgmtTargetTagResourceTest extends AbstractManagementApiIntegrationT @Test @Description("Verfies that a paged result list of target tags reflects the content on the repository side.") - @ExpectEvents({ @Expect(type = TargetTagCreatedEvent.class, count = 2) }) + @ExpectEvents({ + @Expect(type = TargetTagCreatedEvent.class, count = 2) }) public void getTargetTags() throws Exception { final List tags = testdataFactory.createTargetTags(2, ""); final TargetTag assigned = tags.get(0); @@ -131,7 +132,8 @@ public class MgmtTargetTagResourceTest extends AbstractManagementApiIntegrationT @Test @Description("Verfies that a single result of a target tag reflects the content on the repository side.") - @ExpectEvents({ @Expect(type = TargetTagCreatedEvent.class, count = 2) }) + @ExpectEvents({ + @Expect(type = TargetTagCreatedEvent.class, count = 2) }) public void getTargetTag() throws Exception { final List tags = testdataFactory.createTargetTags(2, ""); final TargetTag assigned = tags.get(0); @@ -150,7 +152,8 @@ public class MgmtTargetTagResourceTest extends AbstractManagementApiIntegrationT @Test @Description("Verifies that created target tags are stored in the repository as send to the API.") - @ExpectEvents({ @Expect(type = TargetTagCreatedEvent.class, count = 2) }) + @ExpectEvents({ + @Expect(type = TargetTagCreatedEvent.class, count = 2) }) public void createTargetTags() throws Exception { final Tag tagOne = entityFactory.tag().create().colour("testcol1").description("its a test1").name("thetest1") .build(); @@ -180,7 +183,8 @@ public class MgmtTargetTagResourceTest extends AbstractManagementApiIntegrationT @Test @Description("Verifies that an updated target tag is stored in the repository as send to the API.") - @ExpectEvents({ @Expect(type = TargetTagCreatedEvent.class, count = 1), + @ExpectEvents({ + @Expect(type = TargetTagCreatedEvent.class, count = 1), @Expect(type = TargetTagUpdatedEvent.class, count = 1) }) public void updateTargetTag() throws Exception { final List tags = testdataFactory.createTargetTags(1, ""); @@ -208,7 +212,8 @@ public class MgmtTargetTagResourceTest extends AbstractManagementApiIntegrationT @Test @Description("Verfies that the delete call is reflected by the repository.") - @ExpectEvents({ @Expect(type = TargetTagCreatedEvent.class, count = 1), + @ExpectEvents({ + @Expect(type = TargetTagCreatedEvent.class, count = 1), @Expect(type = TargetTagDeletedEvent.class, count = 1) }) public void deleteTargetTag() throws Exception { final List tags = testdataFactory.createTargetTags(1, ""); @@ -223,8 +228,10 @@ public class MgmtTargetTagResourceTest extends AbstractManagementApiIntegrationT @Test @Description("Ensures that assigned targets to tag in repository are listed with proper paging results.") - @ExpectEvents({ @Expect(type = TargetTagCreatedEvent.class, count = 1), - @Expect(type = TargetCreatedEvent.class, count = 5), @Expect(type = TargetUpdatedEvent.class, count = 5) }) + @ExpectEvents({ + @Expect(type = TargetTagCreatedEvent.class, count = 1), + @Expect(type = TargetCreatedEvent.class, count = 5), + @Expect(type = TargetUpdatedEvent.class, count = 5) }) public void getAssignedTargets() throws Exception { final TargetTag tag = testdataFactory.createTargetTags(1, "").get(0); final int targetsAssigned = 5; @@ -241,8 +248,10 @@ public class MgmtTargetTagResourceTest extends AbstractManagementApiIntegrationT @Test @Description("Ensures that assigned DS to tag in repository are listed with proper paging results with paging limit parameter.") - @ExpectEvents({ @Expect(type = TargetTagCreatedEvent.class, count = 1), - @Expect(type = TargetCreatedEvent.class, count = 5), @Expect(type = TargetUpdatedEvent.class, count = 5) }) + @ExpectEvents({ + @Expect(type = TargetTagCreatedEvent.class, count = 1), + @Expect(type = TargetCreatedEvent.class, count = 5), + @Expect(type = TargetUpdatedEvent.class, count = 5) }) public void getAssignedTargetsWithPagingLimitRequestParameter() throws Exception { final TargetTag tag = testdataFactory.createTargetTags(1, "").get(0); final int targetsAssigned = 5; @@ -261,8 +270,10 @@ public class MgmtTargetTagResourceTest extends AbstractManagementApiIntegrationT @Test @Description("Ensures that assigned targets to tag in repository are listed with proper paging results with paging limit and offset parameter.") - @ExpectEvents({ @Expect(type = TargetTagCreatedEvent.class, count = 1), - @Expect(type = TargetCreatedEvent.class, count = 5), @Expect(type = TargetUpdatedEvent.class, count = 5) }) + @ExpectEvents({ + @Expect(type = TargetTagCreatedEvent.class, count = 1), + @Expect(type = TargetCreatedEvent.class, count = 5), + @Expect(type = TargetUpdatedEvent.class, count = 5) }) public void getAssignedTargetsWithPagingLimitAndOffsetRequestParameter() throws Exception { final TargetTag tag = testdataFactory.createTargetTags(1, "").get(0); final int targetsAssigned = 5; @@ -612,8 +623,10 @@ public class MgmtTargetTagResourceTest extends AbstractManagementApiIntegrationT // DEPRECATED scenarios @Test @Description("Verifes that tag assignments done through toggle API command are correctly assigned or unassigned.") - @ExpectEvents({ @Expect(type = TargetTagCreatedEvent.class, count = 1), - @Expect(type = TargetCreatedEvent.class, count = 2), @Expect(type = TargetUpdatedEvent.class, count = 4) }) + @ExpectEvents({ + @Expect(type = TargetTagCreatedEvent.class, count = 1), + @Expect(type = TargetCreatedEvent.class, count = 2), + @Expect(type = TargetUpdatedEvent.class, count = 4) }) public void toggleTagAssignment() throws Exception { final TargetTag tag = testdataFactory.createTargetTags(1, "").get(0); final int targetsAssigned = 2; @@ -641,8 +654,10 @@ public class MgmtTargetTagResourceTest extends AbstractManagementApiIntegrationT @Test @Description("Verfies that tag assignments done through tag API command are correctly stored in the repository.") - @ExpectEvents({ @Expect(type = TargetTagCreatedEvent.class, count = 1), - @Expect(type = TargetCreatedEvent.class, count = 2), @Expect(type = TargetUpdatedEvent.class, count = 2) }) + @ExpectEvents({ + @Expect(type = TargetTagCreatedEvent.class, count = 1), + @Expect(type = TargetCreatedEvent.class, count = 2), + @Expect(type = TargetUpdatedEvent.class, count = 2) }) public void assignTargetsByRequestBody() throws Exception { final TargetTag tag = testdataFactory.createTargetTags(1, "").get(0); final int targetsAssigned = 2; diff --git a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/SystemManagement.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/SystemManagement.java index 5aad33cb9..30b56e777 100644 --- a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/SystemManagement.java +++ b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/SystemManagement.java @@ -29,12 +29,6 @@ import org.springframework.security.access.prepost.PreAuthorize; */ public interface SystemManagement { - /** - * Checks if a specific tenant exists. The tenant will not be created lazy. - * - * @return {@code true} in case the tenant exits or {@code false} if not - */ - String currentTenant(); /** * Deletes all data related to a given tenant. @@ -113,13 +107,9 @@ public interface SystemManagement { @PreAuthorize(SpringEvalExpressions.HAS_AUTH_TENANT_CONFIGURATION) TenantMetaData updateTenantMetadata(long defaultDsType); - /** - * Returns {@link TenantMetaData} of given tenant ID. - * - * @param tenantId to retrieve data for - * @return {@link TenantMetaData} of given tenant - */ @PreAuthorize(SpringEvalExpressions.IS_SYSTEM_CODE) TenantMetaData getTenantMetadata(long tenantId); + @PreAuthorize(SpringEvalExpressions.IS_SYSTEM_CODE) + boolean tenantExists(String tenant); } diff --git a/hawkbit-repository/hawkbit-repository-api/src/test/java/org/eclipse/hawkbit/repository/RepositoryManagementMethodPreAuthorizeAnnotatedTest.java b/hawkbit-repository/hawkbit-repository-api/src/test/java/org/eclipse/hawkbit/repository/RepositoryManagementMethodPreAuthorizeAnnotatedTest.java index 06e17dc41..b682837fe 100644 --- a/hawkbit-repository/hawkbit-repository-api/src/test/java/org/eclipse/hawkbit/repository/RepositoryManagementMethodPreAuthorizeAnnotatedTest.java +++ b/hawkbit-repository/hawkbit-repository-api/src/test/java/org/eclipse/hawkbit/repository/RepositoryManagementMethodPreAuthorizeAnnotatedTest.java @@ -30,12 +30,9 @@ import org.springframework.security.access.prepost.PreAuthorize; @Story("Security Test") public class RepositoryManagementMethodPreAuthorizeAnnotatedTest { + // if some methods are to be excluded private static final Set METHOD_SECURITY_EXCLUSION = new HashSet<>(); - static { - METHOD_SECURITY_EXCLUSION.add(getMethod(SystemManagement.class, "currentTenant")); - } - @Test @Description("Verifies that repository methods are @PreAuthorize annotated") public void repositoryManagementMethodsArePreAuthorizedAnnotated() { @@ -74,16 +71,10 @@ public class RepositoryManagementMethodPreAuthorizeAnnotatedTest { continue; } final PreAuthorize annotation = method.getAnnotation(PreAuthorize.class); - assertThat(annotation).as("The public method " + method.getName() + " in class " + clazz.getName() - + " is not annotated with @PreAuthorize, security leak?").isNotNull(); + assertThat(annotation) + .as("The public method " + method.getName() + " in class " + clazz.getName() + + " is not annotated with @PreAuthorize, security leak?") + .isNotNull(); } } - - private static Method getMethod(final Class clazz, final String methodName, final Class... parameterTypes) { - try { - return clazz.getMethod(methodName, parameterTypes); - } catch (NoSuchMethodException | SecurityException e) { - throw new RuntimeException(e.getMessage(), e); - } - } -} +} \ No newline at end of file diff --git a/hawkbit-repository/hawkbit-repository-core/src/main/java/org/eclipse/hawkbit/repository/model/helper/SystemManagementHolder.java b/hawkbit-repository/hawkbit-repository-core/src/main/java/org/eclipse/hawkbit/repository/model/helper/SystemManagementHolder.java index 631cd0706..7d5ee8255 100644 --- a/hawkbit-repository/hawkbit-repository-core/src/main/java/org/eclipse/hawkbit/repository/model/helper/SystemManagementHolder.java +++ b/hawkbit-repository/hawkbit-repository-core/src/main/java/org/eclipse/hawkbit/repository/model/helper/SystemManagementHolder.java @@ -36,11 +36,4 @@ public final class SystemManagementHolder { public static SystemManagementHolder getInstance() { return INSTANCE; } - - /** - * @return the {@link SystemManagement#currentTenant()}. - */ - public String currentTenant() { - return systemManagement.currentTenant(); - } } \ No newline at end of file diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaManagementHelper.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaManagementHelper.java index ba6080280..880e69a62 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaManagementHelper.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaManagementHelper.java @@ -86,7 +86,8 @@ public final class JpaManagementHelper { public static J touch(final EntityManager entityManager, final CrudRepository repository, final J entity) { - // merge base entity so optLockRevision gets updated and auditing log written because modifying e.g. metadata is modifying the base + // merge base entity so optLockRevision gets updated and audit + // log written because modifying e.g. metadata is modifying the base // entity itself for auditing purposes. final J result = entityManager.merge(entity); result.setLastModifiedAt(0L); diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/aspects/ExceptionMappingAspectHandler.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/aspects/ExceptionMappingAspectHandler.java index d39974a4a..b28126569 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/aspects/ExceptionMappingAspectHandler.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/aspects/ExceptionMappingAspectHandler.java @@ -42,9 +42,8 @@ public class ExceptionMappingAspectHandler implements Ordered { private static final Map EXCEPTION_MAPPING = new HashMap<>(4); /** - * this is required to enable a certain order of exception and to select the - * most specific mappable exception according to the type hierarchy of the - * exception. + * this is required to enable a certain order of exception and to select the most specific mappable exception according to the type + * hierarchy of the exception. */ private static final List> MAPPED_EXCEPTION_ORDER = new ArrayList<>(4); @@ -72,22 +71,18 @@ public class ExceptionMappingAspectHandler implements Ordered { // It is a AspectJ proxy which deals with exceptions. @SuppressWarnings({ "squid:S00112", "squid:S1162" }) public void catchAndWrapJpaExceptionsService(final Exception ex) throws Throwable { - - // Workaround for EclipseLink merge where it does not throw ConstraintViolationException directly in case of - // existing entity update + // Workaround for EclipseLink merge where it does not throw ConstraintViolationException directly in case of existing entity update if (ex instanceof TransactionSystemException) { throw replaceWithCauseIfConstraintViolationException((TransactionSystemException) ex); } for (final Class mappedEx : MAPPED_EXCEPTION_ORDER) { - if (!mappedEx.isAssignableFrom(ex.getClass())) { continue; } if (EXCEPTION_MAPPING.containsKey(mappedEx.getName())) { - throw (Exception) Class.forName(EXCEPTION_MAPPING.get(mappedEx.getName())) - .getConstructor(Throwable.class).newInstance(ex); + throw (Exception) Class.forName(EXCEPTION_MAPPING.get(mappedEx.getName())).getConstructor(Throwable.class).newInstance(ex); } log.error("there is no mapping configured for exception class {}", mappedEx.getName()); diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/builder/JpaDistributionSetCreate.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/builder/JpaDistributionSetCreate.java index 98c6388d0..878560fa0 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/builder/JpaDistributionSetCreate.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/builder/JpaDistributionSetCreate.java @@ -51,7 +51,8 @@ public class JpaDistributionSetCreate extends AbstractDistributionSetUpdateCreat @Override public JpaDistributionSet build() { - return new JpaDistributionSet(name, version, description, + return new JpaDistributionSet( + name, version, description, Optional.ofNullable(type).map(this::findDistributionSetTypeWithExceptionIfNotFound).orElse(null), findSoftwareModuleWithExceptionIfNotFound(modules), Optional.ofNullable(requiredMigrationStep).orElse(Boolean.FALSE)); diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/configuration/MultiTenantJpaTransactionManager.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/configuration/MultiTenantJpaTransactionManager.java index 1f25b4109..309658667 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/configuration/MultiTenantJpaTransactionManager.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/configuration/MultiTenantJpaTransactionManager.java @@ -25,8 +25,7 @@ import org.springframework.transaction.TransactionDefinition; import org.springframework.transaction.support.TransactionSynchronizationManager; /** - * {@link JpaTransactionManager} that sets the - * {@link TenantAware#getCurrentTenant()} in the eclipselink session. This has + * {@link JpaTransactionManager} that sets the {@link TenantAware#getCurrentTenant()} in the eclipselink session. This has * to be done in eclipselink after a {@link Transaction} has been started. */ public class MultiTenantJpaTransactionManager extends JpaTransactionManager { diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/management/JpaActionManagement.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/management/JpaActionManagement.java index 782037a71..c2b274155 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/management/JpaActionManagement.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/management/JpaActionManagement.java @@ -66,8 +66,7 @@ public class JpaActionManagement { } protected List findActiveActionsHavingStatus(final String controllerId, final Action.Status status) { - return actionRepository.findAll( - ActionSpecifications.byTargetControllerIdAndIsActiveAndStatus(controllerId, status)); + return actionRepository.findAll(ActionSpecifications.byTargetControllerIdAndIsActiveAndStatus(controllerId, status)); } protected Action addActionStatus(final JpaActionStatusCreate statusCreate) { diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/management/JpaDistributionSetTypeManagement.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/management/JpaDistributionSetTypeManagement.java index fb9c42345..afc80f087 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/management/JpaDistributionSetTypeManagement.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/management/JpaDistributionSetTypeManagement.java @@ -64,20 +64,15 @@ import org.springframework.validation.annotation.Validated; public class JpaDistributionSetTypeManagement implements DistributionSetTypeManagement { private final DistributionSetTypeRepository distributionSetTypeRepository; - private final SoftwareModuleTypeRepository softwareModuleTypeRepository; - private final DistributionSetRepository distributionSetRepository; - private final TargetTypeRepository targetTypeRepository; - private final VirtualPropertyReplacer virtualPropertyReplacer; - private final Database database; - private final QuotaManagement quotaManagement; - public JpaDistributionSetTypeManagement(final DistributionSetTypeRepository distributionSetTypeRepository, + public JpaDistributionSetTypeManagement( + final DistributionSetTypeRepository distributionSetTypeRepository, final SoftwareModuleTypeRepository softwareModuleTypeRepository, final DistributionSetRepository distributionSetRepository, final TargetTypeRepository targetTypeRepository, final VirtualPropertyReplacer virtualPropertyReplacer, final Database database, diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/management/JpaSystemManagement.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/management/JpaSystemManagement.java index d66da34cb..b6d4ff47a 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/management/JpaSystemManagement.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/management/JpaSystemManagement.java @@ -24,7 +24,6 @@ import org.eclipse.hawkbit.repository.exception.EntityNotFoundException; import org.eclipse.hawkbit.repository.jpa.CurrentTenantCacheKeyGenerator; import org.eclipse.hawkbit.repository.jpa.SystemManagementCacheKeyGenerator; import org.eclipse.hawkbit.repository.jpa.configuration.Constants; -import org.eclipse.hawkbit.repository.jpa.configuration.MultiTenantJpaTransactionManager; import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSetType; import org.eclipse.hawkbit.repository.jpa.model.JpaSoftwareModuleType; import org.eclipse.hawkbit.repository.jpa.model.JpaTenantMetaData; @@ -141,16 +140,6 @@ public class JpaSystemManagement implements CurrentTenantCacheKeyGenerator, Syst return currentTenantCacheKeyGenerator.currentTenantKeyGenerator(); } - @Override - @Cacheable(value = "currentTenant", keyGenerator = "currentTenantKeyGenerator", cacheManager = "directCacheManager", unless = "#result == null") - public String currentTenant() { - return currentTenantCacheKeyGenerator.getTenantInCreation().orElseGet(() -> { - final TenantMetaData findByTenant = tenantMetaDataRepository - .findByTenantIgnoreCase(tenantAware.getCurrentTenant()); - return findByTenant != null ? findByTenant.getTenant() : null; - }); - } - @Override @Transactional @Retryable(retryFor = { ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX, @@ -295,6 +284,12 @@ public class JpaSystemManagement implements CurrentTenantCacheKeyGenerator, Syst .orElseThrow(() -> new EntityNotFoundException(TenantMetaData.class, tenantId)); } + @Override + @Cacheable(value = "currentTenant", keyGenerator = "currentTenantKeyGenerator", cacheManager = "directCacheManager", unless = "#result == null") + public boolean tenantExists(final String tenant) { + return tenantMetaDataRepository.findByTenantIgnoreCase(tenant) != null; + } + private static boolean isPostgreSql(final JpaProperties properties) { return Database.POSTGRESQL == properties.getDatabase(); } @@ -342,13 +337,13 @@ public class JpaSystemManagement implements CurrentTenantCacheKeyGenerator, Syst } /** - * Creating the initial tenant meta-data in a new transaction. Due the - * {@link MultiTenantJpaTransactionManager} is using the current tenant to + * Creating the initial tenant meta-data in a new transaction. Due to the + * {@link org.eclipse.hawkbit.repository.jpa.configuration.MultiTenantJpaTransactionManager} is using the current tenant to * set the necessary tenant discriminator to the query. This is not working - * if we don't have a current tenant set. Due the + * if we don't have a current tenant set. Due to the * {@link #createTenantMetadata(String)} is maybe called without having a * current tenant we need to re-open a new transaction so the - * {@link MultiTenantJpaTransactionManager} is called again and set the + * {@link org.eclipse.hawkbit.repository.jpa.configuration.MultiTenantJpaTransactionManager} is called again and set the * tenant for this transaction. * * @param tenant the tenant to be created diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/AbstractJpaTenantAwareBaseEntity.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/AbstractJpaTenantAwareBaseEntity.java index 940ce9712..f90646805 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/AbstractJpaTenantAwareBaseEntity.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/AbstractJpaTenantAwareBaseEntity.java @@ -28,6 +28,7 @@ import org.eclipse.hawkbit.repository.model.helper.SystemManagementHolder; import org.eclipse.persistence.annotations.Multitenant; import org.eclipse.persistence.annotations.MultitenantType; import org.eclipse.persistence.annotations.TenantDiscriminatorColumn; +import org.hibernate.annotations.TenantId; /** * Holder of the base attributes common to all tenant aware entities. @@ -88,11 +89,14 @@ public abstract class AbstractJpaTenantAwareBaseEntity extends AbstractJpaBaseEn /** * PrePersist listener method for all {@link TenantAwareBaseEntity} entities. + * + * // TODO - check if the tenant support should set tenant from context + * // TODO - should we check if tenant exists in the system? Note: seems it's not good to work with db in the listener */ @PrePersist void prePersist() { // before persisting the entity check the current ID of the tenant by using the TenantAware service - final String currentTenant = SystemManagementHolder.getInstance().currentTenant(); + final String currentTenant = TenantAwareHolder.getInstance().getTenantAware().getCurrentTenant(); if (currentTenant == null) { throw new TenantNotExistException( String.format( diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/repository/ActionRepository.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/repository/ActionRepository.java index 4e40cdb95..c29f9065e 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/repository/ActionRepository.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/repository/ActionRepository.java @@ -71,7 +71,7 @@ public interface ActionRepository extends BaseEntityRepository { */ @Modifying @Transactional - @Query("UPDATE JpaAction a SET a.status = :statusToSet WHERE a.target IN :targetsIds AND a.active = :active AND a.status = :currentStatus AND a.distributionSet.requiredMigrationStep = false") + @Query("UPDATE JpaAction a SET a.status = :statusToSet WHERE a.target.id IN :targetsIds AND a.active = :active AND a.status = :currentStatus AND a.distributionSet.requiredMigrationStep = false") void switchStatus(@Param("statusToSet") Action.Status statusToSet, @Param("targetsIds") List targetIds, @Param("active") boolean active, @Param("currentStatus") Action.Status currentStatus); diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/repository/BaseEntityRepository.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/repository/BaseEntityRepository.java index fedb9f7d8..cda97aeec 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/repository/BaseEntityRepository.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/repository/BaseEntityRepository.java @@ -16,6 +16,7 @@ import java.util.Optional; import jakarta.persistence.EntityManager; +import org.eclipse.hawkbit.repository.exception.EntityNotFoundException; import org.eclipse.hawkbit.repository.jpa.acm.AccessController; import org.eclipse.hawkbit.repository.jpa.model.AbstractJpaBaseEntity_; import org.eclipse.hawkbit.repository.jpa.model.AbstractJpaTenantAwareBaseEntity; @@ -65,6 +66,17 @@ public interface BaseEntityRepository findAll(); + /** + * Gets by id requiring entity to exists + * + * @param id the entity id + * @return the existing entity. + * @throws EntityNotFoundException if the entity doesn't exist + */ + default T getById(final Long id) { + return findById(id).orElseThrow(() -> new EntityNotFoundException(getDomainClass(), id)); + } + /** * Overrides * {@link org.springframework.data.repository.CrudRepository#findAllById(Iterable)} diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/management/ArtifactManagementTest.java b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/management/ArtifactManagementTest.java index cffe9392d..df97560ab 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/management/ArtifactManagementTest.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/management/ArtifactManagementTest.java @@ -67,9 +67,9 @@ import org.junit.jupiter.api.Test; public class ArtifactManagementTest extends AbstractJpaIntegrationTest { @Test - @Description("Verifies that management get access react as specfied on calls for non existing entities by means " - + "of Optional not present.") - @ExpectEvents({ @Expect(type = SoftwareModuleCreatedEvent.class, count = 1) }) + @Description("Verifies that management get access react as specfied on calls for non existing entities by means of Optional not present.") + @ExpectEvents({ + @Expect(type = SoftwareModuleCreatedEvent.class, count = 1) }) public void nonExistingEntityAccessReturnsNotPresent() { final SoftwareModule module = testdataFactory.createSoftwareModuleOs(); @@ -85,7 +85,8 @@ public class ArtifactManagementTest extends AbstractJpaIntegrationTest { @Test @Description("Verifies that management queries react as specfied on calls for non existing entities " + " by means of throwing EntityNotFoundException.") - @ExpectEvents({ @Expect(type = SoftwareModuleDeletedEvent.class, count = 0) }) + @ExpectEvents({ + @Expect(type = SoftwareModuleDeletedEvent.class, count = 0) }) public void entityQueriesReferringToNotExistingEntitiesThrowsException() throws URISyntaxException { final String artifactData = "test"; @@ -319,10 +320,9 @@ public class ArtifactManagementTest extends AbstractJpaIntegrationTest { } @Test - @Description("Test the deletion of an artifact metadata where the binary is still linked to another " - + "metadata element. The expected result is that the metadata is deleted but the binary kept.") + @Description("Test the deletion of an artifact metadata where the binary is still linked to another metadata element. " + + "The expected result is that the metadata is deleted but the binary kept.") public void deleteDuplicateArtifacts() throws IOException { - final JpaSoftwareModule sm = softwareModuleRepository .save(new JpaSoftwareModule(osType, "name 1", "version 1")); final JpaSoftwareModule sm2 = softwareModuleRepository @@ -334,29 +334,21 @@ public class ArtifactManagementTest extends AbstractJpaIntegrationTest { try (final InputStream inputStream1 = new ByteArrayInputStream(randomBytes); final InputStream inputStream2 = new ByteArrayInputStream(randomBytes)) { final Artifact artifact1 = createArtifactForSoftwareModule("file1", sm.getId(), artifactSize, inputStream1); - final Artifact artifact2 = createArtifactForSoftwareModule("file2", sm2.getId(), artifactSize, - inputStream2); + final Artifact artifact2 = createArtifactForSoftwareModule("file2", sm2.getId(), artifactSize, inputStream2); - assertThat(artifactRepository.findAll()).hasSize(2); assertThat(artifact1.getId()).isNotNull(); assertThat(artifact2.getId()).isNotNull(); - assertThat(((JpaArtifact) artifact1).getSha1Hash()).isEqualTo(((JpaArtifact) artifact2).getSha1Hash()); - - assertThat( - binaryArtifactRepository.getArtifactBySha1(tenantAware.getCurrentTenant(), artifact1.getSha1Hash())) - .isNotNull(); + assertThat((artifact1).getSha1Hash()).isEqualTo(artifact2.getSha1Hash()); + assertThat(artifactRepository.findAll()).hasSize(2); + assertThat(binaryArtifactRepository.getArtifactBySha1(tenantAware.getCurrentTenant(), artifact1.getSha1Hash())).isNotNull(); artifactManagement.delete(artifact1.getId()); - assertThat( - binaryArtifactRepository.getArtifactBySha1(tenantAware.getCurrentTenant(), artifact1.getSha1Hash())) - .isNotNull(); - assertThat(artifactRepository.findAll()).hasSize(1); assertThat(artifactRepository.existsById(artifact1.getId())).isFalse(); + assertThat(artifactRepository.findAll()).hasSize(1); + assertThat(binaryArtifactRepository.getArtifactBySha1(tenantAware.getCurrentTenant(), artifact1.getSha1Hash())).isNotNull(); artifactManagement.delete(artifact2.getId()); - assertThat( - binaryArtifactRepository.getArtifactBySha1(tenantAware.getCurrentTenant(), artifact1.getSha1Hash())) - .isNull(); + assertThat(binaryArtifactRepository.getArtifactBySha1(tenantAware.getCurrentTenant(), artifact1.getSha1Hash())).isNull(); assertThat(artifactRepository.findAll()).hasSize(0); } } @@ -435,8 +427,8 @@ public class ArtifactManagementTest extends AbstractJpaIntegrationTest { public void findArtifact() throws IOException { final int artifactSize = 5 * 1024; try (final InputStream inputStream = new RandomGeneratedInputStream(artifactSize)) { - final Artifact artifact = createArtifactForSoftwareModule("file1", - testdataFactory.createSoftwareModuleOs().getId(), artifactSize, inputStream); + final Artifact artifact = createArtifactForSoftwareModule( + "file1", testdataFactory.createSoftwareModuleOs().getId(), artifactSize, inputStream); assertThat(artifactManagement.get(artifact.getId()).get()).isEqualTo(artifact); } } diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/management/ControllerManagementTest.java b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/management/ControllerManagementTest.java index 77f175db5..dc0f39698 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/management/ControllerManagementTest.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/management/ControllerManagementTest.java @@ -68,6 +68,7 @@ import org.eclipse.hawkbit.repository.exception.EntityNotFoundException; import org.eclipse.hawkbit.repository.exception.InvalidTargetAttributeException; import org.eclipse.hawkbit.repository.jpa.AbstractJpaIntegrationTest; import org.eclipse.hawkbit.repository.jpa.model.JpaAction_; +import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSet; import org.eclipse.hawkbit.repository.jpa.model.JpaTarget; import org.eclipse.hawkbit.repository.jpa.repository.TargetRepository; import org.eclipse.hawkbit.repository.jpa.specifications.ActionSpecifications; @@ -101,7 +102,8 @@ class ControllerManagementTest extends AbstractJpaIntegrationTest { @Test @Description("Ensures that target attribute update fails if quota hits.") - @ExpectEvents({ @Expect(type = TargetCreatedEvent.class, count = 1), + @ExpectEvents({ + @Expect(type = TargetCreatedEvent.class, count = 1), @Expect(type = TargetUpdatedEvent.class, count = 2) }) public void updateTargetAttributesFailsIfTooManyEntries() throws Exception { final String controllerId = "test123"; @@ -165,12 +167,14 @@ class ControllerManagementTest extends AbstractJpaIntegrationTest { @Test @Description("Controller providing status entries fails if providing more than permitted by quota.") - @ExpectEvents({ @Expect(type = TargetCreatedEvent.class, count = 1), + @ExpectEvents({ + @Expect(type = TargetCreatedEvent.class, count = 1), @Expect(type = DistributionSetCreatedEvent.class, count = 1), @Expect(type = SoftwareModuleCreatedEvent.class, count = 3), @Expect(type = DistributionSetUpdatedEvent.class, count = 1), // implicit lock @Expect(type = SoftwareModuleUpdatedEvent.class, count = 3), // implicit lock - @Expect(type = ActionCreatedEvent.class, count = 1), @Expect(type = TargetUpdatedEvent.class, count = 1), + @Expect(type = ActionCreatedEvent.class, count = 1), + @Expect(type = TargetUpdatedEvent.class, count = 1), @Expect(type = TargetAssignDistributionSetEvent.class, count = 1) }) public void controllerProvidesIntermediateFeedbackFailsIfQuotaHit() { final int allowStatusEntries = 10; @@ -213,12 +217,14 @@ class ControllerManagementTest extends AbstractJpaIntegrationTest { @Test @Description("Verifies that the quota specifying the maximum number of status entries per action is enforced.") - @ExpectEvents({ @Expect(type = TargetCreatedEvent.class, count = 2), + @ExpectEvents({ + @Expect(type = TargetCreatedEvent.class, count = 2), @Expect(type = DistributionSetCreatedEvent.class, count = 2), @Expect(type = SoftwareModuleCreatedEvent.class, count = 6), @Expect(type = DistributionSetUpdatedEvent.class, count = 2), // implicit lock @Expect(type = SoftwareModuleUpdatedEvent.class, count = 6), // implicit lock - @Expect(type = ActionCreatedEvent.class, count = 2), @Expect(type = TargetUpdatedEvent.class, count = 2), + @Expect(type = ActionCreatedEvent.class, count = 2), + @Expect(type = TargetUpdatedEvent.class, count = 2), @Expect(type = TargetAssignDistributionSetEvent.class, count = 2) }) public void addActionStatusUpdatesUntilQuotaIsExceeded() { @@ -251,12 +257,14 @@ class ControllerManagementTest extends AbstractJpaIntegrationTest { @Test @Description("Verifies that the quota specifying the maximum number of messages per action status is enforced.") - @ExpectEvents({ @Expect(type = TargetCreatedEvent.class, count = 1), + @ExpectEvents({ + @Expect(type = TargetCreatedEvent.class, count = 1), @Expect(type = DistributionSetCreatedEvent.class, count = 1), @Expect(type = SoftwareModuleCreatedEvent.class, count = 3), @Expect(type = DistributionSetUpdatedEvent.class, count = 1), // implicit lock @Expect(type = SoftwareModuleUpdatedEvent.class, count = 3), // implicit lock - @Expect(type = ActionCreatedEvent.class, count = 1), @Expect(type = TargetUpdatedEvent.class, count = 1), + @Expect(type = ActionCreatedEvent.class, count = 1), + @Expect(type = TargetUpdatedEvent.class, count = 1), @Expect(type = TargetAssignDistributionSetEvent.class, count = 1) }) public void createActionStatusWithTooManyMessages() { @@ -281,12 +289,14 @@ class ControllerManagementTest extends AbstractJpaIntegrationTest { @Test @Description("Verifies that a DOWNLOAD_ONLY action is not marked complete when the controller reports DOWNLOAD") - @ExpectEvents({ @Expect(type = TargetCreatedEvent.class, count = 1), + @ExpectEvents({ + @Expect(type = TargetCreatedEvent.class, count = 1), @Expect(type = DistributionSetCreatedEvent.class, count = 1), @Expect(type = SoftwareModuleCreatedEvent.class, count = 3), @Expect(type = DistributionSetUpdatedEvent.class, count = 1), // implicit lock @Expect(type = SoftwareModuleUpdatedEvent.class, count = 3), // implicit lock - @Expect(type = ActionCreatedEvent.class, count = 1), @Expect(type = TargetUpdatedEvent.class, count = 1), + @Expect(type = ActionCreatedEvent.class, count = 1), + @Expect(type = TargetUpdatedEvent.class, count = 1), @Expect(type = TargetAssignDistributionSetEvent.class, count = 1) }) public void controllerReportsDownloadForDownloadOnlyAction() { testdataFactory.createTarget(); @@ -305,7 +315,8 @@ class ControllerManagementTest extends AbstractJpaIntegrationTest { @Test @Description("Verifies that management get access react as specified on calls for non existing entities by means " + "of Optional not present.") - @ExpectEvents({ @Expect(type = TargetCreatedEvent.class, count = 1), + @ExpectEvents({ + @Expect(type = TargetCreatedEvent.class, count = 1), @Expect(type = SoftwareModuleCreatedEvent.class, count = 1) }) void nonExistingEntityAccessReturnsNotPresent() { final Target target = testdataFactory.createTarget(); @@ -326,7 +337,8 @@ class ControllerManagementTest extends AbstractJpaIntegrationTest { @Test @Description("Verifies that management queries react as specified on calls for non existing entities " + " by means of throwing EntityNotFoundException.") - @ExpectEvents({ @Expect(type = TargetCreatedEvent.class, count = 1), + @ExpectEvents({ + @Expect(type = TargetCreatedEvent.class, count = 1), @Expect(type = SoftwareModuleCreatedEvent.class, count = 1) }) void entityQueriesReferringToNotExistingEntitiesThrowsException() throws URISyntaxException { final Target target = testdataFactory.createTarget(); @@ -362,12 +374,14 @@ class ControllerManagementTest extends AbstractJpaIntegrationTest { @Test @Description("Controller confirms successful update with FINISHED status.") - @ExpectEvents({ @Expect(type = TargetCreatedEvent.class, count = 1), + @ExpectEvents({ + @Expect(type = TargetCreatedEvent.class, count = 1), @Expect(type = DistributionSetCreatedEvent.class, count = 1), @Expect(type = SoftwareModuleCreatedEvent.class, count = 3), @Expect(type = DistributionSetUpdatedEvent.class, count = 1), // implicit lock @Expect(type = SoftwareModuleUpdatedEvent.class, count = 3), // implicit lock - @Expect(type = ActionCreatedEvent.class, count = 1), @Expect(type = ActionUpdatedEvent.class, count = 1), + @Expect(type = ActionCreatedEvent.class, count = 1), + @Expect(type = ActionUpdatedEvent.class, count = 1), @Expect(type = TargetUpdatedEvent.class, count = 2), @Expect(type = TargetAssignDistributionSetEvent.class, count = 1), @Expect(type = TargetAttributesRequestedEvent.class, count = 1) }) @@ -387,12 +401,14 @@ class ControllerManagementTest extends AbstractJpaIntegrationTest { @Test @Description("Controller confirmation fails with invalid messages.") - @ExpectEvents({ @Expect(type = TargetCreatedEvent.class, count = 1), + @ExpectEvents({ + @Expect(type = TargetCreatedEvent.class, count = 1), @Expect(type = DistributionSetCreatedEvent.class, count = 1), @Expect(type = SoftwareModuleCreatedEvent.class, count = 3), @Expect(type = DistributionSetUpdatedEvent.class, count = 1), // implicit lock @Expect(type = SoftwareModuleUpdatedEvent.class, count = 3), // implicit lock - @Expect(type = ActionCreatedEvent.class, count = 1), @Expect(type = TargetUpdatedEvent.class, count = 1), + @Expect(type = ActionCreatedEvent.class, count = 1), + @Expect(type = TargetUpdatedEvent.class, count = 1), @Expect(type = TargetAssignDistributionSetEvent.class, count = 1) }) void controllerConfirmationFailsWithInvalidMessages() { final Long actionId = createTargetAndAssignDs(); @@ -417,12 +433,14 @@ class ControllerManagementTest extends AbstractJpaIntegrationTest { @Test @Description("Controller confirms successful update with FINISHED status on a action that is on canceling. " + "Reason: The decision to ignore the cancellation is in fact up to the controller.") - @ExpectEvents({ @Expect(type = TargetCreatedEvent.class, count = 1), + @ExpectEvents({ + @Expect(type = TargetCreatedEvent.class, count = 1), @Expect(type = DistributionSetCreatedEvent.class, count = 1), @Expect(type = SoftwareModuleCreatedEvent.class, count = 3), @Expect(type = DistributionSetUpdatedEvent.class, count = 1), // implicit lock @Expect(type = SoftwareModuleUpdatedEvent.class, count = 3), // implicit lock - @Expect(type = ActionCreatedEvent.class, count = 1), @Expect(type = ActionUpdatedEvent.class, count = 2), + @Expect(type = ActionCreatedEvent.class, count = 1), + @Expect(type = ActionUpdatedEvent.class, count = 2), @Expect(type = CancelTargetAssignmentEvent.class, count = 1), @Expect(type = TargetUpdatedEvent.class, count = 2), @Expect(type = TargetAssignDistributionSetEvent.class, count = 1), @@ -442,12 +460,14 @@ class ControllerManagementTest extends AbstractJpaIntegrationTest { @Test @Description("Update server rejects cancellation feedback if action is not in CANCELING state.") - @ExpectEvents({ @Expect(type = TargetCreatedEvent.class, count = 1), + @ExpectEvents({ + @Expect(type = TargetCreatedEvent.class, count = 1), @Expect(type = DistributionSetCreatedEvent.class, count = 1), @Expect(type = SoftwareModuleCreatedEvent.class, count = 3), @Expect(type = DistributionSetUpdatedEvent.class, count = 1), // implicit lock @Expect(type = SoftwareModuleUpdatedEvent.class, count = 3), // implicit lock - @Expect(type = ActionCreatedEvent.class, count = 1), @Expect(type = TargetUpdatedEvent.class, count = 1), + @Expect(type = ActionCreatedEvent.class, count = 1), + @Expect(type = TargetUpdatedEvent.class, count = 1), @Expect(type = TargetAssignDistributionSetEvent.class, count = 1) }) void cancellationFeedbackRejectedIfActionIsNotInCanceling() { final Long actionId = createTargetAndAssignDs(); @@ -466,12 +486,14 @@ class ControllerManagementTest extends AbstractJpaIntegrationTest { @Test @Description("Controller confirms action cancellation with FINISHED status.") - @ExpectEvents({ @Expect(type = TargetCreatedEvent.class, count = 1), + @ExpectEvents({ + @Expect(type = TargetCreatedEvent.class, count = 1), @Expect(type = DistributionSetCreatedEvent.class, count = 1), @Expect(type = SoftwareModuleCreatedEvent.class, count = 3), @Expect(type = DistributionSetUpdatedEvent.class, count = 1), // implicit lock @Expect(type = SoftwareModuleUpdatedEvent.class, count = 3), // implicit lock - @Expect(type = ActionCreatedEvent.class, count = 1), @Expect(type = ActionUpdatedEvent.class, count = 2), + @Expect(type = ActionCreatedEvent.class, count = 1), + @Expect(type = ActionUpdatedEvent.class, count = 2), @Expect(type = TargetUpdatedEvent.class, count = 2), @Expect(type = CancelTargetAssignmentEvent.class, count = 1), @Expect(type = TargetAssignDistributionSetEvent.class, count = 1) }) @@ -495,12 +517,14 @@ class ControllerManagementTest extends AbstractJpaIntegrationTest { @Test @Description("Controller confirms action cancellation with FINISHED status.") - @ExpectEvents({ @Expect(type = TargetCreatedEvent.class, count = 1), + @ExpectEvents({ + @Expect(type = TargetCreatedEvent.class, count = 1), @Expect(type = DistributionSetCreatedEvent.class, count = 1), @Expect(type = SoftwareModuleCreatedEvent.class, count = 3), @Expect(type = DistributionSetUpdatedEvent.class, count = 1), // implicit lock @Expect(type = SoftwareModuleUpdatedEvent.class, count = 3), // implicit lock - @Expect(type = ActionCreatedEvent.class, count = 1), @Expect(type = ActionUpdatedEvent.class, count = 2), + @Expect(type = ActionCreatedEvent.class, count = 1), + @Expect(type = ActionUpdatedEvent.class, count = 2), @Expect(type = TargetUpdatedEvent.class, count = 2), @Expect(type = CancelTargetAssignmentEvent.class, count = 1), @Expect(type = TargetAssignDistributionSetEvent.class, count = 1) }) @@ -525,12 +549,14 @@ class ControllerManagementTest extends AbstractJpaIntegrationTest { @Test @Description("Controller rejects action cancellation with CANCEL_REJECTED status. Action goes back to RUNNING status as it expects " + "that the controller will continue the original update.") - @ExpectEvents({ @Expect(type = TargetCreatedEvent.class, count = 1), + @ExpectEvents({ + @Expect(type = TargetCreatedEvent.class, count = 1), @Expect(type = DistributionSetCreatedEvent.class, count = 1), @Expect(type = SoftwareModuleCreatedEvent.class, count = 3), @Expect(type = DistributionSetUpdatedEvent.class, count = 1), // implicit lock @Expect(type = SoftwareModuleUpdatedEvent.class, count = 3), // implicit lock - @Expect(type = ActionCreatedEvent.class, count = 1), @Expect(type = ActionUpdatedEvent.class, count = 2), + @Expect(type = ActionCreatedEvent.class, count = 1), + @Expect(type = ActionUpdatedEvent.class, count = 2), @Expect(type = TargetUpdatedEvent.class, count = 1), @Expect(type = CancelTargetAssignmentEvent.class, count = 1), @Expect(type = TargetAssignDistributionSetEvent.class, count = 1) }) @@ -555,12 +581,14 @@ class ControllerManagementTest extends AbstractJpaIntegrationTest { @Test @Description("Controller rejects action cancellation with ERROR status. Action goes back to RUNNING status as it expects " + "that the controller will continue the original update.") - @ExpectEvents({ @Expect(type = TargetCreatedEvent.class, count = 1), + @ExpectEvents({ + @Expect(type = TargetCreatedEvent.class, count = 1), @Expect(type = DistributionSetCreatedEvent.class, count = 1), @Expect(type = SoftwareModuleCreatedEvent.class, count = 3), @Expect(type = DistributionSetUpdatedEvent.class, count = 1), // implicit lock @Expect(type = SoftwareModuleUpdatedEvent.class, count = 3), // implicit lock - @Expect(type = ActionCreatedEvent.class, count = 1), @Expect(type = ActionUpdatedEvent.class, count = 2), + @Expect(type = ActionCreatedEvent.class, count = 1), + @Expect(type = ActionUpdatedEvent.class, count = 2), @Expect(type = TargetUpdatedEvent.class, count = 1), @Expect(type = CancelTargetAssignmentEvent.class, count = 1), @Expect(type = TargetAssignDistributionSetEvent.class, count = 1) }) @@ -585,12 +613,14 @@ class ControllerManagementTest extends AbstractJpaIntegrationTest { @Test @Description("Verifies that assignment verification works based on SHA1 hash. By design it is not important which artifact " + "is actually used for the check as long as they have an identical binary, i.e. same SHA1 hash. ") - @ExpectEvents({ @Expect(type = TargetCreatedEvent.class, count = 1), + @ExpectEvents({ + @Expect(type = TargetCreatedEvent.class, count = 1), @Expect(type = DistributionSetCreatedEvent.class, count = 2), @Expect(type = SoftwareModuleCreatedEvent.class, count = 6), @Expect(type = DistributionSetUpdatedEvent.class, count = 1), // implicit lock @Expect(type = SoftwareModuleUpdatedEvent.class, count = 5), // implicit lock - @Expect(type = ActionCreatedEvent.class, count = 1), @Expect(type = TargetUpdatedEvent.class, count = 1), + @Expect(type = ActionCreatedEvent.class, count = 1), + @Expect(type = TargetUpdatedEvent.class, count = 1), @Expect(type = TargetAssignDistributionSetEvent.class, count = 1) }) void hasTargetArtifactAssignedIsTrueWithMultipleArtifacts() { final int artifactSize = 5 * 1024; @@ -654,7 +684,8 @@ class ControllerManagementTest extends AbstractJpaIntegrationTest { @Test @Description("Register a controller which does not exist with existing target type and update its target type to another existing one") @WithUser(principal = "controller", authorities = { CONTROLLER_ROLE }) - @ExpectEvents({ @Expect(type = TargetTypeCreatedEvent.class, count = 2), + @ExpectEvents({ + @Expect(type = TargetTypeCreatedEvent.class, count = 2), @Expect(type = TargetCreatedEvent.class, count = 1), @Expect(type = TargetPollEvent.class, count = 2), @Expect(type = TargetUpdatedEvent.class, count = 1) }) @@ -676,7 +707,8 @@ class ControllerManagementTest extends AbstractJpaIntegrationTest { @Test @Description("Register a controller which does not exist with existing target type and update its target type to non existing one") @WithUser(principal = "controller", authorities = { CONTROLLER_ROLE }) - @ExpectEvents({ @Expect(type = TargetTypeCreatedEvent.class, count = 1), + @ExpectEvents({ + @Expect(type = TargetTypeCreatedEvent.class, count = 1), @Expect(type = TargetCreatedEvent.class, count = 1), @Expect(type = TargetPollEvent.class, count = 2) }) void findOrRegisterTargetIfItDoesNotExistWithExistingTypeAndUpdateToNonExistingType() { @@ -694,7 +726,8 @@ class ControllerManagementTest extends AbstractJpaIntegrationTest { @Test @Description("Register a controller which does not exist with existing target type and unassign its target type") @WithUser(principal = "controller", authorities = { CONTROLLER_ROLE }) - @ExpectEvents({ @Expect(type = TargetTypeCreatedEvent.class, count = 1), + @ExpectEvents({ + @Expect(type = TargetTypeCreatedEvent.class, count = 1), @Expect(type = TargetCreatedEvent.class, count = 1), @Expect(type = TargetPollEvent.class, count = 2), @Expect(type = TargetUpdatedEvent.class, count = 1) }) @@ -713,7 +746,8 @@ class ControllerManagementTest extends AbstractJpaIntegrationTest { @Test @Description("Register a controller which does not exist without target type and update its target type to existing one") @WithUser(principal = "controller", authorities = { CONTROLLER_ROLE }) - @ExpectEvents({ @Expect(type = TargetTypeCreatedEvent.class, count = 1), + @ExpectEvents({ + @Expect(type = TargetTypeCreatedEvent.class, count = 1), @Expect(type = TargetCreatedEvent.class, count = 1), @Expect(type = TargetPollEvent.class, count = 2), @Expect(type = TargetUpdatedEvent.class, count = 1) }) @@ -734,7 +768,8 @@ class ControllerManagementTest extends AbstractJpaIntegrationTest { @Test @Description("Register a controller which does not exist with non existing target type and update its target type to existing one") @WithUser(principal = "controller", authorities = { CONTROLLER_ROLE }) - @ExpectEvents({ @Expect(type = TargetTypeCreatedEvent.class, count = 1), + @ExpectEvents({ + @Expect(type = TargetTypeCreatedEvent.class, count = 1), @Expect(type = TargetCreatedEvent.class, count = 1), @Expect(type = TargetPollEvent.class, count = 2), @Expect(type = TargetUpdatedEvent.class, count = 1) }) @@ -796,7 +831,8 @@ class ControllerManagementTest extends AbstractJpaIntegrationTest { @Test @Description("Register a controller which does not exist, when a ConcurrencyFailureException is raised, the " + "exception is not rethrown when the max retries are not yet reached") - @ExpectEvents({ @Expect(type = TargetCreatedEvent.class, count = 1), + @ExpectEvents({ + @Expect(type = TargetCreatedEvent.class, count = 1), @Expect(type = TargetPollEvent.class, count = 1) }) void findOrRegisterTargetIfItDoesNotExistDoesNotThrowExceptionBeforeMaxRetries() { @@ -822,8 +858,10 @@ class ControllerManagementTest extends AbstractJpaIntegrationTest { @Test @Description("Register a controller which does not exist, then update the controller twice, first time by providing a name property and second time without a new name") - @ExpectEvents({ @Expect(type = TargetCreatedEvent.class, count = 1), - @Expect(type = TargetPollEvent.class, count = 3), @Expect(type = TargetUpdatedEvent.class, count = 1) }) + @ExpectEvents({ + @Expect(type = TargetCreatedEvent.class, count = 1), + @Expect(type = TargetPollEvent.class, count = 3), + @Expect(type = TargetUpdatedEvent.class, count = 1) }) void findOrRegisterTargetIfItDoesNotExistDoesUpdateNameOnExistingTargetProperly() { final String controllerId = "12345"; @@ -889,7 +927,8 @@ class ControllerManagementTest extends AbstractJpaIntegrationTest { @Test @Description("Verify that targetVisible metadata is returned from repository") - @ExpectEvents({ @Expect(type = DistributionSetCreatedEvent.class, count = 1), + @ExpectEvents({ + @Expect(type = DistributionSetCreatedEvent.class, count = 1), @Expect(type = SoftwareModuleCreatedEvent.class, count = 3), @Expect(type = SoftwareModuleUpdatedEvent.class, count = 6) }) void findTargetVisibleMetaDataBySoftwareModuleId() { @@ -906,7 +945,8 @@ class ControllerManagementTest extends AbstractJpaIntegrationTest { @Test @Description("Verify that controller registration does not result in a TargetPollEvent if feature is disabled") - @ExpectEvents({ @Expect(type = TargetCreatedEvent.class, count = 1), + @ExpectEvents({ + @Expect(type = TargetCreatedEvent.class, count = 1), @Expect(type = TargetPollEvent.class, count = 0) }) void targetPollEventNotSendIfDisabled() { repositoryProperties.setPublishTargetPollEvent(false); @@ -916,12 +956,14 @@ class ControllerManagementTest extends AbstractJpaIntegrationTest { @Test @Description("Controller tries to finish an update process after it has been finished by an error action status.") - @ExpectEvents({ @Expect(type = TargetCreatedEvent.class, count = 1), + @ExpectEvents({ + @Expect(type = TargetCreatedEvent.class, count = 1), @Expect(type = DistributionSetCreatedEvent.class, count = 1), @Expect(type = SoftwareModuleCreatedEvent.class, count = 3), @Expect(type = DistributionSetUpdatedEvent.class, count = 1), // implicit lock @Expect(type = SoftwareModuleUpdatedEvent.class, count = 3), // implicit lock - @Expect(type = ActionCreatedEvent.class, count = 1), @Expect(type = ActionUpdatedEvent.class, count = 1), + @Expect(type = ActionCreatedEvent.class, count = 1), + @Expect(type = ActionUpdatedEvent.class, count = 1), @Expect(type = TargetUpdatedEvent.class, count = 2), @Expect(type = TargetAssignDistributionSetEvent.class, count = 1) }) void tryToFinishWithErrorUpdateProcessMoreThanOnce() { @@ -964,12 +1006,14 @@ class ControllerManagementTest extends AbstractJpaIntegrationTest { @Test @Description("Controller tries to finish an update process after it has been finished by an FINISHED action status.") - @ExpectEvents({ @Expect(type = TargetCreatedEvent.class, count = 1), + @ExpectEvents({ + @Expect(type = TargetCreatedEvent.class, count = 1), @Expect(type = DistributionSetCreatedEvent.class, count = 1), @Expect(type = SoftwareModuleCreatedEvent.class, count = 3), @Expect(type = DistributionSetUpdatedEvent.class, count = 1), // implicit lock @Expect(type = SoftwareModuleUpdatedEvent.class, count = 3), // implicit lock - @Expect(type = ActionCreatedEvent.class, count = 1), @Expect(type = ActionUpdatedEvent.class, count = 1), + @Expect(type = ActionCreatedEvent.class, count = 1), + @Expect(type = ActionUpdatedEvent.class, count = 1), @Expect(type = TargetUpdatedEvent.class, count = 2), @Expect(type = TargetAssignDistributionSetEvent.class, count = 1), @Expect(type = TargetAttributesRequestedEvent.class, count = 1) }) @@ -1003,12 +1047,14 @@ class ControllerManagementTest extends AbstractJpaIntegrationTest { @Test @Description("Controller tries to send an update feedback after it has been finished which is reject as the repository is " + "configured to reject that.") - @ExpectEvents({ @Expect(type = TargetCreatedEvent.class, count = 1), + @ExpectEvents({ + @Expect(type = TargetCreatedEvent.class, count = 1), @Expect(type = DistributionSetCreatedEvent.class, count = 1), @Expect(type = SoftwareModuleCreatedEvent.class, count = 3), @Expect(type = DistributionSetUpdatedEvent.class, count = 1), // implicit lock @Expect(type = SoftwareModuleUpdatedEvent.class, count = 3), // implicit lock - @Expect(type = ActionCreatedEvent.class, count = 1), @Expect(type = ActionUpdatedEvent.class, count = 1), + @Expect(type = ActionCreatedEvent.class, count = 1), + @Expect(type = ActionUpdatedEvent.class, count = 1), @Expect(type = TargetUpdatedEvent.class, count = 2), @Expect(type = TargetAssignDistributionSetEvent.class, count = 1), @Expect(type = TargetAttributesRequestedEvent.class, count = 1) }) @@ -1034,7 +1080,8 @@ class ControllerManagementTest extends AbstractJpaIntegrationTest { @Test @Description("Controller tries to send an update feedback after it has been finished which is accepted as the repository is " + "configured to accept them.") - @ExpectEvents({ @Expect(type = TargetCreatedEvent.class, count = 1), + @ExpectEvents({ + @Expect(type = TargetCreatedEvent.class, count = 1), @Expect(type = DistributionSetCreatedEvent.class, count = 1), @Expect(type = SoftwareModuleCreatedEvent.class, count = 3), @Expect(type = DistributionSetUpdatedEvent.class, count = 1), // implicit lock @@ -1063,7 +1110,8 @@ class ControllerManagementTest extends AbstractJpaIntegrationTest { @Test @Description("Ensures that target attribute update is reflected by the repository.") - @ExpectEvents({ @Expect(type = TargetCreatedEvent.class, count = 1), + @ExpectEvents({ + @Expect(type = TargetCreatedEvent.class, count = 1), @Expect(type = TargetUpdatedEvent.class, count = 3) }) void updateTargetAttributes() throws Exception { final String controllerId = "test123"; @@ -1110,12 +1158,14 @@ class ControllerManagementTest extends AbstractJpaIntegrationTest { @Test @Description("Verifies that a DOWNLOAD_ONLY action is marked complete once the controller reports DOWNLOADED") - @ExpectEvents({ @Expect(type = TargetCreatedEvent.class, count = 1), + @ExpectEvents({ + @Expect(type = TargetCreatedEvent.class, count = 1), @Expect(type = DistributionSetCreatedEvent.class, count = 1), @Expect(type = SoftwareModuleCreatedEvent.class, count = 3), @Expect(type = DistributionSetUpdatedEvent.class, count = 1), // implicit lock @Expect(type = SoftwareModuleUpdatedEvent.class, count = 3), // implicit lock - @Expect(type = ActionCreatedEvent.class, count = 1), @Expect(type = TargetUpdatedEvent.class, count = 2), + @Expect(type = ActionCreatedEvent.class, count = 1), + @Expect(type = TargetUpdatedEvent.class, count = 2), @Expect(type = TargetAttributesRequestedEvent.class, count = 1), @Expect(type = ActionUpdatedEvent.class, count = 1), @Expect(type = TargetAssignDistributionSetEvent.class, count = 1) }) @@ -1123,10 +1173,9 @@ class ControllerManagementTest extends AbstractJpaIntegrationTest { testdataFactory.createTarget(); final Long actionId = createAndAssignDsAsDownloadOnly("downloadOnlyDs", DEFAULT_CONTROLLER_ID); assertThat(actionId).isNotNull(); - controllerManagement - .addUpdateActionStatus(entityFactory.actionStatus().create(actionId).status(Status.DOWNLOADED)); - assertActionStatus(actionId, DEFAULT_CONTROLLER_ID, TargetUpdateStatus.IN_SYNC, Action.Status.DOWNLOADED, - Action.Status.DOWNLOADED, false); + controllerManagement.addUpdateActionStatus(entityFactory.actionStatus().create(actionId).status(Status.DOWNLOADED)); + assertActionStatus( + actionId, DEFAULT_CONTROLLER_ID, TargetUpdateStatus.IN_SYNC, Action.Status.DOWNLOADED, Action.Status.DOWNLOADED, false); assertThat(actionStatusRepository.count()).isEqualTo(2); assertThat(controllerManagement.findActionStatusByAction(PAGE, actionId).getNumberOfElements()).isEqualTo(2); @@ -1135,12 +1184,14 @@ class ControllerManagementTest extends AbstractJpaIntegrationTest { @Test @Description("Verifies that a controller can report a FINISHED event for a DOWNLOAD_ONLY non-active action.") - @ExpectEvents({ @Expect(type = TargetCreatedEvent.class, count = 1), + @ExpectEvents({ + @Expect(type = TargetCreatedEvent.class, count = 1), @Expect(type = DistributionSetCreatedEvent.class, count = 1), @Expect(type = SoftwareModuleCreatedEvent.class, count = 3), @Expect(type = DistributionSetUpdatedEvent.class, count = 1), // implicit lock @Expect(type = SoftwareModuleUpdatedEvent.class, count = 3), // implicit lock - @Expect(type = ActionCreatedEvent.class, count = 1), @Expect(type = TargetUpdatedEvent.class, count = 3), + @Expect(type = ActionCreatedEvent.class, count = 1), + @Expect(type = TargetUpdatedEvent.class, count = 3), @Expect(type = TargetAttributesRequestedEvent.class, count = 2), @Expect(type = ActionUpdatedEvent.class, count = 2), @Expect(type = TargetAssignDistributionSetEvent.class, count = 1) }) @@ -1160,7 +1211,8 @@ class ControllerManagementTest extends AbstractJpaIntegrationTest { @Test @Description("Verifies that multiple DOWNLOADED events for a DOWNLOAD_ONLY action are handled.") - @ExpectEvents({ @Expect(type = TargetCreatedEvent.class, count = 1), + @ExpectEvents({ + @Expect(type = TargetCreatedEvent.class, count = 1), @Expect(type = DistributionSetCreatedEvent.class, count = 1), @Expect(type = SoftwareModuleCreatedEvent.class, count = 3), @Expect(type = DistributionSetUpdatedEvent.class, count = 1), // implicit lock @@ -1188,12 +1240,14 @@ class ControllerManagementTest extends AbstractJpaIntegrationTest { @Test @Description("Verifies that quota is asserted when a controller reports too many DOWNLOADED events for a " + "DOWNLOAD_ONLY action.") - @ExpectEvents({ @Expect(type = TargetCreatedEvent.class, count = 1), + @ExpectEvents({ + @Expect(type = TargetCreatedEvent.class, count = 1), @Expect(type = DistributionSetCreatedEvent.class, count = 1), @Expect(type = SoftwareModuleCreatedEvent.class, count = 3), @Expect(type = DistributionSetUpdatedEvent.class, count = 1), // implicit lock @Expect(type = SoftwareModuleUpdatedEvent.class, count = 3), // implicit lock - @Expect(type = ActionCreatedEvent.class, count = 1), @Expect(type = TargetUpdatedEvent.class, count = 2), + @Expect(type = ActionCreatedEvent.class, count = 1), + @Expect(type = TargetUpdatedEvent.class, count = 2), @Expect(type = TargetAssignDistributionSetEvent.class, count = 1), @Expect(type = TargetAttributesRequestedEvent.class, count = 9), @Expect(type = ActionUpdatedEvent.class, count = 1) }) @@ -1210,12 +1264,14 @@ class ControllerManagementTest extends AbstractJpaIntegrationTest { @Test @Description("Verifies that quota is enforced for UpdateActionStatus events for DOWNLOAD_ONLY assignments.") - @ExpectEvents({ @Expect(type = TargetCreatedEvent.class, count = 1), + @ExpectEvents({ + @Expect(type = TargetCreatedEvent.class, count = 1), @Expect(type = DistributionSetCreatedEvent.class, count = 1), @Expect(type = SoftwareModuleCreatedEvent.class, count = 3), @Expect(type = DistributionSetUpdatedEvent.class, count = 1), // implicit lock @Expect(type = SoftwareModuleUpdatedEvent.class, count = 3), // implicit lock - @Expect(type = ActionCreatedEvent.class, count = 1), @Expect(type = TargetUpdatedEvent.class, count = 3), + @Expect(type = ActionCreatedEvent.class, count = 1), + @Expect(type = TargetUpdatedEvent.class, count = 3), @Expect(type = TargetAttributesRequestedEvent.class, count = 10), @Expect(type = ActionUpdatedEvent.class, count = 2), @Expect(type = TargetAssignDistributionSetEvent.class, count = 1) }) @@ -1254,7 +1310,8 @@ class ControllerManagementTest extends AbstractJpaIntegrationTest { @Test @Description("Verifies that quota is enforced for UpdateActionStatus events for FORCED assignments.") - @ExpectEvents({ @Expect(type = TargetCreatedEvent.class, count = 1), + @ExpectEvents({ + @Expect(type = TargetCreatedEvent.class, count = 1), @Expect(type = DistributionSetCreatedEvent.class, count = 1), @Expect(type = SoftwareModuleCreatedEvent.class, count = 3), @Expect(type = DistributionSetUpdatedEvent.class, count = 1), // implicit lock @@ -1352,7 +1409,8 @@ class ControllerManagementTest extends AbstractJpaIntegrationTest { @Test @Description("Verify that assigning version form target works") - @ExpectEvents({ @Expect(type = TargetCreatedEvent.class, count = 1), + @ExpectEvents({ + @Expect(type = TargetCreatedEvent.class, count = 1), @Expect(type = DistributionSetCreatedEvent.class, count = 1), @Expect(type = TargetUpdatedEvent.class, count = 1), @Expect(type = DistributionSetUpdatedEvent.class, count = 1), @@ -1392,12 +1450,14 @@ class ControllerManagementTest extends AbstractJpaIntegrationTest { @Test @Description("Verifies that a target can report FINISHED/ERROR updates for DOWNLOAD_ONLY assignments regardless of " + "repositoryProperties.rejectActionStatusForClosedAction value.") - @ExpectEvents({ @Expect(type = TargetCreatedEvent.class, count = 1), + @ExpectEvents({ + @Expect(type = TargetCreatedEvent.class, count = 1), @Expect(type = DistributionSetCreatedEvent.class, count = 4), @Expect(type = SoftwareModuleCreatedEvent.class, count = 12), @Expect(type = DistributionSetUpdatedEvent.class, count = 4), // implicit lock @Expect(type = SoftwareModuleUpdatedEvent.class, count = 12), // implicit lock - @Expect(type = ActionCreatedEvent.class, count = 4), @Expect(type = TargetUpdatedEvent.class, count = 12), + @Expect(type = ActionCreatedEvent.class, count = 4), + @Expect(type = TargetUpdatedEvent.class, count = 12), @Expect(type = TargetAssignDistributionSetEvent.class, count = 4), @Expect(type = TargetAttributesRequestedEvent.class, count = 6), @Expect(type = ActionUpdatedEvent.class, count = 8) }) @@ -1435,12 +1495,14 @@ class ControllerManagementTest extends AbstractJpaIntegrationTest { @Test @Description("Verifies that a controller can report a FINISHED event for a DOWNLOAD_ONLY action after having" + " installed an intermediate update.") - @ExpectEvents({ @Expect(type = TargetCreatedEvent.class, count = 1), + @ExpectEvents({ + @Expect(type = TargetCreatedEvent.class, count = 1), @Expect(type = DistributionSetCreatedEvent.class, count = 2), @Expect(type = SoftwareModuleCreatedEvent.class, count = 6), @Expect(type = DistributionSetUpdatedEvent.class, count = 2), // implicit lock @Expect(type = SoftwareModuleUpdatedEvent.class, count = 6), // implicit lock - @Expect(type = ActionCreatedEvent.class, count = 2), @Expect(type = TargetUpdatedEvent.class, count = 5), + @Expect(type = ActionCreatedEvent.class, count = 2), + @Expect(type = TargetUpdatedEvent.class, count = 5), @Expect(type = TargetAttributesRequestedEvent.class, count = 3), @Expect(type = ActionUpdatedEvent.class, count = 3), @Expect(type = TargetAssignDistributionSetEvent.class, count = 2) }) @@ -1506,8 +1568,10 @@ class ControllerManagementTest extends AbstractJpaIntegrationTest { @Test @Description("Delete a target on requested target deletion from client side") - @ExpectEvents({ @Expect(type = TargetCreatedEvent.class, count = 1), - @Expect(type = TargetPollEvent.class, count = 1), @Expect(type = TargetDeletedEvent.class, count = 1) }) + @ExpectEvents({ + @Expect(type = TargetCreatedEvent.class, count = 1), + @Expect(type = TargetPollEvent.class, count = 1), + @Expect(type = TargetDeletedEvent.class, count = 1) }) void deleteTargetWithValidThingId() { final Target target = controllerManagement.findOrRegisterTargetIfItDoesNotExist("AA", LOCALHOST); assertThat(target).as("target should not be null").isNotNull(); @@ -1520,7 +1584,8 @@ class ControllerManagementTest extends AbstractJpaIntegrationTest { @Test @Description("Delete a target with a non existing thingId") - @ExpectEvents({ @Expect(type = TargetDeletedEvent.class, count = 0) }) + @ExpectEvents({ + @Expect(type = TargetDeletedEvent.class, count = 0) }) void deleteTargetWithInvalidThingId() { assertThatExceptionOfType(EntityNotFoundException.class) .as("No EntityNotFoundException thrown when deleting a non-existing target") @@ -1530,8 +1595,10 @@ class ControllerManagementTest extends AbstractJpaIntegrationTest { @Test @Description("Delete a target after it has been deleted already") - @ExpectEvents({ @Expect(type = TargetCreatedEvent.class, count = 1), - @Expect(type = TargetPollEvent.class, count = 1), @Expect(type = TargetDeletedEvent.class, count = 1) }) + @ExpectEvents({ + @Expect(type = TargetCreatedEvent.class, count = 1), + @Expect(type = TargetPollEvent.class, count = 1), + @Expect(type = TargetDeletedEvent.class, count = 1) }) void deleteTargetAfterItWasDeleted() { final Target target = controllerManagement.findOrRegisterTargetIfItDoesNotExist("AA", LOCALHOST); assertThat(target).as("target should not be null").isNotNull(); @@ -1574,13 +1641,12 @@ class ControllerManagementTest extends AbstractJpaIntegrationTest { @Step private Long createAndAssignDsAsDownloadOnly(final String dsName, final String defaultControllerId) { - final Long dsId = testdataFactory.createDistributionSet(dsName).getId(); + final DistributionSet ds = testdataFactory.createDistributionSet(dsName); + final Long dsId = ds.getId(); assignDistributionSet(dsId, defaultControllerId, DOWNLOAD_ONLY); - assertThat(targetManagement.getByControllerID(defaultControllerId).get().getUpdateStatus()) - .isEqualTo(TargetUpdateStatus.PENDING); + assertThat(targetManagement.getByControllerID(defaultControllerId).get().getUpdateStatus()).isEqualTo(TargetUpdateStatus.PENDING); - final Long id = deploymentManagement.findActiveActionsByTarget(PAGE, defaultControllerId).getContent().get(0) - .getId(); + final Long id = deploymentManagement.findActiveActionsByTarget(PAGE, defaultControllerId).getContent().get(0).getId(); assertThat(id).isNotNull(); return id; } diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/management/DeploymentManagementTest.java b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/management/DeploymentManagementTest.java index 153002013..6e2a3b8a8 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/management/DeploymentManagementTest.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/management/DeploymentManagementTest.java @@ -146,7 +146,8 @@ class DeploymentManagementTest extends AbstractJpaIntegrationTest { @Test @Description("Verifies that management get access react as specified on calls for non existing entities by means " + "of Optional not present.") - @ExpectEvents({ @Expect(type = TargetCreatedEvent.class, count = 0) }) + @ExpectEvents({ + @Expect(type = TargetCreatedEvent.class, count = 0) }) void nonExistingEntityAccessReturnsNotPresent() { assertThat(deploymentManagement.findAction(1234L)).isNotPresent(); assertThat(deploymentManagement.findActionWithDetails(NOT_EXIST_IDL)).isNotPresent(); @@ -155,7 +156,8 @@ class DeploymentManagementTest extends AbstractJpaIntegrationTest { @Test @Description("Verifies that management queries react as specified on calls for non existing entities " + " by means of throwing EntityNotFoundException.") - @ExpectEvents({ @Expect(type = TargetCreatedEvent.class, count = 1) }) + @ExpectEvents({ + @Expect(type = TargetCreatedEvent.class, count = 1) }) void entityQueriesReferringToNotExistingEntitiesThrowsException() { final Target target = testdataFactory.createTarget(); final String dsName = "DistributionSet"; @@ -307,7 +309,8 @@ class DeploymentManagementTest extends AbstractJpaIntegrationTest { @Test @Description("Test verifies that an assignment with automatic cancelation works correctly even if the update is split into multiple partitions on the database.") - @ExpectEvents({ @Expect(type = TargetCreatedEvent.class, count = 20), + @ExpectEvents({ + @Expect(type = TargetCreatedEvent.class, count = 20), @Expect(type = TargetUpdatedEvent.class, count = 40), @Expect(type = TargetAssignDistributionSetEvent.class, count = 2), @Expect(type = ActionCreatedEvent.class, count = 40), @@ -491,8 +494,10 @@ class DeploymentManagementTest extends AbstractJpaIntegrationTest { @Test @Description("Simple offline deployment of a distribution set to a list of targets. Verifies that offline assigment " + "is correctly executed for targets that do not have a running update already. Those are ignored.") - @ExpectEvents({ @Expect(type = TargetCreatedEvent.class, count = 20), - @Expect(type = TargetUpdatedEvent.class, count = 20), @Expect(type = ActionCreatedEvent.class, count = 20), + @ExpectEvents({ + @Expect(type = TargetCreatedEvent.class, count = 20), + @Expect(type = TargetUpdatedEvent.class, count = 20), + @Expect(type = ActionCreatedEvent.class, count = 20), @Expect(type = DistributionSetCreatedEvent.class, count = 2), @Expect(type = SoftwareModuleCreatedEvent.class, count = 6), @Expect(type = DistributionSetUpdatedEvent.class, count = 2), // implicit lock @@ -535,8 +540,10 @@ class DeploymentManagementTest extends AbstractJpaIntegrationTest { @Test @Description("Offline assign multiple DSs to a single Target in multiassignment mode.") - @ExpectEvents({ @Expect(type = TargetCreatedEvent.class, count = 1), - @Expect(type = TargetUpdatedEvent.class, count = 4), @Expect(type = ActionCreatedEvent.class, count = 4), + @ExpectEvents({ + @Expect(type = TargetCreatedEvent.class, count = 1), + @Expect(type = TargetUpdatedEvent.class, count = 4), + @Expect(type = ActionCreatedEvent.class, count = 4), @Expect(type = DistributionSetCreatedEvent.class, count = 4), @Expect(type = SoftwareModuleCreatedEvent.class, count = 12), @Expect(type = DistributionSetUpdatedEvent.class, count = 4), // implicit lock @@ -571,8 +578,10 @@ class DeploymentManagementTest extends AbstractJpaIntegrationTest { @Test @Description("Verifies that if an account is set to action autoclose running actions in case of a new assigned set get closed and set to CANCELED.") - @ExpectEvents({ @Expect(type = TargetCreatedEvent.class, count = 10), - @Expect(type = TargetUpdatedEvent.class, count = 20), @Expect(type = ActionCreatedEvent.class, count = 20), + @ExpectEvents({ + @Expect(type = TargetCreatedEvent.class, count = 10), + @Expect(type = TargetUpdatedEvent.class, count = 20), + @Expect(type = ActionCreatedEvent.class, count = 20), @Expect(type = ActionUpdatedEvent.class, count = 10), @Expect(type = DistributionSetCreatedEvent.class, count = 2), @Expect(type = SoftwareModuleCreatedEvent.class, count = 6), @@ -612,8 +621,10 @@ class DeploymentManagementTest extends AbstractJpaIntegrationTest { @Test @Description("If multi-assignment is enabled, verify that the previous Distribution Set assignment is not canceled when a new one is assigned.") - @ExpectEvents({ @Expect(type = TargetCreatedEvent.class, count = 10), - @Expect(type = TargetUpdatedEvent.class, count = 20), @Expect(type = ActionCreatedEvent.class, count = 20), + @ExpectEvents({ + @Expect(type = TargetCreatedEvent.class, count = 10), + @Expect(type = TargetUpdatedEvent.class, count = 20), + @Expect(type = ActionCreatedEvent.class, count = 20), @Expect(type = DistributionSetCreatedEvent.class, count = 2), @Expect(type = SoftwareModuleCreatedEvent.class, count = 6), @Expect(type = DistributionSetUpdatedEvent.class, count = 2), // implicit lock @@ -643,8 +654,10 @@ class DeploymentManagementTest extends AbstractJpaIntegrationTest { @Test @Description("Assign multiple DSs to a single Target in one request in multiassignment mode.") - @ExpectEvents({ @Expect(type = TargetCreatedEvent.class, count = 1), - @Expect(type = TargetUpdatedEvent.class, count = 4), @Expect(type = ActionCreatedEvent.class, count = 4), + @ExpectEvents({ + @Expect(type = TargetCreatedEvent.class, count = 1), + @Expect(type = TargetUpdatedEvent.class, count = 4), + @Expect(type = ActionCreatedEvent.class, count = 4), @Expect(type = DistributionSetCreatedEvent.class, count = 4), @Expect(type = SoftwareModuleCreatedEvent.class, count = 12), @Expect(type = DistributionSetUpdatedEvent.class, count = 4), // implicit lock @@ -679,8 +692,10 @@ class DeploymentManagementTest extends AbstractJpaIntegrationTest { @Test @Description("Assign multiple DSs to single Target in one request in multiAssignment mode and cancel each created action afterwards.") - @ExpectEvents({ @Expect(type = TargetCreatedEvent.class, count = 1), - @Expect(type = TargetUpdatedEvent.class, count = 4), @Expect(type = ActionCreatedEvent.class, count = 4), + @ExpectEvents({ + @Expect(type = TargetCreatedEvent.class, count = 1), + @Expect(type = TargetUpdatedEvent.class, count = 4), + @Expect(type = ActionCreatedEvent.class, count = 4), @Expect(type = DistributionSetCreatedEvent.class, count = 4), @Expect(type = SoftwareModuleCreatedEvent.class, count = 12), @Expect(type = DistributionSetUpdatedEvent.class, count = 4), // implicit lock @@ -900,13 +915,15 @@ class DeploymentManagementTest extends AbstractJpaIntegrationTest { @Test @Description("Duplicate Assignments are removed from a request when multiassignment is disabled, otherwise not") - @ExpectEvents({ @Expect(type = TargetCreatedEvent.class, count = 1), + @ExpectEvents({ + @Expect(type = TargetCreatedEvent.class, count = 1), @Expect(type = DistributionSetCreatedEvent.class, count = 1), @Expect(type = SoftwareModuleCreatedEvent.class, count = 3), @Expect(type = DistributionSetUpdatedEvent.class, count = 1), // implicit lock @Expect(type = SoftwareModuleUpdatedEvent.class, count = 3), // implicit lock @Expect(type = TargetAssignDistributionSetEvent.class, count = 1), - @Expect(type = ActionCreatedEvent.class, count = 2), @Expect(type = TargetUpdatedEvent.class, count = 2), + @Expect(type = ActionCreatedEvent.class, count = 2), + @Expect(type = TargetUpdatedEvent.class, count = 2), @Expect(type = MultiActionAssignEvent.class, count = 1), @Expect(type = TenantConfigurationCreatedEvent.class, count = 1) }) void duplicateAssignmentsInRequestAreRemovedIfMultiassignmentEnabled() { @@ -928,7 +945,8 @@ class DeploymentManagementTest extends AbstractJpaIntegrationTest { @Test @Description("An assignment request is not accepted if it would lead to a target exceeding the max actions per target quota.") - @ExpectEvents({ @Expect(type = TargetCreatedEvent.class, count = 1), + @ExpectEvents({ + @Expect(type = TargetCreatedEvent.class, count = 1), @Expect(type = DistributionSetCreatedEvent.class, count = 21), // max actions per target are 20 for test @Expect(type = SoftwareModuleCreatedEvent.class, count = 3 * 21), @Expect(type = TargetAssignDistributionSetEvent.class, count = 0), @@ -980,12 +998,14 @@ class DeploymentManagementTest extends AbstractJpaIntegrationTest { @Test @Description("Weights are validated and contained in the resulting Action.") - @ExpectEvents({ @Expect(type = TargetCreatedEvent.class, count = 1), + @ExpectEvents({ + @Expect(type = TargetCreatedEvent.class, count = 1), @Expect(type = DistributionSetCreatedEvent.class, count = 1), @Expect(type = SoftwareModuleCreatedEvent.class, count = 3), @Expect(type = DistributionSetUpdatedEvent.class, count = 1), // implicit lock @Expect(type = SoftwareModuleUpdatedEvent.class, count = 3), // implicit lock - @Expect(type = ActionCreatedEvent.class, count = 2), @Expect(type = TargetUpdatedEvent.class, count = 2), + @Expect(type = ActionCreatedEvent.class, count = 2), + @Expect(type = TargetUpdatedEvent.class, count = 2), @Expect(type = MultiActionAssignEvent.class, count = 2), @Expect(type = TenantConfigurationCreatedEvent.class, count = 1) }) void weightValidatedAndSaved() { @@ -1019,12 +1039,14 @@ class DeploymentManagementTest extends AbstractJpaIntegrationTest { */ @Test @Description("Simple deployment or distribution set to target assignment test.") - @ExpectEvents({ @Expect(type = TargetAssignDistributionSetEvent.class, count = 1), + @ExpectEvents({ + @Expect(type = TargetAssignDistributionSetEvent.class, count = 1), @Expect(type = DistributionSetCreatedEvent.class, count = 1), @Expect(type = SoftwareModuleCreatedEvent.class, count = 3), @Expect(type = DistributionSetUpdatedEvent.class, count = 1), // implicit lock @Expect(type = SoftwareModuleUpdatedEvent.class, count = 3), // implicit lock - @Expect(type = TargetCreatedEvent.class, count = 30), @Expect(type = ActionCreatedEvent.class, count = 20), + @Expect(type = TargetCreatedEvent.class, count = 30), + @Expect(type = ActionCreatedEvent.class, count = 20), @Expect(type = TargetUpdatedEvent.class, count = 20) }) void assignDistributionSet2Targets() { @@ -1078,12 +1100,14 @@ class DeploymentManagementTest extends AbstractJpaIntegrationTest { @Test @Description("Test that it is not possible to assign a distribution set that is not complete.") - @ExpectEvents({ @Expect(type = TargetAssignDistributionSetEvent.class, count = 1), + @ExpectEvents({ + @Expect(type = TargetAssignDistributionSetEvent.class, count = 1), @Expect(type = DistributionSetCreatedEvent.class, count = 1), @Expect(type = SoftwareModuleCreatedEvent.class, count = 2), @Expect(type = DistributionSetUpdatedEvent.class, count = 2), // implicit lock @Expect(type = SoftwareModuleUpdatedEvent.class, count = 2), // implicit lock - @Expect(type = TargetCreatedEvent.class, count = 10), @Expect(type = ActionCreatedEvent.class, count = 10), + @Expect(type = TargetCreatedEvent.class, count = 10), + @Expect(type = ActionCreatedEvent.class, count = 10), @Expect(type = TargetUpdatedEvent.class, count = 10) }) void failDistributionSetAssigmentThatIsNotComplete() throws InterruptedException { final List targets = testdataFactory.createTargets(10); @@ -1108,7 +1132,8 @@ class DeploymentManagementTest extends AbstractJpaIntegrationTest { @Test @Description("Multiple deployments or distribution set to target assignment test. Expected behaviour is that a new deployment " + "overides unfinished old one which are canceled as part of the operation.") - @ExpectEvents({ @Expect(type = TargetCreatedEvent.class, count = 5 + 4), + @ExpectEvents({ + @Expect(type = TargetCreatedEvent.class, count = 5 + 4), @Expect(type = TargetUpdatedEvent.class, count = 3 * 4), @Expect(type = ActionCreatedEvent.class, count = 3 * 4), @Expect(type = ActionUpdatedEvent.class, count = 4 * 2), diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/management/DistributionSetManagementTest.java b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/management/DistributionSetManagementTest.java index b485464af..27925b7b6 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/management/DistributionSetManagementTest.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/management/DistributionSetManagementTest.java @@ -92,7 +92,8 @@ class DistributionSetManagementTest extends AbstractJpaIntegrationTest { @Test @Description("Verifies that management get access react as specified on calls for non existing entities by means " + "of Optional not present.") - @ExpectEvents({ @Expect(type = DistributionSetCreatedEvent.class, count = 1), + @ExpectEvents({ + @Expect(type = DistributionSetCreatedEvent.class, count = 1), @Expect(type = SoftwareModuleCreatedEvent.class, count = 3) }) void nonExistingEntityAccessReturnsNotPresent() { final DistributionSet set = testdataFactory.createDistributionSet(); @@ -105,7 +106,8 @@ class DistributionSetManagementTest extends AbstractJpaIntegrationTest { @Test @Description("Verifies that management queries react as specfied on calls for non existing entities " + " by means of throwing EntityNotFoundException.") - @ExpectEvents({ @Expect(type = DistributionSetCreatedEvent.class, count = 1), + @ExpectEvents({ + @Expect(type = DistributionSetCreatedEvent.class, count = 1), @Expect(type = DistributionSetTagCreatedEvent.class, count = 1), @Expect(type = SoftwareModuleCreatedEvent.class, count = 4) }) void entityQueriesReferringToNotExistingEntitiesThrowsException() { @@ -202,7 +204,8 @@ class DistributionSetManagementTest extends AbstractJpaIntegrationTest { @Test @Description("Verify that a DistributionSet with invalid properties cannot be created or updated") - @ExpectEvents({ @Expect(type = DistributionSetCreatedEvent.class, count = 1), + @ExpectEvents({ + @Expect(type = DistributionSetCreatedEvent.class, count = 1), @Expect(type = SoftwareModuleCreatedEvent.class, count = 3), @Expect(type = DistributionSetUpdatedEvent.class) }) void createAndUpdateDistributionSetWithInvalidFields() { @@ -941,7 +944,8 @@ class DistributionSetManagementTest extends AbstractJpaIntegrationTest { @Test @Description("Verify that the find all by ids contains the entities which are looking for") - @ExpectEvents({ @Expect(type = DistributionSetCreatedEvent.class, count = 12), + @ExpectEvents({ + @Expect(type = DistributionSetCreatedEvent.class, count = 12), @Expect(type = SoftwareModuleCreatedEvent.class, count = 36) }) void verifyFindDistributionSetAllById() { final List searchIds = new ArrayList<>(); diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/management/DistributionSetTagManagementTest.java b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/management/DistributionSetTagManagementTest.java index 3cef72444..0f036abb9 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/management/DistributionSetTagManagementTest.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/management/DistributionSetTagManagementTest.java @@ -54,7 +54,8 @@ class DistributionSetTagManagementTest extends AbstractJpaIntegrationTest { @Test @Description("Verifies that management get access reacts as specified on calls for non existing entities by means of Optional not present.") - @ExpectEvents({ @Expect(type = TargetCreatedEvent.class, count = 0) }) + @ExpectEvents({ + @Expect(type = TargetCreatedEvent.class, count = 0) }) void nonExistingEntityAccessReturnsNotPresent() { assertThat(distributionSetTagManagement.getByName(NOT_EXIST_ID)).isNotPresent(); assertThat(distributionSetTagManagement.get(NOT_EXIST_IDL)).isNotPresent(); diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/management/DistributionSetTypeManagementTest.java b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/management/DistributionSetTypeManagementTest.java index 868bcb0dd..7f10ba7b7 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/management/DistributionSetTypeManagementTest.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/management/DistributionSetTypeManagementTest.java @@ -55,7 +55,8 @@ public class DistributionSetTypeManagementTest extends AbstractJpaIntegrationTes @Test @Description("Verifies that management get access react as specfied on calls for non existing entities by means " + "of Optional not present.") - @ExpectEvents({ @Expect(type = DistributionSetCreatedEvent.class, count = 0) }) + @ExpectEvents({ + @Expect(type = DistributionSetCreatedEvent.class, count = 0) }) public void nonExistingEntityAccessReturnsNotPresent() { assertThat(distributionSetTypeManagement.get(NOT_EXIST_IDL)).isNotPresent(); assertThat(distributionSetTypeManagement.getByKey(NOT_EXIST_ID)).isNotPresent(); @@ -65,7 +66,8 @@ public class DistributionSetTypeManagementTest extends AbstractJpaIntegrationTes @Test @Description("Verifies that management queries react as specfied on calls for non existing entities " + " by means of throwing EntityNotFoundException.") - @ExpectEvents({ @Expect(type = DistributionSetCreatedEvent.class, count = 0), + @ExpectEvents({ + @Expect(type = DistributionSetCreatedEvent.class, count = 0), @Expect(type = DistributionSetTypeCreatedEvent.class, count = 1) }) public void entityQueriesReferringToNotExistingEntitiesThrowsException() { @@ -93,7 +95,8 @@ public class DistributionSetTypeManagementTest extends AbstractJpaIntegrationTes @Test @Description("Verify that a DistributionSet with invalid properties cannot be created or updated") - @ExpectEvents({ @Expect(type = DistributionSetCreatedEvent.class, count = 1), + @ExpectEvents({ + @Expect(type = DistributionSetCreatedEvent.class, count = 1), @Expect(type = SoftwareModuleCreatedEvent.class, count = 3), @Expect(type = DistributionSetUpdatedEvent.class, count = 0) }) public void createAndUpdateDistributionSetWithInvalidFields() { diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/management/LazyControllerManagementTest.java b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/management/LazyControllerManagementTest.java index 582ddfcab..11e6d7915 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/management/LazyControllerManagementTest.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/management/LazyControllerManagementTest.java @@ -39,7 +39,8 @@ public class LazyControllerManagementTest extends AbstractJpaIntegrationTest { @Test @Description("Verfies that lazy target poll update is executed as specified.") - @ExpectEvents({ @Expect(type = TargetCreatedEvent.class, count = 1), + @ExpectEvents({ + @Expect(type = TargetCreatedEvent.class, count = 1), @Expect(type = TargetPollEvent.class, count = 2) }) public void lazyFindOrRegisterTargetIfItDoesNotexist() throws InterruptedException { final Target target = controllerManagement.findOrRegisterTargetIfItDoesNotExist("AA", LOCALHOST); diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/management/RolloutGroupManagementTest.java b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/management/RolloutGroupManagementTest.java index 99cc22953..da65b5830 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/management/RolloutGroupManagementTest.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/management/RolloutGroupManagementTest.java @@ -49,7 +49,8 @@ class RolloutGroupManagementTest extends AbstractJpaIntegrationTest { @Test @Description("Verifies that management get access reacts as specified on calls for non existing entities by means " + "of Optional not present.") - @ExpectEvents({ @Expect(type = TargetCreatedEvent.class, count = 0) }) + @ExpectEvents({ + @Expect(type = TargetCreatedEvent.class, count = 0) }) void nonExistingEntityAccessReturnsNotPresent() { assertThat(rolloutGroupManagement.get(NOT_EXIST_IDL)).isNotPresent(); assertThat(rolloutGroupManagement.getWithDetailedStatus(NOT_EXIST_IDL)).isNotPresent(); @@ -58,7 +59,8 @@ class RolloutGroupManagementTest extends AbstractJpaIntegrationTest { @Test @Description("Verifies that management queries react as specified on calls for non existing entities " + " by means of throwing EntityNotFoundException.") - @ExpectEvents({ @Expect(type = RolloutDeletedEvent.class, count = 0), + @ExpectEvents({ + @Expect(type = RolloutDeletedEvent.class, count = 0), @Expect(type = RolloutGroupCreatedEvent.class, count = 5), @Expect(type = RolloutGroupUpdatedEvent.class, count = 5), @Expect(type = DistributionSetCreatedEvent.class, count = 1), diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/management/RolloutManagementTest.java b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/management/RolloutManagementTest.java index e946efb1c..4f92f5171 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/management/RolloutManagementTest.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/management/RolloutManagementTest.java @@ -283,7 +283,8 @@ class RolloutManagementTest extends AbstractJpaIntegrationTest { @Test @Description("Verifies that management get access reacts as specified on calls for non existing entities by means " + "of Optional not present.") - @ExpectEvents({ @Expect(type = TargetCreatedEvent.class) }) + @ExpectEvents({ + @Expect(type = TargetCreatedEvent.class) }) void nonExistingEntityAccessReturnsNotPresent() { assertThat(rolloutManagement.get(NOT_EXIST_IDL)).isNotPresent(); assertThat(rolloutManagement.getByName(NOT_EXIST_ID)).isNotPresent(); @@ -293,14 +294,16 @@ class RolloutManagementTest extends AbstractJpaIntegrationTest { @Test @Description("Verifies that management queries react as specified on calls for non existing entities " + " by means of throwing EntityNotFoundException.") - @ExpectEvents({ @Expect(type = RolloutDeletedEvent.class, count = 0), + @ExpectEvents({ + @Expect(type = RolloutDeletedEvent.class, count = 0), @Expect(type = RolloutGroupCreatedEvent.class, count = 5), @Expect(type = RolloutGroupUpdatedEvent.class, count = 5), @Expect(type = DistributionSetCreatedEvent.class, count = 1), @Expect(type = SoftwareModuleCreatedEvent.class, count = 3), @Expect(type = DistributionSetUpdatedEvent.class, count = 1), // implicit lock @Expect(type = SoftwareModuleUpdatedEvent.class, count = 3), // implicit lock - @Expect(type = RolloutCreatedEvent.class, count = 1), @Expect(type = RolloutUpdatedEvent.class, count = 1), + @Expect(type = RolloutCreatedEvent.class, count = 1), + @Expect(type = RolloutUpdatedEvent.class, count = 1), @Expect(type = TargetCreatedEvent.class, count = 125) }) void entityQueriesReferringToNotExistingEntitiesThrowsException() { testdataFactory.createRollout("xxx"); @@ -1766,8 +1769,10 @@ class RolloutManagementTest extends AbstractJpaIntegrationTest { } @Test - @ExpectEvents({ @Expect(type = RolloutDeletedEvent.class, count = 1), - @Expect(type = TargetCreatedEvent.class, count = 25), @Expect(type = RolloutUpdatedEvent.class, count = 2), + @ExpectEvents({ + @Expect(type = RolloutDeletedEvent.class, count = 1), + @Expect(type = TargetCreatedEvent.class, count = 25), + @Expect(type = RolloutUpdatedEvent.class, count = 2), @Expect(type = RolloutGroupCreatedEvent.class, count = 5), @Expect(type = RolloutGroupDeletedEvent.class, count = 5), @Expect(type = DistributionSetCreatedEvent.class, count = 1), @@ -1798,16 +1803,19 @@ class RolloutManagementTest extends AbstractJpaIntegrationTest { } @Test - @ExpectEvents({ @Expect(type = SoftwareModuleCreatedEvent.class, count = 3), + @ExpectEvents({ + @Expect(type = SoftwareModuleCreatedEvent.class, count = 3), @Expect(type = RolloutGroupUpdatedEvent.class, count = 10), @Expect(type = RolloutUpdatedEvent.class, count = 6), @Expect(type = DistributionSetCreatedEvent.class, count = 1), @Expect(type = DistributionSetUpdatedEvent.class, count = 1), // implicit lock @Expect(type = SoftwareModuleUpdatedEvent.class, count = 3), // implicit lock - @Expect(type = TargetCreatedEvent.class, count = 25), @Expect(type = TargetUpdatedEvent.class, count = 2), + @Expect(type = TargetCreatedEvent.class, count = 25), + @Expect(type = TargetUpdatedEvent.class, count = 2), @Expect(type = TargetAssignDistributionSetEvent.class, count = 1), @Expect(type = RolloutGroupCreatedEvent.class, count = 5), - @Expect(type = ActionCreatedEvent.class, count = 10), @Expect(type = ActionUpdatedEvent.class, count = 2), + @Expect(type = ActionCreatedEvent.class, count = 10), + @Expect(type = ActionUpdatedEvent.class, count = 2), @Expect(type = RolloutDeletedEvent.class, count = 1), @Expect(type = RolloutCreatedEvent.class, count = 1) }) void deleteRolloutWhichHasBeenStartedBeforeIsSoftDeleted() { diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/management/SoftwareModuleManagementTest.java b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/management/SoftwareModuleManagementTest.java index 6b0ab0240..2b2e278a7 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/management/SoftwareModuleManagementTest.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/management/SoftwareModuleManagementTest.java @@ -62,7 +62,8 @@ public class SoftwareModuleManagementTest extends AbstractJpaIntegrationTest { @Test @Description("Verifies that management get access reacts as specified on calls for non existing entities by means " + "of Optional not present.") - @ExpectEvents({ @Expect(type = SoftwareModuleCreatedEvent.class, count = 1) }) + @ExpectEvents({ + @Expect(type = SoftwareModuleCreatedEvent.class, count = 1) }) public void nonExistingEntityAccessReturnsNotPresent() { final SoftwareModule module = testdataFactory.createSoftwareModuleApp(); @@ -77,7 +78,8 @@ public class SoftwareModuleManagementTest extends AbstractJpaIntegrationTest { @Test @Description("Verifies that management queries react as specfied on calls for non existing entities " + " by means of throwing EntityNotFoundException.") - @ExpectEvents({ @Expect(type = SoftwareModuleCreatedEvent.class, count = 1) }) + @ExpectEvents({ + @Expect(type = SoftwareModuleCreatedEvent.class, count = 1) }) public void entityQueriesReferringToNotExistingEntitiesThrowsException() { final SoftwareModule module = testdataFactory.createSoftwareModuleApp(); diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/management/SoftwareModuleTypeManagementTest.java b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/management/SoftwareModuleTypeManagementTest.java index 78759980c..0c817ac5d 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/management/SoftwareModuleTypeManagementTest.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/management/SoftwareModuleTypeManagementTest.java @@ -37,7 +37,8 @@ public class SoftwareModuleTypeManagementTest extends AbstractJpaIntegrationTest @Test @Description("Verifies that management get access reacts as specfied on calls for non existing entities by means " + "of Optional not present.") - @ExpectEvents({ @Expect(type = SoftwareModuleCreatedEvent.class, count = 0) }) + @ExpectEvents({ + @Expect(type = SoftwareModuleCreatedEvent.class, count = 0) }) public void nonExistingEntityAccessReturnsNotPresent() { assertThat(softwareModuleTypeManagement.get(NOT_EXIST_IDL)).isNotPresent(); @@ -48,7 +49,8 @@ public class SoftwareModuleTypeManagementTest extends AbstractJpaIntegrationTest @Test @Description("Verifies that management queries react as specfied on calls for non existing entities " + " by means of throwing EntityNotFoundException.") - @ExpectEvents({ @Expect(type = SoftwareModuleCreatedEvent.class, count = 0) }) + @ExpectEvents({ + @Expect(type = SoftwareModuleCreatedEvent.class, count = 0) }) public void entityQueriesReferringToNotExistingEntitiesThrowsException() { verifyThrownExceptionBy(() -> softwareModuleTypeManagement.delete(NOT_EXIST_IDL), "SoftwareModuleType"); diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/management/SystemManagementTest.java b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/management/SystemManagementTest.java index 85721f819..583f3c5b8 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/management/SystemManagementTest.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/management/SystemManagementTest.java @@ -68,13 +68,13 @@ public class SystemManagementTest extends AbstractJpaIntegrationTest { // per tenant data final List tenants = systemManagement.getSystemUsageStatisticsWithTenants().getTenants(); assertThat(tenants).hasSize(3); - final TenantUsage tenantUsage0 = new TenantUsage("tenant0"); + final TenantUsage tenantUsage0 = new TenantUsage("TENANT0"); tenantUsage0.setArtifacts(1); tenantUsage0.setOverallArtifactVolumeInBytes(1234); - final TenantUsage tenantUsage1 = new TenantUsage("tenant1"); + final TenantUsage tenantUsage1 = new TenantUsage("TENANT1"); tenantUsage1.setArtifacts(1); tenantUsage1.setOverallArtifactVolumeInBytes(1234); - assertThat(tenants).containsOnly(new TenantUsage("default"), + assertThat(tenants).containsOnly(new TenantUsage("DEFAULT"), tenantUsage0, tenantUsage1); } @@ -92,13 +92,11 @@ public class SystemManagementTest extends AbstractJpaIntegrationTest { // per tenant data final List tenants = systemManagement.getSystemUsageStatisticsWithTenants().getTenants(); assertThat(tenants).hasSize(3); - final TenantUsage tenantUsage0 = new TenantUsage("tenant0"); + final TenantUsage tenantUsage0 = new TenantUsage("TENANT0"); tenantUsage0.setTargets(100); - final TenantUsage tenantUsage1 = new TenantUsage("tenant1"); + final TenantUsage tenantUsage1 = new TenantUsage("TENANT1"); tenantUsage1.setTargets(100); - assertThat(tenants).containsOnly(new TenantUsage("default"), - tenantUsage0, - tenantUsage1); + assertThat(tenants).containsOnly(new TenantUsage("DEFAULT"), tenantUsage0, tenantUsage1); } @Test @@ -113,15 +111,13 @@ public class SystemManagementTest extends AbstractJpaIntegrationTest { // per tenant data final List tenants = systemManagement.getSystemUsageStatisticsWithTenants().getTenants(); assertThat(tenants).hasSize(3); - final TenantUsage tenantUsage0 = new TenantUsage("tenant0"); + final TenantUsage tenantUsage0 = new TenantUsage("TENANT0"); tenantUsage0.setTargets(20); tenantUsage0.setActions(40); - final TenantUsage tenantUsage1 = new TenantUsage("tenant1"); + final TenantUsage tenantUsage1 = new TenantUsage("TENANT1"); tenantUsage1.setTargets(20); tenantUsage1.setActions(40); - assertThat(tenants).containsOnly(new TenantUsage("default"), - tenantUsage0, - tenantUsage1); + assertThat(tenants).containsOnly(new TenantUsage("DEFAULT"), tenantUsage0, tenantUsage1); } private byte[] createTestTenantsForSystemStatistics(final int tenants, final int artifactSize, final int targets, @@ -131,7 +127,7 @@ public class SystemManagementTest extends AbstractJpaIntegrationTest { randomgen.nextBytes(random); for (int i = 0; i < tenants; i++) { - final String tenantname = "tenant" + i; + final String tenantname = "TENANT" + i; SecurityContextSwitch.runAs(SecurityContextSwitch.withUserAndTenant("bumlux", tenantname, true, true, false, SpringEvalExpressions.SYSTEM_ROLE), () -> { systemManagement.getTenantMetadata(); @@ -171,9 +167,9 @@ public class SystemManagementTest extends AbstractJpaIntegrationTest { private void createDeletedTestArtifact(final byte[] random) { final DistributionSet ds = testdataFactory.createDistributionSet("deleted garbage", true); - ds.getModules().stream().forEach(module -> { - artifactManagement.create(new ArtifactUpload(new ByteArrayInputStream(random), module.getId(), "file1", - false, random.length)); + ds.getModules().forEach(module -> { + artifactManagement.create( + new ArtifactUpload(new ByteArrayInputStream(random), module.getId(), "file1", false, random.length)); softwareModuleManagement.delete(module.getId()); }); } diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/management/TargetFilterQueryManagementTest.java b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/management/TargetFilterQueryManagementTest.java index 4c67c6732..a83fea042 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/management/TargetFilterQueryManagementTest.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/management/TargetFilterQueryManagementTest.java @@ -66,7 +66,8 @@ public class TargetFilterQueryManagementTest extends AbstractJpaIntegrationTest @Test @Description("Verifies that management get access reacts as specfied on calls for non existing entities by means " + "of Optional not present.") - @ExpectEvents({ @Expect(type = TargetCreatedEvent.class, count = 0) }) + @ExpectEvents({ + @Expect(type = TargetCreatedEvent.class, count = 0) }) public void nonExistingEntityAccessReturnsNotPresent() { assertThat(targetFilterQueryManagement.get(NOT_EXIST_IDL)).isNotPresent(); assertThat(targetFilterQueryManagement.getByName(NOT_EXIST_ID)).isNotPresent(); @@ -75,7 +76,8 @@ public class TargetFilterQueryManagementTest extends AbstractJpaIntegrationTest @Test @Description("Verifies that management queries react as specfied on calls for non existing entities " + " by means of throwing EntityNotFoundException.") - @ExpectEvents({ @Expect(type = DistributionSetCreatedEvent.class, count = 1), + @ExpectEvents({ + @Expect(type = DistributionSetCreatedEvent.class, count = 1), @Expect(type = SoftwareModuleCreatedEvent.class, count = 3), @Expect(type = TargetFilterQueryCreatedEvent.class, count = 1) }) public void entityQueriesReferringToNotExistingEntitiesThrowsException() { diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/management/TargetManagementTest.java b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/management/TargetManagementTest.java index 252d3faaa..15b9192a9 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/management/TargetManagementTest.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/management/TargetManagementTest.java @@ -96,7 +96,8 @@ class TargetManagementTest extends AbstractJpaIntegrationTest { @Test @Description("Verifies that management get access react as specified on calls for non existing entities by means " + "of Optional not present.") - @ExpectEvents({ @Expect(type = TargetCreatedEvent.class, count = 1) }) + @ExpectEvents({ + @Expect(type = TargetCreatedEvent.class, count = 1) }) void nonExistingEntityAccessReturnsNotPresent() { final Target target = testdataFactory.createTarget(); assertThat(targetManagement.getByControllerID(NOT_EXIST_ID)).isNotPresent(); @@ -107,7 +108,8 @@ class TargetManagementTest extends AbstractJpaIntegrationTest { @Test @Description("Verifies that management queries react as specified on calls for non existing entities " + " by means of throwing EntityNotFoundException.") - @ExpectEvents({ @Expect(type = TargetCreatedEvent.class, count = 1), + @ExpectEvents({ + @Expect(type = TargetCreatedEvent.class, count = 1), @Expect(type = TargetTagCreatedEvent.class, count = 1) }) void entityQueriesReferringToNotExistingEntitiesThrowsException() { final TargetTag tag = targetTagManagement.create(entityFactory.tag().create().name("A")); @@ -182,7 +184,8 @@ class TargetManagementTest extends AbstractJpaIntegrationTest { @Test @Description("Ensures that retrieving the target security is only permitted with the necessary permissions.") - @ExpectEvents({ @Expect(type = TargetCreatedEvent.class, count = 1) }) + @ExpectEvents({ + @Expect(type = TargetCreatedEvent.class, count = 1) }) void getTargetSecurityTokenOnlyWithCorrectPermission() throws Exception { final Target createdTarget = targetManagement .create(entityFactory.target().create().controllerId("targetWithSecurityToken").securityToken("token")); @@ -216,22 +219,10 @@ class TargetManagementTest extends AbstractJpaIntegrationTest { assertThat(securityTokenWithoutPermission).isNull(); } - @Test - @Description("Ensures that targets cannot be created e.g. in plug'n play scenarios when tenant does not exists.") - @WithUser(tenantId = "tenantWhichDoesNotExists", allSpPermissions = true, autoCreateTenant = false) - @ExpectEvents({ @Expect(type = TargetCreatedEvent.class) }) - void createTargetForTenantWhichDoesNotExistThrowsTenantNotExistException() { - try { - targetManagement.create(entityFactory.target().create().controllerId("targetId123")); - fail("should not be possible as the tenant does not exist"); - } catch (final TenantNotExistException e) { - // ok - } - } - @Test @Description("Verify that a target with same controller ID than another device cannot be created.") - @ExpectEvents({ @Expect(type = TargetCreatedEvent.class, count = 1) }) + @ExpectEvents({ + @Expect(type = TargetCreatedEvent.class, count = 1) }) void createTargetThatViolatesUniqueConstraintFails() { targetManagement.create(entityFactory.target().create().controllerId("123")); @@ -241,7 +232,9 @@ class TargetManagementTest extends AbstractJpaIntegrationTest { @Test @Description("Verify that a target with with invalid properties cannot be created or updated") - @ExpectEvents({ @Expect(type = TargetCreatedEvent.class, count = 1), @Expect(type = TargetUpdatedEvent.class) }) + @ExpectEvents({ + @Expect(type = TargetCreatedEvent.class, count = 1), + @Expect(type = TargetUpdatedEvent.class) }) void createAndUpdateTargetWithInvalidFields() { final Target target = testdataFactory.createTarget(); @@ -254,7 +247,8 @@ class TargetManagementTest extends AbstractJpaIntegrationTest { @Test @Description("Ensures that targets can assigned and unassigned to a target tag. Not exists target will be ignored for the assignment.") - @ExpectEvents({ @Expect(type = TargetCreatedEvent.class, count = 4), + @ExpectEvents({ + @Expect(type = TargetCreatedEvent.class, count = 4), @Expect(type = TargetTagCreatedEvent.class, count = 1), @Expect(type = TargetUpdatedEvent.class, count = 5) }) void assignAndUnassignTargetsToTag() { @@ -294,8 +288,10 @@ class TargetManagementTest extends AbstractJpaIntegrationTest { @Test @Description("Ensures that targets can deleted e.g. test all cascades") - @ExpectEvents({ @Expect(type = TargetCreatedEvent.class, count = 12), - @Expect(type = TargetDeletedEvent.class, count = 12), @Expect(type = TargetUpdatedEvent.class, count = 6) }) + @ExpectEvents({ + @Expect(type = TargetCreatedEvent.class, count = 12), + @Expect(type = TargetDeletedEvent.class, count = 12), + @Expect(type = TargetUpdatedEvent.class, count = 6) }) void deleteAndCreateTargets() { Target target = targetManagement.create(entityFactory.target().create().controllerId("targetId123")); assertThat(targetManagement.count()).as("target count is wrong").isEqualTo(1); @@ -322,12 +318,15 @@ class TargetManagementTest extends AbstractJpaIntegrationTest { @Test @Description("Finds a target by given ID and checks if all data is in the response (including the data defined as lazy).") - @ExpectEvents({ @Expect(type = DistributionSetCreatedEvent.class, count = 2), + @ExpectEvents({ + @Expect(type = DistributionSetCreatedEvent.class, count = 2), @Expect(type = SoftwareModuleCreatedEvent.class, count = 6), @Expect(type = DistributionSetUpdatedEvent.class, count = 2), // implicit lock @Expect(type = SoftwareModuleUpdatedEvent.class, count = 6), // implicit lock - @Expect(type = TargetCreatedEvent.class, count = 1), @Expect(type = TargetUpdatedEvent.class, count = 5), - @Expect(type = ActionCreatedEvent.class, count = 2), @Expect(type = ActionUpdatedEvent.class, count = 1), + @Expect(type = TargetCreatedEvent.class, count = 1), + @Expect(type = TargetUpdatedEvent.class, count = 5), + @Expect(type = ActionCreatedEvent.class, count = 2), + @Expect(type = ActionUpdatedEvent.class, count = 1), @Expect(type = TargetAssignDistributionSetEvent.class, count = 2), @Expect(type = TargetAttributesRequestedEvent.class, count = 1), @Expect(type = TargetPollEvent.class, count = 1) }) @@ -389,7 +388,8 @@ class TargetManagementTest extends AbstractJpaIntegrationTest { @Test @Description("Checks if the EntityAlreadyExistsException is thrown if the targets with the same controller ID are created twice.") - @ExpectEvents({ @Expect(type = TargetCreatedEvent.class, count = 5) }) + @ExpectEvents({ + @Expect(type = TargetCreatedEvent.class, count = 5) }) void createMultipleTargetsDuplicate() { testdataFactory.createTargets(5, "mySimpleTargs", "my simple targets"); try { @@ -402,7 +402,8 @@ class TargetManagementTest extends AbstractJpaIntegrationTest { @Test @Description("Checks if the EntityAlreadyExistsException is thrown if a single target with the same controller ID are created twice.") - @ExpectEvents({ @Expect(type = TargetCreatedEvent.class, count = 1) }) + @ExpectEvents({ + @Expect(type = TargetCreatedEvent.class, count = 1) }) void createTargetDuplicate() { targetManagement.create(entityFactory.target().create().controllerId("4711")); try { @@ -415,7 +416,8 @@ class TargetManagementTest extends AbstractJpaIntegrationTest { @Test @WithUser(allSpPermissions = true) @Description("Creates and updates a target and verifies the changes in the repository.") - @ExpectEvents({ @Expect(type = TargetCreatedEvent.class, count = 1), + @ExpectEvents({ + @Expect(type = TargetCreatedEvent.class, count = 1), @Expect(type = TargetUpdatedEvent.class, count = 1) }) void singleTargetIsInsertedIntoRepo() throws Exception { @@ -452,7 +454,8 @@ class TargetManagementTest extends AbstractJpaIntegrationTest { @Test @WithUser(allSpPermissions = true) @Description("Create multiple targets as bulk operation and delete them in bulk.") - @ExpectEvents({ @Expect(type = TargetCreatedEvent.class, count = 101), + @ExpectEvents({ + @Expect(type = TargetCreatedEvent.class, count = 101), @Expect(type = TargetUpdatedEvent.class, count = 100), @Expect(type = TargetDeletedEvent.class, count = 51) }) void bulkTargetCreationAndDelete() { @@ -518,7 +521,8 @@ class TargetManagementTest extends AbstractJpaIntegrationTest { @Test @Description("Tests the assignment of tags to the a single target.") - @ExpectEvents({ @Expect(type = TargetCreatedEvent.class, count = 2), + @ExpectEvents({ + @Expect(type = TargetCreatedEvent.class, count = 2), @Expect(type = TargetTagCreatedEvent.class, count = 7), @Expect(type = TargetUpdatedEvent.class, count = 7) }) void targetTagAssignment() { @@ -550,7 +554,8 @@ class TargetManagementTest extends AbstractJpaIntegrationTest { @Test @Description("Tests the assignment of tags to multiple targets.") - @ExpectEvents({ @Expect(type = TargetCreatedEvent.class, count = 50), + @ExpectEvents({ + @Expect(type = TargetCreatedEvent.class, count = 50), @Expect(type = TargetTagCreatedEvent.class, count = 4), @Expect(type = TargetUpdatedEvent.class, count = 80) }) void targetTagBulkAssignments() { @@ -619,7 +624,8 @@ class TargetManagementTest extends AbstractJpaIntegrationTest { @Test @Description("Tests the unassigment of tags to multiple targets.") - @ExpectEvents({ @Expect(type = TargetTagCreatedEvent.class, count = 3), + @ExpectEvents({ + @Expect(type = TargetTagCreatedEvent.class, count = 3), @Expect(type = TargetCreatedEvent.class, count = 109), @Expect(type = TargetUpdatedEvent.class, count = 227) }) void targetTagBulkUnassignments() { @@ -677,7 +683,8 @@ class TargetManagementTest extends AbstractJpaIntegrationTest { @Test @Description("Test that NO TAG functionality which gives all targets with no tag assigned.") - @ExpectEvents({ @Expect(type = TargetTagCreatedEvent.class, count = 1), + @ExpectEvents({ + @Expect(type = TargetTagCreatedEvent.class, count = 1), @Expect(type = TargetCreatedEvent.class, count = 50), @Expect(type = TargetUpdatedEvent.class, count = 25) }) void findTargetsWithNoTag() { @@ -698,7 +705,8 @@ class TargetManagementTest extends AbstractJpaIntegrationTest { @Test @Description("Tests the a target can be read with only the read target permission") - @ExpectEvents({ @Expect(type = TargetCreatedEvent.class, count = 1), + @ExpectEvents({ + @Expect(type = TargetCreatedEvent.class, count = 1), @Expect(type = TargetPollEvent.class, count = 1) }) void targetCanBeReadWithOnlyReadTargetPermission() throws Exception { final String knownTargetControllerId = "readTarget"; @@ -735,7 +743,8 @@ class TargetManagementTest extends AbstractJpaIntegrationTest { @Test @Description("Verify that the find all targets by ids method contains the entities that we are looking for") - @ExpectEvents({ @Expect(type = TargetCreatedEvent.class, count = 12) }) + @ExpectEvents({ + @Expect(type = TargetCreatedEvent.class, count = 12) }) void verifyFindTargetAllById() { final List searchIds = Arrays.asList(testdataFactory.createTarget("target-4").getId(), testdataFactory.createTarget("target-5").getId(), testdataFactory.createTarget("target-6").getId()); @@ -933,9 +942,11 @@ class TargetManagementTest extends AbstractJpaIntegrationTest { @Test @WithUser(allSpPermissions = true) @Description("Tests the assignment of types to multiple targets.") - @ExpectEvents({ @Expect(type = TargetCreatedEvent.class, count = 20), + @ExpectEvents({ + @Expect(type = TargetCreatedEvent.class, count = 20), @Expect(type = TargetTypeCreatedEvent.class, count = 2), - @Expect(type = TargetUpdatedEvent.class, count = 29), @Expect(type = TargetDeletedEvent.class, count = 1) }) + @Expect(type = TargetUpdatedEvent.class, count = 29), + @Expect(type = TargetDeletedEvent.class, count = 1) }) void targetTypeBulkAssignments() { final List typeATargets = testdataFactory.createTargets(10, "typeATargets", "first description"); final List typeBTargets = testdataFactory.createTargets(10, "typeBTargets", "first description"); diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/management/TargetTagManagementTest.java b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/management/TargetTagManagementTest.java index 92e91cef0..adbd5e3c2 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/management/TargetTagManagementTest.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/management/TargetTagManagementTest.java @@ -90,7 +90,8 @@ class TargetTagManagementTest extends AbstractJpaIntegrationTest { @Test @Description("Verifies that management get access reacts as specfied on calls for non existing entities by means " + "of Optional not present.") - @ExpectEvents({ @Expect(type = TargetCreatedEvent.class) }) + @ExpectEvents({ + @Expect(type = TargetCreatedEvent.class) }) void nonExistingEntityAccessReturnsNotPresent() { assertThat(targetTagManagement.getByName(NOT_EXIST_ID)).isNotPresent(); assertThat(targetTagManagement.get(NOT_EXIST_IDL)).isNotPresent(); @@ -99,7 +100,9 @@ class TargetTagManagementTest extends AbstractJpaIntegrationTest { @Test @Description("Verifies that management queries react as specfied on calls for non existing entities " + " by means of throwing EntityNotFoundException.") - @ExpectEvents({ @Expect(type = DistributionSetTagUpdatedEvent.class), @Expect(type = TargetTagUpdatedEvent.class) }) + @ExpectEvents({ + @Expect(type = DistributionSetTagUpdatedEvent.class), + @Expect(type = TargetTagUpdatedEvent.class) }) void entityQueriesReferringToNotExistingEntitiesThrowsException() { verifyThrownExceptionBy(() -> targetTagManagement.delete(NOT_EXIST_ID), "TargetTag"); verifyThrownExceptionBy(() -> targetTagManagement.update(entityFactory.tag().update(NOT_EXIST_IDL)), "TargetTag"); diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/management/TargetTypeManagementTest.java b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/management/TargetTypeManagementTest.java index 9dff10bc3..7ff86b503 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/management/TargetTypeManagementTest.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/management/TargetTypeManagementTest.java @@ -43,7 +43,8 @@ class TargetTypeManagementTest extends AbstractJpaIntegrationTest { @Test @Description("Verifies that management get access react as specified on calls for non existing entities by means " + "of Optional not present.") - @ExpectEvents({ @Expect(type = TargetTypeCreatedEvent.class) }) + @ExpectEvents({ + @Expect(type = TargetTypeCreatedEvent.class) }) void nonExistingEntityAccessReturnsNotPresent() { assertThat(targetTypeManagement.get(NOT_EXIST_IDL)).isNotPresent(); assertThat(targetTypeManagement.getByName(NOT_EXIST_ID)).isNotPresent(); @@ -52,7 +53,8 @@ class TargetTypeManagementTest extends AbstractJpaIntegrationTest { @Test @Description("Verifies that management queries react as specified on calls for non existing entities " + " by means of throwing EntityNotFoundException.") - @ExpectEvents({ @Expect(type = TargetTypeUpdatedEvent.class) }) + @ExpectEvents({ + @Expect(type = TargetTypeUpdatedEvent.class) }) void entityQueriesReferringToNotExistingEntitiesThrowsException() { verifyThrownExceptionBy(() -> targetTypeManagement.delete(NOT_EXIST_IDL), "TargetType"); verifyThrownExceptionBy(() -> targetTypeManagement.update(entityFactory.targetType().update(NOT_EXIST_IDL)), diff --git a/hawkbit-repository/hawkbit-repository-test/src/main/java/org/eclipse/hawkbit/repository/test/util/SecurityContextSwitch.java b/hawkbit-repository/hawkbit-repository-test/src/main/java/org/eclipse/hawkbit/repository/test/util/SecurityContextSwitch.java index ac9d2ad0b..b35828631 100644 --- a/hawkbit-repository/hawkbit-repository-test/src/main/java/org/eclipse/hawkbit/repository/test/util/SecurityContextSwitch.java +++ b/hawkbit-repository/hawkbit-repository-test/src/main/java/org/eclipse/hawkbit/repository/test/util/SecurityContextSwitch.java @@ -28,7 +28,7 @@ import org.springframework.security.core.context.SecurityContextHolder; public class SecurityContextSwitch { - public static final String DEFAULT_TENANT = "default"; + public static final String DEFAULT_TENANT = "DEFAULT"; private static final WithUser PRIVILEDGED_USER = createWithUser("bumlux", DEFAULT_TENANT, false, true, false, "ROLE_CONTROLLER", "ROLE_SYSTEM_CODE"); diff --git a/hawkbit-repository/hawkbit-repository-test/src/main/java/org/eclipse/hawkbit/repository/test/util/TestdataFactory.java b/hawkbit-repository/hawkbit-repository-test/src/main/java/org/eclipse/hawkbit/repository/test/util/TestdataFactory.java index d25a7840b..365de6d9b 100644 --- a/hawkbit-repository/hawkbit-repository-test/src/main/java/org/eclipse/hawkbit/repository/test/util/TestdataFactory.java +++ b/hawkbit-repository/hawkbit-repository-test/src/main/java/org/eclipse/hawkbit/repository/test/util/TestdataFactory.java @@ -81,6 +81,7 @@ import org.eclipse.hawkbit.repository.model.TargetUpdateStatus; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.domain.PageRequest; import org.springframework.data.domain.Pageable; +import org.springframework.util.ObjectUtils; /** * Data generator utility for tests. @@ -314,7 +315,7 @@ public class TestdataFactory { return distributionSetManagement.create( entityFactory.distributionSet().create() .type(findOrCreateDefaultTestDsType()) - .name(prefix == null || prefix.isEmpty() ? "DS" : prefix) + .name(ObjectUtils.isEmpty(prefix) ? "DS" : prefix) .version(version) .description(randomDescriptionShort()) .modules(Arrays.asList(osMod.getId(), runtimeMod.getId(), appMod.getId())) @@ -322,8 +323,7 @@ public class TestdataFactory { } /** - * Adds {@link SoftwareModuleMetadata} to every module of given - * {@link DistributionSet}. + * Adds {@link SoftwareModuleMetadata} to every module of given {@link DistributionSet}. * * {@link #VISIBLE_SM_MD_VALUE}, {@link #VISIBLE_SM_MD_KEY} with * {@link SoftwareModuleMetadata#isTargetVisible()} and diff --git a/hawkbit-repository/hawkbit-repository-test/src/main/java/org/eclipse/hawkbit/repository/test/util/WithUser.java b/hawkbit-repository/hawkbit-repository-test/src/main/java/org/eclipse/hawkbit/repository/test/util/WithUser.java index 0acefb3fb..71c63e3e8 100644 --- a/hawkbit-repository/hawkbit-repository-test/src/main/java/org/eclipse/hawkbit/repository/test/util/WithUser.java +++ b/hawkbit-repository/hawkbit-repository-test/src/main/java/org/eclipse/hawkbit/repository/test/util/WithUser.java @@ -48,7 +48,7 @@ public @interface WithUser { * * @return test tenant id */ - String tenantId() default "default"; + String tenantId() default "DEFAULT"; /** * Should tenant auto created.