Remove TargetInfo entity (#453)

Signed-off-by: kaizimmerm <kai.zimmermann@bosch-si.com>
This commit is contained in:
Kai Zimmermann
2017-03-17 12:18:43 +01:00
committed by GitHub
parent 67d17fe661
commit 602fb78168
89 changed files with 1166 additions and 1462 deletions

View File

@@ -76,9 +76,6 @@ public abstract class AbstractJpaIntegrationTest extends AbstractIntegrationTest
@Autowired
protected LocalArtifactRepository artifactRepository;
@Autowired
protected TargetInfoRepository targetInfoRepository;
@Autowired
protected RolloutGroupRepository rolloutGroupRepository;

View File

@@ -65,20 +65,20 @@ public class ArtifactManagementTest extends AbstractJpaIntegrationTest {
assertThatThrownBy(() -> artifactManagement.deleteArtifact(1234L)).isInstanceOf(EntityNotFoundException.class)
.hasMessageContaining("1234").hasMessageContaining("Artifact");
assertThat(artifactManagement.findArtifact(1234L).isPresent()).isFalse();
assertThat(artifactManagement.findArtifact(1234L)).isNotPresent();
assertThatThrownBy(() -> artifactManagement.findArtifactBySoftwareModule(pageReq, 1234L))
.isInstanceOf(EntityNotFoundException.class).hasMessageContaining("1234")
.hasMessageContaining("SoftwareModule");
assertThat(artifactManagement.findArtifactByFilename("1234").isPresent()).isFalse();
assertThat(artifactManagement.findArtifactByFilename("1234")).isNotPresent();
assertThatThrownBy(() -> artifactManagement.findByFilenameAndSoftwareModule("xxx", 1234L))
.isInstanceOf(EntityNotFoundException.class).hasMessageContaining("1234")
.hasMessageContaining("SoftwareModule");
assertThat(artifactManagement.findByFilenameAndSoftwareModule("1234", module.getId()).isPresent()).isFalse();
assertThat(artifactManagement.findByFilenameAndSoftwareModule("1234", module.getId())).isNotPresent();
assertThat(artifactManagement.findFirstArtifactBySHA1("1234").isPresent()).isFalse();
assertThat(artifactManagement.loadArtifactBinary("1234").isPresent()).isFalse();
assertThat(artifactManagement.findFirstArtifactBySHA1("1234")).isNotPresent();
assertThat(artifactManagement.loadArtifactBinary("1234")).isNotPresent();
}
@@ -271,12 +271,12 @@ public class ArtifactManagementTest extends AbstractJpaIntegrationTest {
public void findByFilenameAndSoftwareModule() {
final SoftwareModule sm = testdataFactory.createSoftwareModuleOs();
assertThat(artifactManagement.findByFilenameAndSoftwareModule("file1", sm.getId()).isPresent()).isFalse();
assertThat(artifactManagement.findByFilenameAndSoftwareModule("file1", sm.getId())).isNotPresent();
artifactManagement.createArtifact(new RandomGeneratedInputStream(5 * 1024), sm.getId(), "file1", false);
artifactManagement.createArtifact(new RandomGeneratedInputStream(5 * 1024), sm.getId(), "file2", false);
assertThat(artifactManagement.findByFilenameAndSoftwareModule("file1", sm.getId()).isPresent()).isTrue();
assertThat(artifactManagement.findByFilenameAndSoftwareModule("file1", sm.getId())).isPresent();
}
}

View File

@@ -10,6 +10,7 @@ package org.eclipse.hawkbit.repository.jpa;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.eclipse.hawkbit.im.authentication.SpPermission.SpringEvalExpressions.CONTROLLER_ROLE_ANONYMOUS;
import static org.junit.Assert.fail;
import java.io.ByteArrayInputStream;
@@ -43,6 +44,7 @@ import org.eclipse.hawkbit.repository.model.TargetUpdateStatus;
import org.eclipse.hawkbit.repository.test.matcher.Expect;
import org.eclipse.hawkbit.repository.test.matcher.ExpectEvents;
import org.eclipse.hawkbit.repository.test.util.TestdataFactory;
import org.eclipse.hawkbit.repository.test.util.WithSpringAuthorityRule;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
@@ -83,9 +85,9 @@ public class ControllerManagementTest extends AbstractJpaIntegrationTest {
.isInstanceOf(EntityNotFoundException.class).hasMessageContaining("1234")
.hasMessageContaining("Action");
assertThat(controllerManagement.findActionWithDetails(1234L).isPresent()).isFalse();
assertThat(controllerManagement.findByControllerId("1234").isPresent()).isFalse();
assertThat(controllerManagement.findByTargetId(1234L).isPresent()).isFalse();
assertThat(controllerManagement.findActionWithDetails(1234L)).isNotPresent();
assertThat(controllerManagement.findByControllerId("1234")).isNotPresent();
assertThat(controllerManagement.findByTargetId(1234L)).isNotPresent();
assertThatThrownBy(() -> controllerManagement.findOldestActiveActionByTarget("1234"))
.isInstanceOf(EntityNotFoundException.class).hasMessageContaining("1234")
@@ -316,7 +318,7 @@ public class ControllerManagementTest extends AbstractJpaIntegrationTest {
testdataFactory.createTarget();
assignDistributionSet(dsId, TestdataFactory.DEFAULT_CONTROLLER_ID);
assertThat(targetManagement.findTargetByControllerID(TestdataFactory.DEFAULT_CONTROLLER_ID).get()
.getTargetInfo().getUpdateStatus()).isEqualTo(TargetUpdateStatus.PENDING);
.getUpdateStatus()).isEqualTo(TargetUpdateStatus.PENDING);
return deploymentManagement.findActiveActionsByTarget(TestdataFactory.DEFAULT_CONTROLLER_ID).get(0).getId();
}
@@ -371,7 +373,7 @@ public class ControllerManagementTest extends AbstractJpaIntegrationTest {
final TargetUpdateStatus expectedTargetUpdateStatus, final Action.Status expectedActionActionStatus,
final Action.Status expectedActionStatus, final boolean actionActive) {
final TargetUpdateStatus targetStatus = targetManagement.findTargetByControllerID(controllerId).get()
.getTargetInfo().getUpdateStatus();
.getUpdateStatus();
assertThat(targetStatus).isEqualTo(expectedTargetUpdateStatus);
final Action action = deploymentManagement.findAction(actionId).get();
assertThat(action.getStatus()).isEqualTo(expectedActionActionStatus);
@@ -428,7 +430,7 @@ public class ControllerManagementTest extends AbstractJpaIntegrationTest {
assertThat(target).as("target should not be null").isNotNull();
final Target sameTarget = controllerManagement.findOrRegisterTargetIfItDoesNotexist("AA", null);
assertThat(target).as("Target should be the equals").isEqualTo(sameTarget);
assertThat(target.getId()).as("Target should be the equals").isEqualTo(sameTarget.getId());
assertThat(targetRepository.count()).as("Only 1 target should be registred").isEqualTo(1L);
// throws exception
@@ -540,7 +542,7 @@ public class ControllerManagementTest extends AbstractJpaIntegrationTest {
// nothing changed as "feedback after close" is disabled
assertThat(targetManagement.findTargetByControllerID(TestdataFactory.DEFAULT_CONTROLLER_ID).get()
.getTargetInfo().getUpdateStatus()).isEqualTo(TargetUpdateStatus.IN_SYNC);
.getUpdateStatus()).isEqualTo(TargetUpdateStatus.IN_SYNC);
assertThat(actionStatusRepository.count()).isEqualTo(3);
assertThat(deploymentManagement.findActionStatusByAction(pageReq, action.getId()).getNumberOfElements())
@@ -565,7 +567,7 @@ public class ControllerManagementTest extends AbstractJpaIntegrationTest {
// nothing changed as "feedback after close" is disabled
assertThat(targetManagement.findTargetByControllerID(TestdataFactory.DEFAULT_CONTROLLER_ID).get()
.getTargetInfo().getUpdateStatus()).isEqualTo(TargetUpdateStatus.IN_SYNC);
.getUpdateStatus()).isEqualTo(TargetUpdateStatus.IN_SYNC);
// however, additional action status has been stored
assertThat(actionStatusRepository.findAll(pageReq).getNumberOfElements()).isEqualTo(4);
@@ -577,12 +579,23 @@ public class ControllerManagementTest extends AbstractJpaIntegrationTest {
@Description("Ensures that target attribute update is reflected by the repository.")
@ExpectEvents({ @Expect(type = TargetCreatedEvent.class, count = 1),
@Expect(type = TargetUpdatedEvent.class, count = 3) })
public void updateTargetAttributes() {
public void updateTargetAttributes() throws Exception {
final String controllerId = "test123";
testdataFactory.createTarget(controllerId);
addAttributeAndVerify(controllerId);
addSecondAttributeAndVerify(controllerId);
updateAttributeAndVerify(controllerId);
final Target target = testdataFactory.createTarget(controllerId);
securityRule.runAs(WithSpringAuthorityRule.withController("controller", CONTROLLER_ROLE_ANONYMOUS), () -> {
addAttributeAndVerify(controllerId);
addSecondAttributeAndVerify(controllerId);
updateAttributeAndVerify(controllerId);
return null;
});
// verify that audit information has not changed
final Target targetVerify = targetManagement.findTargetByControllerID(controllerId).get();
assertThat(targetVerify.getCreatedBy()).isEqualTo(target.getCreatedBy());
assertThat(targetVerify.getCreatedAt()).isEqualTo(target.getCreatedAt());
assertThat(targetVerify.getLastModifiedBy()).isEqualTo(target.getLastModifiedBy());
assertThat(targetVerify.getLastModifiedAt()).isEqualTo(target.getLastModifiedAt());
}
@Step
@@ -591,8 +604,7 @@ public class ControllerManagementTest extends AbstractJpaIntegrationTest {
testData.put("test1", "testdata1");
controllerManagement.updateControllerAttributes(controllerId, testData);
final Target target = targetManagement.findTargetByControllerIDWithDetails(controllerId).get();
assertThat(target.getTargetInfo().getControllerAttributes()).as("Controller Attributes are wrong")
assertThat(targetManagement.getControllerAttributes(controllerId)).as("Controller Attributes are wrong")
.isEqualTo(testData);
}
@@ -602,9 +614,8 @@ public class ControllerManagementTest extends AbstractJpaIntegrationTest {
testData.put("test2", "testdata20");
controllerManagement.updateControllerAttributes(controllerId, testData);
final Target target = targetManagement.findTargetByControllerIDWithDetails(controllerId).get();
testData.put("test1", "testdata1");
assertThat(target.getTargetInfo().getControllerAttributes()).as("Controller Attributes are wrong")
assertThat(targetManagement.getControllerAttributes(controllerId)).as("Controller Attributes are wrong")
.isEqualTo(testData);
}
@@ -615,9 +626,8 @@ public class ControllerManagementTest extends AbstractJpaIntegrationTest {
controllerManagement.updateControllerAttributes(controllerId, testData);
final Target target = targetManagement.findTargetByControllerIDWithDetails(controllerId).get();
testData.put("test2", "testdata20");
assertThat(target.getTargetInfo().getControllerAttributes()).as("Controller Attributes are wrong")
assertThat(targetManagement.getControllerAttributes(controllerId)).as("Controller Attributes are wrong")
.isEqualTo(testData);
}
}

View File

@@ -96,8 +96,8 @@ public class DeploymentManagementTest extends AbstractJpaIntegrationTest {
assertThat(action.getDistributionSet()).as("DistributionSet in action").isNotNull();
assertThat(action.getTarget()).as("Target in action").isNotNull();
assertThat(action.getTarget().getAssignedDistributionSet()).as("AssignedDistributionSet of target in action")
.isNotNull();
assertThat(deploymentManagement.getAssignedDistributionSet(action.getTarget().getControllerId()).get())
.as("AssignedDistributionSet of target in action").isNotNull();
}
@@ -213,7 +213,7 @@ public class DeploymentManagementTest extends AbstractJpaIntegrationTest {
final DistributionSet dsInstalled = action.getDistributionSet();
// check initial status
assertThat(targetManagement.findTargetByControllerID("4712").get().getTargetInfo().getUpdateStatus())
assertThat(targetManagement.findTargetByControllerID("4712").get().getUpdateStatus())
.as("target has update status").isEqualTo(TargetUpdateStatus.IN_SYNC);
// assign the two sets in a row
@@ -230,10 +230,9 @@ public class DeploymentManagementTest extends AbstractJpaIntegrationTest {
controllerManagement.addCancelActionStatus(
entityFactory.actionStatus().create(secondAction.getId()).status(Status.CANCELED));
assertThat(actionStatusRepository.findAll()).as("wrong size of actions status").hasSize(7);
assertThat(targetManagement.findTargetByControllerID("4712").get().getAssignedDistributionSet()).as("wrong ds")
.isEqualTo(dsFirst);
assertThat(targetManagement.findTargetByControllerID("4712").get().getTargetInfo().getUpdateStatus())
.as("wrong update status").isEqualTo(TargetUpdateStatus.PENDING);
assertThat(deploymentManagement.getAssignedDistributionSet("4712").get()).as("wrong ds").isEqualTo(dsFirst);
assertThat(targetManagement.findTargetByControllerID("4712").get().getUpdateStatus()).as("wrong update status")
.isEqualTo(TargetUpdateStatus.PENDING);
// we cancel first -> back to installed
deploymentManagement.cancelAction(firstAction.getId());
@@ -242,10 +241,10 @@ public class DeploymentManagementTest extends AbstractJpaIntegrationTest {
controllerManagement.addCancelActionStatus(
entityFactory.actionStatus().create(firstAction.getId()).status(Status.CANCELED));
assertThat(actionStatusRepository.findAll()).as("wrong size of action status").hasSize(9);
assertThat(targetManagement.findTargetByControllerID("4712").get().getAssignedDistributionSet())
.as("wrong assigned ds").isEqualTo(dsInstalled);
assertThat(targetManagement.findTargetByControllerID("4712").get().getTargetInfo().getUpdateStatus())
.as("wrong update status").isEqualTo(TargetUpdateStatus.IN_SYNC);
assertThat(deploymentManagement.getAssignedDistributionSet("4712").get()).as("wrong assigned ds")
.isEqualTo(dsInstalled);
assertThat(targetManagement.findTargetByControllerID("4712").get().getUpdateStatus()).as("wrong update status")
.isEqualTo(TargetUpdateStatus.IN_SYNC);
}
@Test
@@ -260,8 +259,8 @@ public class DeploymentManagementTest extends AbstractJpaIntegrationTest {
final DistributionSet dsInstalled = action.getDistributionSet();
// check initial status
assertThat(targetManagement.findTargetByControllerID("4712").get().getTargetInfo().getUpdateStatus())
.as("wrong update status").isEqualTo(TargetUpdateStatus.IN_SYNC);
assertThat(targetManagement.findTargetByControllerID("4712").get().getUpdateStatus()).as("wrong update status")
.isEqualTo(TargetUpdateStatus.IN_SYNC);
// assign the two sets in a row
JpaAction firstAction = assignSet(target, dsFirst);
@@ -277,24 +276,24 @@ public class DeploymentManagementTest extends AbstractJpaIntegrationTest {
controllerManagement.addCancelActionStatus(
entityFactory.actionStatus().create(firstAction.getId()).status(Status.CANCELED));
assertThat(actionStatusRepository.findAll()).as("wrong size of action status").hasSize(7);
assertThat(targetManagement.findTargetByControllerID("4712").get().getAssignedDistributionSet())
.as("wrong assigned ds").isEqualTo(dsSecond);
assertThat(targetManagement.findTargetByControllerID("4712").get().getTargetInfo().getUpdateStatus())
assertThat(deploymentManagement.getAssignedDistributionSet("4712").get()).as("wrong assigned ds")
.isEqualTo(dsSecond);
assertThat(targetManagement.findTargetByControllerID("4712").get().getUpdateStatus())
.as("wrong target update status").isEqualTo(TargetUpdateStatus.PENDING);
// we cancel second -> remain assigned until finished cancellation
deploymentManagement.cancelAction(secondAction.getId());
secondAction = (JpaAction) deploymentManagement.findActionWithDetails(secondAction.getId()).get();
assertThat(actionStatusRepository.findAll()).as("wrong size of action status").hasSize(8);
assertThat(targetManagement.findTargetByControllerID("4712").get().getAssignedDistributionSet())
.as("wrong assigned ds").isEqualTo(dsSecond);
assertThat(deploymentManagement.getAssignedDistributionSet("4712").get()).as("wrong assigned ds")
.isEqualTo(dsSecond);
// confirm cancellation
controllerManagement.addCancelActionStatus(
entityFactory.actionStatus().create(secondAction.getId()).status(Status.CANCELED));
// cancelled success -> back to dsInstalled
assertThat(targetManagement.findTargetByControllerID("4712").get().getAssignedDistributionSet())
.as("wrong installed ds").isEqualTo(dsInstalled);
assertThat(targetManagement.findTargetByControllerID("4712").get().getTargetInfo().getUpdateStatus())
assertThat(deploymentManagement.getAssignedDistributionSet("4712").get()).as("wrong installed ds")
.isEqualTo(dsInstalled);
assertThat(targetManagement.findTargetByControllerID("4712").get().getUpdateStatus())
.as("wrong target info update status").isEqualTo(TargetUpdateStatus.IN_SYNC);
}
@@ -308,7 +307,7 @@ public class DeploymentManagementTest extends AbstractJpaIntegrationTest {
final DistributionSet ds = testdataFactory.createDistributionSet("newDS", true);
// verify initial status
assertThat(targetManagement.findTargetByControllerID("4712").get().getTargetInfo().getUpdateStatus())
assertThat(targetManagement.findTargetByControllerID("4712").get().getUpdateStatus())
.as("wrong target info update status").isEqualTo(TargetUpdateStatus.IN_SYNC);
Action assigningAction = assignSet(target, ds);
@@ -329,9 +328,9 @@ public class DeploymentManagementTest extends AbstractJpaIntegrationTest {
// verify
assertThat(assigningAction.getStatus()).as("wrong size of status").isEqualTo(Status.CANCELED);
assertThat(targetManagement.findTargetByControllerID("4712").get().getAssignedDistributionSet())
.as("wrong assigned ds").isEqualTo(dsInstalled);
assertThat(targetManagement.findTargetByControllerID("4712").get().getTargetInfo().getUpdateStatus())
assertThat(deploymentManagement.getAssignedDistributionSet("4712").get()).as("wrong assigned ds")
.isEqualTo(dsInstalled);
assertThat(targetManagement.findTargetByControllerID("4712").get().getUpdateStatus())
.as("wrong target update status").isEqualTo(TargetUpdateStatus.IN_SYNC);
}
@@ -344,8 +343,8 @@ public class DeploymentManagementTest extends AbstractJpaIntegrationTest {
final DistributionSet ds = testdataFactory.createDistributionSet("newDS", true);
// verify initial status
assertThat(targetManagement.findTargetByControllerID("4712").get().getTargetInfo().getUpdateStatus())
.as("wrong update status").isEqualTo(TargetUpdateStatus.IN_SYNC);
assertThat(targetManagement.findTargetByControllerID("4712").get().getUpdateStatus()).as("wrong update status")
.isEqualTo(TargetUpdateStatus.IN_SYNC);
final Action assigningAction = assignSet(target, ds);
@@ -363,11 +362,10 @@ public class DeploymentManagementTest extends AbstractJpaIntegrationTest {
private JpaAction assignSet(final Target target, final DistributionSet ds) {
assignDistributionSet(ds.getId(), target.getControllerId());
assertThat(targetManagement.findTargetByControllerID(target.getControllerId()).get().getTargetInfo()
.getUpdateStatus()).as("wrong update status").isEqualTo(TargetUpdateStatus.PENDING);
assertThat(
targetManagement.findTargetByControllerID(target.getControllerId()).get().getAssignedDistributionSet())
.as("wrong assigned ds").isEqualTo(ds);
assertThat(targetManagement.findTargetByControllerID(target.getControllerId()).get().getUpdateStatus())
.as("wrong update status").isEqualTo(TargetUpdateStatus.PENDING);
assertThat(deploymentManagement.getAssignedDistributionSet(target.getControllerId()).get())
.as("wrong assigned ds").isEqualTo(ds);
final JpaAction action = actionRepository
.findByTargetAndDistributionSet(pageReq, (JpaTarget) target, (JpaDistributionSet) ds).getContent()
.get(0);
@@ -425,8 +423,7 @@ public class DeploymentManagementTest extends AbstractJpaIntegrationTest {
final List<Action> activeActionsByTarget = deploymentManagement
.findActiveActionsByTarget(t.getControllerId());
assertThat(activeActionsByTarget).as("action should not be empty").isNotEmpty();
assertThat(t.getTargetInfo().getUpdateStatus()).as("wrong target update status")
.isEqualTo(TargetUpdateStatus.PENDING);
assertThat(t.getUpdateStatus()).as("wrong target update status").isEqualTo(TargetUpdateStatus.PENDING);
for (final Action ua : activeActionsByTarget) {
assertThat(ua.getDistributionSet()).as("action has wrong ds").isEqualTo(ds);
}
@@ -564,37 +561,40 @@ public class DeploymentManagementTest extends AbstractJpaIntegrationTest {
// verifying the correctness of the assignments
for (final Target t : deployResWithDsA.getDeployedTargets()) {
assertThat(t.getAssignedDistributionSet().getId()).as("assignment is not correct").isEqualTo(dsA.getId());
assertThat(targetManagement.findTargetByControllerID(t.getControllerId()).get().getTargetInfo()
.getInstalledDistributionSet()).as("installed ds should be null").isNull();
assertThat(deploymentManagement.getAssignedDistributionSet(t.getControllerId()).get().getId())
.as("assignment is not correct").isEqualTo(dsA.getId());
assertThat(deploymentManagement.getInstalledDistributionSet(t.getControllerId()))
.as("installed ds should be null").isNotPresent();
}
for (final Target t : deployResWithDsB.getDeployedTargets()) {
assertThat(t.getAssignedDistributionSet().getId()).as("assigned ds is wrong").isEqualTo(dsB.getId());
assertThat(targetManagement.findTargetByControllerID(t.getControllerId()).get().getTargetInfo()
.getInstalledDistributionSet()).as("installed ds should be null").isNull();
assertThat(deploymentManagement.getAssignedDistributionSet(t.getControllerId()).get().getId())
.as("assigned ds is wrong").isEqualTo(dsB.getId());
assertThat(deploymentManagement.getInstalledDistributionSet(t.getControllerId()))
.as("installed ds should be null").isNotPresent();
}
for (final Target t : deployResWithDsC.getDeployedTargets()) {
assertThat(t.getAssignedDistributionSet().getId()).isEqualTo(dsC.getId());
assertThat(targetManagement.findTargetByControllerID(t.getControllerId()).get().getTargetInfo()
.getInstalledDistributionSet()).as("installed ds should not be null").isNull();
assertThat(targetManagement.findTargetByControllerID(t.getControllerId()).get().getTargetInfo()
.getUpdateStatus()).as("wrong target info update status").isEqualTo(TargetUpdateStatus.PENDING);
assertThat(deploymentManagement.getAssignedDistributionSet(t.getControllerId()).get().getId())
.isEqualTo(dsC.getId());
assertThat(deploymentManagement.getInstalledDistributionSet(t.getControllerId()))
.as("installed ds should not be null").isNotPresent();
assertThat(targetManagement.findTargetByControllerID(t.getControllerId()).get().getUpdateStatus())
.as("wrong target info update status").isEqualTo(TargetUpdateStatus.PENDING);
}
final List<Target> updatedTsDsA = testdataFactory
.sendUpdateActionStatusToTargets(deployResWithDsA.getDeployedTargets(), Status.FINISHED,
Collections.singletonList("alles gut"))
.stream().map(action -> action.getTarget()).collect(Collectors.toList());
.stream().map(Action::getTarget).collect(Collectors.toList());
// verify, that dsA is deployed correctly
assertThat(updatedTsDsA).as("ds is not deployed correctly").isEqualTo(deployResWithDsA.getDeployedTargets());
for (final Target t_ : updatedTsDsA) {
final Target t = targetManagement.findTargetByControllerID(t_.getControllerId()).get();
assertThat(t.getAssignedDistributionSet()).as("assigned ds is wrong").isEqualTo(dsA);
assertThat(targetManagement.findTargetByControllerID(t.getControllerId()).get().getTargetInfo()
.getInstalledDistributionSet()).as("installed ds is wrong").isEqualTo(dsA);
assertThat(targetManagement.findTargetByControllerID(t.getControllerId()).get().getTargetInfo()
.getUpdateStatus()).as("wrong target info update status").isEqualTo(TargetUpdateStatus.IN_SYNC);
assertThat(deploymentManagement.getAssignedDistributionSet(t.getControllerId()).get())
.as("assigned ds is wrong").isEqualTo(dsA);
assertThat(deploymentManagement.getInstalledDistributionSet(t.getControllerId()).get())
.as("installed ds is wrong").isEqualTo(dsA);
assertThat(targetManagement.findTargetByControllerID(t.getControllerId()).get().getUpdateStatus())
.as("wrong target info update status").isEqualTo(TargetUpdateStatus.IN_SYNC);
assertThat(deploymentManagement.findActiveActionsByTarget(t.getControllerId()))
.as("no actions should be active").hasSize(0);
}
@@ -609,18 +609,19 @@ public class DeploymentManagementTest extends AbstractJpaIntegrationTest {
// get final updated version of targets
final List<Target> deployResWithDsBTargets = targetManagement.findTargetByControllerID(deployResWithDsB
.getDeployedTargets().stream().map(target -> target.getControllerId()).collect(Collectors.toList()));
.getDeployedTargets().stream().map(Target::getControllerId).collect(Collectors.toList()));
assertThat(deployed2DS).as("deployed ds is wrong").containsAll(deployResWithDsBTargets);
assertThat(deployed2DS).as("deployed ds is wrong").hasSameSizeAs(deployResWithDsBTargets);
for (final Target t_ : deployed2DS) {
final Target t = targetManagement.findTargetByControllerID(t_.getControllerId()).get();
assertThat(t.getAssignedDistributionSet()).as("assigned ds is wrong").isEqualTo(dsA);
assertThat(targetManagement.findTargetByControllerID(t.getControllerId()).get().getTargetInfo()
.getInstalledDistributionSet()).as("installed ds should be null").isNull();
assertThat(targetManagement.findTargetByControllerID(t.getControllerId()).get().getTargetInfo()
.getUpdateStatus()).as("wrong target info update status").isEqualTo(TargetUpdateStatus.PENDING);
assertThat(deploymentManagement.getAssignedDistributionSet(t.getControllerId()).get())
.as("assigned ds is wrong").isEqualTo(dsA);
assertThat(deploymentManagement.getInstalledDistributionSet(t.getControllerId()))
.as("installed ds should be null").isNotPresent();
assertThat(targetManagement.findTargetByControllerID(t.getControllerId()).get().getUpdateStatus())
.as("wrong target info update status").isEqualTo(TargetUpdateStatus.PENDING);
}
}
@@ -653,7 +654,7 @@ public class DeploymentManagementTest extends AbstractJpaIntegrationTest {
distributionSetManagement.deleteDistributionSet(dsA.getId());
assertThat(distributionSetManagement.findDistributionSetById(dsA.getId()).isPresent()).isFalse();
assertThat(distributionSetManagement.findDistributionSetById(dsA.getId())).isNotPresent();
// // verify that the ds is not physically deleted
for (final DistributionSet ds : deploymentResult.getDistributionSets()) {
@@ -743,9 +744,9 @@ public class DeploymentManagementTest extends AbstractJpaIntegrationTest {
.as("Active target actions are wrong").isEqualTo(1);
assertThat(deploymentManagement.countActionsByTarget(targ.getControllerId())).as("Target actions are wrong")
.isEqualTo(1);
assertThat(targ.getTargetInfo().getUpdateStatus()).as("UpdateStatus of target is wrong")
.isEqualTo(TargetUpdateStatus.PENDING);
assertThat(targ.getAssignedDistributionSet()).as("Assigned distribution set of target is wrong").isEqualTo(dsA);
assertThat(targ.getUpdateStatus()).as("UpdateStatus of target is wrong").isEqualTo(TargetUpdateStatus.PENDING);
assertThat(deploymentManagement.getAssignedDistributionSet(targ.getControllerId()).get())
.as("Assigned distribution set of target is wrong").isEqualTo(dsA);
assertThat(deploymentManagement.findActiveActionsByTarget(targ.getControllerId()).get(0).getDistributionSet())
.as("Distribution set of actionn is wrong").isEqualTo(dsA);
assertThat(deploymentManagement.findActiveActionsByTarget(targ.getControllerId()).get(0).getDistributionSet())
@@ -762,10 +763,11 @@ public class DeploymentManagementTest extends AbstractJpaIntegrationTest {
assertEquals("active actions are wrong", 1,
deploymentManagement.findInActiveActionsByTarget(targ.getControllerId()).size());
assertEquals("tagret update status is not correct", TargetUpdateStatus.IN_SYNC,
targ.getTargetInfo().getUpdateStatus());
assertEquals("wrong assigned ds", dsA, targ.getAssignedDistributionSet());
assertEquals("wrong installed ds", dsA, targ.getTargetInfo().getInstalledDistributionSet());
assertEquals("tagret update status is not correct", TargetUpdateStatus.IN_SYNC, targ.getUpdateStatus());
assertEquals("wrong assigned ds", dsA,
deploymentManagement.getAssignedDistributionSet(targ.getControllerId()).get());
assertEquals("wrong installed ds", dsA,
deploymentManagement.getInstalledDistributionSet(targ.getControllerId()).get());
targs = assignDistributionSet(dsB.getId(), "target-id-A").getAssignedEntity();
@@ -773,12 +775,12 @@ public class DeploymentManagementTest extends AbstractJpaIntegrationTest {
assertEquals("active actions are wrong", 1,
deploymentManagement.findActiveActionsByTarget(targ.getControllerId()).size());
assertEquals("target status is wrong", TargetUpdateStatus.PENDING, targetManagement
.findTargetByControllerID(targ.getControllerId()).get().getTargetInfo().getUpdateStatus());
assertEquals("wrong assigned ds", dsB, targ.getAssignedDistributionSet());
assertEquals("target status is wrong", TargetUpdateStatus.PENDING,
targetManagement.findTargetByControllerID(targ.getControllerId()).get().getUpdateStatus());
assertEquals("wrong assigned ds", dsB,
deploymentManagement.getAssignedDistributionSet(targ.getControllerId()).get());
assertEquals("Installed ds is wrong", dsA.getId(),
targetManagement.findTargetByControllerIDWithDetails(targ.getControllerId()).get().getTargetInfo()
.getInstalledDistributionSet().getId());
deploymentManagement.getInstalledDistributionSet(targ.getControllerId()).get().getId());
assertEquals("Active ds is wrong", dsB,
deploymentManagement.findActiveActionsByTarget(targ.getControllerId()).get(0).getDistributionSet());

View File

@@ -23,7 +23,6 @@ import java.util.stream.Collectors;
import org.eclipse.hawkbit.repository.ReportManagement;
import org.eclipse.hawkbit.repository.ReportManagement.DateTypes;
import org.eclipse.hawkbit.repository.jpa.model.JpaTarget;
import org.eclipse.hawkbit.repository.jpa.model.JpaTargetInfo;
import org.eclipse.hawkbit.repository.model.Action.Status;
import org.eclipse.hawkbit.repository.model.DistributionSet;
import org.eclipse.hawkbit.repository.model.DistributionSetAssignmentResult;
@@ -504,11 +503,9 @@ public class ReportManagementTest extends AbstractJpaIntegrationTest {
for (int index = 0; index < amount; index++) {
final JpaTarget createTarget = (JpaTarget) testdataFactory.createTarget(prefix + index);
if (lastTargetQuery != null) {
final JpaTargetInfo targetInfo = (JpaTargetInfo) createTarget.getTargetInfo();
targetInfo.setNew(false);
targetInfo
createTarget
.setLastTargetQuery(lastTargetQuery.atZone(ZoneId.systemDefault()).toInstant().toEpochMilli());
targetInfoRepository.save(targetInfo);
targetRepository.save(createTarget);
}
}
}
@@ -516,10 +513,8 @@ public class ReportManagementTest extends AbstractJpaIntegrationTest {
private void createTargetsWithStatus(final String prefix, final long amount, final TargetUpdateStatus status) {
for (int index = 0; index < amount; index++) {
final JpaTarget target = new JpaTarget(prefix + index);
final Target sTarget = targetRepository.save(target);
final JpaTargetInfo targetInfo = (JpaTargetInfo) sTarget.getTargetInfo();
targetInfo.setUpdateStatus(status);
targetInfoRepository.save(targetInfo);
target.setUpdateStatus(status);
targetRepository.save(target);
}
}

View File

@@ -262,8 +262,8 @@ public class RolloutManagementTest extends AbstractJpaIntegrationTest {
@Step("Check the status of the rollout groups and the rollout")
private void verifyRolloutAndAllGroupsAreFinished(final Rollout createdRollout) {
rolloutManagement.handleRollouts();
final List<RolloutGroup> runningRolloutGroups = rolloutGroupManagement.findRolloutGroupsByRolloutId(
createdRollout.getId(), new OffsetBasedPageRequest(0, 10, new Sort(Direction.ASC, "id"))).getContent();
final List<RolloutGroup> runningRolloutGroups = rolloutGroupManagement
.findRolloutGroupsByRolloutId(createdRollout.getId(), pageReq).getContent();
assertThat(runningRolloutGroups.get(0).getStatus()).isEqualTo(RolloutGroupStatus.FINISHED);
assertThat(runningRolloutGroups.get(1).getStatus()).isEqualTo(RolloutGroupStatus.FINISHED);
assertThat(runningRolloutGroups.get(2).getStatus()).isEqualTo(RolloutGroupStatus.FINISHED);
@@ -568,13 +568,12 @@ public class RolloutManagementTest extends AbstractJpaIntegrationTest {
// 5 targets are in the group and the DS has been assigned
final List<RolloutGroup> rolloutGroups = createdRollout.getRolloutGroups();
final Page<Target> targets = rolloutGroupManagement.findRolloutGroupTargets(rolloutGroups.get(0).getId(),
new OffsetBasedPageRequest(0, 20, new Sort(Direction.ASC, "id")));
pageReq);
final List<Target> targetList = targets.getContent();
assertThat(targetList.size()).isEqualTo(5);
for (final Target t : targetList) {
final DistributionSet assignedDs = t.getAssignedDistributionSet();
assertThat(assignedDs.getId()).isEqualTo(ds.getId());
}
targets.getContent().stream().map(Target::getControllerId).map(deploymentManagement::getAssignedDistributionSet)
.forEach(d -> assertThat(d.get().getId()).isEqualTo(ds.getId()));
final List<Target> targetToCancel = new ArrayList<>();
targetToCancel.add(targetList.get(0));
@@ -674,7 +673,7 @@ public class RolloutManagementTest extends AbstractJpaIntegrationTest {
rolloutManagement.handleRollouts();
rolloutTwo = rolloutManagement.findRolloutById(rolloutTwo.getId()).get();
// 6 error targets are know running
// 6 error targets are now running
expectedTargetCountStatus = createInitStatusMap();
expectedTargetCountStatus.put(TotalTargetCountStatus.Status.RUNNING, 6L);
expectedTargetCountStatus.put(TotalTargetCountStatus.Status.FINISHED, 9L);
@@ -684,10 +683,8 @@ public class RolloutManagementTest extends AbstractJpaIntegrationTest {
final List<Target> targetList = targetPage.getContent();
// 15 targets in finished/IN_SYNC status and same DS assigned
assertThat(targetList.size()).isEqualTo(amountTargetsForRollout);
for (final Target t : targetList) {
final DistributionSet ds = t.getAssignedDistributionSet();
assertThat(ds).isEqualTo(distributionSet);
}
targetList.stream().map(Target::getControllerId).map(deploymentManagement::getAssignedDistributionSet)
.forEach(d -> assertThat(d.get()).isEqualTo(distributionSet));
}
@Test
@@ -1425,7 +1422,7 @@ public class RolloutManagementTest extends AbstractJpaIntegrationTest {
@Expect(type = RolloutGroupUpdatedEvent.class, count = 16),
@Expect(type = RolloutUpdatedEvent.class, count = 6),
@Expect(type = DistributionSetCreatedEvent.class, count = 1),
@Expect(type = TargetCreatedEvent.class, count = 25), @Expect(type = TargetUpdatedEvent.class, count = 4),
@Expect(type = TargetCreatedEvent.class, count = 25), @Expect(type = TargetUpdatedEvent.class, count = 2),
@Expect(type = TargetAssignDistributionSetEvent.class, count = 2),
@Expect(type = RolloutGroupCreatedEvent.class, count = 5),
@Expect(type = ActionCreatedEvent.class, count = 10), @Expect(type = ActionUpdatedEvent.class, count = 2),
@@ -1504,7 +1501,7 @@ public class RolloutManagementTest extends AbstractJpaIntegrationTest {
final Map<TotalTargetCountStatus.Status, Long> expectedTotalCountStates) {
for (final Map.Entry<TotalTargetCountStatus.Status, Long> entry : expectedTotalCountStates.entrySet()) {
final Long countReady = totalTargetCountStatus.getTotalTargetCountByStatus(entry.getKey());
assertThat(countReady).isEqualTo(entry.getValue());
assertThat(countReady).as("targets in status " + entry.getKey()).isEqualTo(entry.getValue());
}
}

View File

@@ -186,11 +186,9 @@ public class SoftwareManagementTest extends AbstractJpaIntegrationTest {
private Action assignSet(final JpaTarget target, final JpaDistributionSet ds) {
assignDistributionSet(ds.getId(), target.getControllerId());
assertThat(targetManagement.findTargetByControllerID(target.getControllerId()).get().getTargetInfo()
.getUpdateStatus()).isEqualTo(TargetUpdateStatus.PENDING);
assertThat(
targetManagement.findTargetByControllerID(target.getControllerId()).get().getAssignedDistributionSet())
.isEqualTo(ds);
assertThat(targetManagement.findTargetByControllerID(target.getControllerId()).get().getUpdateStatus())
.isEqualTo(TargetUpdateStatus.PENDING);
assertThat(deploymentManagement.getAssignedDistributionSet(target.getControllerId()).get()).isEqualTo(ds);
final Action action = actionRepository.findByTargetAndDistributionSet(pageReq, target, ds).getContent().get(0);
assertThat(action).isNotNull();
return action;
@@ -289,7 +287,7 @@ public class SoftwareManagementTest extends AbstractJpaIntegrationTest {
// [VERIFY EXPECTED RESULT]:
// verify: SoftwareModule is deleted
assertThat(softwareModuleRepository.findAll()).hasSize(0);
assertThat(softwareManagement.findSoftwareModuleById(unassignedModule.getId()).isPresent()).isFalse();
assertThat(softwareManagement.findSoftwareModuleById(unassignedModule.getId())).isNotPresent();
// verify: binary data of artifact is deleted
assertArtfiactNull(artifact1, artifact2);
@@ -399,8 +397,8 @@ public class SoftwareManagementTest extends AbstractJpaIntegrationTest {
// [VERIFY EXPECTED RESULT]:
// verify: SoftwareModuleX is deleted, and ModuelY still exists
assertThat(softwareModuleRepository.findAll()).hasSize(1);
assertThat(softwareManagement.findSoftwareModuleById(moduleX.getId()).isPresent()).isFalse();
assertThat(softwareManagement.findSoftwareModuleById(moduleY.getId()).isPresent()).isTrue();
assertThat(softwareManagement.findSoftwareModuleById(moduleX.getId())).isNotPresent();
assertThat(softwareManagement.findSoftwareModuleById(moduleY.getId())).isPresent();
// verify: binary data of artifact is not deleted
assertArtfiactNotNull(artifactY);
@@ -822,7 +820,7 @@ public class SoftwareManagementTest extends AbstractJpaIntegrationTest {
.createSoftwareModuleMetadata(ah.getId(), entityFactory.generateMetadata(knownKey1, knownValue1))
.getSoftwareModule();
assertThat(softwareManagement.findSoftwareModuleMetadata(ah.getId(), "doesnotexist").isPresent()).isFalse();
assertThat(softwareManagement.findSoftwareModuleMetadata(ah.getId(), "doesnotexist")).isNotPresent();
}
@Test

View File

@@ -100,7 +100,7 @@ public class SystemManagementTest extends AbstractJpaIntegrationTest {
for (int i = 0; i < tenants; i++) {
final String tenantname = "tenant" + i;
securityRule.runAs(WithSpringAuthorityRule.withUserAndTenant("bumlux", tenantname, true, true,
securityRule.runAs(WithSpringAuthorityRule.withUserAndTenant("bumlux", tenantname, true, true, false,
SpringEvalExpressions.SYSTEM_ROLE), () -> {
systemManagement.getTenantMetadata(tenantname);
if (artifactSize > 0) {

View File

@@ -209,7 +209,7 @@ public class TagManagementTest extends AbstractJpaIntegrationTest {
TargetTagAssignmentResult result = toggleTagAssignment(groupA, tag);
assertThat(result.getAlreadyAssigned()).isEqualTo(0);
assertThat(result.getAssigned()).isEqualTo(20);
assertThat(result.getAssignedEntity()).containsAll(targetManagement.findTargetsByControllerIDsWithTags(
assertThat(result.getAssignedEntity()).containsAll(targetManagement.findTargetByControllerID(
groupA.stream().map(target -> target.getControllerId()).collect(Collectors.toList())));
assertThat(result.getUnassigned()).isEqualTo(0);
assertThat(result.getUnassignedEntity()).isEmpty();
@@ -219,7 +219,7 @@ public class TagManagementTest extends AbstractJpaIntegrationTest {
result = toggleTagAssignment(concat(groupA, groupB), tag);
assertThat(result.getAlreadyAssigned()).isEqualTo(20);
assertThat(result.getAssigned()).isEqualTo(20);
assertThat(result.getAssignedEntity()).containsAll(targetManagement.findTargetsByControllerIDsWithTags(
assertThat(result.getAssignedEntity()).containsAll(targetManagement.findTargetByControllerID(
groupB.stream().map(target -> target.getControllerId()).collect(Collectors.toList())));
assertThat(result.getUnassigned()).isEqualTo(0);
assertThat(result.getUnassignedEntity()).isEmpty();
@@ -231,7 +231,7 @@ public class TagManagementTest extends AbstractJpaIntegrationTest {
assertThat(result.getAssigned()).isEqualTo(0);
assertThat(result.getAssignedEntity()).isEmpty();
assertThat(result.getUnassigned()).isEqualTo(40);
assertThat(result.getUnassignedEntity()).containsAll(targetManagement.findTargetsByControllerIDsWithTags(
assertThat(result.getUnassignedEntity()).containsAll(targetManagement.findTargetByControllerID(
concat(groupB, groupA).stream().map(target -> target.getControllerId()).collect(Collectors.toList())));
assertThat(result.getTargetTag()).isEqualTo(tag);
@@ -275,7 +275,7 @@ public class TagManagementTest extends AbstractJpaIntegrationTest {
final TargetTag toDelete = tags.iterator().next();
for (final Target target : targetRepository.findAll()) {
assertThat(targetManagement.findTargetByControllerID(target.getControllerId()).get().getTags())
assertThat(tagManagement.findAllTargetTags(pageReq, target.getControllerId()).getContent())
.contains(toDelete);
}
@@ -284,7 +284,7 @@ public class TagManagementTest extends AbstractJpaIntegrationTest {
// check
for (final Target target : targetRepository.findAll()) {
assertThat(targetManagement.findTargetByControllerID(target.getControllerId()).get().getTags())
assertThat(tagManagement.findAllTargetTags(pageReq, target.getControllerId()).getContent())
.doesNotContain(toDelete);
}
assertThat(targetTagRepository.findOne(toDelete.getId())).as("No tag should be found").isNull();

View File

@@ -604,13 +604,13 @@ public class TargetManagementSearchTest extends AbstractJpaIntegrationTest {
assertThat(result.getNumberOfElements()).isEqualTo(9);
final List<Target> expected = new ArrayList<>();
expected.addAll(targInstalled.stream().sorted(byId)
.filter(item -> lastTargetQueryAlwaysOverdue.equals(item.getTargetInfo().getLastTargetQuery()))
.filter(item -> lastTargetQueryAlwaysOverdue.equals(item.getLastTargetQuery()))
.collect(Collectors.toList()));
expected.addAll(targAssigned.stream().sorted(byId)
.filter(item -> lastTargetQueryAlwaysOverdue.equals(item.getTargetInfo().getLastTargetQuery()))
.filter(item -> lastTargetQueryAlwaysOverdue.equals(item.getLastTargetQuery()))
.collect(Collectors.toList()));
expected.addAll(notAssigned.stream().sorted(byId)
.filter(item -> lastTargetQueryAlwaysOverdue.equals(item.getTargetInfo().getLastTargetQuery()))
.filter(item -> lastTargetQueryAlwaysOverdue.equals(item.getLastTargetQuery()))
.collect(Collectors.toList()));
assertThat(result.getContent()).containsExactly(expected.toArray(new Target[0]));

View File

@@ -13,6 +13,7 @@ import static com.google.common.collect.Iterables.toArray;
import static com.google.common.collect.Lists.newArrayList;
import static java.util.stream.Collectors.toList;
import static org.assertj.core.api.Assertions.assertThat;
import static org.eclipse.hawkbit.im.authentication.SpPermission.SpringEvalExpressions.CONTROLLER_ROLE_ANONYMOUS;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.fail;
@@ -63,6 +64,40 @@ import ru.yandex.qatools.allure.annotations.Stories;
@Stories("Target Management")
public class TargetManagementTest extends AbstractJpaIntegrationTest {
@Test
@Description("Ensures that an anonymous target update is not monitored by auditing.")
@WithUser(principal = "knownPrincipal", authorities = { SpPermission.READ_TARGET, SpPermission.UPDATE_TARGET,
SpPermission.CREATE_TARGET }, allSpPermissions = false)
@ExpectEvents({ @Expect(type = TargetCreatedEvent.class, count = 1),
@Expect(type = TargetUpdatedEvent.class, count = 2) })
public void controllerAccessDoesNotChangeAuditData() throws Exception {
// create target first with "knownPrincipal" user and audit data
final String knownTargetControllerId = "target1";
final String knownCreatedBy = "knownPrincipal";
testdataFactory.createTarget(knownTargetControllerId);
targetManagement.updateTarget(entityFactory.target().update(knownTargetControllerId).description("updated1"));
final Target findTargetByControllerID = targetManagement.findTargetByControllerID(knownTargetControllerId)
.get();
assertThat(findTargetByControllerID.getCreatedBy()).isEqualTo(knownCreatedBy);
assertThat(findTargetByControllerID.getCreatedAt()).isNotNull();
assertThat(findTargetByControllerID.getLastModifiedBy()).isEqualTo(knownCreatedBy);
assertThat(findTargetByControllerID.getLastModifiedAt()).isNotNull();
// make an update, audit information should not be changed, run as
// controller principal!
securityRule.runAs(WithSpringAuthorityRule.withController("controller", CONTROLLER_ROLE_ANONYMOUS), () -> {
targetManagement.updateTarget(entityFactory.target().update("target1").description("updated2"));
return null;
});
// verify that audit information has not changed
final Target targetVerify = targetManagement.findTargetByControllerID(knownTargetControllerId).get();
assertThat(targetVerify.getCreatedBy()).isEqualTo(findTargetByControllerID.getCreatedBy());
assertThat(targetVerify.getCreatedAt()).isEqualTo(findTargetByControllerID.getCreatedAt());
assertThat(targetVerify.getLastModifiedBy()).isEqualTo(findTargetByControllerID.getLastModifiedBy());
assertThat(targetVerify.getLastModifiedAt()).isEqualTo(findTargetByControllerID.getLastModifiedAt());
}
@Test
@Description("Ensures that retrieving the target security is only permitted with the necessary permissions.")
@ExpectEvents({ @Expect(type = TargetCreatedEvent.class, count = 1) })
@@ -195,7 +230,8 @@ public class TargetManagementTest extends AbstractJpaIntegrationTest {
final List<Target> assignedTargets = targetManagement.assignTag(assignTarget, targetTag.getId());
assertThat(assignedTargets.size()).as("Assigned targets are wrong").isEqualTo(4);
assignedTargets.forEach(target -> assertThat(target.getTags().size()).isEqualTo(1));
assignedTargets.forEach(target -> assertThat(
tagManagement.findAllTargetTags(pageReq, target.getControllerId()).getNumberOfElements()).isEqualTo(1));
TargetTag findTargetTag = tagManagement.findTargetTag("Tag1").get();
assertThat(assignedTargets.size()).as("Assigned targets are wrong")
@@ -206,7 +242,8 @@ public class TargetManagementTest extends AbstractJpaIntegrationTest {
final Target unAssignTarget = targetManagement.unAssignTag("targetId123", findTargetTag.getId());
assertThat(unAssignTarget.getControllerId()).as("Controller id is wrong").isEqualTo("targetId123");
assertThat(unAssignTarget.getTags()).as("Tag size is wrong").isEmpty();
assertThat(tagManagement.findAllTargetTags(pageReq, unAssignTarget.getControllerId())).as("Tag size is wrong")
.isEmpty();
findTargetTag = tagManagement.findTargetTag("Tag1").get();
assertThat(findTargetTag.getAssignedToTargets()).as("Assigned targets are wrong").hasSize(3);
@@ -214,7 +251,9 @@ public class TargetManagementTest extends AbstractJpaIntegrationTest {
findTargetTag = tagManagement.findTargetTag("Tag1").get();
assertThat(findTargetTag.getAssignedToTargets()).as("Unassigned targets are wrong").isEmpty();
assertThat(unAssignTargets).as("Unassigned targets are wrong").hasSize(3);
unAssignTargets.forEach(target -> assertThat(target.getTags().size()).isEqualTo(0));
unAssignTargets.forEach(target -> assertThat(
tagManagement.findAllTargetTags(pageReq, unAssignTarget.getControllerId()).getNumberOfElements())
.isEqualTo(0));
}
@Test
@@ -248,10 +287,9 @@ public class TargetManagementTest extends AbstractJpaIntegrationTest {
testData.put("test1", "testdata1");
targetManagement.createTarget(entityFactory.target().create().controllerId(controllerId));
controllerManagement.updateControllerAttributes(controllerId, testData);
final Target target = controllerManagement.updateControllerAttributes(controllerId, testData);
final Target target = targetManagement.findTargetByControllerIDWithDetails(controllerId).get();
assertThat(target.getTargetInfo().getControllerAttributes()).as("Controller Attributes are wrong")
assertThat(targetManagement.getControllerAttributes(controllerId)).as("Controller Attributes are wrong")
.isEqualTo(testData);
return target;
}
@@ -287,7 +325,7 @@ public class TargetManagementTest extends AbstractJpaIntegrationTest {
entityFactory.actionStatus().create(result.getActions().get(0)).status(Status.FINISHED));
assignDistributionSet(set2.getId(), "4711");
target = targetManagement.findTargetByControllerIDWithDetails("4711").get();
target = targetManagement.findTargetByControllerID("4711").get();
// read data
assertThat(targetManagement.countTargetByAssignedDistributionSet(set.getId())).as("Target count is wrong")
@@ -298,17 +336,11 @@ public class TargetManagementTest extends AbstractJpaIntegrationTest {
.isEqualTo(1);
assertThat(targetManagement.countTargetByInstalledDistributionSet(set2.getId())).as("Target count is wrong")
.isEqualTo(0);
assertThat(target.getTargetInfo().getLastTargetQuery()).as("Target query is not work")
.isGreaterThanOrEqualTo(current);
assertThat(target.getAssignedDistributionSet()).as("Assigned ds size is wrong").isEqualTo(set2);
assertThat(target.getTargetInfo().getInstalledDistributionSet().getId()).as("Installed ds is wrong")
.isEqualTo(set.getId());
}
@Test
@Description("Ensures that repositoy returns null if given controller ID does not exist without exception.")
public void findTargetByControllerIDWithDetailsReturnsNullForNonexisting() {
assertThat(targetManagement.findTargetByControllerIDWithDetails("dsfsdfsdfsd").isPresent()).isFalse();
assertThat(target.getLastTargetQuery()).as("Target query is not work").isGreaterThanOrEqualTo(current);
assertThat(deploymentManagement.getAssignedDistributionSet("4711").get()).as("Assigned ds size is wrong")
.isEqualTo(set2);
assertThat(deploymentManagement.getInstalledDistributionSet("4711").get()).as("Installed ds is wrong")
.isEqualTo(set);
}
@Test
@@ -356,7 +388,7 @@ public class TargetManagementTest extends AbstractJpaIntegrationTest {
_target: for (final Target tl : targets) {
final Target t = targetManagement.findTargetByControllerID(tl.getControllerId()).get();
for (final Tag tt : t.getTags()) {
for (final Tag tt : tagManagement.findAllTargetTags(pageReq, tl.getControllerId())) {
for (final Tag tag : tags) {
if (tag.getName().equals(tt.getName())) {
continue _target;
@@ -375,7 +407,7 @@ public class TargetManagementTest extends AbstractJpaIntegrationTest {
final Target t = targetManagement.findTargetByControllerID(tl.getControllerId()).get();
for (final Tag tag : tags) {
for (final Tag tt : t.getTags()) {
for (final Tag tt : tagManagement.findAllTargetTags(pageReq, tl.getControllerId())) {
if (tag.getName().equals(tt.getName())) {
fail("Target should have no tags");
}
@@ -507,14 +539,16 @@ public class TargetManagementTest extends AbstractJpaIntegrationTest {
t2Tags.forEach(tag -> targetManagement.assignTag(Lists.newArrayList(t2.getControllerId()), tag.getId()));
final Target t11 = targetManagement.findTargetByControllerID(t1.getControllerId()).get();
assertThat(t11.getTags()).as("Tag size is wrong").hasSize(noT1Tags).containsAll(t1Tags);
assertThat(t11.getTags()).as("Tag size is wrong").hasSize(noT1Tags)
.doesNotContain(Iterables.toArray(t2Tags, TargetTag.class));
assertThat(tagManagement.findAllTargetTags(pageReq, t11.getControllerId()).getContent()).as("Tag size is wrong")
.hasSize(noT1Tags).containsAll(t1Tags);
assertThat(tagManagement.findAllTargetTags(pageReq, t11.getControllerId()).getContent()).as("Tag size is wrong")
.hasSize(noT1Tags).doesNotContain(Iterables.toArray(t2Tags, TargetTag.class));
final Target t21 = targetManagement.findTargetByControllerID(t2.getControllerId()).get();
assertThat(t21.getTags()).as("Tag size is wrong").hasSize(noT2Tags).containsAll(t2Tags);
assertThat(t21.getTags()).as("Tag size is wrong").hasSize(noT2Tags)
.doesNotContain(Iterables.toArray(t1Tags, TargetTag.class));
assertThat(tagManagement.findAllTargetTags(pageReq, t21.getControllerId()).getContent()).as("Tag size is wrong")
.hasSize(noT2Tags).containsAll(t2Tags);
assertThat(tagManagement.findAllTargetTags(pageReq, t21.getControllerId()).getContent()).as("Tag size is wrong")
.hasSize(noT2Tags).doesNotContain(Iterables.toArray(t1Tags, TargetTag.class));
}
@Test
@@ -644,29 +678,6 @@ public class TargetManagementTest extends AbstractJpaIntegrationTest {
checkTargetHasNotTags(targABCs, targTagC);
}
@Test
@Description("Retrieves targets by ID with lazy loading of the tags. Checks the successfull load.")
@ExpectEvents({ @Expect(type = TargetTagCreatedEvent.class, count = 1),
@Expect(type = TargetCreatedEvent.class, count = 25),
@Expect(type = TargetUpdatedEvent.class, count = 25) })
public void findTargetsByControllerIDsWithTags() {
final TargetTag targTagA = tagManagement.createTargetTag(entityFactory.tag().create().name("Targ-A-Tag"));
final List<Target> targAs = testdataFactory.createTargets(25, "target-id-A", "first description");
toggleTagAssignment(targAs, targTagA);
assertThat(targetManagement
.findTargetsByControllerIDsWithTags(targAs.stream().map(Target::getControllerId).collect(toList())))
.as("Target count is wrong").hasSize(25);
// no lazy loading exception and tag correctly assigned
assertThat(targetManagement
.findTargetsByControllerIDsWithTags(targAs.stream().map(Target::getControllerId).collect(toList()))
.stream().map(target -> target.getTags().contains(targTagA)).collect(toList()))
.as("Tags not correctly assigned").containsOnly(true);
}
@Test
@Description("Test that NO TAG functionality which gives all targets with no tag assigned.")
@ExpectEvents({ @Expect(type = TargetTagCreatedEvent.class, count = 1),
@@ -700,8 +711,7 @@ public class TargetManagementTest extends AbstractJpaIntegrationTest {
final Target findTargetByControllerID = targetManagement.findTargetByControllerID(knownTargetControllerId)
.get();
assertThat(findTargetByControllerID).isNotNull();
assertThat(findTargetByControllerID.getTargetInfo()).isNotNull();
assertThat(findTargetByControllerID.getTargetInfo().getPollStatus()).isNotNull();
assertThat(findTargetByControllerID.getPollStatus()).isNotNull();
return null;
});

View File

@@ -19,7 +19,6 @@ import org.eclipse.hawkbit.repository.model.Target;
import org.eclipse.hawkbit.repository.model.TargetFilterQuery;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Slice;
import ru.yandex.qatools.allure.annotations.Description;
@@ -146,12 +145,13 @@ public class AutoAssignCheckerTest extends AbstractJpaIntegrationTest {
final int count) {
final List<Long> targetIds = targets.stream().map(Target::getId).collect(Collectors.toList());
final Slice<Target> targetsAll = targetManagement.findTargetsAll(new PageRequest(0, 1000));
final Slice<Target> targetsAll = targetManagement.findTargetsAll(pageReq);
assertThat(targetsAll).as("Count of targets").hasSize(count);
for (final Target target : targetsAll) {
if (targetIds.contains(target.getId())) {
assertThat(target.getAssignedDistributionSet()).as("assigned DS").isEqualTo(set);
assertThat(deploymentManagement.getAssignedDistributionSet(target.getControllerId()).get())
.as("assigned DS").isEqualTo(set);
}
}

View File

@@ -170,18 +170,12 @@ public class RSQLTargetFieldTest extends AbstractJpaIntegrationTest {
@Test
@Description("Test filter target by lastTargetQuery")
public void testFilterByLastTargetQuery() throws InterruptedException {
assertRSQLQuery(
TargetFields.LASTCONTROLLERREQUESTAT.name() + "==" + target.getTargetInfo().getLastTargetQuery(), 1);
assertRSQLQuery(
TargetFields.LASTCONTROLLERREQUESTAT.name() + "!=" + target.getTargetInfo().getLastTargetQuery(), 1);
assertRSQLQuery(
TargetFields.LASTCONTROLLERREQUESTAT.name() + "=lt=" + target.getTargetInfo().getLastTargetQuery(), 0);
assertRSQLQuery(
TargetFields.LASTCONTROLLERREQUESTAT.name() + "=lt=" + target2.getTargetInfo().getLastTargetQuery(), 1);
assertRSQLQuery(
TargetFields.LASTCONTROLLERREQUESTAT.name() + "=gt=" + target.getTargetInfo().getLastTargetQuery(), 1);
assertRSQLQuery(
TargetFields.LASTCONTROLLERREQUESTAT.name() + "=gt=" + target2.getTargetInfo().getLastTargetQuery(), 0);
assertRSQLQuery(TargetFields.LASTCONTROLLERREQUESTAT.name() + "==" + target.getLastTargetQuery(), 1);
assertRSQLQuery(TargetFields.LASTCONTROLLERREQUESTAT.name() + "!=" + target.getLastTargetQuery(), 1);
assertRSQLQuery(TargetFields.LASTCONTROLLERREQUESTAT.name() + "=lt=" + target.getLastTargetQuery(), 0);
assertRSQLQuery(TargetFields.LASTCONTROLLERREQUESTAT.name() + "=lt=" + target2.getLastTargetQuery(), 1);
assertRSQLQuery(TargetFields.LASTCONTROLLERREQUESTAT.name() + "=gt=" + target.getLastTargetQuery(), 1);
assertRSQLQuery(TargetFields.LASTCONTROLLERREQUESTAT.name() + "=gt=" + target2.getLastTargetQuery(), 0);
}
private void assertRSQLQuery(final String rsqlParam, final long expcetedTargets) {