Skip to content

Commit

Permalink
Remove TestHelper (#1654)
Browse files Browse the repository at this point in the history
in favor of placing implicitLock helpers into AbstractJpaIntegrationTest
as it is done in rest tests

Signed-off-by: Marinov Avgustin <Avgustin.Marinov@bosch.com>
  • Loading branch information
avgustinmm committed Feb 19, 2024
1 parent 1845f98 commit 1d98180
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 59 deletions.
Expand Up @@ -24,8 +24,10 @@
import org.assertj.core.api.ThrowableAssert.ThrowingCallable;
import org.eclipse.hawkbit.repository.exception.EntityNotFoundException;
import org.eclipse.hawkbit.repository.jpa.model.JpaAction;
import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSet;
import org.eclipse.hawkbit.repository.jpa.model.JpaRollout;
import org.eclipse.hawkbit.repository.jpa.model.JpaRolloutGroup;
import org.eclipse.hawkbit.repository.jpa.model.JpaSoftwareModule;
import org.eclipse.hawkbit.repository.jpa.repository.ActionRepository;
import org.eclipse.hawkbit.repository.jpa.repository.ActionStatusRepository;
import org.eclipse.hawkbit.repository.jpa.repository.DistributionSetRepository;
Expand All @@ -48,6 +50,7 @@
import org.eclipse.hawkbit.repository.model.DistributionSetTagAssignmentResult;
import org.eclipse.hawkbit.repository.model.Rollout;
import org.eclipse.hawkbit.repository.model.RolloutGroup;
import org.eclipse.hawkbit.repository.model.SoftwareModule;
import org.eclipse.hawkbit.repository.model.Target;
import org.eclipse.hawkbit.repository.model.TargetTag;
import org.eclipse.hawkbit.repository.model.TargetTagAssignmentResult;
Expand Down Expand Up @@ -220,4 +223,12 @@ protected static <T> T[] toArray(final Iterable<? extends T> it, final Class<T>
}
return array;
}

protected static void implicitLock(final DistributionSet set) {
((JpaDistributionSet) set).setOptLockRevision(set.getOptLockRevision() + 1);
}

protected static void implicitLock(final SoftwareModule module) {
((JpaSoftwareModule) module).setOptLockRevision(module.getOptLockRevision() + 1);
}
}

This file was deleted.

Expand Up @@ -23,7 +23,6 @@
import org.eclipse.hawkbit.repository.DeploymentManagement;
import org.eclipse.hawkbit.repository.exception.IncompleteDistributionSetException;
import org.eclipse.hawkbit.repository.jpa.AbstractJpaIntegrationTest;
import org.eclipse.hawkbit.repository.jpa.TestHelper;
import org.eclipse.hawkbit.repository.jpa.specifications.ActionSpecifications;
import org.eclipse.hawkbit.repository.model.Action;
import org.eclipse.hawkbit.repository.model.Action.ActionType;
Expand Down Expand Up @@ -119,7 +118,7 @@ void checkAutoAssign() {
.updateAutoAssign(targetFilterQueryManagement
.create(entityFactory.targetFilterQuery().create().name("filterA").query("name==*")).getId())
.ds(setA.getId()));
TestHelper.implicitLock(setA);
implicitLock(setA);

