Split repository API for module and DS management. Refactor utility usage (#524)

* Split DS management and reduce util usage.

Signed-off-by: kaizimmerm <kai.zimmermann@bosch-si.com>

* Split sw module and type management.

Signed-off-by: kaizimmerm <kai.zimmermann@bosch-si.com>

* Sonar issues.

Signed-off-by: kaizimmerm <kai.zimmermann@bosch-si.com>

* Make sonar listen to the exception!

Signed-off-by: kaizimmerm <kai.zimmermann@bosch-si.com>

* Register both beans.

Signed-off-by: kaizimmerm <kai.zimmermann@bosch-si.com>

* Split JPA implementations.

Signed-off-by: kaizimmerm <kai.zimmermann@bosch-si.com>

* Revert user details change.

Signed-off-by: kaizimmerm <kai.zimmermann@bosch-si.com>

* Fix compilation errors.

Signed-off-by: kaizimmerm <kai.zimmermann@bosch-si.com>

* Fix bean queries. Fix image path.

Signed-off-by: kaizimmerm <kai.zimmermann@bosch-si.com>

* Document preferred utility usage.

Signed-off-by: kaizimmerm <kai.zimmermann@bosch-si.com>

* Fix exmaples and revert unintended checkin.

Signed-off-by: kaizimmerm <kai.zimmermann@bosch-si.com>

* Code cleanup.

Signed-off-by: kaizimmerm <kai.zimmermann@bosch-si.com>

* Typos, readibility.

Signed-off-by: kaizimmerm <kai.zimmermann@bosch-si.com>

* Remove unused reference.

Signed-off-by: kaizimmerm <kai.zimmermann@bosch-si.com>

* Rollouts cache delete aware.

Signed-off-by: kaizimmerm <kai.zimmermann@bosch-si.com>

* Fix rolloutgroup delete event.

Signed-off-by: kaizimmerm <kai.zimmermann@bosch-si.com>

* Add new RolloutGroupDeletedEvent event

Signed-off-by: kaizimmerm <kai.zimmermann@bosch-si.com>
This commit is contained in:
Kai Zimmermann
2017-06-01 06:28:59 +02:00
committed by GitHub
parent 0ab995d1a4
commit 67a4677ef6
203 changed files with 2738 additions and 2320 deletions

View File

@@ -12,7 +12,6 @@ import static org.junit.Assert.fail;
import java.util.Map;
import org.apache.commons.lang3.ClassUtils;
import org.eclipse.hawkbit.event.BusProtoStuffMessageConverter;
import org.eclipse.hawkbit.repository.event.TenantAwareEvent;
import org.eclipse.hawkbit.repository.jpa.AbstractJpaIntegrationTest;
@@ -27,6 +26,7 @@ import org.springframework.messaging.Message;
import org.springframework.messaging.MessageHeaders;
import org.springframework.messaging.converter.AbstractMessageConverter;
import org.springframework.test.util.ReflectionTestUtils;
import org.springframework.util.ClassUtils;
import org.springframework.util.MimeType;
import org.springframework.util.MimeTypeUtils;

View File

@@ -17,7 +17,6 @@ import javax.persistence.PersistenceContext;
import org.assertj.core.api.Assertions;
import org.assertj.core.api.ThrowableAssert.ThrowingCallable;
import org.eclipse.hawkbit.cache.TenantAwareCacheManager;
import org.eclipse.hawkbit.repository.exception.EntityNotFoundException;
import org.eclipse.hawkbit.repository.model.Action;
import org.eclipse.hawkbit.repository.model.DistributionSet;
@@ -90,9 +89,6 @@ public abstract class AbstractJpaIntegrationTest extends AbstractIntegrationTest
@Autowired
protected RolloutRepository rolloutRepository;
@Autowired
protected TenantAwareCacheManager cacheManager;
@Autowired
protected TenantConfigurationProperties tenantConfigurationProperties;
@@ -108,7 +104,7 @@ public abstract class AbstractJpaIntegrationTest extends AbstractIntegrationTest
protected TargetTagAssignmentResult toggleTagAssignment(final Collection<Target> targets, final TargetTag tag) {
return targetManagement.toggleTagAssignment(
targets.stream().map(target -> target.getControllerId()).collect(Collectors.toList()), tag.getName());
targets.stream().map(Target::getControllerId).collect(Collectors.toList()), tag.getName());
}
public DistributionSetTagAssignmentResult toggleTagAssignment(final Collection<DistributionSet> sets,

View File

@@ -127,7 +127,7 @@ public class ArtifactManagementTest extends AbstractJpaIntegrationTest {
assertThat(artifactRepository.findAll()).hasSize(4);
assertThat(softwareModuleRepository.findAll()).hasSize(3);
assertThat(softwareManagement.findSoftwareModuleById(sm.getId()).get().getArtifacts()).hasSize(3);
assertThat(softwareModuleManagement.findSoftwareModuleById(sm.getId()).get().getArtifacts()).hasSize(3);
}
@Test

View File

@@ -14,6 +14,7 @@ import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.LinkedList;
@@ -111,13 +112,11 @@ public class DeploymentManagementTest extends AbstractJpaIntegrationTest {
final Target target = testdataFactory.createTarget();
verifyThrownExceptionBy(() -> deploymentManagement.assignDistributionSet(NOT_EXIST_IDL,
Lists.newArrayList(new TargetWithActionType(target.getControllerId()))), "DistributionSet");
verifyThrownExceptionBy(
() -> deploymentManagement.assignDistributionSet(NOT_EXIST_IDL,
Lists.newArrayList(new TargetWithActionType(target.getControllerId())), "xxx"),
"DistributionSet");
Arrays.asList(new TargetWithActionType(target.getControllerId()))), "DistributionSet");
verifyThrownExceptionBy(() -> deploymentManagement.assignDistributionSet(NOT_EXIST_IDL,
Arrays.asList(new TargetWithActionType(target.getControllerId())), "xxx"), "DistributionSet");
verifyThrownExceptionBy(() -> deploymentManagement.assignDistributionSet(NOT_EXIST_IDL, ActionType.FORCED,
System.currentTimeMillis(), Lists.newArrayList(target.getControllerId())), "DistributionSet");
System.currentTimeMillis(), Arrays.asList(target.getControllerId())), "DistributionSet");
verifyThrownExceptionBy(() -> deploymentManagement.cancelAction(NOT_EXIST_IDL), "Action");
verifyThrownExceptionBy(() -> deploymentManagement.countActionsByTarget(NOT_EXIST_ID), "Target");
@@ -126,12 +125,10 @@ public class DeploymentManagementTest extends AbstractJpaIntegrationTest {
verifyThrownExceptionBy(() -> deploymentManagement.findActionsByDistributionSet(PAGE, NOT_EXIST_IDL),
"DistributionSet");
verifyThrownExceptionBy(() -> deploymentManagement.findActionsByTarget(NOT_EXIST_ID, PAGE), "Target");
verifyThrownExceptionBy(() -> deploymentManagement.findActionsByTarget("id==*", NOT_EXIST_ID, PAGE),
"Target");
verifyThrownExceptionBy(() -> deploymentManagement.findActionsByTarget("id==*", NOT_EXIST_ID, PAGE), "Target");
verifyThrownExceptionBy(() -> deploymentManagement.findActiveActionsByTarget(PAGE, NOT_EXIST_ID), "Target");
verifyThrownExceptionBy(() -> deploymentManagement.findInActiveActionsByTarget(PAGE, NOT_EXIST_ID),
"Target");
verifyThrownExceptionBy(() -> deploymentManagement.findInActiveActionsByTarget(PAGE, NOT_EXIST_ID), "Target");
verifyThrownExceptionBy(() -> deploymentManagement.forceQuitAction(NOT_EXIST_IDL), "Action");
verifyThrownExceptionBy(() -> deploymentManagement.forceTargetAction(NOT_EXIST_IDL), "Action");
}
@@ -200,7 +197,7 @@ public class DeploymentManagementTest extends AbstractJpaIntegrationTest {
final Long actionId = assignDistributionSet(testDs, testTarget).getActions().get(0);
// create action-status entry with one message
controllerManagement.addUpdateActionStatus(entityFactory.actionStatus().create(actionId)
.status(Action.Status.FINISHED).messages(Lists.newArrayList("finished message")));
.status(Action.Status.FINISHED).messages(Arrays.asList("finished message")));
final Page<ActionStatus> actionStates = deploymentManagement.findActionStatusByAction(PAGE, actionId);
// find newly created action-status entry with message
@@ -426,8 +423,7 @@ public class DeploymentManagementTest extends AbstractJpaIntegrationTest {
assertThat(deploymentManagement.getAssignedDistributionSet(target.getControllerId()).get())
.as("wrong assigned ds").isEqualTo(ds);
final JpaAction action = actionRepository
.findByTargetAndDistributionSet(PAGE, (JpaTarget) target, (JpaDistributionSet) ds).getContent()
.get(0);
.findByTargetAndDistributionSet(PAGE, (JpaTarget) target, (JpaDistributionSet) ds).getContent().get(0);
assertThat(action).as("action should not be null").isNotNull();
return action;
}
@@ -505,7 +501,7 @@ public class DeploymentManagementTest extends AbstractJpaIntegrationTest {
final DistributionSet incomplete = distributionSetManagement
.createDistributionSet(entityFactory.distributionSet().create().name("incomplete").version("v1")
.type(standardDsType).modules(Lists.newArrayList(ah.getId())));
.type(standardDsType).modules(Arrays.asList(ah.getId())));
try {
assignDistributionSet(incomplete, targets);
@@ -786,7 +782,7 @@ public class DeploymentManagementTest extends AbstractJpaIntegrationTest {
final DistributionSet dsA = testdataFactory.createDistributionSet("a");
final DistributionSet dsB = testdataFactory.createDistributionSet("b");
List<Target> targs = Lists.newArrayList(testdataFactory.createTarget("target-id-A"));
List<Target> targs = Arrays.asList(testdataFactory.createTarget("target-id-A"));
// doing the assignment
targs = assignDistributionSet(dsA, targs).getAssignedEntity();
@@ -856,7 +852,7 @@ public class DeploymentManagementTest extends AbstractJpaIntegrationTest {
assertThat(dsA.getOptLockRevision()).as("lock revision is wrong").isEqualTo(
distributionSetManagement.findDistributionSetByIdWithDetails(dsA.getId()).get().getOptLockRevision());
assignDistributionSet(dsA, Lists.newArrayList(targ));
assignDistributionSet(dsA, Arrays.asList(targ));
assertThat(dsA.getOptLockRevision()).as("lock revision is wrong").isEqualTo(
distributionSetManagement.findDistributionSetByIdWithDetails(dsA.getId()).get().getOptLockRevision());
@@ -872,7 +868,7 @@ public class DeploymentManagementTest extends AbstractJpaIntegrationTest {
final DistributionSetAssignmentResult assignDistributionSet = deploymentManagement.assignDistributionSet(
ds.getId(), ActionType.SOFT,
org.eclipse.hawkbit.repository.model.RepositoryModelConstants.NO_FORCE_TIME,
Lists.newArrayList(target.getControllerId()));
Arrays.asList(target.getControllerId()));
final Action action = deploymentManagement.findActionWithDetails(assignDistributionSet.getActions().get(0))
.get();
// verify preparation
@@ -897,7 +893,7 @@ public class DeploymentManagementTest extends AbstractJpaIntegrationTest {
final DistributionSetAssignmentResult assignDistributionSet = deploymentManagement.assignDistributionSet(
ds.getId(), ActionType.FORCED,
org.eclipse.hawkbit.repository.model.RepositoryModelConstants.NO_FORCE_TIME,
Lists.newArrayList(target.getControllerId()));
Arrays.asList(target.getControllerId()));
final Action action = deploymentManagement.findActionWithDetails(assignDistributionSet.getActions().get(0))
.get();
// verify perparation

View File

@@ -13,6 +13,7 @@ import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.Iterator;
@@ -31,7 +32,6 @@ import org.eclipse.hawkbit.repository.exception.EntityReadOnlyException;
import org.eclipse.hawkbit.repository.exception.UnsupportedSoftwareModuleForThisDistributionSetException;
import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSet;
import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSetMetadata;
import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSetType;
import org.eclipse.hawkbit.repository.model.Action.Status;
import org.eclipse.hawkbit.repository.model.DistributionSet;
import org.eclipse.hawkbit.repository.model.DistributionSetAssignmentResult;
@@ -75,9 +75,6 @@ public class DistributionSetManagementTest extends AbstractJpaIntegrationTest {
.isNotPresent();
assertThat(distributionSetManagement.findDistributionSetMetadata(set.getId(), NOT_EXIST_ID)).isNotPresent();
assertThat(distributionSetManagement.findDistributionSetTypeById(NOT_EXIST_IDL)).isNotPresent();
assertThat(distributionSetManagement.findDistributionSetTypeByKey(NOT_EXIST_ID)).isNotPresent();
assertThat(distributionSetManagement.findDistributionSetTypeByName(NOT_EXIST_ID)).isNotPresent();
}
@Test
@@ -91,22 +88,11 @@ public class DistributionSetManagementTest extends AbstractJpaIntegrationTest {
final DistributionSetTag dsTag = testdataFactory.createDistributionSetTags(1).get(0);
final SoftwareModule module = testdataFactory.createSoftwareModuleApp();
verifyThrownExceptionBy(() -> distributionSetManagement.assignMandatorySoftwareModuleTypes(NOT_EXIST_IDL,
Lists.newArrayList(osType.getId())), "DistributionSetType");
verifyThrownExceptionBy(() -> distributionSetManagement.assignMandatorySoftwareModuleTypes(
testdataFactory.findOrCreateDistributionSetType("xxx", "xxx").getId(),
Lists.newArrayList(NOT_EXIST_IDL)), "SoftwareModuleType");
verifyThrownExceptionBy(() -> distributionSetManagement.assignOptionalSoftwareModuleTypes(1234L,
Lists.newArrayList(osType.getId())), "DistributionSetType");
verifyThrownExceptionBy(() -> distributionSetManagement.assignOptionalSoftwareModuleTypes(
testdataFactory.findOrCreateDistributionSetType("xxx", "xxx").getId(),
Lists.newArrayList(NOT_EXIST_IDL)), "SoftwareModuleType");
verifyThrownExceptionBy(() -> distributionSetManagement.assignSoftwareModules(NOT_EXIST_IDL,
Lists.newArrayList(module.getId())), "DistributionSet");
verifyThrownExceptionBy(
() -> distributionSetManagement.assignSoftwareModules(set.getId(), Lists.newArrayList(NOT_EXIST_IDL)),
() -> distributionSetManagement.assignSoftwareModules(NOT_EXIST_IDL, Arrays.asList(module.getId())),
"DistributionSet");
verifyThrownExceptionBy(
() -> distributionSetManagement.assignSoftwareModules(set.getId(), Arrays.asList(NOT_EXIST_IDL)),
"SoftwareModule");
verifyThrownExceptionBy(() -> distributionSetManagement.unassignSoftwareModule(NOT_EXIST_IDL, module.getId()),
@@ -114,12 +100,10 @@ public class DistributionSetManagementTest extends AbstractJpaIntegrationTest {
verifyThrownExceptionBy(() -> distributionSetManagement.unassignSoftwareModule(set.getId(), NOT_EXIST_IDL),
"SoftwareModule");
verifyThrownExceptionBy(
() -> distributionSetManagement.assignTag(Lists.newArrayList(set.getId()), NOT_EXIST_IDL),
verifyThrownExceptionBy(() -> distributionSetManagement.assignTag(Arrays.asList(set.getId()), NOT_EXIST_IDL),
"DistributionSetTag");
verifyThrownExceptionBy(
() -> distributionSetManagement.assignTag(Lists.newArrayList(NOT_EXIST_IDL), dsTag.getId()),
verifyThrownExceptionBy(() -> distributionSetManagement.assignTag(Arrays.asList(NOT_EXIST_IDL), dsTag.getId()),
"DistributionSet");
verifyThrownExceptionBy(() -> distributionSetManagement.findDistributionSetsByTag(PAGE, NOT_EXIST_IDL),
@@ -129,10 +113,10 @@ public class DistributionSetManagementTest extends AbstractJpaIntegrationTest {
"DistributionSetTag");
verifyThrownExceptionBy(
() -> distributionSetManagement.toggleTagAssignment(Lists.newArrayList(NOT_EXIST_IDL), dsTag.getName()),
() -> distributionSetManagement.toggleTagAssignment(Arrays.asList(NOT_EXIST_IDL), dsTag.getName()),
"DistributionSet");
verifyThrownExceptionBy(
() -> distributionSetManagement.toggleTagAssignment(Lists.newArrayList(set.getId()), NOT_EXIST_ID),
() -> distributionSetManagement.toggleTagAssignment(Arrays.asList(set.getId()), NOT_EXIST_ID),
"DistributionSetTag");
verifyThrownExceptionBy(() -> distributionSetManagement.unAssignTag(set.getId(), NOT_EXIST_IDL),
@@ -141,19 +125,15 @@ public class DistributionSetManagementTest extends AbstractJpaIntegrationTest {
verifyThrownExceptionBy(() -> distributionSetManagement.unAssignTag(NOT_EXIST_IDL, dsTag.getId()),
"DistributionSet");
verifyThrownExceptionBy(() -> distributionSetManagement.countDistributionSetsByType(NOT_EXIST_IDL),
"DistributionSet");
verifyThrownExceptionBy(
() -> distributionSetManagement
.createDistributionSet(entityFactory.distributionSet().create().name("xxx").type(NOT_EXIST_ID)),
"DistributionSetType");
verifyThrownExceptionBy(() -> distributionSetManagement.createDistributionSetMetadata(NOT_EXIST_IDL,
Lists.newArrayList(entityFactory.generateMetadata("123", "123"))), "DistributionSet");
Arrays.asList(entityFactory.generateMetadata("123", "123"))), "DistributionSet");
verifyThrownExceptionBy(
() -> distributionSetManagement.deleteDistributionSet(Lists.newArrayList(NOT_EXIST_IDL)),
verifyThrownExceptionBy(() -> distributionSetManagement.deleteDistributionSet(Arrays.asList(NOT_EXIST_IDL)),
"DistributionSet");
verifyThrownExceptionBy(() -> distributionSetManagement.deleteDistributionSet(NOT_EXIST_IDL),
"DistributionSet");
@@ -163,9 +143,6 @@ public class DistributionSetManagementTest extends AbstractJpaIntegrationTest {
() -> distributionSetManagement.deleteDistributionSetMetadata(set.getId(), NOT_EXIST_ID),
"DistributionSetMetadata");
verifyThrownExceptionBy(() -> distributionSetManagement.deleteDistributionSetType(NOT_EXIST_IDL),
"DistributionSetType");
verifyThrownExceptionBy(() -> distributionSetManagement.findDistributionSetByAction(NOT_EXIST_IDL), "Action");
verifyThrownExceptionBy(() -> distributionSetManagement.findDistributionSetMetadata(NOT_EXIST_IDL, "xxx"),
@@ -192,124 +169,6 @@ public class DistributionSetManagementTest extends AbstractJpaIntegrationTest {
verifyThrownExceptionBy(() -> distributionSetManagement.updateDistributionSetMetadata(set.getId(),
entityFactory.generateMetadata(NOT_EXIST_ID, "xxx")), "DistributionSetMetadata");
verifyThrownExceptionBy(
() -> distributionSetManagement
.updateDistributionSetType(entityFactory.distributionSetType().update(NOT_EXIST_IDL)),
"DistributionSet");
}
@Test
@Description("Tests the successfull module update of unused distribution set type which is in fact allowed.")
public void updateUnassignedDistributionSetTypeModules() {
final DistributionSetType updatableType = distributionSetManagement.createDistributionSetType(
entityFactory.distributionSetType().create().key("updatableType").name("to be deleted"));
assertThat(
distributionSetManagement.findDistributionSetTypeByKey("updatableType").get().getMandatoryModuleTypes())
.isEmpty();
// add OS
distributionSetManagement.assignMandatorySoftwareModuleTypes(updatableType.getId(),
Sets.newHashSet(osType.getId()));
assertThat(
distributionSetManagement.findDistributionSetTypeByKey("updatableType").get().getMandatoryModuleTypes())
.containsOnly(osType);
// add JVM
distributionSetManagement.assignMandatorySoftwareModuleTypes(updatableType.getId(),
Sets.newHashSet(runtimeType.getId()));
assertThat(
distributionSetManagement.findDistributionSetTypeByKey("updatableType").get().getMandatoryModuleTypes())
.containsOnly(osType, runtimeType);
// remove OS
distributionSetManagement.unassignSoftwareModuleType(updatableType.getId(), osType.getId());
assertThat(
distributionSetManagement.findDistributionSetTypeByKey("updatableType").get().getMandatoryModuleTypes())
.containsOnly(runtimeType);
}
@Test
@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(entityFactory
.distributionSetType().create().key("updatableType").name("to be deleted").colour("test123"));
assertThat(
distributionSetManagement.findDistributionSetTypeByKey("updatableType").get().getMandatoryModuleTypes())
.isEmpty();
distributionSetManagement.createDistributionSet(entityFactory.distributionSet().create().name("newtypesoft")
.version("1").type(nonUpdatableType.getKey()));
distributionSetManagement.updateDistributionSetType(
entityFactory.distributionSetType().update(nonUpdatableType.getId()).description("a new description"));
assertThat(distributionSetManagement.findDistributionSetTypeByKey("updatableType").get().getDescription())
.isEqualTo("a new description");
assertThat(distributionSetManagement.findDistributionSetTypeByKey("updatableType").get().getColour())
.isEqualTo("test123");
}
@Test
@Description("Tests the unsuccessfull update of used distribution set type (module addition).")
public void addModuleToAssignedDistributionSetTypeFails() {
final DistributionSetType nonUpdatableType = distributionSetManagement.createDistributionSetType(
entityFactory.distributionSetType().create().key("updatableType").name("to be deleted"));
assertThat(
distributionSetManagement.findDistributionSetTypeByKey("updatableType").get().getMandatoryModuleTypes())
.isEmpty();
distributionSetManagement.createDistributionSet(entityFactory.distributionSet().create().name("newtypesoft")
.version("1").type(nonUpdatableType.getKey()));
assertThatThrownBy(() -> distributionSetManagement.assignMandatorySoftwareModuleTypes(nonUpdatableType.getId(),
Sets.newHashSet(osType.getId()))).isInstanceOf(EntityReadOnlyException.class);
}
@Test
@Description("Tests the unsuccessfull update of used distribution set type (module removal).")
public void removeModuleToAssignedDistributionSetTypeFails() {
DistributionSetType nonUpdatableType = distributionSetManagement.createDistributionSetType(
entityFactory.distributionSetType().create().key("updatableType").name("to be deleted"));
assertThat(
distributionSetManagement.findDistributionSetTypeByKey("updatableType").get().getMandatoryModuleTypes())
.isEmpty();
nonUpdatableType = distributionSetManagement.assignMandatorySoftwareModuleTypes(nonUpdatableType.getId(),
Sets.newHashSet(osType.getId()));
distributionSetManagement.createDistributionSet(entityFactory.distributionSet().create().name("newtypesoft")
.version("1").type(nonUpdatableType.getKey()));
final Long typeId = nonUpdatableType.getId();
assertThatThrownBy(() -> distributionSetManagement.unassignSoftwareModuleType(typeId, osType.getId()))
.isInstanceOf(EntityReadOnlyException.class);
}
@Test
@Description("Tests the successfull deletion of unused (hard delete) distribution set types.")
public void deleteUnassignedDistributionSetType() {
final JpaDistributionSetType hardDelete = (JpaDistributionSetType) distributionSetManagement
.createDistributionSetType(
entityFactory.distributionSetType().create().key("delete").name("to be deleted"));
assertThat(distributionSetTypeRepository.findAll()).contains(hardDelete);
distributionSetManagement.deleteDistributionSetType(hardDelete.getId());
assertThat(distributionSetTypeRepository.findAll()).doesNotContain(hardDelete);
}
@Test
@Description("Tests the successfull deletion of used (soft delete) distribution set types.")
public void deleteAssignedDistributionSetType() {
final JpaDistributionSetType softDelete = (JpaDistributionSetType) distributionSetManagement
.createDistributionSetType(
entityFactory.distributionSetType().create().key("softdeleted").name("to be deleted"));
assertThat(distributionSetTypeRepository.findAll()).contains(softDelete);
distributionSetManagement.createDistributionSet(
entityFactory.distributionSet().create().name("softdeleted").version("1").type(softDelete.getKey()));
distributionSetManagement.deleteDistributionSetType(softDelete.getId());
assertThat(distributionSetManagement.findDistributionSetTypeByKey("softdeleted").get().isDeleted())
.isEqualTo(true);
}
@Test
@@ -451,12 +310,14 @@ public class DistributionSetManagementTest extends AbstractJpaIntegrationTest {
@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 = 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()));
.createDistributionSet(
entityFactory.distributionSet().create().name("agent-hub2").version("1.0.5")
.type(distributionSetTypeManagement
.createDistributionSetType(entityFactory.distributionSetType().create()
.key("test").name("test").mandatory(Arrays.asList(osType.getId())))
.getKey()));
final SoftwareModule module = softwareManagement.createSoftwareModule(
final SoftwareModule module = softwareModuleManagement.createSoftwareModule(
entityFactory.softwareModule().create().name("agent-hub2").version("1.0.5").type(appType.getKey()));
// update data
@@ -554,7 +415,7 @@ public class DistributionSetManagementTest extends AbstractJpaIntegrationTest {
assignDistributionSet(dsThree.getId(), tFirst.getControllerId());
// set installed
testdataFactory.sendUpdateActionStatusToTargets(Collections.singleton(tSecond), Status.FINISHED,
Lists.newArrayList("some message"));
Arrays.asList("some message"));
assignDistributionSet(dsFour.getId(), tSecond.getControllerId());
@@ -593,19 +454,19 @@ public class DistributionSetManagementTest extends AbstractJpaIntegrationTest {
final DistributionSet dsInComplete = distributionSetManagement.createDistributionSet(entityFactory
.distributionSet().create().name("notcomplete").version("1").type(standardDsType.getKey()));
DistributionSetType newType = distributionSetManagement.createDistributionSetType(
DistributionSetType newType = distributionSetTypeManagement.createDistributionSetType(
entityFactory.distributionSetType().create().key("foo").name("bar").description("test"));
distributionSetManagement.assignMandatorySoftwareModuleTypes(newType.getId(),
Lists.newArrayList(osType.getId()));
newType = distributionSetManagement.assignOptionalSoftwareModuleTypes(newType.getId(),
Lists.newArrayList(appType.getId(), runtimeType.getId()));
distributionSetTypeManagement.assignMandatorySoftwareModuleTypes(newType.getId(),
Arrays.asList(osType.getId()));
newType = distributionSetTypeManagement.assignOptionalSoftwareModuleTypes(newType.getId(),
Arrays.asList(appType.getId(), runtimeType.getId()));
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)));
assignDistributionSet(dsDeleted, testdataFactory.createTargets(5));
distributionSetManagement.deleteDistributionSet(dsDeleted.getId());
dsDeleted = distributionSetManagement.findDistributionSetById(dsDeleted.getId()).get();
@@ -635,13 +496,12 @@ public class DistributionSetManagementTest extends AbstractJpaIntegrationTest {
// search for not deleted
distributionSetFilterBuilder = getDistributionSetFilterBuilder().setIsDeleted(Boolean.TRUE);
assertThat(distributionSetManagement
.findDistributionSetsByFilters(PAGE, distributionSetFilterBuilder.build()).getContent()).hasSize(1);
assertThat(distributionSetManagement.findDistributionSetsByFilters(PAGE, distributionSetFilterBuilder.build())
.getContent()).hasSize(1);
distributionSetFilterBuilder = getDistributionSetFilterBuilder().setIsDeleted(false);
assertThat(distributionSetManagement
.findDistributionSetsByFilters(PAGE, distributionSetFilterBuilder.build()).getContent())
.hasSize(202);
assertThat(distributionSetManagement.findDistributionSetsByFilters(PAGE, distributionSetFilterBuilder.build())
.getContent()).hasSize(202);
// search for completed
expected = new ArrayList<>();
@@ -651,62 +511,51 @@ public class DistributionSetManagementTest extends AbstractJpaIntegrationTest {
expected.add(dsNewType);
distributionSetFilterBuilder = getDistributionSetFilterBuilder().setIsComplete(true);
assertThat(distributionSetManagement
.findDistributionSetsByFilters(PAGE, distributionSetFilterBuilder.build()).getContent()).hasSize(202)
.containsOnly(expected.toArray(new DistributionSet[0]));
assertThat(distributionSetManagement.findDistributionSetsByFilters(PAGE, distributionSetFilterBuilder.build())
.getContent()).hasSize(202).containsOnly(expected.toArray(new DistributionSet[0]));
distributionSetFilterBuilder = getDistributionSetFilterBuilder().setIsComplete(Boolean.FALSE);
expected = new ArrayList<>();
expected.add(dsInComplete);
assertThat(distributionSetManagement
.findDistributionSetsByFilters(PAGE, distributionSetFilterBuilder.build()).getContent()).hasSize(1)
.containsOnly(expected.toArray(new DistributionSet[0]));
assertThat(distributionSetManagement.findDistributionSetsByFilters(PAGE, distributionSetFilterBuilder.build())
.getContent()).hasSize(1).containsOnly(expected.toArray(new DistributionSet[0]));
// search for type
distributionSetFilterBuilder = getDistributionSetFilterBuilder().setType(newType);
assertThat(distributionSetManagement
.findDistributionSetsByFilters(PAGE, distributionSetFilterBuilder.build()).getContent()).hasSize(1);
assertThat(distributionSetManagement.findDistributionSetsByFilters(PAGE, distributionSetFilterBuilder.build())
.getContent()).hasSize(1);
distributionSetFilterBuilder = getDistributionSetFilterBuilder().setType(standardDsType);
assertThat(distributionSetManagement
.findDistributionSetsByFilters(PAGE, distributionSetFilterBuilder.build()).getContent())
.hasSize(202);
assertThat(distributionSetManagement.findDistributionSetsByFilters(PAGE, distributionSetFilterBuilder.build())
.getContent()).hasSize(202);
// search for text
distributionSetFilterBuilder = getDistributionSetFilterBuilder().setSearchText("%test2");
assertThat(distributionSetManagement
.findDistributionSetsByFilters(PAGE, distributionSetFilterBuilder.build()).getContent())
.hasSize(100);
assertThat(distributionSetManagement.findDistributionSetsByFilters(PAGE, distributionSetFilterBuilder.build())
.getContent()).hasSize(100);
// search for tags
distributionSetFilterBuilder = getDistributionSetFilterBuilder()
.setTagNames(Lists.newArrayList(dsTagA.getName()));
assertThat(distributionSetManagement
.findDistributionSetsByFilters(PAGE, distributionSetFilterBuilder.build()).getContent())
.hasSize(200);
distributionSetFilterBuilder = getDistributionSetFilterBuilder().setTagNames(Arrays.asList(dsTagA.getName()));
assertThat(distributionSetManagement.findDistributionSetsByFilters(PAGE, distributionSetFilterBuilder.build())
.getContent()).hasSize(200);
distributionSetFilterBuilder = getDistributionSetFilterBuilder().setTagNames(Arrays.asList(dsTagB.getName()));
assertThat(distributionSetManagement.findDistributionSetsByFilters(PAGE, distributionSetFilterBuilder.build())
.getContent()).hasSize(100);
distributionSetFilterBuilder = getDistributionSetFilterBuilder()
.setTagNames(Lists.newArrayList(dsTagB.getName()));
assertThat(distributionSetManagement
.findDistributionSetsByFilters(PAGE, distributionSetFilterBuilder.build()).getContent())
.hasSize(100);
.setTagNames(Arrays.asList(dsTagA.getName(), dsTagB.getName()));
assertThat(distributionSetManagement.findDistributionSetsByFilters(PAGE, distributionSetFilterBuilder.build())
.getContent()).hasSize(200);
distributionSetFilterBuilder = getDistributionSetFilterBuilder()
.setTagNames(Lists.newArrayList(dsTagA.getName(), dsTagB.getName()));
assertThat(distributionSetManagement
.findDistributionSetsByFilters(PAGE, distributionSetFilterBuilder.build()).getContent())
.hasSize(200);
.setTagNames(Arrays.asList(dsTagC.getName(), dsTagB.getName()));
assertThat(distributionSetManagement.findDistributionSetsByFilters(PAGE, distributionSetFilterBuilder.build())
.getContent()).hasSize(100);
distributionSetFilterBuilder = getDistributionSetFilterBuilder()
.setTagNames(Lists.newArrayList(dsTagC.getName(), dsTagB.getName()));
assertThat(distributionSetManagement
.findDistributionSetsByFilters(PAGE, distributionSetFilterBuilder.build()).getContent())
.hasSize(100);
distributionSetFilterBuilder = getDistributionSetFilterBuilder()
.setTagNames(Lists.newArrayList(dsTagC.getName()));
assertThat(distributionSetManagement
.findDistributionSetsByFilters(PAGE, distributionSetFilterBuilder.build()).getContent()).hasSize(0);
distributionSetFilterBuilder = getDistributionSetFilterBuilder().setTagNames(Arrays.asList(dsTagC.getName()));
assertThat(distributionSetManagement.findDistributionSetsByFilters(PAGE, distributionSetFilterBuilder.build())
.getContent()).hasSize(0);
// combine deleted and complete
expected = new ArrayList<>();
@@ -716,29 +565,26 @@ public class DistributionSetManagementTest extends AbstractJpaIntegrationTest {
distributionSetFilterBuilder = getDistributionSetFilterBuilder().setIsComplete(Boolean.TRUE)
.setIsDeleted(Boolean.FALSE);
assertThat(distributionSetManagement
.findDistributionSetsByFilters(PAGE, distributionSetFilterBuilder.build()).getContent()).hasSize(201)
.containsOnly(expected.toArray(new DistributionSet[0]));
assertThat(distributionSetManagement.findDistributionSetsByFilters(PAGE, distributionSetFilterBuilder.build())
.getContent()).hasSize(201).containsOnly(expected.toArray(new DistributionSet[0]));
expected = new ArrayList<>();
expected.add(dsInComplete);
distributionSetFilterBuilder = getDistributionSetFilterBuilder().setIsComplete(Boolean.FALSE);
assertThat(distributionSetManagement
.findDistributionSetsByFilters(PAGE, distributionSetFilterBuilder.build()).getContent()).hasSize(1)
.containsOnly(expected.toArray(new DistributionSet[0]));
assertThat(distributionSetManagement.findDistributionSetsByFilters(PAGE, distributionSetFilterBuilder.build())
.getContent()).hasSize(1).containsOnly(expected.toArray(new DistributionSet[0]));
expected = new ArrayList<>();
expected.add(dsDeleted);
distributionSetFilterBuilder = getDistributionSetFilterBuilder().setIsComplete(Boolean.TRUE)
.setIsDeleted(Boolean.TRUE);
assertThat(distributionSetManagement
.findDistributionSetsByFilters(PAGE, distributionSetFilterBuilder.build()).getContent()).hasSize(1)
.containsOnly(expected.toArray(new DistributionSet[0]));
assertThat(distributionSetManagement.findDistributionSetsByFilters(PAGE, distributionSetFilterBuilder.build())
.getContent()).hasSize(1).containsOnly(expected.toArray(new DistributionSet[0]));
distributionSetFilterBuilder = getDistributionSetFilterBuilder().setIsDeleted(Boolean.TRUE)
.setIsComplete(Boolean.FALSE);
assertThat(distributionSetManagement
.findDistributionSetsByFilters(PAGE, distributionSetFilterBuilder.build()).getContent()).hasSize(0);
assertThat(distributionSetManagement.findDistributionSetsByFilters(PAGE, distributionSetFilterBuilder.build())
.getContent()).hasSize(0);
// combine deleted and complete and type
expected = new ArrayList<>();
@@ -746,68 +592,62 @@ public class DistributionSetManagementTest extends AbstractJpaIntegrationTest {
expected.addAll(ds100Group2);
distributionSetFilterBuilder = getDistributionSetFilterBuilder().setIsDeleted(Boolean.FALSE)
.setIsComplete(Boolean.TRUE).setType(standardDsType);
assertThat(distributionSetManagement
.findDistributionSetsByFilters(PAGE, distributionSetFilterBuilder.build()).getContent()).hasSize(200)
.containsOnly(expected.toArray(new DistributionSet[0]));
assertThat(distributionSetManagement.findDistributionSetsByFilters(PAGE, distributionSetFilterBuilder.build())
.getContent()).hasSize(200).containsOnly(expected.toArray(new DistributionSet[0]));
expected = new ArrayList<>();
expected.add(dsDeleted);
distributionSetFilterBuilder = getDistributionSetFilterBuilder().setIsComplete(Boolean.TRUE)
.setType(standardDsType).setIsDeleted(Boolean.TRUE);
assertThat(distributionSetManagement
.findDistributionSetsByFilters(PAGE, distributionSetFilterBuilder.build()).getContent()).hasSize(1)
.containsOnly(expected.toArray(new DistributionSet[0]));
assertThat(distributionSetManagement.findDistributionSetsByFilters(PAGE, distributionSetFilterBuilder.build())
.getContent()).hasSize(1).containsOnly(expected.toArray(new DistributionSet[0]));
distributionSetFilterBuilder = getDistributionSetFilterBuilder().setIsDeleted(Boolean.TRUE)
.setIsComplete(Boolean.FALSE).setType(standardDsType);
assertThat(distributionSetManagement
.findDistributionSetsByFilters(PAGE, distributionSetFilterBuilder.build()).getContent()).hasSize(0);
assertThat(distributionSetManagement.findDistributionSetsByFilters(PAGE, distributionSetFilterBuilder.build())
.getContent()).hasSize(0);
expected = new ArrayList<>();
expected.add(dsNewType);
distributionSetFilterBuilder = getDistributionSetFilterBuilder().setIsComplete(Boolean.TRUE).setType(newType);
assertThat(distributionSetManagement
.findDistributionSetsByFilters(PAGE, distributionSetFilterBuilder.build()).getContent()).hasSize(1)
.containsOnly(expected.toArray(new DistributionSet[0]));
assertThat(distributionSetManagement.findDistributionSetsByFilters(PAGE, distributionSetFilterBuilder.build())
.getContent()).hasSize(1).containsOnly(expected.toArray(new DistributionSet[0]));
// combine deleted and complete and type and text
expected = new ArrayList<>();
expected.addAll(ds100Group2);
distributionSetFilterBuilder = getDistributionSetFilterBuilder().setIsComplete(Boolean.TRUE)
.setType(standardDsType).setSearchText("%test2");
assertThat(distributionSetManagement
.findDistributionSetsByFilters(PAGE, distributionSetFilterBuilder.build()).getContent()).hasSize(100)
.containsOnly(expected.toArray(new DistributionSet[0]));
assertThat(distributionSetManagement.findDistributionSetsByFilters(PAGE, distributionSetFilterBuilder.build())
.getContent()).hasSize(100).containsOnly(expected.toArray(new DistributionSet[0]));
distributionSetFilterBuilder = getDistributionSetFilterBuilder().setIsComplete(Boolean.TRUE)
.setIsDeleted(Boolean.TRUE).setType(standardDsType).setSearchText("%test2");
assertThat(distributionSetManagement
.findDistributionSetsByFilters(PAGE, distributionSetFilterBuilder.build()).getContent()).hasSize(0);
assertThat(distributionSetManagement.findDistributionSetsByFilters(PAGE, distributionSetFilterBuilder.build())
.getContent()).hasSize(0);
distributionSetFilterBuilder = getDistributionSetFilterBuilder().setType(standardDsType).setSearchText("%test2")
.setIsComplete(false).setIsDeleted(false);
assertThat(distributionSetManagement
.findDistributionSetsByFilters(PAGE, distributionSetFilterBuilder.build()).getContent()).hasSize(0);
assertThat(distributionSetManagement.findDistributionSetsByFilters(PAGE, distributionSetFilterBuilder.build())
.getContent()).hasSize(0);
distributionSetFilterBuilder = getDistributionSetFilterBuilder().setType(newType).setSearchText("%test2")
.setIsComplete(Boolean.TRUE).setIsDeleted(false);
assertThat(distributionSetManagement
.findDistributionSetsByFilters(PAGE, distributionSetFilterBuilder.build()).getContent()).hasSize(0);
assertThat(distributionSetManagement.findDistributionSetsByFilters(PAGE, distributionSetFilterBuilder.build())
.getContent()).hasSize(0);
// combine deleted and complete and type and text and tag
expected = new ArrayList<>();
expected.addAll(ds100Group2);
distributionSetFilterBuilder = getDistributionSetFilterBuilder().setIsComplete(true).setType(standardDsType)
.setSearchText("%test2").setTagNames(Lists.newArrayList(dsTagA.getName()));
assertThat(distributionSetManagement
.findDistributionSetsByFilters(PAGE, distributionSetFilterBuilder.build()).getContent()).hasSize(100)
.containsOnly(expected.toArray(new DistributionSet[0]));
.setSearchText("%test2").setTagNames(Arrays.asList(dsTagA.getName()));
assertThat(distributionSetManagement.findDistributionSetsByFilters(PAGE, distributionSetFilterBuilder.build())
.getContent()).hasSize(100).containsOnly(expected.toArray(new DistributionSet[0]));
distributionSetFilterBuilder = getDistributionSetFilterBuilder().setType(standardDsType).setSearchText("%test2")
.setTagNames(Lists.newArrayList(dsTagA.getName())).setIsComplete(Boolean.FALSE)
.setIsDeleted(Boolean.FALSE);
assertThat(distributionSetManagement
.findDistributionSetsByFilters(PAGE, distributionSetFilterBuilder.build()).getContent()).hasSize(0);
.setTagNames(Arrays.asList(dsTagA.getName())).setIsComplete(Boolean.FALSE).setIsDeleted(Boolean.FALSE);
assertThat(distributionSetManagement.findDistributionSetsByFilters(PAGE, distributionSetFilterBuilder.build())
.getContent()).hasSize(0);
}
@@ -891,7 +731,7 @@ public class DistributionSetManagementTest extends AbstractJpaIntegrationTest {
// delete assigned ds
assertThat(distributionSetRepository.findAll()).hasSize(4);
distributionSetManagement
.deleteDistributionSet(Lists.newArrayList(dsToTargetAssigned.getId(), dsToRolloutAssigned.getId()));
.deleteDistributionSet(Arrays.asList(dsToTargetAssigned.getId(), dsToRolloutAssigned.getId()));
// not assigned so not marked as deleted
assertThat(distributionSetRepository.findAll()).hasSize(4);

View File

@@ -0,0 +1,186 @@
/**
* Copyright (c) 2015 Bosch Software Innovations GmbH and others.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*/
package org.eclipse.hawkbit.repository.jpa;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import java.util.Arrays;
import org.eclipse.hawkbit.repository.DistributionSetManagement;
import org.eclipse.hawkbit.repository.event.remote.entity.DistributionSetCreatedEvent;
import org.eclipse.hawkbit.repository.exception.EntityReadOnlyException;
import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSetType;
import org.eclipse.hawkbit.repository.model.DistributionSetType;
import org.eclipse.hawkbit.repository.test.matcher.Expect;
import org.eclipse.hawkbit.repository.test.matcher.ExpectEvents;
import org.junit.Test;
import com.google.common.collect.Sets;
import ru.yandex.qatools.allure.annotations.Description;
import ru.yandex.qatools.allure.annotations.Features;
import ru.yandex.qatools.allure.annotations.Stories;
/**
* {@link DistributionSetManagement} tests.
*
*/
@Features("Component Tests - Repository")
@Stories("DistributionSet Management")
public class DistributionSetTypeManagementTest extends AbstractJpaIntegrationTest {
@Test
@Description("Verifies that management get access react as specfied on calls for non existing entities by means "
+ "of Optional not present.")
@ExpectEvents({ @Expect(type = DistributionSetCreatedEvent.class, count = 0) })
public void nonExistingEntityAccessReturnsNotPresent() {
assertThat(distributionSetTypeManagement.findDistributionSetTypeById(NOT_EXIST_IDL)).isNotPresent();
assertThat(distributionSetTypeManagement.findDistributionSetTypeByKey(NOT_EXIST_ID)).isNotPresent();
assertThat(distributionSetTypeManagement.findDistributionSetTypeByName(NOT_EXIST_ID)).isNotPresent();
}
@Test
@Description("Verifies that management queries react as specfied on calls for non existing entities "
+ " by means of throwing EntityNotFoundException.")
@ExpectEvents({ @Expect(type = DistributionSetCreatedEvent.class, count = 0) })
public void entityQueriesReferringToNotExistingEntitiesThrowsException() {
verifyThrownExceptionBy(() -> distributionSetTypeManagement.assignMandatorySoftwareModuleTypes(NOT_EXIST_IDL,
Arrays.asList(osType.getId())), "DistributionSetType");
verifyThrownExceptionBy(() -> distributionSetTypeManagement.assignMandatorySoftwareModuleTypes(
testdataFactory.findOrCreateDistributionSetType("xxx", "xxx").getId(), Arrays.asList(NOT_EXIST_IDL)),
"SoftwareModuleType");
verifyThrownExceptionBy(() -> distributionSetTypeManagement.assignOptionalSoftwareModuleTypes(1234L,
Arrays.asList(osType.getId())), "DistributionSetType");
verifyThrownExceptionBy(() -> distributionSetTypeManagement.assignOptionalSoftwareModuleTypes(
testdataFactory.findOrCreateDistributionSetType("xxx", "xxx").getId(), Arrays.asList(NOT_EXIST_IDL)),
"SoftwareModuleType");
verifyThrownExceptionBy(() -> distributionSetTypeManagement.countDistributionSetsByType(NOT_EXIST_IDL),
"DistributionSet");
verifyThrownExceptionBy(() -> distributionSetTypeManagement.deleteDistributionSetType(NOT_EXIST_IDL),
"DistributionSetType");
verifyThrownExceptionBy(
() -> distributionSetTypeManagement
.updateDistributionSetType(entityFactory.distributionSetType().update(NOT_EXIST_IDL)),
"DistributionSet");
}
@Test
@Description("Tests the successfull module update of unused distribution set type which is in fact allowed.")
public void updateUnassignedDistributionSetTypeModules() {
final DistributionSetType updatableType = distributionSetTypeManagement.createDistributionSetType(
entityFactory.distributionSetType().create().key("updatableType").name("to be deleted"));
assertThat(distributionSetTypeManagement.findDistributionSetTypeByKey("updatableType").get()
.getMandatoryModuleTypes()).isEmpty();
// add OS
distributionSetTypeManagement.assignMandatorySoftwareModuleTypes(updatableType.getId(),
Sets.newHashSet(osType.getId()));
assertThat(distributionSetTypeManagement.findDistributionSetTypeByKey("updatableType").get()
.getMandatoryModuleTypes()).containsOnly(osType);
// add JVM
distributionSetTypeManagement.assignMandatorySoftwareModuleTypes(updatableType.getId(),
Sets.newHashSet(runtimeType.getId()));
assertThat(distributionSetTypeManagement.findDistributionSetTypeByKey("updatableType").get()
.getMandatoryModuleTypes()).containsOnly(osType, runtimeType);
// remove OS
distributionSetTypeManagement.unassignSoftwareModuleType(updatableType.getId(), osType.getId());
assertThat(distributionSetTypeManagement.findDistributionSetTypeByKey("updatableType").get()
.getMandatoryModuleTypes()).containsOnly(runtimeType);
}
@Test
@Description("Tests the successfull update of used distribution set type meta data which is in fact allowed.")
public void updateAssignedDistributionSetTypeMetaData() {
final DistributionSetType nonUpdatableType = distributionSetTypeManagement
.createDistributionSetType(entityFactory.distributionSetType().create().key("updatableType")
.name("to be deleted").colour("test123"));
assertThat(distributionSetTypeManagement.findDistributionSetTypeByKey("updatableType").get()
.getMandatoryModuleTypes()).isEmpty();
distributionSetManagement.createDistributionSet(entityFactory.distributionSet().create().name("newtypesoft")
.version("1").type(nonUpdatableType.getKey()));
distributionSetTypeManagement.updateDistributionSetType(
entityFactory.distributionSetType().update(nonUpdatableType.getId()).description("a new description"));
assertThat(distributionSetTypeManagement.findDistributionSetTypeByKey("updatableType").get().getDescription())
.isEqualTo("a new description");
assertThat(distributionSetTypeManagement.findDistributionSetTypeByKey("updatableType").get().getColour())
.isEqualTo("test123");
}
@Test
@Description("Tests the unsuccessfull update of used distribution set type (module addition).")
public void addModuleToAssignedDistributionSetTypeFails() {
final DistributionSetType nonUpdatableType = distributionSetTypeManagement.createDistributionSetType(
entityFactory.distributionSetType().create().key("updatableType").name("to be deleted"));
assertThat(distributionSetTypeManagement.findDistributionSetTypeByKey("updatableType").get()
.getMandatoryModuleTypes()).isEmpty();
distributionSetManagement.createDistributionSet(entityFactory.distributionSet().create().name("newtypesoft")
.version("1").type(nonUpdatableType.getKey()));
assertThatThrownBy(() -> distributionSetTypeManagement
.assignMandatorySoftwareModuleTypes(nonUpdatableType.getId(), Sets.newHashSet(osType.getId())))
.isInstanceOf(EntityReadOnlyException.class);
}
@Test
@Description("Tests the unsuccessfull update of used distribution set type (module removal).")
public void removeModuleToAssignedDistributionSetTypeFails() {
DistributionSetType nonUpdatableType = distributionSetTypeManagement.createDistributionSetType(
entityFactory.distributionSetType().create().key("updatableType").name("to be deleted"));
assertThat(distributionSetTypeManagement.findDistributionSetTypeByKey("updatableType").get()
.getMandatoryModuleTypes()).isEmpty();
nonUpdatableType = distributionSetTypeManagement.assignMandatorySoftwareModuleTypes(nonUpdatableType.getId(),
Sets.newHashSet(osType.getId()));
distributionSetManagement.createDistributionSet(entityFactory.distributionSet().create().name("newtypesoft")
.version("1").type(nonUpdatableType.getKey()));
final Long typeId = nonUpdatableType.getId();
assertThatThrownBy(() -> distributionSetTypeManagement.unassignSoftwareModuleType(typeId, osType.getId()))
.isInstanceOf(EntityReadOnlyException.class);
}
@Test
@Description("Tests the successfull deletion of unused (hard delete) distribution set types.")
public void deleteUnassignedDistributionSetType() {
final JpaDistributionSetType hardDelete = (JpaDistributionSetType) distributionSetTypeManagement
.createDistributionSetType(
entityFactory.distributionSetType().create().key("delete").name("to be deleted"));
assertThat(distributionSetTypeRepository.findAll()).contains(hardDelete);
distributionSetTypeManagement.deleteDistributionSetType(hardDelete.getId());
assertThat(distributionSetTypeRepository.findAll()).doesNotContain(hardDelete);
}
@Test
@Description("Tests the successfull deletion of used (soft delete) distribution set types.")
public void deleteAssignedDistributionSetType() {
final JpaDistributionSetType softDelete = (JpaDistributionSetType) distributionSetTypeManagement
.createDistributionSetType(
entityFactory.distributionSetType().create().key("softdeleted").name("to be deleted"));
assertThat(distributionSetTypeRepository.findAll()).contains(softDelete);
distributionSetManagement.createDistributionSet(
entityFactory.distributionSet().create().name("softdeleted").version("1").type(softDelete.getKey()));
distributionSetTypeManagement.deleteDistributionSetType(softDelete.getId());
assertThat(distributionSetTypeManagement.findDistributionSetTypeByKey("softdeleted").get().isDeleted())
.isEqualTo(true);
}
}

View File

@@ -26,6 +26,7 @@ import org.eclipse.hawkbit.repository.OffsetBasedPageRequest;
import org.eclipse.hawkbit.repository.builder.RolloutCreate;
import org.eclipse.hawkbit.repository.builder.RolloutGroupCreate;
import org.eclipse.hawkbit.repository.event.remote.RolloutDeletedEvent;
import org.eclipse.hawkbit.repository.event.remote.RolloutGroupDeletedEvent;
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;
@@ -69,8 +70,6 @@ import org.springframework.data.domain.Slice;
import org.springframework.data.domain.Sort;
import org.springframework.data.domain.Sort.Direction;
import com.google.common.collect.Lists;
import ru.yandex.qatools.allure.annotations.Description;
import ru.yandex.qatools.allure.annotations.Features;
import ru.yandex.qatools.allure.annotations.Step;
@@ -282,12 +281,12 @@ public class RolloutManagementTest extends AbstractJpaIntegrationTest {
// finish group one by finishing targets and deleting targets
final Slice<JpaAction> runningActionsSlice = actionRepository.findByRolloutIdAndStatus(PAGE,
createdRollout.getId(), Status.RUNNING);
final List<JpaAction> runningActions = Lists.newArrayList(runningActionsSlice.iterator());
final List<JpaAction> runningActions = runningActionsSlice.getContent();
finishAction(runningActions.get(0));
finishAction(runningActions.get(1));
finishAction(runningActions.get(2));
targetManagement.deleteTargets(Lists.newArrayList(runningActions.get(3).getTarget().getId(),
runningActions.get(4).getTarget().getId()));
targetManagement.deleteTargets(
Arrays.asList(runningActions.get(3).getTarget().getId(), runningActions.get(4).getTarget().getId()));
}
@Step("Check the status of the rollout groups, second group should be in running status")
@@ -304,10 +303,10 @@ public class RolloutManagementTest extends AbstractJpaIntegrationTest {
private void finishActionAndDeleteTargetsOfSecondRunningGroup(final Rollout createdRollout) {
final Slice<JpaAction> runningActionsSlice = actionRepository.findByRolloutIdAndStatus(PAGE,
createdRollout.getId(), Status.RUNNING);
final List<JpaAction> runningActions = Lists.newArrayList(runningActionsSlice.iterator());
final List<JpaAction> runningActions = runningActionsSlice.getContent();
finishAction(runningActions.get(0));
targetManagement.deleteTargets(
Lists.newArrayList(runningActions.get(1).getTarget().getId(), runningActions.get(2).getTarget().getId(),
Arrays.asList(runningActions.get(1).getTarget().getId(), runningActions.get(2).getTarget().getId(),
runningActions.get(3).getTarget().getId(), runningActions.get(4).getTarget().getId()));
}
@@ -316,8 +315,8 @@ public class RolloutManagementTest extends AbstractJpaIntegrationTest {
private void deleteAllTargetsFromThirdGroup(final Rollout createdRollout) {
final Slice<JpaAction> runningActionsSlice = actionRepository.findByRolloutIdAndStatus(PAGE,
createdRollout.getId(), Status.SCHEDULED);
final List<JpaAction> runningActions = Lists.newArrayList(runningActionsSlice.iterator());
targetManagement.deleteTargets(Lists.newArrayList(runningActions.get(0).getTarget().getId(),
final List<JpaAction> runningActions = runningActionsSlice.getContent();
targetManagement.deleteTargets(Arrays.asList(runningActions.get(0).getTarget().getId(),
runningActions.get(1).getTarget().getId(), runningActions.get(2).getTarget().getId(),
runningActions.get(3).getTarget().getId(), runningActions.get(4).getTarget().getId()));
}
@@ -1417,6 +1416,7 @@ public class RolloutManagementTest extends AbstractJpaIntegrationTest {
@Expect(type = DistributionSetCreatedEvent.class, count = 1),
@Expect(type = TargetCreatedEvent.class, count = 25), @Expect(type = RolloutUpdatedEvent.class, count = 2),
@Expect(type = RolloutGroupCreatedEvent.class, count = 5),
@Expect(type = RolloutGroupDeletedEvent.class, count = 5),
@Expect(type = SoftwareModuleCreatedEvent.class, count = 3),
@Expect(type = RolloutGroupUpdatedEvent.class, count = 5) })
public void deleteRolloutWhichHasNeverStartedIsHardDeleted() {
@@ -1447,6 +1447,7 @@ public class RolloutManagementTest extends AbstractJpaIntegrationTest {
@Expect(type = TargetCreatedEvent.class, count = 25), @Expect(type = TargetUpdatedEvent.class, count = 2),
@Expect(type = TargetAssignDistributionSetEvent.class, count = 2),
@Expect(type = RolloutGroupCreatedEvent.class, count = 5),
@Expect(type = RolloutGroupDeletedEvent.class, count = 5),
@Expect(type = ActionCreatedEvent.class, count = 10), @Expect(type = ActionUpdatedEvent.class, count = 2),
@Expect(type = RolloutDeletedEvent.class, count = 1) })
public void deleteRolloutWhichHasBeenStartedBeforeIsSoftDeleted() {

View File

@@ -14,20 +14,17 @@ import static org.junit.Assert.fail;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.util.Arrays;
import java.util.Collections;
import java.util.Iterator;
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.event.remote.entity.SoftwareModuleCreatedEvent;
import org.eclipse.hawkbit.repository.exception.EntityAlreadyExistsException;
import org.eclipse.hawkbit.repository.jpa.model.JpaArtifact;
import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSet;
import org.eclipse.hawkbit.repository.jpa.model.JpaSoftwareModuleMetadata;
import org.eclipse.hawkbit.repository.jpa.model.JpaSoftwareModuleType;
import org.eclipse.hawkbit.repository.jpa.model.JpaTarget;
import org.eclipse.hawkbit.repository.model.Action;
import org.eclipse.hawkbit.repository.model.Artifact;
@@ -54,8 +51,8 @@ import ru.yandex.qatools.allure.annotations.Features;
import ru.yandex.qatools.allure.annotations.Stories;
@Features("Component Tests - Repository")
@Stories("Software Management")
public class SoftwareManagementTest extends AbstractJpaIntegrationTest {
@Stories("Software Module Management")
public class SoftwareModuleManagementTest extends AbstractJpaIntegrationTest {
@Test
@Description("Verifies that management get access reacts as specfied on calls for non existing entities by means "
@@ -64,16 +61,13 @@ public class SoftwareManagementTest extends AbstractJpaIntegrationTest {
public void nonExistingEntityAccessReturnsNotPresent() {
final SoftwareModule module = testdataFactory.createSoftwareModuleApp();
assertThat(softwareManagement.findSoftwareModuleById(1234L)).isNotPresent();
assertThat(softwareModuleManagement.findSoftwareModuleById(1234L)).isNotPresent();
assertThat(softwareManagement.findSoftwareModuleTypeById(NOT_EXIST_IDL)).isNotPresent();
assertThat(softwareManagement.findSoftwareModuleTypeByKey(NOT_EXIST_ID)).isNotPresent();
assertThat(softwareManagement.findSoftwareModuleTypeByName(NOT_EXIST_ID)).isNotPresent();
assertThat(
softwareModuleManagement.findSoftwareModuleByNameAndVersion(NOT_EXIST_ID, NOT_EXIST_ID, osType.getId()))
.isNotPresent();
assertThat(softwareManagement.findSoftwareModuleByNameAndVersion(NOT_EXIST_ID, NOT_EXIST_ID, osType.getId()))
.isNotPresent();
assertThat(softwareManagement.findSoftwareModuleMetadata(module.getId(), NOT_EXIST_ID)).isNotPresent();
assertThat(softwareModuleManagement.findSoftwareModuleMetadata(module.getId(), NOT_EXIST_ID)).isNotPresent();
}
@Test
@@ -84,87 +78,53 @@ public class SoftwareManagementTest extends AbstractJpaIntegrationTest {
final SoftwareModule module = testdataFactory.createSoftwareModuleApp();
verifyThrownExceptionBy(
() -> softwareManagement.createSoftwareModule(
Lists.newArrayList(entityFactory.softwareModule().create().name("xxx").type(NOT_EXIST_ID))),
() -> softwareModuleManagement.createSoftwareModule(
Arrays.asList(entityFactory.softwareModule().create().name("xxx").type(NOT_EXIST_ID))),
"SoftwareModuleType");
verifyThrownExceptionBy(
() -> softwareManagement
() -> softwareModuleManagement
.createSoftwareModule(entityFactory.softwareModule().create().name("xxx").type(NOT_EXIST_ID)),
"SoftwareModuleType");
verifyThrownExceptionBy(() -> softwareManagement.createSoftwareModuleMetadata(NOT_EXIST_IDL,
verifyThrownExceptionBy(() -> softwareModuleManagement.createSoftwareModuleMetadata(NOT_EXIST_IDL,
entityFactory.generateMetadata("xxx", "xxx")), "SoftwareModule");
verifyThrownExceptionBy(() -> softwareManagement.createSoftwareModuleMetadata(NOT_EXIST_IDL,
Lists.newArrayList(entityFactory.generateMetadata("xxx", "xxx"))), "SoftwareModule");
verifyThrownExceptionBy(() -> softwareModuleManagement.createSoftwareModuleMetadata(NOT_EXIST_IDL,
Arrays.asList(entityFactory.generateMetadata("xxx", "xxx"))), "SoftwareModule");
verifyThrownExceptionBy(() -> softwareManagement.deleteSoftwareModule(NOT_EXIST_IDL), "SoftwareModule");
verifyThrownExceptionBy(() -> softwareManagement.deleteSoftwareModules(Lists.newArrayList(NOT_EXIST_IDL)),
verifyThrownExceptionBy(() -> softwareModuleManagement.deleteSoftwareModule(NOT_EXIST_IDL), "SoftwareModule");
verifyThrownExceptionBy(() -> softwareModuleManagement.deleteSoftwareModules(Arrays.asList(NOT_EXIST_IDL)),
"SoftwareModule");
verifyThrownExceptionBy(() -> softwareManagement.deleteSoftwareModuleMetadata(NOT_EXIST_IDL, "xxx"),
verifyThrownExceptionBy(() -> softwareModuleManagement.deleteSoftwareModuleMetadata(NOT_EXIST_IDL, "xxx"),
"SoftwareModule");
verifyThrownExceptionBy(() -> softwareManagement.deleteSoftwareModuleMetadata(module.getId(), NOT_EXIST_ID),
verifyThrownExceptionBy(
() -> softwareModuleManagement.deleteSoftwareModuleMetadata(module.getId(), NOT_EXIST_ID),
"SoftwareModuleMetadata");
verifyThrownExceptionBy(() -> softwareManagement.updateSoftwareModuleMetadata(NOT_EXIST_IDL,
verifyThrownExceptionBy(() -> softwareModuleManagement.updateSoftwareModuleMetadata(NOT_EXIST_IDL,
entityFactory.generateMetadata("xxx", "xxx")), "SoftwareModule");
verifyThrownExceptionBy(() -> softwareManagement.updateSoftwareModuleMetadata(module.getId(),
verifyThrownExceptionBy(() -> softwareModuleManagement.updateSoftwareModuleMetadata(module.getId(),
entityFactory.generateMetadata(NOT_EXIST_ID, "xxx")), "SoftwareModuleMetadata");
verifyThrownExceptionBy(() -> softwareManagement.deleteSoftwareModuleType(NOT_EXIST_IDL), "SoftwareModuleType");
verifyThrownExceptionBy(() -> softwareManagement.findSoftwareModuleByAssignedTo(PAGE, NOT_EXIST_IDL),
verifyThrownExceptionBy(() -> softwareModuleManagement.findSoftwareModuleByAssignedTo(PAGE, NOT_EXIST_IDL),
"DistributionSet");
verifyThrownExceptionBy(
() -> softwareManagement.findSoftwareModuleByNameAndVersion("xxx", "xxx", NOT_EXIST_IDL),
() -> softwareModuleManagement.findSoftwareModuleByNameAndVersion("xxx", "xxx", NOT_EXIST_IDL),
"SoftwareModuleType");
verifyThrownExceptionBy(() -> softwareManagement.findSoftwareModuleMetadata(NOT_EXIST_IDL, NOT_EXIST_ID),
verifyThrownExceptionBy(() -> softwareModuleManagement.findSoftwareModuleMetadata(NOT_EXIST_IDL, NOT_EXIST_ID),
"SoftwareModule");
verifyThrownExceptionBy(
() -> softwareManagement.findSoftwareModuleMetadataBySoftwareModuleId(PAGE, NOT_EXIST_IDL),
() -> softwareModuleManagement.findSoftwareModuleMetadataBySoftwareModuleId(PAGE, NOT_EXIST_IDL),
"SoftwareModule");
verifyThrownExceptionBy(() -> softwareManagement.findSoftwareModuleMetadataBySoftwareModuleId(NOT_EXIST_IDL,
"name==*", PAGE), "SoftwareModule");
verifyThrownExceptionBy(() -> softwareManagement.findSoftwareModulesByType(PAGE, NOT_EXIST_IDL),
verifyThrownExceptionBy(() -> softwareModuleManagement
.findSoftwareModuleMetadataBySoftwareModuleId(NOT_EXIST_IDL, "name==*", PAGE), "SoftwareModule");
verifyThrownExceptionBy(() -> softwareModuleManagement.findSoftwareModulesByType(PAGE, NOT_EXIST_IDL),
"SoftwareModule");
verifyThrownExceptionBy(
() -> softwareManagement.updateSoftwareModule(entityFactory.softwareModule().update(NOT_EXIST_IDL)),
"SoftwareModule");
verifyThrownExceptionBy(
() -> softwareManagement.updateSoftwareModuleType(entityFactory.softwareModuleType().update(1234L)),
"SoftwareModuleType");
}
@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(
entityFactory.softwareModuleType().create().key("test-key").name("test-name"));
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")
.isEqualTo(created.getOptLockRevision());
}
@Test
@Description("Calling update for changed fields results in change in the repository.")
public void updateSoftareModuleTypeFieldsToNewValue() {
final SoftwareModuleType created = softwareManagement.createSoftwareModuleType(
entityFactory.softwareModuleType().create().key("test-key").name("test-name"));
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);
assertThat(updated.getDescription()).as("Updated description is").isEqualTo("changed");
assertThat(updated.getColour()).as("Updated vendor is").isEqualTo("changed");
verifyThrownExceptionBy(() -> softwareModuleManagement
.updateSoftwareModule(entityFactory.softwareModule().update(NOT_EXIST_IDL)), "SoftwareModule");
}
@Test
@@ -172,7 +132,7 @@ public class SoftwareManagementTest extends AbstractJpaIntegrationTest {
public void updateNothingResultsInUnchangedRepository() {
final SoftwareModule ah = testdataFactory.createSoftwareModuleOs();
final SoftwareModule updated = softwareManagement
final SoftwareModule updated = softwareModuleManagement
.updateSoftwareModule(entityFactory.softwareModule().update(ah.getId()));
assertThat(updated.getOptLockRevision())
@@ -185,7 +145,7 @@ public class SoftwareManagementTest extends AbstractJpaIntegrationTest {
public void updateSoftareModuleFieldsToNewValue() {
final SoftwareModule ah = testdataFactory.createSoftwareModuleOs();
final SoftwareModule updated = softwareManagement.updateSoftwareModule(
final SoftwareModule updated = softwareModuleManagement.updateSoftwareModule(
entityFactory.softwareModule().update(ah.getId()).description("changed").vendor("changed"));
assertThat(updated.getOptLockRevision()).as("Expected version number of updated entitity is")
@@ -206,66 +166,52 @@ public class SoftwareManagementTest extends AbstractJpaIntegrationTest {
}
}
@Test
@Description("Create Software Module Types call fails when called for existing entities.")
public void createModuleTypesCallFailsForExistingTypes() {
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.");
} catch (final EntityAlreadyExistsException e) {
}
}
@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(
final SoftwareModule ah = softwareModuleManagement.createSoftwareModule(
entityFactory.softwareModule().create().type(appType).name("agent-hub").version("1.0.1"));
final SoftwareModule jvm = softwareManagement.createSoftwareModule(
final SoftwareModule jvm = softwareModuleManagement.createSoftwareModule(
entityFactory.softwareModule().create().type(runtimeType).name("oracle-jre").version("1.7.2"));
final SoftwareModule os = softwareManagement.createSoftwareModule(
final SoftwareModule os = softwareModuleManagement.createSoftwareModule(
entityFactory.softwareModule().create().type(osType).name("poky").version("3.0.2"));
final SoftwareModule ah2 = softwareManagement.createSoftwareModule(
final SoftwareModule ah2 = softwareModuleManagement.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())));
.type(standardDsType).modules(Arrays.asList(os.getId(), jvm.getId(), ah2.getId())));
final JpaTarget target = (JpaTarget) testdataFactory.createTarget();
ds = (JpaDistributionSet) assignSet(target, ds).getDistributionSet();
// standard searches
assertThat(softwareManagement.findSoftwareModuleByFilters(PAGE, "poky", osType.getId()).getContent())
.hasSize(1);
assertThat(softwareManagement.findSoftwareModuleByFilters(PAGE, "poky", osType.getId()).getContent().get(0))
.isEqualTo(os);
assertThat(softwareManagement.findSoftwareModuleByFilters(PAGE, "oracle%", runtimeType.getId()).getContent())
.hasSize(1);
assertThat(softwareManagement.findSoftwareModuleByFilters(PAGE, "oracle%", runtimeType.getId()).getContent()
.get(0)).isEqualTo(jvm);
assertThat(softwareManagement.findSoftwareModuleByFilters(PAGE, "1.0.1", appType.getId()).getContent())
assertThat(softwareModuleManagement.findSoftwareModuleByFilters(PAGE, "poky", osType.getId()).getContent())
.hasSize(1);
assertThat(
softwareManagement.findSoftwareModuleByFilters(PAGE, "1.0.1", appType.getId()).getContent().get(0))
.isEqualTo(ah);
assertThat(softwareManagement.findSoftwareModuleByFilters(PAGE, "1.0%", appType.getId()).getContent())
softwareModuleManagement.findSoftwareModuleByFilters(PAGE, "poky", osType.getId()).getContent().get(0))
.isEqualTo(os);
assertThat(
softwareModuleManagement.findSoftwareModuleByFilters(PAGE, "oracle%", runtimeType.getId()).getContent())
.hasSize(1);
assertThat(softwareModuleManagement.findSoftwareModuleByFilters(PAGE, "oracle%", runtimeType.getId())
.getContent().get(0)).isEqualTo(jvm);
assertThat(softwareModuleManagement.findSoftwareModuleByFilters(PAGE, "1.0.1", appType.getId()).getContent())
.hasSize(1);
assertThat(softwareModuleManagement.findSoftwareModuleByFilters(PAGE, "1.0.1", appType.getId()).getContent()
.get(0)).isEqualTo(ah);
assertThat(softwareModuleManagement.findSoftwareModuleByFilters(PAGE, "1.0%", appType.getId()).getContent())
.hasSize(2);
// no we search with on entity marked as deleted
softwareManagement.deleteSoftwareModule(
softwareModuleManagement.deleteSoftwareModule(
softwareModuleRepository.findByAssignedToAndType(PAGE, ds, appType).getContent().get(0).getId());
assertThat(softwareManagement.findSoftwareModuleByFilters(PAGE, "1.0%", appType.getId()).getContent())
assertThat(softwareModuleManagement.findSoftwareModuleByFilters(PAGE, "1.0%", appType.getId()).getContent())
.hasSize(1);
assertThat(softwareManagement.findSoftwareModuleByFilters(PAGE, "1.0%", appType.getId()).getContent().get(0))
.isEqualTo(ah);
assertThat(
softwareModuleManagement.findSoftwareModuleByFilters(PAGE, "1.0%", appType.getId()).getContent().get(0))
.isEqualTo(ah);
}
private Action assignSet(final JpaTarget target, final JpaDistributionSet ds) {
@@ -282,10 +228,10 @@ public class SoftwareManagementTest extends AbstractJpaIntegrationTest {
@Description("Searches for software modules based on a list of IDs.")
public void findSoftwareModulesById() {
final List<Long> modules = Lists.newArrayList(testdataFactory.createSoftwareModuleOs().getId(),
final List<Long> modules = Arrays.asList(testdataFactory.createSoftwareModuleOs().getId(),
testdataFactory.createSoftwareModuleApp().getId(), 624355263L);
assertThat(softwareManagement.findSoftwareModulesById(modules)).hasSize(2);
assertThat(softwareModuleManagement.findSoftwareModulesById(modules)).hasSize(2);
}
@Test
@@ -295,10 +241,10 @@ public class SoftwareManagementTest extends AbstractJpaIntegrationTest {
final SoftwareModule one = testdataFactory.createSoftwareModuleOs("one");
final SoftwareModule two = testdataFactory.createSoftwareModuleOs("two");
// ignored
softwareManagement.deleteSoftwareModule(testdataFactory.createSoftwareModuleOs("deleted").getId());
softwareModuleManagement.deleteSoftwareModule(testdataFactory.createSoftwareModuleOs("deleted").getId());
testdataFactory.createSoftwareModuleApp();
assertThat(softwareManagement.findSoftwareModulesByType(PAGE, osType.getId()).getContent())
assertThat(softwareModuleManagement.findSoftwareModulesByType(PAGE, osType.getId()).getContent())
.as("Expected to find the following number of modules:").hasSize(2).as("with the following elements")
.contains(two, one);
}
@@ -311,48 +257,10 @@ public class SoftwareManagementTest extends AbstractJpaIntegrationTest {
final SoftwareModule two = testdataFactory.createSoftwareModuleOs("two");
final SoftwareModule deleted = testdataFactory.createSoftwareModuleOs("deleted");
// ignored
softwareManagement.deleteSoftwareModule(deleted.getId());
softwareModuleManagement.deleteSoftwareModule(deleted.getId());
assertThat(softwareManagement.countSoftwareModulesAll()).as("Expected to find the following number of modules:")
.isEqualTo(2);
}
@Test
@Description("Tests the successfull deletion of software module types. Both unused (hard delete) and used ones (soft delete).")
public void deleteAssignedAndUnassignedSoftwareModuleTypes() {
assertThat(softwareManagement.findSoftwareModuleTypesAll(PAGE)).hasSize(3).contains(osType, runtimeType,
appType);
SoftwareModuleType type = softwareManagement.createSoftwareModuleType(
entityFactory.softwareModuleType().create().key("bundle").name("OSGi Bundle"));
assertThat(softwareManagement.findSoftwareModuleTypesAll(PAGE)).hasSize(4).contains(osType, runtimeType,
appType, type);
// delete unassigned
softwareManagement.deleteSoftwareModuleType(type.getId());
assertThat(softwareManagement.findSoftwareModuleTypesAll(PAGE)).hasSize(3).contains(osType, runtimeType,
appType);
assertThat(softwareModuleTypeRepository.findAll()).hasSize(3).contains((JpaSoftwareModuleType) osType,
(JpaSoftwareModuleType) runtimeType, (JpaSoftwareModuleType) appType);
type = softwareManagement.createSoftwareModuleType(
entityFactory.softwareModuleType().create().key("bundle2").name("OSGi Bundle2"));
assertThat(softwareManagement.findSoftwareModuleTypesAll(PAGE)).hasSize(4).contains(osType, runtimeType,
appType, type);
softwareManagement.createSoftwareModule(
entityFactory.softwareModule().create().type(type).name("Test SM").version("1.0"));
// delete assigned
softwareManagement.deleteSoftwareModuleType(type.getId());
assertThat(softwareManagement.findSoftwareModuleTypesAll(PAGE)).hasSize(3).contains(osType, runtimeType,
appType);
assertThat(softwareModuleTypeRepository.findAll()).hasSize(4).contains((JpaSoftwareModuleType) osType,
(JpaSoftwareModuleType) runtimeType, (JpaSoftwareModuleType) appType,
softwareModuleTypeRepository.findOne(type.getId()));
assertThat(softwareModuleManagement.countSoftwareModulesAll())
.as("Expected to find the following number of modules:").isEqualTo(2);
}
@Test
@@ -366,12 +274,12 @@ public class SoftwareManagementTest extends AbstractJpaIntegrationTest {
final Artifact artifact2 = artifactsIt.next();
// [STEP2]: Delete unassigned SoftwareModule
softwareManagement.deleteSoftwareModule(unassignedModule.getId());
softwareModuleManagement.deleteSoftwareModule(unassignedModule.getId());
// [VERIFY EXPECTED RESULT]:
// verify: SoftwareModule is deleted
assertThat(softwareModuleRepository.findAll()).hasSize(0);
assertThat(softwareManagement.findSoftwareModuleById(unassignedModule.getId())).isNotPresent();
assertThat(softwareModuleManagement.findSoftwareModuleById(unassignedModule.getId())).isNotPresent();
// verify: binary data of artifact is deleted
assertArtfiactNull(artifact1, artifact2);
@@ -392,13 +300,13 @@ public class SoftwareManagementTest extends AbstractJpaIntegrationTest {
testdataFactory.createDistributionSet(Sets.newHashSet(assignedModule));
// [STEP3]: Delete the assigned SoftwareModule
softwareManagement.deleteSoftwareModule(assignedModule.getId());
softwareModuleManagement.deleteSoftwareModule(assignedModule.getId());
// [VERIFY EXPECTED RESULT]:
// verify: assignedModule is marked as deleted
assignedModule = softwareManagement.findSoftwareModuleById(assignedModule.getId()).get();
assignedModule = softwareModuleManagement.findSoftwareModuleById(assignedModule.getId()).get();
assertTrue("The module should be flagged as deleted", assignedModule.isDeleted());
assertThat(softwareManagement.findSoftwareModulesAll(PAGE)).hasSize(0);
assertThat(softwareModuleManagement.findSoftwareModulesAll(PAGE)).hasSize(0);
assertThat(softwareModuleRepository.findAll()).hasSize(1);
// verify: binary data is deleted
@@ -426,19 +334,19 @@ public class SoftwareManagementTest extends AbstractJpaIntegrationTest {
final DistributionSet disSet = testdataFactory.createDistributionSet(Sets.newHashSet(assignedModule));
// [STEP3]: Assign DistributionSet to a Device
assignDistributionSet(disSet, Lists.newArrayList(target));
assignDistributionSet(disSet, Arrays.asList(target));
// [STEP4]: Delete the DistributionSet
distributionSetManagement.deleteDistributionSet(disSet.getId());
// [STEP5]: Delete the assigned SoftwareModule
softwareManagement.deleteSoftwareModule(assignedModule.getId());
softwareModuleManagement.deleteSoftwareModule(assignedModule.getId());
// [VERIFY EXPECTED RESULT]:
// verify: assignedModule is marked as deleted
assignedModule = softwareManagement.findSoftwareModuleById(assignedModule.getId()).get();
assignedModule = softwareModuleManagement.findSoftwareModuleById(assignedModule.getId()).get();
assertTrue("The found module should be flagged deleted", assignedModule.isDeleted());
assertThat(softwareManagement.findSoftwareModulesAll(PAGE)).hasSize(0);
assertThat(softwareModuleManagement.findSoftwareModulesAll(PAGE)).hasSize(0);
assertThat(softwareModuleRepository.findAll()).hasSize(1);
// verify: binary data is deleted
@@ -464,7 +372,7 @@ public class SoftwareManagementTest extends AbstractJpaIntegrationTest {
// [STEP2]: Create newArtifactX and add it to SoftwareModuleX
artifactManagement.createArtifact(new ByteArrayInputStream(source), moduleX.getId(), "artifactx", false);
moduleX = softwareManagement.findSoftwareModuleById(moduleX.getId()).get();
moduleX = softwareModuleManagement.findSoftwareModuleById(moduleX.getId()).get();
final Artifact artifactX = moduleX.getArtifacts().iterator().next();
// [STEP3]: Create SoftwareModuleY and add the same ArtifactX
@@ -472,17 +380,17 @@ public class SoftwareManagementTest extends AbstractJpaIntegrationTest {
// [STEP4]: Assign the same ArtifactX to SoftwareModuleY
artifactManagement.createArtifact(new ByteArrayInputStream(source), moduleY.getId(), "artifactx", false);
moduleY = softwareManagement.findSoftwareModuleById(moduleY.getId()).get();
moduleY = softwareModuleManagement.findSoftwareModuleById(moduleY.getId()).get();
final Artifact artifactY = moduleY.getArtifacts().iterator().next();
// [STEP5]: Delete SoftwareModuleX
softwareManagement.deleteSoftwareModule(moduleX.getId());
softwareModuleManagement.deleteSoftwareModule(moduleX.getId());
// [VERIFY EXPECTED RESULT]:
// verify: SoftwareModuleX is deleted, and ModuelY still exists
assertThat(softwareModuleRepository.findAll()).hasSize(1);
assertThat(softwareManagement.findSoftwareModuleById(moduleX.getId())).isNotPresent();
assertThat(softwareManagement.findSoftwareModuleById(moduleY.getId())).isPresent();
assertThat(softwareModuleManagement.findSoftwareModuleById(moduleX.getId())).isNotPresent();
assertThat(softwareModuleManagement.findSoftwareModuleById(moduleY.getId())).isPresent();
// verify: binary data of artifact is not deleted
assertArtfiactNotNull(artifactY);
@@ -506,40 +414,40 @@ public class SoftwareManagementTest extends AbstractJpaIntegrationTest {
SoftwareModule moduleX = createSoftwareModuleWithArtifacts(osType, "modulex", "v1.0", 0);
artifactManagement.createArtifact(new ByteArrayInputStream(source), moduleX.getId(), "artifactx", false);
moduleX = softwareManagement.findSoftwareModuleById(moduleX.getId()).get();
moduleX = softwareModuleManagement.findSoftwareModuleById(moduleX.getId()).get();
final Artifact artifactX = moduleX.getArtifacts().iterator().next();
// [STEP2]: Create SoftwareModuleY and add the same ArtifactX
SoftwareModule moduleY = createSoftwareModuleWithArtifacts(osType, "moduley", "v1.0", 0);
artifactManagement.createArtifact(new ByteArrayInputStream(source), moduleY.getId(), "artifactx", false);
moduleY = softwareManagement.findSoftwareModuleById(moduleY.getId()).get();
moduleY = softwareModuleManagement.findSoftwareModuleById(moduleY.getId()).get();
final Artifact artifactY = moduleY.getArtifacts().iterator().next();
// [STEP3]: Assign SoftwareModuleX to DistributionSetX and to target
final DistributionSet disSetX = testdataFactory.createDistributionSet(Sets.newHashSet(moduleX), "X");
assignDistributionSet(disSetX, Lists.newArrayList(target));
assignDistributionSet(disSetX, Arrays.asList(target));
// [STEP4]: Assign SoftwareModuleY to DistributionSet and to target
final DistributionSet disSetY = testdataFactory.createDistributionSet(Sets.newHashSet(moduleY), "Y");
assignDistributionSet(disSetY, Lists.newArrayList(target));
assignDistributionSet(disSetY, Arrays.asList(target));
// [STEP5]: Delete SoftwareModuleX
softwareManagement.deleteSoftwareModule(moduleX.getId());
softwareModuleManagement.deleteSoftwareModule(moduleX.getId());
// [STEP6]: Delete SoftwareModuleY
softwareManagement.deleteSoftwareModule(moduleY.getId());
softwareModuleManagement.deleteSoftwareModule(moduleY.getId());
// [VERIFY EXPECTED RESULT]:
moduleX = softwareManagement.findSoftwareModuleById(moduleX.getId()).get();
moduleY = softwareManagement.findSoftwareModuleById(moduleY.getId()).get();
moduleX = softwareModuleManagement.findSoftwareModuleById(moduleX.getId()).get();
moduleY = softwareModuleManagement.findSoftwareModuleById(moduleY.getId()).get();
// verify: SoftwareModuleX and SofwtareModule are marked as deleted
assertThat(moduleX).isNotNull();
assertThat(moduleY).isNotNull();
assertTrue("The module should be flagged deleted", moduleX.isDeleted());
assertTrue("The module should be flagged deleted", moduleY.isDeleted());
assertThat(softwareManagement.findSoftwareModulesAll(PAGE)).hasSize(0);
assertThat(softwareModuleManagement.findSoftwareModulesAll(PAGE)).hasSize(0);
assertThat(softwareModuleRepository.findAll()).hasSize(2);
// verify: binary data of artifact is deleted
@@ -555,8 +463,8 @@ public class SoftwareManagementTest extends AbstractJpaIntegrationTest {
final long countSoftwareModule = softwareModuleRepository.count();
// create SoftwareModule
SoftwareModule softwareModule = softwareManagement.createSoftwareModule(entityFactory.softwareModule().create()
.type(type).name(name).version(version).description("description of artifact " + name));
SoftwareModule softwareModule = softwareModuleManagement.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(),
@@ -564,7 +472,7 @@ public class SoftwareManagementTest extends AbstractJpaIntegrationTest {
}
// Verify correct Creation of SoftwareModule and corresponding artifacts
softwareModule = softwareManagement.findSoftwareModuleById(softwareModule.getId()).get();
softwareModule = softwareModuleManagement.findSoftwareModuleById(softwareModule.getId()).get();
assertThat(softwareModuleRepository.findAll()).hasSize((int) countSoftwareModule + 1);
final List<Artifact> artifacts = softwareModule.getArtifacts();
@@ -596,15 +504,15 @@ 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(
final SoftwareModuleType testType = softwareModuleTypeManagement.createSoftwareModuleType(
entityFactory.softwareModuleType().create().key("thetype").name("thename").maxAssignments(100));
DistributionSetType testDsType = distributionSetManagement
DistributionSetType testDsType = distributionSetTypeManagement
.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()));
distributionSetTypeManagement.assignMandatorySoftwareModuleTypes(testDsType.getId(),
Arrays.asList(osType.getId()));
testDsType = distributionSetTypeManagement.assignOptionalSoftwareModuleTypes(testDsType.getId(),
Arrays.asList(testType.getId()));
// found in test
final SoftwareModule unassigned = testdataFactory.createSoftwareModule("thetype", "unassignedfound");
@@ -619,25 +527,26 @@ public class SoftwareManagementTest extends AbstractJpaIntegrationTest {
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());
softwareModuleManagement.deleteSoftwareModule(deleted.getId());
// with filter on name, version and module type
assertThat(softwareManagement.findSoftwareModuleOrderBySetAssignmentAndModuleNameAscModuleVersionAsc(PAGE,
assertThat(softwareModuleManagement.findSoftwareModuleOrderBySetAssignmentAndModuleNameAscModuleVersionAsc(PAGE,
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));
// with filter on module type only
assertThat(softwareManagement.findSoftwareModuleOrderBySetAssignmentAndModuleNameAscModuleVersionAsc(PAGE,
assertThat(softwareModuleManagement.findSoftwareModuleOrderBySetAssignmentAndModuleNameAscModuleVersionAsc(PAGE,
set.getId(), null, testType.getId()).getContent())
.as("Found modules with given module type and the assigned ones first").containsExactly(
new AssignedSoftwareModule(differentName, true), new AssignedSoftwareModule(one, true),
new AssignedSoftwareModule(two, true), new AssignedSoftwareModule(unassigned, false));
// without any filter
assertThat(softwareManagement.findSoftwareModuleOrderBySetAssignmentAndModuleNameAscModuleVersionAsc(PAGE,
set.getId(), null, null).getContent()).as("Found modules with the assigned ones first").containsExactly(
assertThat(softwareModuleManagement
.findSoftwareModuleOrderBySetAssignmentAndModuleNameAscModuleVersionAsc(PAGE, set.getId(), null, null)
.getContent()).as("Found modules with the assigned ones first").containsExactly(
new AssignedSoftwareModule(differentName, true), new AssignedSoftwareModule(one, true),
new AssignedSoftwareModule(two, true), new AssignedSoftwareModule(four, true),
new AssignedSoftwareModule(unassigned, false));
@@ -647,15 +556,15 @@ public class SoftwareManagementTest extends AbstractJpaIntegrationTest {
@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(
final SoftwareModuleType testType = softwareModuleTypeManagement.createSoftwareModuleType(
entityFactory.softwareModuleType().create().key("thetype").name("thename").maxAssignments(100));
DistributionSetType testDsType = distributionSetManagement
DistributionSetType testDsType = distributionSetTypeManagement
.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()));
distributionSetTypeManagement.assignMandatorySoftwareModuleTypes(testDsType.getId(),
Arrays.asList(osType.getId()));
testDsType = distributionSetTypeManagement.assignOptionalSoftwareModuleTypes(testDsType.getId(),
Arrays.asList(testType.getId()));
// found in test
testdataFactory.createSoftwareModule("thetype", "unassignedfound");
@@ -670,14 +579,14 @@ public class SoftwareManagementTest extends AbstractJpaIntegrationTest {
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());
softwareModuleManagement.deleteSoftwareModule(deleted.getId());
// test
assertThat(softwareManagement.countSoftwareModuleByFilters("%found%", testType.getId()))
assertThat(softwareModuleManagement.countSoftwareModuleByFilters("%found%", testType.getId()))
.as("Number of modules with given name or version and type").isEqualTo(3);
assertThat(softwareManagement.countSoftwareModuleByFilters(null, testType.getId()))
assertThat(softwareModuleManagement.countSoftwareModuleByFilters(null, testType.getId()))
.as("Number of modules with given type").isEqualTo(4);
assertThat(softwareManagement.countSoftwareModuleByFilters(null, null)).as("Number of modules overall")
assertThat(softwareModuleManagement.countSoftwareModuleByFilters(null, null)).as("Number of modules overall")
.isEqualTo(5);
}
@@ -688,79 +597,13 @@ public class SoftwareManagementTest extends AbstractJpaIntegrationTest {
// one soft deleted
final SoftwareModule deleted = testdataFactory.createSoftwareModuleApp();
testdataFactory.createDistributionSet(Lists.newArrayList(deleted));
softwareManagement.deleteSoftwareModule(deleted.getId());
testdataFactory.createDistributionSet(Arrays.asList(deleted));
softwareModuleManagement.deleteSoftwareModule(deleted.getId());
assertThat(softwareManagement.countSoftwareModulesAll()).as("Number of undeleted modules").isEqualTo(1);
assertThat(softwareModuleManagement.countSoftwareModulesAll()).as("Number of undeleted modules").isEqualTo(1);
assertThat(softwareModuleRepository.count()).as("Number of all modules").isEqualTo(2);
}
@Test
@Description("Checks that software module typeis found based on given name.")
public void findSoftwareModuleTypeByName() {
testdataFactory.createSoftwareModuleOs();
final SoftwareModuleType found = softwareManagement
.createSoftwareModuleType(entityFactory.softwareModuleType().create().key("thetype").name("thename"));
softwareManagement.createSoftwareModuleType(
entityFactory.softwareModuleType().create().key("thetype2").name("anothername"));
assertThat(softwareManagement.findSoftwareModuleTypeByName("thename").get()).as("Type with given name")
.isEqualTo(found);
}
@Test
@Description("Verfies that it is not possible to create a type that alrady exists.")
public void createSoftwareModuleTypeFailsWithExistingEntity() {
final SoftwareModuleType created = softwareManagement
.createSoftwareModuleType(entityFactory.softwareModuleType().create().key("thetype").name("thename"));
try {
softwareManagement.createSoftwareModuleType(
entityFactory.softwareModuleType().create().key("thetype").name("thename"));
fail("should not have worked as module type already exists");
} catch (final EntityAlreadyExistsException e) {
}
}
@Test
@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(entityFactory.softwareModuleType().create().key("thetype").name("thename"));
try {
softwareManagement.createSoftwareModuleType(
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) {
}
}
@Test
@Description("Verifies that the creation of a softwareModuleType is failing because of invalid max assignment")
public void createSoftwareModuleTypesFailsWithInvalidMaxAssignment() {
try {
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) {
}
}
@Test
@Description("Verfies that multiple types are created as requested.")
public void createMultipleSoftwareModuleTypes() {
final List<SoftwareModuleType> created = softwareManagement.createSoftwareModuleType(
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);
}
@Test
@Description("Verfies that software modules are resturned that are assigned to given DS.")
public void findSoftwareModuleByAssignedTo() {
@@ -771,10 +614,10 @@ public class SoftwareManagementTest extends AbstractJpaIntegrationTest {
// one soft 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());
.create().name("set").version("1").modules(Arrays.asList(one.getId(), deleted.getId())));
softwareModuleManagement.deleteSoftwareModule(deleted.getId());
assertThat(softwareManagement.findSoftwareModuleByAssignedTo(PAGE, set.getId()).getContent())
assertThat(softwareModuleManagement.findSoftwareModuleByAssignedTo(PAGE, set.getId()).getContent())
.as("Found this number of modules").hasSize(2);
}
@@ -796,10 +639,11 @@ public class SoftwareManagementTest extends AbstractJpaIntegrationTest {
final SoftwareModuleMetadata swMetadata2 = new JpaSoftwareModuleMetadata(knownKey2, ah, knownValue2);
final List<SoftwareModuleMetadata> softwareModuleMetadata = softwareManagement
.createSoftwareModuleMetadata(ah.getId(), Lists.newArrayList(swMetadata1, swMetadata2));
final List<SoftwareModuleMetadata> softwareModuleMetadata = softwareModuleManagement
.createSoftwareModuleMetadata(ah.getId(), Arrays.asList(swMetadata1, swMetadata2));
final SoftwareModule changedLockRevisionModule = softwareManagement.findSoftwareModuleById(ah.getId()).get();
final SoftwareModule changedLockRevisionModule = softwareModuleManagement.findSoftwareModuleById(ah.getId())
.get();
assertThat(changedLockRevisionModule.getOptLockRevision()).isEqualTo(2);
assertThat(softwareModuleMetadata).hasSize(2);
@@ -819,11 +663,11 @@ public class SoftwareManagementTest extends AbstractJpaIntegrationTest {
final SoftwareModule ah = testdataFactory.createSoftwareModuleApp();
softwareManagement.createSoftwareModuleMetadata(ah.getId(),
softwareModuleManagement.createSoftwareModuleMetadata(ah.getId(),
entityFactory.generateMetadata(knownKey1, knownValue1));
try {
softwareManagement.createSoftwareModuleMetadata(ah.getId(),
softwareModuleManagement.createSoftwareModuleMetadata(ah.getId(),
entityFactory.generateMetadata(knownKey1, knownValue2));
fail("should not have worked as module metadata already exists");
} catch (final EntityAlreadyExistsException e) {
@@ -845,23 +689,24 @@ public class SoftwareManagementTest extends AbstractJpaIntegrationTest {
assertThat(ah.getOptLockRevision()).isEqualTo(1);
// create an software module meta data entry
final List<SoftwareModuleMetadata> softwareModuleMetadata = softwareManagement.createSoftwareModuleMetadata(
ah.getId(), Collections.singleton(entityFactory.generateMetadata(knownKey, knownValue)));
final List<SoftwareModuleMetadata> softwareModuleMetadata = softwareModuleManagement
.createSoftwareModuleMetadata(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
// base software module
SoftwareModule changedLockRevisionModule = softwareManagement.findSoftwareModuleById(ah.getId()).get();
SoftwareModule changedLockRevisionModule = softwareModuleManagement.findSoftwareModuleById(ah.getId()).get();
assertThat(changedLockRevisionModule.getOptLockRevision()).isEqualTo(2);
// update the software module metadata
Thread.sleep(100);
final SoftwareModuleMetadata updated = softwareManagement.updateSoftwareModuleMetadata(ah.getId(),
final SoftwareModuleMetadata updated = softwareModuleManagement.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
changedLockRevisionModule = softwareManagement.findSoftwareModuleById(ah.getId()).get();
changedLockRevisionModule = softwareModuleManagement.findSoftwareModuleById(ah.getId()).get();
assertThat(changedLockRevisionModule.getOptLockRevision()).isEqualTo(3);
// verify updated meta data contains the updated value
@@ -879,17 +724,19 @@ public class SoftwareManagementTest extends AbstractJpaIntegrationTest {
SoftwareModule ah = testdataFactory.createSoftwareModuleApp();
ah = softwareManagement
ah = softwareModuleManagement
.createSoftwareModuleMetadata(ah.getId(), entityFactory.generateMetadata(knownKey1, knownValue1))
.getSoftwareModule();
assertThat(softwareManagement.findSoftwareModuleMetadataBySoftwareModuleId(new PageRequest(0, 100), ah.getId())
.getContent()).as("Contains the created metadata element")
assertThat(softwareModuleManagement
.findSoftwareModuleMetadataBySoftwareModuleId(new PageRequest(0, 100), ah.getId()).getContent())
.as("Contains the created metadata element")
.containsExactly(new JpaSoftwareModuleMetadata(knownKey1, ah, knownValue1));
softwareManagement.deleteSoftwareModuleMetadata(ah.getId(), knownKey1);
assertThat(softwareManagement.findSoftwareModuleMetadataBySoftwareModuleId(new PageRequest(0, 100), ah.getId())
.getContent()).as("Metadata elemenets are").isEmpty();
softwareModuleManagement.deleteSoftwareModuleMetadata(ah.getId(), knownKey1);
assertThat(softwareModuleManagement
.findSoftwareModuleMetadataBySoftwareModuleId(new PageRequest(0, 100), ah.getId()).getContent())
.as("Metadata elemenets are").isEmpty();
}
@Test
@@ -900,11 +747,11 @@ public class SoftwareManagementTest extends AbstractJpaIntegrationTest {
SoftwareModule ah = testdataFactory.createSoftwareModuleApp();
ah = softwareManagement
ah = softwareModuleManagement
.createSoftwareModuleMetadata(ah.getId(), entityFactory.generateMetadata(knownKey1, knownValue1))
.getSoftwareModule();
assertThat(softwareManagement.findSoftwareModuleMetadata(ah.getId(), "doesnotexist")).isNotPresent();
assertThat(softwareModuleManagement.findSoftwareModuleMetadata(ah.getId(), "doesnotexist")).isNotPresent();
}
@Test
@@ -916,19 +763,19 @@ public class SoftwareManagementTest extends AbstractJpaIntegrationTest {
SoftwareModule sw2 = testdataFactory.createSoftwareModuleOs();
for (int index = 0; index < 10; index++) {
sw1 = softwareManagement.createSoftwareModuleMetadata(sw1.getId(),
sw1 = softwareModuleManagement.createSoftwareModuleMetadata(sw1.getId(),
entityFactory.generateMetadata("key" + index, "value" + index)).getSoftwareModule();
}
for (int index = 0; index < 20; index++) {
sw2 = softwareManagement.createSoftwareModuleMetadata(sw2.getId(),
sw2 = softwareModuleManagement.createSoftwareModuleMetadata(sw2.getId(),
new JpaSoftwareModuleMetadata("key" + index, sw2, "value" + index)).getSoftwareModule();
}
final Page<SoftwareModuleMetadata> metadataOfSw1 = softwareManagement
final Page<SoftwareModuleMetadata> metadataOfSw1 = softwareModuleManagement
.findSoftwareModuleMetadataBySoftwareModuleId(sw1.getId(), new PageRequest(0, 100));
final Page<SoftwareModuleMetadata> metadataOfSw2 = softwareManagement
final Page<SoftwareModuleMetadata> metadataOfSw2 = softwareModuleManagement
.findSoftwareModuleMetadataBySoftwareModuleId(sw2.getId(), new PageRequest(0, 100));
assertThat(metadataOfSw1.getNumberOfElements()).isEqualTo(10);

View File

@@ -0,0 +1,211 @@
/**
* Copyright (c) 2015 Bosch Software Innovations GmbH and others.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*/
package org.eclipse.hawkbit.repository.jpa;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.fail;
import java.util.Arrays;
import java.util.List;
import javax.validation.ConstraintViolationException;
import org.eclipse.hawkbit.repository.builder.SoftwareModuleTypeCreate;
import org.eclipse.hawkbit.repository.event.remote.entity.SoftwareModuleCreatedEvent;
import org.eclipse.hawkbit.repository.exception.EntityAlreadyExistsException;
import org.eclipse.hawkbit.repository.jpa.model.JpaSoftwareModuleType;
import org.eclipse.hawkbit.repository.model.SoftwareModuleType;
import org.eclipse.hawkbit.repository.test.matcher.Expect;
import org.eclipse.hawkbit.repository.test.matcher.ExpectEvents;
import org.junit.Test;
import ru.yandex.qatools.allure.annotations.Description;
import ru.yandex.qatools.allure.annotations.Features;
import ru.yandex.qatools.allure.annotations.Stories;
@Features("Component Tests - Repository")
@Stories("Software Module Management")
public class SoftwareModuleTypeManagementTest extends AbstractJpaIntegrationTest {
@Test
@Description("Verifies that management get access reacts as specfied on calls for non existing entities by means "
+ "of Optional not present.")
@ExpectEvents({ @Expect(type = SoftwareModuleCreatedEvent.class, count = 0) })
public void nonExistingEntityAccessReturnsNotPresent() {
assertThat(softwareModuleTypeManagement.findSoftwareModuleTypeById(NOT_EXIST_IDL)).isNotPresent();
assertThat(softwareModuleTypeManagement.findSoftwareModuleTypeByKey(NOT_EXIST_ID)).isNotPresent();
assertThat(softwareModuleTypeManagement.findSoftwareModuleTypeByName(NOT_EXIST_ID)).isNotPresent();
}
@Test
@Description("Verifies that management queries react as specfied on calls for non existing entities "
+ " by means of throwing EntityNotFoundException.")
@ExpectEvents({ @Expect(type = SoftwareModuleCreatedEvent.class, count = 0) })
public void entityQueriesReferringToNotExistingEntitiesThrowsException() {
verifyThrownExceptionBy(() -> softwareModuleTypeManagement.deleteSoftwareModuleType(NOT_EXIST_IDL),
"SoftwareModuleType");
verifyThrownExceptionBy(
() -> softwareModuleTypeManagement
.updateSoftwareModuleType(entityFactory.softwareModuleType().update(1234L)),
"SoftwareModuleType");
}
@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 = softwareModuleTypeManagement.createSoftwareModuleType(
entityFactory.softwareModuleType().create().key("test-key").name("test-name"));
final SoftwareModuleType updated = softwareModuleTypeManagement
.updateSoftwareModuleType(entityFactory.softwareModuleType().update(created.getId()));
assertThat(updated.getOptLockRevision())
.as("Expected version number of updated entitity to be equal to created version")
.isEqualTo(created.getOptLockRevision());
}
@Test
@Description("Calling update for changed fields results in change in the repository.")
public void updateSoftareModuleTypeFieldsToNewValue() {
final SoftwareModuleType created = softwareModuleTypeManagement.createSoftwareModuleType(
entityFactory.softwareModuleType().create().key("test-key").name("test-name"));
final SoftwareModuleType updated = softwareModuleTypeManagement.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);
assertThat(updated.getDescription()).as("Updated description is").isEqualTo("changed");
assertThat(updated.getColour()).as("Updated vendor is").isEqualTo("changed");
}
@Test
@Description("Create Software Module Types call fails when called for existing entities.")
public void createModuleTypesCallFailsForExistingTypes() {
final List<SoftwareModuleTypeCreate> created = Arrays.asList(
entityFactory.softwareModuleType().create().key("test-key").name("test-name"),
entityFactory.softwareModuleType().create().key("test-key2").name("test-name2"));
softwareModuleTypeManagement.createSoftwareModuleType(created);
try {
softwareModuleTypeManagement.createSoftwareModuleType(created);
fail("Should not have worked as module already exists.");
} catch (final EntityAlreadyExistsException e) {
}
}
@Test
@Description("Tests the successfull deletion of software module types. Both unused (hard delete) and used ones (soft delete).")
public void deleteAssignedAndUnassignedSoftwareModuleTypes() {
assertThat(softwareModuleTypeManagement.findSoftwareModuleTypesAll(PAGE)).hasSize(3).contains(osType,
runtimeType, appType);
SoftwareModuleType type = softwareModuleTypeManagement.createSoftwareModuleType(
entityFactory.softwareModuleType().create().key("bundle").name("OSGi Bundle"));
assertThat(softwareModuleTypeManagement.findSoftwareModuleTypesAll(PAGE)).hasSize(4).contains(osType,
runtimeType, appType, type);
// delete unassigned
softwareModuleTypeManagement.deleteSoftwareModuleType(type.getId());
assertThat(softwareModuleTypeManagement.findSoftwareModuleTypesAll(PAGE)).hasSize(3).contains(osType,
runtimeType, appType);
assertThat(softwareModuleTypeRepository.findAll()).hasSize(3).contains((JpaSoftwareModuleType) osType,
(JpaSoftwareModuleType) runtimeType, (JpaSoftwareModuleType) appType);
type = softwareModuleTypeManagement.createSoftwareModuleType(
entityFactory.softwareModuleType().create().key("bundle2").name("OSGi Bundle2"));
assertThat(softwareModuleTypeManagement.findSoftwareModuleTypesAll(PAGE)).hasSize(4).contains(osType,
runtimeType, appType, type);
softwareModuleManagement.createSoftwareModule(
entityFactory.softwareModule().create().type(type).name("Test SM").version("1.0"));
// delete assigned
softwareModuleTypeManagement.deleteSoftwareModuleType(type.getId());
assertThat(softwareModuleTypeManagement.findSoftwareModuleTypesAll(PAGE)).hasSize(3).contains(osType,
runtimeType, appType);
assertThat(softwareModuleTypeRepository.findAll()).hasSize(4).contains((JpaSoftwareModuleType) osType,
(JpaSoftwareModuleType) runtimeType, (JpaSoftwareModuleType) appType,
softwareModuleTypeRepository.findOne(type.getId()));
}
@Test
@Description("Checks that software module typeis found based on given name.")
public void findSoftwareModuleTypeByName() {
testdataFactory.createSoftwareModuleOs();
final SoftwareModuleType found = softwareModuleTypeManagement
.createSoftwareModuleType(entityFactory.softwareModuleType().create().key("thetype").name("thename"));
softwareModuleTypeManagement.createSoftwareModuleType(
entityFactory.softwareModuleType().create().key("thetype2").name("anothername"));
assertThat(softwareModuleTypeManagement.findSoftwareModuleTypeByName("thename").get())
.as("Type with given name").isEqualTo(found);
}
@Test
@Description("Verfies that it is not possible to create a type that alrady exists.")
public void createSoftwareModuleTypeFailsWithExistingEntity() {
softwareModuleTypeManagement
.createSoftwareModuleType(entityFactory.softwareModuleType().create().key("thetype").name("thename"));
try {
softwareModuleTypeManagement.createSoftwareModuleType(
entityFactory.softwareModuleType().create().key("thetype").name("thename"));
fail("should not have worked as module type already exists");
} catch (final EntityAlreadyExistsException e) {
}
}
@Test
@Description("Verfies that it is not possible to create a list of types where one already exists.")
public void createSoftwareModuleTypesFailsWithExistingEntity() {
softwareModuleTypeManagement
.createSoftwareModuleType(entityFactory.softwareModuleType().create().key("thetype").name("thename"));
try {
softwareModuleTypeManagement.createSoftwareModuleType(
Arrays.asList(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) {
}
}
@Test
@Description("Verifies that the creation of a softwareModuleType is failing because of invalid max assignment")
public void createSoftwareModuleTypesFailsWithInvalidMaxAssignment() {
try {
softwareModuleTypeManagement.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) {
}
}
@Test
@Description("Verfies that multiple types are created as requested.")
public void createMultipleSoftwareModuleTypes() {
final List<SoftwareModuleType> created = softwareModuleTypeManagement.createSoftwareModuleType(
Arrays.asList(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(softwareModuleTypeManagement.countSoftwareModuleTypesAll()).as("Number of types in repository")
.isEqualTo(5);
}
}

View File

@@ -140,7 +140,7 @@ public class SystemManagementTest extends AbstractJpaIntegrationTest {
final DistributionSet ds = testdataFactory.createDistributionSet("deleted garbage", true);
ds.getModules().stream().forEach(module -> {
artifactManagement.createArtifact(new ByteArrayInputStream(random), module.getId(), "file1", false);
softwareManagement.deleteSoftwareModule(module.getId());
softwareModuleManagement.deleteSoftwareModule(module.getId());
});
}

View File

@@ -36,8 +36,6 @@ import org.eclipse.hawkbit.repository.test.matcher.Expect;
import org.eclipse.hawkbit.repository.test.matcher.ExpectEvents;
import org.junit.Test;
import com.google.common.collect.Lists;
import ru.yandex.qatools.allure.annotations.Description;
import ru.yandex.qatools.allure.annotations.Features;
import ru.yandex.qatools.allure.annotations.Stories;
@@ -119,7 +117,7 @@ public class TagManagementTest extends AbstractJpaIntegrationTest {
// search for not deleted
distributionSetFilterBuilder = getDistributionSetFilterBuilder().setIsComplete(true)
.setTagNames(Lists.newArrayList(tagA.getName()));
.setTagNames(Arrays.asList(tagA.getName()));
assertEquals("filter works not correct",
dsAs.spliterator().getExactSizeIfKnown() + dsABs.spliterator().getExactSizeIfKnown()
+ dsACs.spliterator().getExactSizeIfKnown() + dsABCs.spliterator().getExactSizeIfKnown(),
@@ -127,7 +125,7 @@ public class TagManagementTest extends AbstractJpaIntegrationTest {
.getTotalElements());
distributionSetFilterBuilder = getDistributionSetFilterBuilder().setIsComplete(true)
.setTagNames(Lists.newArrayList(tagB.getName()));
.setTagNames(Arrays.asList(tagB.getName()));
assertEquals("filter works not correct",
dsBs.spliterator().getExactSizeIfKnown() + dsABs.spliterator().getExactSizeIfKnown()
+ dsBCs.spliterator().getExactSizeIfKnown() + dsABCs.spliterator().getExactSizeIfKnown(),
@@ -135,7 +133,7 @@ public class TagManagementTest extends AbstractJpaIntegrationTest {
.getTotalElements());
distributionSetFilterBuilder = getDistributionSetFilterBuilder().setIsComplete(true)
.setTagNames(Lists.newArrayList(tagC.getName()));
.setTagNames(Arrays.asList(tagC.getName()));
assertEquals("filter works not correct",
dsCs.spliterator().getExactSizeIfKnown() + dsACs.spliterator().getExactSizeIfKnown()
+ dsBCs.spliterator().getExactSizeIfKnown() + dsABCs.spliterator().getExactSizeIfKnown(),
@@ -143,7 +141,7 @@ public class TagManagementTest extends AbstractJpaIntegrationTest {
.getTotalElements());
distributionSetFilterBuilder = getDistributionSetFilterBuilder().setIsComplete(true)
.setTagNames(Lists.newArrayList(tagX.getName()));
.setTagNames(Arrays.asList(tagX.getName()));
assertEquals("filter works not correct", 0, distributionSetManagement
.findDistributionSetsByFilters(PAGE, distributionSetFilterBuilder.build()).getTotalElements());
@@ -158,7 +156,7 @@ public class TagManagementTest extends AbstractJpaIntegrationTest {
assertEquals("wrong tag size", 2, distributionSetTagRepository.findAll().spliterator().getExactSizeIfKnown());
distributionSetFilterBuilder = getDistributionSetFilterBuilder().setIsComplete(Boolean.TRUE)
.setTagNames(Lists.newArrayList(tagA.getName()));
.setTagNames(Arrays.asList(tagA.getName()));
assertEquals("filter works not correct",
dsAs.spliterator().getExactSizeIfKnown() + dsABs.spliterator().getExactSizeIfKnown()
+ dsACs.spliterator().getExactSizeIfKnown() + dsABCs.spliterator().getExactSizeIfKnown(),
@@ -166,12 +164,12 @@ public class TagManagementTest extends AbstractJpaIntegrationTest {
.getTotalElements());
distributionSetFilterBuilder = getDistributionSetFilterBuilder().setIsComplete(Boolean.TRUE)
.setTagNames(Lists.newArrayList(tagB.getName()));
.setTagNames(Arrays.asList(tagB.getName()));
assertEquals("filter works not correct", 0, distributionSetManagement
.findDistributionSetsByFilters(PAGE, distributionSetFilterBuilder.build()).getTotalElements());
distributionSetFilterBuilder = getDistributionSetFilterBuilder().setIsComplete(Boolean.TRUE)
.setTagNames(Lists.newArrayList(tagC.getName()));
.setTagNames(Arrays.asList(tagC.getName()));
assertEquals("filter works not correct",
dsCs.spliterator().getExactSizeIfKnown() + dsACs.spliterator().getExactSizeIfKnown()
+ dsBCs.spliterator().getExactSizeIfKnown() + dsABCs.spliterator().getExactSizeIfKnown(),

View File

@@ -100,9 +100,9 @@ public class TargetManagementSearchTest extends AbstractJpaIntegrationTest {
entityFactory.actionStatus().create(actionId).status(Status.FINISHED).message("message"));
assignDistributionSet(setA.getId(), installedC);
final List<TargetUpdateStatus> unknown = Lists.newArrayList(TargetUpdateStatus.UNKNOWN);
final List<TargetUpdateStatus> pending = Lists.newArrayList(TargetUpdateStatus.PENDING);
final List<TargetUpdateStatus> both = Lists.newArrayList(TargetUpdateStatus.UNKNOWN,
final List<TargetUpdateStatus> unknown = Arrays.asList(TargetUpdateStatus.UNKNOWN);
final List<TargetUpdateStatus> pending = Arrays.asList(TargetUpdateStatus.PENDING);
final List<TargetUpdateStatus> both = Arrays.asList(TargetUpdateStatus.UNKNOWN,
TargetUpdateStatus.PENDING);
// get final updated version of targets
@@ -123,14 +123,14 @@ public class TargetManagementSearchTest extends AbstractJpaIntegrationTest {
verifyThat0TargetsWithTagAndDescOrNameHasDS(targTagW, setA);
verifyThat0TargetsWithNameOrdescAndDSHaveTag(targTagX, setA);
verifyThat3TargetsHaveDSAssigned(setA,
targetManagement.findTargetsByControllerID(Lists.newArrayList(assignedA, assignedB, assignedC)));
targetManagement.findTargetsByControllerID(Arrays.asList(assignedA, assignedB, assignedC)));
verifyThat1TargetWithDescOrNameHasDS(setA, targetManagement.findTargetByControllerID(assignedA).get());
List<Target> expected = concat(targAs, targBs, targCs, targDs);
expected.removeAll(
targetManagement.findTargetsByControllerID(Lists.newArrayList(assignedA, assignedB, assignedC)));
targetManagement.findTargetsByControllerID(Arrays.asList(assignedA, assignedB, assignedC)));
verifyThat397TargetsAreInStatusUnknown(unknown, expected);
expected = concat(targBs, targCs);
expected.removeAll(targetManagement.findTargetsByControllerID(Lists.newArrayList(assignedB, assignedC)));
expected.removeAll(targetManagement.findTargetsByControllerID(Arrays.asList(assignedB, assignedC)));
verifyThat198TargetsAreInStatusUnknownAndHaveGivenTags(targTagY, targTagW, unknown, expected);
verfyThat0TargetsAreInStatusUnknownAndHaveDSAssigned(setA, unknown);
expected = concat(targAs);
@@ -140,23 +140,23 @@ public class TargetManagementSearchTest extends AbstractJpaIntegrationTest {
expected.remove(targetManagement.findTargetByControllerID(assignedB).get());
verifyThat99TargetsWithGivenNameOrDescAndTagAreInStatusUnknown(targTagW, unknown, expected);
verifyThat3TargetsAreInStatusPending(pending,
targetManagement.findTargetsByControllerID(Lists.newArrayList(assignedA, assignedB, assignedC)));
targetManagement.findTargetsByControllerID(Arrays.asList(assignedA, assignedB, assignedC)));
verifyThat3TargetsWithGivenDSAreInPending(setA, pending,
targetManagement.findTargetsByControllerID(Lists.newArrayList(assignedA, assignedB, assignedC)));
targetManagement.findTargetsByControllerID(Arrays.asList(assignedA, assignedB, assignedC)));
verifyThat1TargetWithGivenNameOrDescAndDSIsInPending(setA, pending,
targetManagement.findTargetByControllerID(assignedA).get());
verifyThat1TargetWithGivenNameOrDescAndTagAndDSIsInPending(targTagW, setA, pending,
targetManagement.findTargetByControllerID(assignedB).get());
verifyThat2TargetsWithGivenTagAndDSIsInPending(targTagW, setA, pending,
targetManagement.findTargetsByControllerID(Lists.newArrayList(assignedB, assignedC)));
targetManagement.findTargetsByControllerID(Arrays.asList(assignedB, assignedC)));
verifyThat2TargetsWithGivenTagAreInPending(targTagW, pending,
targetManagement.findTargetsByControllerID(Lists.newArrayList(assignedB, assignedC)));
targetManagement.findTargetsByControllerID(Arrays.asList(assignedB, assignedC)));
verifyThat200targetsWithGivenTagAreInStatusPendingorUnknown(targTagW, both, concat(targBs, targCs));
verfiyThat1TargetAIsInStatusPendingAndHasDSInstalled(installedSet, pending,
targetManagement.findTargetByControllerID(installedC).get());
expected = concat(targBs, targCs);
expected.removeAll(targetManagement.findTargetsByControllerID(Lists.newArrayList(assignedB, assignedC)));
expected.removeAll(targetManagement.findTargetsByControllerID(Arrays.asList(assignedB, assignedC)));
verifyThat198TargetsAreInStatusUnknownAndOverdue(unknown, expected);
}

View File

@@ -15,6 +15,8 @@ import static org.junit.Assert.fail;
import java.net.URI;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@@ -50,7 +52,6 @@ import org.springframework.data.domain.Page;
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;
@@ -79,14 +80,11 @@ public class TargetManagementTest extends AbstractJpaIntegrationTest {
final Target target = testdataFactory.createTarget();
verifyThrownExceptionBy(
() -> targetManagement.assignTag(Lists.newArrayList(target.getControllerId()), NOT_EXIST_IDL),
"TargetTag");
verifyThrownExceptionBy(() -> targetManagement.assignTag(Lists.newArrayList(NOT_EXIST_ID), tag.getId()),
"Target");
() -> targetManagement.assignTag(Arrays.asList(target.getControllerId()), NOT_EXIST_IDL), "TargetTag");
verifyThrownExceptionBy(() -> targetManagement.assignTag(Arrays.asList(NOT_EXIST_ID), tag.getId()), "Target");
verifyThrownExceptionBy(() -> targetManagement.findTargetsByTag(PAGE, NOT_EXIST_IDL), "TargetTag");
verifyThrownExceptionBy(() -> targetManagement.findTargetsByTag(PAGE, "name==*", NOT_EXIST_IDL),
"TargetTag");
verifyThrownExceptionBy(() -> targetManagement.findTargetsByTag(PAGE, "name==*", NOT_EXIST_IDL), "TargetTag");
verifyThrownExceptionBy(() -> targetManagement.countTargetByAssignedDistributionSet(NOT_EXIST_IDL),
"DistributionSet");
@@ -100,13 +98,12 @@ public class TargetManagementTest extends AbstractJpaIntegrationTest {
"DistributionSet");
verifyThrownExceptionBy(() -> targetManagement.deleteTarget(NOT_EXIST_ID), "Target");
verifyThrownExceptionBy(() -> targetManagement.deleteTargets(Lists.newArrayList(NOT_EXIST_IDL)), "Target");
verifyThrownExceptionBy(() -> targetManagement.deleteTargets(Arrays.asList(NOT_EXIST_IDL)), "Target");
verifyThrownExceptionBy(
() -> targetManagement.findAllTargetsByTargetFilterQueryAndNonDS(PAGE, NOT_EXIST_IDL, "name==*"),
"DistributionSet");
verifyThrownExceptionBy(
() -> targetManagement.findAllTargetsInRolloutGroupWithoutAction(PAGE, NOT_EXIST_IDL),
verifyThrownExceptionBy(() -> targetManagement.findAllTargetsInRolloutGroupWithoutAction(PAGE, NOT_EXIST_IDL),
"RolloutGroup");
verifyThrownExceptionBy(() -> targetManagement.findTargetByAssignedDistributionSet(NOT_EXIST_IDL, PAGE),
"DistributionSet");
@@ -121,10 +118,10 @@ public class TargetManagementTest extends AbstractJpaIntegrationTest {
"DistributionSet");
verifyThrownExceptionBy(
() -> targetManagement.toggleTagAssignment(Lists.newArrayList(target.getControllerId()), NOT_EXIST_ID),
() -> targetManagement.toggleTagAssignment(Arrays.asList(target.getControllerId()), NOT_EXIST_ID),
"TargetTag");
verifyThrownExceptionBy(
() -> targetManagement.toggleTagAssignment(Lists.newArrayList(NOT_EXIST_ID), tag.getName()), "Target");
verifyThrownExceptionBy(() -> targetManagement.toggleTagAssignment(Arrays.asList(NOT_EXIST_ID), tag.getName()),
"Target");
verifyThrownExceptionBy(() -> targetManagement.unAssignTag(NOT_EXIST_ID, tag.getId()), "Target");
verifyThrownExceptionBy(() -> targetManagement.unAssignTag(target.getControllerId(), NOT_EXIST_IDL),
@@ -302,12 +299,12 @@ public class TargetManagementTest extends AbstractJpaIntegrationTest {
public void deleteAndCreateTargets() {
Target target = targetManagement.createTarget(entityFactory.target().create().controllerId("targetId123"));
assertThat(targetManagement.countTargetsAll()).as("target count is wrong").isEqualTo(1);
targetManagement.deleteTargets(Lists.newArrayList(target.getId()));
targetManagement.deleteTargets(Arrays.asList(target.getId()));
assertThat(targetManagement.countTargetsAll()).as("target count is wrong").isEqualTo(0);
target = createTargetWithAttributes("4711");
assertThat(targetManagement.countTargetsAll()).as("target count is wrong").isEqualTo(1);
targetManagement.deleteTargets(Lists.newArrayList(target.getId()));
targetManagement.deleteTargets(Arrays.asList(target.getId()));
assertThat(targetManagement.countTargetsAll()).as("target count is wrong").isEqualTo(0);
final List<Long> targets = new ArrayList<>();
@@ -546,10 +543,9 @@ public class TargetManagementTest extends AbstractJpaIntegrationTest {
targetManagement.deleteTarget(extra.getControllerId());
final int numberToDelete = 50;
final Iterable<Target> targetsToDelete = Iterables.limit(firstList, numberToDelete);
final Collection<Target> targetsToDelete = firstList.subList(0, numberToDelete);
final Target[] deletedTargets = Iterables.toArray(targetsToDelete, Target.class);
final List<Long> targetsIdsToDelete = Lists.newArrayList(targetsToDelete.iterator()).stream().map(Target::getId)
.collect(Collectors.toList());
final List<Long> targetsIdsToDelete = targetsToDelete.stream().map(Target::getId).collect(Collectors.toList());
targetManagement.deleteTargets(targetsIdsToDelete);
@@ -571,11 +567,11 @@ public class TargetManagementTest extends AbstractJpaIntegrationTest {
final int noT1Tags = 3;
final List<TargetTag> t1Tags = testdataFactory.createTargetTags(noT1Tags, "tag1");
t1Tags.forEach(tag -> targetManagement.assignTag(Lists.newArrayList(t1.getControllerId()), tag.getId()));
t1Tags.forEach(tag -> targetManagement.assignTag(Arrays.asList(t1.getControllerId()), tag.getId()));
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.getId()));
t2Tags.forEach(tag -> targetManagement.assignTag(Arrays.asList(t2.getControllerId()), tag.getId()));
final Target t11 = targetManagement.findTargetByControllerID(t1.getControllerId()).get();
assertThat(tagManagement.findAllTargetTags(PAGE, t11.getControllerId()).getContent()).as("Tag size is wrong")
@@ -777,7 +773,7 @@ public class TargetManagementTest extends AbstractJpaIntegrationTest {
@Description("Verify that the find all targets by ids method contains the entities that we are looking for")
@ExpectEvents({ @Expect(type = TargetCreatedEvent.class, count = 12) })
public void verifyFindTargetAllById() {
final List<Long> searchIds = Lists.newArrayList(testdataFactory.createTarget("target-4").getId(),
final List<Long> searchIds = Arrays.asList(testdataFactory.createTarget("target-4").getId(),
testdataFactory.createTarget("target-5").getId(), testdataFactory.createTarget("target-6").getId());
for (int i = 0; i < 9; i++) {
testdataFactory.createTarget("test" + i);

View File

@@ -155,7 +155,7 @@ public class RepositoryEntityEventTest extends AbstractJpaIntegrationTest {
@Description("Verifies that the software module update event is published when a software module has been updated")
public void softwareModuleUpdateEventIsPublished() throws InterruptedException {
final SoftwareModule softwareModule = testdataFactory.createSoftwareModuleApp();
softwareManagement
softwareModuleManagement
.updateSoftwareModule(entityFactory.softwareModule().update(softwareModule.getId()).description("New"));
final SoftwareModuleUpdatedEvent softwareModuleUpdatedEvent = eventListener
@@ -168,7 +168,7 @@ public class RepositoryEntityEventTest extends AbstractJpaIntegrationTest {
@Description("Verifies that the software module deleted event is published when a software module has been deleted")
public void softwareModuleDeletedEventIsPublished() throws InterruptedException {
final SoftwareModule softwareModule = testdataFactory.createSoftwareModuleApp();
softwareManagement.deleteSoftwareModule(softwareModule.getId());
softwareModuleManagement.deleteSoftwareModule(softwareModule.getId());
final SoftwareModuleDeletedEvent softwareModuleDeletedEvent = eventListener
.waitForEvent(SoftwareModuleDeletedEvent.class, 1, TimeUnit.SECONDS);

View File

@@ -103,10 +103,10 @@ public class EntityInterceptorListenerTest extends AbstractJpaIntegrationTest {
private void executeDeleteAndAssertCallbackResult(final AbstractEntityListener entityInterceptor) {
EntityInterceptorHolder.getInstance().getEntityInterceptors().add(entityInterceptor);
final SoftwareModuleType type = softwareManagement
final SoftwareModuleType type = softwareModuleTypeManagement
.createSoftwareModuleType(entityFactory.softwareModuleType().create().name("test").key("test"));
softwareManagement.deleteSoftwareModuleType(type.getId());
softwareModuleTypeManagement.deleteSoftwareModuleType(type.getId());
assertThat(entityInterceptor.getEntity()).isNotNull();
assertThat(entityInterceptor.getEntity()).isEqualTo(type);
}

View File

@@ -55,12 +55,12 @@ public class ModelEqualsHashcodeTest extends AbstractJpaIntegrationTest {
@Test
@Description("Verfies that updated entities are not equal.")
public void changedEntitiesAreNotEqual() {
final SoftwareModuleType type = softwareManagement
final SoftwareModuleType type = softwareModuleTypeManagement
.createSoftwareModuleType(entityFactory.softwareModuleType().create().key("test").name("test"));
assertThat(type).as("persited entity is not equal to regular object")
.isNotEqualTo(entityFactory.softwareModuleType().create().key("test").name("test").build());
final SoftwareModuleType updated = softwareManagement.updateSoftwareModuleType(
final SoftwareModuleType updated = softwareModuleTypeManagement.updateSoftwareModuleType(
entityFactory.softwareModuleType().update(type.getId()).description("another"));
assertThat(type).as("Changed entity is not equal to the previous version").isNotEqualTo(updated);
}
@@ -68,7 +68,7 @@ public class ModelEqualsHashcodeTest extends AbstractJpaIntegrationTest {
@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(
final SoftwareModuleType type = softwareModuleTypeManagement.createSoftwareModuleType(
entityFactory.softwareModuleType().create().key("test").name("test").description("test"));
final JpaSoftwareModuleType mock = new JpaSoftwareModuleType("test", "test", "test", 1);

View File

@@ -31,21 +31,21 @@ public class RSQLSoftwareModuleFieldTest extends AbstractJpaIntegrationTest {
@Before
public void setupBeforeTest() {
final SoftwareModule ah = softwareManagement.createSoftwareModule(entityFactory.softwareModule().create()
final SoftwareModule ah = softwareModuleManagement.createSoftwareModule(entityFactory.softwareModule().create()
.type(appType).name("agent-hub").version("1.0.1").description("agent-hub"));
softwareManagement.createSoftwareModule(entityFactory.softwareModule().create().type(runtimeType)
softwareModuleManagement.createSoftwareModule(entityFactory.softwareModule().create().type(runtimeType)
.name("oracle-jre").version("1.7.2").description("aa"));
softwareManagement.createSoftwareModule(
softwareModuleManagement.createSoftwareModule(
entityFactory.softwareModule().create().type(osType).name("poky").version("3.0.2").description("aa"));
final JpaSoftwareModule ah2 = (JpaSoftwareModule) softwareManagement.createSoftwareModule(entityFactory
final JpaSoftwareModule ah2 = (JpaSoftwareModule) softwareModuleManagement.createSoftwareModule(entityFactory
.softwareModule().create().type(appType).name("agent-hub2").version("1.0.1").description("agent-hub2"));
final MetaData softwareModuleMetadata = entityFactory.generateMetadata("metaKey", "metaValue");
softwareManagement.createSoftwareModuleMetadata(ah.getId(), softwareModuleMetadata);
softwareModuleManagement.createSoftwareModuleMetadata(ah.getId(), softwareModuleMetadata);
final MetaData softwareModuleMetadata2 = entityFactory.generateMetadata("metaKey", "value");
softwareManagement.createSoftwareModuleMetadata(ah2.getId(), softwareModuleMetadata2);
softwareModuleManagement.createSoftwareModuleMetadata(ah2.getId(), softwareModuleMetadata2);
}
@Test
@@ -105,7 +105,7 @@ public class RSQLSoftwareModuleFieldTest extends AbstractJpaIntegrationTest {
}
private void assertRSQLQuery(final String rsqlParam, final long excpectedEntity) {
final Page<SoftwareModule> find = softwareManagement.findSoftwareModulesByPredicate(rsqlParam,
final Page<SoftwareModule> find = softwareModuleManagement.findSoftwareModulesByPredicate(rsqlParam,
new PageRequest(0, 100));
final long countAll = find.getTotalElements();
assertThat(find).isNotNull();

View File

@@ -45,7 +45,7 @@ public class RSQLSoftwareModuleMetadataFieldsTest extends AbstractJpaIntegration
metadata.add(entityFactory.generateMetadata("" + i, "" + i));
}
softwareManagement.createSoftwareModuleMetadata(softwareModule.getId(), metadata);
softwareModuleManagement.createSoftwareModuleMetadata(softwareModule.getId(), metadata);
}
@@ -69,7 +69,7 @@ public class RSQLSoftwareModuleMetadataFieldsTest extends AbstractJpaIntegration
private void assertRSQLQuery(final String rsqlParam, final long expectedEntities) {
final Page<SoftwareModuleMetadata> findEnitity = softwareManagement
final Page<SoftwareModuleMetadata> findEnitity = softwareModuleManagement
.findSoftwareModuleMetadataBySoftwareModuleId(softwareModuleId, rsqlParam, new PageRequest(0, 100));
final long countAllEntities = findEnitity.getTotalElements();
assertThat(findEnitity).isNotNull();

View File

@@ -60,7 +60,7 @@ public class RSQLSoftwareModuleTypeFieldsTest extends AbstractJpaIntegrationTest
}
private void assertRSQLQuery(final String rsqlParam, final long excpectedEntity) {
final Page<SoftwareModuleType> find = softwareManagement.findSoftwareModuleTypesAll(rsqlParam,
final Page<SoftwareModuleType> find = softwareModuleTypeManagement.findSoftwareModuleTypesAll(rsqlParam,
new PageRequest(0, 100));
final long countAll = find.getTotalElements();
assertThat(find).isNotNull();

View File

@@ -11,6 +11,7 @@ package org.eclipse.hawkbit.repository.jpa.tenancy;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.fail;
import java.util.Arrays;
import java.util.Collection;
import org.eclipse.hawkbit.repository.exception.EntityNotFoundException;
@@ -23,8 +24,6 @@ import org.junit.Test;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Slice;
import com.google.common.collect.Lists;
import ru.yandex.qatools.allure.annotations.Description;
import ru.yandex.qatools.allure.annotations.Features;
import ru.yandex.qatools.allure.annotations.Stories;
@@ -92,8 +91,7 @@ public class MultiTenancyEntityTest extends AbstractJpaIntegrationTest {
final String controllerAnotherTenant = "anotherController";
createTargetForTenant(controllerAnotherTenant, anotherTenant);
assertThat(systemManagement.findTenants(PAGE)).as("Expected number if tenants before deletion is")
.hasSize(3);
assertThat(systemManagement.findTenants(PAGE)).as("Expected number if tenants before deletion is").hasSize(3);
systemManagement.deleteTenant(anotherTenant);
@@ -107,9 +105,9 @@ public class MultiTenancyEntityTest extends AbstractJpaIntegrationTest {
// logged in tenant mytenant - check if tenant default data is
// autogenerated
assertThat(distributionSetManagement.findDistributionSetTypesAll(PAGE)).isEmpty();
assertThat(distributionSetTypeManagement.findDistributionSetTypesAll(PAGE)).isEmpty();
assertThat(systemManagement.getTenantMetadata().getTenant().toUpperCase()).isEqualTo("mytenant".toUpperCase());
assertThat(distributionSetManagement.findDistributionSetTypesAll(PAGE)).isNotEmpty();
assertThat(distributionSetTypeManagement.findDistributionSetTypesAll(PAGE)).isNotEmpty();
// check that the cache is not getting in the way, i.e. "bumlux" results
// in bumlux and not
@@ -130,7 +128,7 @@ public class MultiTenancyEntityTest extends AbstractJpaIntegrationTest {
// ensure target cannot be deleted by 'mytenant'
try {
targetManagement.deleteTargets(Lists.newArrayList(createTargetForTenant.getId()));
targetManagement.deleteTargets(Arrays.asList(createTargetForTenant.getId()));
fail("mytenant should not have been able to delete target of anotherTenant");
} catch (final EntityNotFoundException ex) {
// ok
@@ -140,7 +138,7 @@ public class MultiTenancyEntityTest extends AbstractJpaIntegrationTest {
assertThat(targetsForAnotherTenant).hasSize(1);
// ensure another tenant can delete the target
deleteTargetsForTenant(anotherTenant, Lists.newArrayList(createTargetForTenant.getId()));
deleteTargetsForTenant(anotherTenant, Arrays.asList(createTargetForTenant.getId()));
targetsForAnotherTenant = findTargetsForTenant(anotherTenant);
assertThat(targetsForAnotherTenant).hasSize(0);
}