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 0443de3de..a1aae6e83 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 @@ -472,7 +472,7 @@ class DeploymentManagementTest extends AbstractJpaIntegrationTest { + "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 = TargetUpdatedEvent.class, count = 20), @Expect(type = ActionCreatedEvent.class, count = 20), @Expect(type = DistributionSetCreatedEvent.class, count = 2), @Expect(type = SoftwareModuleCreatedEvent.class, count = 6), @@ -480,11 +480,9 @@ class DeploymentManagementTest extends AbstractJpaIntegrationTest { @Expect(type = SoftwareModuleUpdatedEvent.class, count = 6), // implicit lock @Expect(type = TargetAssignDistributionSetEvent.class, count = 1) }) void assignedDistributionSet() { - - final List controllerIds = testdataFactory.createTargets(10).stream().map(Target::getControllerId) - .toList(); final List onlineAssignedTargets = testdataFactory.createTargets(10, "2"); - controllerIds.addAll(onlineAssignedTargets.stream().map(Target::getControllerId).toList()); + final List controllerIds = Stream.concat(testdataFactory.createTargets(10).stream(), onlineAssignedTargets.stream()) + .map(Target::getControllerId).toList(); final DistributionSet ds = testdataFactory.createDistributionSet(); assignDistributionSet(testdataFactory.createDistributionSet("2"), onlineAssignedTargets); @@ -492,12 +490,11 @@ class DeploymentManagementTest extends AbstractJpaIntegrationTest { final long current = System.currentTimeMillis(); final List> offlineAssignments = controllerIds.stream() - .map(targetId -> (Entry)new SimpleEntry<>(targetId, ds.getId())).toList(); + .map(targetId -> (Entry) new SimpleEntry<>(targetId, ds.getId())).toList(); final List assignmentResults = deploymentManagement .offlineAssignedDistributionSets(offlineAssignments); assertThat(assignmentResults).hasSize(1); - final List targets = assignmentResults.get(0).getAssignedEntity().stream().map(Action::getTarget) - .toList(); + final List targets = assignmentResults.get(0).getAssignedEntity().stream().map(Action::getTarget).toList(); assertThat(actionRepository.count()).isEqualTo(20); assertThat(findActionsByDistributionSet(PAGE, ds.getId())).as("Offline actions are not active") @@ -518,7 +515,7 @@ class DeploymentManagementTest extends AbstractJpaIntegrationTest { @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 = TargetUpdatedEvent.class, count = 4), @Expect(type = ActionCreatedEvent.class, count = 4), @Expect(type = DistributionSetCreatedEvent.class, count = 4), @Expect(type = SoftwareModuleCreatedEvent.class, count = 12), @@ -554,7 +551,7 @@ class DeploymentManagementTest extends AbstractJpaIntegrationTest { @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 = TargetUpdatedEvent.class, count = 20), @Expect(type = ActionCreatedEvent.class, count = 20), @Expect(type = ActionUpdatedEvent.class, count = 10), @Expect(type = DistributionSetCreatedEvent.class, count = 2), @@ -597,7 +594,7 @@ class DeploymentManagementTest extends AbstractJpaIntegrationTest { @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 = TargetUpdatedEvent.class, count = 20), @Expect(type = ActionCreatedEvent.class, count = 20), @Expect(type = DistributionSetCreatedEvent.class, count = 2), @Expect(type = SoftwareModuleCreatedEvent.class, count = 6), @@ -628,7 +625,7 @@ class DeploymentManagementTest extends AbstractJpaIntegrationTest { @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 = TargetUpdatedEvent.class, count = 4), @Expect(type = ActionCreatedEvent.class, count = 4), @Expect(type = DistributionSetCreatedEvent.class, count = 4), @Expect(type = SoftwareModuleCreatedEvent.class, count = 12), @@ -665,7 +662,7 @@ class DeploymentManagementTest extends AbstractJpaIntegrationTest { @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 = TargetUpdatedEvent.class, count = 4), @Expect(type = ActionCreatedEvent.class, count = 4), @Expect(type = DistributionSetCreatedEvent.class, count = 4), @Expect(type = SoftwareModuleCreatedEvent.class, count = 12), @@ -689,12 +686,12 @@ class DeploymentManagementTest extends AbstractJpaIntegrationTest { final List dsIds = distributionSets.stream().map(DistributionSet::getId).toList(); targets.forEach(target -> - deploymentManagement.findActionsByTarget(target.getControllerId(), PAGE).forEach(action -> { - assertThat(action.getDistributionSet().getId()).isIn(dsIds); - assertThat(action.getInitiatedBy()).as("Should be Initiated by current user") - .isEqualTo(tenantAware.getCurrentUsername()); - deploymentManagement.cancelAction(action.getId()); - })); + deploymentManagement.findActionsByTarget(target.getControllerId(), PAGE).forEach(action -> { + assertThat(action.getDistributionSet().getId()).isIn(dsIds); + assertThat(action.getInitiatedBy()).as("Should be Initiated by current user") + .isEqualTo(tenantAware.getCurrentUsername()); + deploymentManagement.cancelAction(action.getId()); + })); } @Test @@ -756,16 +753,16 @@ class DeploymentManagementTest extends AbstractJpaIntegrationTest { assertThat(getResultingActionCount(results)).isEqualTo(controllerIds.size()); controllerIds.forEach(controllerId -> - deploymentManagement.findActionsByTarget(controllerId, PAGE).forEach(action -> { - assertThat(action.getDistributionSet().getId()).isIn(distributionSet.getId()); - assertThat(action.getInitiatedBy()).as("Should be Initiated by current user") - .isEqualTo(tenantAware.getCurrentUsername()); - if (confirmationRequired) { - assertThat(action.getStatus()).isEqualTo(Status.WAIT_FOR_CONFIRMATION); - } else { - assertThat(action.getStatus()).isEqualTo(RUNNING); - } - })); + deploymentManagement.findActionsByTarget(controllerId, PAGE).forEach(action -> { + assertThat(action.getDistributionSet().getId()).isIn(distributionSet.getId()); + assertThat(action.getInitiatedBy()).as("Should be Initiated by current user") + .isEqualTo(tenantAware.getCurrentUsername()); + if (confirmationRequired) { + assertThat(action.getStatus()).isEqualTo(Status.WAIT_FOR_CONFIRMATION); + } else { + assertThat(action.getStatus()).isEqualTo(RUNNING); + } + })); } @ParameterizedTest @@ -870,12 +867,12 @@ class DeploymentManagementTest extends AbstractJpaIntegrationTest { assertThat(getResultingActionCount(results)).isEqualTo(controllerIds.size()); controllerIds.forEach(controllerId -> - deploymentManagement.findActionsByTarget(controllerId, PAGE).forEach(action -> { - assertThat(action.getDistributionSet().getId()).isIn(distributionSet.getId()); - assertThat(action.getInitiatedBy()).as("Should be Initiated by current user") - .isEqualTo(tenantAware.getCurrentUsername()); - assertThat(action.getStatus()).isEqualTo(RUNNING); - })); + deploymentManagement.findActionsByTarget(controllerId, PAGE).forEach(action -> { + assertThat(action.getDistributionSet().getId()).isIn(distributionSet.getId()); + assertThat(action.getInitiatedBy()).as("Should be Initiated by current user") + .isEqualTo(tenantAware.getCurrentUsername()); + assertThat(action.getStatus()).isEqualTo(RUNNING); + })); } @Test @@ -887,7 +884,7 @@ class DeploymentManagementTest extends AbstractJpaIntegrationTest { @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 = ActionCreatedEvent.class, count = 2), @Expect(type = TargetUpdatedEvent.class, count = 2), @Expect(type = MultiActionAssignEvent.class, count = 1), @Expect(type = TenantConfigurationCreatedEvent.class, count = 1) }) @@ -968,7 +965,7 @@ class DeploymentManagementTest extends AbstractJpaIntegrationTest { @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 = ActionCreatedEvent.class, count = 2), @Expect(type = TargetUpdatedEvent.class, count = 2), @Expect(type = MultiActionAssignEvent.class, count = 2), @Expect(type = TenantConfigurationCreatedEvent.class, count = 1) }) @@ -1009,7 +1006,7 @@ class DeploymentManagementTest extends AbstractJpaIntegrationTest { @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 = TargetCreatedEvent.class, count = 30), @Expect(type = ActionCreatedEvent.class, count = 20), @Expect(type = TargetUpdatedEvent.class, count = 20) }) void assignDistributionSet2Targets() { @@ -1065,7 +1062,7 @@ class DeploymentManagementTest extends AbstractJpaIntegrationTest { @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 = TargetCreatedEvent.class, count = 10), @Expect(type = ActionCreatedEvent.class, count = 10), @Expect(type = TargetUpdatedEvent.class, count = 10) }) void failDistributionSetAssigmentThatIsNotComplete() { @@ -1557,9 +1554,9 @@ class DeploymentManagementTest extends AbstractJpaIntegrationTest { deploymentManagement.assignDistributionSets(deploymentRequests); implicitLock(ds); - final DistributionSet assignedDsTarget1 = ((JpaTarget)targetManagement + final DistributionSet assignedDsTarget1 = ((JpaTarget) targetManagement .getWithDetails(target1.getControllerId(), "assignedDistributionSet")).getAssignedDistributionSet(); - final DistributionSet assignedDsTarget2 = ((JpaTarget)targetManagement + final DistributionSet assignedDsTarget2 = ((JpaTarget) targetManagement .getWithDetails(target1.getControllerId(), "assignedDistributionSet")).getAssignedDistributionSet(); assertThat(assignedDsTarget1).isEqualTo(ds); diff --git a/hawkbit-repository/hawkbit-repository-test/src/main/java/org/eclipse/hawkbit/repository/test/util/AbstractIntegrationTest.java b/hawkbit-repository/hawkbit-repository-test/src/main/java/org/eclipse/hawkbit/repository/test/util/AbstractIntegrationTest.java index 246472a65..80d18f73c 100644 --- a/hawkbit-repository/hawkbit-repository-test/src/main/java/org/eclipse/hawkbit/repository/test/util/AbstractIntegrationTest.java +++ b/hawkbit-repository/hawkbit-repository-test/src/main/java/org/eclipse/hawkbit/repository/test/util/AbstractIntegrationTest.java @@ -22,7 +22,6 @@ import java.util.Collections; import java.util.Comparator; import java.util.List; import java.util.NoSuchElementException; -import java.util.stream.Collectors; import lombok.extern.slf4j.Slf4j; import org.apache.commons.io.FileUtils; @@ -99,14 +98,11 @@ import org.springframework.test.context.TestPropertySource; @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.NONE) @ContextConfiguration(classes = { TestConfiguration.class }) @Import(TestChannelBinderConfiguration.class) -// destroy the context after each test class because otherwise we get problem -// when context is -// refreshed we e.g. get two instances of CacheManager which leads to very -// strange test failures. +// destroy the context after each test class because otherwise we get problem when context is +// refreshed we e.g. get two instances of CacheManager which leads to very strange test failures. @DirtiesContext(classMode = ClassMode.AFTER_CLASS) // Cleaning repository will fire "delete" events. We won't count them to the -// test execution. So, the order execution between EventVerifier and Cleanup is -// important! +// test execution. So, the order execution between EventVerifier and Cleanup is important! @TestExecutionListeners( listeners = { EventVerifier.class, CleanupTestExecutionListener.class }, mergeMode = MergeMode.MERGE_WITH_DEFAULTS) @@ -189,7 +185,7 @@ public abstract class AbstractIntegrationTest { protected ServiceMatcher serviceMatcher; @Autowired protected ApplicationEventPublisher eventPublisher; - private static final String ARTIFACT_DIRECTORY = createTempDir().toString(); + private static final String ARTIFACT_DIRECTORY = createTempDir().getAbsolutePath() + "/" + randomString(20); @BeforeAll public static void beforeClass() { @@ -209,7 +205,6 @@ public abstract class AbstractIntegrationTest { @BeforeEach public void beforeAll() throws Exception { - final String description = "Updated description."; osType = SecurityContextSwitch @@ -485,7 +480,7 @@ public abstract class AbstractIntegrationTest { private static File createTempDir() { try { - final File file = Files.createTempFile(String.valueOf(System.currentTimeMillis()), "hawkbit_test").toFile(); + final File file = Files.createTempDirectory(System.currentTimeMillis() + "_").toFile(); file.deleteOnExit(); if (!file.setReadable(true, true) || !file.setWritable(true, true)) { if (file.delete()) { // try to delete immediately, if failed - on exit @@ -498,6 +493,9 @@ public abstract class AbstractIntegrationTest { if (!file.setExecutable(false)) { log.debug("Can't remove executable permissions for temp file {}", file); } + if (!file.setExecutable(true, true)) { + log.debug("Can't set executable permissions for temp directory {} for the owner", file); + } return file; } catch (final IOException e) { throw new ArtifactStoreException("Cannot create temp file", e);