final String targetDsAIdPref = "targ";
final List<Target> targets = testdataFactory.createTargets(25, targetDsAIdPref,
Expand All @@ -136,7 +135,7 @@ void checkAutoAssign() {
// they have now 2 DS in their action history and should not get updated
// with dsA
assignDistributionSet(setB, targets.subList(0, 5));
TestHelper.implicitLock(setB);
implicitLock(setB);
verifyThatTargetsHaveDistributionSetAssignment(setB, targets.subList(0, 5), targetsCount);

// assign set B to next 10 targets
Expand Down Expand Up @@ -169,7 +168,7 @@ void checkAutoAssignmentForDevice() {
.updateAutoAssign(targetFilterQueryManagement
.create(entityFactory.targetFilterQuery().create().name("filterA").query("name==*")).getId())
.ds(toAssignDs.getId()));
TestHelper.implicitLock(toAssignDs);
implicitLock(toAssignDs);

final List<Target> targets = testdataFactory.createTargets(25);
final int targetsCount = targets.size();
Expand Down Expand Up @@ -270,7 +269,7 @@ void checkAutoAssignWithFailures() {
// target filter query that matches failed bunch of targets
targetFilterQueryManagement.create(entityFactory.targetFilterQuery().create().name("filterB")
.query("id==" + targetDsAIdPref + "*").autoAssignDistributionSet(setA.getId()));
TestHelper.implicitLock(setA);
implicitLock(setA);

final List<Target> targetsF = testdataFactory.createTargets(10, targetDsFIdPref,
targetDsFIdPref.concat(" description"));
Expand All @@ -282,7 +281,7 @@ void checkAutoAssignWithFailures() {

// assign set B to first 5 targets of fail group
assignDistributionSet(setB, targetsF.subList(0, 5));
TestHelper.implicitLock(setB);
implicitLock(setB);
verifyThatTargetsHaveDistributionSetAssignment(setB, targetsF.subList(0, 5), targetsCount);

// Run the check
Expand Down Expand Up @@ -371,7 +370,7 @@ void checkAutoAssignWithDifferentActionTypes() {

final List<Target> targetsA = createTargetsAndAutoAssignDistSet(targetDsAIdPref, 5, distributionSet,
ActionType.FORCED);
TestHelper.implicitLock(distributionSet);
implicitLock(distributionSet);
final List<Target> targetsB = createTargetsAndAutoAssignDistSet(targetDsBIdPref, 10, distributionSet,
ActionType.SOFT);
final List<Target> targetsC = createTargetsAndAutoAssignDistSet(targetDsCIdPref, 10, distributionSet,
Expand Down
Expand Up @@ -55,7 +55,6 @@
import org.eclipse.hawkbit.repository.exception.InvalidDistributionSetException;
import org.eclipse.hawkbit.repository.exception.MultiAssignmentIsNotEnabledException;
import org.eclipse.hawkbit.repository.jpa.AbstractJpaIntegrationTest;
import org.eclipse.hawkbit.repository.jpa.TestHelper;
import org.eclipse.hawkbit.repository.jpa.model.JpaAction;
import org.eclipse.hawkbit.repository.jpa.model.JpaActionStatus;
import org.eclipse.hawkbit.repository.jpa.model.JpaAction_;
Expand Down Expand Up @@ -456,7 +455,7 @@ void forceQuitNotAllowedThrowsException() {

private JpaAction assignSet(final Target target, final DistributionSet ds) {
assignDistributionSet(ds.getId(), target.getControllerId());
TestHelper.implicitLock(ds);
implicitLock(ds);
assertThat(targetManagement.getByControllerID(target.getControllerId()).get().getUpdateStatus())
.as("wrong update status").isEqualTo(TargetUpdateStatus.PENDING);
assertThat(deploymentManagement.getAssignedDistributionSet(target.getControllerId())).as("wrong assigned ds")
Expand Down Expand Up @@ -1059,7 +1058,7 @@ void assignDistributionSet2Targets() {

final DistributionSet ds = testdataFactory.createDistributionSet("");
assignDistributionSet(ds, savedDeployedTargets);
TestHelper.implicitLock(ds);
implicitLock(ds);

// verify that one Action for each assignDistributionSet
final Page<JpaAction> actions = actionRepository.findAll(PAGE);
Expand Down Expand Up @@ -1385,7 +1384,7 @@ void alternatingAssignmentAndAddUpdateActionStatus() {
// doing the assignment
targs = assignDistributionSet(dsA, targs).getAssignedEntity().stream().map(Action::getTarget)
.collect(Collectors.toList());
TestHelper.implicitLock(dsA);
implicitLock(dsA);
Target targ = targetManagement.getByControllerID(targs.iterator().next().getControllerId()).get();

// checking the revisions of the created entities
Expand Down Expand Up @@ -1427,7 +1426,7 @@ void alternatingAssignmentAndAddUpdateActionStatus() {

targs = assignDistributionSet(dsB.getId(), "target-id-A").getAssignedEntity().stream().map(Action::getTarget)
.collect(Collectors.toList());
TestHelper.implicitLock(dsB);
implicitLock(dsB);

targ = targs.iterator().next();

Expand Down Expand Up @@ -1594,7 +1593,7 @@ void verifyDSAssignmentForMultipleTargetsWithSameTargetType() {
}

deploymentManagement.assignDistributionSets(deploymentRequests);
TestHelper.implicitLock(ds);
implicitLock(ds);

final List<Target> content = targetManagement.findAll(Pageable.unpaged()).getContent();

Expand All @@ -1620,7 +1619,7 @@ void verifyDSAssignmentForMultipleTargetsWithDifferentTargetTypes() {
final List<DeploymentRequest> deploymentRequests = Arrays.asList(deployment1, deployment2);

deploymentManagement.assignDistributionSets(deploymentRequests);
TestHelper.implicitLock(ds);
implicitLock(ds);

final Optional<DistributionSet> assignedDsTarget1 = targetManagement
.getByControllerID(target1.getControllerId()).map(JpaTarget.class::cast)
Expand Down Expand Up @@ -1708,7 +1707,7 @@ private DeploymentResult prepareComplexRepo(final String undeployedTargetPrefix,
for (final DistributionSet ds : dsList) {
deployedTargets = assignDistributionSet(ds, deployedTargets).getAssignedEntity().stream()
.map(Action::getTarget).collect(Collectors.toList());
TestHelper.implicitLock(ds);
implicitLock(ds);
}

return new DeploymentResult(deployedTargets, nakedTargets, dsList, deployedTargetPrefix, undeployedTargetPrefix,
Expand Down
Expand Up @@ -45,7 +45,6 @@
import org.eclipse.hawkbit.repository.exception.LockedException;
import org.eclipse.hawkbit.repository.exception.UnsupportedSoftwareModuleForThisDistributionSetException;
import org.eclipse.hawkbit.repository.jpa.AbstractJpaIntegrationTest;
import org.eclipse.hawkbit.repository.jpa.TestHelper;
import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSet;
import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSetMetadata;
import org.eclipse.hawkbit.repository.model.Action.Status;
Expand Down Expand Up @@ -641,15 +640,15 @@ void findDistributionSetsAllOrderedByLinkTarget() {

// set assigned
assignDistributionSet(dsSecond.getId(), tSecond.getControllerId());
TestHelper.implicitLock(dsSecond);
implicitLock(dsSecond);
assignDistributionSet(dsThree.getId(), tFirst.getControllerId());
TestHelper.implicitLock(dsThree);
implicitLock(dsThree);
// set installed
testdataFactory.sendUpdateActionStatusToTargets(Collections.singleton(tSecond), Status.FINISHED,
singletonList("some message"));

assignDistributionSet(dsFour.getId(), tSecond.getControllerId());
TestHelper.implicitLock(dsFour);
implicitLock(dsFour);

final DistributionSetFilter distributionSetFilter =
DistributionSetFilter.builder()
Expand Down
Expand Up @@ -31,7 +31,6 @@
import org.eclipse.hawkbit.repository.exception.LockedException;
import org.eclipse.hawkbit.repository.jpa.AbstractJpaIntegrationTest;
import org.eclipse.hawkbit.repository.jpa.RandomGeneratedInputStream;
import org.eclipse.hawkbit.repository.jpa.TestHelper;
import org.eclipse.hawkbit.repository.jpa.model.JpaAction_;
import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSet;
import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSet_;
Expand Down Expand Up @@ -197,8 +196,8 @@ public void findSoftwareModuleByFilters() {

final JpaTarget target = (JpaTarget) testdataFactory.createTarget();
ds = (JpaDistributionSet) assignSet(target, ds).getDistributionSet();
TestHelper.implicitLock(os);
TestHelper.implicitLock(jvm);
implicitLock(os);
implicitLock(jvm);

// standard searches
assertThat(softwareModuleManagement.findByTextAndType(PAGE, "poky", osType.getId()).getContent()).hasSize(1);
Expand All @@ -222,7 +221,7 @@ public void findSoftwareModuleByFilters() {

private Action assignSet(final JpaTarget target, final JpaDistributionSet ds) {
assignDistributionSet(ds.getId(), target.getControllerId());
TestHelper.implicitLock(ds);
implicitLock(ds);
assertThat(targetManagement.getByControllerID(target.getControllerId()).get().getUpdateStatus())
.isEqualTo(TargetUpdateStatus.PENDING);
final Optional<DistributionSet> assignedDistributionSet = deploymentManagement
Expand Down
Expand Up @@ -37,7 +37,6 @@
import org.eclipse.hawkbit.repository.exception.InvalidDistributionSetException;
import org.eclipse.hawkbit.repository.exception.RSQLParameterUnsupportedFieldException;
import org.eclipse.hawkbit.repository.jpa.AbstractJpaIntegrationTest;
import org.eclipse.hawkbit.repository.jpa.TestHelper;
import org.eclipse.hawkbit.repository.model.Action;
import org.eclipse.hawkbit.repository.model.Action.ActionType;
import org.eclipse.hawkbit.repository.model.DistributionSet;
Expand Down Expand Up @@ -220,7 +219,7 @@ private void verifyAutoAssignmentWithDefaultActionType(final String filterName,
final TargetFilterQuery targetFilterQuery, final DistributionSet distributionSet) {
targetFilterQueryManagement.updateAutoAssignDS(entityFactory.targetFilterQuery()
.updateAutoAssign(targetFilterQuery.getId()).ds(distributionSet.getId()));
TestHelper.implicitLock(distributionSet);
implicitLock(distributionSet);
verifyAutoAssignDsAndActionType(filterName, distributionSet, ActionType.FORCED);
}

Expand Down Expand Up @@ -324,7 +323,7 @@ public void removeAssignDistributionSet() {

targetFilterQueryManagement.updateAutoAssignDS(entityFactory.targetFilterQuery()
.updateAutoAssign(targetFilterQuery.getId()).ds(distributionSet.getId()));
TestHelper.implicitLock(distributionSet);
implicitLock(distributionSet);

// Check if target filter query is there
TargetFilterQuery tfq = targetFilterQueryManagement.getByName(filterName).get();
Expand Down Expand Up @@ -356,7 +355,7 @@ public void implicitlyRemoveAssignDistributionSet() {
.getId();
targetFilterQueryManagement.updateAutoAssignDS(
entityFactory.targetFilterQuery().updateAutoAssign(filterId).ds(distributionSet.getId()));
TestHelper.implicitLock(distributionSet);
implicitLock(distributionSet);

// Check if target filter query is there with the distribution set
TargetFilterQuery tfq = targetFilterQueryManagement.getByName(filterName).get();
Expand Down
Expand Up @@ -55,7 +55,6 @@
import org.eclipse.hawkbit.repository.exception.RSQLParameterUnsupportedFieldException;
import org.eclipse.hawkbit.repository.exception.TenantNotExistException;
import org.eclipse.hawkbit.repository.jpa.AbstractJpaIntegrationTest;
import org.eclipse.hawkbit.repository.jpa.TestHelper;
import org.eclipse.hawkbit.repository.jpa.model.JpaAction;
import org.eclipse.hawkbit.repository.jpa.model.JpaTarget;
import org.eclipse.hawkbit.repository.jpa.model.JpaTargetMetadata;
Expand Down Expand Up @@ -485,12 +484,12 @@ void findTargetByControllerIDWithDetails() {
controllerManagement.findOrRegisterTargetIfItDoesNotExist("4711", LOCALHOST);

final DistributionSetAssignmentResult result = assignDistributionSet(testDs1.getId(), "4711");
TestHelper.implicitLock(testDs1);
implicitLock(testDs1);

controllerManagement.addUpdateActionStatus(
entityFactory.actionStatus().create(getFirstAssignedActionId(result)).status(Status.FINISHED));
assignDistributionSet(testDs2.getId(), "4711");
TestHelper.implicitLock(testDs2);
implicitLock(testDs2);

target = targetManagement.getByControllerID("4711").orElseThrow(IllegalStateException::new);
// read data
Expand Down

0 comments on commit 1d98180

Please sign in to comment.