Make entities immutable and create proper update methods that state by signature what can be updated. (#342)
Signed-off-by: kaizimmerm <kai.zimmermann@bosch-si.com>
This commit is contained in:
@@ -56,10 +56,9 @@ public class RemoteTenantAwareEventTest extends AbstractRemoteEventTest {
|
||||
@Description("Verifies that target assignment event works")
|
||||
public void testTargetAssignDistributionSetEvent() {
|
||||
final DistributionSet dsA = testdataFactory.createDistributionSet("");
|
||||
final JpaAction generateAction = (JpaAction) entityFactory.generateAction();
|
||||
final JpaAction generateAction = new JpaAction();
|
||||
generateAction.setActionType(ActionType.FORCED);
|
||||
final Target generateTarget = entityFactory.generateTarget("Test");
|
||||
final Target target = targetManagement.createTarget(generateTarget);
|
||||
final Target target = testdataFactory.createTarget("Test");
|
||||
generateAction.setTarget(target);
|
||||
generateAction.setDistributionSet(dsA);
|
||||
final Action action = actionRepository.save(generateAction);
|
||||
|
||||
@@ -8,8 +8,6 @@
|
||||
*/
|
||||
package org.eclipse.hawkbit.repository.event.remote.entity;
|
||||
|
||||
import org.eclipse.hawkbit.repository.event.remote.entity.ActionCreatedEvent;
|
||||
import org.eclipse.hawkbit.repository.event.remote.entity.ActionUpdatedEvent;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaAction;
|
||||
import org.eclipse.hawkbit.repository.model.Action;
|
||||
import org.eclipse.hawkbit.repository.model.Action.ActionType;
|
||||
@@ -42,10 +40,9 @@ public class ActionEventTest extends AbstractRemoteEntityEventTest<Action> {
|
||||
|
||||
@Override
|
||||
protected Action createEntity() {
|
||||
final JpaAction generateAction = (JpaAction) entityFactory.generateAction();
|
||||
final JpaAction generateAction = new JpaAction();
|
||||
generateAction.setActionType(ActionType.FORCED);
|
||||
final Target generateTarget = entityFactory.generateTarget("Test");
|
||||
final Target target = targetManagement.createTarget(generateTarget);
|
||||
final Target target = testdataFactory.createTarget("Test");
|
||||
generateAction.setTarget(target);
|
||||
return actionRepository.save(generateAction);
|
||||
}
|
||||
|
||||
@@ -8,8 +8,6 @@
|
||||
*/
|
||||
package org.eclipse.hawkbit.repository.event.remote.entity;
|
||||
|
||||
import org.eclipse.hawkbit.repository.event.remote.entity.DistributionSetCreatedEvent;
|
||||
import org.eclipse.hawkbit.repository.event.remote.entity.DistributionSetUpdateEvent;
|
||||
import org.eclipse.hawkbit.repository.model.DistributionSet;
|
||||
import org.junit.Test;
|
||||
|
||||
@@ -38,8 +36,8 @@ public class DistributionSetEventTest extends AbstractRemoteEntityEventTest<Dist
|
||||
|
||||
@Override
|
||||
protected DistributionSet createEntity() {
|
||||
return distributionSetManagement.createDistributionSet(entityFactory.generateDistributionSet("incomplete", "2",
|
||||
"incomplete", distributionSetManagement.findDistributionSetTypeByKey("os"), null));
|
||||
return distributionSetManagement.createDistributionSet(entityFactory.distributionSet().create()
|
||||
.name("incomplete").version("2").description("incomplete").type("os"));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -8,8 +8,6 @@
|
||||
*/
|
||||
package org.eclipse.hawkbit.repository.event.remote.entity;
|
||||
|
||||
import org.eclipse.hawkbit.repository.event.remote.entity.DistributionSetTagCreatedEvent;
|
||||
import org.eclipse.hawkbit.repository.event.remote.entity.DistributionSetTagUpdateEvent;
|
||||
import org.eclipse.hawkbit.repository.model.DistributionSetTag;
|
||||
import org.junit.Test;
|
||||
|
||||
@@ -38,7 +36,7 @@ public class DistributionSetTagEventTest extends AbstractRemoteEntityEventTest<D
|
||||
|
||||
@Override
|
||||
protected DistributionSetTag createEntity() {
|
||||
return tagManagement.createDistributionSetTag(entityFactory.generateDistributionSetTag("tag1"));
|
||||
return tagManagement.createDistributionSetTag(entityFactory.tag().create().name("tag1"));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -8,8 +8,6 @@
|
||||
*/
|
||||
package org.eclipse.hawkbit.repository.event.remote.entity;
|
||||
|
||||
import org.eclipse.hawkbit.repository.event.remote.entity.RolloutUpdatedEvent;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaRollout;
|
||||
import org.eclipse.hawkbit.repository.model.DistributionSet;
|
||||
import org.eclipse.hawkbit.repository.model.Rollout;
|
||||
import org.eclipse.hawkbit.repository.model.RolloutGroup.RolloutGroupSuccessCondition;
|
||||
@@ -35,21 +33,14 @@ public class RolloutEventTest extends AbstractRemoteEntityEventTest<Rollout> {
|
||||
|
||||
@Override
|
||||
protected Rollout createEntity() {
|
||||
targetManagement.createTarget(entityFactory.generateTarget("12345"));
|
||||
final DistributionSet ds = distributionSetManagement
|
||||
.createDistributionSet(entityFactory.generateDistributionSet("incomplete", "2", "incomplete",
|
||||
distributionSetManagement.findDistributionSetTypeByKey("os"), null));
|
||||
testdataFactory.createTarget("12345");
|
||||
final DistributionSet ds = distributionSetManagement.createDistributionSet(entityFactory.distributionSet()
|
||||
.create().name("incomplete").version("2").description("incomplete").type("os"));
|
||||
|
||||
final Rollout rollout = entityFactory.generateRollout();
|
||||
rollout.setName("exampleRollout");
|
||||
rollout.setTargetFilterQuery("controllerId==*");
|
||||
rollout.setDistributionSet(ds);
|
||||
|
||||
final JpaRollout entity = (JpaRollout) rolloutManagement.createRollout(rollout, 10,
|
||||
new RolloutGroupConditionBuilder().successCondition(RolloutGroupSuccessCondition.THRESHOLD, "10")
|
||||
.build());
|
||||
|
||||
return entity;
|
||||
return rolloutManagement.createRollout(
|
||||
entityFactory.rollout().create().name("exampleRollout").targetFilterQuery("controllerId==*").set(ds),
|
||||
10, new RolloutGroupConditionBuilder().withDefaults()
|
||||
.successCondition(RolloutGroupSuccessCondition.THRESHOLD, "10").build());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -12,9 +12,6 @@ import static org.fest.assertions.api.Assertions.assertThat;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
import org.eclipse.hawkbit.repository.event.remote.entity.RolloutGroupCreatedEvent;
|
||||
import org.eclipse.hawkbit.repository.event.remote.entity.RolloutGroupUpdatedEvent;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaRollout;
|
||||
import org.eclipse.hawkbit.repository.model.DistributionSet;
|
||||
import org.eclipse.hawkbit.repository.model.Rollout;
|
||||
import org.eclipse.hawkbit.repository.model.RolloutGroup;
|
||||
@@ -49,19 +46,15 @@ public class RolloutGroupEventTest extends AbstractRemoteEntityEventTest<Rollout
|
||||
|
||||
@Override
|
||||
protected RolloutGroup createEntity() {
|
||||
targetManagement.createTarget(entityFactory.generateTarget(UUID.randomUUID().toString()));
|
||||
final DistributionSet ds = distributionSetManagement
|
||||
.createDistributionSet(entityFactory.generateDistributionSet(UUID.randomUUID().toString(), "2",
|
||||
"incomplete", distributionSetManagement.findDistributionSetTypeByKey("os"), null));
|
||||
testdataFactory.createTarget(UUID.randomUUID().toString());
|
||||
|
||||
final Rollout rollout = entityFactory.generateRollout();
|
||||
rollout.setName(UUID.randomUUID().toString());
|
||||
rollout.setTargetFilterQuery("controllerId==*");
|
||||
rollout.setDistributionSet(ds);
|
||||
final DistributionSet ds = distributionSetManagement.createDistributionSet(entityFactory.distributionSet()
|
||||
.create().name("incomplete").version("2").description("incomplete").type("os"));
|
||||
|
||||
final JpaRollout entity = (JpaRollout) rolloutManagement.createRollout(rollout, 10,
|
||||
new RolloutGroupConditionBuilder().successCondition(RolloutGroupSuccessCondition.THRESHOLD, "10")
|
||||
.build());
|
||||
final Rollout entity = rolloutManagement.createRollout(
|
||||
entityFactory.rollout().create().name("exampleRollout").targetFilterQuery("controllerId==*").set(ds),
|
||||
10, new RolloutGroupConditionBuilder().withDefaults()
|
||||
.successCondition(RolloutGroupSuccessCondition.THRESHOLD, "10").build());
|
||||
|
||||
return rolloutManagement.findRolloutById(entity.getId()).getRolloutGroups().get(0);
|
||||
}
|
||||
|
||||
@@ -49,7 +49,7 @@ public class TargetEventTest extends AbstractRemoteEntityEventTest<Target> {
|
||||
|
||||
@Override
|
||||
protected Target createEntity() {
|
||||
return targetManagement.createTarget(entityFactory.generateTarget("12345"));
|
||||
return testdataFactory.createTarget("12345");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -8,8 +8,6 @@
|
||||
*/
|
||||
package org.eclipse.hawkbit.repository.event.remote.entity;
|
||||
|
||||
import org.eclipse.hawkbit.repository.event.remote.entity.TargetTagCreatedEvent;
|
||||
import org.eclipse.hawkbit.repository.event.remote.entity.TargetTagUpdateEvent;
|
||||
import org.eclipse.hawkbit.repository.model.TargetTag;
|
||||
import org.junit.Test;
|
||||
|
||||
@@ -38,7 +36,7 @@ public class TargetTagEventTest extends AbstractRemoteEntityEventTest<TargetTag>
|
||||
|
||||
@Override
|
||||
protected TargetTag createEntity() {
|
||||
return tagManagement.createTargetTag(entityFactory.generateTargetTag("tag1"));
|
||||
return tagManagement.createTargetTag(entityFactory.tag().create().name("tag1"));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -8,13 +8,20 @@
|
||||
*/
|
||||
package org.eclipse.hawkbit.repository.jpa;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import javax.persistence.EntityManager;
|
||||
import javax.persistence.PersistenceContext;
|
||||
|
||||
import org.eclipse.hawkbit.cache.TenantAwareCacheManager;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaRollout;
|
||||
import org.eclipse.hawkbit.repository.model.Action;
|
||||
import org.eclipse.hawkbit.repository.model.Rollout;
|
||||
import org.eclipse.hawkbit.repository.test.util.AbstractIntegrationTest;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.SpringApplicationConfiguration;
|
||||
import org.springframework.transaction.annotation.Isolation;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
@SpringApplicationConfiguration(classes = { org.eclipse.hawkbit.RepositoryApplicationConfiguration.class })
|
||||
public abstract class AbstractJpaIntegrationTest extends AbstractIntegrationTest {
|
||||
@@ -69,4 +76,9 @@ public abstract class AbstractJpaIntegrationTest extends AbstractIntegrationTest
|
||||
|
||||
@Autowired
|
||||
protected TenantAwareCacheManager cacheManager;
|
||||
|
||||
@Transactional(readOnly = true, isolation = Isolation.READ_UNCOMMITTED)
|
||||
public List<Action> findActionsByRolloutAndStatus(final Rollout rollout, final Action.Status actionStatus) {
|
||||
return actionRepository.findByRolloutAndStatus((JpaRollout) rollout, actionStatus);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -197,46 +197,22 @@ public class ArtifactManagementTest extends AbstractJpaIntegrationTest {
|
||||
assertThat(binaryArtifactRepository.getArtifactBySha1(((JpaArtifact) result).getGridFsFileName())).isNull();
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for
|
||||
* {@link org.eclipse.hawkbit.repository.ArtifactManagement#findArtifact(java.lang.Long)}
|
||||
* .
|
||||
*
|
||||
* @throws IOException
|
||||
* @throws NoSuchAlgorithmException
|
||||
*/
|
||||
@Test
|
||||
@Description("Loads an local artifact based on given ID.")
|
||||
public void findArtifact() throws NoSuchAlgorithmException, IOException {
|
||||
SoftwareModule sm = new JpaSoftwareModule(softwareManagement.findSoftwareModuleTypeByKey("os"), "name 1",
|
||||
"version 1", null, null);
|
||||
sm = softwareManagement.createSoftwareModule(sm);
|
||||
|
||||
final Artifact result = artifactManagement.createArtifact(new RandomGeneratedInputStream(5 * 1024), sm.getId(),
|
||||
"file1", false);
|
||||
final Artifact result = artifactManagement.createArtifact(new RandomGeneratedInputStream(5 * 1024),
|
||||
testdataFactory.createSoftwareModuleOs().getId(), "file1", false);
|
||||
|
||||
assertThat(artifactManagement.findArtifact(result.getId())).isEqualTo(result);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for
|
||||
* {@link org.eclipse.hawkbit.repository.ArtifactManagement#loadArtifactBinary(java.lang.Long)}
|
||||
* .
|
||||
*
|
||||
* @throws IOException
|
||||
* @throws NoSuchAlgorithmException
|
||||
*/
|
||||
@Test
|
||||
@Description("Loads an artifact binary based on given ID.")
|
||||
public void loadStreamOfArtifact() throws NoSuchAlgorithmException, IOException {
|
||||
SoftwareModule sm = new JpaSoftwareModule(softwareManagement.findSoftwareModuleTypeByKey("os"), "name 1",
|
||||
"version 1", null, null);
|
||||
sm = softwareManagement.createSoftwareModule(sm);
|
||||
|
||||
final byte random[] = RandomStringUtils.random(5 * 1024).getBytes();
|
||||
|
||||
final Artifact result = artifactManagement.createArtifact(new ByteArrayInputStream(random), sm.getId(), "file1",
|
||||
false);
|
||||
final Artifact result = artifactManagement.createArtifact(new ByteArrayInputStream(random),
|
||||
testdataFactory.createSoftwareModuleOs().getId(), "file1", false);
|
||||
|
||||
try (InputStream fileInputStream = artifactManagement.loadArtifactBinary(result).getFileInputStream()) {
|
||||
assertTrue("The stored binary matches the given binary",
|
||||
@@ -259,11 +235,7 @@ public class ArtifactManagementTest extends AbstractJpaIntegrationTest {
|
||||
@Test
|
||||
@Description("Searches an artifact through the relations of a software module.")
|
||||
public void findArtifactBySoftwareModule() {
|
||||
SoftwareModule sm = new JpaSoftwareModule(osType, "name 1", "version 1", null, null);
|
||||
sm = softwareManagement.createSoftwareModule(sm);
|
||||
|
||||
SoftwareModule sm2 = new JpaSoftwareModule(osType, "name 2", "version 2", null, null);
|
||||
sm2 = softwareManagement.createSoftwareModule(sm2);
|
||||
final SoftwareModule sm = testdataFactory.createSoftwareModuleOs();
|
||||
|
||||
assertThat(artifactManagement.findArtifactBySoftwareModule(pageReq, sm.getId())).isEmpty();
|
||||
|
||||
@@ -276,8 +248,7 @@ public class ArtifactManagementTest extends AbstractJpaIntegrationTest {
|
||||
@Test
|
||||
@Description("Searches an artifact through the relations of a software module and the filename.")
|
||||
public void findByFilenameAndSoftwareModule() {
|
||||
SoftwareModule sm = new JpaSoftwareModule(osType, "name 1", "version 1", null, null);
|
||||
sm = softwareManagement.createSoftwareModule(sm);
|
||||
final SoftwareModule sm = testdataFactory.createSoftwareModuleOs();
|
||||
|
||||
assertThat(artifactManagement.findByFilenameAndSoftwareModule("file1", sm.getId())).isEmpty();
|
||||
|
||||
|
||||
@@ -11,21 +11,23 @@ package org.eclipse.hawkbit.repository.jpa;
|
||||
import static org.fest.assertions.api.Assertions.assertThat;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import javax.validation.ConstraintViolationException;
|
||||
|
||||
import org.apache.commons.lang3.RandomStringUtils;
|
||||
import org.eclipse.hawkbit.repository.RepositoryProperties;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaActionStatus;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaTarget;
|
||||
import org.eclipse.hawkbit.repository.event.remote.TargetAssignDistributionSetEvent;
|
||||
import org.eclipse.hawkbit.repository.event.remote.entity.ActionCreatedEvent;
|
||||
import org.eclipse.hawkbit.repository.event.remote.entity.ActionUpdatedEvent;
|
||||
import org.eclipse.hawkbit.repository.event.remote.entity.DistributionSetCreatedEvent;
|
||||
import org.eclipse.hawkbit.repository.event.remote.entity.TargetCreatedEvent;
|
||||
import org.eclipse.hawkbit.repository.event.remote.entity.TargetUpdatedEvent;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaAction;
|
||||
import org.eclipse.hawkbit.repository.model.Action;
|
||||
import org.eclipse.hawkbit.repository.model.Action.Status;
|
||||
import org.eclipse.hawkbit.repository.model.ActionStatus;
|
||||
import org.eclipse.hawkbit.repository.model.DistributionSet;
|
||||
import org.eclipse.hawkbit.repository.model.Target;
|
||||
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.junit.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
@@ -36,41 +38,39 @@ import ru.yandex.qatools.allure.annotations.Stories;
|
||||
@Features("Component Tests - Repository")
|
||||
@Stories("Controller Management")
|
||||
public class ControllerManagementTest extends AbstractJpaIntegrationTest {
|
||||
|
||||
@Autowired
|
||||
private RepositoryProperties repositoryProperties;
|
||||
|
||||
@Test
|
||||
@Description("Controller adds a new action status.")
|
||||
@ExpectEvents({ @Expect(type = TargetCreatedEvent.class, count = 1),
|
||||
@Expect(type = DistributionSetCreatedEvent.class, count = 1),
|
||||
@Expect(type = ActionCreatedEvent.class, count = 1), @Expect(type = ActionUpdatedEvent.class, count = 1),
|
||||
@Expect(type = TargetUpdatedEvent.class, count = 2),
|
||||
@Expect(type = TargetAssignDistributionSetEvent.class, count = 1) })
|
||||
public void controllerAddsActionStatus() {
|
||||
final Target target = new JpaTarget("4712");
|
||||
final DistributionSet ds = testdataFactory.createDistributionSet("");
|
||||
Target savedTarget = targetManagement.createTarget(target);
|
||||
|
||||
final List<Target> toAssign = new ArrayList<>();
|
||||
toAssign.add(savedTarget);
|
||||
Target savedTarget = testdataFactory.createTarget();
|
||||
|
||||
assertThat(savedTarget.getTargetInfo().getUpdateStatus()).isEqualTo(TargetUpdateStatus.UNKNOWN);
|
||||
|
||||
savedTarget = deploymentManagement.assignDistributionSet(ds, toAssign).getAssignedEntity().iterator().next();
|
||||
final Action savedAction = deploymentManagement.findActiveActionsByTarget(savedTarget).get(0);
|
||||
savedTarget = assignDistributionSet(ds.getId(), savedTarget.getControllerId()).getAssignedEntity().iterator()
|
||||
.next();
|
||||
final JpaAction savedAction = (JpaAction) deploymentManagement.findActiveActionsByTarget(savedTarget).get(0);
|
||||
|
||||
assertThat(targetManagement.findTargetByControllerID(savedTarget.getControllerId()).getTargetInfo()
|
||||
.getUpdateStatus()).isEqualTo(TargetUpdateStatus.PENDING);
|
||||
|
||||
ActionStatus actionStatusMessage = new JpaActionStatus(savedAction, Action.Status.RUNNING,
|
||||
System.currentTimeMillis());
|
||||
actionStatusMessage.addMessage("foobar");
|
||||
savedAction.setStatus(Status.RUNNING);
|
||||
controllerManagament.addUpdateActionStatus(actionStatusMessage);
|
||||
assertThat(targetManagement.findTargetByControllerID("4712").getTargetInfo().getUpdateStatus())
|
||||
.isEqualTo(TargetUpdateStatus.PENDING);
|
||||
controllerManagament.addUpdateActionStatus(
|
||||
entityFactory.actionStatus().create(savedAction.getId()).status(Action.Status.RUNNING));
|
||||
assertThat(targetManagement.findTargetByControllerID(TestdataFactory.DEFAULT_CONTROLLER_ID).getTargetInfo()
|
||||
.getUpdateStatus()).isEqualTo(TargetUpdateStatus.PENDING);
|
||||
|
||||
actionStatusMessage = new JpaActionStatus(savedAction, Action.Status.FINISHED, System.currentTimeMillis());
|
||||
actionStatusMessage.addMessage(RandomStringUtils.randomAscii(512));
|
||||
savedAction.setStatus(Status.FINISHED);
|
||||
controllerManagament.addUpdateActionStatus(actionStatusMessage);
|
||||
assertThat(targetManagement.findTargetByControllerID("4712").getTargetInfo().getUpdateStatus())
|
||||
.isEqualTo(TargetUpdateStatus.IN_SYNC);
|
||||
controllerManagament.addUpdateActionStatus(
|
||||
entityFactory.actionStatus().create(savedAction.getId()).status(Action.Status.FINISHED));
|
||||
assertThat(targetManagement.findTargetByControllerID(TestdataFactory.DEFAULT_CONTROLLER_ID).getTargetInfo()
|
||||
.getUpdateStatus()).isEqualTo(TargetUpdateStatus.IN_SYNC);
|
||||
|
||||
assertThat(actionStatusRepository.findAll(pageReq).getNumberOfElements()).isEqualTo(3);
|
||||
assertThat(deploymentManagement.findActionStatusByAction(pageReq, savedAction).getNumberOfElements())
|
||||
@@ -99,52 +99,40 @@ public class ControllerManagementTest extends AbstractJpaIntegrationTest {
|
||||
@Test
|
||||
@Description("Controller trys to finish an update process after it has been finished by an error action status.")
|
||||
public void tryToFinishUpdateProcessMoreThanOnce() {
|
||||
|
||||
// mock
|
||||
final Target target = new JpaTarget("Rabbit");
|
||||
final DistributionSet ds = testdataFactory.createDistributionSet("");
|
||||
Target savedTarget = targetManagement.createTarget(target);
|
||||
final List<Target> toAssign = new ArrayList<>();
|
||||
toAssign.add(savedTarget);
|
||||
savedTarget = deploymentManagement.assignDistributionSet(ds, toAssign).getAssignedEntity().iterator().next();
|
||||
Target savedTarget = testdataFactory.createTarget();
|
||||
savedTarget = assignDistributionSet(ds.getId(), savedTarget.getControllerId()).getAssignedEntity().iterator()
|
||||
.next();
|
||||
Action savedAction = deploymentManagement.findActiveActionsByTarget(savedTarget).get(0);
|
||||
|
||||
// test and verify
|
||||
final ActionStatus actionStatusMessage = new JpaActionStatus(savedAction, Action.Status.RUNNING,
|
||||
System.currentTimeMillis());
|
||||
actionStatusMessage.addMessage("running");
|
||||
savedAction = controllerManagament.addUpdateActionStatus(actionStatusMessage);
|
||||
assertThat(targetManagement.findTargetByControllerID("Rabbit").getTargetInfo().getUpdateStatus())
|
||||
.isEqualTo(TargetUpdateStatus.PENDING);
|
||||
savedAction = controllerManagament.addUpdateActionStatus(
|
||||
entityFactory.actionStatus().create(savedAction.getId()).status(Action.Status.RUNNING));
|
||||
assertThat(targetManagement.findTargetByControllerID(TestdataFactory.DEFAULT_CONTROLLER_ID).getTargetInfo()
|
||||
.getUpdateStatus()).isEqualTo(TargetUpdateStatus.PENDING);
|
||||
|
||||
final ActionStatus actionStatusMessage2 = new JpaActionStatus(savedAction, Action.Status.ERROR,
|
||||
System.currentTimeMillis());
|
||||
actionStatusMessage2.addMessage("error");
|
||||
savedAction = controllerManagament.addUpdateActionStatus(actionStatusMessage2);
|
||||
assertThat(targetManagement.findTargetByControllerID("Rabbit").getTargetInfo().getUpdateStatus())
|
||||
.isEqualTo(TargetUpdateStatus.ERROR);
|
||||
savedAction = controllerManagament.addUpdateActionStatus(
|
||||
entityFactory.actionStatus().create(savedAction.getId()).status(Action.Status.ERROR));
|
||||
assertThat(targetManagement.findTargetByControllerID(TestdataFactory.DEFAULT_CONTROLLER_ID).getTargetInfo()
|
||||
.getUpdateStatus()).isEqualTo(TargetUpdateStatus.ERROR);
|
||||
|
||||
// try with disabled late feedback
|
||||
repositoryProperties.setRejectActionStatusForClosedAction(true);
|
||||
final ActionStatus actionStatusMessage3 = new JpaActionStatus(savedAction, Action.Status.FINISHED,
|
||||
System.currentTimeMillis());
|
||||
actionStatusMessage3.addMessage("finish");
|
||||
savedAction = controllerManagament.addUpdateActionStatus(actionStatusMessage3);
|
||||
savedAction = controllerManagament.addUpdateActionStatus(
|
||||
entityFactory.actionStatus().create(savedAction.getId()).status(Action.Status.FINISHED));
|
||||
|
||||
// test
|
||||
assertThat(targetManagement.findTargetByControllerID("Rabbit").getTargetInfo().getUpdateStatus())
|
||||
.isEqualTo(TargetUpdateStatus.ERROR);
|
||||
assertThat(targetManagement.findTargetByControllerID(TestdataFactory.DEFAULT_CONTROLLER_ID).getTargetInfo()
|
||||
.getUpdateStatus()).isEqualTo(TargetUpdateStatus.ERROR);
|
||||
|
||||
// try with enabled late feedback
|
||||
repositoryProperties.setRejectActionStatusForClosedAction(false);
|
||||
final ActionStatus actionStatusMessage4 = new JpaActionStatus(savedAction, Action.Status.FINISHED,
|
||||
System.currentTimeMillis());
|
||||
actionStatusMessage4.addMessage("finish");
|
||||
controllerManagament.addUpdateActionStatus(actionStatusMessage3);
|
||||
controllerManagament.addUpdateActionStatus(
|
||||
entityFactory.actionStatus().create(savedAction.getId()).status(Action.Status.FINISHED));
|
||||
|
||||
// test
|
||||
assertThat(targetManagement.findTargetByControllerID("Rabbit").getTargetInfo().getUpdateStatus())
|
||||
.isEqualTo(TargetUpdateStatus.ERROR);
|
||||
assertThat(targetManagement.findTargetByControllerID(TestdataFactory.DEFAULT_CONTROLLER_ID).getTargetInfo()
|
||||
.getUpdateStatus()).isEqualTo(TargetUpdateStatus.ERROR);
|
||||
|
||||
}
|
||||
|
||||
@@ -154,16 +142,14 @@ public class ControllerManagementTest extends AbstractJpaIntegrationTest {
|
||||
public void sendUpdatesForFinishUpdateProcessDropedIfDisabled() {
|
||||
repositoryProperties.setRejectActionStatusForClosedAction(true);
|
||||
|
||||
final Action action = prepareFinishedUpdate("Rabbit");
|
||||
final Action action = prepareFinishedUpdate();
|
||||
|
||||
final ActionStatus actionStatusMessage1 = new JpaActionStatus(action, Action.Status.RUNNING,
|
||||
System.currentTimeMillis());
|
||||
actionStatusMessage1.addMessage("got some additional feedback");
|
||||
controllerManagament.addUpdateActionStatus(actionStatusMessage1);
|
||||
controllerManagament.addUpdateActionStatus(
|
||||
entityFactory.actionStatus().create(action.getId()).status(Action.Status.RUNNING));
|
||||
|
||||
// nothing changed as "feedback after close" is disabled
|
||||
assertThat(targetManagement.findTargetByControllerID("Rabbit").getTargetInfo().getUpdateStatus())
|
||||
.isEqualTo(TargetUpdateStatus.IN_SYNC);
|
||||
assertThat(targetManagement.findTargetByControllerID(TestdataFactory.DEFAULT_CONTROLLER_ID).getTargetInfo()
|
||||
.getUpdateStatus()).isEqualTo(TargetUpdateStatus.IN_SYNC);
|
||||
assertThat(actionStatusRepository.findAll(pageReq).getNumberOfElements()).isEqualTo(3);
|
||||
assertThat(deploymentManagement.findActionStatusByAction(pageReq, action).getNumberOfElements()).isEqualTo(3);
|
||||
}
|
||||
@@ -174,51 +160,15 @@ public class ControllerManagementTest extends AbstractJpaIntegrationTest {
|
||||
public void sendUpdatesForFinishUpdateProcessAcceptedIfEnabled() {
|
||||
repositoryProperties.setRejectActionStatusForClosedAction(false);
|
||||
|
||||
Action action = prepareFinishedUpdate("Rabbit");
|
||||
|
||||
final ActionStatus actionStatusMessage1 = new JpaActionStatus(action, Action.Status.RUNNING,
|
||||
System.currentTimeMillis());
|
||||
actionStatusMessage1.addMessage("got some additional feedback");
|
||||
action = controllerManagament.addUpdateActionStatus(actionStatusMessage1);
|
||||
Action action = prepareFinishedUpdate();
|
||||
action = controllerManagament.addUpdateActionStatus(
|
||||
entityFactory.actionStatus().create(action.getId()).status(Action.Status.RUNNING));
|
||||
|
||||
// nothing changed as "feedback after close" is disabled
|
||||
assertThat(targetManagement.findTargetByControllerID("Rabbit").getTargetInfo().getUpdateStatus())
|
||||
.isEqualTo(TargetUpdateStatus.IN_SYNC);
|
||||
assertThat(targetManagement.findTargetByControllerID(TestdataFactory.DEFAULT_CONTROLLER_ID).getTargetInfo()
|
||||
.getUpdateStatus()).isEqualTo(TargetUpdateStatus.IN_SYNC);
|
||||
assertThat(actionStatusRepository.findAll(pageReq).getNumberOfElements()).isEqualTo(4);
|
||||
assertThat(deploymentManagement.findActionStatusByAction(pageReq, action).getNumberOfElements()).isEqualTo(4);
|
||||
}
|
||||
|
||||
private Action prepareFinishedUpdate(final String controllerId) {
|
||||
// mock
|
||||
final Target target = new JpaTarget(controllerId);
|
||||
final DistributionSet ds = testdataFactory.createDistributionSet("");
|
||||
Target savedTarget = targetManagement.createTarget(target);
|
||||
final List<Target> toAssign = new ArrayList<>();
|
||||
toAssign.add(savedTarget);
|
||||
savedTarget = deploymentManagement.assignDistributionSet(ds, toAssign).getAssignedEntity().iterator().next();
|
||||
Action savedAction = deploymentManagement.findActiveActionsByTarget(savedTarget).get(0);
|
||||
|
||||
// test and verify
|
||||
final ActionStatus actionStatusMessage = new JpaActionStatus(savedAction, Action.Status.RUNNING,
|
||||
System.currentTimeMillis());
|
||||
actionStatusMessage.addMessage("running");
|
||||
savedAction = controllerManagament.addUpdateActionStatus(actionStatusMessage);
|
||||
assertThat(targetManagement.findTargetByControllerID(controllerId).getTargetInfo().getUpdateStatus())
|
||||
.isEqualTo(TargetUpdateStatus.PENDING);
|
||||
|
||||
final ActionStatus actionStatusMessage2 = new JpaActionStatus(savedAction, Action.Status.FINISHED,
|
||||
System.currentTimeMillis());
|
||||
actionStatusMessage2.addMessage("finish");
|
||||
savedAction = controllerManagament.addUpdateActionStatus(actionStatusMessage2);
|
||||
|
||||
// test
|
||||
assertThat(targetManagement.findTargetByControllerID(controllerId).getTargetInfo().getUpdateStatus())
|
||||
.isEqualTo(TargetUpdateStatus.IN_SYNC);
|
||||
|
||||
assertThat(actionStatusRepository.findAll(pageReq).getNumberOfElements()).isEqualTo(3);
|
||||
assertThat(deploymentManagement.findActionStatusByAction(pageReq, savedAction).getNumberOfElements())
|
||||
.isEqualTo(3);
|
||||
|
||||
return savedAction;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,14 +30,10 @@ import org.eclipse.hawkbit.repository.jpa.configuration.Constants;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaAction;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaActionStatus;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSet;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSetTag;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaSoftwareModule;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaTarget;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaTargetInfo;
|
||||
import org.eclipse.hawkbit.repository.model.Action;
|
||||
import org.eclipse.hawkbit.repository.model.Action.ActionType;
|
||||
import org.eclipse.hawkbit.repository.model.Action.Status;
|
||||
import org.eclipse.hawkbit.repository.model.ActionStatus;
|
||||
import org.eclipse.hawkbit.repository.model.ActionWithStatusCount;
|
||||
import org.eclipse.hawkbit.repository.model.DistributionSet;
|
||||
import org.eclipse.hawkbit.repository.model.DistributionSetAssignmentResult;
|
||||
@@ -56,6 +52,7 @@ import org.springframework.data.domain.Sort.Direction;
|
||||
|
||||
import com.google.common.collect.Iterables;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.collect.Sets;
|
||||
|
||||
import ru.yandex.qatools.allure.annotations.Description;
|
||||
import ru.yandex.qatools.allure.annotations.Features;
|
||||
@@ -93,7 +90,7 @@ public class DeploymentManagementTest extends AbstractJpaIntegrationTest {
|
||||
new ArrayList<DistributionSetTag>());
|
||||
final List<Target> testTarget = testdataFactory.createTargets(1);
|
||||
// one action with one action status is generated
|
||||
final Long actionId = deploymentManagement.assignDistributionSet(testDs, testTarget).getActions().get(0);
|
||||
final Long actionId = assignDistributionSet(testDs, testTarget).getActions().get(0);
|
||||
final Action action = deploymentManagement.findActionWithDetails(actionId);
|
||||
|
||||
assertThat(action.getDistributionSet()).as("DistributionSet in action").isNotNull();
|
||||
@@ -110,8 +107,8 @@ public class DeploymentManagementTest extends AbstractJpaIntegrationTest {
|
||||
new ArrayList<DistributionSetTag>());
|
||||
final List<Target> testTarget = testdataFactory.createTargets(1);
|
||||
// one action with one action status is generated
|
||||
final Action action = deploymentManagement.findActionWithDetails(
|
||||
deploymentManagement.assignDistributionSet(testDs, testTarget).getActions().get(0));
|
||||
final Action action = deploymentManagement
|
||||
.findActionWithDetails(assignDistributionSet(testDs, testTarget).getActions().get(0));
|
||||
// save 2 action status
|
||||
actionStatusRepository.save(new JpaActionStatus(action, Status.RETRIEVED, System.currentTimeMillis()));
|
||||
actionStatusRepository.save(new JpaActionStatus(action, Status.RUNNING, System.currentTimeMillis()));
|
||||
@@ -134,7 +131,8 @@ public class DeploymentManagementTest extends AbstractJpaIntegrationTest {
|
||||
}
|
||||
// not exists
|
||||
assignDS.add(Long.valueOf(100));
|
||||
final DistributionSetTag tag = tagManagement.createDistributionSetTag(new JpaDistributionSetTag("Tag1"));
|
||||
final DistributionSetTag tag = tagManagement
|
||||
.createDistributionSetTag(entityFactory.tag().create().name("Tag1"));
|
||||
|
||||
final List<DistributionSet> assignedDS = distributionSetManagement.assignTag(assignDS, tag);
|
||||
assertThat(assignedDS.size()).as("assigned ds has wrong size").isEqualTo(4);
|
||||
@@ -170,15 +168,15 @@ public class DeploymentManagementTest extends AbstractJpaIntegrationTest {
|
||||
public void multiAssigmentHistoryOverMultiplePagesResultsInTwoActiveAction() {
|
||||
|
||||
final DistributionSet cancelDs = testdataFactory.createDistributionSet("Canceled DS", "1.0",
|
||||
new ArrayList<DistributionSetTag>());
|
||||
Collections.emptyList());
|
||||
|
||||
final DistributionSet cancelDs2 = testdataFactory.createDistributionSet("Canceled DS", "1.2",
|
||||
new ArrayList<DistributionSetTag>());
|
||||
Collections.emptyList());
|
||||
|
||||
List<Target> targets = testdataFactory.createTargets(Constants.MAX_ENTRIES_IN_STATEMENT + 10);
|
||||
|
||||
targets = deploymentManagement.assignDistributionSet(cancelDs, targets).getAssignedEntity();
|
||||
targets = deploymentManagement.assignDistributionSet(cancelDs2, targets).getAssignedEntity();
|
||||
targets = assignDistributionSet(cancelDs, targets).getAssignedEntity();
|
||||
targets = assignDistributionSet(cancelDs2, targets).getAssignedEntity();
|
||||
|
||||
targetManagement.findAllTargetIds().forEach(targetIdName -> {
|
||||
assertThat(deploymentManagement.findActiveActionsByTarget(
|
||||
@@ -192,35 +190,31 @@ public class DeploymentManagementTest extends AbstractJpaIntegrationTest {
|
||||
+ "actions after canceling the second active action the first one is still running as it is not touched by the cancelation. After canceling the first one "
|
||||
+ "also the target goes back to IN_SYNC as no open action is left.")
|
||||
public void manualCancelWithMultipleAssignmentsCancelLastOneFirst() {
|
||||
JpaTarget target = new JpaTarget("4712");
|
||||
final Action action = prepareFinishedUpdate("4712", "installed", true);
|
||||
final Target target = action.getTarget();
|
||||
final DistributionSet dsFirst = testdataFactory.createDistributionSet("", true);
|
||||
dsFirst.setRequiredMigrationStep(true);
|
||||
final DistributionSet dsSecond = testdataFactory.createDistributionSet("2", true);
|
||||
final DistributionSet dsInstalled = testdataFactory.createDistributionSet("installed", true);
|
||||
|
||||
((JpaTargetInfo) target.getTargetInfo()).setInstalledDistributionSet((JpaDistributionSet) dsInstalled);
|
||||
target = (JpaTarget) targetManagement.createTarget(target);
|
||||
final DistributionSet dsInstalled = action.getDistributionSet();
|
||||
|
||||
// check initial status
|
||||
assertThat(targetManagement.findTargetByControllerID("4712").getTargetInfo().getUpdateStatus())
|
||||
.as("target has update status").isEqualTo(TargetUpdateStatus.UNKNOWN);
|
||||
.as("target has update status").isEqualTo(TargetUpdateStatus.IN_SYNC);
|
||||
|
||||
// assign the two sets in a row
|
||||
Action firstAction = assignSet(target, dsFirst);
|
||||
Action secondAction = assignSet(target, dsSecond);
|
||||
JpaAction firstAction = assignSet(target, dsFirst);
|
||||
JpaAction secondAction = assignSet(target, dsSecond);
|
||||
|
||||
assertThat(actionRepository.findAll()).as("wrong size of actions").hasSize(2);
|
||||
assertThat(actionStatusRepository.findAll()).as("wrong size of action status").hasSize(2);
|
||||
assertThat(actionRepository.findAll()).as("wrong size of actions").hasSize(3);
|
||||
assertThat(actionStatusRepository.findAll()).as("wrong size of action status").hasSize(5);
|
||||
|
||||
// we cancel second -> back to first
|
||||
deploymentManagement.cancelAction(secondAction,
|
||||
targetManagement.findTargetByControllerID(target.getControllerId()));
|
||||
secondAction = deploymentManagement.findActionWithDetails(secondAction.getId());
|
||||
secondAction = (JpaAction) deploymentManagement.findActionWithDetails(secondAction.getId());
|
||||
// confirm cancellation
|
||||
secondAction.setStatus(Status.CANCELED);
|
||||
controllerManagement
|
||||
.addCancelActionStatus(new JpaActionStatus(secondAction, Status.CANCELED, System.currentTimeMillis()));
|
||||
assertThat(actionStatusRepository.findAll()).as("wrong size of actions status").hasSize(4);
|
||||
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").getAssignedDistributionSet()).as("wrong ds")
|
||||
.isEqualTo(dsFirst);
|
||||
assertThat(targetManagement.findTargetByControllerID("4712").getTargetInfo().getUpdateStatus())
|
||||
@@ -229,12 +223,11 @@ public class DeploymentManagementTest extends AbstractJpaIntegrationTest {
|
||||
// we cancel first -> back to installed
|
||||
deploymentManagement.cancelAction(firstAction,
|
||||
targetManagement.findTargetByControllerID(target.getControllerId()));
|
||||
firstAction = deploymentManagement.findActionWithDetails(firstAction.getId());
|
||||
firstAction = (JpaAction) deploymentManagement.findActionWithDetails(firstAction.getId());
|
||||
// confirm cancellation
|
||||
firstAction.setStatus(Status.CANCELED);
|
||||
controllerManagement
|
||||
.addCancelActionStatus(new JpaActionStatus(firstAction, Status.CANCELED, System.currentTimeMillis()));
|
||||
assertThat(actionStatusRepository.findAll()).as("wrong size of action status").hasSize(6);
|
||||
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").getAssignedDistributionSet())
|
||||
.as("wrong assigned ds").isEqualTo(dsInstalled);
|
||||
assertThat(targetManagement.findTargetByControllerID("4712").getTargetInfo().getUpdateStatus())
|
||||
@@ -246,35 +239,31 @@ public class DeploymentManagementTest extends AbstractJpaIntegrationTest {
|
||||
+ "actions after canceling the first active action the system switched to second one. After canceling this one "
|
||||
+ "also the target goes back to IN_SYNC as no open action is left.")
|
||||
public void manualCancelWithMultipleAssignmentsCancelMiddleOneFirst() {
|
||||
JpaTarget target = new JpaTarget("4712");
|
||||
final Action action = prepareFinishedUpdate("4712", "installed", true);
|
||||
final Target target = action.getTarget();
|
||||
final DistributionSet dsFirst = testdataFactory.createDistributionSet("", true);
|
||||
dsFirst.setRequiredMigrationStep(true);
|
||||
final DistributionSet dsSecond = testdataFactory.createDistributionSet("2", true);
|
||||
final DistributionSet dsInstalled = testdataFactory.createDistributionSet("installed", true);
|
||||
|
||||
((JpaTargetInfo) target.getTargetInfo()).setInstalledDistributionSet((JpaDistributionSet) dsInstalled);
|
||||
target = (JpaTarget) targetManagement.createTarget(target);
|
||||
final DistributionSet dsInstalled = action.getDistributionSet();
|
||||
|
||||
// check initial status
|
||||
assertThat(targetManagement.findTargetByControllerID("4712").getTargetInfo().getUpdateStatus())
|
||||
.as("wrong update status").isEqualTo(TargetUpdateStatus.UNKNOWN);
|
||||
.as("wrong update status").isEqualTo(TargetUpdateStatus.IN_SYNC);
|
||||
|
||||
// assign the two sets in a row
|
||||
Action firstAction = assignSet(target, dsFirst);
|
||||
Action secondAction = assignSet(target, dsSecond);
|
||||
JpaAction firstAction = assignSet(target, dsFirst);
|
||||
JpaAction secondAction = assignSet(target, dsSecond);
|
||||
|
||||
assertThat(actionRepository.findAll()).as("wrong size of actions").hasSize(2);
|
||||
assertThat(actionStatusRepository.findAll()).as("wrong size of action status").hasSize(2);
|
||||
assertThat(actionRepository.findAll()).as("wrong size of actions").hasSize(3);
|
||||
assertThat(actionStatusRepository.findAll()).as("wrong size of action status").hasSize(5);
|
||||
|
||||
// we cancel first -> second is left
|
||||
deploymentManagement.cancelAction(firstAction,
|
||||
targetManagement.findTargetByControllerID(target.getControllerId()));
|
||||
// confirm cancellation
|
||||
firstAction = deploymentManagement.findActionWithDetails(firstAction.getId());
|
||||
firstAction.setStatus(Status.CANCELED);
|
||||
controllerManagement
|
||||
.addCancelActionStatus(new JpaActionStatus(firstAction, Status.CANCELED, System.currentTimeMillis()));
|
||||
assertThat(actionStatusRepository.findAll()).as("wrong size of action status").hasSize(4);
|
||||
firstAction = (JpaAction) deploymentManagement.findActionWithDetails(firstAction.getId());
|
||||
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").getAssignedDistributionSet())
|
||||
.as("wrong assigned ds").isEqualTo(dsSecond);
|
||||
assertThat(targetManagement.findTargetByControllerID("4712").getTargetInfo().getUpdateStatus())
|
||||
@@ -283,14 +272,13 @@ public class DeploymentManagementTest extends AbstractJpaIntegrationTest {
|
||||
// we cancel second -> remain assigned until finished cancellation
|
||||
deploymentManagement.cancelAction(secondAction,
|
||||
targetManagement.findTargetByControllerID(target.getControllerId()));
|
||||
secondAction = deploymentManagement.findActionWithDetails(secondAction.getId());
|
||||
assertThat(actionStatusRepository.findAll()).as("wrong size of action status").hasSize(5);
|
||||
secondAction = (JpaAction) deploymentManagement.findActionWithDetails(secondAction.getId());
|
||||
assertThat(actionStatusRepository.findAll()).as("wrong size of action status").hasSize(8);
|
||||
assertThat(targetManagement.findTargetByControllerID("4712").getAssignedDistributionSet())
|
||||
.as("wrong assigned ds").isEqualTo(dsSecond);
|
||||
// confirm cancellation
|
||||
secondAction.setStatus(Status.CANCELED);
|
||||
controllerManagement
|
||||
.addCancelActionStatus(new JpaActionStatus(secondAction, Status.CANCELED, System.currentTimeMillis()));
|
||||
controllerManagement.addCancelActionStatus(
|
||||
entityFactory.actionStatus().create(secondAction.getId()).status(Status.CANCELED));
|
||||
// cancelled success -> back to dsInstalled
|
||||
assertThat(targetManagement.findTargetByControllerID("4712").getAssignedDistributionSet())
|
||||
.as("wrong installed ds").isEqualTo(dsInstalled);
|
||||
@@ -301,26 +289,23 @@ public class DeploymentManagementTest extends AbstractJpaIntegrationTest {
|
||||
@Test
|
||||
@Description("Force Quit an Assignment. Expected behaviour is that the action is canceled and is marked as deleted. The assigned Software module")
|
||||
public void forceQuitSetActionToInactive() throws InterruptedException {
|
||||
|
||||
JpaTarget target = new JpaTarget("4712");
|
||||
final DistributionSet dsInstalled = testdataFactory.createDistributionSet("installed", true);
|
||||
((JpaTargetInfo) target.getTargetInfo()).setInstalledDistributionSet((JpaDistributionSet) dsInstalled);
|
||||
target = (JpaTarget) targetManagement.createTarget(target);
|
||||
final Action action = prepareFinishedUpdate("4712", "installed", true);
|
||||
Target target = action.getTarget();
|
||||
final DistributionSet dsInstalled = action.getDistributionSet();
|
||||
|
||||
final DistributionSet ds = testdataFactory.createDistributionSet("newDS", true);
|
||||
ds.setRequiredMigrationStep(true);
|
||||
|
||||
// verify initial status
|
||||
assertThat(targetManagement.findTargetByControllerID("4712").getTargetInfo().getUpdateStatus())
|
||||
.as("wrong target info update status").isEqualTo(TargetUpdateStatus.UNKNOWN);
|
||||
.as("wrong target info update status").isEqualTo(TargetUpdateStatus.IN_SYNC);
|
||||
|
||||
Action assigningAction = assignSet(target, ds);
|
||||
|
||||
// verify assignment
|
||||
assertThat(actionRepository.findAll()).as("wrong size of action").hasSize(1);
|
||||
assertThat(actionStatusRepository.findAll()).as("wrong size of action status").hasSize(1);
|
||||
assertThat(actionRepository.findAll()).as("wrong size of action").hasSize(2);
|
||||
assertThat(actionStatusRepository.findAll()).as("wrong size of action status").hasSize(4);
|
||||
|
||||
target = (JpaTarget) targetManagement.findTargetByControllerID(target.getControllerId());
|
||||
target = targetManagement.findTargetByControllerID(target.getControllerId());
|
||||
|
||||
// force quit assignment
|
||||
deploymentManagement.cancelAction(assigningAction, target);
|
||||
@@ -341,24 +326,20 @@ public class DeploymentManagementTest extends AbstractJpaIntegrationTest {
|
||||
@Test
|
||||
@Description("Force Quit an not canceled Assignment. Expected behaviour is that the action can not be force quit and there is thrown an exception.")
|
||||
public void forceQuitNotAllowedThrowsException() {
|
||||
|
||||
Target target = new JpaTarget("4712");
|
||||
final DistributionSet dsInstalled = testdataFactory.createDistributionSet("installed", true);
|
||||
((JpaTargetInfo) target.getTargetInfo()).setInstalledDistributionSet((JpaDistributionSet) dsInstalled);
|
||||
target = targetManagement.createTarget(target);
|
||||
final Action action = prepareFinishedUpdate("4712", "installed", true);
|
||||
final Target target = action.getTarget();
|
||||
|
||||
final DistributionSet ds = testdataFactory.createDistributionSet("newDS", true);
|
||||
ds.setRequiredMigrationStep(true);
|
||||
|
||||
// verify initial status
|
||||
assertThat(targetManagement.findTargetByControllerID("4712").getTargetInfo().getUpdateStatus())
|
||||
.as("wrong update status").isEqualTo(TargetUpdateStatus.UNKNOWN);
|
||||
.as("wrong update status").isEqualTo(TargetUpdateStatus.IN_SYNC);
|
||||
|
||||
final Action assigningAction = assignSet(target, ds);
|
||||
|
||||
// verify assignment
|
||||
assertThat(actionRepository.findAll()).as("wrong size of action").hasSize(1);
|
||||
assertThat(actionStatusRepository.findAll()).as("wrong size of action status").hasSize(1);
|
||||
assertThat(actionRepository.findAll()).as("wrong size of action").hasSize(2);
|
||||
assertThat(actionStatusRepository.findAll()).as("wrong size of action status").hasSize(4);
|
||||
|
||||
// force quit assignment
|
||||
try {
|
||||
@@ -368,14 +349,14 @@ public class DeploymentManagementTest extends AbstractJpaIntegrationTest {
|
||||
}
|
||||
}
|
||||
|
||||
private Action assignSet(final Target target, final DistributionSet ds) {
|
||||
deploymentManagement.assignDistributionSet(ds.getId(), new String[] { target.getControllerId() });
|
||||
private JpaAction assignSet(final Target target, final DistributionSet ds) {
|
||||
assignDistributionSet(ds.getId(), target.getControllerId());
|
||||
assertThat(
|
||||
targetManagement.findTargetByControllerID(target.getControllerId()).getTargetInfo().getUpdateStatus())
|
||||
.as("wrong update status").isEqualTo(TargetUpdateStatus.PENDING);
|
||||
assertThat(targetManagement.findTargetByControllerID(target.getControllerId()).getAssignedDistributionSet())
|
||||
.as("wrong assigned ds").isEqualTo(ds);
|
||||
final Action action = actionRepository
|
||||
final JpaAction action = actionRepository
|
||||
.findByTargetAndDistributionSet(pageReq, (JpaTarget) target, (JpaDistributionSet) ds).getContent()
|
||||
.get(0);
|
||||
assertThat(action).as("action should not be null").isNotNull();
|
||||
@@ -395,16 +376,15 @@ public class DeploymentManagementTest extends AbstractJpaIntegrationTest {
|
||||
eventHandlerStub.setExpectedNumberOfEvents(20);
|
||||
|
||||
final String myCtrlIDPref = "myCtrlID";
|
||||
final Iterable<Target> savedNakedTargets = targetManagement
|
||||
.createTargets(testdataFactory.generateTargets(10, myCtrlIDPref, "first description"));
|
||||
final Iterable<Target> savedNakedTargets = testdataFactory.createTargets(10, myCtrlIDPref, "first description");
|
||||
|
||||
final String myDeployedCtrlIDPref = "myDeployedCtrlID";
|
||||
List<Target> savedDeployedTargets = targetManagement
|
||||
.createTargets(testdataFactory.generateTargets(20, myDeployedCtrlIDPref, "first description"));
|
||||
List<Target> savedDeployedTargets = testdataFactory.createTargets(20, myDeployedCtrlIDPref,
|
||||
"first description");
|
||||
|
||||
final DistributionSet ds = testdataFactory.createDistributionSet("");
|
||||
|
||||
deploymentManagement.assignDistributionSet(ds, savedDeployedTargets);
|
||||
assignDistributionSet(ds, savedDeployedTargets);
|
||||
|
||||
// verify that one Action for each assignDistributionSet
|
||||
assertThat(actionRepository.findAll(pageReq).getNumberOfElements()).as("wrong size of actions").isEqualTo(20);
|
||||
@@ -450,18 +430,15 @@ public class DeploymentManagementTest extends AbstractJpaIntegrationTest {
|
||||
|
||||
final List<Target> targets = testdataFactory.createTargets(10);
|
||||
|
||||
final SoftwareModule ah = softwareManagement
|
||||
.createSoftwareModule(new JpaSoftwareModule(appType, "agent-hub", "1.0.1", null, ""));
|
||||
final SoftwareModule jvm = softwareManagement
|
||||
.createSoftwareModule(new JpaSoftwareModule(runtimeType, "oracle-jre", "1.7.2", null, ""));
|
||||
final SoftwareModule os = softwareManagement
|
||||
.createSoftwareModule(new JpaSoftwareModule(osType, "poky", "3.0.2", null, ""));
|
||||
final SoftwareModule ah = testdataFactory.createSoftwareModuleApp();
|
||||
final SoftwareModule os = testdataFactory.createSoftwareModuleOs();
|
||||
|
||||
final DistributionSet incomplete = distributionSetManagement.createDistributionSet(
|
||||
new JpaDistributionSet("incomplete", "v1", "", standardDsType, Lists.newArrayList(ah, jvm)));
|
||||
final DistributionSet incomplete = distributionSetManagement
|
||||
.createDistributionSet(entityFactory.distributionSet().create().name("incomplete").version("v1")
|
||||
.type(standardDsType).modules(Lists.newArrayList(ah.getId())));
|
||||
|
||||
try {
|
||||
deploymentManagement.assignDistributionSet(incomplete, targets);
|
||||
assignDistributionSet(incomplete, targets);
|
||||
fail("expected IncompleteDistributionSetException");
|
||||
} catch (final IncompleteDistributionSetException ex) {
|
||||
}
|
||||
@@ -471,13 +448,13 @@ public class DeploymentManagementTest extends AbstractJpaIntegrationTest {
|
||||
final List<TargetAssignDistributionSetEvent> events = eventHandlerStub.getEvents(5, TimeUnit.SECONDS);
|
||||
assertThat(events).as("events should be empty").isEmpty();
|
||||
|
||||
incomplete.addModule(os);
|
||||
final DistributionSet nowComplete = distributionSetManagement.updateDistributionSet(incomplete);
|
||||
final DistributionSet nowComplete = distributionSetManagement.assignSoftwareModules(incomplete.getId(),
|
||||
Sets.newHashSet(os.getId()));
|
||||
|
||||
eventHandlerStub.setExpectedNumberOfEvents(10);
|
||||
|
||||
assertThat(deploymentManagement.assignDistributionSet(nowComplete, targets).getAssigned())
|
||||
.as("assign ds doesn't work").isEqualTo(10);
|
||||
assertThat(assignDistributionSet(nowComplete, targets).getAssigned()).as("assign ds doesn't work")
|
||||
.isEqualTo(10);
|
||||
|
||||
assertTargetAssignDistributionSetEvents(targets, nowComplete, eventHandlerStub.getEvents(15, TimeUnit.SECONDS));
|
||||
}
|
||||
@@ -590,8 +567,10 @@ public class DeploymentManagementTest extends AbstractJpaIntegrationTest {
|
||||
.as("wrong target info update status").isEqualTo(TargetUpdateStatus.PENDING);
|
||||
}
|
||||
|
||||
final List<Target> updatedTsDsA = sendUpdateActionStatusToTargets(dsA, deployResWithDsA.getDeployedTargets(),
|
||||
Status.FINISHED, new String[] { "alles gut" });
|
||||
final List<Target> updatedTsDsA = testdataFactory
|
||||
.sendUpdateActionStatusToTargets(deployResWithDsA.getDeployedTargets(), Status.FINISHED,
|
||||
Collections.singletonList("alles gut"))
|
||||
.stream().map(action -> action.getTarget()).collect(Collectors.toList());
|
||||
|
||||
// verify, that dsA is deployed correctly
|
||||
assertThat(updatedTsDsA).as("ds is not deployed correctly").isEqualTo(deployResWithDsA.getDeployedTargets());
|
||||
@@ -609,8 +588,8 @@ public class DeploymentManagementTest extends AbstractJpaIntegrationTest {
|
||||
// remove updActB from
|
||||
// activeActions, add a corresponding cancelAction and another
|
||||
// UpdateAction for dsA
|
||||
final Iterable<Target> deployed2DS = deploymentManagement
|
||||
.assignDistributionSet(dsA, deployResWithDsB.getDeployedTargets()).getAssignedEntity();
|
||||
final Iterable<Target> deployed2DS = assignDistributionSet(dsA, deployResWithDsB.getDeployedTargets())
|
||||
.getAssignedEntity();
|
||||
actionRepository.findByDistributionSet(pageRequest, dsA).getContent().get(1);
|
||||
|
||||
// get final updated version of targets
|
||||
@@ -666,7 +645,7 @@ public class DeploymentManagementTest extends AbstractJpaIntegrationTest {
|
||||
distributionSetManagement.deleteDistributionSet(ds.getId());
|
||||
final DistributionSet foundDS = distributionSetManagement.findDistributionSetById(ds.getId());
|
||||
assertThat(foundDS).as("founded should not be null").isNotNull();
|
||||
assertThat(foundDS.isDeleted()).as("founded ds should be deleted").isTrue();
|
||||
assertThat(foundDS.isDeleted()).as("found ds should be deleted").isTrue();
|
||||
}
|
||||
|
||||
// verify that deleted attribute is used correctly
|
||||
@@ -678,8 +657,8 @@ public class DeploymentManagementTest extends AbstractJpaIntegrationTest {
|
||||
assertThat(allFoundDS).as("wrong size of founded ds").hasSize(noOfDistributionSets);
|
||||
|
||||
for (final DistributionSet ds : deploymentResult.getDistributionSets()) {
|
||||
sendUpdateActionStatusToTargets(ds, deploymentResult.getDeployedTargets(), Status.FINISHED,
|
||||
"blabla alles gut");
|
||||
testdataFactory.sendUpdateActionStatusToTargets(deploymentResult.getDeployedTargets(), Status.FINISHED,
|
||||
Collections.singletonList("blabla alles gut"));
|
||||
}
|
||||
// try to delete again
|
||||
distributionSetManagement.deleteDistributionSet(deploymentResult.getDistributionSetIDs()
|
||||
@@ -713,8 +692,8 @@ public class DeploymentManagementTest extends AbstractJpaIntegrationTest {
|
||||
deployedTargetPrefix, noOfDeployedTargets, noOfDistributionSets, "myTestDS");
|
||||
|
||||
for (final DistributionSet ds : deploymentResult.getDistributionSets()) {
|
||||
sendUpdateActionStatusToTargets(ds, deploymentResult.getDeployedTargets(), Status.FINISHED,
|
||||
"blabla alles gut");
|
||||
testdataFactory.sendUpdateActionStatusToTargets(deploymentResult.getDeployedTargets(), Status.FINISHED,
|
||||
Collections.singletonList("blabla alles gut"));
|
||||
}
|
||||
|
||||
assertThat(targetManagement.countTargetsAll()).as("size of targets is wrong").isNotZero();
|
||||
@@ -728,47 +707,17 @@ public class DeploymentManagementTest extends AbstractJpaIntegrationTest {
|
||||
assertThat(actionStatusRepository.count()).as("size of action status is wrong").isZero();
|
||||
}
|
||||
|
||||
private List<Target> sendUpdateActionStatusToTargets(final DistributionSet dsA, final Iterable<Target> targs,
|
||||
final Status status, final String... msgs) {
|
||||
final List<Target> result = new ArrayList<>();
|
||||
for (final Target t : targs) {
|
||||
final List<Action> findByTarget = actionRepository.findByTarget((JpaTarget) t);
|
||||
for (final Action action : findByTarget) {
|
||||
result.add(sendUpdateActionStatusToTarget(status, action, t, msgs));
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private Target sendUpdateActionStatusToTarget(final Status status, final Action updActA, final Target t,
|
||||
final String... msgs) {
|
||||
updActA.setStatus(status);
|
||||
|
||||
final ActionStatus statusMessages = new JpaActionStatus();
|
||||
statusMessages.setAction(updActA);
|
||||
statusMessages.setOccurredAt(System.currentTimeMillis());
|
||||
statusMessages.setStatus(status);
|
||||
for (final String msg : msgs) {
|
||||
statusMessages.addMessage(msg);
|
||||
}
|
||||
controllerManagament.addUpdateActionStatus(statusMessages);
|
||||
return targetManagement.findTargetByControllerID(t.getControllerId());
|
||||
}
|
||||
|
||||
@Test
|
||||
@Description("Testing if changing target and the status without refreshing the entities from the DB (e.g. concurrent changes from UI and from controller) works")
|
||||
public void alternatingAssignmentAndAddUpdateActionStatus() {
|
||||
|
||||
final DistributionSet dsA = testdataFactory.createDistributionSet("a");
|
||||
final DistributionSet dsB = testdataFactory.createDistributionSet("b");
|
||||
Target targ = targetManagement.createTarget(testdataFactory.generateTarget("target-id-A", "first description"));
|
||||
|
||||
List<Target> targs = new ArrayList<>();
|
||||
targs.add(targ);
|
||||
List<Target> targs = Lists.newArrayList(testdataFactory.createTarget("target-id-A"));
|
||||
|
||||
// doing the assignment
|
||||
targs = deploymentManagement.assignDistributionSet(dsA, targs).getAssignedEntity();
|
||||
targ = targetManagement.findTargetByControllerID(targs.iterator().next().getControllerId());
|
||||
targs = assignDistributionSet(dsA, targs).getAssignedEntity();
|
||||
Target targ = targetManagement.findTargetByControllerID(targs.iterator().next().getControllerId());
|
||||
|
||||
// checking the revisions of the created entities
|
||||
// verifying that the revision of the object and the revision within the
|
||||
@@ -789,11 +738,8 @@ public class DeploymentManagementTest extends AbstractJpaIntegrationTest {
|
||||
.as("Installed distribution set of action should be null").isNotNull();
|
||||
|
||||
final Page<Action> updAct = actionRepository.findByDistributionSet(pageReq, (JpaDistributionSet) dsA);
|
||||
final Action action = updAct.getContent().get(0);
|
||||
action.setStatus(Status.FINISHED);
|
||||
final ActionStatus statusMessage = new JpaActionStatus((JpaAction) action, Status.FINISHED,
|
||||
System.currentTimeMillis(), "");
|
||||
controllerManagament.addUpdateActionStatus(statusMessage);
|
||||
controllerManagament.addUpdateActionStatus(
|
||||
entityFactory.actionStatus().create(updAct.getContent().get(0).getId()).status(Status.FINISHED));
|
||||
|
||||
targ = targetManagement.findTargetByControllerID(targ.getControllerId());
|
||||
|
||||
@@ -805,8 +751,7 @@ public class DeploymentManagementTest extends AbstractJpaIntegrationTest {
|
||||
assertEquals("wrong assigned ds", dsA, targ.getAssignedDistributionSet());
|
||||
assertEquals("wrong installed ds", dsA, targ.getTargetInfo().getInstalledDistributionSet());
|
||||
|
||||
targs = deploymentManagement.assignDistributionSet(dsB.getId(), new String[] { "target-id-A" })
|
||||
.getAssignedEntity();
|
||||
targs = assignDistributionSet(dsB.getId(), "target-id-A").getAssignedEntity();
|
||||
|
||||
targ = targs.iterator().next();
|
||||
|
||||
@@ -828,15 +773,12 @@ public class DeploymentManagementTest extends AbstractJpaIntegrationTest {
|
||||
public void checkThatDsRevisionsIsNotChangedWithTargetAssignment() {
|
||||
final DistributionSet dsA = testdataFactory.createDistributionSet("a");
|
||||
testdataFactory.createDistributionSet("b");
|
||||
Target targ = targetManagement.createTarget(testdataFactory.generateTarget("target-id-A", "first description"));
|
||||
final Target targ = testdataFactory.createTarget("target-id-A");
|
||||
|
||||
assertThat(dsA.getOptLockRevision()).as("lock revision is wrong").isEqualTo(
|
||||
distributionSetManagement.findDistributionSetByIdWithDetails(dsA.getId()).getOptLockRevision());
|
||||
|
||||
final List<Target> targs = new ArrayList<>();
|
||||
targs.add(targ);
|
||||
final Iterable<Target> savedTargs = deploymentManagement.assignDistributionSet(dsA, targs).getAssignedEntity();
|
||||
targ = savedTargs.iterator().next();
|
||||
assignDistributionSet(dsA, Lists.newArrayList(targ));
|
||||
|
||||
assertThat(dsA.getOptLockRevision()).as("lock revision is wrong").isEqualTo(
|
||||
distributionSetManagement.findDistributionSetByIdWithDetails(dsA.getId()).getOptLockRevision());
|
||||
@@ -846,12 +788,13 @@ public class DeploymentManagementTest extends AbstractJpaIntegrationTest {
|
||||
@Description("Tests the switch from a soft to hard update by API")
|
||||
public void forceSoftAction() {
|
||||
// prepare
|
||||
final Target target = targetManagement.createTarget(new JpaTarget("knownControllerId"));
|
||||
final Target target = testdataFactory.createTarget("knownControllerId");
|
||||
final DistributionSet ds = testdataFactory.createDistributionSet("a");
|
||||
// assign ds to create an action
|
||||
final DistributionSetAssignmentResult assignDistributionSet = deploymentManagement.assignDistributionSet(
|
||||
ds.getId(), ActionType.SOFT,
|
||||
org.eclipse.hawkbit.repository.model.RepositoryModelConstants.NO_FORCE_TIME, target.getControllerId());
|
||||
org.eclipse.hawkbit.repository.model.RepositoryModelConstants.NO_FORCE_TIME,
|
||||
Lists.newArrayList(target.getControllerId()));
|
||||
final Action action = deploymentManagement.findActionWithDetails(assignDistributionSet.getActions().get(0));
|
||||
// verify preparation
|
||||
Action findAction = deploymentManagement.findAction(action.getId());
|
||||
@@ -869,12 +812,13 @@ public class DeploymentManagementTest extends AbstractJpaIntegrationTest {
|
||||
@Description("Tests the switch from a hard to hard update by API, e.g. which in fact should not change anything.")
|
||||
public void forceAlreadyForcedActionNothingChanges() {
|
||||
// prepare
|
||||
final Target target = targetManagement.createTarget(new JpaTarget("knownControllerId"));
|
||||
final Target target = testdataFactory.createTarget("knownControllerId");
|
||||
final DistributionSet ds = testdataFactory.createDistributionSet("a");
|
||||
// assign ds to create an action
|
||||
final DistributionSetAssignmentResult assignDistributionSet = deploymentManagement.assignDistributionSet(
|
||||
ds.getId(), ActionType.FORCED,
|
||||
org.eclipse.hawkbit.repository.model.RepositoryModelConstants.NO_FORCE_TIME, target.getControllerId());
|
||||
org.eclipse.hawkbit.repository.model.RepositoryModelConstants.NO_FORCE_TIME,
|
||||
Lists.newArrayList(target.getControllerId()));
|
||||
final Action action = deploymentManagement.findActionWithDetails(assignDistributionSet.getActions().get(0));
|
||||
// verify perparation
|
||||
Action findAction = deploymentManagement.findAction(action.getId());
|
||||
@@ -916,11 +860,11 @@ public class DeploymentManagementTest extends AbstractJpaIntegrationTest {
|
||||
private DeploymentResult prepareComplexRepo(final String undeployedTargetPrefix, final int noOfUndeployedTargets,
|
||||
final String deployedTargetPrefix, final int noOfDeployedTargets, final int noOfDistributionSets,
|
||||
final String distributionSetPrefix) {
|
||||
final Iterable<Target> nakedTargets = targetManagement.createTargets(
|
||||
testdataFactory.generateTargets(noOfUndeployedTargets, undeployedTargetPrefix, "first description"));
|
||||
final Iterable<Target> nakedTargets = testdataFactory.createTargets(noOfUndeployedTargets,
|
||||
undeployedTargetPrefix, "first description");
|
||||
|
||||
List<Target> deployedTargets = targetManagement.createTargets(
|
||||
testdataFactory.generateTargets(noOfDeployedTargets, deployedTargetPrefix, "first description"));
|
||||
List<Target> deployedTargets = testdataFactory.createTargets(noOfDeployedTargets, deployedTargetPrefix,
|
||||
"first description");
|
||||
|
||||
// creating 10 DistributionSets
|
||||
final Collection<DistributionSet> dsList = testdataFactory.createDistributionSets(distributionSetPrefix,
|
||||
@@ -931,7 +875,7 @@ public class DeploymentManagementTest extends AbstractJpaIntegrationTest {
|
||||
// assigning all DistributionSet to the Target in the list
|
||||
// deployedTargets
|
||||
for (final DistributionSet ds : dsList) {
|
||||
deployedTargets = deploymentManagement.assignDistributionSet(ds, deployedTargets).getAssignedEntity();
|
||||
deployedTargets = assignDistributionSet(ds, deployedTargets).getAssignedEntity();
|
||||
}
|
||||
|
||||
final DeploymentResult deploymentResult = new DeploymentResult(deployedTargets, nakedTargets, dsList,
|
||||
@@ -962,10 +906,6 @@ public class DeploymentManagementTest extends AbstractJpaIntegrationTest {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
*/
|
||||
private class DeploymentResult {
|
||||
final List<Long> deployedTargetIDs = new ArrayList<>();
|
||||
final List<Long> undeployedTargetIDs = new ArrayList<>();
|
||||
|
||||
@@ -13,38 +13,25 @@ import static org.junit.Assert.fail;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.eclipse.hawkbit.repository.DistributionSetManagement;
|
||||
import org.eclipse.hawkbit.repository.exception.DistributionSetTypeUndefinedException;
|
||||
import org.eclipse.hawkbit.repository.builder.DistributionSetCreate;
|
||||
import org.eclipse.hawkbit.repository.exception.EntityAlreadyExistsException;
|
||||
import org.eclipse.hawkbit.repository.exception.EntityLockedException;
|
||||
import org.eclipse.hawkbit.repository.exception.EntityReadOnlyException;
|
||||
import org.eclipse.hawkbit.repository.exception.UnsupportedSoftwareModuleForThisDistributionSetException;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaActionStatus;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSet;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSetMetadata;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSetTag;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSetType;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaRollout;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaSoftwareModule;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaTarget;
|
||||
import org.eclipse.hawkbit.repository.model.Action;
|
||||
import org.eclipse.hawkbit.repository.model.Action.Status;
|
||||
import org.eclipse.hawkbit.repository.model.ActionStatus;
|
||||
import org.eclipse.hawkbit.repository.model.DistributionSet;
|
||||
import org.eclipse.hawkbit.repository.model.DistributionSetAssignmentResult;
|
||||
import org.eclipse.hawkbit.repository.model.DistributionSetFilter.DistributionSetFilterBuilder;
|
||||
import org.eclipse.hawkbit.repository.model.DistributionSetMetadata;
|
||||
import org.eclipse.hawkbit.repository.model.DistributionSetTag;
|
||||
import org.eclipse.hawkbit.repository.model.DistributionSetType;
|
||||
import org.eclipse.hawkbit.repository.model.Rollout;
|
||||
import org.eclipse.hawkbit.repository.model.RolloutGroup.RolloutGroupErrorAction;
|
||||
import org.eclipse.hawkbit.repository.model.RolloutGroup.RolloutGroupErrorCondition;
|
||||
import org.eclipse.hawkbit.repository.model.RolloutGroup.RolloutGroupSuccessCondition;
|
||||
import org.eclipse.hawkbit.repository.model.RolloutGroupConditionBuilder;
|
||||
import org.eclipse.hawkbit.repository.model.RolloutGroupConditions;
|
||||
import org.eclipse.hawkbit.repository.model.SoftwareModule;
|
||||
import org.eclipse.hawkbit.repository.model.Target;
|
||||
import org.eclipse.hawkbit.repository.test.util.WithUser;
|
||||
@@ -54,6 +41,7 @@ import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.PageRequest;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.collect.Sets;
|
||||
|
||||
import ru.yandex.qatools.allure.annotations.Description;
|
||||
import ru.yandex.qatools.allure.annotations.Features;
|
||||
@@ -70,44 +58,41 @@ public class DistributionSetManagementTest extends AbstractJpaIntegrationTest {
|
||||
@Test
|
||||
@Description("Tests the successfull module update of unused distribution set type which is in fact allowed.")
|
||||
public void updateUnassignedDistributionSetTypeModules() {
|
||||
DistributionSetType updatableType = distributionSetManagement
|
||||
.createDistributionSetType(new JpaDistributionSetType("updatableType", "to be deleted", ""));
|
||||
DistributionSetType updatableType = distributionSetManagement.createDistributionSetType(
|
||||
entityFactory.distributionSetType().create().key("updatableType").name("to be deleted"));
|
||||
assertThat(distributionSetManagement.findDistributionSetTypeByKey("updatableType").getMandatoryModuleTypes())
|
||||
.isEmpty();
|
||||
|
||||
// add OS
|
||||
updatableType.addMandatoryModuleType(osType);
|
||||
updatableType = distributionSetManagement.updateDistributionSetType(updatableType);
|
||||
updatableType = distributionSetManagement.assignMandatorySoftwareModuleTypes(updatableType.getId(),
|
||||
Sets.newHashSet(osType.getId()));
|
||||
assertThat(distributionSetManagement.findDistributionSetTypeByKey("updatableType").getMandatoryModuleTypes())
|
||||
.containsOnly(osType);
|
||||
|
||||
// add JVM
|
||||
updatableType.addMandatoryModuleType(runtimeType);
|
||||
updatableType = distributionSetManagement.updateDistributionSetType(updatableType);
|
||||
updatableType = distributionSetManagement.assignMandatorySoftwareModuleTypes(updatableType.getId(),
|
||||
Sets.newHashSet(runtimeType.getId()));
|
||||
assertThat(distributionSetManagement.findDistributionSetTypeByKey("updatableType").getMandatoryModuleTypes())
|
||||
.containsOnly(osType, runtimeType);
|
||||
|
||||
// remove OS
|
||||
updatableType.removeModuleType(osType.getId());
|
||||
updatableType = distributionSetManagement.updateDistributionSetType(updatableType);
|
||||
updatableType = distributionSetManagement.unassignSoftwareModuleType(updatableType.getId(), osType.getId());
|
||||
assertThat(distributionSetManagement.findDistributionSetTypeByKey("updatableType").getMandatoryModuleTypes())
|
||||
.containsOnly(runtimeType);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Description("Tests the successfull update of used distribution set type meta data hich is in fact allowed.")
|
||||
@Description("Tests the successfull update of used distribution set type meta data which is in fact allowed.")
|
||||
public void updateAssignedDistributionSetTypeMetaData() {
|
||||
final DistributionSetType nonUpdatableType = distributionSetManagement
|
||||
.createDistributionSetType(new JpaDistributionSetType("updatableType", "to be deletd", ""));
|
||||
final DistributionSetType nonUpdatableType = distributionSetManagement.createDistributionSetType(entityFactory
|
||||
.distributionSetType().create().key("updatableType").name("to be deleted").colour("test123"));
|
||||
assertThat(distributionSetManagement.findDistributionSetTypeByKey("updatableType").getMandatoryModuleTypes())
|
||||
.isEmpty();
|
||||
distributionSetManagement
|
||||
.createDistributionSet(new JpaDistributionSet("newtypesoft", "1", "", nonUpdatableType, null));
|
||||
distributionSetManagement.createDistributionSet(entityFactory.distributionSet().create().name("newtypesoft")
|
||||
.version("1").type(nonUpdatableType.getKey()));
|
||||
|
||||
nonUpdatableType.setDescription("a new description");
|
||||
nonUpdatableType.setColour("test123");
|
||||
|
||||
distributionSetManagement.updateDistributionSetType(nonUpdatableType);
|
||||
distributionSetManagement.updateDistributionSetType(
|
||||
entityFactory.distributionSetType().update(nonUpdatableType.getId()).description("a new description"));
|
||||
|
||||
assertThat(distributionSetManagement.findDistributionSetTypeByKey("updatableType").getDescription())
|
||||
.isEqualTo("a new description");
|
||||
@@ -118,17 +103,16 @@ public class DistributionSetManagementTest extends AbstractJpaIntegrationTest {
|
||||
@Test
|
||||
@Description("Tests the unsuccessfull update of used distribution set type (module addition).")
|
||||
public void addModuleToAssignedDistributionSetTypeFails() {
|
||||
final DistributionSetType nonUpdatableType = distributionSetManagement
|
||||
.createDistributionSetType(new JpaDistributionSetType("updatableType", "to be deletd", ""));
|
||||
final DistributionSetType nonUpdatableType = distributionSetManagement.createDistributionSetType(
|
||||
entityFactory.distributionSetType().create().key("updatableType").name("to be deleted"));
|
||||
assertThat(distributionSetManagement.findDistributionSetTypeByKey("updatableType").getMandatoryModuleTypes())
|
||||
.isEmpty();
|
||||
distributionSetManagement
|
||||
.createDistributionSet(new JpaDistributionSet("newtypesoft", "1", "", nonUpdatableType, null));
|
||||
|
||||
nonUpdatableType.addMandatoryModuleType(osType);
|
||||
distributionSetManagement.createDistributionSet(entityFactory.distributionSet().create().name("newtypesoft")
|
||||
.version("1").type(nonUpdatableType.getKey()));
|
||||
|
||||
try {
|
||||
distributionSetManagement.updateDistributionSetType(nonUpdatableType);
|
||||
distributionSetManagement.assignMandatorySoftwareModuleTypes(nonUpdatableType.getId(),
|
||||
Sets.newHashSet(osType.getId()));
|
||||
fail("Should not have worked as DS is in use.");
|
||||
} catch (final EntityReadOnlyException e) {
|
||||
|
||||
@@ -139,19 +123,18 @@ public class DistributionSetManagementTest extends AbstractJpaIntegrationTest {
|
||||
@Test
|
||||
@Description("Tests the unsuccessfull update of used distribution set type (module removal).")
|
||||
public void removeModuleToAssignedDistributionSetTypeFails() {
|
||||
DistributionSetType nonUpdatableType = distributionSetManagement
|
||||
.createDistributionSetType(new JpaDistributionSetType("updatableType", "to be deletd", ""));
|
||||
DistributionSetType nonUpdatableType = distributionSetManagement.createDistributionSetType(
|
||||
entityFactory.distributionSetType().create().key("updatableType").name("to be deleted"));
|
||||
assertThat(distributionSetManagement.findDistributionSetTypeByKey("updatableType").getMandatoryModuleTypes())
|
||||
.isEmpty();
|
||||
|
||||
nonUpdatableType.addMandatoryModuleType(osType);
|
||||
nonUpdatableType = distributionSetManagement.updateDistributionSetType(nonUpdatableType);
|
||||
distributionSetManagement
|
||||
.createDistributionSet(new JpaDistributionSet("newtypesoft", "1", "", nonUpdatableType, null));
|
||||
nonUpdatableType = distributionSetManagement.assignMandatorySoftwareModuleTypes(nonUpdatableType.getId(),
|
||||
Sets.newHashSet(osType.getId()));
|
||||
distributionSetManagement.createDistributionSet(entityFactory.distributionSet().create().name("newtypesoft")
|
||||
.version("1").type(nonUpdatableType.getKey()));
|
||||
|
||||
nonUpdatableType.removeModuleType(osType.getId());
|
||||
try {
|
||||
distributionSetManagement.updateDistributionSetType(nonUpdatableType);
|
||||
distributionSetManagement.unassignSoftwareModuleType(nonUpdatableType.getId(), osType.getId());
|
||||
fail("Should not have worked as DS is in use.");
|
||||
} catch (final EntityReadOnlyException e) {
|
||||
|
||||
@@ -162,7 +145,8 @@ public class DistributionSetManagementTest extends AbstractJpaIntegrationTest {
|
||||
@Description("Tests the successfull deletion of unused (hard delete) distribution set types.")
|
||||
public void deleteUnassignedDistributionSetType() {
|
||||
final JpaDistributionSetType hardDelete = (JpaDistributionSetType) distributionSetManagement
|
||||
.createDistributionSetType(new JpaDistributionSetType("deleted", "to be deleted", ""));
|
||||
.createDistributionSetType(
|
||||
entityFactory.distributionSetType().create().key("delete").name("to be deleted"));
|
||||
|
||||
assertThat(distributionSetTypeRepository.findAll()).contains(hardDelete);
|
||||
distributionSetManagement.deleteDistributionSetType(hardDelete);
|
||||
@@ -174,11 +158,12 @@ public class DistributionSetManagementTest extends AbstractJpaIntegrationTest {
|
||||
@Description("Tests the successfull deletion of used (soft delete) distribution set types.")
|
||||
public void deleteAssignedDistributionSetType() {
|
||||
final JpaDistributionSetType softDelete = (JpaDistributionSetType) distributionSetManagement
|
||||
.createDistributionSetType(new JpaDistributionSetType("softdeleted", "to be deletd", ""));
|
||||
.createDistributionSetType(
|
||||
entityFactory.distributionSetType().create().key("softdeleted").name("to be deleted"));
|
||||
|
||||
assertThat(distributionSetTypeRepository.findAll()).contains(softDelete);
|
||||
distributionSetManagement
|
||||
.createDistributionSet(new JpaDistributionSet("newtypesoft", "1", "", softDelete, null));
|
||||
distributionSetManagement.createDistributionSet(
|
||||
entityFactory.distributionSet().create().name("softdeleted").version("1").type(softDelete.getKey()));
|
||||
|
||||
distributionSetManagement.deleteDistributionSetType(softDelete);
|
||||
assertThat(distributionSetManagement.findDistributionSetTypeByKey("softdeleted").isDeleted()).isEqualTo(true);
|
||||
@@ -201,7 +186,7 @@ public class DistributionSetManagementTest extends AbstractJpaIntegrationTest {
|
||||
@Description("Verifies that a DS is of default type if not specified explicitly at creation time.")
|
||||
public void createDistributionSetWithImplicitType() {
|
||||
final DistributionSet set = distributionSetManagement
|
||||
.createDistributionSet(new JpaDistributionSet("newtypesoft", "1", "", null, null));
|
||||
.createDistributionSet(entityFactory.distributionSet().create().name("newtypesoft").version("1"));
|
||||
|
||||
assertThat(set.getType()).as("Type should be equal to default type of tenant")
|
||||
.isEqualTo(systemManagement.getTenantMetadata().getDefaultDsType());
|
||||
@@ -212,12 +197,12 @@ public class DistributionSetManagementTest extends AbstractJpaIntegrationTest {
|
||||
@Description("Verifies that multiple DS are of default type if not specified explicitly at creation time.")
|
||||
public void createMultipleDistributionSetsWithImplicitType() {
|
||||
|
||||
List<DistributionSet> sets = new ArrayList<>();
|
||||
final List<DistributionSetCreate> creates = Lists.newArrayListWithExpectedSize(10);
|
||||
for (int i = 0; i < 10; i++) {
|
||||
sets.add(new JpaDistributionSet("another DS" + i, "X" + i, "", null, null));
|
||||
creates.add(entityFactory.distributionSet().create().name("newtypesoft" + i).version("1" + i));
|
||||
}
|
||||
|
||||
sets = distributionSetManagement.createDistributionSets(sets);
|
||||
final List<DistributionSet> sets = distributionSetManagement.createDistributionSets(creates);
|
||||
|
||||
assertThat(sets).as("Type should be equal to default type of tenant").are(new Condition<DistributionSet>() {
|
||||
@Override
|
||||
@@ -228,20 +213,6 @@ public class DistributionSetManagementTest extends AbstractJpaIntegrationTest {
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
@Description("Verifies that a DS entity cannot be used for creation.")
|
||||
public void createDistributionSetFailsOnExistingEntity() {
|
||||
final DistributionSet set = distributionSetManagement
|
||||
.createDistributionSet(new JpaDistributionSet("newtypesoft", "1", "", null, null));
|
||||
|
||||
try {
|
||||
distributionSetManagement.createDistributionSet(set);
|
||||
fail("Should not have worked to create based on a persisted entity.");
|
||||
} catch (final EntityAlreadyExistsException e) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@Description("Checks that metadata for a distribution set can be created.")
|
||||
public void createDistributionSetMetadata() {
|
||||
@@ -251,8 +222,8 @@ public class DistributionSetManagementTest extends AbstractJpaIntegrationTest {
|
||||
final DistributionSet ds = testdataFactory.createDistributionSet("testDs");
|
||||
|
||||
final DistributionSetMetadata metadata = new JpaDistributionSetMetadata(knownKey, ds, knownValue);
|
||||
final JpaDistributionSetMetadata createdMetadata = (JpaDistributionSetMetadata) distributionSetManagement
|
||||
.createDistributionSetMetadata(metadata);
|
||||
final JpaDistributionSetMetadata createdMetadata = (JpaDistributionSetMetadata) createDistributionSetMetadata(
|
||||
ds.getId(), metadata);
|
||||
|
||||
assertThat(createdMetadata).isNotNull();
|
||||
assertThat(createdMetadata.getId().getKey()).isEqualTo(knownKey);
|
||||
@@ -264,67 +235,34 @@ public class DistributionSetManagementTest extends AbstractJpaIntegrationTest {
|
||||
@Description("Ensures that updates concerning the internal software structure of a DS are not possible if the DS is already assigned.")
|
||||
public void updateDistributionSetForbiddedWithIllegalUpdate() {
|
||||
// prepare data
|
||||
Target target = new JpaTarget("4711");
|
||||
target = targetManagement.createTarget(target);
|
||||
|
||||
SoftwareModule ah2 = new JpaSoftwareModule(appType, "agent-hub2", "1.0.5", null, "");
|
||||
SoftwareModule os2 = new JpaSoftwareModule(osType, "poky2", "3.0.3", null, "");
|
||||
final Target target = testdataFactory.createTarget();
|
||||
|
||||
DistributionSet ds = testdataFactory.createDistributionSet("ds-1");
|
||||
|
||||
ah2 = softwareManagement.createSoftwareModule(ah2);
|
||||
os2 = softwareManagement.createSoftwareModule(os2);
|
||||
final SoftwareModule ah2 = testdataFactory.createSoftwareModuleApp();
|
||||
final SoftwareModule os2 = testdataFactory.createSoftwareModuleOs();
|
||||
|
||||
// update is allowed as it is still not assigned to a target
|
||||
ds.addModule(ah2);
|
||||
ds = distributionSetManagement.updateDistributionSet(ds);
|
||||
ds = distributionSetManagement.assignSoftwareModules(ds.getId(), Sets.newHashSet(ah2.getId()));
|
||||
|
||||
// assign target
|
||||
deploymentManagement.assignDistributionSet(ds.getId(), target.getControllerId());
|
||||
assignDistributionSet(ds.getId(), target.getControllerId());
|
||||
ds = distributionSetManagement.findDistributionSetByIdWithDetails(ds.getId());
|
||||
|
||||
// description change is still allowed
|
||||
ds.setDescription("a different desc");
|
||||
ds = distributionSetManagement.updateDistributionSet(ds);
|
||||
|
||||
// description change is still allowed
|
||||
ds.setName("a new name");
|
||||
ds = distributionSetManagement.updateDistributionSet(ds);
|
||||
|
||||
// description change is still allowed
|
||||
ds.setVersion("a new version");
|
||||
ds = distributionSetManagement.updateDistributionSet(ds);
|
||||
|
||||
// not allowed as it is assigned now
|
||||
ds.addModule(os2);
|
||||
try {
|
||||
ds = distributionSetManagement.updateDistributionSet(ds);
|
||||
fail("Expected EntityLockedException");
|
||||
} catch (final EntityLockedException e) {
|
||||
ds = distributionSetManagement.assignSoftwareModules(ds.getId(), Sets.newHashSet(os2.getId()));
|
||||
fail("Expected EntityReadOnlyException");
|
||||
} catch (final EntityReadOnlyException e) {
|
||||
|
||||
}
|
||||
|
||||
// not allowed as it is assigned now
|
||||
ds.removeModule(ds.findFirstModuleByType(appType));
|
||||
try {
|
||||
ds = distributionSetManagement.updateDistributionSet(ds);
|
||||
fail("Expected EntityLockedException");
|
||||
} catch (final EntityLockedException e) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@Description("Ensures that it is not possible to add a software module to a set that has no type defined.")
|
||||
public void updateDistributionSetModuleWithUndefinedTypeFails() {
|
||||
final DistributionSet testSet = new JpaDistributionSet();
|
||||
final SoftwareModule module = new JpaSoftwareModule(appType, "agent-hub2", "1.0.5", null, "");
|
||||
|
||||
// update data
|
||||
try {
|
||||
testSet.addModule(module);
|
||||
fail("Should not have worked as DS type is undefined.");
|
||||
} catch (final DistributionSetTypeUndefinedException e) {
|
||||
ds = distributionSetManagement.unassignSoftwareModule(ds.getId(),
|
||||
ds.findFirstModuleByType(appType).getId());
|
||||
fail("Expected EntityReadOnlyException");
|
||||
} catch (final EntityReadOnlyException e) {
|
||||
|
||||
}
|
||||
}
|
||||
@@ -332,13 +270,18 @@ public class DistributionSetManagementTest extends AbstractJpaIntegrationTest {
|
||||
@Test
|
||||
@Description("Ensures that it is not possible to add a software module that is not defined of the DS's type.")
|
||||
public void updateDistributionSetUnsupportedModuleFails() {
|
||||
final DistributionSet set = new JpaDistributionSet("agent-hub2", "1.0.5", "desc",
|
||||
new JpaDistributionSetType("test", "test", "test").addMandatoryModuleType(osType), null);
|
||||
final SoftwareModule module = new JpaSoftwareModule(appType, "agent-hub2", "1.0.5", null, "");
|
||||
final DistributionSet set = distributionSetManagement
|
||||
.createDistributionSet(entityFactory.distributionSet().create().name("agent-hub2").version("1.0.5")
|
||||
.type(distributionSetManagement.createDistributionSetType(entityFactory.distributionSetType()
|
||||
.create().key("test").name("test").mandatory(Lists.newArrayList(osType.getId())))
|
||||
.getKey()));
|
||||
|
||||
final SoftwareModule module = softwareManagement.createSoftwareModule(
|
||||
entityFactory.softwareModule().create().name("agent-hub2").version("1.0.5").type(appType.getKey()));
|
||||
|
||||
// update data
|
||||
try {
|
||||
set.addModule(module);
|
||||
distributionSetManagement.assignSoftwareModules(set.getId(), Sets.newHashSet(module.getId()));
|
||||
fail("Should not have worked as module type is not in DS type.");
|
||||
} catch (final UnsupportedSoftwareModuleForThisDistributionSetException e) {
|
||||
|
||||
@@ -349,40 +292,30 @@ public class DistributionSetManagementTest extends AbstractJpaIntegrationTest {
|
||||
@Description("Legal updates of a DS, e.g. name or description and module addition, removal while still unassigned.")
|
||||
public void updateDistributionSet() {
|
||||
// prepare data
|
||||
Target target = new JpaTarget("4711");
|
||||
target = targetManagement.createTarget(target);
|
||||
|
||||
SoftwareModule os2 = new JpaSoftwareModule(osType, "poky2", "3.0.3", null, "");
|
||||
final SoftwareModule app2 = new JpaSoftwareModule(appType, "app2", "3.0.3", null, "");
|
||||
|
||||
final Target target = testdataFactory.createTarget();
|
||||
DistributionSet ds = testdataFactory.createDistributionSet("");
|
||||
|
||||
os2 = softwareManagement.createSoftwareModule(os2);
|
||||
final SoftwareModule os = testdataFactory.createSoftwareModuleOs();
|
||||
|
||||
// update data
|
||||
// legal update of module addition
|
||||
ds.addModule(os2);
|
||||
distributionSetManagement.updateDistributionSet(ds);
|
||||
distributionSetManagement.assignSoftwareModules(ds.getId(), Sets.newHashSet(os.getId()));
|
||||
ds = distributionSetManagement.findDistributionSetByIdWithDetails(ds.getId());
|
||||
assertThat(ds.findFirstModuleByType(osType)).isEqualTo(os2);
|
||||
assertThat(ds.findFirstModuleByType(osType)).isEqualTo(os);
|
||||
|
||||
// legal update of module removal
|
||||
ds.removeModule(ds.findFirstModuleByType(appType));
|
||||
distributionSetManagement.updateDistributionSet(ds);
|
||||
distributionSetManagement.unassignSoftwareModule(ds.getId(), ds.findFirstModuleByType(appType).getId());
|
||||
ds = distributionSetManagement.findDistributionSetByIdWithDetails(ds.getId());
|
||||
assertThat(ds.findFirstModuleByType(appType)).isNull();
|
||||
|
||||
// Update description
|
||||
ds.setDescription("a new description");
|
||||
distributionSetManagement.updateDistributionSet(ds);
|
||||
distributionSetManagement
|
||||
.updateDistributionSet(entityFactory.distributionSet().update(ds.getId()).name("a new name")
|
||||
.description("a new description").version("a new version").requiredMigrationStep(true));
|
||||
ds = distributionSetManagement.findDistributionSetByIdWithDetails(ds.getId());
|
||||
assertThat(ds.getDescription()).isEqualTo("a new description");
|
||||
|
||||
// Update name
|
||||
ds.setName("a new name");
|
||||
distributionSetManagement.updateDistributionSet(ds);
|
||||
ds = distributionSetManagement.findDistributionSetByIdWithDetails(ds.getId());
|
||||
assertThat(ds.getName()).isEqualTo("a new name");
|
||||
assertThat(ds.getVersion()).isEqualTo("a new version");
|
||||
assertThat(ds.isRequiredMigrationStep()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -399,22 +332,16 @@ public class DistributionSetManagementTest extends AbstractJpaIntegrationTest {
|
||||
assertThat(ds.getOptLockRevision()).isEqualTo(1);
|
||||
|
||||
// create an DS meta data entry
|
||||
final DistributionSetMetadata dsMetadata = distributionSetManagement
|
||||
.createDistributionSetMetadata(new JpaDistributionSetMetadata(knownKey, ds, knownValue));
|
||||
createDistributionSetMetadata(ds.getId(), new JpaDistributionSetMetadata(knownKey, ds, knownValue));
|
||||
|
||||
DistributionSet changedLockRevisionDS = distributionSetManagement.findDistributionSetById(ds.getId());
|
||||
assertThat(changedLockRevisionDS.getOptLockRevision()).isEqualTo(2);
|
||||
|
||||
// modifying the meta data value
|
||||
dsMetadata.setValue(knownUpdateValue);
|
||||
dsMetadata.setKey(knownKey);
|
||||
((JpaDistributionSetMetadata) dsMetadata).setDistributionSet(changedLockRevisionDS);
|
||||
|
||||
Thread.sleep(100);
|
||||
|
||||
// update the DS metadata
|
||||
final JpaDistributionSetMetadata updated = (JpaDistributionSetMetadata) distributionSetManagement
|
||||
.updateDistributionSetMetadata(dsMetadata);
|
||||
.updateDistributionSetMetadata(ds.getId(), entityFactory.generateMetadata(knownKey, knownUpdateValue));
|
||||
// we are updating the sw meta data so also modifying the base software
|
||||
// module so opt lock
|
||||
// revision must be three
|
||||
@@ -435,8 +362,7 @@ public class DistributionSetManagementTest extends AbstractJpaIntegrationTest {
|
||||
|
||||
final List<DistributionSet> buildDistributionSets = testdataFactory.createDistributionSets("dsOrder", 10);
|
||||
|
||||
final List<Target> buildTargetFixtures = targetManagement
|
||||
.createTargets(testdataFactory.generateTargets(5, "tOrder", "someDesc"));
|
||||
final List<Target> buildTargetFixtures = testdataFactory.createTargets(5, "tOrder", "someDesc");
|
||||
|
||||
final Iterator<DistributionSet> dsIterator = buildDistributionSets.iterator();
|
||||
final Iterator<Target> tIterator = buildTargetFixtures.iterator();
|
||||
@@ -448,14 +374,13 @@ public class DistributionSetManagementTest extends AbstractJpaIntegrationTest {
|
||||
final Target tSecond = tIterator.next();
|
||||
|
||||
// set assigned
|
||||
deploymentManagement.assignDistributionSet(dsSecond.getId(), tSecond.getControllerId());
|
||||
deploymentManagement.assignDistributionSet(dsThree.getId(), tFirst.getControllerId());
|
||||
assignDistributionSet(dsSecond.getId(), tSecond.getControllerId());
|
||||
assignDistributionSet(dsThree.getId(), tFirst.getControllerId());
|
||||
// set installed
|
||||
final ArrayList<Target> installedDSSecond = new ArrayList<>();
|
||||
installedDSSecond.add(tSecond);
|
||||
sendUpdateActionStatusToTargets(dsSecond, installedDSSecond, Status.FINISHED, "some message");
|
||||
testdataFactory.sendUpdateActionStatusToTargets(Collections.singleton(tSecond), Status.FINISHED,
|
||||
Lists.newArrayList("some message"));
|
||||
|
||||
deploymentManagement.assignDistributionSet(dsFour.getId(), tSecond.getControllerId());
|
||||
assignDistributionSet(dsFour.getId(), tSecond.getControllerId());
|
||||
|
||||
final DistributionSetFilterBuilder distributionSetFilterBuilder = new DistributionSetFilterBuilder()
|
||||
.setIsDeleted(false).setIsComplete(true).setSelectDSWithNoTag(Boolean.FALSE);
|
||||
@@ -479,28 +404,32 @@ public class DistributionSetManagementTest extends AbstractJpaIntegrationTest {
|
||||
@Description("searches for distribution sets based on the various filter options, e.g. name, version, desc., tags.")
|
||||
public void searchDistributionSetsOnFilters() {
|
||||
DistributionSetTag dsTagA = tagManagement
|
||||
.createDistributionSetTag(new JpaDistributionSetTag("DistributionSetTag-A"));
|
||||
.createDistributionSetTag(entityFactory.tag().create().name("DistributionSetTag-A"));
|
||||
final DistributionSetTag dsTagB = tagManagement
|
||||
.createDistributionSetTag(new JpaDistributionSetTag("DistributionSetTag-B"));
|
||||
.createDistributionSetTag(entityFactory.tag().create().name("DistributionSetTag-B"));
|
||||
final DistributionSetTag dsTagC = tagManagement
|
||||
.createDistributionSetTag(new JpaDistributionSetTag("DistributionSetTag-C"));
|
||||
final DistributionSetTag dsTagD = tagManagement
|
||||
.createDistributionSetTag(new JpaDistributionSetTag("DistributionSetTag-D"));
|
||||
.createDistributionSetTag(entityFactory.tag().create().name("DistributionSetTag-C"));
|
||||
tagManagement.createDistributionSetTag(entityFactory.tag().create().name("DistributionSetTag-D"));
|
||||
|
||||
Collection<DistributionSet> ds100Group1 = testdataFactory.createDistributionSets("", 100);
|
||||
Collection<DistributionSet> ds100Group2 = testdataFactory.createDistributionSets("test2", 100);
|
||||
DistributionSet dsDeleted = testdataFactory.createDistributionSet("deleted");
|
||||
final DistributionSet dsInComplete = distributionSetManagement
|
||||
.createDistributionSet(new JpaDistributionSet("notcomplete", "1", "", standardDsType, null));
|
||||
final DistributionSet dsInComplete = distributionSetManagement.createDistributionSet(entityFactory
|
||||
.distributionSet().create().name("notcomplete").version("1").type(standardDsType.getKey()));
|
||||
|
||||
final DistributionSetType newType = distributionSetManagement.createDistributionSetType(
|
||||
new JpaDistributionSetType("foo", "bar", "test").addMandatoryModuleType(osType)
|
||||
.addOptionalModuleType(appType).addOptionalModuleType(runtimeType));
|
||||
DistributionSetType newType = distributionSetManagement.createDistributionSetType(
|
||||
entityFactory.distributionSetType().create().key("foo").name("bar").description("test"));
|
||||
|
||||
final DistributionSet dsNewType = distributionSetManagement
|
||||
.createDistributionSet(new JpaDistributionSet("newtype", "1", "", newType, dsDeleted.getModules()));
|
||||
distributionSetManagement.assignMandatorySoftwareModuleTypes(newType.getId(),
|
||||
Lists.newArrayList(osType.getId()));
|
||||
newType = distributionSetManagement.assignOptionalSoftwareModuleTypes(newType.getId(),
|
||||
Lists.newArrayList(appType.getId(), runtimeType.getId()));
|
||||
|
||||
deploymentManagement.assignDistributionSet(dsDeleted, Lists.newArrayList(testdataFactory.createTargets(5)));
|
||||
final DistributionSet dsNewType = distributionSetManagement.createDistributionSet(
|
||||
entityFactory.distributionSet().create().name("newtype").version("1").type(newType.getKey()).modules(
|
||||
dsDeleted.getModules().stream().map(SoftwareModule::getId).collect(Collectors.toList())));
|
||||
|
||||
assignDistributionSet(dsDeleted, Lists.newArrayList(testdataFactory.createTargets(5)));
|
||||
distributionSetManagement.deleteDistributionSet(dsDeleted);
|
||||
dsDeleted = distributionSetManagement.findDistributionSetById(dsDeleted.getId());
|
||||
|
||||
@@ -515,7 +444,7 @@ public class DistributionSetManagementTest extends AbstractJpaIntegrationTest {
|
||||
assertThat(distributionSetRepository.findAll()).hasSize(203);
|
||||
|
||||
// Find all
|
||||
List<DistributionSet> expected = new ArrayList<DistributionSet>();
|
||||
List<DistributionSet> expected = Lists.newArrayListWithExpectedSize(203);
|
||||
expected.addAll(ds100Group1);
|
||||
expected.addAll(ds100Group2);
|
||||
expected.add(dsDeleted);
|
||||
@@ -539,7 +468,7 @@ public class DistributionSetManagementTest extends AbstractJpaIntegrationTest {
|
||||
.hasSize(202);
|
||||
|
||||
// search for completed
|
||||
expected = new ArrayList<DistributionSet>();
|
||||
expected = new ArrayList<>();
|
||||
expected.addAll(ds100Group1);
|
||||
expected.addAll(ds100Group2);
|
||||
expected.add(dsDeleted);
|
||||
@@ -551,7 +480,7 @@ public class DistributionSetManagementTest extends AbstractJpaIntegrationTest {
|
||||
.containsOnly(expected.toArray(new DistributionSet[0]));
|
||||
|
||||
distributionSetFilterBuilder = getDistributionSetFilterBuilder().setIsComplete(Boolean.FALSE);
|
||||
expected = new ArrayList<DistributionSet>();
|
||||
expected = new ArrayList<>();
|
||||
expected.add(dsInComplete);
|
||||
assertThat(distributionSetManagement
|
||||
.findDistributionSetsByFilters(pageReq, distributionSetFilterBuilder.build()).getContent()).hasSize(1)
|
||||
@@ -604,7 +533,7 @@ public class DistributionSetManagementTest extends AbstractJpaIntegrationTest {
|
||||
.findDistributionSetsByFilters(pageReq, distributionSetFilterBuilder.build()).getContent()).hasSize(0);
|
||||
|
||||
// combine deleted and complete
|
||||
expected = new ArrayList<DistributionSet>();
|
||||
expected = new ArrayList<>();
|
||||
expected.addAll(ds100Group1);
|
||||
expected.addAll(ds100Group2);
|
||||
expected.add(dsNewType);
|
||||
@@ -615,14 +544,14 @@ public class DistributionSetManagementTest extends AbstractJpaIntegrationTest {
|
||||
.findDistributionSetsByFilters(pageReq, distributionSetFilterBuilder.build()).getContent()).hasSize(201)
|
||||
.containsOnly(expected.toArray(new DistributionSet[0]));
|
||||
|
||||
expected = new ArrayList<DistributionSet>();
|
||||
expected = new ArrayList<>();
|
||||
expected.add(dsInComplete);
|
||||
distributionSetFilterBuilder = getDistributionSetFilterBuilder().setIsComplete(Boolean.FALSE);
|
||||
assertThat(distributionSetManagement
|
||||
.findDistributionSetsByFilters(pageReq, distributionSetFilterBuilder.build()).getContent()).hasSize(1)
|
||||
.containsOnly(expected.toArray(new DistributionSet[0]));
|
||||
|
||||
expected = new ArrayList<DistributionSet>();
|
||||
expected = new ArrayList<>();
|
||||
expected.add(dsDeleted);
|
||||
distributionSetFilterBuilder = getDistributionSetFilterBuilder().setIsComplete(Boolean.TRUE)
|
||||
.setIsDeleted(Boolean.TRUE);
|
||||
@@ -710,18 +639,6 @@ public class DistributionSetManagementTest extends AbstractJpaIntegrationTest {
|
||||
return new DistributionSetFilterBuilder();
|
||||
}
|
||||
|
||||
private List<Target> sendUpdateActionStatusToTargets(final DistributionSet dsA, final Iterable<Target> targs,
|
||||
final Status status, final String... msgs) {
|
||||
final List<Target> result = new ArrayList<>();
|
||||
for (final Target t : targs) {
|
||||
final List<Action> findByTarget = actionRepository.findByTarget((JpaTarget) t);
|
||||
for (final Action action : findByTarget) {
|
||||
result.add(sendUpdateActionStatusToTarget(status, action, t, msgs));
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@Test
|
||||
@Description("Simple DS load without the related data that should be loaded lazy.")
|
||||
public void findDistributionSetsWithoutLazy() {
|
||||
@@ -759,16 +676,14 @@ public class DistributionSetManagementTest extends AbstractJpaIntegrationTest {
|
||||
|
||||
for (int index = 0; index < 10; index++) {
|
||||
|
||||
ds1 = distributionSetManagement
|
||||
.createDistributionSetMetadata(new JpaDistributionSetMetadata("key" + index, ds1, "value" + index))
|
||||
.getDistributionSet();
|
||||
ds1 = createDistributionSetMetadata(ds1.getId(),
|
||||
new JpaDistributionSetMetadata("key" + index, ds1, "value" + index)).getDistributionSet();
|
||||
}
|
||||
|
||||
for (int index = 0; index < 20; index++) {
|
||||
|
||||
ds2 = distributionSetManagement
|
||||
.createDistributionSetMetadata(new JpaDistributionSetMetadata("key" + index, ds2, "value" + index))
|
||||
.getDistributionSet();
|
||||
ds2 = createDistributionSetMetadata(ds2.getId(),
|
||||
new JpaDistributionSetMetadata("key" + index, ds2, "value" + index)).getDistributionSet();
|
||||
}
|
||||
|
||||
final Page<DistributionSetMetadata> metadataOfDs1 = distributionSetManagement
|
||||
@@ -799,11 +714,8 @@ public class DistributionSetManagementTest extends AbstractJpaIntegrationTest {
|
||||
// create assigned DS
|
||||
dsToTargetAssigned = distributionSetManagement.findDistributionSetByNameAndVersion(dsToTargetAssigned.getName(),
|
||||
dsToTargetAssigned.getVersion());
|
||||
final Target target = new JpaTarget("4712");
|
||||
final Target savedTarget = targetManagement.createTarget(target);
|
||||
final List<Target> toAssign = new ArrayList<>();
|
||||
toAssign.add(savedTarget);
|
||||
deploymentManagement.assignDistributionSet(dsToTargetAssigned, toAssign);
|
||||
final Target savedTarget = testdataFactory.createTarget();
|
||||
assignDistributionSet(dsToTargetAssigned.getId(), savedTarget.getControllerId());
|
||||
|
||||
// create assigned rollout
|
||||
createRolloutByVariables("test", "test", 5, "name==*", dsToRolloutAssigned, "50", "5");
|
||||
@@ -827,47 +739,15 @@ public class DistributionSetManagementTest extends AbstractJpaIntegrationTest {
|
||||
// create assigned DS
|
||||
dsToTargetAssigned = distributionSetManagement.findDistributionSetByNameAndVersion(dsToTargetAssigned.getName(),
|
||||
dsToTargetAssigned.getVersion());
|
||||
final Target target = new JpaTarget("4712");
|
||||
final Target savedTarget = targetManagement.createTarget(target);
|
||||
final List<Target> toAssign = Lists.newArrayList(savedTarget);
|
||||
DistributionSetAssignmentResult assignmentResult = deploymentManagement
|
||||
.assignDistributionSet(dsToTargetAssigned, toAssign);
|
||||
final Target savedTarget = testdataFactory.createTarget();
|
||||
DistributionSetAssignmentResult assignmentResult = assignDistributionSet(dsToTargetAssigned.getId(),
|
||||
savedTarget.getControllerId());
|
||||
assertThat(assignmentResult.getAssignedEntity()).hasSize(1);
|
||||
|
||||
assignmentResult = deploymentManagement.assignDistributionSet(dsToTargetAssigned, toAssign);
|
||||
assignmentResult = assignDistributionSet(dsToTargetAssigned.getId(), savedTarget.getControllerId());
|
||||
assertThat(assignmentResult.getAssignedEntity()).hasSize(0);
|
||||
|
||||
assertThat(distributionSetRepository.findAll()).hasSize(1);
|
||||
}
|
||||
|
||||
private Rollout createRolloutByVariables(final String rolloutName, final String rolloutDescription,
|
||||
final int groupSize, final String filterQuery, final DistributionSet distributionSet,
|
||||
final String successCondition, final String errorCondition) {
|
||||
final RolloutGroupConditions conditions = new RolloutGroupConditionBuilder()
|
||||
.successCondition(RolloutGroupSuccessCondition.THRESHOLD, successCondition)
|
||||
.errorCondition(RolloutGroupErrorCondition.THRESHOLD, errorCondition)
|
||||
.errorAction(RolloutGroupErrorAction.PAUSE, null).build();
|
||||
final Rollout rolloutToCreate = new JpaRollout();
|
||||
rolloutToCreate.setName(rolloutName);
|
||||
rolloutToCreate.setDescription(rolloutDescription);
|
||||
rolloutToCreate.setTargetFilterQuery(filterQuery);
|
||||
rolloutToCreate.setDistributionSet(distributionSet);
|
||||
return rolloutManagement.createRollout(rolloutToCreate, groupSize, conditions);
|
||||
}
|
||||
|
||||
private Target sendUpdateActionStatusToTarget(final Status status, final Action updActA, final Target t,
|
||||
final String... msgs) {
|
||||
updActA.setStatus(status);
|
||||
|
||||
final ActionStatus statusMessages = new JpaActionStatus();
|
||||
statusMessages.setAction(updActA);
|
||||
statusMessages.setOccurredAt(System.currentTimeMillis());
|
||||
statusMessages.setStatus(status);
|
||||
for (final String msg : msgs) {
|
||||
statusMessages.addMessage(msg);
|
||||
}
|
||||
controllerManagament.addUpdateActionStatus(statusMessages);
|
||||
return targetManagement.findTargetByControllerID(t.getControllerId());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -14,20 +14,17 @@ import static org.fest.assertions.api.Assertions.fail;
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.ZoneId;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Calendar;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
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.JpaActionStatus;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaTarget;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaTargetInfo;
|
||||
import org.eclipse.hawkbit.repository.model.Action;
|
||||
import org.eclipse.hawkbit.repository.model.Action.Status;
|
||||
import org.eclipse.hawkbit.repository.model.ActionStatus;
|
||||
import org.eclipse.hawkbit.repository.model.DistributionSet;
|
||||
import org.eclipse.hawkbit.repository.model.DistributionSetAssignmentResult;
|
||||
import org.eclipse.hawkbit.repository.model.SoftwareModule;
|
||||
@@ -59,6 +56,8 @@ import ru.yandex.qatools.allure.annotations.Stories;
|
||||
@Stories("Report Management")
|
||||
public class ReportManagementTest extends AbstractJpaIntegrationTest {
|
||||
|
||||
private static final String TEST_MESSAGE = "some message";
|
||||
|
||||
@Autowired
|
||||
private ReportManagement reportManagement;
|
||||
|
||||
@@ -86,7 +85,7 @@ public class ReportManagementTest extends AbstractJpaIntegrationTest {
|
||||
|
||||
for (int month = 0; month < maxMonthBackAmountCreateTargets; month++) {
|
||||
dynamicDateTimeProvider.nowMinusMonths(month);
|
||||
targetManagement.createTarget(new JpaTarget("t" + month));
|
||||
testdataFactory.createTarget("t" + month);
|
||||
}
|
||||
|
||||
final LocalDateTime to = LocalDateTime.now();
|
||||
@@ -108,7 +107,7 @@ public class ReportManagementTest extends AbstractJpaIntegrationTest {
|
||||
// check cache evict
|
||||
for (int month = 0; month < maxMonthBackAmountCreateTargets; month++) {
|
||||
dynamicDateTimeProvider.nowMinusMonths(month);
|
||||
targetManagement.createTarget(new JpaTarget("t2" + month));
|
||||
testdataFactory.createTarget("t2" + month);
|
||||
}
|
||||
targetsCreatedOverPeriod = reportManagement.targetsCreatedOverPeriod(DateTypes.perMonth(), from, to);
|
||||
for (final DataReportSeriesItem<LocalDate> reportItem : targetsCreatedOverPeriod.getData()) {
|
||||
@@ -137,8 +136,8 @@ public class ReportManagementTest extends AbstractJpaIntegrationTest {
|
||||
|
||||
for (int month = 0; month < maxMonthBackAmountCreateTargets; month++) {
|
||||
dynamicDateTimeProvider.nowMinusMonths(month);
|
||||
final Target createTarget = targetManagement.createTarget(new JpaTarget("t" + month));
|
||||
final DistributionSetAssignmentResult result = deploymentManagement.assignDistributionSet(distributionSet,
|
||||
final Target createTarget = testdataFactory.createTarget("t" + month);
|
||||
final DistributionSetAssignmentResult result = assignDistributionSet(distributionSet,
|
||||
Lists.newArrayList(createTarget));
|
||||
controllerManagament.registerRetrieved(
|
||||
deploymentManagement.findActionWithDetails(result.getActions().get(0)),
|
||||
@@ -159,8 +158,8 @@ public class ReportManagementTest extends AbstractJpaIntegrationTest {
|
||||
// check cache evict
|
||||
for (int month = 0; month < maxMonthBackAmountCreateTargets; month++) {
|
||||
dynamicDateTimeProvider.nowMinusMonths(month);
|
||||
final Target createTarget = targetManagement.createTarget(new JpaTarget("t2" + month));
|
||||
final DistributionSetAssignmentResult result = deploymentManagement.assignDistributionSet(distributionSet,
|
||||
final Target createTarget = testdataFactory.createTarget("t2" + month);
|
||||
final DistributionSetAssignmentResult result = assignDistributionSet(distributionSet,
|
||||
Lists.newArrayList(createTarget));
|
||||
controllerManagament.registerRetrieved(
|
||||
deploymentManagement.findActionWithDetails(result.getActions().get(0)),
|
||||
@@ -176,43 +175,40 @@ public class ReportManagementTest extends AbstractJpaIntegrationTest {
|
||||
@Test
|
||||
@Description("Tests correct statistics calculation including a correct cache evict.")
|
||||
public void distributionUsageInstalled() {
|
||||
final Target knownTarget1 = targetManagement.createTarget(new JpaTarget("t1"));
|
||||
final Target knownTarget2 = targetManagement.createTarget(new JpaTarget("t2"));
|
||||
final Target knownTarget3 = targetManagement.createTarget(new JpaTarget("t3"));
|
||||
final Target knownTarget4 = targetManagement.createTarget(new JpaTarget("t4"));
|
||||
final Target knownTarget5 = targetManagement.createTarget(new JpaTarget("t5"));
|
||||
final Target knownTarget1 = testdataFactory.createTarget("t1");
|
||||
final Target knownTarget2 = testdataFactory.createTarget("t2");
|
||||
final Target knownTarget3 = testdataFactory.createTarget("t3");
|
||||
final Target knownTarget4 = testdataFactory.createTarget("t4");
|
||||
final Target knownTarget5 = testdataFactory.createTarget("t5");
|
||||
|
||||
final SoftwareModule ah = testdataFactory.createSoftwareModule(TestdataFactory.SM_TYPE_APP);
|
||||
final SoftwareModule jvm = testdataFactory.createSoftwareModule(TestdataFactory.SM_TYPE_RT);
|
||||
final SoftwareModule os = testdataFactory.createSoftwareModule(TestdataFactory.SM_TYPE_OS);
|
||||
|
||||
final DistributionSet distributionSet1 = distributionSetManagement.createDistributionSet(testdataFactory
|
||||
.generateDistributionSet("ds1", "0.0.0", standardDsType, Lists.newArrayList(os, jvm, ah)));
|
||||
final DistributionSet distributionSet11 = distributionSetManagement.createDistributionSet(testdataFactory
|
||||
.generateDistributionSet("ds1", "0.0.1", standardDsType, Lists.newArrayList(os, jvm, ah)));
|
||||
final DistributionSet distributionSet2 = distributionSetManagement.createDistributionSet(testdataFactory
|
||||
.generateDistributionSet("ds2", "0.0.2", standardDsType, Lists.newArrayList(os, jvm, ah)));
|
||||
final DistributionSet distributionSet3 = distributionSetManagement.createDistributionSet(testdataFactory
|
||||
.generateDistributionSet("ds3", "0.0.3", standardDsType, Lists.newArrayList(os, jvm, ah)));
|
||||
final DistributionSet distributionSet1 = testdataFactory.createDistributionSet("ds1", "0.0.0", standardDsType,
|
||||
Lists.newArrayList(os, jvm, ah));
|
||||
final DistributionSet distributionSet11 = testdataFactory.createDistributionSet("ds1", "0.0.1", standardDsType,
|
||||
Lists.newArrayList(os, jvm, ah));
|
||||
final DistributionSet distributionSet2 = testdataFactory.createDistributionSet("ds2", "0.0.2", standardDsType,
|
||||
Lists.newArrayList(os, jvm, ah));
|
||||
final DistributionSet distributionSet3 = testdataFactory.createDistributionSet("ds3", "0.0.3", standardDsType,
|
||||
Lists.newArrayList(os, jvm, ah));
|
||||
|
||||
// ds1(0.0.0)=[target1,target2], ds1(0.0.1)=[target3]
|
||||
deploymentManagement.assignDistributionSet(distributionSet1.getId(), knownTarget1.getControllerId());
|
||||
deploymentManagement.assignDistributionSet(distributionSet1.getId(), knownTarget2.getControllerId());
|
||||
deploymentManagement.assignDistributionSet(distributionSet11.getId(), knownTarget3.getControllerId());
|
||||
assignDistributionSet(distributionSet1.getId(), knownTarget1.getControllerId());
|
||||
assignDistributionSet(distributionSet1.getId(), knownTarget2.getControllerId());
|
||||
assignDistributionSet(distributionSet11.getId(), knownTarget3.getControllerId());
|
||||
|
||||
// ds2=[target4]
|
||||
deploymentManagement.assignDistributionSet(distributionSet2.getId(), knownTarget4.getControllerId());
|
||||
assignDistributionSet(distributionSet2.getId(), knownTarget4.getControllerId());
|
||||
|
||||
// ds3=[target5] --> ONLY ASSIGNED AND NOT INSTALLED
|
||||
deploymentManagement.assignDistributionSet(distributionSet3.getId(), knownTarget5.getControllerId());
|
||||
assignDistributionSet(distributionSet3.getId(), knownTarget5.getControllerId());
|
||||
|
||||
// set installed status
|
||||
sendUpdateActionStatusToTargets(distributionSet1, Lists.newArrayList(knownTarget1, knownTarget2),
|
||||
Status.FINISHED, "some message");
|
||||
sendUpdateActionStatusToTargets(distributionSet11, Lists.newArrayList(knownTarget3), Status.FINISHED,
|
||||
"some message");
|
||||
sendUpdateActionStatusToTargets(distributionSet2, Lists.newArrayList(knownTarget4), Status.FINISHED,
|
||||
"some message");
|
||||
testdataFactory.sendUpdateActionStatusToTargets(
|
||||
Lists.newArrayList(knownTarget1, knownTarget2, knownTarget3, knownTarget4), Status.FINISHED,
|
||||
Collections.singletonList(TEST_MESSAGE));
|
||||
|
||||
List<InnerOuterDataReportSeries<String>> distributionUsage = reportManagement.distributionUsageInstalled(100);
|
||||
|
||||
@@ -249,10 +245,10 @@ public class ReportManagementTest extends AbstractJpaIntegrationTest {
|
||||
}
|
||||
|
||||
// Test cache evict
|
||||
final Target knownTarget6 = targetManagement.createTarget(new JpaTarget("t6"));
|
||||
deploymentManagement.assignDistributionSet(distributionSet1.getId(), knownTarget6.getControllerId());
|
||||
sendUpdateActionStatusToTargets(distributionSet1, Lists.newArrayList(knownTarget6), Status.FINISHED,
|
||||
"some message");
|
||||
final Target knownTarget6 = testdataFactory.createTarget("t6");
|
||||
assignDistributionSet(distributionSet1.getId(), knownTarget6.getControllerId());
|
||||
testdataFactory.sendUpdateActionStatusToTargets(Lists.newArrayList(knownTarget6), Status.FINISHED,
|
||||
Collections.singletonList(TEST_MESSAGE));
|
||||
distributionUsage = reportManagement.distributionUsageInstalled(100);
|
||||
for (final InnerOuterDataReportSeries<String> innerOuterDataReportSeries : distributionUsage) {
|
||||
final DataReportSeriesItem<String> dataReportSeriesItem = innerOuterDataReportSeries.getInnerSeries()
|
||||
@@ -347,32 +343,31 @@ public class ReportManagementTest extends AbstractJpaIntegrationTest {
|
||||
@Test
|
||||
@Description("Tests correct statistics calculation including a correct cache evict.")
|
||||
public void topXDistributionUsage() {
|
||||
|
||||
final Target knownTarget1 = targetManagement.createTarget(new JpaTarget("t1"));
|
||||
final Target knownTarget2 = targetManagement.createTarget(new JpaTarget("t2"));
|
||||
final Target knownTarget3 = targetManagement.createTarget(new JpaTarget("t3"));
|
||||
final Target knownTarget4 = targetManagement.createTarget(new JpaTarget("t4"));
|
||||
final Target knownTarget1 = testdataFactory.createTarget("t1");
|
||||
final Target knownTarget2 = testdataFactory.createTarget("t2");
|
||||
final Target knownTarget3 = testdataFactory.createTarget("t3");
|
||||
final Target knownTarget4 = testdataFactory.createTarget("t4");
|
||||
|
||||
final SoftwareModule ah = testdataFactory.createSoftwareModule(TestdataFactory.SM_TYPE_APP);
|
||||
final SoftwareModule jvm = testdataFactory.createSoftwareModule(TestdataFactory.SM_TYPE_RT);
|
||||
final SoftwareModule os = testdataFactory.createSoftwareModule(TestdataFactory.SM_TYPE_OS);
|
||||
|
||||
final DistributionSet distributionSet1 = distributionSetManagement.createDistributionSet(testdataFactory
|
||||
.generateDistributionSet("ds1", "0.0.0", standardDsType, Lists.newArrayList(os, jvm, ah)));
|
||||
final DistributionSet distributionSet11 = distributionSetManagement.createDistributionSet(testdataFactory
|
||||
.generateDistributionSet("ds1", "0.0.1", standardDsType, Lists.newArrayList(os, jvm, ah)));
|
||||
final DistributionSet distributionSet2 = distributionSetManagement.createDistributionSet(testdataFactory
|
||||
.generateDistributionSet("ds2", "0.0.2", standardDsType, Lists.newArrayList(os, jvm, ah)));
|
||||
final DistributionSet distributionSet3 = distributionSetManagement.createDistributionSet(testdataFactory
|
||||
.generateDistributionSet("ds3", "0.0.3", standardDsType, Lists.newArrayList(os, jvm, ah)));
|
||||
final DistributionSet distributionSet1 = testdataFactory.createDistributionSet("ds1", "0.0.0", standardDsType,
|
||||
Lists.newArrayList(os, jvm, ah));
|
||||
final DistributionSet distributionSet11 = testdataFactory.createDistributionSet("ds1", "0.0.1", standardDsType,
|
||||
Lists.newArrayList(os, jvm, ah));
|
||||
final DistributionSet distributionSet2 = testdataFactory.createDistributionSet("ds2", "0.0.2", standardDsType,
|
||||
Lists.newArrayList(os, jvm, ah));
|
||||
final DistributionSet distributionSet3 = testdataFactory.createDistributionSet("ds3", "0.0.3", standardDsType,
|
||||
Lists.newArrayList(os, jvm, ah));
|
||||
|
||||
// ds1(0.0.0)=[target1,target2], ds1(0.0.1)=[target3]
|
||||
deploymentManagement.assignDistributionSet(distributionSet1.getId(), knownTarget1.getControllerId());
|
||||
deploymentManagement.assignDistributionSet(distributionSet1.getId(), knownTarget2.getControllerId());
|
||||
deploymentManagement.assignDistributionSet(distributionSet11.getId(), knownTarget3.getControllerId());
|
||||
assignDistributionSet(distributionSet1.getId(), knownTarget1.getControllerId());
|
||||
assignDistributionSet(distributionSet1.getId(), knownTarget2.getControllerId());
|
||||
assignDistributionSet(distributionSet11.getId(), knownTarget3.getControllerId());
|
||||
|
||||
// ds2=[target4]
|
||||
deploymentManagement.assignDistributionSet(distributionSet2.getId(), knownTarget4.getControllerId());
|
||||
assignDistributionSet(distributionSet2.getId(), knownTarget4.getControllerId());
|
||||
|
||||
// expect: ds1(0.0.0)=[target1,target2], ds1(0.0.1)=[target3],
|
||||
// ds2=[target4], ds3=[]
|
||||
@@ -415,8 +410,8 @@ public class ReportManagementTest extends AbstractJpaIntegrationTest {
|
||||
}
|
||||
|
||||
// test cache evict
|
||||
final Target knownTarget5 = targetManagement.createTarget(new JpaTarget("t5"));
|
||||
deploymentManagement.assignDistributionSet(distributionSet1.getId(), knownTarget5.getControllerId());
|
||||
final Target knownTarget5 = testdataFactory.createTarget("t5");
|
||||
assignDistributionSet(distributionSet1.getId(), knownTarget5.getControllerId());
|
||||
distributionUsage = reportManagement.distributionUsageAssigned(100);
|
||||
for (final InnerOuterDataReportSeries<String> innerOuterDataReportSeries : distributionUsage) {
|
||||
final DataReportSeriesItem<String> dataReportSeriesItem = innerOuterDataReportSeries.getInnerSeries()
|
||||
@@ -486,7 +481,7 @@ public class ReportManagementTest extends AbstractJpaIntegrationTest {
|
||||
// create targets for another tenant
|
||||
securityRule.runAs(WithSpringAuthorityRule.withUserAndTenant("user", "anotherTenant"), () -> {
|
||||
for (int index = 0; index < targetCreateAmount; index++) {
|
||||
targetManagement.createTarget(new JpaTarget("t" + index));
|
||||
testdataFactory.createTarget("t" + index);
|
||||
}
|
||||
return null;
|
||||
});
|
||||
@@ -509,8 +504,7 @@ public class ReportManagementTest extends AbstractJpaIntegrationTest {
|
||||
|
||||
private void createTargets(final String prefix, final int amount, final LocalDateTime lastTargetQuery) {
|
||||
for (int index = 0; index < amount; index++) {
|
||||
final Target target = new JpaTarget(prefix + index);
|
||||
final JpaTarget createTarget = (JpaTarget) targetManagement.createTarget(target);
|
||||
final JpaTarget createTarget = (JpaTarget) testdataFactory.createTarget(prefix + index);
|
||||
if (lastTargetQuery != null) {
|
||||
final JpaTargetInfo targetInfo = (JpaTargetInfo) createTarget.getTargetInfo();
|
||||
targetInfo.setNew(false);
|
||||
@@ -531,42 +525,10 @@ public class ReportManagementTest extends AbstractJpaIntegrationTest {
|
||||
}
|
||||
}
|
||||
|
||||
private List<Target> sendUpdateActionStatusToTargets(final DistributionSet dsA, final Iterable<Target> targs,
|
||||
final Status status, final String... msgs) {
|
||||
final List<Target> result = new ArrayList<>();
|
||||
for (final Target t : targs) {
|
||||
final List<Action> findByTarget = actionRepository.findByTarget((JpaTarget) t);
|
||||
for (final Action action : findByTarget) {
|
||||
result.add(sendUpdateActionStatusToTarget(status, action, t, msgs));
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private Target sendUpdateActionStatusToTarget(final Status status, final Action updActA, final Target t,
|
||||
final String... msgs) {
|
||||
updActA.setStatus(status);
|
||||
|
||||
final ActionStatus statusMessages = new JpaActionStatus();
|
||||
statusMessages.setAction(updActA);
|
||||
statusMessages.setOccurredAt(System.currentTimeMillis());
|
||||
statusMessages.setStatus(status);
|
||||
for (final String msg : msgs) {
|
||||
statusMessages.addMessage(msg);
|
||||
}
|
||||
controllerManagament.addUpdateActionStatus(statusMessages);
|
||||
return targetManagement.findTargetByControllerID(t.getControllerId());
|
||||
}
|
||||
|
||||
private class DynamicDateTimeProvider implements DateTimeProvider {
|
||||
|
||||
private Calendar datetime = Calendar.getInstance();
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see org.springframework.data.auditing.DateTimeProvider#getNow()
|
||||
*/
|
||||
@Override
|
||||
public Calendar getNow() {
|
||||
return datetime;
|
||||
|
||||
@@ -21,12 +21,12 @@ import java.util.concurrent.TimeUnit;
|
||||
import org.eclipse.hawkbit.repository.OffsetBasedPageRequest;
|
||||
import org.eclipse.hawkbit.repository.RolloutGroupManagement;
|
||||
import org.eclipse.hawkbit.repository.RolloutManagement;
|
||||
import org.eclipse.hawkbit.repository.builder.RolloutCreate;
|
||||
import org.eclipse.hawkbit.repository.builder.RolloutGroupCreate;
|
||||
import org.eclipse.hawkbit.repository.exception.ConstraintViolationException;
|
||||
import org.eclipse.hawkbit.repository.exception.EntityAlreadyExistsException;
|
||||
import org.eclipse.hawkbit.repository.exception.RolloutIllegalStateException;
|
||||
import org.eclipse.hawkbit.repository.exception.RolloutVerificationException;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaAction;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaActionStatus;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaRollout;
|
||||
import org.eclipse.hawkbit.repository.jpa.utils.MultipleInvokeHelper;
|
||||
import org.eclipse.hawkbit.repository.jpa.utils.SuccessCondition;
|
||||
import org.eclipse.hawkbit.repository.model.Action;
|
||||
@@ -116,11 +116,10 @@ public class RolloutManagementTest extends AbstractJpaIntegrationTest {
|
||||
.as("group which should be in scheduled state is in " + group.getStatus() + " state"));
|
||||
// verify that the first group actions has been started and are in state
|
||||
// running
|
||||
final List<Action> runningActions = deploymentManagement.findActionsByRolloutAndStatus(createdRollout,
|
||||
Status.RUNNING);
|
||||
final List<Action> runningActions = findActionsByRolloutAndStatus(createdRollout, Status.RUNNING);
|
||||
assertThat(runningActions).hasSize(amountTargetsForRollout / amountGroups);
|
||||
// the rest targets are only scheduled
|
||||
assertThat(deploymentManagement.findActionsByRolloutAndStatus(createdRollout, Status.SCHEDULED))
|
||||
assertThat(findActionsByRolloutAndStatus(createdRollout, Status.SCHEDULED))
|
||||
.hasSize(amountTargetsForRollout - (amountTargetsForRollout / amountGroups));
|
||||
}
|
||||
|
||||
@@ -135,14 +134,12 @@ public class RolloutManagementTest extends AbstractJpaIntegrationTest {
|
||||
final Rollout createdRollout = createAndStartRollout(amountTargetsForRollout, amountOtherTargets, amountGroups,
|
||||
successCondition, errorCondition);
|
||||
|
||||
final List<Action> runningActions = deploymentManagement.findActionsByRolloutAndStatus(createdRollout,
|
||||
Status.RUNNING);
|
||||
final List<Action> runningActions = findActionsByRolloutAndStatus(createdRollout, Status.RUNNING);
|
||||
// finish one action should be sufficient due the finish condition is at
|
||||
// 50%
|
||||
final JpaAction action = (JpaAction) runningActions.get(0);
|
||||
action.setStatus(Status.FINISHED);
|
||||
controllerManagament
|
||||
.addUpdateActionStatus(new JpaActionStatus(action, Status.FINISHED, System.currentTimeMillis(), ""));
|
||||
.addUpdateActionStatus(entityFactory.actionStatus().create(action.getId()).status(Status.FINISHED));
|
||||
|
||||
// check running rollouts again, now the finish condition should be hit
|
||||
// and should start the next group
|
||||
@@ -258,10 +255,8 @@ public class RolloutManagementTest extends AbstractJpaIntegrationTest {
|
||||
}
|
||||
|
||||
private void finishAction(final Action action) {
|
||||
final JpaAction jpaAction = (JpaAction) action;
|
||||
action.setStatus(Status.FINISHED);
|
||||
controllerManagament
|
||||
.addUpdateActionStatus(new JpaActionStatus(jpaAction, Status.FINISHED, System.currentTimeMillis(), ""));
|
||||
.addUpdateActionStatus(entityFactory.actionStatus().create(action.getId()).status(Status.FINISHED));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -277,14 +272,12 @@ public class RolloutManagementTest extends AbstractJpaIntegrationTest {
|
||||
|
||||
// set both actions in error state so error condition is hit and error
|
||||
// action is executed
|
||||
final List<Action> runningActions = deploymentManagement.findActionsByRolloutAndStatus(createdRollout,
|
||||
Status.RUNNING);
|
||||
final List<Action> runningActions = findActionsByRolloutAndStatus(createdRollout, Status.RUNNING);
|
||||
|
||||
// finish actions with error
|
||||
for (final Action action : runningActions) {
|
||||
action.setStatus(Status.ERROR);
|
||||
controllerManagament.addUpdateActionStatus(
|
||||
new JpaActionStatus((JpaAction) action, Status.ERROR, System.currentTimeMillis(), ""));
|
||||
controllerManagament
|
||||
.addUpdateActionStatus(entityFactory.actionStatus().create(action.getId()).status(Status.ERROR));
|
||||
}
|
||||
|
||||
// check running rollouts again, now the error condition should be hit
|
||||
@@ -320,13 +313,11 @@ public class RolloutManagementTest extends AbstractJpaIntegrationTest {
|
||||
|
||||
// set both actions in error state so error condition is hit and error
|
||||
// action is executed
|
||||
final List<Action> runningActions = deploymentManagement.findActionsByRolloutAndStatus(createdRollout,
|
||||
Status.RUNNING);
|
||||
final List<Action> runningActions = findActionsByRolloutAndStatus(createdRollout, Status.RUNNING);
|
||||
// finish actions with error
|
||||
for (final Action action : runningActions) {
|
||||
action.setStatus(Status.ERROR);
|
||||
controllerManagament.addUpdateActionStatus(
|
||||
new JpaActionStatus((JpaAction) action, Status.ERROR, System.currentTimeMillis(), ""));
|
||||
controllerManagament
|
||||
.addUpdateActionStatus(entityFactory.actionStatus().create(action.getId()).status(Status.ERROR));
|
||||
}
|
||||
|
||||
// check running rollouts again, now the error condition should be hit
|
||||
@@ -553,8 +544,7 @@ public class RolloutManagementTest extends AbstractJpaIntegrationTest {
|
||||
|
||||
createdRollout = rolloutManagement.findRolloutById(createdRollout.getId());
|
||||
// 5 targets are running
|
||||
final List<Action> runningActions = deploymentManagement.findActionsByRolloutAndStatus(createdRollout,
|
||||
Status.RUNNING);
|
||||
final List<Action> runningActions = findActionsByRolloutAndStatus(createdRollout, Status.RUNNING);
|
||||
assertThat(runningActions.size()).isEqualTo(5);
|
||||
|
||||
// 5 targets are in the group and the DS has been assigned
|
||||
@@ -568,12 +558,12 @@ public class RolloutManagementTest extends AbstractJpaIntegrationTest {
|
||||
assertThat(assignedDs.getId()).isEqualTo(ds.getId());
|
||||
}
|
||||
|
||||
final List<Target> targetToCancel = new ArrayList<Target>();
|
||||
final List<Target> targetToCancel = new ArrayList<>();
|
||||
targetToCancel.add(targetList.get(0));
|
||||
targetToCancel.add(targetList.get(1));
|
||||
targetToCancel.add(targetList.get(2));
|
||||
final DistributionSet dsForCancelTest = testdataFactory.createDistributionSet("dsForTest");
|
||||
deploymentManagement.assignDistributionSet(dsForCancelTest, targetToCancel);
|
||||
assignDistributionSet(dsForCancelTest, targetToCancel);
|
||||
// 5 targets are canceling but still have the status running and 5 are
|
||||
// still in SCHEDULED
|
||||
final Map<TotalTargetCountStatus.Status, Long> validationMap = createInitStatusMap();
|
||||
@@ -964,7 +954,7 @@ public class RolloutManagementTest extends AbstractJpaIntegrationTest {
|
||||
Rollout myRollout = createTestRolloutWithTargetsAndDistributionSet(amountTargetsForRollout, amountGroups,
|
||||
successCondition, errorCondition, rolloutName, rolloutName);
|
||||
|
||||
targetManagement.createTargets(testdataFactory.generateTargets(amountOtherTargets, "others-", "rollout"));
|
||||
testdataFactory.createTargets(amountOtherTargets, "others-", "rollout");
|
||||
|
||||
final String rsqlParam = "controllerId==*MyRoll*";
|
||||
|
||||
@@ -1010,7 +1000,7 @@ public class RolloutManagementTest extends AbstractJpaIntegrationTest {
|
||||
createRolloutByVariables(rolloutName, "desc", amountGroups, "id==notExisting", distributionSet,
|
||||
successCondition, errorCondition);
|
||||
fail("Was able to create a Rollout without targets.");
|
||||
} catch(RolloutVerificationException e) {
|
||||
} catch (final ConstraintViolationException e) {
|
||||
// OK
|
||||
}
|
||||
|
||||
@@ -1025,17 +1015,17 @@ public class RolloutManagementTest extends AbstractJpaIntegrationTest {
|
||||
final String errorCondition = "80";
|
||||
final String rolloutName = "rolloutTest4";
|
||||
|
||||
targetManagement.createTargets(testdataFactory.generateTargets(amountTargetsForRollout, "dup-ro-", "rollout"));
|
||||
testdataFactory.createTargets(amountTargetsForRollout, "dup-ro-", "rollout");
|
||||
|
||||
final DistributionSet distributionSet = testdataFactory.createDistributionSet("dsFor" + rolloutName);
|
||||
createRolloutByVariables(rolloutName, "desc", amountGroups, "id==dup-ro-*", distributionSet,
|
||||
successCondition, errorCondition);
|
||||
createRolloutByVariables(rolloutName, "desc", amountGroups, "id==dup-ro-*", distributionSet, successCondition,
|
||||
errorCondition);
|
||||
|
||||
try {
|
||||
createRolloutByVariables(rolloutName, "desc", amountGroups, "id==dup-ro-*", distributionSet,
|
||||
successCondition, errorCondition);
|
||||
fail("Was able to create a duplicate Rollout.");
|
||||
} catch(EntityAlreadyExistsException e) {
|
||||
} catch (final EntityAlreadyExistsException e) {
|
||||
// OK
|
||||
}
|
||||
|
||||
@@ -1051,15 +1041,14 @@ public class RolloutManagementTest extends AbstractJpaIntegrationTest {
|
||||
final String rolloutName = "rolloutTestG";
|
||||
final String targetPrefixName = rolloutName;
|
||||
final DistributionSet distributionSet = testdataFactory.createDistributionSet("dsFor" + rolloutName);
|
||||
targetManagement.createTargets(
|
||||
testdataFactory.generateTargets(amountTargetsForRollout, targetPrefixName + "-", targetPrefixName));
|
||||
testdataFactory.createTargets(amountTargetsForRollout, targetPrefixName + "-", targetPrefixName);
|
||||
|
||||
Rollout myRollout = createRolloutByVariables(rolloutName, "desc", amountGroups,
|
||||
"controllerId==" + targetPrefixName + "-*", distributionSet, successCondition, errorCondition);
|
||||
|
||||
assertThat(myRollout.getStatus()).isEqualTo(RolloutStatus.READY);
|
||||
|
||||
List<RolloutGroup> groups = myRollout.getRolloutGroups();
|
||||
final List<RolloutGroup> groups = myRollout.getRolloutGroups();
|
||||
assertThat(groups.get(0).getStatus()).isEqualTo(RolloutGroupStatus.READY);
|
||||
assertThat(groups.get(0).getTotalTargets()).isEqualTo(1);
|
||||
assertThat(groups.get(1).getStatus()).isEqualTo(RolloutGroupStatus.READY);
|
||||
@@ -1076,7 +1065,8 @@ public class RolloutManagementTest extends AbstractJpaIntegrationTest {
|
||||
// Run here, because scheduler is disabled during tests
|
||||
rolloutManagement.checkStartingRollouts(0);
|
||||
|
||||
SuccessConditionRolloutStatus conditionRolloutStatus = new SuccessConditionRolloutStatus(RolloutStatus.RUNNING);
|
||||
final SuccessConditionRolloutStatus conditionRolloutStatus = new SuccessConditionRolloutStatus(
|
||||
RolloutStatus.RUNNING);
|
||||
assertThat(MultipleInvokeHelper.doWithTimeout(new RolloutStatusCallable(myRollout.getId()),
|
||||
conditionRolloutStatus, 15000, 500)).as("Rollout status").isNotNull();
|
||||
|
||||
@@ -1100,8 +1090,7 @@ public class RolloutManagementTest extends AbstractJpaIntegrationTest {
|
||||
final String rolloutName = "rolloutTest";
|
||||
final String targetPrefixName = rolloutName;
|
||||
final DistributionSet distributionSet = testdataFactory.createDistributionSet("dsFor" + rolloutName);
|
||||
targetManagement.createTargets(
|
||||
testdataFactory.generateTargets(amountTargetsForRollout, targetPrefixName + "-", targetPrefixName));
|
||||
testdataFactory.createTargets(amountTargetsForRollout, targetPrefixName + "-", targetPrefixName);
|
||||
|
||||
Rollout myRollout = createRolloutByVariables(rolloutName, "desc", amountGroups,
|
||||
"controllerId==" + targetPrefixName + "-*", distributionSet, successCondition, errorCondition);
|
||||
@@ -1112,7 +1101,7 @@ public class RolloutManagementTest extends AbstractJpaIntegrationTest {
|
||||
// Run here, because scheduler is disabled during tests
|
||||
rolloutManagement.checkStartingRollouts(0);
|
||||
|
||||
SuccessConditionRolloutStatus conditionRolloutTargetCount = new SuccessConditionRolloutStatus(
|
||||
final SuccessConditionRolloutStatus conditionRolloutTargetCount = new SuccessConditionRolloutStatus(
|
||||
RolloutStatus.RUNNING);
|
||||
assertThat(MultipleInvokeHelper.doWithTimeout(new RolloutStatusCallable(myRollout.getId()),
|
||||
conditionRolloutTargetCount, 15000, 500)).as("Rollout status").isNotNull();
|
||||
@@ -1138,42 +1127,41 @@ public class RolloutManagementTest extends AbstractJpaIntegrationTest {
|
||||
final int percentTargetsInGroup3 = 100;
|
||||
|
||||
final int countTargetsInGroup2 = (int) Math
|
||||
.ceil((double) percentTargetsInGroup2 / 100 * (double) amountTargetsInGroup1and2);
|
||||
.ceil((double) percentTargetsInGroup2 / 100 * amountTargetsInGroup1and2);
|
||||
final int countTargetsInGroup3 = amountTargetsInGroup1and2 - countTargetsInGroup2;
|
||||
|
||||
final RolloutGroupConditions conditions = new RolloutGroupConditionBuilder().build();
|
||||
final RolloutGroupConditions conditions = new RolloutGroupConditionBuilder().withDefaults().build();
|
||||
// Generate Targets for group 2 and 3 and generate the Rollout
|
||||
Rollout myRollout = generateTargetsAndRollout(rolloutName, amountTargetsInGroup1and2);
|
||||
final RolloutCreate rolloutcreate = generateTargetsAndRollout(rolloutName, amountTargetsInGroup1and2);
|
||||
|
||||
// Generate Targets for group 1
|
||||
targetManagement.createTargets(
|
||||
testdataFactory.generateTargets(amountTargetsInGroup1, rolloutName + "-gr1-", rolloutName));
|
||||
testdataFactory.createTargets(amountTargetsInGroup1, rolloutName + "-gr1-", rolloutName);
|
||||
|
||||
List<RolloutGroup> rolloutGroups = new ArrayList<>(3);
|
||||
final List<RolloutGroupCreate> rolloutGroups = new ArrayList<>(3);
|
||||
rolloutGroups.add(generateRolloutGroup(0, percentTargetsInGroup1, "id==" + rolloutName + "-gr1-*"));
|
||||
rolloutGroups.add(generateRolloutGroup(1, percentTargetsInGroup2, null));
|
||||
rolloutGroups.add(generateRolloutGroup(2, percentTargetsInGroup3, null));
|
||||
|
||||
myRollout = rolloutManagement.createRollout(myRollout, rolloutGroups, conditions);
|
||||
Rollout myRollout = rolloutManagement.createRollout(rolloutcreate, rolloutGroups, conditions);
|
||||
myRollout = rolloutManagement.findRolloutById(myRollout.getId());
|
||||
|
||||
assertThat(myRollout.getStatus()).isEqualTo(RolloutStatus.CREATING);
|
||||
for (RolloutGroup group : myRollout.getRolloutGroups()) {
|
||||
for (final RolloutGroup group : myRollout.getRolloutGroups()) {
|
||||
assertThat(group.getStatus()).isEqualTo(RolloutGroupStatus.CREATING);
|
||||
}
|
||||
|
||||
// Generate Targets that must not be addressed by the rollout, because
|
||||
// they were added after the rollout was created
|
||||
TimeUnit.SECONDS.sleep(1);
|
||||
targetManagement.createTargets(testdataFactory.generateTargets(10, rolloutName + "-notIn-", rolloutName));
|
||||
testdataFactory.createTargets(10, rolloutName + "-notIn-", rolloutName);
|
||||
|
||||
rolloutManagement.fillRolloutGroupsWithTargets(myRollout);
|
||||
rolloutManagement.fillRolloutGroupsWithTargets(myRollout.getId());
|
||||
|
||||
myRollout = rolloutManagement.findRolloutById(myRollout.getId());
|
||||
assertThat(myRollout.getStatus()).isEqualTo(RolloutStatus.READY);
|
||||
assertThat(myRollout.getTotalTargets()).isEqualTo(amountTargetsInGroup1and2 + amountTargetsInGroup1);
|
||||
|
||||
List<RolloutGroup> groups = myRollout.getRolloutGroups();
|
||||
final List<RolloutGroup> groups = myRollout.getRolloutGroups();
|
||||
assertThat(groups.get(0).getStatus()).isEqualTo(RolloutGroupStatus.READY);
|
||||
assertThat(groups.get(0).getTotalTargets()).isEqualTo(amountTargetsInGroup1);
|
||||
|
||||
@@ -1193,17 +1181,17 @@ public class RolloutManagementTest extends AbstractJpaIntegrationTest {
|
||||
final int percentTargetsInGroup1 = 20;
|
||||
final int percentTargetsInGroup2 = 50;
|
||||
|
||||
final RolloutGroupConditions conditions = new RolloutGroupConditionBuilder().build();
|
||||
Rollout myRollout = generateTargetsAndRollout(rolloutName, amountTargetsForRollout);
|
||||
final RolloutGroupConditions conditions = new RolloutGroupConditionBuilder().withDefaults().build();
|
||||
final RolloutCreate myRollout = generateTargetsAndRollout(rolloutName, amountTargetsForRollout);
|
||||
|
||||
List<RolloutGroup> rolloutGroups = new ArrayList<>(2);
|
||||
final List<RolloutGroupCreate> rolloutGroups = new ArrayList<>(2);
|
||||
rolloutGroups.add(generateRolloutGroup(0, percentTargetsInGroup1, null));
|
||||
rolloutGroups.add(generateRolloutGroup(1, percentTargetsInGroup2, null));
|
||||
|
||||
try {
|
||||
rolloutManagement.createRollout(myRollout, rolloutGroups, conditions);
|
||||
fail("Was able to create a Rollout with groups that are not addressing all targets");
|
||||
} catch(RolloutVerificationException e) {
|
||||
} catch (final ConstraintViolationException e) {
|
||||
// OK
|
||||
}
|
||||
|
||||
@@ -1217,17 +1205,17 @@ public class RolloutManagementTest extends AbstractJpaIntegrationTest {
|
||||
final int percentTargetsInGroup1 = 101;
|
||||
final int percentTargetsInGroup2 = 50;
|
||||
|
||||
final RolloutGroupConditions conditions = new RolloutGroupConditionBuilder().build();
|
||||
Rollout myRollout = generateTargetsAndRollout(rolloutName, amountTargetsForRollout);
|
||||
final RolloutGroupConditions conditions = new RolloutGroupConditionBuilder().withDefaults().build();
|
||||
final RolloutCreate myRollout = generateTargetsAndRollout(rolloutName, amountTargetsForRollout);
|
||||
|
||||
List<RolloutGroup> rolloutGroups = new ArrayList<>(2);
|
||||
final List<RolloutGroupCreate> rolloutGroups = new ArrayList<>(2);
|
||||
rolloutGroups.add(generateRolloutGroup(0, percentTargetsInGroup1, null));
|
||||
rolloutGroups.add(generateRolloutGroup(1, percentTargetsInGroup2, null));
|
||||
|
||||
try {
|
||||
rolloutManagement.createRollout(myRollout, rolloutGroups, conditions);
|
||||
fail("Was able to create a Rollout with groups that have illegal percentages");
|
||||
} catch(RolloutVerificationException e) {
|
||||
} catch (final ConstraintViolationException e) {
|
||||
// OK
|
||||
}
|
||||
|
||||
@@ -1240,13 +1228,13 @@ public class RolloutManagementTest extends AbstractJpaIntegrationTest {
|
||||
final int amountTargetsForRollout = 10;
|
||||
final int illegalGroupAmount = 501;
|
||||
|
||||
final RolloutGroupConditions conditions = new RolloutGroupConditionBuilder().build();
|
||||
Rollout myRollout = generateTargetsAndRollout(rolloutName, amountTargetsForRollout);
|
||||
final RolloutGroupConditions conditions = new RolloutGroupConditionBuilder().withDefaults().build();
|
||||
final RolloutCreate myRollout = generateTargetsAndRollout(rolloutName, amountTargetsForRollout);
|
||||
|
||||
try {
|
||||
rolloutManagement.createRollout(myRollout, illegalGroupAmount, conditions);
|
||||
fail("Was able to create a Rollout with too many groups");
|
||||
} catch(RolloutVerificationException e) {
|
||||
} catch (final ConstraintViolationException e) {
|
||||
// OK
|
||||
}
|
||||
|
||||
@@ -1262,18 +1250,15 @@ public class RolloutManagementTest extends AbstractJpaIntegrationTest {
|
||||
final String rolloutName = "rolloutTestGC";
|
||||
final String targetPrefixName = rolloutName;
|
||||
final DistributionSet distributionSet = testdataFactory.createDistributionSet("dsFor" + rolloutName);
|
||||
targetManagement.createTargets(
|
||||
testdataFactory.generateTargets(amountTargetsForRollout, targetPrefixName + "-", targetPrefixName));
|
||||
testdataFactory.createTargets(amountTargetsForRollout, targetPrefixName + "-", targetPrefixName);
|
||||
|
||||
final RolloutGroupConditions conditions = new RolloutGroupConditionBuilder()
|
||||
final RolloutGroupConditions conditions = new RolloutGroupConditionBuilder().withDefaults()
|
||||
.successCondition(RolloutGroupSuccessCondition.THRESHOLD, successCondition)
|
||||
.errorCondition(RolloutGroupErrorCondition.THRESHOLD, errorCondition)
|
||||
.errorAction(RolloutGroupErrorAction.PAUSE, null).build();
|
||||
final Rollout rolloutToCreate = new JpaRollout();
|
||||
rolloutToCreate.setName(rolloutName);
|
||||
rolloutToCreate.setDescription("some description");
|
||||
rolloutToCreate.setTargetFilterQuery("id==" + targetPrefixName + "-*");
|
||||
rolloutToCreate.setDistributionSet(distributionSet);
|
||||
final RolloutCreate rolloutToCreate = entityFactory.rollout().create().name(rolloutName)
|
||||
.description("some description").targetFilterQuery("id==" + targetPrefixName + "-*")
|
||||
.set(distributionSet);
|
||||
|
||||
Rollout myRollout = rolloutManagement.createRollout(rolloutToCreate, amountGroups, conditions);
|
||||
myRollout = rolloutManagement.findRolloutById(myRollout.getId());
|
||||
@@ -1283,38 +1268,27 @@ public class RolloutManagementTest extends AbstractJpaIntegrationTest {
|
||||
try {
|
||||
rolloutManagement.startRollout(myRollout);
|
||||
fail("Was able to start a Rollout in CREATING status");
|
||||
} catch(RolloutIllegalStateException e) {
|
||||
} catch (final RolloutIllegalStateException e) {
|
||||
// OK
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private RolloutGroup generateRolloutGroup(final int index, Integer percentage, String targetFilter) {
|
||||
RolloutGroup group = entityFactory.generateRolloutGroup();
|
||||
group.setName("Group" + index);
|
||||
group.setDescription("Group" + index + "desc");
|
||||
if (percentage != null) {
|
||||
group.setTargetPercentage(percentage);
|
||||
}
|
||||
if (targetFilter != null) {
|
||||
group.setTargetFilterQuery(targetFilter);
|
||||
}
|
||||
return group;
|
||||
private RolloutGroupCreate generateRolloutGroup(final int index, final Integer percentage,
|
||||
final String targetFilter) {
|
||||
return entityFactory.rolloutGroup().create().name("Group" + index).description("Group" + index + "desc")
|
||||
.targetPercentage(Float.valueOf(percentage)).targetFilterQuery(targetFilter);
|
||||
|
||||
}
|
||||
|
||||
private Rollout generateTargetsAndRollout(final String rolloutName, final int amountTargetsForRollout) {
|
||||
private RolloutCreate generateTargetsAndRollout(final String rolloutName, final int amountTargetsForRollout) {
|
||||
final DistributionSet distributionSet = testdataFactory.createDistributionSet("dsFor" + rolloutName);
|
||||
|
||||
targetManagement.createTargets(
|
||||
testdataFactory.generateTargets(amountTargetsForRollout, rolloutName + "-", rolloutName));
|
||||
testdataFactory.createTargets(amountTargetsForRollout, rolloutName + "-", rolloutName);
|
||||
|
||||
Rollout myRollout = entityFactory.generateRollout();
|
||||
myRollout.setName(rolloutName);
|
||||
myRollout.setDescription("This is a test description for the rollout");
|
||||
myRollout.setTargetFilterQuery("controllerId==" + rolloutName + "-*");
|
||||
myRollout.setDistributionSet(distributionSet);
|
||||
|
||||
return myRollout;
|
||||
return entityFactory.rollout().create().name(rolloutName)
|
||||
.description("This is a test description for the rollout")
|
||||
.targetFilterQuery("controllerId==" + rolloutName + "-*").set(distributionSet);
|
||||
}
|
||||
|
||||
private void validateRolloutGroupActionStatus(final RolloutGroup rolloutGroup,
|
||||
@@ -1345,10 +1319,10 @@ public class RolloutManagementTest extends AbstractJpaIntegrationTest {
|
||||
final SoftwareModule jvm = testdataFactory.createSoftwareModule(TestdataFactory.SM_TYPE_RT);
|
||||
final SoftwareModule os = testdataFactory.createSoftwareModule(TestdataFactory.SM_TYPE_OS);
|
||||
|
||||
final DistributionSet rolloutDS = distributionSetManagement.createDistributionSet(testdataFactory
|
||||
.generateDistributionSet("rolloutDS", "0.0.0", standardDsType, Lists.newArrayList(os, jvm, ah)));
|
||||
targetManagement.createTargets(testdataFactory.generateTargets(amountTargetsForRollout, "rollout-", "rollout"));
|
||||
targetManagement.createTargets(testdataFactory.generateTargets(amountOtherTargets, "others-", "rollout"));
|
||||
final DistributionSet rolloutDS = testdataFactory.createDistributionSet("rolloutDS", "0.0.0", standardDsType,
|
||||
Lists.newArrayList(os, jvm, ah));
|
||||
testdataFactory.createTargets(amountTargetsForRollout, "rollout-", "rollout");
|
||||
testdataFactory.createTargets(amountOtherTargets, "others-", "rollout");
|
||||
final String filterQuery = "controllerId==rollout-*";
|
||||
return createRolloutByVariables("test-rollout-name-1", "test-rollout-description-1", groupSize, filterQuery,
|
||||
rolloutDS, successCondition, errorCondition);
|
||||
@@ -1358,49 +1332,27 @@ public class RolloutManagementTest extends AbstractJpaIntegrationTest {
|
||||
final int groupSize, final String successCondition, final String errorCondition, final String rolloutName,
|
||||
final String targetPrefixName) {
|
||||
final DistributionSet dsForRolloutTwo = testdataFactory.createDistributionSet("dsFor" + rolloutName);
|
||||
targetManagement.createTargets(
|
||||
testdataFactory.generateTargets(amountTargetsForRollout, targetPrefixName + "-", targetPrefixName));
|
||||
testdataFactory.createTargets(amountTargetsForRollout, targetPrefixName + "-", targetPrefixName);
|
||||
return createRolloutByVariables(rolloutName, rolloutName + "description", groupSize,
|
||||
"controllerId==" + targetPrefixName + "-*", dsForRolloutTwo, successCondition, errorCondition);
|
||||
}
|
||||
|
||||
private Rollout createRolloutByVariables(final String rolloutName, final String rolloutDescription,
|
||||
final int groupSize, final String filterQuery, final DistributionSet distributionSet,
|
||||
final String successCondition, final String errorCondition) {
|
||||
final RolloutGroupConditions conditions = new RolloutGroupConditionBuilder()
|
||||
.successCondition(RolloutGroupSuccessCondition.THRESHOLD, successCondition)
|
||||
.errorCondition(RolloutGroupErrorCondition.THRESHOLD, errorCondition)
|
||||
.errorAction(RolloutGroupErrorAction.PAUSE, null).build();
|
||||
final Rollout rolloutToCreate = new JpaRollout();
|
||||
rolloutToCreate.setName(rolloutName);
|
||||
rolloutToCreate.setDescription(rolloutDescription);
|
||||
rolloutToCreate.setTargetFilterQuery(filterQuery);
|
||||
rolloutToCreate.setDistributionSet(distributionSet);
|
||||
final Rollout rollout = rolloutManagement.createRollout(rolloutToCreate, groupSize, conditions);
|
||||
|
||||
// Run here, because Scheduler is disabled during tests
|
||||
rolloutManagement.fillRolloutGroupsWithTargets(rolloutManagement.findRolloutById(rollout.getId()));
|
||||
|
||||
return rolloutManagement.findRolloutById(rollout.getId());
|
||||
}
|
||||
|
||||
private int changeStatusForAllRunningActions(final Rollout rollout, final Status status) {
|
||||
final List<Action> runningActions = deploymentManagement.findActionsByRolloutAndStatus(rollout, Status.RUNNING);
|
||||
final List<Action> runningActions = findActionsByRolloutAndStatus(rollout, Status.RUNNING);
|
||||
for (final Action action : runningActions) {
|
||||
action.setStatus(status);
|
||||
controllerManagament.addUpdateActionStatus(
|
||||
new JpaActionStatus((JpaAction) action, status, System.currentTimeMillis(), ""));
|
||||
controllerManagament
|
||||
.addUpdateActionStatus(entityFactory.actionStatus().create(action.getId()).status(status));
|
||||
}
|
||||
return runningActions.size();
|
||||
}
|
||||
|
||||
private int changeStatusForRunningActions(final Rollout rollout, final Status status,
|
||||
final int amountOfTargetsToGetChanged) {
|
||||
final List<Action> runningActions = deploymentManagement.findActionsByRolloutAndStatus(rollout, Status.RUNNING);
|
||||
final List<Action> runningActions = findActionsByRolloutAndStatus(rollout, Status.RUNNING);
|
||||
assertThat(runningActions.size()).isGreaterThanOrEqualTo(amountOfTargetsToGetChanged);
|
||||
for (int i = 0; i < amountOfTargetsToGetChanged; i++) {
|
||||
controllerManagament.addUpdateActionStatus(
|
||||
new JpaActionStatus((JpaAction) runningActions.get(i), status, System.currentTimeMillis(), ""));
|
||||
entityFactory.actionStatus().create(runningActions.get(i).getId()).status(status));
|
||||
}
|
||||
return runningActions.size();
|
||||
}
|
||||
|
||||
@@ -14,7 +14,6 @@ import static org.junit.Assert.fail;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
@@ -22,12 +21,11 @@ import java.util.List;
|
||||
import javax.validation.ConstraintViolationException;
|
||||
|
||||
import org.apache.commons.lang3.RandomUtils;
|
||||
import org.eclipse.hawkbit.repository.builder.SoftwareModuleTypeCreate;
|
||||
import org.eclipse.hawkbit.repository.exception.EntityAlreadyExistsException;
|
||||
import org.eclipse.hawkbit.repository.exception.EntityNotFoundException;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaArtifact;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSet;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSetType;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaSoftwareModule;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaSoftwareModuleMetadata;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaSoftwareModuleType;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaTarget;
|
||||
@@ -57,27 +55,14 @@ import ru.yandex.qatools.allure.annotations.Stories;
|
||||
@Stories("Software Management")
|
||||
public class SoftwareManagementTest extends AbstractJpaIntegrationTest {
|
||||
|
||||
@Test
|
||||
@Description("Try to update non updatable fields results in repository doing nothing.")
|
||||
public void updateTypeNonUpdateableFieldsFails() {
|
||||
final SoftwareModuleType created = softwareManagement
|
||||
.createSoftwareModuleType(new JpaSoftwareModuleType("test-key", "test-name", "test-desc", 1));
|
||||
|
||||
created.setName("a new name");
|
||||
final SoftwareModuleType updated = softwareManagement.updateSoftwareModuleType(created);
|
||||
|
||||
assertThat(updated.getOptLockRevision())
|
||||
.as("Expected version number of updated entitity to be equal to created version")
|
||||
.isEqualTo(created.getOptLockRevision());
|
||||
}
|
||||
|
||||
@Test
|
||||
@Description("Calling update without changing fields results in no recorded change in the repository including unchanged audit fields.")
|
||||
public void updateNothingResultsInUnchangedRepositoryForType() {
|
||||
final SoftwareModuleType created = softwareManagement
|
||||
.createSoftwareModuleType(new JpaSoftwareModuleType("test-key", "test-name", "test-desc", 1));
|
||||
final SoftwareModuleType created = softwareManagement.createSoftwareModuleType(
|
||||
entityFactory.softwareModuleType().create().key("test-key").name("test-name"));
|
||||
|
||||
final SoftwareModuleType updated = softwareManagement.updateSoftwareModuleType(created);
|
||||
final SoftwareModuleType updated = softwareManagement
|
||||
.updateSoftwareModuleType(entityFactory.softwareModuleType().update(created.getId()));
|
||||
|
||||
assertThat(updated.getOptLockRevision())
|
||||
.as("Expected version number of updated entitity to be equal to created version")
|
||||
@@ -87,13 +72,11 @@ public class SoftwareManagementTest extends AbstractJpaIntegrationTest {
|
||||
@Test
|
||||
@Description("Calling update for changed fields results in change in the repository.")
|
||||
public void updateSoftareModuleTypeFieldsToNewValue() {
|
||||
final SoftwareModuleType created = softwareManagement
|
||||
.createSoftwareModuleType(new JpaSoftwareModuleType("test-key", "test-name", "test-desc", 1));
|
||||
final SoftwareModuleType created = softwareManagement.createSoftwareModuleType(
|
||||
entityFactory.softwareModuleType().create().key("test-key").name("test-name"));
|
||||
|
||||
created.setDescription("changed");
|
||||
created.setColour("changed");
|
||||
|
||||
final SoftwareModuleType updated = softwareManagement.updateSoftwareModuleType(created);
|
||||
final SoftwareModuleType updated = softwareManagement.updateSoftwareModuleType(
|
||||
entityFactory.softwareModuleType().update(created.getId()).description("changed").colour("changed"));
|
||||
|
||||
assertThat(updated.getOptLockRevision()).as("Expected version number of updated entitity is")
|
||||
.isEqualTo(created.getOptLockRevision() + 1);
|
||||
@@ -101,27 +84,13 @@ public class SoftwareManagementTest extends AbstractJpaIntegrationTest {
|
||||
assertThat(updated.getColour()).as("Updated vendor is").isEqualTo("changed");
|
||||
}
|
||||
|
||||
@Test
|
||||
@Description("Try to update non updatable fields results in repository doing nothing.")
|
||||
public void updateNonUpdateableFieldsFails() {
|
||||
final SoftwareModule ah = softwareManagement
|
||||
.createSoftwareModule(new JpaSoftwareModule(appType, "agent-hub", "1.0.1", null, ""));
|
||||
|
||||
ah.setName("a new name");
|
||||
final SoftwareModule updated = softwareManagement.updateSoftwareModule(ah);
|
||||
|
||||
assertThat(updated.getOptLockRevision())
|
||||
.as("Expected version number of updated entitity to be equal to created version")
|
||||
.isEqualTo(ah.getOptLockRevision());
|
||||
}
|
||||
|
||||
@Test
|
||||
@Description("Calling update without changing fields results in no recorded change in the repository including unchanged audit fields.")
|
||||
public void updateNothingResultsInUnchangedRepository() {
|
||||
final SoftwareModule ah = softwareManagement
|
||||
.createSoftwareModule(new JpaSoftwareModule(appType, "agent-hub", "1.0.1", null, ""));
|
||||
final SoftwareModule ah = testdataFactory.createSoftwareModuleOs();
|
||||
|
||||
final SoftwareModule updated = softwareManagement.updateSoftwareModule(ah);
|
||||
final SoftwareModule updated = softwareManagement
|
||||
.updateSoftwareModule(entityFactory.softwareModule().update(ah.getId()));
|
||||
|
||||
assertThat(updated.getOptLockRevision())
|
||||
.as("Expected version number of updated entitity to be equal to created version")
|
||||
@@ -131,12 +100,10 @@ public class SoftwareManagementTest extends AbstractJpaIntegrationTest {
|
||||
@Test
|
||||
@Description("Calling update for changed fields results in change in the repository.")
|
||||
public void updateSoftareModuleFieldsToNewValue() {
|
||||
final SoftwareModule ah = softwareManagement
|
||||
.createSoftwareModule(new JpaSoftwareModule(appType, "agent-hub", "1.0.1", "test desc", "test vendor"));
|
||||
final SoftwareModule ah = testdataFactory.createSoftwareModuleOs();
|
||||
|
||||
ah.setDescription("changed");
|
||||
ah.setVendor("changed");
|
||||
final SoftwareModule updated = softwareManagement.updateSoftwareModule(ah);
|
||||
final SoftwareModule updated = softwareManagement.updateSoftwareModule(
|
||||
entityFactory.softwareModule().update(ah.getId()).description("changed").vendor("changed"));
|
||||
|
||||
assertThat(updated.getOptLockRevision()).as("Expected version number of updated entitity is")
|
||||
.isEqualTo(ah.getOptLockRevision() + 1);
|
||||
@@ -147,38 +114,9 @@ public class SoftwareManagementTest extends AbstractJpaIntegrationTest {
|
||||
@Test
|
||||
@Description("Create Software Module call fails when called for existing entity.")
|
||||
public void createModuleCallFailsForExistingModule() {
|
||||
final SoftwareModule ah = softwareManagement
|
||||
.createSoftwareModule(new JpaSoftwareModule(appType, "agent-hub", "1.0.1", "test desc", "test vendor"));
|
||||
testdataFactory.createSoftwareModuleOs();
|
||||
try {
|
||||
softwareManagement.createSoftwareModule(ah);
|
||||
fail("Should not have worked as module already exists.");
|
||||
} catch (final EntityAlreadyExistsException e) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@Description("Create Software Modules call fails when called for existing entities.")
|
||||
public void createModulesCallFailsForExistingModule() {
|
||||
final List<SoftwareModule> modules = softwareManagement.createSoftwareModule(
|
||||
Lists.newArrayList(new JpaSoftwareModule(appType, "agent-hub", "1.0.1", "test desc", "test vendor"),
|
||||
new JpaSoftwareModule(appType, "agent-hub", "1.0.2", "test desc", "test vendor")));
|
||||
try {
|
||||
softwareManagement.createSoftwareModule(modules);
|
||||
fail("Should not have worked as module already exists.");
|
||||
} catch (final EntityAlreadyExistsException e) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@Description("Create Software Module Type call fails when called for existing entity.")
|
||||
public void createModuleTypeCallFailsForExistingType() {
|
||||
final SoftwareModuleType created = softwareManagement
|
||||
.createSoftwareModuleType(new JpaSoftwareModuleType("test-key", "test-name", "test-desc", 1));
|
||||
|
||||
try {
|
||||
softwareManagement.createSoftwareModuleType(created);
|
||||
testdataFactory.createSoftwareModuleOs();
|
||||
fail("Should not have worked as module already exists.");
|
||||
} catch (final EntityAlreadyExistsException e) {
|
||||
|
||||
@@ -188,10 +126,11 @@ public class SoftwareManagementTest extends AbstractJpaIntegrationTest {
|
||||
@Test
|
||||
@Description("Create Software Module Types call fails when called for existing entities.")
|
||||
public void createModuleTypesCallFailsForExistingTypes() {
|
||||
final List<SoftwareModuleType> created = softwareManagement.createSoftwareModuleType(
|
||||
Lists.newArrayList(new JpaSoftwareModuleType("test-key-bumlux", "test-name", "test-desc", 1),
|
||||
new JpaSoftwareModuleType("test-key-bumlux2", "test-name2", "test-desc", 1)));
|
||||
final List<SoftwareModuleTypeCreate> created = Lists.newArrayList(
|
||||
entityFactory.softwareModuleType().create().key("test-key").name("test-name"),
|
||||
entityFactory.softwareModuleType().create().key("test-key2").name("test-name2"));
|
||||
|
||||
softwareManagement.createSoftwareModuleType(created);
|
||||
try {
|
||||
softwareManagement.createSoftwareModuleType(created);
|
||||
fail("Should not have worked as module already exists.");
|
||||
@@ -200,38 +139,23 @@ public class SoftwareManagementTest extends AbstractJpaIntegrationTest {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@Description("Calling update for changing fields to null results in change in the repository.")
|
||||
public void eraseSoftareModuleFields() {
|
||||
final SoftwareModule ah = softwareManagement
|
||||
.createSoftwareModule(new JpaSoftwareModule(appType, "agent-hub", "1.0.1", "test desc", "test vendor"));
|
||||
|
||||
ah.setDescription(null);
|
||||
ah.setVendor(null);
|
||||
final SoftwareModule updated = softwareManagement.updateSoftwareModule(ah);
|
||||
|
||||
assertThat(updated.getOptLockRevision()).as("Expected version number of updated entitity is")
|
||||
.isEqualTo(ah.getOptLockRevision() + 1);
|
||||
assertThat(updated.getDescription()).as("Updated description is").isNull();
|
||||
assertThat(updated.getVendor()).as("Updated vendor is").isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
@Description("searched for software modules based on the various filter options, e.g. name,desc,type, version.")
|
||||
public void findSoftwareModuleByFilters() {
|
||||
final SoftwareModule ah = softwareManagement
|
||||
.createSoftwareModule(new JpaSoftwareModule(appType, "agent-hub", "1.0.1", null, ""));
|
||||
final SoftwareModule jvm = softwareManagement
|
||||
.createSoftwareModule(new JpaSoftwareModule(runtimeType, "oracle-jre", "1.7.2", null, ""));
|
||||
final SoftwareModule os = softwareManagement
|
||||
.createSoftwareModule(new JpaSoftwareModule(osType, "poky", "3.0.2", null, ""));
|
||||
final SoftwareModule ah = softwareManagement.createSoftwareModule(
|
||||
entityFactory.softwareModule().create().type(appType).name("agent-hub").version("1.0.1"));
|
||||
final SoftwareModule jvm = softwareManagement.createSoftwareModule(
|
||||
entityFactory.softwareModule().create().type(runtimeType).name("oracle-jre").version("1.7.2"));
|
||||
final SoftwareModule os = softwareManagement.createSoftwareModule(
|
||||
entityFactory.softwareModule().create().type(osType).name("poky").version("3.0.2"));
|
||||
|
||||
final SoftwareModule ah2 = softwareManagement
|
||||
.createSoftwareModule(new JpaSoftwareModule(appType, "agent-hub", "1.0.2", null, ""));
|
||||
JpaDistributionSet ds = (JpaDistributionSet) distributionSetManagement.createDistributionSet(testdataFactory
|
||||
.generateDistributionSet("ds-1", "1.0.1", standardDsType, Lists.newArrayList(os, jvm, ah2)));
|
||||
final SoftwareModule ah2 = softwareManagement.createSoftwareModule(
|
||||
entityFactory.softwareModule().create().type(appType).name("agent-hub").version("1.0.2"));
|
||||
JpaDistributionSet ds = (JpaDistributionSet) distributionSetManagement
|
||||
.createDistributionSet(entityFactory.distributionSet().create().name("ds-1").version("1.0.1")
|
||||
.type(standardDsType).modules(Lists.newArrayList(os.getId(), jvm.getId(), ah2.getId())));
|
||||
|
||||
final JpaTarget target = (JpaTarget) targetManagement.createTarget(new JpaTarget("test123"));
|
||||
final JpaTarget target = (JpaTarget) testdataFactory.createTarget();
|
||||
ds = (JpaDistributionSet) assignSet(target, ds).getDistributionSet();
|
||||
|
||||
// standard searches
|
||||
@@ -262,7 +186,7 @@ public class SoftwareManagementTest extends AbstractJpaIntegrationTest {
|
||||
}
|
||||
|
||||
private Action assignSet(final JpaTarget target, final JpaDistributionSet ds) {
|
||||
deploymentManagement.assignDistributionSet(ds.getId(), new String[] { target.getControllerId() });
|
||||
assignDistributionSet(ds.getId(), target.getControllerId());
|
||||
assertThat(
|
||||
targetManagement.findTargetByControllerID(target.getControllerId()).getTargetInfo().getUpdateStatus())
|
||||
.isEqualTo(TargetUpdateStatus.PENDING);
|
||||
@@ -277,13 +201,8 @@ public class SoftwareManagementTest extends AbstractJpaIntegrationTest {
|
||||
@Description("Searches for software modules based on a list of IDs.")
|
||||
public void findSoftwareModulesById() {
|
||||
|
||||
final List<Long> modules = new ArrayList<>();
|
||||
|
||||
modules.add(softwareManagement
|
||||
.createSoftwareModule(new JpaSoftwareModule(osType, "poky-una", "3.0.2", null, "")).getId());
|
||||
modules.add(softwareManagement
|
||||
.createSoftwareModule(new JpaSoftwareModule(osType, "poky-u2na", "3.0.3", null, "")).getId());
|
||||
modules.add(624355263L);
|
||||
final List<Long> modules = Lists.newArrayList(testdataFactory.createSoftwareModuleOs().getId(),
|
||||
testdataFactory.createSoftwareModuleApp().getId(), 624355263L);
|
||||
|
||||
assertThat(softwareManagement.findSoftwareModulesById(modules)).hasSize(2);
|
||||
}
|
||||
@@ -292,14 +211,11 @@ public class SoftwareManagementTest extends AbstractJpaIntegrationTest {
|
||||
@Description("Searches for software modules by type.")
|
||||
public void findSoftwareModulesByType() {
|
||||
// found in test
|
||||
final SoftwareModule one = softwareManagement
|
||||
.createSoftwareModule(new JpaSoftwareModule(osType, "one", "one", null, ""));
|
||||
final SoftwareModule two = softwareManagement
|
||||
.createSoftwareModule(new JpaSoftwareModule(osType, "two", "two", null, ""));
|
||||
final SoftwareModule one = testdataFactory.createSoftwareModuleOs("one");
|
||||
final SoftwareModule two = testdataFactory.createSoftwareModuleOs("two");
|
||||
// ignored
|
||||
softwareManagement.deleteSoftwareModule(softwareManagement
|
||||
.createSoftwareModule(new JpaSoftwareModule(osType, "deleted", "deleted", null, "")).getId());
|
||||
softwareManagement.createSoftwareModule(new JpaSoftwareModule(appType, "three", "3.0.2", null, ""));
|
||||
softwareManagement.deleteSoftwareModule(testdataFactory.createSoftwareModuleOs("deleted").getId());
|
||||
testdataFactory.createSoftwareModuleApp();
|
||||
|
||||
assertThat(softwareManagement.findSoftwareModulesByType(pageReq, osType.getId()).getContent())
|
||||
.as("Expected to find the following number of modules:").hasSize(2).as("with the following elements")
|
||||
@@ -310,11 +226,11 @@ public class SoftwareManagementTest extends AbstractJpaIntegrationTest {
|
||||
@Description("Counts all software modules in the repsitory that are not marked as deleted.")
|
||||
public void countSoftwareModulesAll() {
|
||||
// found in test
|
||||
softwareManagement.createSoftwareModule(new JpaSoftwareModule(osType, "one", "one", null, ""));
|
||||
softwareManagement.createSoftwareModule(new JpaSoftwareModule(appType, "two", "two", null, ""));
|
||||
final SoftwareModule one = testdataFactory.createSoftwareModuleOs("one");
|
||||
final SoftwareModule two = testdataFactory.createSoftwareModuleOs("two");
|
||||
final SoftwareModule deleted = testdataFactory.createSoftwareModuleOs("deleted");
|
||||
// ignored
|
||||
softwareManagement.deleteSoftwareModule(softwareManagement
|
||||
.createSoftwareModule(new JpaSoftwareModule(osType, "deleted", "deleted", null, "")).getId());
|
||||
softwareManagement.deleteSoftwareModule(deleted.getId());
|
||||
|
||||
assertThat(softwareManagement.countSoftwareModulesAll()).as("Expected to find the following number of modules:")
|
||||
.isEqualTo(2);
|
||||
@@ -327,7 +243,7 @@ public class SoftwareManagementTest extends AbstractJpaIntegrationTest {
|
||||
appType);
|
||||
|
||||
SoftwareModuleType type = softwareManagement.createSoftwareModuleType(
|
||||
new JpaSoftwareModuleType("bundle", "OSGi Bundle", "fancy stuff", Integer.MAX_VALUE));
|
||||
entityFactory.softwareModuleType().create().key("bundle").name("OSGi Bundle"));
|
||||
|
||||
assertThat(softwareManagement.findSoftwareModuleTypesAll(pageReq)).hasSize(4).contains(osType, runtimeType,
|
||||
appType, type);
|
||||
@@ -340,13 +256,13 @@ public class SoftwareManagementTest extends AbstractJpaIntegrationTest {
|
||||
(JpaSoftwareModuleType) runtimeType, (JpaSoftwareModuleType) appType);
|
||||
|
||||
type = softwareManagement.createSoftwareModuleType(
|
||||
new JpaSoftwareModuleType("bundle2", "OSGi Bundle2", "fancy stuff", Integer.MAX_VALUE));
|
||||
entityFactory.softwareModuleType().create().key("bundle2").name("OSGi Bundle2"));
|
||||
|
||||
assertThat(softwareManagement.findSoftwareModuleTypesAll(pageReq)).hasSize(4).contains(osType, runtimeType,
|
||||
appType, type);
|
||||
|
||||
softwareManagement
|
||||
.createSoftwareModule(new JpaSoftwareModule(type, "Test SM", "1.0", "cool module", "from meeee"));
|
||||
softwareManagement.createSoftwareModule(
|
||||
entityFactory.softwareModule().create().type(type).name("Test SM").version("1.0"));
|
||||
|
||||
// delete assigned
|
||||
softwareManagement.deleteSoftwareModuleType(type);
|
||||
@@ -388,15 +304,11 @@ public class SoftwareManagementTest extends AbstractJpaIntegrationTest {
|
||||
@Description("Deletes an artifact, which is assigned to a DistributionSet")
|
||||
public void softDeleteOfAssignedArtifact() {
|
||||
|
||||
// Init DistributionSet
|
||||
final DistributionSet disSet = distributionSetManagement
|
||||
.createDistributionSet(new JpaDistributionSet("ds1", "v1.0", "test ds", standardDsType, null));
|
||||
|
||||
// [STEP1]: Create SoftwareModuleX with ArtifactX
|
||||
SoftwareModule assignedModule = createSoftwareModuleWithArtifacts(osType, "moduleX", "3.0.2", 2);
|
||||
|
||||
// [STEP2]: Assign SoftwareModule to DistributionSet
|
||||
distributionSetManagement.assignSoftwareModules(disSet, Sets.newHashSet(assignedModule));
|
||||
testdataFactory.createDistributionSet(Sets.newHashSet(assignedModule));
|
||||
|
||||
// [STEP3]: Delete the assigned SoftwareModule
|
||||
softwareManagement.deleteSoftwareModule(assignedModule.getId());
|
||||
@@ -423,19 +335,17 @@ public class SoftwareManagementTest extends AbstractJpaIntegrationTest {
|
||||
@Description("Delete an artifact, which has been assigned to a rolled out DistributionSet in the past")
|
||||
public void softDeleteOfHistoricalAssignedArtifact() {
|
||||
|
||||
// Init target and DistributionSet
|
||||
final Target target = targetManagement.createTarget(new JpaTarget("test123"));
|
||||
final DistributionSet disSet = distributionSetManagement
|
||||
.createDistributionSet(new JpaDistributionSet("ds1", "v1.0", "test ds", standardDsType, null));
|
||||
// Init target
|
||||
final Target target = testdataFactory.createTarget();
|
||||
|
||||
// [STEP1]: Create SoftwareModuleX and include the new ArtifactX
|
||||
SoftwareModule assignedModule = createSoftwareModuleWithArtifacts(osType, "moduleX", "3.0.2", 2);
|
||||
|
||||
// [STEP2]: Assign SoftwareModule to DistributionSet
|
||||
distributionSetManagement.assignSoftwareModules(disSet, Sets.newHashSet(assignedModule));
|
||||
final DistributionSet disSet = testdataFactory.createDistributionSet(Sets.newHashSet(assignedModule));
|
||||
|
||||
// [STEP3]: Assign DistributionSet to a Device
|
||||
deploymentManagement.assignDistributionSet(disSet, Lists.newArrayList(target));
|
||||
assignDistributionSet(disSet, Lists.newArrayList(target));
|
||||
|
||||
// [STEP4]: Delete the DistributionSet
|
||||
distributionSetManagement.deleteDistributionSet(disSet);
|
||||
@@ -509,11 +419,7 @@ public class SoftwareManagementTest extends AbstractJpaIntegrationTest {
|
||||
|
||||
// Init artifact binary data, target and DistributionSets
|
||||
final byte[] source = RandomUtils.nextBytes(1024);
|
||||
final Target target = targetManagement.createTarget(new JpaTarget("test123"));
|
||||
final DistributionSet disSetX = distributionSetManagement
|
||||
.createDistributionSet(new JpaDistributionSet("dsX", "v1.0", "test dsX", standardDsType, null));
|
||||
final DistributionSet disSetY = distributionSetManagement
|
||||
.createDistributionSet(new JpaDistributionSet("dsY", "v1.0", "test dsY", standardDsType, null));
|
||||
final Target target = testdataFactory.createTarget();
|
||||
|
||||
// [STEP1]: Create SoftwareModuleX and add a new ArtifactX
|
||||
SoftwareModule moduleX = createSoftwareModuleWithArtifacts(osType, "modulex", "v1.0", 0);
|
||||
@@ -530,12 +436,12 @@ public class SoftwareManagementTest extends AbstractJpaIntegrationTest {
|
||||
final Artifact artifactY = moduleY.getArtifacts().iterator().next();
|
||||
|
||||
// [STEP3]: Assign SoftwareModuleX to DistributionSetX and to target
|
||||
distributionSetManagement.assignSoftwareModules(disSetX, Sets.newHashSet(moduleX));
|
||||
deploymentManagement.assignDistributionSet(disSetX, Lists.newArrayList(target));
|
||||
final DistributionSet disSetX = testdataFactory.createDistributionSet(Sets.newHashSet(moduleX), "X");
|
||||
assignDistributionSet(disSetX, Lists.newArrayList(target));
|
||||
|
||||
// [STEP4]: Assign SoftwareModuleY to DistributionSet and to target
|
||||
distributionSetManagement.assignSoftwareModules(disSetY, Sets.newHashSet(moduleY));
|
||||
deploymentManagement.assignDistributionSet(disSetY, Lists.newArrayList(target));
|
||||
final DistributionSet disSetY = testdataFactory.createDistributionSet(Sets.newHashSet(moduleY), "Y");
|
||||
assignDistributionSet(disSetY, Lists.newArrayList(target));
|
||||
|
||||
// [STEP5]: Delete SoftwareModuleX
|
||||
softwareManagement.deleteSoftwareModule(moduleX.getId());
|
||||
@@ -568,8 +474,8 @@ public class SoftwareManagementTest extends AbstractJpaIntegrationTest {
|
||||
final long countSoftwareModule = softwareModuleRepository.count();
|
||||
|
||||
// create SoftwareModule
|
||||
SoftwareModule softwareModule = softwareManagement.createSoftwareModule(
|
||||
new JpaSoftwareModule(type, name, version, "description of artifact " + name, ""));
|
||||
SoftwareModule softwareModule = softwareManagement.createSoftwareModule(entityFactory.softwareModule().create()
|
||||
.type(type).name(name).version(version).description("description of artifact " + name));
|
||||
|
||||
for (int i = 0; i < numberArtifacts; i++) {
|
||||
artifactManagement.createArtifact(new RandomGeneratedInputStream(5 * 1024), softwareModule.getId(),
|
||||
@@ -587,9 +493,7 @@ public class SoftwareManagementTest extends AbstractJpaIntegrationTest {
|
||||
assertArtfiactNotNull(artifacts.toArray(new Artifact[artifacts.size()]));
|
||||
}
|
||||
|
||||
artifacts.forEach(artifact -> {
|
||||
assertThat(artifactRepository.findOne(artifact.getId())).isNotNull();
|
||||
});
|
||||
artifacts.forEach(artifact -> assertThat(artifactRepository.findOne(artifact.getId())).isNotNull());
|
||||
return softwareModule;
|
||||
}
|
||||
|
||||
@@ -612,35 +516,34 @@ public class SoftwareManagementTest extends AbstractJpaIntegrationTest {
|
||||
@Description("Test verfies that results are returned based on given filter parameters and in the specified order.")
|
||||
public void findSoftwareModuleOrderByDistributionModuleNameAscModuleVersionAsc() {
|
||||
// test meta data
|
||||
final SoftwareModuleType testType = softwareManagement
|
||||
.createSoftwareModuleType(new JpaSoftwareModuleType("thetype", "thename", "desc", 100));
|
||||
final DistributionSetType testDsType = distributionSetManagement
|
||||
.createDistributionSetType(new JpaDistributionSetType("key", "name", "desc")
|
||||
.addMandatoryModuleType(osType).addOptionalModuleType(testType));
|
||||
final SoftwareModuleType testType = softwareManagement.createSoftwareModuleType(
|
||||
entityFactory.softwareModuleType().create().key("thetype").name("thename").maxAssignments(100));
|
||||
DistributionSetType testDsType = distributionSetManagement
|
||||
.createDistributionSetType(entityFactory.distributionSetType().create().key("key").name("name"));
|
||||
|
||||
distributionSetManagement.assignMandatorySoftwareModuleTypes(testDsType.getId(),
|
||||
Lists.newArrayList(osType.getId()));
|
||||
testDsType = distributionSetManagement.assignOptionalSoftwareModuleTypes(testDsType.getId(),
|
||||
Lists.newArrayList(testType.getId()));
|
||||
|
||||
// found in test
|
||||
final SoftwareModule unassigned = softwareManagement
|
||||
.createSoftwareModule(new JpaSoftwareModule(testType, "asis", "found", null, ""));
|
||||
final SoftwareModule one = softwareManagement
|
||||
.createSoftwareModule(new JpaSoftwareModule(testType, "found", "b", null, ""));
|
||||
final SoftwareModule two = softwareManagement
|
||||
.createSoftwareModule(new JpaSoftwareModule(testType, "found", "c", null, ""));
|
||||
final SoftwareModule differentName = softwareManagement
|
||||
.createSoftwareModule(new JpaSoftwareModule(testType, "differentname", "d", null, ""));
|
||||
final SoftwareModule unassigned = testdataFactory.createSoftwareModule("thetype", "unassignedfound");
|
||||
final SoftwareModule one = testdataFactory.createSoftwareModule("thetype", "bfound");
|
||||
final SoftwareModule two = testdataFactory.createSoftwareModule("thetype", "cfound");
|
||||
final SoftwareModule differentName = testdataFactory.createSoftwareModule("thetype", "a");
|
||||
|
||||
// ignored
|
||||
final SoftwareModule deleted = softwareManagement
|
||||
.createSoftwareModule(new JpaSoftwareModule(testType, "deleted", "deleted", null, ""));
|
||||
final SoftwareModule four = softwareManagement
|
||||
.createSoftwareModule(new JpaSoftwareModule(osType, "sdfjhsdj", "e", null, ""));
|
||||
final SoftwareModule deleted = testdataFactory.createSoftwareModule("thetype", "deleted");
|
||||
final SoftwareModule four = testdataFactory.createSoftwareModuleOs("e");
|
||||
|
||||
final DistributionSet set = distributionSetManagement.createDistributionSet(new JpaDistributionSet("set", "1",
|
||||
"desc", testDsType, Lists.newArrayList(one, two, deleted, four, differentName)));
|
||||
final DistributionSet set = distributionSetManagement.createDistributionSet(
|
||||
entityFactory.distributionSet().create().name("set").version("1").type(testDsType).modules(Lists
|
||||
.newArrayList(one.getId(), two.getId(), deleted.getId(), four.getId(), differentName.getId())));
|
||||
softwareManagement.deleteSoftwareModule(deleted.getId());
|
||||
|
||||
// with filter on name, version and module type
|
||||
assertThat(softwareManagement.findSoftwareModuleOrderBySetAssignmentAndModuleNameAscModuleVersionAsc(pageReq,
|
||||
set.getId(), "found", testType.getId()).getContent())
|
||||
set.getId(), "%found%", testType.getId()).getContent())
|
||||
.as("Found modules with given name, given module type and the assigned ones first")
|
||||
.containsExactly(new AssignedSoftwareModule(one, true), new AssignedSoftwareModule(two, true),
|
||||
new AssignedSoftwareModule(unassigned, false));
|
||||
@@ -663,34 +566,34 @@ public class SoftwareManagementTest extends AbstractJpaIntegrationTest {
|
||||
@Test
|
||||
@Description("Checks that number of modules is returned as expected based on given filters.")
|
||||
public void countSoftwareModuleByFilters() {
|
||||
|
||||
// test meta data
|
||||
final SoftwareModuleType testType = softwareManagement
|
||||
.createSoftwareModuleType(new JpaSoftwareModuleType("thetype", "thename", "desc", 100));
|
||||
final DistributionSetType testDsType = distributionSetManagement
|
||||
.createDistributionSetType(new JpaDistributionSetType("key", "name", "desc")
|
||||
.addMandatoryModuleType(osType).addOptionalModuleType(testType));
|
||||
final SoftwareModuleType testType = softwareManagement.createSoftwareModuleType(
|
||||
entityFactory.softwareModuleType().create().key("thetype").name("thename").maxAssignments(100));
|
||||
DistributionSetType testDsType = distributionSetManagement
|
||||
.createDistributionSetType(entityFactory.distributionSetType().create().key("key").name("name"));
|
||||
|
||||
// test modules
|
||||
softwareManagement.createSoftwareModule(new JpaSoftwareModule(testType, "asis", "found", null, ""));
|
||||
final SoftwareModule one = softwareManagement
|
||||
.createSoftwareModule(new JpaSoftwareModule(testType, "found", "b", null, ""));
|
||||
final SoftwareModule two = softwareManagement
|
||||
.createSoftwareModule(new JpaSoftwareModule(testType, "found", "c", null, ""));
|
||||
final SoftwareModule differentName = softwareManagement
|
||||
.createSoftwareModule(new JpaSoftwareModule(testType, "differentname", "d", null, ""));
|
||||
final SoftwareModule four = softwareManagement
|
||||
.createSoftwareModule(new JpaSoftwareModule(osType, "found", "3.0.2", null, ""));
|
||||
distributionSetManagement.assignMandatorySoftwareModuleTypes(testDsType.getId(),
|
||||
Lists.newArrayList(osType.getId()));
|
||||
testDsType = distributionSetManagement.assignOptionalSoftwareModuleTypes(testDsType.getId(),
|
||||
Lists.newArrayList(testType.getId()));
|
||||
|
||||
// one soft deleted
|
||||
final SoftwareModule deleted = softwareManagement
|
||||
.createSoftwareModule(new JpaSoftwareModule(testType, "deleted", "deleted", null, ""));
|
||||
distributionSetManagement.createDistributionSet(new JpaDistributionSet("set", "1", "desc", testDsType,
|
||||
Lists.newArrayList(one, two, deleted, four, differentName)));
|
||||
// found in test
|
||||
testdataFactory.createSoftwareModule("thetype", "unassignedfound");
|
||||
final SoftwareModule one = testdataFactory.createSoftwareModule("thetype", "bfound");
|
||||
final SoftwareModule two = testdataFactory.createSoftwareModule("thetype", "cfound");
|
||||
final SoftwareModule differentName = testdataFactory.createSoftwareModule("thetype", "d");
|
||||
|
||||
// ignored
|
||||
final SoftwareModule deleted = testdataFactory.createSoftwareModule("thetype", "deleted");
|
||||
final SoftwareModule four = testdataFactory.createSoftwareModuleOs("e");
|
||||
|
||||
distributionSetManagement.createDistributionSet(
|
||||
entityFactory.distributionSet().create().name("set").version("1").type(testDsType).modules(Lists
|
||||
.newArrayList(one.getId(), two.getId(), deleted.getId(), four.getId(), differentName.getId())));
|
||||
softwareManagement.deleteSoftwareModule(deleted.getId());
|
||||
|
||||
// test
|
||||
assertThat(softwareManagement.countSoftwareModuleByFilters("found", testType.getId()))
|
||||
assertThat(softwareManagement.countSoftwareModuleByFilters("%found%", testType.getId()))
|
||||
.as("Number of modules with given name or version and type").isEqualTo(3);
|
||||
assertThat(softwareManagement.countSoftwareModuleByFilters(null, testType.getId()))
|
||||
.as("Number of modules with given type").isEqualTo(4);
|
||||
@@ -701,19 +604,11 @@ public class SoftwareManagementTest extends AbstractJpaIntegrationTest {
|
||||
@Test
|
||||
@Description("Verfies that all undeleted software modules are found in the repository.")
|
||||
public void countSoftwareModuleTypesAll() {
|
||||
final SoftwareModuleType testType = softwareManagement
|
||||
.createSoftwareModuleType(new JpaSoftwareModuleType("thetype", "thename", "desc", 100));
|
||||
final DistributionSetType testDsType = distributionSetManagement
|
||||
.createDistributionSetType(new JpaDistributionSetType("key", "name", "desc")
|
||||
.addMandatoryModuleType(osType).addOptionalModuleType(testType));
|
||||
final SoftwareModule four = softwareManagement
|
||||
.createSoftwareModule(new JpaSoftwareModule(osType, "found", "3.0.2", null, ""));
|
||||
testdataFactory.createSoftwareModuleOs();
|
||||
|
||||
// one soft deleted
|
||||
final SoftwareModule deleted = softwareManagement
|
||||
.createSoftwareModule(new JpaSoftwareModule(testType, "deleted", "deleted", null, ""));
|
||||
distributionSetManagement.createDistributionSet(
|
||||
new JpaDistributionSet("set", "1", "desc", testDsType, Lists.newArrayList(deleted, four)));
|
||||
final SoftwareModule deleted = testdataFactory.createSoftwareModuleApp();
|
||||
testdataFactory.createDistributionSet(Lists.newArrayList(deleted));
|
||||
softwareManagement.deleteSoftwareModule(deleted.getId());
|
||||
|
||||
assertThat(softwareManagement.countSoftwareModulesAll()).as("Number of undeleted modules").isEqualTo(1);
|
||||
@@ -723,9 +618,11 @@ public class SoftwareManagementTest extends AbstractJpaIntegrationTest {
|
||||
@Test
|
||||
@Description("Checks that software module typeis found based on given name.")
|
||||
public void findSoftwareModuleTypeByName() {
|
||||
testdataFactory.createSoftwareModuleOs();
|
||||
final SoftwareModuleType found = softwareManagement
|
||||
.createSoftwareModuleType(new JpaSoftwareModuleType("thetype", "thename", "desc", 100));
|
||||
softwareManagement.createSoftwareModuleType(new JpaSoftwareModuleType("thetype2", "anothername", "desc", 100));
|
||||
.createSoftwareModuleType(entityFactory.softwareModuleType().create().key("thetype").name("thename"));
|
||||
softwareManagement.createSoftwareModuleType(
|
||||
entityFactory.softwareModuleType().create().key("thetype2").name("anothername"));
|
||||
|
||||
assertThat(softwareManagement.findSoftwareModuleTypeByName("thename")).as("Type with given name")
|
||||
.isEqualTo(found);
|
||||
@@ -735,9 +632,10 @@ public class SoftwareManagementTest extends AbstractJpaIntegrationTest {
|
||||
@Description("Verfies that it is not possible to create a type that alrady exists.")
|
||||
public void createSoftwareModuleTypeFailsWithExistingEntity() {
|
||||
final SoftwareModuleType created = softwareManagement
|
||||
.createSoftwareModuleType(new JpaSoftwareModuleType("thetype", "thename", "desc", 100));
|
||||
.createSoftwareModuleType(entityFactory.softwareModuleType().create().key("thetype").name("thename"));
|
||||
try {
|
||||
softwareManagement.createSoftwareModuleType(created);
|
||||
softwareManagement.createSoftwareModuleType(
|
||||
entityFactory.softwareModuleType().create().key("thetype").name("thename"));
|
||||
fail("should not have worked as module type already exists");
|
||||
} catch (final EntityAlreadyExistsException e) {
|
||||
|
||||
@@ -749,10 +647,11 @@ public class SoftwareManagementTest extends AbstractJpaIntegrationTest {
|
||||
@Description("Verfies that it is not possible to create a list of types where one already exists.")
|
||||
public void createSoftwareModuleTypesFailsWithExistingEntity() {
|
||||
final SoftwareModuleType created = softwareManagement
|
||||
.createSoftwareModuleType(new JpaSoftwareModuleType("thetype", "thename", "desc", 100));
|
||||
.createSoftwareModuleType(entityFactory.softwareModuleType().create().key("thetype").name("thename"));
|
||||
try {
|
||||
softwareManagement.createSoftwareModuleType(
|
||||
Lists.newArrayList(created, new JpaSoftwareModuleType("anothertype", "anothername", "desc", 100)));
|
||||
Lists.newArrayList(entityFactory.softwareModuleType().create().key("thetype").name("thename"),
|
||||
entityFactory.softwareModuleType().create().key("anothertype").name("anothername")));
|
||||
fail("should not have worked as module type already exists");
|
||||
} catch (final EntityAlreadyExistsException e) {
|
||||
|
||||
@@ -763,7 +662,8 @@ public class SoftwareManagementTest extends AbstractJpaIntegrationTest {
|
||||
@Description("Verifies that the creation of a softwareModuleType is failing because of invalid max assignment")
|
||||
public void createSoftwareModuleTypesFailsWithInvalidMaxAssignment() {
|
||||
try {
|
||||
softwareManagement.createSoftwareModuleType(new JpaSoftwareModuleType("type", "name", "desc", 0));
|
||||
softwareManagement.createSoftwareModuleType(
|
||||
entityFactory.softwareModuleType().create().key("type").name("name").maxAssignments(0));
|
||||
fail("should not have worked as max assignment is invalid. Should be greater than 0.");
|
||||
} catch (final ConstraintViolationException e) {
|
||||
|
||||
@@ -774,8 +674,8 @@ public class SoftwareManagementTest extends AbstractJpaIntegrationTest {
|
||||
@Description("Verfies that multiple types are created as requested.")
|
||||
public void createMultipleSoftwareModuleTypes() {
|
||||
final List<SoftwareModuleType> created = softwareManagement.createSoftwareModuleType(
|
||||
Lists.newArrayList(new JpaSoftwareModuleType("thetype", "thename", "desc", 100),
|
||||
new JpaSoftwareModuleType("thetype2", "thename2", "desc2", 100)));
|
||||
Lists.newArrayList(entityFactory.softwareModuleType().create().key("thetype").name("thename"),
|
||||
entityFactory.softwareModuleType().create().key("thetype2").name("thename2")));
|
||||
|
||||
assertThat(created.size()).as("Number of created types").isEqualTo(2);
|
||||
assertThat(softwareManagement.countSoftwareModuleTypesAll()).as("Number of types in repository").isEqualTo(5);
|
||||
@@ -784,23 +684,14 @@ public class SoftwareManagementTest extends AbstractJpaIntegrationTest {
|
||||
@Test
|
||||
@Description("Verfies that software modules are resturned that are assigned to given DS.")
|
||||
public void findSoftwareModuleByAssignedTo() {
|
||||
// test meta data
|
||||
final SoftwareModuleType testType = softwareManagement
|
||||
.createSoftwareModuleType(new JpaSoftwareModuleType("thetype", "thename", "desc", 100));
|
||||
final DistributionSetType testDsType = distributionSetManagement
|
||||
.createDistributionSetType(new JpaDistributionSetType("key", "name", "desc")
|
||||
.addMandatoryModuleType(osType).addOptionalModuleType(testType));
|
||||
|
||||
// test modules
|
||||
softwareManagement.createSoftwareModule(new JpaSoftwareModule(testType, "asis", "found", null, ""));
|
||||
final SoftwareModule one = softwareManagement
|
||||
.createSoftwareModule(new JpaSoftwareModule(testType, "found", "b", null, ""));
|
||||
final SoftwareModule one = testdataFactory.createSoftwareModuleOs();
|
||||
testdataFactory.createSoftwareModuleOs("notassigned");
|
||||
|
||||
// one soft deleted
|
||||
final SoftwareModule deleted = softwareManagement
|
||||
.createSoftwareModule(new JpaSoftwareModule(testType, "deleted", "deleted", null, ""));
|
||||
final DistributionSet set = distributionSetManagement.createDistributionSet(
|
||||
new JpaDistributionSet("set", "1", "desc", testDsType, Lists.newArrayList(one, deleted)));
|
||||
final SoftwareModule deleted = testdataFactory.createSoftwareModuleApp();
|
||||
final DistributionSet set = distributionSetManagement.createDistributionSet(entityFactory.distributionSet()
|
||||
.create().name("set").version("1").modules(Lists.newArrayList(one.getId(), deleted.getId())));
|
||||
softwareManagement.deleteSoftwareModule(deleted.getId());
|
||||
|
||||
assertThat(softwareManagement.findSoftwareModuleByAssignedTo(pageReq, set).getContent())
|
||||
@@ -817,8 +708,7 @@ public class SoftwareManagementTest extends AbstractJpaIntegrationTest {
|
||||
final String knownKey2 = "myKnownKey2";
|
||||
final String knownValue2 = "myKnownValue2";
|
||||
|
||||
final SoftwareModule ah = softwareManagement
|
||||
.createSoftwareModule(new JpaSoftwareModule(appType, "agent-hub", "1.0.1", null, ""));
|
||||
final SoftwareModule ah = testdataFactory.createSoftwareModuleApp();
|
||||
|
||||
assertThat(ah.getOptLockRevision()).isEqualTo(1);
|
||||
|
||||
@@ -827,7 +717,7 @@ public class SoftwareManagementTest extends AbstractJpaIntegrationTest {
|
||||
final SoftwareModuleMetadata swMetadata2 = new JpaSoftwareModuleMetadata(knownKey2, ah, knownValue2);
|
||||
|
||||
final List<SoftwareModuleMetadata> softwareModuleMetadata = softwareManagement
|
||||
.createSoftwareModuleMetadata(Lists.newArrayList(swMetadata1, swMetadata2));
|
||||
.createSoftwareModuleMetadata(ah.getId(), Lists.newArrayList(swMetadata1, swMetadata2));
|
||||
|
||||
final SoftwareModule changedLockRevisionModule = softwareManagement.findSoftwareModuleById(ah.getId());
|
||||
assertThat(changedLockRevisionModule.getOptLockRevision()).isEqualTo(2);
|
||||
@@ -847,13 +737,14 @@ public class SoftwareManagementTest extends AbstractJpaIntegrationTest {
|
||||
final String knownValue1 = "myKnownValue1";
|
||||
final String knownValue2 = "myKnownValue2";
|
||||
|
||||
final SoftwareModule ah = softwareManagement
|
||||
.createSoftwareModule(new JpaSoftwareModule(appType, "agent-hub", "1.0.1", null, ""));
|
||||
final SoftwareModule ah = testdataFactory.createSoftwareModuleApp();
|
||||
|
||||
softwareManagement.createSoftwareModuleMetadata(new JpaSoftwareModuleMetadata(knownKey1, ah, knownValue1));
|
||||
softwareManagement.createSoftwareModuleMetadata(ah.getId(),
|
||||
entityFactory.generateMetadata(knownKey1, knownValue1));
|
||||
|
||||
try {
|
||||
softwareManagement.createSoftwareModuleMetadata(new JpaSoftwareModuleMetadata(knownKey1, ah, knownValue2));
|
||||
softwareManagement.createSoftwareModuleMetadata(ah.getId(),
|
||||
entityFactory.generateMetadata(knownKey1, knownValue2));
|
||||
fail("should not have worked as module metadata already exists");
|
||||
} catch (final EntityAlreadyExistsException e) {
|
||||
|
||||
@@ -869,14 +760,13 @@ public class SoftwareManagementTest extends AbstractJpaIntegrationTest {
|
||||
final String knownUpdateValue = "myNewUpdatedValue";
|
||||
|
||||
// create a base software module
|
||||
final SoftwareModule ah = softwareManagement
|
||||
.createSoftwareModule(new JpaSoftwareModule(appType, "agent-hub", "1.0.1", null, ""));
|
||||
final SoftwareModule ah = testdataFactory.createSoftwareModuleApp();
|
||||
// initial opt lock revision must be 1
|
||||
assertThat(ah.getOptLockRevision()).isEqualTo(1);
|
||||
|
||||
// create an software module meta data entry
|
||||
final List<SoftwareModuleMetadata> softwareModuleMetadata = softwareManagement.createSoftwareModuleMetadata(
|
||||
Collections.singleton(new JpaSoftwareModuleMetadata(knownKey, ah, knownValue)));
|
||||
ah.getId(), Collections.singleton(entityFactory.generateMetadata(knownKey, knownValue)));
|
||||
assertThat(softwareModuleMetadata).hasSize(1);
|
||||
// base software module should have now the opt lock revision one
|
||||
// because we are modifying the
|
||||
@@ -884,15 +774,10 @@ public class SoftwareManagementTest extends AbstractJpaIntegrationTest {
|
||||
SoftwareModule changedLockRevisionModule = softwareManagement.findSoftwareModuleById(ah.getId());
|
||||
assertThat(changedLockRevisionModule.getOptLockRevision()).isEqualTo(2);
|
||||
|
||||
// modifying the meta data value
|
||||
softwareModuleMetadata.get(0).setValue(knownUpdateValue);
|
||||
softwareModuleMetadata.get(0).setSoftwareModule(softwareManagement.findSoftwareModuleById(ah.getId()));
|
||||
softwareModuleMetadata.get(0).setKey(knownKey);
|
||||
|
||||
// update the software module metadata
|
||||
Thread.sleep(100);
|
||||
final SoftwareModuleMetadata updated = softwareManagement
|
||||
.updateSoftwareModuleMetadata(softwareModuleMetadata.get(0));
|
||||
final SoftwareModuleMetadata updated = softwareManagement.updateSoftwareModuleMetadata(ah.getId(),
|
||||
entityFactory.generateMetadata(knownKey, knownUpdateValue));
|
||||
// we are updating the sw meta data so also modiying the base software
|
||||
// module so opt lock
|
||||
// revision must be two
|
||||
@@ -912,10 +797,10 @@ public class SoftwareManagementTest extends AbstractJpaIntegrationTest {
|
||||
final String knownKey1 = "myKnownKey1";
|
||||
final String knownValue1 = "myKnownValue1";
|
||||
|
||||
SoftwareModule ah = softwareManagement
|
||||
.createSoftwareModule(new JpaSoftwareModule(appType, "agent-hub", "1.0.1", null, ""));
|
||||
SoftwareModule ah = testdataFactory.createSoftwareModuleApp();
|
||||
|
||||
ah = softwareManagement.createSoftwareModuleMetadata(new JpaSoftwareModuleMetadata(knownKey1, ah, knownValue1))
|
||||
ah = softwareManagement
|
||||
.createSoftwareModuleMetadata(ah.getId(), entityFactory.generateMetadata(knownKey1, knownValue1))
|
||||
.getSoftwareModule();
|
||||
|
||||
assertThat(softwareManagement.findSoftwareModuleMetadataBySoftwareModuleId(ah.getId()))
|
||||
@@ -933,10 +818,10 @@ public class SoftwareManagementTest extends AbstractJpaIntegrationTest {
|
||||
final String knownKey1 = "myKnownKey1";
|
||||
final String knownValue1 = "myKnownValue1";
|
||||
|
||||
SoftwareModule ah = softwareManagement
|
||||
.createSoftwareModule(new JpaSoftwareModule(appType, "agent-hub", "1.0.1", null, ""));
|
||||
SoftwareModule ah = testdataFactory.createSoftwareModuleApp();
|
||||
|
||||
ah = softwareManagement.createSoftwareModuleMetadata(new JpaSoftwareModuleMetadata(knownKey1, ah, knownValue1))
|
||||
ah = softwareManagement
|
||||
.createSoftwareModuleMetadata(ah.getId(), entityFactory.generateMetadata(knownKey1, knownValue1))
|
||||
.getSoftwareModule();
|
||||
|
||||
try {
|
||||
@@ -951,22 +836,18 @@ public class SoftwareManagementTest extends AbstractJpaIntegrationTest {
|
||||
@Description("Queries and loads the metadata related to a given software module.")
|
||||
public void findAllSoftwareModuleMetadataBySwId() {
|
||||
|
||||
SoftwareModule sw1 = softwareManagement
|
||||
.createSoftwareModule(new JpaSoftwareModule(appType, "agent-hub", "1.0.1", null, ""));
|
||||
SoftwareModule sw1 = testdataFactory.createSoftwareModuleApp();
|
||||
|
||||
SoftwareModule sw2 = softwareManagement
|
||||
.createSoftwareModule(new JpaSoftwareModule(osType, "os", "1.0.1", null, ""));
|
||||
SoftwareModule sw2 = testdataFactory.createSoftwareModuleOs();
|
||||
|
||||
for (int index = 0; index < 10; index++) {
|
||||
sw1 = softwareManagement
|
||||
.createSoftwareModuleMetadata(new JpaSoftwareModuleMetadata("key" + index, sw1, "value" + index))
|
||||
.getSoftwareModule();
|
||||
sw1 = softwareManagement.createSoftwareModuleMetadata(sw1.getId(),
|
||||
entityFactory.generateMetadata("key" + index, "value" + index)).getSoftwareModule();
|
||||
}
|
||||
|
||||
for (int index = 0; index < 20; index++) {
|
||||
sw2 = softwareManagement
|
||||
.createSoftwareModuleMetadata(new JpaSoftwareModuleMetadata("key" + index, sw2, "value" + index))
|
||||
.getSoftwareModule();
|
||||
sw2 = softwareManagement.createSoftwareModuleMetadata(sw2.getId(),
|
||||
new JpaSoftwareModuleMetadata("key" + index, sw2, "value" + index)).getSoftwareModule();
|
||||
}
|
||||
|
||||
final Page<SoftwareModuleMetadata> metadataOfSw1 = softwareManagement
|
||||
|
||||
@@ -114,7 +114,7 @@ public class SystemManagementTest extends AbstractJpaIntegrationTest {
|
||||
final DistributionSet ds = testdataFactory
|
||||
.createDistributionSet("to be deployed" + x, true);
|
||||
|
||||
deploymentManagement.assignDistributionSet(ds, createdTargets);
|
||||
assignDistributionSet(ds, createdTargets);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -127,8 +127,7 @@ public class SystemManagementTest extends AbstractJpaIntegrationTest {
|
||||
}
|
||||
|
||||
private List<Target> createTestTargets(final int targets) {
|
||||
return targetManagement
|
||||
.createTargets(testdataFactory.generateTargets(targets, "testTargetOfTenant", "testTargetOfTenant"));
|
||||
return testdataFactory.createTargets(targets, "testTargetOfTenant", "testTargetOfTenant");
|
||||
}
|
||||
|
||||
private void createTestArtifact(final byte[] random) {
|
||||
|
||||
@@ -20,7 +20,6 @@ import java.util.stream.Collectors;
|
||||
|
||||
import org.eclipse.hawkbit.repository.TagManagement;
|
||||
import org.eclipse.hawkbit.repository.exception.EntityAlreadyExistsException;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSetTag;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaTargetTag;
|
||||
import org.eclipse.hawkbit.repository.model.DistributionSet;
|
||||
import org.eclipse.hawkbit.repository.model.DistributionSetFilter.DistributionSetFilterBuilder;
|
||||
@@ -63,11 +62,11 @@ public class TagManagementTest extends AbstractJpaIntegrationTest {
|
||||
final Collection<DistributionSet> dsBCs = testdataFactory.createDistributionSets("DS-BC", 13);
|
||||
final Collection<DistributionSet> dsABCs = testdataFactory.createDistributionSets("DS-ABC", 9);
|
||||
|
||||
final DistributionSetTag tagA = tagManagement.createDistributionSetTag(new JpaDistributionSetTag("A"));
|
||||
final DistributionSetTag tagB = tagManagement.createDistributionSetTag(new JpaDistributionSetTag("B"));
|
||||
final DistributionSetTag tagC = tagManagement.createDistributionSetTag(new JpaDistributionSetTag("C"));
|
||||
final DistributionSetTag tagX = tagManagement.createDistributionSetTag(new JpaDistributionSetTag("X"));
|
||||
final DistributionSetTag tagY = tagManagement.createDistributionSetTag(new JpaDistributionSetTag("Y"));
|
||||
final DistributionSetTag tagA = tagManagement.createDistributionSetTag(entityFactory.tag().create().name("A"));
|
||||
final DistributionSetTag tagB = tagManagement.createDistributionSetTag(entityFactory.tag().create().name("B"));
|
||||
final DistributionSetTag tagC = tagManagement.createDistributionSetTag(entityFactory.tag().create().name("C"));
|
||||
final DistributionSetTag tagX = tagManagement.createDistributionSetTag(entityFactory.tag().create().name("X"));
|
||||
final DistributionSetTag tagY = tagManagement.createDistributionSetTag(entityFactory.tag().create().name("Y"));
|
||||
|
||||
distributionSetManagement.toggleTagAssignment(dsAs, tagA);
|
||||
distributionSetManagement.toggleTagAssignment(dsBs, tagB);
|
||||
@@ -162,7 +161,7 @@ public class TagManagementTest extends AbstractJpaIntegrationTest {
|
||||
final Collection<DistributionSet> groupB = testdataFactory.createDistributionSets("unassigned", 20);
|
||||
|
||||
final DistributionSetTag tag = tagManagement
|
||||
.createDistributionSetTag(new JpaDistributionSetTag("tag1", "tagdesc1", ""));
|
||||
.createDistributionSetTag(entityFactory.tag().create().name("tag1").description("tagdesc1"));
|
||||
|
||||
// toggle A only -> A is now assigned
|
||||
DistributionSetTagAssignmentResult result = distributionSetManagement.toggleTagAssignment(groupA, tag);
|
||||
@@ -200,10 +199,11 @@ public class TagManagementTest extends AbstractJpaIntegrationTest {
|
||||
@Description("Verifies the toogle mechanism by means on assigning tag if at least on target in the list does not have"
|
||||
+ "the tag yet. Unassign if all of them have the tag already.")
|
||||
public void assignAndUnassignTargetTags() {
|
||||
final List<Target> groupA = targetManagement.createTargets(testdataFactory.generateTargets(20, ""));
|
||||
final List<Target> groupB = targetManagement.createTargets(testdataFactory.generateTargets(20, "groupb"));
|
||||
final List<Target> groupA = testdataFactory.createTargets(20);
|
||||
final List<Target> groupB = testdataFactory.createTargets(20, "groupb", "groupb");
|
||||
|
||||
final TargetTag tag = tagManagement.createTargetTag(new JpaTargetTag("tag1", "tagdesc1", ""));
|
||||
final TargetTag tag = tagManagement
|
||||
.createTargetTag(entityFactory.tag().create().name("tag1").description("tagdesc1"));
|
||||
|
||||
// toggle A only -> A is now assigned
|
||||
TargetTagAssignmentResult result = targetManagement.toggleTagAssignment(groupA, tag);
|
||||
@@ -256,7 +256,8 @@ public class TagManagementTest extends AbstractJpaIntegrationTest {
|
||||
@Test
|
||||
@Description("Ensures that a created tag is persisted in the repository as defined.")
|
||||
public void createTargetTag() {
|
||||
final Tag tag = tagManagement.createTargetTag(new JpaTargetTag("kai1", "kai2", "colour"));
|
||||
final Tag tag = tagManagement
|
||||
.createTargetTag(entityFactory.tag().create().name("kai1").description("kai2").colour("colour"));
|
||||
|
||||
assertThat(targetTagRepository.findByNameEquals("kai1").getDescription()).as("wrong tag ed").isEqualTo("kai2");
|
||||
assertThat(tagManagement.findTargetTag("kai1").getColour()).as("wrong tag found").isEqualTo("colour");
|
||||
@@ -295,10 +296,9 @@ public class TagManagementTest extends AbstractJpaIntegrationTest {
|
||||
|
||||
// change data
|
||||
final TargetTag savedAssigned = tags.iterator().next();
|
||||
savedAssigned.setName("test123");
|
||||
|
||||
// persist
|
||||
tagManagement.updateTargetTag(savedAssigned);
|
||||
tagManagement.updateTargetTag(entityFactory.tag().update(savedAssigned.getId()).name("test123"));
|
||||
|
||||
// check data
|
||||
assertThat(targetTagRepository.findAll()).as("Wrong target tag size").hasSize(tags.size());
|
||||
@@ -311,7 +311,8 @@ public class TagManagementTest extends AbstractJpaIntegrationTest {
|
||||
@Test
|
||||
@Description("Ensures that a created tag is persisted in the repository as defined.")
|
||||
public void createDistributionSetTag() {
|
||||
final Tag tag = tagManagement.createDistributionSetTag(new JpaDistributionSetTag("kai1", "kai2", "colour"));
|
||||
final Tag tag = tagManagement.createDistributionSetTag(
|
||||
entityFactory.tag().create().name("kai1").description("kai2").colour("colour"));
|
||||
|
||||
assertThat(distributionSetTagRepository.findByNameEquals("kai1").getDescription()).as("wrong tag found")
|
||||
.isEqualTo("kai2");
|
||||
@@ -355,10 +356,10 @@ public class TagManagementTest extends AbstractJpaIntegrationTest {
|
||||
@Test
|
||||
@Description("Ensures that a tag cannot be created if one exists already with that name (ecpects EntityAlreadyExistsException).")
|
||||
public void failedDuplicateTargetTagNameException() {
|
||||
tagManagement.createTargetTag(new JpaTargetTag("A"));
|
||||
tagManagement.createTargetTag(entityFactory.tag().create().name("A"));
|
||||
|
||||
try {
|
||||
tagManagement.createTargetTag(new JpaTargetTag("A"));
|
||||
tagManagement.createTargetTag(entityFactory.tag().create().name("A"));
|
||||
fail("should not have worked as tag already exists");
|
||||
} catch (final EntityAlreadyExistsException e) {
|
||||
|
||||
@@ -368,12 +369,11 @@ public class TagManagementTest extends AbstractJpaIntegrationTest {
|
||||
@Test
|
||||
@Description("Ensures that a tag cannot be updated to a name that already exists on another tag (ecpects EntityAlreadyExistsException).")
|
||||
public void failedDuplicateTargetTagNameExceptionAfterUpdate() {
|
||||
tagManagement.createTargetTag(new JpaTargetTag("A"));
|
||||
final TargetTag tag = tagManagement.createTargetTag(new JpaTargetTag("B"));
|
||||
tag.setName("A");
|
||||
tagManagement.createTargetTag(entityFactory.tag().create().name("A"));
|
||||
final TargetTag tag = tagManagement.createTargetTag(entityFactory.tag().create().name("B"));
|
||||
|
||||
try {
|
||||
tagManagement.updateTargetTag(tag);
|
||||
tagManagement.updateTargetTag(entityFactory.tag().update(tag.getId()).name("A"));
|
||||
fail("should not have worked as tag already exists");
|
||||
} catch (final EntityAlreadyExistsException e) {
|
||||
|
||||
@@ -383,9 +383,9 @@ public class TagManagementTest extends AbstractJpaIntegrationTest {
|
||||
@Test
|
||||
@Description("Ensures that a tag cannot be created if one exists already with that name (ecpects EntityAlreadyExistsException).")
|
||||
public void failedDuplicateDsTagNameException() {
|
||||
tagManagement.createDistributionSetTag(new JpaDistributionSetTag("A"));
|
||||
tagManagement.createDistributionSetTag(entityFactory.tag().create().name("A"));
|
||||
try {
|
||||
tagManagement.createDistributionSetTag(new JpaDistributionSetTag("A"));
|
||||
tagManagement.createDistributionSetTag(entityFactory.tag().create().name("A"));
|
||||
fail("should not have worked as tag already exists");
|
||||
} catch (final EntityAlreadyExistsException e) {
|
||||
|
||||
@@ -395,12 +395,11 @@ public class TagManagementTest extends AbstractJpaIntegrationTest {
|
||||
@Test
|
||||
@Description("Ensures that a tag cannot be updated to a name that already exists on another tag (ecpects EntityAlreadyExistsException).")
|
||||
public void failedDuplicateDsTagNameExceptionAfterUpdate() {
|
||||
tagManagement.createDistributionSetTag(new JpaDistributionSetTag("A"));
|
||||
final DistributionSetTag tag = tagManagement.createDistributionSetTag(new JpaDistributionSetTag("B"));
|
||||
tag.setName("A");
|
||||
tagManagement.createDistributionSetTag(entityFactory.tag().create().name("A"));
|
||||
final DistributionSetTag tag = tagManagement.createDistributionSetTag(entityFactory.tag().create().name("B"));
|
||||
|
||||
try {
|
||||
tagManagement.updateDistributionSetTag(tag);
|
||||
tagManagement.updateDistributionSetTag(entityFactory.tag().update(tag.getId()).name("A"));
|
||||
fail("should not have worked as tag already exists");
|
||||
} catch (final EntityAlreadyExistsException e) {
|
||||
|
||||
@@ -416,10 +415,9 @@ public class TagManagementTest extends AbstractJpaIntegrationTest {
|
||||
|
||||
// change data
|
||||
final DistributionSetTag savedAssigned = tags.iterator().next();
|
||||
savedAssigned.setName("test123");
|
||||
|
||||
// persist
|
||||
tagManagement.updateDistributionSetTag(savedAssigned);
|
||||
tagManagement.updateDistributionSetTag(entityFactory.tag().update(savedAssigned.getId()).name("test123"));
|
||||
|
||||
// check data
|
||||
assertThat(tagManagement.findAllDistributionSetTags()).as("Wrong size of ds tags").hasSize(tags.size());
|
||||
@@ -439,7 +437,7 @@ public class TagManagementTest extends AbstractJpaIntegrationTest {
|
||||
|
||||
private List<JpaTargetTag> createTargetsWithTags() {
|
||||
final List<Target> targets = testdataFactory.createTargets(20);
|
||||
final Iterable<TargetTag> tags = tagManagement.createTargetTags(testdataFactory.generateTargetTags(20));
|
||||
final Iterable<TargetTag> tags = testdataFactory.createTargetTags(20, "");
|
||||
|
||||
tags.forEach(tag -> targetManagement.toggleTagAssignment(targets, tag));
|
||||
|
||||
|
||||
@@ -21,8 +21,6 @@ import java.util.List;
|
||||
import org.eclipse.hawkbit.repository.TargetFilterQueryManagement;
|
||||
import org.eclipse.hawkbit.repository.exception.EntityAlreadyExistsException;
|
||||
import org.eclipse.hawkbit.repository.exception.RSQLParameterUnsupportedFieldException;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSet;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaTargetFilterQuery;
|
||||
import org.eclipse.hawkbit.repository.model.DistributionSet;
|
||||
import org.eclipse.hawkbit.repository.model.Target;
|
||||
import org.eclipse.hawkbit.repository.model.TargetFilterQuery;
|
||||
@@ -46,8 +44,8 @@ public class TargetFilterQueryManagementTest extends AbstractJpaIntegrationTest
|
||||
@Description("Test creation of target filter query.")
|
||||
public void createTargetFilterQuery() {
|
||||
final String filterName = "new target filter";
|
||||
final TargetFilterQuery targetFilterQuery = targetFilterQueryManagement
|
||||
.createTargetFilterQuery(new JpaTargetFilterQuery(filterName, "name==PendingTargets001"));
|
||||
final TargetFilterQuery targetFilterQuery = targetFilterQueryManagement.createTargetFilterQuery(
|
||||
entityFactory.targetFilterQuery().create().name(filterName).query("name==PendingTargets001"));
|
||||
assertEquals("Retrieved newly created custom target filter", targetFilterQuery,
|
||||
targetFilterQueryManagement.findTargetFilterQueryByName(filterName));
|
||||
}
|
||||
@@ -56,13 +54,13 @@ public class TargetFilterQueryManagementTest extends AbstractJpaIntegrationTest
|
||||
@Description("Test searching a target filter query.")
|
||||
public void searchTargetFilterQuery() {
|
||||
final String filterName = "targetFilterQueryName";
|
||||
final TargetFilterQuery targetFilterQuery = targetFilterQueryManagement
|
||||
.createTargetFilterQuery(new JpaTargetFilterQuery(filterName, "name==PendingTargets001"));
|
||||
final TargetFilterQuery targetFilterQuery = targetFilterQueryManagement.createTargetFilterQuery(
|
||||
entityFactory.targetFilterQuery().create().name(filterName).query("name==PendingTargets001"));
|
||||
|
||||
targetFilterQueryManagement
|
||||
.createTargetFilterQuery(new JpaTargetFilterQuery("someOtherFilter", "name==PendingTargets002"));
|
||||
targetFilterQueryManagement.createTargetFilterQuery(
|
||||
entityFactory.targetFilterQuery().create().name("someOtherFilter").query("name==PendingTargets002"));
|
||||
|
||||
List<TargetFilterQuery> results = targetFilterQueryManagement
|
||||
final List<TargetFilterQuery> results = targetFilterQueryManagement
|
||||
.findTargetFilterQueryByFilter(new PageRequest(0, 10), "name==" + filterName).getContent();
|
||||
assertEquals("Search result should have 1 result", 1, results.size());
|
||||
assertEquals("Retrieved newly created custom target filter", targetFilterQuery, results.get(0));
|
||||
@@ -81,12 +79,12 @@ public class TargetFilterQueryManagementTest extends AbstractJpaIntegrationTest
|
||||
@Description("Checks if the EntityAlreadyExistsException is thrown if a targetfilterquery with the same name are created more than once.")
|
||||
public void createDuplicateTargetFilterQuery() {
|
||||
final String filterName = "new target filter duplicate";
|
||||
targetFilterQueryManagement
|
||||
.createTargetFilterQuery(new JpaTargetFilterQuery(filterName, "name==PendingTargets001"));
|
||||
targetFilterQueryManagement.createTargetFilterQuery(
|
||||
entityFactory.targetFilterQuery().create().name(filterName).query("name==PendingTargets001"));
|
||||
|
||||
try {
|
||||
targetFilterQueryManagement
|
||||
.createTargetFilterQuery(new JpaTargetFilterQuery(filterName, "name==PendingTargets001"));
|
||||
targetFilterQueryManagement.createTargetFilterQuery(
|
||||
entityFactory.targetFilterQuery().create().name(filterName).query("name==PendingTargets001"));
|
||||
fail("should not have worked as query already exists");
|
||||
} catch (final EntityAlreadyExistsException e) {
|
||||
|
||||
@@ -97,8 +95,8 @@ public class TargetFilterQueryManagementTest extends AbstractJpaIntegrationTest
|
||||
@Description("Test deletion of target filter query.")
|
||||
public void deleteTargetFilterQuery() {
|
||||
final String filterName = "delete_target_filter_query";
|
||||
final TargetFilterQuery targetFilterQuery = targetFilterQueryManagement
|
||||
.createTargetFilterQuery(new JpaTargetFilterQuery(filterName, "name==PendingTargets001"));
|
||||
final TargetFilterQuery targetFilterQuery = targetFilterQueryManagement.createTargetFilterQuery(
|
||||
entityFactory.targetFilterQuery().create().name(filterName).query("name==PendingTargets001"));
|
||||
targetFilterQueryManagement.deleteTargetFilterQuery(targetFilterQuery.getId());
|
||||
assertEquals("Returns null as the target filter is deleted", null,
|
||||
targetFilterQueryManagement.findTargetFilterQueryById(targetFilterQuery.getId()));
|
||||
@@ -109,12 +107,12 @@ public class TargetFilterQueryManagementTest extends AbstractJpaIntegrationTest
|
||||
@Description("Test updation of target filter query.")
|
||||
public void updateTargetFilterQuery() {
|
||||
final String filterName = "target_filter_01";
|
||||
final TargetFilterQuery targetFilterQuery = targetFilterQueryManagement
|
||||
.createTargetFilterQuery(new JpaTargetFilterQuery(filterName, "name==PendingTargets001"));
|
||||
final TargetFilterQuery targetFilterQuery = targetFilterQueryManagement.createTargetFilterQuery(
|
||||
entityFactory.targetFilterQuery().create().name(filterName).query("name==PendingTargets001"));
|
||||
|
||||
final String newQuery = "status==UNKNOWN";
|
||||
targetFilterQuery.setQuery(newQuery);
|
||||
targetFilterQueryManagement.updateTargetFilterQuery(targetFilterQuery);
|
||||
targetFilterQueryManagement.updateTargetFilterQuery(
|
||||
entityFactory.targetFilterQuery().update(targetFilterQuery.getId()).query(newQuery));
|
||||
assertEquals("Returns updated target filter query", newQuery,
|
||||
targetFilterQueryManagement.findTargetFilterQueryByName(filterName).getQuery());
|
||||
|
||||
@@ -124,20 +122,17 @@ public class TargetFilterQueryManagementTest extends AbstractJpaIntegrationTest
|
||||
@Description("Test assigning a distribution set")
|
||||
public void assignDistributionSet() {
|
||||
final String filterName = "target_filter_02";
|
||||
final TargetFilterQuery targetFilterQuery = targetFilterQueryManagement
|
||||
.createTargetFilterQuery(new JpaTargetFilterQuery(filterName, "name==PendingTargets001"));
|
||||
final TargetFilterQuery targetFilterQuery = targetFilterQueryManagement.createTargetFilterQuery(
|
||||
entityFactory.targetFilterQuery().create().name(filterName).query("name==PendingTargets001"));
|
||||
|
||||
final DistributionSet distributionSet = distributionSetManagement.createDistributionSet(new JpaDistributionSet(
|
||||
"dist_Set_01", "0.1", "", null, null
|
||||
));
|
||||
final DistributionSet distributionSet = testdataFactory.createDistributionSet();
|
||||
|
||||
targetFilterQuery.setAutoAssignDistributionSet(distributionSet);
|
||||
targetFilterQueryManagement.updateTargetFilterQuery(targetFilterQuery);
|
||||
targetFilterQueryManagement.updateTargetFilterQueryAutoAssignDS(targetFilterQuery.getId(),
|
||||
distributionSet.getId());
|
||||
|
||||
TargetFilterQuery tfq = targetFilterQueryManagement.findTargetFilterQueryByName(filterName);
|
||||
final TargetFilterQuery tfq = targetFilterQueryManagement.findTargetFilterQueryByName(filterName);
|
||||
|
||||
assertEquals("Returns correct distribution set", distributionSet,
|
||||
tfq.getAutoAssignDistributionSet());
|
||||
assertEquals("Returns correct distribution set", distributionSet, tfq.getAutoAssignDistributionSet());
|
||||
|
||||
}
|
||||
|
||||
@@ -145,20 +140,17 @@ public class TargetFilterQueryManagementTest extends AbstractJpaIntegrationTest
|
||||
@Description("Test removing distribution set while it has a relation to a target filter query")
|
||||
public void removeAssignDistributionSet() {
|
||||
final String filterName = "target_filter_03";
|
||||
final TargetFilterQuery targetFilterQuery = targetFilterQueryManagement
|
||||
.createTargetFilterQuery(new JpaTargetFilterQuery(filterName, "name==PendingTargets001"));
|
||||
final TargetFilterQuery targetFilterQuery = targetFilterQueryManagement.createTargetFilterQuery(
|
||||
entityFactory.targetFilterQuery().create().name(filterName).query("name==PendingTargets001"));
|
||||
|
||||
final DistributionSet distributionSet = distributionSetManagement.createDistributionSet(new JpaDistributionSet(
|
||||
"dist_Set_02", "0.1", "", null, null
|
||||
));
|
||||
final DistributionSet distributionSet = testdataFactory.createDistributionSet();
|
||||
|
||||
targetFilterQuery.setAutoAssignDistributionSet(distributionSet);
|
||||
targetFilterQueryManagement.updateTargetFilterQuery(targetFilterQuery);
|
||||
targetFilterQueryManagement.updateTargetFilterQueryAutoAssignDS(targetFilterQuery.getId(),
|
||||
distributionSet.getId());
|
||||
|
||||
// Check if target filter query is there
|
||||
TargetFilterQuery tfq = targetFilterQueryManagement.findTargetFilterQueryByName(filterName);
|
||||
assertEquals("Returns correct distribution set", distributionSet,
|
||||
tfq.getAutoAssignDistributionSet());
|
||||
assertEquals("Returns correct distribution set", distributionSet, tfq.getAutoAssignDistributionSet());
|
||||
|
||||
distributionSetManagement.deleteDistributionSet(distributionSet);
|
||||
|
||||
@@ -173,15 +165,17 @@ public class TargetFilterQueryManagementTest extends AbstractJpaIntegrationTest
|
||||
@Description("Test to implicitly remove the auto assign distribution set when the ds is soft deleted")
|
||||
public void implicitlyRemoveAssignDistributionSet() {
|
||||
final String filterName = "target_filter_03";
|
||||
DistributionSet distributionSet = testdataFactory.createDistributionSet("dist_set");
|
||||
Target target = testdataFactory.createTarget();
|
||||
final DistributionSet distributionSet = testdataFactory.createDistributionSet("dist_set");
|
||||
final Target target = testdataFactory.createTarget();
|
||||
|
||||
// Assign the distribution set to an target, to force a soft delete in a
|
||||
// later step
|
||||
deploymentManagement.assignDistributionSet(distributionSet.getId(), target.getControllerId());
|
||||
assignDistributionSet(distributionSet.getId(), target.getControllerId());
|
||||
|
||||
targetFilterQueryManagement.createTargetFilterQuery(
|
||||
new JpaTargetFilterQuery(filterName, "name==PendingTargets001", (JpaDistributionSet) distributionSet));
|
||||
targetFilterQueryManagement.updateTargetFilterQueryAutoAssignDS(targetFilterQueryManagement
|
||||
.createTargetFilterQuery(
|
||||
entityFactory.targetFilterQuery().create().name(filterName).query("name==PendingTargets001"))
|
||||
.getId(), distributionSet.getId());
|
||||
|
||||
// Check if target filter query is there with the distribution set
|
||||
TargetFilterQuery tfq = targetFilterQueryManagement.findTargetFilterQueryByName(filterName);
|
||||
@@ -208,19 +202,24 @@ public class TargetFilterQueryManagementTest extends AbstractJpaIntegrationTest
|
||||
|
||||
assertEquals(0L, targetFilterQueryManagement.countAllTargetFilterQuery().longValue());
|
||||
|
||||
targetFilterQueryManagement.createTargetFilterQuery(new JpaTargetFilterQuery("a", "name==*"));
|
||||
targetFilterQueryManagement.createTargetFilterQuery(new JpaTargetFilterQuery("b", "name==*"));
|
||||
targetFilterQueryManagement
|
||||
.createTargetFilterQuery(entityFactory.targetFilterQuery().create().name("a").query("name==*"));
|
||||
targetFilterQueryManagement
|
||||
.createTargetFilterQuery(entityFactory.targetFilterQuery().create().name("b").query("name==*"));
|
||||
|
||||
final DistributionSet distributionSet = distributionSetManagement
|
||||
.createDistributionSet(new JpaDistributionSet("dist_Set_01", "0.1", "", null, null));
|
||||
final DistributionSet distributionSet2 = distributionSetManagement
|
||||
.createDistributionSet(new JpaDistributionSet("dist_Set_02", "0.1", "", null, null));
|
||||
final DistributionSet distributionSet = testdataFactory.createDistributionSet();
|
||||
final DistributionSet distributionSet2 = testdataFactory.createDistributionSet("2");
|
||||
|
||||
final TargetFilterQuery tfq = targetFilterQueryManagement.createTargetFilterQuery(
|
||||
new JpaTargetFilterQuery("c", "name==x", (JpaDistributionSet) distributionSet));
|
||||
final TargetFilterQuery tfq = targetFilterQueryManagement
|
||||
.updateTargetFilterQueryAutoAssignDS(
|
||||
targetFilterQueryManagement.createTargetFilterQuery(
|
||||
entityFactory.targetFilterQuery().create().name("c").query("name==x")).getId(),
|
||||
distributionSet.getId());
|
||||
|
||||
final TargetFilterQuery tfq2 = targetFilterQueryManagement.createTargetFilterQuery(
|
||||
new JpaTargetFilterQuery(filterName, "name==z*", (JpaDistributionSet) distributionSet2));
|
||||
final TargetFilterQuery tfq2 = targetFilterQueryManagement.updateTargetFilterQueryAutoAssignDS(
|
||||
targetFilterQueryManagement.createTargetFilterQuery(
|
||||
entityFactory.targetFilterQuery().create().name(filterName).query("name==z*")).getId(),
|
||||
distributionSet2.getId());
|
||||
|
||||
assertEquals(4L, targetFilterQueryManagement.countAllTargetFilterQuery().longValue());
|
||||
|
||||
@@ -231,8 +230,7 @@ public class TargetFilterQueryManagementTest extends AbstractJpaIntegrationTest
|
||||
|
||||
assertEquals("Returns correct target filter query", tfq.getId(), tfqList.iterator().next().getId());
|
||||
|
||||
tfq2.setAutoAssignDistributionSet(distributionSet);
|
||||
targetFilterQueryManagement.updateTargetFilterQuery(tfq2);
|
||||
targetFilterQueryManagement.updateTargetFilterQueryAutoAssignDS(tfq2.getId(), distributionSet.getId());
|
||||
|
||||
// check if find works for two
|
||||
tfqList = targetFilterQueryManagement.findTargetFilterQueryByAutoAssignDS(new PageRequest(0, 500),
|
||||
|
||||
@@ -19,14 +19,9 @@ import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.eclipse.hawkbit.repository.FilterParams;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaAction;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaActionStatus;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaTarget;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaTargetFilterQuery;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaTargetTag;
|
||||
import org.eclipse.hawkbit.repository.model.Action;
|
||||
import org.eclipse.hawkbit.repository.model.Action.Status;
|
||||
import org.eclipse.hawkbit.repository.model.ActionStatus;
|
||||
import org.eclipse.hawkbit.repository.model.DistributionSet;
|
||||
import org.eclipse.hawkbit.repository.model.Target;
|
||||
import org.eclipse.hawkbit.repository.model.TargetFilterQuery;
|
||||
@@ -54,10 +49,10 @@ public class TargetManagementSearchTest extends AbstractJpaIntegrationTest {
|
||||
+ "That includes both the test itself, as a count operation with the same filters "
|
||||
+ "and query definitions by RSQL (named and un-named).")
|
||||
public void targetSearchWithVariousFilterCombinations() {
|
||||
final TargetTag targTagX = tagManagement.createTargetTag(new JpaTargetTag("TargTag-X"));
|
||||
final TargetTag targTagY = tagManagement.createTargetTag(new JpaTargetTag("TargTag-Y"));
|
||||
final TargetTag targTagZ = tagManagement.createTargetTag(new JpaTargetTag("TargTag-Z"));
|
||||
final TargetTag targTagW = tagManagement.createTargetTag(new JpaTargetTag("TargTag-W"));
|
||||
final TargetTag targTagX = tagManagement.createTargetTag(entityFactory.tag().create().name("TargTag-X"));
|
||||
final TargetTag targTagY = tagManagement.createTargetTag(entityFactory.tag().create().name("TargTag-Y"));
|
||||
final TargetTag targTagZ = tagManagement.createTargetTag(entityFactory.tag().create().name("TargTag-Z"));
|
||||
final TargetTag targTagW = tagManagement.createTargetTag(entityFactory.tag().create().name("TargTag-W"));
|
||||
|
||||
final DistributionSet setA = testdataFactory.createDistributionSet("");
|
||||
|
||||
@@ -68,72 +63,54 @@ public class TargetManagementSearchTest extends AbstractJpaIntegrationTest {
|
||||
final Long lastTargetNull = null;
|
||||
|
||||
final String targetDsAIdPref = "targ-A";
|
||||
List<Target> targAs = new ArrayList<Target>();
|
||||
for (Target t : testdataFactory.generateTargets(100, targetDsAIdPref, targetDsAIdPref.concat(" description"))) {
|
||||
targAs.add(targetManagement.createTarget(t, TargetUpdateStatus.UNKNOWN, lastTargetQueryNotOverdue,
|
||||
t.getTargetInfo().getAddress()));
|
||||
}
|
||||
List<Target> targAs = testdataFactory.createTargets(100, targetDsAIdPref,
|
||||
targetDsAIdPref.concat(" description"), lastTargetQueryNotOverdue);
|
||||
targAs = targetManagement.toggleTagAssignment(targAs, targTagX).getAssignedEntity();
|
||||
|
||||
final String targetDsBIdPref = "targ-B";
|
||||
List<Target> targBs = new ArrayList<Target>();
|
||||
for (Target t : testdataFactory.generateTargets(100, targetDsBIdPref, targetDsBIdPref.concat(" description"))) {
|
||||
targBs.add(targetManagement.createTarget(t, TargetUpdateStatus.UNKNOWN, lastTargetQueryAlwaysOverdue,
|
||||
t.getTargetInfo().getAddress()));
|
||||
}
|
||||
List<Target> targBs = testdataFactory.createTargets(100, targetDsBIdPref,
|
||||
targetDsBIdPref.concat(" description"), lastTargetQueryAlwaysOverdue);
|
||||
|
||||
targBs = targetManagement.toggleTagAssignment(targBs, targTagY).getAssignedEntity();
|
||||
targBs = targetManagement.toggleTagAssignment(targBs, targTagW).getAssignedEntity();
|
||||
|
||||
final String targetDsCIdPref = "targ-C";
|
||||
List<Target> targCs = new ArrayList<Target>();
|
||||
for (Target t : testdataFactory.generateTargets(100, targetDsCIdPref, targetDsCIdPref.concat(" description"))) {
|
||||
targCs.add(targetManagement.createTarget(t, TargetUpdateStatus.UNKNOWN, lastTargetQueryAlwaysOverdue,
|
||||
t.getTargetInfo().getAddress()));
|
||||
}
|
||||
List<Target> targCs = testdataFactory.createTargets(100, targetDsCIdPref,
|
||||
targetDsCIdPref.concat(" description"), lastTargetQueryAlwaysOverdue);
|
||||
|
||||
targCs = targetManagement.toggleTagAssignment(targCs, targTagZ).getAssignedEntity();
|
||||
targCs = targetManagement.toggleTagAssignment(targCs, targTagW).getAssignedEntity();
|
||||
|
||||
final String targetDsDIdPref = "targ-D";
|
||||
List<Target> targDs = new ArrayList<Target>();
|
||||
for (Target t : testdataFactory.generateTargets(100, targetDsDIdPref, targetDsDIdPref.concat(" description"))) {
|
||||
targDs.add(targetManagement.createTarget(t, TargetUpdateStatus.UNKNOWN, lastTargetNull,
|
||||
t.getTargetInfo().getAddress()));
|
||||
}
|
||||
final List<Target> targDs = testdataFactory.createTargets(100, targetDsDIdPref,
|
||||
targetDsDIdPref.concat(" description"), lastTargetNull);
|
||||
|
||||
final String assignedC = targCs.iterator().next().getControllerId();
|
||||
deploymentManagement.assignDistributionSet(setA.getId(), assignedC);
|
||||
assignDistributionSet(setA.getId(), assignedC);
|
||||
final String assignedA = targAs.iterator().next().getControllerId();
|
||||
deploymentManagement.assignDistributionSet(setA.getId(), assignedA);
|
||||
assignDistributionSet(setA.getId(), assignedA);
|
||||
final String assignedB = targBs.iterator().next().getControllerId();
|
||||
deploymentManagement.assignDistributionSet(setA.getId(), assignedB);
|
||||
assignDistributionSet(setA.getId(), assignedB);
|
||||
final String installedC = targCs.iterator().next().getControllerId();
|
||||
final Long actionId = deploymentManagement.assignDistributionSet(installedSet.getId(), assignedC).getActions()
|
||||
.get(0);
|
||||
final Long actionId = assignDistributionSet(installedSet.getId(), assignedC).getActions().get(0);
|
||||
|
||||
// set one installed DS also
|
||||
final Action action = deploymentManagement.findActionWithDetails(actionId);
|
||||
action.setStatus(Status.FINISHED);
|
||||
controllerManagament.addUpdateActionStatus(
|
||||
new JpaActionStatus((JpaAction) action, Status.FINISHED, System.currentTimeMillis(), "message"));
|
||||
deploymentManagement.assignDistributionSet(setA.getId(), installedC);
|
||||
entityFactory.actionStatus().create(actionId).status(Status.FINISHED).message("message"));
|
||||
assignDistributionSet(setA.getId(), installedC);
|
||||
|
||||
final List<TargetUpdateStatus> unknown = new ArrayList<>();
|
||||
unknown.add(TargetUpdateStatus.UNKNOWN);
|
||||
|
||||
final List<TargetUpdateStatus> pending = new ArrayList<>();
|
||||
pending.add(TargetUpdateStatus.PENDING);
|
||||
|
||||
final List<TargetUpdateStatus> both = new ArrayList<>();
|
||||
both.add(TargetUpdateStatus.UNKNOWN);
|
||||
both.add(TargetUpdateStatus.PENDING);
|
||||
final List<TargetUpdateStatus> unknown = Lists.newArrayList(TargetUpdateStatus.UNKNOWN);
|
||||
final List<TargetUpdateStatus> pending = Lists.newArrayList(TargetUpdateStatus.PENDING);
|
||||
final List<TargetUpdateStatus> both = Lists.newArrayList(TargetUpdateStatus.UNKNOWN,
|
||||
TargetUpdateStatus.PENDING);
|
||||
|
||||
// get final updated version of targets
|
||||
targAs = targetManagement.findTargetByControllerID(
|
||||
targAs.stream().map(target -> target.getControllerId()).collect(Collectors.toList()));
|
||||
targBs = targetManagement.findTargetByControllerID(
|
||||
targBs.stream().map(target -> target.getControllerId()).collect(Collectors.toList()));
|
||||
targCs = targetManagement.findTargetByControllerID(
|
||||
targCs.stream().map(target -> target.getControllerId()).collect(Collectors.toList()));
|
||||
targAs = targetManagement
|
||||
.findTargetByControllerID(targAs.stream().map(Target::getControllerId).collect(Collectors.toList()));
|
||||
targBs = targetManagement
|
||||
.findTargetByControllerID(targBs.stream().map(Target::getControllerId).collect(Collectors.toList()));
|
||||
targCs = targetManagement
|
||||
.findTargetByControllerID(targCs.stream().map(Target::getControllerId).collect(Collectors.toList()));
|
||||
|
||||
// try to find several targets with different filter settings
|
||||
verifyThatRepositoryContains400Targets();
|
||||
@@ -352,7 +329,8 @@ public class TargetManagementSearchTest extends AbstractJpaIntegrationTest {
|
||||
|
||||
assertThat(targetManagement
|
||||
.findTargetByFilters(pageReq, pending, null, null, setA.getId(), Boolean.FALSE, new String[0])
|
||||
.getContent()).as("has number of elements").hasSize(3).as("that number is also returned by count query")
|
||||
.getContent()).as("has number of elements").hasSize(3)
|
||||
.as("that number is also returned by count query")
|
||||
.hasSize(Ints.saturatedCast(targetManagement.countTargetByFilters(pending, null, null,
|
||||
setA.getId(), Boolean.FALSE, new String[0])))
|
||||
.as("and contains the following elements").containsAll(expected)
|
||||
@@ -427,8 +405,9 @@ public class TargetManagementSearchTest extends AbstractJpaIntegrationTest {
|
||||
assertThat(targetManagement
|
||||
.findTargetByFilters(pageReq, unknown, null, "%targ-A%", null, Boolean.FALSE, new String[0])
|
||||
.getContent()).as("has number of elements").hasSize(99)
|
||||
.as("that number is also returned by count query").hasSize(Ints.saturatedCast(targetManagement
|
||||
.countTargetByFilters(unknown, null, "%targ-A%", null, Boolean.FALSE, new String[0])))
|
||||
.as("that number is also returned by count query")
|
||||
.hasSize(Ints.saturatedCast(targetManagement.countTargetByFilters(unknown, null, "%targ-A%",
|
||||
null, Boolean.FALSE, new String[0])))
|
||||
.as("and contains the following elements").containsAll(expected)
|
||||
.as("and filter query returns the same result")
|
||||
.containsAll(targetManagement.findTargetsAll(query, pageReq).getContent())
|
||||
@@ -450,7 +429,8 @@ public class TargetManagementSearchTest extends AbstractJpaIntegrationTest {
|
||||
|
||||
assertThat(targetManagement
|
||||
.findTargetByFilters(pageReq, unknown, null, null, setA.getId(), Boolean.FALSE, new String[0])
|
||||
.getContent()).as("has number of elements").hasSize(0).as("that number is also returned by count query")
|
||||
.getContent()).as("has number of elements").hasSize(0)
|
||||
.as("that number is also returned by count query")
|
||||
.hasSize(Ints.saturatedCast(targetManagement.countTargetByFilters(unknown, null, null,
|
||||
setA.getId(), Boolean.FALSE, new String[0])))
|
||||
.as("and filter query returns the same result")
|
||||
@@ -727,19 +707,17 @@ public class TargetManagementSearchTest extends AbstractJpaIntegrationTest {
|
||||
@Description("Tests the correct order of targets based on selected distribution set. The system expects to have an order based on installed, assigned DS.")
|
||||
public void targetSearchWithVariousFilterCombinationsAndOrderByDistributionSet() {
|
||||
|
||||
final List<Target> notAssigned = targetManagement
|
||||
.createTargets(testdataFactory.generateTargets(3, "not", "first description"));
|
||||
List<Target> targAssigned = targetManagement
|
||||
.createTargets(testdataFactory.generateTargets(3, "assigned", "first description"));
|
||||
List<Target> targInstalled = targetManagement
|
||||
.createTargets(testdataFactory.generateTargets(3, "installed", "first description"));
|
||||
final List<Target> notAssigned = testdataFactory.createTargets(3, "not", "first description");
|
||||
List<Target> targAssigned = testdataFactory.createTargets(3, "assigned", "first description");
|
||||
List<Target> targInstalled = testdataFactory.createTargets(3, "installed", "first description");
|
||||
|
||||
final DistributionSet ds = testdataFactory.createDistributionSet("a");
|
||||
|
||||
targAssigned = Lists
|
||||
.newLinkedList(deploymentManagement.assignDistributionSet(ds, targAssigned).getAssignedEntity());
|
||||
targInstalled = deploymentManagement.assignDistributionSet(ds, targInstalled).getAssignedEntity();
|
||||
targInstalled = sendUpdateActionStatusToTargets(ds, targInstalled, Status.FINISHED, "installed");
|
||||
targAssigned = Lists.newLinkedList(assignDistributionSet(ds, targAssigned).getAssignedEntity());
|
||||
targInstalled = assignDistributionSet(ds, targInstalled).getAssignedEntity();
|
||||
targInstalled = testdataFactory
|
||||
.sendUpdateActionStatusToTargets(targInstalled, Status.FINISHED, Collections.singletonList("installed"))
|
||||
.stream().map(Action::getTarget).collect(Collectors.toList());
|
||||
|
||||
final Slice<Target> result = targetManagement.findTargetsAllOrderByLinkedDistributionSet(pageReq, ds.getId(),
|
||||
new FilterParams(null, null, null, null, Boolean.FALSE, new String[0]));
|
||||
@@ -770,31 +748,26 @@ public class TargetManagementSearchTest extends AbstractJpaIntegrationTest {
|
||||
final Long[] overdueMix = { lastTargetQueryAlwaysOverdue, lastTargetQueryNotOverdue,
|
||||
lastTargetQueryAlwaysOverdue, lastTargetNull, lastTargetQueryAlwaysOverdue };
|
||||
|
||||
List<Target> notAssignedToBeCreated = testdataFactory.generateTargets(overdueMix.length, "not",
|
||||
"first description");
|
||||
List<Target> targAssignedToBeCreated = testdataFactory.generateTargets(overdueMix.length, "assigned",
|
||||
"first description");
|
||||
List<Target> targInstalledToBeCreated = testdataFactory.generateTargets(overdueMix.length, "installed",
|
||||
"first description");
|
||||
|
||||
List<Target> notAssigned = new ArrayList<>();
|
||||
List<Target> targAssigned = new ArrayList<>();
|
||||
List<Target> targInstalled = new ArrayList<>();
|
||||
final List<Target> notAssigned = Lists.newArrayListWithExpectedSize(overdueMix.length);
|
||||
List<Target> targAssigned = Lists.newArrayListWithExpectedSize(overdueMix.length);
|
||||
List<Target> targInstalled = Lists.newArrayListWithExpectedSize(overdueMix.length);
|
||||
|
||||
for (int i = 0; i < overdueMix.length; i++) {
|
||||
notAssigned.add(targetManagement.createTarget(notAssignedToBeCreated.get(i), TargetUpdateStatus.UNKNOWN,
|
||||
overdueMix[i], notAssignedToBeCreated.get(i).getTargetInfo().getAddress()));
|
||||
targAssigned.add(targetManagement.createTarget(targAssignedToBeCreated.get(i), TargetUpdateStatus.UNKNOWN,
|
||||
overdueMix[i], targAssignedToBeCreated.get(i).getTargetInfo().getAddress()));
|
||||
targInstalled.add(targetManagement.createTarget(targInstalledToBeCreated.get(i), TargetUpdateStatus.UNKNOWN,
|
||||
overdueMix[i], targInstalledToBeCreated.get(i).getTargetInfo().getAddress()));
|
||||
notAssigned.add(targetManagement.createTarget(
|
||||
entityFactory.target().create().controllerId("not" + i).lastTargetQuery(overdueMix[i])));
|
||||
targAssigned.add(targetManagement.createTarget(
|
||||
entityFactory.target().create().controllerId("assigned" + i).lastTargetQuery(overdueMix[i])));
|
||||
targInstalled.add(targetManagement.createTarget(
|
||||
entityFactory.target().create().controllerId("installed" + i).lastTargetQuery(overdueMix[i])));
|
||||
}
|
||||
|
||||
final DistributionSet ds = testdataFactory.createDistributionSet("a");
|
||||
|
||||
targAssigned = deploymentManagement.assignDistributionSet(ds, targAssigned).getAssignedEntity();
|
||||
targInstalled = deploymentManagement.assignDistributionSet(ds, targInstalled).getAssignedEntity();
|
||||
targInstalled = sendUpdateActionStatusToTargets(ds, targInstalled, Status.FINISHED, "installed");
|
||||
targAssigned = assignDistributionSet(ds, targAssigned).getAssignedEntity();
|
||||
targInstalled = assignDistributionSet(ds, targInstalled).getAssignedEntity();
|
||||
targInstalled = testdataFactory
|
||||
.sendUpdateActionStatusToTargets(targInstalled, Status.FINISHED, Collections.singletonList("installed"))
|
||||
.stream().map(action -> action.getTarget()).collect(Collectors.toList());
|
||||
|
||||
final Slice<Target> result = targetManagement.findTargetsAllOrderByLinkedDistributionSet(pageReq, ds.getId(),
|
||||
new FilterParams(null, null, Boolean.TRUE, null, Boolean.FALSE, new String[0]));
|
||||
@@ -821,10 +794,10 @@ public class TargetManagementSearchTest extends AbstractJpaIntegrationTest {
|
||||
@Description("Verfies that targets with given assigned DS are returned from repository.")
|
||||
public void findTargetByAssignedDistributionSet() {
|
||||
final DistributionSet assignedSet = testdataFactory.createDistributionSet("");
|
||||
targetManagement.createTargets(testdataFactory.generateTargets(10, "unassigned"));
|
||||
List<Target> assignedtargets = targetManagement.createTargets(testdataFactory.generateTargets(10, "assigned"));
|
||||
testdataFactory.createTargets(10, "unassigned", "unassigned");
|
||||
List<Target> assignedtargets = testdataFactory.createTargets(10, "assigned", "assigned");
|
||||
|
||||
deploymentManagement.assignDistributionSet(assignedSet, assignedtargets);
|
||||
assignDistributionSet(assignedSet, assignedtargets);
|
||||
|
||||
// get final updated version of targets
|
||||
assignedtargets = targetManagement.findTargetByControllerID(
|
||||
@@ -841,18 +814,16 @@ public class TargetManagementSearchTest extends AbstractJpaIntegrationTest {
|
||||
public void findTargetWithoutAssignedDistributionSet() {
|
||||
final DistributionSet assignedSet = testdataFactory.createDistributionSet("");
|
||||
final TargetFilterQuery tfq = targetFilterQueryManagement
|
||||
.createTargetFilterQuery(entityFactory.generateTargetFilterQuery("tfq", "name==*"));
|
||||
List<Target> unassignedTargets = targetManagement
|
||||
.createTargets(testdataFactory.generateTargets(12, "unassigned"));
|
||||
List<Target> assignedTargets = targetManagement.createTargets(testdataFactory.generateTargets(10, "assigned"));
|
||||
.createTargetFilterQuery(entityFactory.targetFilterQuery().create().name("tfq").query("name==*"));
|
||||
final List<Target> unassignedTargets = testdataFactory.createTargets(12, "unassigned", "unassigned");
|
||||
final List<Target> assignedTargets = testdataFactory.createTargets(10, "assigned", "assigned");
|
||||
|
||||
deploymentManagement.assignDistributionSet(assignedSet, assignedTargets);
|
||||
assignDistributionSet(assignedSet, assignedTargets);
|
||||
|
||||
List<Target> result = targetManagement.findAllTargetsByTargetFilterQueryAndNonDS(pageReq,
|
||||
assignedSet.getId(), tfq).getContent();
|
||||
assertThat(result)
|
||||
.as("count of targets").hasSize(unassignedTargets.size())
|
||||
.as("contains all targets").containsAll(unassignedTargets);
|
||||
final List<Target> result = targetManagement
|
||||
.findAllTargetsByTargetFilterQueryAndNonDS(pageReq, assignedSet.getId(), tfq).getContent();
|
||||
assertThat(result).as("count of targets").hasSize(unassignedTargets.size()).as("contains all targets")
|
||||
.containsAll(unassignedTargets);
|
||||
|
||||
}
|
||||
|
||||
@@ -861,17 +832,13 @@ public class TargetManagementSearchTest extends AbstractJpaIntegrationTest {
|
||||
public void findTargetByInstalledDistributionSet() {
|
||||
final DistributionSet assignedSet = testdataFactory.createDistributionSet("");
|
||||
final DistributionSet installedSet = testdataFactory.createDistributionSet("another");
|
||||
targetManagement.createTargets(testdataFactory.generateTargets(10, "unassigned"));
|
||||
List<Target> installedtargets = targetManagement.createTargets(testdataFactory.generateTargets(10, "assigned"));
|
||||
testdataFactory.createTargets(10, "unassigned", "unassigned");
|
||||
List<Target> installedtargets = testdataFactory.createTargets(10, "assigned", "assigned");
|
||||
|
||||
// set on installed and assign another one
|
||||
deploymentManagement.assignDistributionSet(installedSet, installedtargets).getActions().forEach(actionId -> {
|
||||
final Action action = deploymentManagement.findActionWithDetails(actionId);
|
||||
action.setStatus(Status.FINISHED);
|
||||
controllerManagament.addUpdateActionStatus(
|
||||
new JpaActionStatus((JpaAction) action, Status.FINISHED, System.currentTimeMillis(), "message"));
|
||||
});
|
||||
deploymentManagement.assignDistributionSet(assignedSet, installedtargets);
|
||||
assignDistributionSet(installedSet, installedtargets).getActions().forEach(actionId -> controllerManagament
|
||||
.addUpdateActionStatus(entityFactory.actionStatus().create(actionId).status(Status.FINISHED)));
|
||||
assignDistributionSet(assignedSet, installedtargets);
|
||||
|
||||
// get final updated version of targets
|
||||
installedtargets = targetManagement.findTargetByControllerID(
|
||||
@@ -882,32 +849,4 @@ public class TargetManagementSearchTest extends AbstractJpaIntegrationTest {
|
||||
.as("and that means the following expected amount").hasSize(10);
|
||||
|
||||
}
|
||||
|
||||
private List<Target> sendUpdateActionStatusToTargets(final DistributionSet dsA, final Iterable<Target> targs,
|
||||
final Status status, final String... msgs) {
|
||||
final List<Target> result = new ArrayList<>();
|
||||
for (final Target t : targs) {
|
||||
final List<Action> findByTarget = actionRepository.findByTarget((JpaTarget) t);
|
||||
for (final Action action : findByTarget) {
|
||||
result.add(sendUpdateActionStatusToTarget(status, action, t, msgs));
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private Target sendUpdateActionStatusToTarget(final Status status, final Action updActA, final Target t,
|
||||
final String... msgs) {
|
||||
updActA.setStatus(status);
|
||||
|
||||
final ActionStatus statusMessages = new JpaActionStatus();
|
||||
statusMessages.setAction(updActA);
|
||||
statusMessages.setOccurredAt(System.currentTimeMillis());
|
||||
statusMessages.setStatus(status);
|
||||
for (final String msg : msgs) {
|
||||
statusMessages.addMessage(msg);
|
||||
}
|
||||
controllerManagament.addUpdateActionStatus(statusMessages);
|
||||
return targetManagement.findTargetByControllerID(t.getControllerId());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -13,23 +13,16 @@ 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.fest.assertions.api.Assertions.assertThat;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
import java.net.URI;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import javax.persistence.Query;
|
||||
import javax.validation.ConstraintViolationException;
|
||||
|
||||
import org.eclipse.hawkbit.im.authentication.SpPermission;
|
||||
@@ -43,11 +36,7 @@ import org.eclipse.hawkbit.repository.event.remote.entity.TargetTagCreatedEvent;
|
||||
import org.eclipse.hawkbit.repository.event.remote.entity.TargetUpdatedEvent;
|
||||
import org.eclipse.hawkbit.repository.exception.EntityAlreadyExistsException;
|
||||
import org.eclipse.hawkbit.repository.exception.TenantNotExistException;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaAction;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaActionStatus;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaTarget;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaTargetInfo;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaTargetTag;
|
||||
import org.eclipse.hawkbit.repository.model.Action.Status;
|
||||
import org.eclipse.hawkbit.repository.model.DistributionSet;
|
||||
import org.eclipse.hawkbit.repository.model.DistributionSetAssignmentResult;
|
||||
@@ -63,6 +52,7 @@ import org.junit.Test;
|
||||
import org.springframework.data.domain.PageRequest;
|
||||
|
||||
import com.google.common.collect.Iterables;
|
||||
import com.google.common.collect.Lists;
|
||||
|
||||
import ru.yandex.qatools.allure.annotations.Description;
|
||||
import ru.yandex.qatools.allure.annotations.Features;
|
||||
@@ -76,7 +66,8 @@ public class TargetManagementTest extends AbstractJpaIntegrationTest {
|
||||
@Description("Ensures that retrieving the target security is only permitted with the necessary permissions.")
|
||||
@ExpectEvents({ @Expect(type = TargetCreatedEvent.class, count = 1) })
|
||||
public void getTargetSecurityTokenOnlyWithCorrectPermission() throws Exception {
|
||||
final Target createdTarget = targetManagement.createTarget(new JpaTarget("targetWithSecurityToken", "token"));
|
||||
final Target createdTarget = targetManagement.createTarget(
|
||||
entityFactory.target().create().controllerId("targetWithSecurityToken").securityToken("token"));
|
||||
|
||||
// retrieve security token only with READ_TARGET_SEC_TOKEN permission
|
||||
final String securityTokenWithReadPermission = securityRule.runAs(WithSpringAuthorityRule
|
||||
@@ -108,7 +99,7 @@ public class TargetManagementTest extends AbstractJpaIntegrationTest {
|
||||
@ExpectEvents({ @Expect(type = TargetCreatedEvent.class, count = 0) })
|
||||
public void createTargetForTenantWhichDoesNotExistThrowsTenantNotExistException() {
|
||||
try {
|
||||
targetManagement.createTarget(new JpaTarget("targetId123"));
|
||||
targetManagement.createTarget(entityFactory.target().create().controllerId("targetId123"));
|
||||
fail("should not be possible as the tenant does not exist");
|
||||
} catch (final TenantNotExistException e) {
|
||||
// ok
|
||||
@@ -120,14 +111,14 @@ public class TargetManagementTest extends AbstractJpaIntegrationTest {
|
||||
@ExpectEvents({ @Expect(type = TargetCreatedEvent.class, count = 0) })
|
||||
public void createTargetWithNoControllerId() {
|
||||
try {
|
||||
targetManagement.createTarget(new JpaTarget(""));
|
||||
targetManagement.createTarget(entityFactory.target().create().controllerId(""));
|
||||
fail("target with empty controller id should not be created");
|
||||
} catch (final ConstraintViolationException e) {
|
||||
// ok
|
||||
}
|
||||
|
||||
try {
|
||||
targetManagement.createTarget(new JpaTarget(null));
|
||||
targetManagement.createTarget(entityFactory.target().create().controllerId(null));
|
||||
fail("target with empty controller id should not be created");
|
||||
} catch (final ConstraintViolationException e) {
|
||||
// ok
|
||||
@@ -140,14 +131,18 @@ public class TargetManagementTest extends AbstractJpaIntegrationTest {
|
||||
@Expect(type = TargetTagCreatedEvent.class, count = 1),
|
||||
@Expect(type = TargetUpdatedEvent.class, count = 8) })
|
||||
public void assignAndUnassignTargetsToTag() {
|
||||
final List<String> assignTarget = new ArrayList<String>();
|
||||
assignTarget.add(targetManagement.createTarget(new JpaTarget("targetId123")).getControllerId());
|
||||
assignTarget.add(targetManagement.createTarget(new JpaTarget("targetId1234")).getControllerId());
|
||||
assignTarget.add(targetManagement.createTarget(new JpaTarget("targetId1235")).getControllerId());
|
||||
assignTarget.add(targetManagement.createTarget(new JpaTarget("targetId1236")).getControllerId());
|
||||
final List<String> assignTarget = new ArrayList<>();
|
||||
assignTarget.add(targetManagement.createTarget(entityFactory.target().create().controllerId("targetId123"))
|
||||
.getControllerId());
|
||||
assignTarget.add(targetManagement.createTarget(entityFactory.target().create().controllerId("targetId1234"))
|
||||
.getControllerId());
|
||||
assignTarget.add(targetManagement.createTarget(entityFactory.target().create().controllerId("targetId1235"))
|
||||
.getControllerId());
|
||||
assignTarget.add(targetManagement.createTarget(entityFactory.target().create().controllerId("targetId1236"))
|
||||
.getControllerId());
|
||||
assignTarget.add("NotExist");
|
||||
|
||||
final TargetTag targetTag = tagManagement.createTargetTag(new JpaTargetTag("Tag1"));
|
||||
final TargetTag targetTag = tagManagement.createTargetTag(entityFactory.tag().create().name("Tag1"));
|
||||
|
||||
final List<Target> assignedTargets = targetManagement.assignTag(assignTarget, targetTag);
|
||||
assertThat(assignedTargets.size()).as("Assigned targets are wrong").isEqualTo(4);
|
||||
@@ -178,7 +173,7 @@ public class TargetManagementTest extends AbstractJpaIntegrationTest {
|
||||
@ExpectEvents({ @Expect(type = TargetCreatedEvent.class, count = 12),
|
||||
@Expect(type = TargetDeletedEvent.class, count = 12), @Expect(type = TargetUpdatedEvent.class, count = 6) })
|
||||
public void deleteAndCreateTargets() {
|
||||
Target target = targetManagement.createTarget(new JpaTarget("targetId123"));
|
||||
Target target = targetManagement.createTarget(entityFactory.target().create().controllerId("targetId123"));
|
||||
assertThat(targetManagement.countTargetsAll()).as("target count is wrong").isEqualTo(1);
|
||||
targetManagement.deleteTargets(target.getId());
|
||||
assertThat(targetManagement.countTargetsAll()).as("target count is wrong").isEqualTo(0);
|
||||
@@ -190,7 +185,7 @@ public class TargetManagementTest extends AbstractJpaIntegrationTest {
|
||||
|
||||
final List<Long> targets = new ArrayList<>();
|
||||
for (int i = 0; i < 5; i++) {
|
||||
target = targetManagement.createTarget(new JpaTarget("" + i));
|
||||
target = targetManagement.createTarget(entityFactory.target().create().controllerId("" + i));
|
||||
targets.add(target.getId());
|
||||
targets.add(createTargetWithAttributes("" + (i * i + 1000)).getId());
|
||||
}
|
||||
@@ -200,14 +195,13 @@ public class TargetManagementTest extends AbstractJpaIntegrationTest {
|
||||
}
|
||||
|
||||
private Target createTargetWithAttributes(final String controllerId) {
|
||||
Target target = new JpaTarget(controllerId);
|
||||
final Map<String, String> testData = new HashMap<>();
|
||||
testData.put("test1", "testdata1");
|
||||
|
||||
target = targetManagement.createTarget(target);
|
||||
target = controllerManagament.updateControllerAttributes(controllerId, testData);
|
||||
targetManagement.createTarget(entityFactory.target().create().controllerId(controllerId));
|
||||
controllerManagament.updateControllerAttributes(controllerId, testData);
|
||||
|
||||
target = targetManagement.findTargetByControllerIDWithDetails(controllerId);
|
||||
final Target target = targetManagement.findTargetByControllerIDWithDetails(controllerId);
|
||||
assertThat(target.getTargetInfo().getControllerAttributes()).as("Controller Attributes are wrong")
|
||||
.isEqualTo(testData);
|
||||
return target;
|
||||
@@ -237,13 +231,11 @@ public class TargetManagementTest extends AbstractJpaIntegrationTest {
|
||||
final long current = System.currentTimeMillis();
|
||||
controllerManagament.updateLastTargetQuery("4711", null);
|
||||
|
||||
final DistributionSetAssignmentResult result = deploymentManagement.assignDistributionSet(set.getId(), "4711");
|
||||
final DistributionSetAssignmentResult result = assignDistributionSet(set.getId(), "4711");
|
||||
|
||||
final JpaAction action = (JpaAction) deploymentManagement.findActionWithDetails(result.getActions().get(0));
|
||||
action.setStatus(Status.FINISHED);
|
||||
controllerManagament.addUpdateActionStatus(
|
||||
new JpaActionStatus(action, Status.FINISHED, System.currentTimeMillis(), "message"));
|
||||
deploymentManagement.assignDistributionSet(set2.getId(), "4711");
|
||||
entityFactory.actionStatus().create(result.getActions().get(0)).status(Status.FINISHED));
|
||||
assignDistributionSet(set2.getId(), "4711");
|
||||
|
||||
target = targetManagement.findTargetByControllerIDWithDetails("4711");
|
||||
// read data
|
||||
@@ -273,10 +265,9 @@ public class TargetManagementTest extends AbstractJpaIntegrationTest {
|
||||
@Description("Checks if the EntityAlreadyExistsException is thrown if the targets with the same controller ID are created twice.")
|
||||
@ExpectEvents({ @Expect(type = TargetCreatedEvent.class, count = 5) })
|
||||
public void createMultipleTargetsDuplicate() {
|
||||
final List<Target> targets = testdataFactory.generateTargets(5, "mySimpleTargs", "my simple targets");
|
||||
targetManagement.createTargets(targets);
|
||||
testdataFactory.createTargets(5, "mySimpleTargs", "my simple targets");
|
||||
try {
|
||||
targetManagement.createTargets(targets);
|
||||
testdataFactory.createTargets(5, "mySimpleTargs", "my simple targets");
|
||||
fail("Targets already exists");
|
||||
} catch (final EntityAlreadyExistsException e) {
|
||||
}
|
||||
@@ -287,9 +278,9 @@ public class TargetManagementTest extends AbstractJpaIntegrationTest {
|
||||
@Description("Checks if the EntityAlreadyExistsException is thrown if a single target with the same controller ID are created twice.")
|
||||
@ExpectEvents({ @Expect(type = TargetCreatedEvent.class, count = 1) })
|
||||
public void createTargetDuplicate() {
|
||||
targetManagement.createTarget(new JpaTarget("4711"));
|
||||
targetManagement.createTarget(entityFactory.target().create().controllerId("4711"));
|
||||
try {
|
||||
targetManagement.createTarget(new JpaTarget("4711"));
|
||||
targetManagement.createTarget(entityFactory.target().create().controllerId("4711"));
|
||||
fail("Target already exists");
|
||||
} catch (final EntityAlreadyExistsException e) {
|
||||
}
|
||||
@@ -351,9 +342,8 @@ public class TargetManagementTest extends AbstractJpaIntegrationTest {
|
||||
public void singleTargetIsInsertedIntoRepo() throws Exception {
|
||||
|
||||
final String myCtrlID = "myCtrlID";
|
||||
final Target target = testdataFactory.generateTarget(myCtrlID, "the description!");
|
||||
|
||||
Target savedTarget = targetManagement.createTarget(target);
|
||||
Target savedTarget = testdataFactory.createTarget(myCtrlID);
|
||||
assertNotNull("The target should not be null", savedTarget);
|
||||
final Long createdAt = savedTarget.getCreatedAt();
|
||||
Long modifiedAt = savedTarget.getLastModifiedAt();
|
||||
@@ -361,11 +351,10 @@ public class TargetManagementTest extends AbstractJpaIntegrationTest {
|
||||
assertThat(createdAt).as("CreatedAt compared with modifiedAt").isEqualTo(modifiedAt);
|
||||
assertNotNull("The createdAt attribut of the target should no be null", savedTarget.getCreatedAt());
|
||||
assertNotNull("The lastModifiedAt attribut of the target should no be null", savedTarget.getLastModifiedAt());
|
||||
assertThat(target).as("Target compared with saved target").isEqualTo(savedTarget);
|
||||
|
||||
savedTarget.setDescription("changed description");
|
||||
Thread.sleep(1);
|
||||
savedTarget = targetManagement.updateTarget(savedTarget);
|
||||
savedTarget = targetManagement.updateTarget(
|
||||
entityFactory.target().update(savedTarget.getControllerId()).description("changed description"));
|
||||
assertNotNull("The lastModifiedAt attribute of the target should not be null", savedTarget.getLastModifiedAt());
|
||||
assertThat(createdAt).as("CreatedAt compared with saved modifiedAt")
|
||||
.isNotEqualTo(savedTarget.getLastModifiedAt());
|
||||
@@ -391,29 +380,27 @@ public class TargetManagementTest extends AbstractJpaIntegrationTest {
|
||||
@Expect(type = TargetDeletedEvent.class, count = 51) })
|
||||
public void bulkTargetCreationAndDelete() throws Exception {
|
||||
final String myCtrlID = "myCtrlID";
|
||||
final List<Target> firstList = testdataFactory.generateTargets(100, myCtrlID, "first description");
|
||||
List<Target> firstList = testdataFactory.createTargets(100, myCtrlID, "first description");
|
||||
|
||||
final Target extra = testdataFactory.generateTarget("myCtrlID-00081XX", "first description");
|
||||
|
||||
List<Target> firstSaved = targetManagement.createTargets(firstList);
|
||||
|
||||
final Target savedExtra = targetManagement.createTarget(extra);
|
||||
final Target extra = testdataFactory.createTarget("myCtrlID-00081XX");
|
||||
|
||||
final Iterable<JpaTarget> allFound = targetRepository.findAll();
|
||||
|
||||
assertThat(Long.valueOf(firstList.size())).as("List size of targets")
|
||||
.isEqualTo(firstSaved.spliterator().getExactSizeIfKnown());
|
||||
.isEqualTo(firstList.spliterator().getExactSizeIfKnown());
|
||||
assertThat(Long.valueOf(firstList.size() + 1)).as("LastModifiedAt compared with saved lastModifiedAt")
|
||||
.isEqualTo(allFound.spliterator().getExactSizeIfKnown());
|
||||
|
||||
// change the objects and save to again to trigger a change on
|
||||
// lastModifiedAt
|
||||
firstSaved.forEach(t -> t.setName(t.getName().concat("\tchanged")));
|
||||
firstSaved = targetManagement.updateTargets(firstSaved);
|
||||
firstList = firstList.stream()
|
||||
.map(t -> targetManagement.updateTarget(
|
||||
entityFactory.target().update(t.getControllerId()).name(t.getName().concat("\tchanged"))))
|
||||
.collect(Collectors.toList());
|
||||
|
||||
// verify that all entries are found
|
||||
_founds: for (final Target foundTarget : allFound) {
|
||||
for (final Target changedTarget : firstSaved) {
|
||||
for (final Target changedTarget : firstList) {
|
||||
if (changedTarget.getControllerId().equals(foundTarget.getControllerId())) {
|
||||
assertThat(changedTarget.getDescription())
|
||||
.as("Description of changed target compared with description saved target")
|
||||
@@ -430,15 +417,15 @@ public class TargetManagementTest extends AbstractJpaIntegrationTest {
|
||||
}
|
||||
}
|
||||
|
||||
if (!foundTarget.getControllerId().equals(savedExtra.getControllerId())) {
|
||||
if (!foundTarget.getControllerId().equals(extra.getControllerId())) {
|
||||
fail("The controllerId of the found target is not equal to the controllerId of the saved target");
|
||||
}
|
||||
}
|
||||
|
||||
targetManagement.deleteTargets(savedExtra.getId());
|
||||
targetManagement.deleteTargets(extra.getId());
|
||||
|
||||
final int numberToDelete = 50;
|
||||
final Iterable<Target> targetsToDelete = limit(firstSaved, numberToDelete);
|
||||
final Iterable<Target> targetsToDelete = limit(firstList, numberToDelete);
|
||||
final Target[] deletedTargets = toArray(targetsToDelete, Target.class);
|
||||
final List<Long> targetsIdsToDelete = newArrayList(targetsToDelete.iterator()).stream().map(Target::getId)
|
||||
.collect(toList());
|
||||
@@ -446,142 +433,28 @@ public class TargetManagementTest extends AbstractJpaIntegrationTest {
|
||||
targetManagement.deleteTargets(targetsIdsToDelete);
|
||||
|
||||
final List<Target> targetsLeft = targetManagement.findTargetsAll(new PageRequest(0, 200)).getContent();
|
||||
assertThat(firstSaved.spliterator().getExactSizeIfKnown() - numberToDelete).as("Size of splited list")
|
||||
assertThat(firstList.spliterator().getExactSizeIfKnown() - numberToDelete).as("Size of splited list")
|
||||
.isEqualTo(targetsLeft.spliterator().getExactSizeIfKnown());
|
||||
|
||||
assertThat(targetsLeft).as("Not all undeleted found").doesNotContain(deletedTargets);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Description("Stores target attributes and verfies existence in the repository.")
|
||||
public void savingTargetControllerAttributes() {
|
||||
Iterable<Target> ts = targetManagement
|
||||
.createTargets(testdataFactory.generateTargets(100, "myCtrlID", "first description"));
|
||||
|
||||
final Map<String, String> attribs = new HashMap<>();
|
||||
attribs.put("a.b.c", "abc");
|
||||
attribs.put("x.y.z", "");
|
||||
attribs.put("1.2.3", "123");
|
||||
attribs.put("1.2.3.4", "1234");
|
||||
attribs.put("1.2.3.4.5", "12345");
|
||||
final Set<String> attribs2Del = new HashSet<>();
|
||||
attribs2Del.add("x.y.z");
|
||||
attribs2Del.add("1.2.3");
|
||||
|
||||
for (final Target t : ts) {
|
||||
JpaTargetInfo targetInfo = (JpaTargetInfo) t.getTargetInfo();
|
||||
targetInfo.setNew(false);
|
||||
for (final Entry<String, String> attrib : attribs.entrySet()) {
|
||||
final String key = attrib.getKey();
|
||||
final String value = String.format("%s-%s", attrib.getValue(), t.getControllerId());
|
||||
targetInfo.getControllerAttributes().put(key, value);
|
||||
}
|
||||
targetInfo = targetInfoRepository.save(targetInfo);
|
||||
}
|
||||
final Query qry = entityManager.createNativeQuery("select * from sp_target_attributes ta");
|
||||
final List<?> result = qry.getResultList();
|
||||
|
||||
assertThat(attribs.size() * ts.spliterator().getExactSizeIfKnown()).as("Amount of all target attributes")
|
||||
.isEqualTo(result.size());
|
||||
|
||||
for (final Target myT : ts) {
|
||||
final Target t = targetManagement.findTargetByControllerIDWithDetails(myT.getControllerId());
|
||||
assertThat(attribs.size()).as("Amount of target attributes per target")
|
||||
.isEqualTo(t.getTargetInfo().getControllerAttributes().size());
|
||||
|
||||
for (final Entry<String, String> ca : t.getTargetInfo().getControllerAttributes().entrySet()) {
|
||||
assertTrue("Attributes list does not contain target attribute key", attribs.containsKey(ca.getKey()));
|
||||
// has the same value: see string concatenation above
|
||||
// assertThat(String.format("%s-%s",
|
||||
// attribs.get(ca.getKey()))).as("Value of string
|
||||
// concatenation")
|
||||
// .isEqualTo(ca.getValue());
|
||||
|
||||
assertEquals("The value of the string concatenation is not equal to the value of the target attributes",
|
||||
String.format("%s-%s", attribs.get(ca.getKey()), t.getControllerId()), ca.getValue());
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
ts = targetManagement.findTargetsAll(new PageRequest(0, 100)).getContent();
|
||||
final Iterator<Target> tsIt = ts.iterator();
|
||||
// all attributs of the target are deleted
|
||||
final Target[] ts2DelAllAttribs = new Target[] { tsIt.next(), tsIt.next(), tsIt.next() };
|
||||
// a few attributs are deleted
|
||||
final Target[] ts2DelAttribs = new Target[] { tsIt.next(), tsIt.next() };
|
||||
|
||||
// perform the deletion operations accordingly
|
||||
for (final Target ta : ts2DelAllAttribs) {
|
||||
final Target t = targetManagement.findTargetByControllerIDWithDetails(ta.getControllerId());
|
||||
|
||||
final JpaTargetInfo targetStatus = (JpaTargetInfo) t.getTargetInfo();
|
||||
targetStatus.getControllerAttributes().clear();
|
||||
targetInfoRepository.save(targetStatus);
|
||||
}
|
||||
|
||||
for (final Target ta : ts2DelAttribs) {
|
||||
final Target t = targetManagement.findTargetByControllerIDWithDetails(ta.getControllerId());
|
||||
|
||||
final JpaTargetInfo targetStatus = (JpaTargetInfo) t.getTargetInfo();
|
||||
for (final String attribKey : attribs2Del) {
|
||||
targetStatus.getControllerAttributes().remove(attribKey);
|
||||
}
|
||||
targetInfoRepository.save(targetStatus);
|
||||
}
|
||||
|
||||
// only the number of the remaining targets and controller attributes
|
||||
// are checked
|
||||
final Iterable<JpaTarget> restTS = targetRepository.findAll();
|
||||
|
||||
restTarget_: for (final Target targetl : restTS) {
|
||||
final Target target = targetManagement.findTargetByControllerIDWithDetails(targetl.getControllerId());
|
||||
|
||||
// verify that all members of the list ts2DelAllAttribs don't have
|
||||
// any attributes
|
||||
for (final Target tNoAttribl : ts2DelAllAttribs) {
|
||||
final Target tNoAttrib = targetManagement.findTargetByControllerID(tNoAttribl.getControllerId());
|
||||
|
||||
if (tNoAttrib.getControllerId().equals(target.getControllerId())) {
|
||||
assertThat(target.getTargetInfo().getControllerAttributes())
|
||||
.as("Controller attributes should be empty").isEmpty();
|
||||
continue restTarget_;
|
||||
}
|
||||
}
|
||||
// verify that that the attribute list of all members of the list
|
||||
// ts2DelAttribs don't have
|
||||
// attributes which have been deleted
|
||||
for (final Target tNoAttribl : ts2DelAttribs) {
|
||||
final Target tNoAttrib = targetManagement.findTargetByControllerID(tNoAttribl.getControllerId());
|
||||
|
||||
if (tNoAttrib.getControllerId().equals(target.getControllerId())) {
|
||||
assertThat(target.getTargetInfo().getControllerAttributes().keySet().toArray())
|
||||
.as("Controller attributes are wrong").doesNotContain(attribs2Del.toArray());
|
||||
continue restTarget_;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@Description("Tests the assigment of tags to the a single target.")
|
||||
@ExpectEvents({ @Expect(type = TargetCreatedEvent.class, count = 2),
|
||||
@Expect(type = TargetTagCreatedEvent.class, count = 7) })
|
||||
@Expect(type = TargetTagCreatedEvent.class, count = 7),
|
||||
@Expect(type = TargetUpdatedEvent.class, count = 7) })
|
||||
public void targetTagAssignment() {
|
||||
final Target t1 = testdataFactory.generateTarget("id-1", "blablub");
|
||||
final Target t1 = testdataFactory.createTarget("id-1");
|
||||
final int noT2Tags = 4;
|
||||
final int noT1Tags = 3;
|
||||
final List<TargetTag> t1Tags = tagManagement
|
||||
.createTargetTags(testdataFactory.generateTargetTags(noT1Tags, "tag1"));
|
||||
final List<TargetTag> t1Tags = testdataFactory.createTargetTags(noT1Tags, "tag1");
|
||||
|
||||
t1Tags.forEach(tag -> ((JpaTarget) t1).addTag(tag));
|
||||
t1Tags.forEach(tag -> targetManagement.assignTag(Lists.newArrayList(t1.getControllerId()), tag));
|
||||
|
||||
targetManagement.createTarget(t1);
|
||||
final Target t2 = testdataFactory.generateTarget("id-2", "blablub");
|
||||
final List<TargetTag> t2Tags = tagManagement
|
||||
.createTargetTags(testdataFactory.generateTargetTags(noT2Tags, "tag2"));
|
||||
|
||||
t2Tags.forEach(tag -> ((JpaTarget) t2).addTag(tag));
|
||||
targetManagement.createTarget(t2);
|
||||
final Target t2 = testdataFactory.createTarget("id-2");
|
||||
final List<TargetTag> t2Tags = testdataFactory.createTargetTags(noT2Tags, "tag2");
|
||||
t2Tags.forEach(tag -> targetManagement.assignTag(Lists.newArrayList(t2.getControllerId()), tag));
|
||||
|
||||
final Target t11 = targetManagement.findTargetByControllerID(t1.getControllerId());
|
||||
assertThat(t11.getTags()).as("Tag size is wrong").hasSize(noT1Tags).containsAll(t1Tags);
|
||||
@@ -600,23 +473,18 @@ public class TargetManagementTest extends AbstractJpaIntegrationTest {
|
||||
@Expect(type = TargetTagCreatedEvent.class, count = 4),
|
||||
@Expect(type = TargetUpdatedEvent.class, count = 80) })
|
||||
public void targetTagBulkAssignments() {
|
||||
final List<Target> tagATargets = targetManagement
|
||||
.createTargets(testdataFactory.generateTargets(10, "tagATargets", "first description"));
|
||||
final List<Target> tagBTargets = targetManagement
|
||||
.createTargets(testdataFactory.generateTargets(10, "tagBTargets", "first description"));
|
||||
final List<Target> tagCTargets = targetManagement
|
||||
.createTargets(testdataFactory.generateTargets(10, "tagCTargets", "first description"));
|
||||
final List<Target> tagATargets = testdataFactory.createTargets(10, "tagATargets", "first description");
|
||||
final List<Target> tagBTargets = testdataFactory.createTargets(10, "tagBTargets", "first description");
|
||||
final List<Target> tagCTargets = testdataFactory.createTargets(10, "tagCTargets", "first description");
|
||||
|
||||
final List<Target> tagABTargets = targetManagement
|
||||
.createTargets(testdataFactory.generateTargets(10, "tagABTargets", "first description"));
|
||||
final List<Target> tagABTargets = testdataFactory.createTargets(10, "tagABTargets", "first description");
|
||||
|
||||
final List<Target> tagABCTargets = targetManagement
|
||||
.createTargets(testdataFactory.generateTargets(10, "tagABCTargets", "first description"));
|
||||
final List<Target> tagABCTargets = testdataFactory.createTargets(10, "tagABCTargets", "first description");
|
||||
|
||||
final TargetTag tagA = tagManagement.createTargetTag(new JpaTargetTag("A"));
|
||||
final TargetTag tagB = tagManagement.createTargetTag(new JpaTargetTag("B"));
|
||||
final TargetTag tagC = tagManagement.createTargetTag(new JpaTargetTag("C"));
|
||||
tagManagement.createTargetTag(new JpaTargetTag("X"));
|
||||
final TargetTag tagA = tagManagement.createTargetTag(entityFactory.tag().create().name("A"));
|
||||
final TargetTag tagB = tagManagement.createTargetTag(entityFactory.tag().create().name("B"));
|
||||
final TargetTag tagC = tagManagement.createTargetTag(entityFactory.tag().create().name("C"));
|
||||
tagManagement.createTargetTag(entityFactory.tag().create().name("X"));
|
||||
|
||||
// doing different assignments
|
||||
targetManagement.toggleTagAssignment(tagATargets, tagA);
|
||||
@@ -634,9 +502,9 @@ public class TargetManagementTest extends AbstractJpaIntegrationTest {
|
||||
.as("Target count is wrong").isEqualTo(0);
|
||||
|
||||
// search for targets with tag tagA
|
||||
final List<Target> targetWithTagA = new ArrayList<Target>();
|
||||
final List<Target> targetWithTagB = new ArrayList<Target>();
|
||||
final List<Target> targetWithTagC = new ArrayList<Target>();
|
||||
final List<Target> targetWithTagA = new ArrayList<>();
|
||||
final List<Target> targetWithTagB = new ArrayList<>();
|
||||
final List<Target> targetWithTagC = new ArrayList<>();
|
||||
|
||||
// storing target lists to enable easy evaluation
|
||||
Iterables.addAll(targetWithTagA, tagATargets);
|
||||
@@ -674,25 +542,18 @@ public class TargetManagementTest extends AbstractJpaIntegrationTest {
|
||||
@Expect(type = TargetCreatedEvent.class, count = 109),
|
||||
@Expect(type = TargetUpdatedEvent.class, count = 227) })
|
||||
public void targetTagBulkUnassignments() {
|
||||
final TargetTag targTagA = tagManagement.createTargetTag(new JpaTargetTag("Targ-A-Tag"));
|
||||
final TargetTag targTagB = tagManagement.createTargetTag(new JpaTargetTag("Targ-B-Tag"));
|
||||
final TargetTag targTagC = tagManagement.createTargetTag(new JpaTargetTag("Targ-C-Tag"));
|
||||
final TargetTag targTagA = tagManagement.createTargetTag(entityFactory.tag().create().name("Targ-A-Tag"));
|
||||
final TargetTag targTagB = tagManagement.createTargetTag(entityFactory.tag().create().name("Targ-B-Tag"));
|
||||
final TargetTag targTagC = tagManagement.createTargetTag(entityFactory.tag().create().name("Targ-C-Tag"));
|
||||
|
||||
final List<Target> targAs = targetManagement
|
||||
.createTargets(testdataFactory.generateTargets(25, "target-id-A", "first description"));
|
||||
final List<Target> targBs = targetManagement
|
||||
.createTargets(testdataFactory.generateTargets(20, "target-id-B", "first description"));
|
||||
final List<Target> targCs = targetManagement
|
||||
.createTargets(testdataFactory.generateTargets(15, "target-id-C", "first description"));
|
||||
final List<Target> targAs = testdataFactory.createTargets(25, "target-id-A", "first description");
|
||||
final List<Target> targBs = testdataFactory.createTargets(20, "target-id-B", "first description");
|
||||
final List<Target> targCs = testdataFactory.createTargets(15, "target-id-C", "first description");
|
||||
|
||||
final List<Target> targABs = targetManagement
|
||||
.createTargets(testdataFactory.generateTargets(12, "target-id-AB", "first description"));
|
||||
final List<Target> targACs = targetManagement
|
||||
.createTargets(testdataFactory.generateTargets(13, "target-id-AC", "first description"));
|
||||
final List<Target> targBCs = targetManagement
|
||||
.createTargets(testdataFactory.generateTargets(7, "target-id-BC", "first description"));
|
||||
final List<Target> targABCs = targetManagement
|
||||
.createTargets(testdataFactory.generateTargets(17, "target-id-ABC", "first description"));
|
||||
final List<Target> targABs = testdataFactory.createTargets(12, "target-id-AB", "first description");
|
||||
final List<Target> targACs = testdataFactory.createTargets(13, "target-id-AC", "first description");
|
||||
final List<Target> targBCs = testdataFactory.createTargets(7, "target-id-BC", "first description");
|
||||
final List<Target> targABCs = testdataFactory.createTargets(17, "target-id-ABC", "first description");
|
||||
|
||||
targetManagement.toggleTagAssignment(targAs, targTagA);
|
||||
targetManagement.toggleTagAssignment(targABs, targTagA);
|
||||
@@ -739,21 +600,20 @@ public class TargetManagementTest extends AbstractJpaIntegrationTest {
|
||||
@Expect(type = TargetCreatedEvent.class, count = 25),
|
||||
@Expect(type = TargetUpdatedEvent.class, count = 25) })
|
||||
public void findTargetsByControllerIDsWithTags() {
|
||||
final TargetTag targTagA = tagManagement.createTargetTag(new JpaTargetTag("Targ-A-Tag"));
|
||||
final TargetTag targTagA = tagManagement.createTargetTag(entityFactory.tag().create().name("Targ-A-Tag"));
|
||||
|
||||
final List<Target> targAs = targetManagement
|
||||
.createTargets(testdataFactory.generateTargets(25, "target-id-A", "first description"));
|
||||
final List<Target> targAs = testdataFactory.createTargets(25, "target-id-A", "first description");
|
||||
|
||||
targetManagement.toggleTagAssignment(targAs, targTagA);
|
||||
|
||||
assertThat(targetManagement.findTargetsByControllerIDsWithTags(
|
||||
targAs.stream().map(target -> target.getControllerId()).collect(Collectors.toList())))
|
||||
.as("Target count is wrong").hasSize(25);
|
||||
targAs.stream().map(Target::getControllerId).collect(Collectors.toList()))).as("Target count is wrong")
|
||||
.hasSize(25);
|
||||
|
||||
// no lazy loading exception and tag correctly assigned
|
||||
assertThat(targetManagement
|
||||
.findTargetsByControllerIDsWithTags(
|
||||
targAs.stream().map(target -> target.getControllerId()).collect(Collectors.toList()))
|
||||
targAs.stream().map(Target::getControllerId).collect(Collectors.toList()))
|
||||
.stream().map(target -> target.getTags().contains(targTagA)).collect(Collectors.toList()))
|
||||
.as("Tags not correctly assigned").containsOnly(true);
|
||||
}
|
||||
@@ -762,9 +622,8 @@ public class TargetManagementTest extends AbstractJpaIntegrationTest {
|
||||
@Description("Test the optimized quere for retrieving all ID/name pairs of targets.")
|
||||
@ExpectEvents({ @Expect(type = TargetCreatedEvent.class, count = 25) })
|
||||
public void findAllTargetIdNamePaiss() {
|
||||
final List<Target> targAs = targetManagement
|
||||
.createTargets(testdataFactory.generateTargets(25, "target-id-A", "first description"));
|
||||
final String[] createdTargetIds = targAs.stream().map(t -> t.getControllerId())
|
||||
final List<Target> targAs = testdataFactory.createTargets(25, "target-id-A", "first description");
|
||||
final String[] createdTargetIds = targAs.stream().map(Target::getControllerId)
|
||||
.toArray(size -> new String[size]);
|
||||
|
||||
final List<TargetIdName> findAllTargetIdNames = targetManagement.findAllTargetIds();
|
||||
@@ -781,17 +640,15 @@ public class TargetManagementTest extends AbstractJpaIntegrationTest {
|
||||
@Expect(type = TargetUpdatedEvent.class, count = 25) })
|
||||
public void findTargetsWithNoTag() {
|
||||
|
||||
final TargetTag targTagA = tagManagement.createTargetTag(new JpaTargetTag("Targ-A-Tag"));
|
||||
final List<Target> targAs = targetManagement
|
||||
.createTargets(testdataFactory.generateTargets(25, "target-id-A", "first description"));
|
||||
final TargetTag targTagA = tagManagement.createTargetTag(entityFactory.tag().create().name("Targ-A-Tag"));
|
||||
final List<Target> targAs = testdataFactory.createTargets(25, "target-id-A", "first description");
|
||||
targetManagement.toggleTagAssignment(targAs, targTagA);
|
||||
|
||||
targetManagement.createTargets(testdataFactory.generateTargets(25, "target-id-B", "first description"));
|
||||
testdataFactory.createTargets(25, "target-id-B", "first description");
|
||||
|
||||
final String[] tagNames = null;
|
||||
final List<Target> targetsListWithNoTag = targetManagement
|
||||
.findTargetByFilters(new PageRequest(0, 500), null, null, null, null, Boolean.TRUE, tagNames)
|
||||
.getContent();
|
||||
.findTargetByFilters(pageReq, null, null, null, null, Boolean.TRUE, tagNames).getContent();
|
||||
|
||||
assertThat(50).as("Total targets").isEqualTo(targetManagement.findAllTargetIds().size());
|
||||
assertThat(25).as("Targets with no tag").isEqualTo(targetsListWithNoTag.size());
|
||||
|
||||
@@ -14,8 +14,6 @@ import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.eclipse.hawkbit.repository.jpa.AbstractJpaIntegrationTest;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSet;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaTargetFilterQuery;
|
||||
import org.eclipse.hawkbit.repository.model.DistributionSet;
|
||||
import org.eclipse.hawkbit.repository.model.Target;
|
||||
import org.eclipse.hawkbit.repository.model.TargetFilterQuery;
|
||||
@@ -44,32 +42,34 @@ public class AutoAssignCheckerTest extends AbstractJpaIntegrationTest {
|
||||
@Description("Test auto assignment of a DS to filtered targets")
|
||||
public void checkAutoAssign() {
|
||||
|
||||
final DistributionSet setA = testdataFactory.createDistributionSet("dsA"); // will be auto assigned
|
||||
final DistributionSet setA = testdataFactory.createDistributionSet("dsA"); // will
|
||||
// be
|
||||
// auto
|
||||
// assigned
|
||||
final DistributionSet setB = testdataFactory.createDistributionSet("dsB");
|
||||
|
||||
// target filter query that matches all targets
|
||||
TargetFilterQuery targetFilterQuery = targetFilterQueryManagement
|
||||
.createTargetFilterQuery(new JpaTargetFilterQuery("filterA", "name==*"));
|
||||
targetFilterQuery.setAutoAssignDistributionSet(setA);
|
||||
targetFilterQueryManagement.updateTargetFilterQuery(targetFilterQuery);
|
||||
|
||||
final TargetFilterQuery targetFilterQuery = targetFilterQueryManagement
|
||||
.createTargetFilterQuery(entityFactory.targetFilterQuery().create().name("filterA").query("name==*"));
|
||||
targetFilterQueryManagement.updateTargetFilterQueryAutoAssignDS(targetFilterQuery.getId(), setA.getId());
|
||||
|
||||
final String targetDsAIdPref = "targ";
|
||||
List<Target> targets = targetManagement.createTargets(
|
||||
testdataFactory.generateTargets(100, targetDsAIdPref, targetDsAIdPref.concat(" description")));
|
||||
int targetsCount = targets.size();
|
||||
final List<Target> targets = testdataFactory.createTargets(100, targetDsAIdPref,
|
||||
targetDsAIdPref.concat(" description"));
|
||||
final int targetsCount = targets.size();
|
||||
|
||||
// assign set A to first 10 targets
|
||||
deploymentManagement.assignDistributionSet(setA, targets.subList(0, 10));
|
||||
assignDistributionSet(setA, targets.subList(0, 10));
|
||||
verifyThatTargetsHaveDistributionSetAssignment(setA, targets.subList(0, 10), targetsCount);
|
||||
|
||||
// assign set B to first 5 targets
|
||||
// they have now 2 DS in their action history and should not get updated with dsA
|
||||
deploymentManagement.assignDistributionSet(setB, targets.subList(0, 5));
|
||||
// they have now 2 DS in their action history and should not get updated
|
||||
// with dsA
|
||||
assignDistributionSet(setB, targets.subList(0, 5));
|
||||
verifyThatTargetsHaveDistributionSetAssignment(setB, targets.subList(0, 5), targetsCount);
|
||||
|
||||
// assign set B to next 10 targets
|
||||
deploymentManagement.assignDistributionSet(setB, targets.subList(10, 20));
|
||||
assignDistributionSet(setB, targets.subList(10, 20));
|
||||
verifyThatTargetsHaveDistributionSetAssignment(setB, targets.subList(10, 20), targetsCount);
|
||||
|
||||
// Count the number of targets that will be assigned with setA
|
||||
@@ -91,9 +91,8 @@ public class AutoAssignCheckerTest extends AbstractJpaIntegrationTest {
|
||||
public void checkAutoAssignWithFailures() {
|
||||
|
||||
// incomplete distribution set that will be assigned
|
||||
final DistributionSet setF = distributionSetManagement
|
||||
.createDistributionSet(entityFactory.generateDistributionSet("dsA", "1", "incomplete ds",
|
||||
testdataFactory.findOrCreateDefaultTestDsType(), null));
|
||||
final DistributionSet setF = distributionSetManagement.createDistributionSet(entityFactory.distributionSet()
|
||||
.create().name("dsA").version("1").type(testdataFactory.findOrCreateDefaultTestDsType()));
|
||||
final DistributionSet setA = testdataFactory.createDistributionSet("dsA");
|
||||
final DistributionSet setB = testdataFactory.createDistributionSet("dsB");
|
||||
|
||||
@@ -102,23 +101,27 @@ public class AutoAssignCheckerTest extends AbstractJpaIntegrationTest {
|
||||
|
||||
// target filter query that matches first bunch of targets, that should
|
||||
// fail
|
||||
targetFilterQueryManagement.createTargetFilterQuery(
|
||||
new JpaTargetFilterQuery("filterA", "id==" + targetDsFIdPref + "*", (JpaDistributionSet) setF));
|
||||
targetFilterQueryManagement.updateTargetFilterQueryAutoAssignDS(
|
||||
targetFilterQueryManagement.createTargetFilterQuery(entityFactory.targetFilterQuery().create()
|
||||
.name("filterA").query("id==" + targetDsFIdPref + "*")).getId(),
|
||||
setF.getId());
|
||||
|
||||
// target filter query that matches failed bunch of targets
|
||||
targetFilterQueryManagement.createTargetFilterQuery(
|
||||
new JpaTargetFilterQuery("filterB", "id==" + targetDsAIdPref + "*", (JpaDistributionSet) setA));
|
||||
targetFilterQueryManagement.updateTargetFilterQueryAutoAssignDS(
|
||||
targetFilterQueryManagement.createTargetFilterQuery(entityFactory.targetFilterQuery().create()
|
||||
.name("filterB").query("id==" + targetDsAIdPref + "*")).getId(),
|
||||
setA.getId());
|
||||
|
||||
List<Target> targetsF = targetManagement.createTargets(
|
||||
testdataFactory.generateTargets(10, targetDsFIdPref, targetDsFIdPref.concat(" description")));
|
||||
final List<Target> targetsF = testdataFactory.createTargets(10, targetDsFIdPref,
|
||||
targetDsFIdPref.concat(" description"));
|
||||
|
||||
List<Target> targetsA = targetManagement.createTargets(
|
||||
testdataFactory.generateTargets(10, targetDsAIdPref, targetDsAIdPref.concat(" description")));
|
||||
final List<Target> targetsA = testdataFactory.createTargets(10, targetDsAIdPref,
|
||||
targetDsAIdPref.concat(" description"));
|
||||
|
||||
int targetsCount = targetsA.size() + targetsF.size();
|
||||
final int targetsCount = targetsA.size() + targetsF.size();
|
||||
|
||||
// assign set B to first 5 targets of fail group
|
||||
deploymentManagement.assignDistributionSet(setB, targetsF.subList(0, 5));
|
||||
assignDistributionSet(setB, targetsF.subList(0, 5));
|
||||
verifyThatTargetsHaveDistributionSetAssignment(setB, targetsF.subList(0, 5), targetsCount);
|
||||
|
||||
// Run the check
|
||||
@@ -133,18 +136,21 @@ public class AutoAssignCheckerTest extends AbstractJpaIntegrationTest {
|
||||
}
|
||||
|
||||
/**
|
||||
* @param set the expected distribution set
|
||||
* @param targets the targets that should have it
|
||||
* @param set
|
||||
* the expected distribution set
|
||||
* @param targets
|
||||
* the targets that should have it
|
||||
*/
|
||||
@Step
|
||||
private void verifyThatTargetsHaveDistributionSetAssignment(final DistributionSet set, List<Target> targets, int count) {
|
||||
List<Long> targetIds = targets.stream().map(Target::getId).collect(Collectors.toList());
|
||||
private void verifyThatTargetsHaveDistributionSetAssignment(final DistributionSet set, final List<Target> targets,
|
||||
final int count) {
|
||||
final List<Long> targetIds = targets.stream().map(Target::getId).collect(Collectors.toList());
|
||||
|
||||
Slice<Target> targetsAll = targetManagement.findTargetsAll(new PageRequest(0, 1000));
|
||||
final Slice<Target> targetsAll = targetManagement.findTargetsAll(new PageRequest(0, 1000));
|
||||
assertThat(targetsAll).as("Count of targets").hasSize(count);
|
||||
|
||||
for (Target target : targetsAll) {
|
||||
if(targetIds.contains(target.getId())) {
|
||||
for (final Target target : targetsAll) {
|
||||
if (targetIds.contains(target.getId())) {
|
||||
assertThat(target.getAssignedDistributionSet()).as("assigned DS").isEqualTo(set);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -52,7 +52,7 @@ public class RepositoryEntityEventTest extends AbstractJpaIntegrationTest {
|
||||
@Test
|
||||
@Description("Verifies that the target created event is published when a target has been created")
|
||||
public void targetCreatedEventIsPublished() throws InterruptedException {
|
||||
final Target createdTarget = targetManagement.createTarget(entityFactory.generateTarget("12345"));
|
||||
final Target createdTarget = testdataFactory.createTarget("12345");
|
||||
|
||||
final TargetCreatedEvent targetCreatedEvent = eventListener.waitForEvent(TargetCreatedEvent.class, 1,
|
||||
TimeUnit.SECONDS);
|
||||
@@ -63,9 +63,9 @@ public class RepositoryEntityEventTest extends AbstractJpaIntegrationTest {
|
||||
@Test
|
||||
@Description("Verifies that the target update event is published when a target has been updated")
|
||||
public void targetUpdateEventIsPublished() throws InterruptedException {
|
||||
final Target createdTarget = targetManagement.createTarget(entityFactory.generateTarget("12345"));
|
||||
createdTarget.setName("updateName");
|
||||
targetManagement.updateTarget(createdTarget);
|
||||
final Target createdTarget = testdataFactory.createTarget("12345");
|
||||
targetManagement
|
||||
.updateTarget(entityFactory.target().update(createdTarget.getControllerId()).name("updateName"));
|
||||
|
||||
final TargetUpdatedEvent targetUpdatedEvent = eventListener.waitForEvent(TargetUpdatedEvent.class, 1,
|
||||
TimeUnit.SECONDS);
|
||||
@@ -76,7 +76,7 @@ public class RepositoryEntityEventTest extends AbstractJpaIntegrationTest {
|
||||
@Test
|
||||
@Description("Verifies that the target deleted event is published when a target has been deleted")
|
||||
public void targetDeletedEventIsPublished() throws InterruptedException {
|
||||
final Target createdTarget = targetManagement.createTarget(entityFactory.generateTarget("12345"));
|
||||
final Target createdTarget = testdataFactory.createTarget("12345");
|
||||
|
||||
targetManagement.deleteTargets(createdTarget.getId());
|
||||
|
||||
@@ -89,11 +89,7 @@ public class RepositoryEntityEventTest extends AbstractJpaIntegrationTest {
|
||||
@Test
|
||||
@Description("Verifies that the distribution set created event is published when a distribution set has been created")
|
||||
public void distributionSetCreatedEventIsPublished() throws InterruptedException {
|
||||
final DistributionSet generateDistributionSet = entityFactory.generateDistributionSet();
|
||||
generateDistributionSet.setName("dsEventTest");
|
||||
generateDistributionSet.setVersion("1");
|
||||
final DistributionSet createDistributionSet = distributionSetManagement
|
||||
.createDistributionSet(generateDistributionSet);
|
||||
final DistributionSet createDistributionSet = testdataFactory.createDistributionSet();
|
||||
|
||||
final DistributionSetCreatedEvent dsCreatedEvent = eventListener.waitForEvent(DistributionSetCreatedEvent.class,
|
||||
1, TimeUnit.SECONDS);
|
||||
@@ -104,12 +100,7 @@ public class RepositoryEntityEventTest extends AbstractJpaIntegrationTest {
|
||||
@Test
|
||||
@Description("Verifies that the distribution set deleted event is published when a distribution set has been deleted")
|
||||
public void distributionSetDeletedEventIsPublished() throws InterruptedException {
|
||||
|
||||
final DistributionSet generateDistributionSet = entityFactory.generateDistributionSet();
|
||||
generateDistributionSet.setName("dsEventTest");
|
||||
generateDistributionSet.setVersion("1");
|
||||
final DistributionSet createDistributionSet = distributionSetManagement
|
||||
.createDistributionSet(generateDistributionSet);
|
||||
final DistributionSet createDistributionSet = testdataFactory.createDistributionSet();
|
||||
|
||||
distributionSetManagement.deleteDistributionSet(createDistributionSet);
|
||||
|
||||
|
||||
@@ -52,9 +52,7 @@ public class EntityInterceptorListenerTest extends AbstractJpaIntegrationTest {
|
||||
final PostLoadEntityListener postLoadEntityListener = new PostLoadEntityListener();
|
||||
EntityInterceptorHolder.getInstance().getEntityInterceptors().add(postLoadEntityListener);
|
||||
|
||||
final Target targetToBeCreated = entityFactory.generateTarget("targetToBeCreated");
|
||||
|
||||
targetManagement.createTarget(targetToBeCreated);
|
||||
final Target targetToBeCreated = testdataFactory.createTarget("targetToBeCreated");
|
||||
|
||||
final Target loadedTarget = targetManagement.findTargetByControllerID(targetToBeCreated.getControllerId());
|
||||
assertThat(postLoadEntityListener.getEntity()).isNotNull();
|
||||
@@ -86,19 +84,17 @@ public class EntityInterceptorListenerTest extends AbstractJpaIntegrationTest {
|
||||
}
|
||||
|
||||
private void executePersistAndAssertCallbackResult(final AbstractEntityListener entityInterceptor) {
|
||||
final Target targetToBeCreated = entityFactory.generateTarget("targetToBeCreated");
|
||||
addListenerAndCreateTarget(entityInterceptor, targetToBeCreated);
|
||||
final Target targetToBeCreated = addListenerAndCreateTarget(entityInterceptor, "targetToBeCreated");
|
||||
|
||||
assertThat(entityInterceptor.getEntity()).isNotNull();
|
||||
assertThat(entityInterceptor.getEntity()).isEqualTo(targetToBeCreated);
|
||||
}
|
||||
|
||||
private void executeUpdateAndAssertCallbackResult(final AbstractEntityListener entityInterceptor) {
|
||||
Target updateTarget = addListenerAndCreateTarget(entityInterceptor,
|
||||
entityFactory.generateTarget("targetToBeCreated"));
|
||||
updateTarget.setDescription("New");
|
||||
Target updateTarget = addListenerAndCreateTarget(entityInterceptor, "targetToBeCreated");
|
||||
|
||||
updateTarget = targetManagement.updateTarget(updateTarget);
|
||||
updateTarget = targetManagement
|
||||
.updateTarget(entityFactory.target().update(updateTarget.getControllerId()).name("New"));
|
||||
|
||||
assertThat(entityInterceptor.getEntity()).isNotNull();
|
||||
assertThat(entityInterceptor.getEntity()).isEqualTo(updateTarget);
|
||||
@@ -107,7 +103,7 @@ public class EntityInterceptorListenerTest extends AbstractJpaIntegrationTest {
|
||||
private void executeDeleteAndAssertCallbackResult(final AbstractEntityListener entityInterceptor) {
|
||||
EntityInterceptorHolder.getInstance().getEntityInterceptors().add(entityInterceptor);
|
||||
final SoftwareModuleType type = softwareManagement
|
||||
.createSoftwareModuleType(entityFactory.generateSoftwareModuleType("test", "test", "test", 1));
|
||||
.createSoftwareModuleType(entityFactory.softwareModuleType().create().name("test").key("test"));
|
||||
|
||||
softwareManagement.deleteSoftwareModuleType(type);
|
||||
assertThat(entityInterceptor.getEntity()).isNotNull();
|
||||
@@ -115,12 +111,12 @@ public class EntityInterceptorListenerTest extends AbstractJpaIntegrationTest {
|
||||
}
|
||||
|
||||
private Target addListenerAndCreateTarget(final AbstractEntityListener entityInterceptor,
|
||||
final Target targetToBeCreated) {
|
||||
final String targetToBeCreated) {
|
||||
EntityInterceptorHolder.getInstance().getEntityInterceptors().add(entityInterceptor);
|
||||
return targetManagement.createTarget(targetToBeCreated);
|
||||
return testdataFactory.createTarget(targetToBeCreated);
|
||||
}
|
||||
|
||||
private static abstract class AbstractEntityListener implements EntityInterceptor {
|
||||
private abstract static class AbstractEntityListener implements EntityInterceptor {
|
||||
|
||||
private Object entity;
|
||||
|
||||
@@ -183,4 +179,4 @@ public class EntityInterceptorListenerTest extends AbstractJpaIntegrationTest {
|
||||
setEntity(entity);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -56,20 +56,20 @@ public class ModelEqualsHashcodeTest extends AbstractJpaIntegrationTest {
|
||||
@Description("Verfies that updated entities are not equal.")
|
||||
public void changedEntitiesAreNotEqual() {
|
||||
final SoftwareModuleType type = softwareManagement
|
||||
.createSoftwareModuleType(new JpaSoftwareModuleType("test", "test", "test", 1));
|
||||
.createSoftwareModuleType(entityFactory.softwareModuleType().create().key("test").name("test"));
|
||||
assertThat(type).as("persited entity is not equal to regular object")
|
||||
.isNotEqualTo(new JpaSoftwareModuleType("test", "test", "test", 1));
|
||||
.isNotEqualTo(entityFactory.softwareModuleType().create().key("test").name("test").build());
|
||||
|
||||
type.setDescription("another");
|
||||
final SoftwareModuleType updated = softwareManagement.updateSoftwareModuleType(type);
|
||||
final SoftwareModuleType updated = softwareManagement.updateSoftwareModuleType(
|
||||
entityFactory.softwareModuleType().update(type.getId()).description("another"));
|
||||
assertThat(type).as("Changed entity is not equal to the previous version").isNotEqualTo(updated);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Description("Verify that no proxy of the entity manager has an influence on the equals or hashcode result.")
|
||||
public void managedEntityIsEqualToUnamangedObjectWithSameKey() {
|
||||
final SoftwareModuleType type = softwareManagement
|
||||
.createSoftwareModuleType(new JpaSoftwareModuleType("test", "test", "test", 1));
|
||||
final SoftwareModuleType type = softwareManagement.createSoftwareModuleType(
|
||||
entityFactory.softwareModuleType().create().key("test").name("test").description("test"));
|
||||
|
||||
final JpaSoftwareModuleType mock = new JpaSoftwareModuleType("test", "test", "test", 1);
|
||||
mock.setId(type.getId());
|
||||
@@ -81,23 +81,4 @@ public class ModelEqualsHashcodeTest extends AbstractJpaIntegrationTest {
|
||||
.isEqualTo(mock.hashCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
@Description("Verfies that updated entities do not have the same hashcode.")
|
||||
public void updatedEntitiesHaveDifferentHashcodes() {
|
||||
final SoftwareModuleType type = softwareManagement
|
||||
.createSoftwareModuleType(new JpaSoftwareModuleType("test", "test", "test", 1));
|
||||
assertThat(type.hashCode()).as("persited entity does not have same hashcode as regular object")
|
||||
.isNotEqualTo(new JpaSoftwareModuleType("test", "test", "test", 1).hashCode());
|
||||
|
||||
final int beforeChange = type.hashCode();
|
||||
type.setDescription("another");
|
||||
assertThat(type.hashCode())
|
||||
.as("Changed entity has no different hashcode than the previous version until updated in repository")
|
||||
.isEqualTo(beforeChange);
|
||||
|
||||
final SoftwareModuleType updated = softwareManagement.updateSoftwareModuleType(type);
|
||||
assertThat(type.hashCode()).as("Updated entity has different hashcode than the previous version")
|
||||
.isNotEqualTo(updated.hashCode());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -38,9 +38,8 @@ public class RSQLActionFieldsTest extends AbstractJpaIntegrationTest {
|
||||
@Before
|
||||
public void setupBeforeTest() {
|
||||
final DistributionSet dsA = testdataFactory.createDistributionSet("daA");
|
||||
target = new JpaTarget("targetId123");
|
||||
target.setDescription("targetId123");
|
||||
targetManagement.createTarget(target);
|
||||
target = (JpaTarget) targetManagement
|
||||
.createTarget(entityFactory.target().create().controllerId("targetId123").description("targetId123"));
|
||||
action = new JpaAction();
|
||||
action.setActionType(ActionType.SOFT);
|
||||
action.setDistributionSet(dsA);
|
||||
|
||||
@@ -16,8 +16,6 @@ import java.util.Arrays;
|
||||
import org.eclipse.hawkbit.repository.DistributionSetFields;
|
||||
import org.eclipse.hawkbit.repository.exception.RSQLParameterSyntaxException;
|
||||
import org.eclipse.hawkbit.repository.jpa.AbstractJpaIntegrationTest;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSetMetadata;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSetTag;
|
||||
import org.eclipse.hawkbit.repository.model.DistributionSet;
|
||||
import org.eclipse.hawkbit.repository.model.DistributionSetTag;
|
||||
import org.eclipse.hawkbit.repository.test.util.TestdataFactory;
|
||||
@@ -38,22 +36,21 @@ public class RSQLDistributionSetFieldTest extends AbstractJpaIntegrationTest {
|
||||
public void seuptBeforeTest() {
|
||||
|
||||
DistributionSet ds = testdataFactory.createDistributionSet("DS");
|
||||
ds.setDescription("DS");
|
||||
ds = distributionSetManagement.updateDistributionSet(ds);
|
||||
distributionSetManagement
|
||||
.createDistributionSetMetadata(new JpaDistributionSetMetadata("metaKey", ds, "metaValue"));
|
||||
ds = distributionSetManagement
|
||||
.updateDistributionSet(entityFactory.distributionSet().update(ds.getId()).description("DS"));
|
||||
createDistributionSetMetadata(ds.getId(), entityFactory.generateMetadata("metaKey", "metaValue"));
|
||||
|
||||
DistributionSet ds2 = testdataFactory.createDistributionSets("NewDS", 3).get(0);
|
||||
|
||||
ds2.setDescription("DS%");
|
||||
ds2 = distributionSetManagement.updateDistributionSet(ds2);
|
||||
distributionSetManagement
|
||||
.createDistributionSetMetadata(new JpaDistributionSetMetadata("metaKey", ds2, "value"));
|
||||
ds2 = distributionSetManagement
|
||||
.updateDistributionSet(entityFactory.distributionSet().update(ds2.getId()).description("DS%"));
|
||||
createDistributionSetMetadata(ds2.getId(), entityFactory.generateMetadata("metaKey", "value"));
|
||||
|
||||
final DistributionSetTag targetTag = tagManagement.createDistributionSetTag(new JpaDistributionSetTag("Tag1"));
|
||||
tagManagement.createDistributionSetTag(new JpaDistributionSetTag("Tag2"));
|
||||
tagManagement.createDistributionSetTag(new JpaDistributionSetTag("Tag3"));
|
||||
tagManagement.createDistributionSetTag(new JpaDistributionSetTag("Tag4"));
|
||||
final DistributionSetTag targetTag = tagManagement
|
||||
.createDistributionSetTag(entityFactory.tag().create().name("Tag1"));
|
||||
tagManagement.createDistributionSetTag(entityFactory.tag().create().name("Tag2"));
|
||||
tagManagement.createDistributionSetTag(entityFactory.tag().create().name("Tag3"));
|
||||
tagManagement.createDistributionSetTag(entityFactory.tag().create().name("Tag4"));
|
||||
|
||||
distributionSetManagement.assignTag(Arrays.asList(ds.getId(), ds2.getId()), targetTag);
|
||||
}
|
||||
|
||||
@@ -15,9 +15,9 @@ import java.util.List;
|
||||
|
||||
import org.eclipse.hawkbit.repository.DistributionSetMetadataFields;
|
||||
import org.eclipse.hawkbit.repository.jpa.AbstractJpaIntegrationTest;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSetMetadata;
|
||||
import org.eclipse.hawkbit.repository.model.DistributionSet;
|
||||
import org.eclipse.hawkbit.repository.model.DistributionSetMetadata;
|
||||
import org.eclipse.hawkbit.repository.model.MetaData;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.springframework.data.domain.Page;
|
||||
@@ -38,12 +38,12 @@ public class RSQLDistributionSetMetadataFieldsTest extends AbstractJpaIntegratio
|
||||
final DistributionSet distributionSet = testdataFactory.createDistributionSet("DS");
|
||||
distributionSetId = distributionSet.getId();
|
||||
|
||||
final List<DistributionSetMetadata> metadata = new ArrayList<>();
|
||||
final List<MetaData> metadata = new ArrayList<>(5);
|
||||
for (int i = 0; i < 5; i++) {
|
||||
metadata.add(new JpaDistributionSetMetadata("" + i, distributionSet, "" + i));
|
||||
metadata.add(entityFactory.generateMetadata("" + i, "" + i));
|
||||
}
|
||||
|
||||
distributionSetManagement.createDistributionSetMetadata(metadata);
|
||||
distributionSetManagement.createDistributionSetMetadata(distributionSetId, metadata);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -12,7 +12,6 @@ import static org.fest.assertions.api.Assertions.assertThat;
|
||||
|
||||
import org.eclipse.hawkbit.repository.RolloutGroupFields;
|
||||
import org.eclipse.hawkbit.repository.jpa.AbstractJpaIntegrationTest;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaRollout;
|
||||
import org.eclipse.hawkbit.repository.model.DistributionSet;
|
||||
import org.eclipse.hawkbit.repository.model.Rollout;
|
||||
import org.eclipse.hawkbit.repository.model.RolloutGroup;
|
||||
@@ -37,7 +36,7 @@ public class RSQLRolloutGroupFields extends AbstractJpaIntegrationTest {
|
||||
@Before
|
||||
public void seuptBeforeTest() {
|
||||
final int amountTargets = 20;
|
||||
targetManagement.createTargets(testdataFactory.generateTargets(amountTargets, "rollout", "rollout"));
|
||||
testdataFactory.createTargets(amountTargets, "rollout", "rollout");
|
||||
final DistributionSet dsA = testdataFactory.createDistributionSet("");
|
||||
rollout = createRollout("rollout1", 4, dsA.getId(), "controllerId==rollout*");
|
||||
rollout = rolloutManagement.findRolloutById(rollout.getId());
|
||||
@@ -83,11 +82,11 @@ public class RSQLRolloutGroupFields extends AbstractJpaIntegrationTest {
|
||||
|
||||
private Rollout createRollout(final String name, final int amountGroups, final long distributionSetId,
|
||||
final String targetFilterQuery) {
|
||||
final Rollout rollout = new JpaRollout();
|
||||
rollout.setDistributionSet(distributionSetManagement.findDistributionSetById(distributionSetId));
|
||||
rollout.setName(name);
|
||||
rollout.setTargetFilterQuery(targetFilterQuery);
|
||||
return rolloutManagement.createRollout(rollout, amountGroups, new RolloutGroupConditionBuilder()
|
||||
.successCondition(RolloutGroupSuccessCondition.THRESHOLD, "100").build());
|
||||
return rolloutManagement.createRollout(
|
||||
entityFactory.rollout().create()
|
||||
.set(distributionSetManagement.findDistributionSetById(distributionSetId)).name(name)
|
||||
.targetFilterQuery(targetFilterQuery),
|
||||
amountGroups, new RolloutGroupConditionBuilder().withDefaults()
|
||||
.successCondition(RolloutGroupSuccessCondition.THRESHOLD, "100").build());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,9 +13,8 @@ import static org.fest.assertions.api.Assertions.assertThat;
|
||||
import org.eclipse.hawkbit.repository.SoftwareModuleFields;
|
||||
import org.eclipse.hawkbit.repository.jpa.AbstractJpaIntegrationTest;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaSoftwareModule;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaSoftwareModuleMetadata;
|
||||
import org.eclipse.hawkbit.repository.model.MetaData;
|
||||
import org.eclipse.hawkbit.repository.model.SoftwareModule;
|
||||
import org.eclipse.hawkbit.repository.model.SoftwareModuleMetadata;
|
||||
import org.eclipse.hawkbit.repository.test.util.TestdataFactory;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
@@ -32,19 +31,21 @@ public class RSQLSoftwareModuleFieldTest extends AbstractJpaIntegrationTest {
|
||||
|
||||
@Before
|
||||
public void setupBeforeTest() {
|
||||
final JpaSoftwareModule ah = (JpaSoftwareModule) softwareManagement
|
||||
.createSoftwareModule(new JpaSoftwareModule(appType, "agent-hub", "1.0.1", "agent-hub", ""));
|
||||
softwareManagement.createSoftwareModule(new JpaSoftwareModule(runtimeType, "oracle-jre", "1.7.2", "aa", ""));
|
||||
softwareManagement.createSoftwareModule(new JpaSoftwareModule(osType, "poky", "3.0.2", "aa", ""));
|
||||
final SoftwareModule ah = softwareManagement.createSoftwareModule(entityFactory.softwareModule().create()
|
||||
.type(appType).name("agent-hub").version("1.0.1").description("agent-hub"));
|
||||
softwareManagement.createSoftwareModule(entityFactory.softwareModule().create().type(runtimeType)
|
||||
.name("oracle-jre").version("1.7.2").description("aa"));
|
||||
softwareManagement.createSoftwareModule(
|
||||
entityFactory.softwareModule().create().type(osType).name("poky").version("3.0.2").description("aa"));
|
||||
|
||||
final JpaSoftwareModule ah2 = (JpaSoftwareModule) softwareManagement
|
||||
.createSoftwareModule(new JpaSoftwareModule(appType, "agent-hub2", "1.0.1", "agent-hub2", ""));
|
||||
final JpaSoftwareModule ah2 = (JpaSoftwareModule) softwareManagement.createSoftwareModule(entityFactory
|
||||
.softwareModule().create().type(appType).name("agent-hub2").version("1.0.1").description("agent-hub2"));
|
||||
|
||||
final SoftwareModuleMetadata softwareModuleMetadata = new JpaSoftwareModuleMetadata("metaKey", ah, "metaValue");
|
||||
softwareManagement.createSoftwareModuleMetadata(softwareModuleMetadata);
|
||||
final MetaData softwareModuleMetadata = entityFactory.generateMetadata("metaKey", "metaValue");
|
||||
softwareManagement.createSoftwareModuleMetadata(ah.getId(), softwareModuleMetadata);
|
||||
|
||||
final SoftwareModuleMetadata softwareModuleMetadata2 = new JpaSoftwareModuleMetadata("metaKey", ah2, "value");
|
||||
softwareManagement.createSoftwareModuleMetadata(softwareModuleMetadata2);
|
||||
final MetaData softwareModuleMetadata2 = entityFactory.generateMetadata("metaKey", "value");
|
||||
softwareManagement.createSoftwareModuleMetadata(ah2.getId(), softwareModuleMetadata2);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -15,7 +15,7 @@ import java.util.List;
|
||||
|
||||
import org.eclipse.hawkbit.repository.SoftwareModuleMetadataFields;
|
||||
import org.eclipse.hawkbit.repository.jpa.AbstractJpaIntegrationTest;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaSoftwareModuleMetadata;
|
||||
import org.eclipse.hawkbit.repository.model.MetaData;
|
||||
import org.eclipse.hawkbit.repository.model.SoftwareModule;
|
||||
import org.eclipse.hawkbit.repository.model.SoftwareModuleMetadata;
|
||||
import org.eclipse.hawkbit.repository.test.util.TestdataFactory;
|
||||
@@ -40,12 +40,12 @@ public class RSQLSoftwareModuleMetadataFieldsTest extends AbstractJpaIntegration
|
||||
|
||||
softwareModuleId = softwareModule.getId();
|
||||
|
||||
final List<SoftwareModuleMetadata> metadata = new ArrayList<>();
|
||||
final List<MetaData> metadata = new ArrayList<>(5);
|
||||
for (int i = 0; i < 5; i++) {
|
||||
metadata.add(new JpaSoftwareModuleMetadata("" + i, softwareModule, "" + i));
|
||||
metadata.add(entityFactory.generateMetadata("" + i, "" + i));
|
||||
}
|
||||
|
||||
softwareManagement.createSoftwareModuleMetadata(metadata);
|
||||
softwareManagement.createSoftwareModuleMetadata(softwareModule.getId(), metadata);
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -11,9 +11,8 @@ package org.eclipse.hawkbit.repository.jpa.rsql;
|
||||
import static org.fest.assertions.api.Assertions.assertThat;
|
||||
|
||||
import org.eclipse.hawkbit.repository.TagFields;
|
||||
import org.eclipse.hawkbit.repository.builder.TagCreate;
|
||||
import org.eclipse.hawkbit.repository.jpa.AbstractJpaIntegrationTest;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSetTag;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaTargetTag;
|
||||
import org.eclipse.hawkbit.repository.model.DistributionSetTag;
|
||||
import org.eclipse.hawkbit.repository.model.TargetTag;
|
||||
import org.junit.Before;
|
||||
@@ -33,11 +32,10 @@ public class RSQLTagFieldsTest extends AbstractJpaIntegrationTest {
|
||||
public void seuptBeforeTest() {
|
||||
|
||||
for (int i = 0; i < 5; i++) {
|
||||
final TargetTag targetTag = new JpaTargetTag("" + i, "" + i, i % 2 == 0 ? "red" : "blue");
|
||||
final TagCreate targetTag = entityFactory.tag().create().name(Integer.toString(i))
|
||||
.description(Integer.toString(i)).colour(i % 2 == 0 ? "red" : "blue");
|
||||
tagManagement.createTargetTag(targetTag);
|
||||
final DistributionSetTag distributionSetTag = new JpaDistributionSetTag("" + i, "" + i,
|
||||
i % 2 == 0 ? "red" : "blue");
|
||||
tagManagement.createDistributionSetTag(distributionSetTag);
|
||||
tagManagement.createDistributionSetTag(targetTag);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -12,18 +12,15 @@ import static org.fest.assertions.api.Assertions.assertThat;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.eclipse.hawkbit.repository.TargetFields;
|
||||
import org.eclipse.hawkbit.repository.exception.RSQLParameterUnsupportedFieldException;
|
||||
import org.eclipse.hawkbit.repository.jpa.AbstractJpaIntegrationTest;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaTarget;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaTargetInfo;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaTargetTag;
|
||||
import org.eclipse.hawkbit.repository.model.DistributionSet;
|
||||
import org.eclipse.hawkbit.repository.model.Target;
|
||||
import org.eclipse.hawkbit.repository.model.TargetInfo;
|
||||
import org.eclipse.hawkbit.repository.model.TargetTag;
|
||||
import org.eclipse.hawkbit.repository.model.TargetUpdateStatus;
|
||||
import org.eclipse.hawkbit.repository.test.util.TestdataFactory;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
@@ -37,40 +34,39 @@ import ru.yandex.qatools.allure.annotations.Stories;
|
||||
@Features("Component Tests - Repository")
|
||||
@Stories("RSQL filter target")
|
||||
public class RSQLTargetFieldTest extends AbstractJpaIntegrationTest {
|
||||
private static final long LAST_TARGET_QUERY = 10000;
|
||||
private static final long LAST_TARGET_QUERY_SMALLER = 1000;
|
||||
|
||||
private Target target;
|
||||
private Target target2;
|
||||
|
||||
@Before
|
||||
public void seuptBeforeTest() {
|
||||
public void seuptBeforeTest() throws InterruptedException {
|
||||
|
||||
final DistributionSet ds = testdataFactory.createDistributionSet("AssignedDs");
|
||||
|
||||
final Target target = entityFactory.generateTarget("targetId123");
|
||||
target.setDescription("targetId123");
|
||||
final TargetInfo targetInfo = target.getTargetInfo();
|
||||
targetInfo.getControllerAttributes().put("revision", "1.1");
|
||||
((JpaTargetInfo) target.getTargetInfo()).setUpdateStatus(TargetUpdateStatus.PENDING);
|
||||
((JpaTargetInfo) target.getTargetInfo()).setLastTargetQuery(LAST_TARGET_QUERY);
|
||||
targetManagement.createTarget(target);
|
||||
final Map<String, String> attributes = new HashMap<>();
|
||||
|
||||
final JpaTarget target2 = new JpaTarget("targetId1234");
|
||||
target2.setDescription("targetId1234");
|
||||
final TargetInfo targetInfo2 = target2.getTargetInfo();
|
||||
targetInfo2.getControllerAttributes().put("revision", "1.2");
|
||||
((JpaTargetInfo) target2.getTargetInfo()).setLastTargetQuery(LAST_TARGET_QUERY_SMALLER);
|
||||
targetManagement.createTarget(target2);
|
||||
target = targetManagement.createTarget(entityFactory.target().create().controllerId("targetId123")
|
||||
.name("targetName123").description("targetDesc123"));
|
||||
attributes.put("revision", "1.1");
|
||||
target = controllerManagament.updateControllerAttributes(target.getControllerId(), attributes);
|
||||
|
||||
targetManagement.createTarget(new JpaTarget("targetId1235"));
|
||||
targetManagement.createTarget(new JpaTarget("targetId1236"));
|
||||
target2 = targetManagement
|
||||
.createTarget(entityFactory.target().create().controllerId("targetId1234").description("targetId1234"));
|
||||
attributes.put("revision", "1.2");
|
||||
Thread.sleep(1);
|
||||
target2 = controllerManagament.updateControllerAttributes(target2.getControllerId(), attributes);
|
||||
|
||||
final TargetTag targetTag = tagManagement.createTargetTag(new JpaTargetTag("Tag1"));
|
||||
tagManagement.createTargetTag(new JpaTargetTag("Tag2"));
|
||||
tagManagement.createTargetTag(new JpaTargetTag("Tag3"));
|
||||
tagManagement.createTargetTag(new JpaTargetTag("Tag4"));
|
||||
testdataFactory.createTarget("targetId1235");
|
||||
testdataFactory.createTarget("targetId1236");
|
||||
|
||||
final TargetTag targetTag = tagManagement.createTargetTag(entityFactory.tag().create().name("Tag1"));
|
||||
tagManagement.createTargetTag(entityFactory.tag().create().name("Tag2"));
|
||||
tagManagement.createTargetTag(entityFactory.tag().create().name("Tag3"));
|
||||
tagManagement.createTargetTag(entityFactory.tag().create().name("Tag4"));
|
||||
|
||||
targetManagement.assignTag(Arrays.asList(target.getControllerId(), target2.getControllerId()), targetTag);
|
||||
|
||||
deploymentManagement.assignDistributionSet(ds.getId(), target.getControllerId());
|
||||
assignDistributionSet(ds.getId(), target.getControllerId());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -86,21 +82,21 @@ public class RSQLTargetFieldTest extends AbstractJpaIntegrationTest {
|
||||
@Test
|
||||
@Description("Test filter target by name")
|
||||
public void testFilterByParameterName() {
|
||||
assertRSQLQuery(TargetFields.NAME.name() + "==targetId123", 1);
|
||||
assertRSQLQuery(TargetFields.NAME.name() + "==targetName123", 1);
|
||||
assertRSQLQuery(TargetFields.NAME.name() + "==target*", 4);
|
||||
assertRSQLQuery(TargetFields.NAME.name() + "==noExist*", 0);
|
||||
assertRSQLQuery(TargetFields.NAME.name() + "=in=(targetId123,notexist)", 1);
|
||||
assertRSQLQuery(TargetFields.NAME.name() + "=out=(targetId123,notexist)", 3);
|
||||
assertRSQLQuery(TargetFields.NAME.name() + "=in=(targetName123,notexist)", 1);
|
||||
assertRSQLQuery(TargetFields.NAME.name() + "=out=(targetName123,notexist)", 3);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Description("Test filter target by description")
|
||||
public void testFilterByParameterDescription() {
|
||||
assertRSQLQuery(TargetFields.DESCRIPTION.name() + "==targetId123", 1);
|
||||
assertRSQLQuery(TargetFields.DESCRIPTION.name() + "==targetDesc123", 1);
|
||||
assertRSQLQuery(TargetFields.DESCRIPTION.name() + "==target*", 2);
|
||||
assertRSQLQuery(TargetFields.DESCRIPTION.name() + "==noExist*", 0);
|
||||
assertRSQLQuery(TargetFields.DESCRIPTION.name() + "=in=(targetId123,notexist)", 1);
|
||||
assertRSQLQuery(TargetFields.DESCRIPTION.name() + "=out=(targetId123,notexist)", 1);
|
||||
assertRSQLQuery(TargetFields.DESCRIPTION.name() + "=in=(targetDesc123,notexist)", 1);
|
||||
assertRSQLQuery(TargetFields.DESCRIPTION.name() + "=out=(targetDesc123,notexist)", 1);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -172,13 +168,19 @@ public class RSQLTargetFieldTest extends AbstractJpaIntegrationTest {
|
||||
|
||||
@Test
|
||||
@Description("Test filter target by lastTargetQuery")
|
||||
public void testFilterByLastTargetQuery() {
|
||||
assertRSQLQuery(TargetFields.LASTCONTROLLERREQUESTAT.name() + "==" + LAST_TARGET_QUERY, 1);
|
||||
assertRSQLQuery(TargetFields.LASTCONTROLLERREQUESTAT.name() + "!=" + LAST_TARGET_QUERY, 1);
|
||||
assertRSQLQuery(TargetFields.LASTCONTROLLERREQUESTAT.name() + "=lt=" + LAST_TARGET_QUERY, 1);
|
||||
assertRSQLQuery(TargetFields.LASTCONTROLLERREQUESTAT.name() + "=lt=" + LAST_TARGET_QUERY_SMALLER, 0);
|
||||
assertRSQLQuery(TargetFields.LASTCONTROLLERREQUESTAT.name() + "=gt=" + LAST_TARGET_QUERY_SMALLER, 1);
|
||||
assertRSQLQuery(TargetFields.LASTCONTROLLERREQUESTAT.name() + "=gt=" + LAST_TARGET_QUERY, 0);
|
||||
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);
|
||||
}
|
||||
|
||||
private void assertRSQLQuery(final String rsqlParam, final long expcetedTargets) {
|
||||
|
||||
@@ -9,8 +9,15 @@
|
||||
package org.eclipse.hawkbit.repository.jpa.rsql;
|
||||
|
||||
import static org.junit.Assert.fail;
|
||||
import static org.mockito.Matchers.*;
|
||||
import static org.mockito.Mockito.*;
|
||||
import static org.mockito.Matchers.any;
|
||||
import static org.mockito.Matchers.anyString;
|
||||
import static org.mockito.Matchers.eq;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.never;
|
||||
import static org.mockito.Mockito.reset;
|
||||
import static org.mockito.Mockito.times;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
import static org.powermock.api.mockito.PowerMockito.mockStatic;
|
||||
|
||||
import javax.persistence.criteria.CriteriaBuilder;
|
||||
@@ -38,9 +45,9 @@ import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.Spy;
|
||||
|
||||
import org.powermock.core.classloader.annotations.PrepareForTest;
|
||||
import org.powermock.modules.junit4.PowerMockRunner;
|
||||
|
||||
import ru.yandex.qatools.allure.annotations.Description;
|
||||
import ru.yandex.qatools.allure.annotations.Features;
|
||||
import ru.yandex.qatools.allure.annotations.Stories;
|
||||
|
||||
@@ -8,10 +8,10 @@
|
||||
*/
|
||||
package org.eclipse.hawkbit.repository.jpa.rsql;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.mockito.Mockito.when;
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
import static org.hamcrest.Matchers.not;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.mockito.Mockito.when;
|
||||
import static org.powermock.api.mockito.PowerMockito.mockStatic;
|
||||
|
||||
import java.time.Instant;
|
||||
@@ -22,15 +22,14 @@ import org.eclipse.hawkbit.repository.TimestampCalculator;
|
||||
import org.eclipse.hawkbit.repository.model.TenantConfigurationValue;
|
||||
import org.eclipse.hawkbit.repository.rsql.VirtualPropertyResolver;
|
||||
import org.eclipse.hawkbit.tenancy.configuration.TenantConfigurationKey;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.Spy;
|
||||
|
||||
import org.powermock.core.classloader.annotations.PrepareForTest;
|
||||
import org.powermock.modules.junit4.PowerMockRunner;
|
||||
|
||||
import ru.yandex.qatools.allure.annotations.Description;
|
||||
import ru.yandex.qatools.allure.annotations.Features;
|
||||
import ru.yandex.qatools.allure.annotations.Stories;
|
||||
|
||||
@@ -11,9 +11,6 @@ package org.eclipse.hawkbit.repository.jpa.tenancy;
|
||||
import static org.fest.assertions.api.Assertions.assertThat;
|
||||
|
||||
import org.eclipse.hawkbit.repository.jpa.AbstractJpaIntegrationTest;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSet;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSetType;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaTarget;
|
||||
import org.eclipse.hawkbit.repository.model.DistributionSet;
|
||||
import org.eclipse.hawkbit.repository.model.Target;
|
||||
import org.eclipse.hawkbit.repository.test.util.WithSpringAuthorityRule;
|
||||
@@ -139,16 +136,12 @@ public class MultiTenancyEntityTest extends AbstractJpaIntegrationTest {
|
||||
@Description(value = "Ensures that multiple distribution sets with same name and version can be created for different tenants.")
|
||||
public void createMultipleDistributionSetsWithSameNameForDifferentTenants() throws Exception {
|
||||
|
||||
// known ds name for overall tenants same
|
||||
final String knownDistributionSetName = "dsName";
|
||||
final String knownDistributionSetVersion = "0.0.0";
|
||||
|
||||
// known tenant names
|
||||
final String tenant = "aTenant";
|
||||
final String anotherTenant = "anotherTenant";
|
||||
// create distribution sets
|
||||
createDistributionSetForTenant(knownDistributionSetName, knownDistributionSetVersion, tenant);
|
||||
createDistributionSetForTenant(knownDistributionSetName, knownDistributionSetVersion, anotherTenant);
|
||||
createDistributionSetForTenant(tenant);
|
||||
createDistributionSetForTenant(anotherTenant);
|
||||
|
||||
// ensure both tenants see their distribution sets
|
||||
final Page<DistributionSet> findDistributionSetsForTenant = findDistributionSetForTenant(tenant);
|
||||
@@ -164,7 +157,7 @@ public class MultiTenancyEntityTest extends AbstractJpaIntegrationTest {
|
||||
|
||||
private Target createTargetForTenant(final String controllerId, final String tenant) throws Exception {
|
||||
return securityRule.runAs(WithSpringAuthorityRule.withUserAndTenant("user", tenant),
|
||||
() -> targetManagement.createTarget(new JpaTarget(controllerId)));
|
||||
() -> testdataFactory.createTarget(controllerId));
|
||||
}
|
||||
|
||||
private Slice<Target> findTargetsForTenant(final String tenant) throws Exception {
|
||||
@@ -179,22 +172,14 @@ public class MultiTenancyEntityTest extends AbstractJpaIntegrationTest {
|
||||
});
|
||||
}
|
||||
|
||||
private DistributionSet createDistributionSetForTenant(final String name, final String version, final String tenant)
|
||||
throws Exception {
|
||||
return securityRule.runAs(WithSpringAuthorityRule.withUserAndTenant("user", tenant), () -> {
|
||||
final JpaDistributionSet ds = new JpaDistributionSet();
|
||||
ds.setName(name);
|
||||
ds.setTenant(tenant);
|
||||
ds.setVersion(version);
|
||||
ds.setType(distributionSetManagement
|
||||
.createDistributionSetType(new JpaDistributionSetType("typetest", "test", "foobar")));
|
||||
return distributionSetManagement.createDistributionSet(ds);
|
||||
});
|
||||
private DistributionSet createDistributionSetForTenant(final String tenant) throws Exception {
|
||||
return securityRule.runAs(WithSpringAuthorityRule.withUserAndTenant("user", tenant),
|
||||
() -> testdataFactory.createDistributionSet());
|
||||
}
|
||||
|
||||
private Page<DistributionSet> findDistributionSetForTenant(final String tenant) throws Exception {
|
||||
return securityRule.runAs(WithSpringAuthorityRule.withUserAndTenant("user", tenant),
|
||||
() -> distributionSetManagement.findDistributionSetsByDeletedAndOrCompleted(pageReq, false, false));
|
||||
() -> distributionSetManagement.findDistributionSetsByDeletedAndOrCompleted(pageReq, false, true));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user