Simplify/Refactor RolloutExecutor ACM test (#2733)

Signed-off-by: Avgustin Marinov <Avgustin.Marinov@bosch.com>
This commit is contained in:
Avgustin Marinov
2025-10-09 12:48:05 +03:00
committed by GitHub
parent bc96c24983
commit 9a70fffeb5
2 changed files with 18 additions and 40 deletions

View File

@@ -21,8 +21,8 @@ import static org.eclipse.hawkbit.repository.test.util.SecurityContextSwitch.run
import java.util.Optional; import java.util.Optional;
import org.eclipse.hawkbit.repository.jpa.rollout.RolloutScheduler; 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.Rollout;
import org.eclipse.hawkbit.repository.model.Target;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
class RolloutExecutionTest extends AbstractAccessControllerTest { class RolloutExecutionTest extends AbstractAccessControllerTest {
@@ -41,37 +41,25 @@ class RolloutExecutionTest extends AbstractAccessControllerTest {
} }
void verify(final Runnable run) { void verify(final Runnable run) {
final Target[] expectedTargets = new Target[] { target1Type1 };
runAs(withAuthorities( runAs(withAuthorities(
READ_TARGET, UPDATE_TARGET + "/type.id==" + targetType1.getId(), READ_TARGET, UPDATE_TARGET + "/type.id==" + targetType1.getId(),
READ_DISTRIBUTION_SET, READ_DISTRIBUTION_SET,
CREATE_ROLLOUT, READ_ROLLOUT, HANDLE_ROLLOUT), CREATE_ROLLOUT, READ_ROLLOUT, HANDLE_ROLLOUT),
() -> { () -> extracted(run, expectedTargets));
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);
});
runAs(withAuthorities( runAs(withAuthorities(
READ_TARGET, UPDATE_TARGET + "/type.id==" + targetType2.getId(), READ_TARGET, UPDATE_TARGET + "/type.id==" + targetType2.getId(),
READ_DISTRIBUTION_SET, READ_DISTRIBUTION_SET,
CREATE_ROLLOUT, READ_ROLLOUT, HANDLE_ROLLOUT), CREATE_ROLLOUT, READ_ROLLOUT, HANDLE_ROLLOUT),
() -> { () -> extracted(run, target2Type2, target3Type2));
}
private void extracted(final Runnable run, final Target... expectedTargets) {
assertThat(targetManagement.findAll(UNPAGED)) assertThat(targetManagement.findAll(UNPAGED))
.as("targetManagement#findAll operation should see all created targets") .as("targetManagement#findAll operation should see all created targets")
.hasSize(3); .hasSize(3);
final Rollout rollout = createRolloutConsideringAllTargets(ds2Type2); final Rollout rollout = testdataFactory.createRolloutByVariables(randomString(16), "description", 5, "id==*", ds2Type2, "50", "80");
rolloutManagement.start(rollout.getId()); rolloutManagement.start(rollout.getId());
run.run(); run.run();
@@ -79,11 +67,6 @@ class RolloutExecutionTest extends AbstractAccessControllerTest {
assertThat(rolloutGroupManagement.findByRollout(rollout.getId(), UNPAGED).getContent().stream() assertThat(rolloutGroupManagement.findByRollout(rollout.getId(), UNPAGED).getContent().stream()
.flatMap(rolloutGroup -> rolloutGroupManagement.findTargetsOfRolloutGroup(rolloutGroup.getId(), UNPAGED).stream())) .flatMap(rolloutGroup -> rolloutGroupManagement.findTargetsOfRolloutGroup(rolloutGroup.getId(), UNPAGED).stream()))
.as("Only updatable targets should be part of the rollout") .as("Only updatable targets should be part of the rollout")
.containsExactly(target2Type2, target3Type2); .containsExactly(expectedTargets);
});
}
private Rollout createRolloutConsideringAllTargets(final DistributionSet ds) {
return testdataFactory.createRolloutByVariables(randomString(16), "description", 5, "id==*", ds, "50", "80");
} }
} }

View File

@@ -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.model.TotalTargetCountStatus.Status.SCHEDULED;
import static org.eclipse.hawkbit.repository.test.util.SecurityContextSwitch.runAs; 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.Identifiable;
import org.eclipse.hawkbit.repository.model.Rollout; 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; import org.junit.jupiter.api.Test;
class RolloutManagementTest extends AbstractAccessControllerTest { class RolloutManagementTest extends AbstractAccessControllerTest {