Simplify/Refactor RolloutExecutor ACM test (#2733)
Signed-off-by: Avgustin Marinov <Avgustin.Marinov@bosch.com>
This commit is contained in:
@@ -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,49 +41,32 @@ 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));
|
||||||
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);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private Rollout createRolloutConsideringAllTargets(final DistributionSet ds) {
|
private void extracted(final Runnable run, final Target... expectedTargets) {
|
||||||
return testdataFactory.createRolloutByVariables(randomString(16), "description", 5, "id==*", ds, "50", "80");
|
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -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 {
|
||||||
|
|||||||
Reference in New Issue
Block a user