From 9a70fffeb5566d19e97ac6c00af7ffa6f43d8959 Mon Sep 17 00:00:00 2001 From: Avgustin Marinov Date: Thu, 9 Oct 2025 12:48:05 +0300 Subject: [PATCH] Simplify/Refactor RolloutExecutor ACM test (#2733) Signed-off-by: Avgustin Marinov --- .../jpa/acm/RolloutExecutionTest.java | 53 +++++++------------ .../jpa/acm/RolloutManagementTest.java | 5 -- 2 files changed, 18 insertions(+), 40 deletions(-) diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/acm/RolloutExecutionTest.java b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/acm/RolloutExecutionTest.java index 8d894c01c..3df0734e5 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/acm/RolloutExecutionTest.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/acm/RolloutExecutionTest.java @@ -21,8 +21,8 @@ import static org.eclipse.hawkbit.repository.test.util.SecurityContextSwitch.run import java.util.Optional; import org.eclipse.hawkbit.repository.jpa.rollout.RolloutScheduler; -import org.eclipse.hawkbit.repository.model.DistributionSet; import org.eclipse.hawkbit.repository.model.Rollout; +import org.eclipse.hawkbit.repository.model.Target; import org.junit.jupiter.api.Test; class RolloutExecutionTest extends AbstractAccessControllerTest { @@ -41,49 +41,32 @@ class RolloutExecutionTest extends AbstractAccessControllerTest { } void verify(final Runnable run) { + final Target[] expectedTargets = new Target[] { target1Type1 }; runAs(withAuthorities( READ_TARGET, UPDATE_TARGET + "/type.id==" + targetType1.getId(), READ_DISTRIBUTION_SET, CREATE_ROLLOUT, READ_ROLLOUT, HANDLE_ROLLOUT), - () -> { - assertThat(targetManagement.findAll(UNPAGED)) - .as("targetManagement#findAll operation should see all created targets") - .hasSize(3); - - final Rollout rollout = createRolloutConsideringAllTargets(ds2Type2); - rolloutManagement.start(rollout.getId()); - - final RolloutScheduler rolloutScheduler = new RolloutScheduler( - rolloutHandler, systemManagement, systemSecurityContext, 1, Optional.empty()); - rolloutScheduler.runningRolloutScheduler(); - - assertThat(rolloutGroupManagement.findByRollout(rollout.getId(), UNPAGED).getContent().stream() - .flatMap(rolloutGroup -> rolloutGroupManagement.findTargetsOfRolloutGroup(rolloutGroup.getId(), UNPAGED).stream())) - .as("Only updatable targets should be part of the rollout") - .containsExactly(target1Type1); - }); + () -> extracted(run, expectedTargets)); runAs(withAuthorities( READ_TARGET, UPDATE_TARGET + "/type.id==" + targetType2.getId(), READ_DISTRIBUTION_SET, CREATE_ROLLOUT, READ_ROLLOUT, HANDLE_ROLLOUT), - () -> { - assertThat(targetManagement.findAll(UNPAGED)) - .as("targetManagement#findAll operation should see all created targets") - .hasSize(3); - - final Rollout rollout = createRolloutConsideringAllTargets(ds2Type2); - rolloutManagement.start(rollout.getId()); - - run.run(); - - assertThat(rolloutGroupManagement.findByRollout(rollout.getId(), UNPAGED).getContent().stream() - .flatMap(rolloutGroup -> rolloutGroupManagement.findTargetsOfRolloutGroup(rolloutGroup.getId(), UNPAGED).stream())) - .as("Only updatable targets should be part of the rollout") - .containsExactly(target2Type2, target3Type2); - }); + () -> extracted(run, target2Type2, target3Type2)); } - private Rollout createRolloutConsideringAllTargets(final DistributionSet ds) { - return testdataFactory.createRolloutByVariables(randomString(16), "description", 5, "id==*", ds, "50", "80"); + private void extracted(final Runnable run, final Target... expectedTargets) { + assertThat(targetManagement.findAll(UNPAGED)) + .as("targetManagement#findAll operation should see all created targets") + .hasSize(3); + + final Rollout rollout = testdataFactory.createRolloutByVariables(randomString(16), "description", 5, "id==*", ds2Type2, "50", "80"); + rolloutManagement.start(rollout.getId()); + + run.run(); + + assertThat(rolloutGroupManagement.findByRollout(rollout.getId(), UNPAGED).getContent().stream() + .flatMap(rolloutGroup -> rolloutGroupManagement.findTargetsOfRolloutGroup(rolloutGroup.getId(), UNPAGED).stream())) + .as("Only updatable targets should be part of the rollout") + .containsExactly(expectedTargets); } } \ No newline at end of file diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/acm/RolloutManagementTest.java b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/acm/RolloutManagementTest.java index 2c09cab19..62b95bf08 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/acm/RolloutManagementTest.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/acm/RolloutManagementTest.java @@ -17,13 +17,8 @@ import static org.eclipse.hawkbit.repository.model.TotalTargetCountStatus.Status import static org.eclipse.hawkbit.repository.model.TotalTargetCountStatus.Status.SCHEDULED; import static org.eclipse.hawkbit.repository.test.util.SecurityContextSwitch.runAs; -import java.util.List; - -import org.assertj.core.api.Assertions; import org.eclipse.hawkbit.repository.Identifiable; import org.eclipse.hawkbit.repository.model.Rollout; -import org.eclipse.hawkbit.repository.model.Target; -import org.eclipse.hawkbit.repository.model.TotalTargetCountStatus; import org.junit.jupiter.api.Test; class RolloutManagementTest extends AbstractAccessControllerTest {