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 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);
}
}

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.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 {