Merge pull request #107 from bsinno/complete-rep-tests
Complete repository tests
This commit is contained in:
@@ -95,7 +95,7 @@ public class TestDataUtil {
|
||||
return distributionSetManagement.createDistributionSet(
|
||||
buildDistributionSet(suffix != null && suffix.length() > 0 ? suffix : "DS", version,
|
||||
findOrCreateDistributionSetType(distributionSetManagement, "ecl_os_app_jvm",
|
||||
"OC mandatory App/JVM optional", mand, opt),
|
||||
"OS mandatory App/JVM optional", mand, opt),
|
||||
os, jvm, ah).setRequiredMigrationStep(isRequiredMigrationStep));
|
||||
}
|
||||
|
||||
@@ -143,7 +143,7 @@ public class TestDataUtil {
|
||||
}
|
||||
|
||||
public static List<DistributionSetTag> generateDistributionSetTags(final int number) {
|
||||
final List<DistributionSetTag> result = new ArrayList<DistributionSetTag>();
|
||||
final List<DistributionSetTag> result = new ArrayList<>();
|
||||
|
||||
for (int i = 0; i < number; i++) {
|
||||
result.add(new DistributionSetTag("tag" + i, "tagdesc" + i, "" + i));
|
||||
|
||||
@@ -33,12 +33,10 @@ public class ActionTest {
|
||||
final Action timeforcedAction = new Action();
|
||||
timeforcedAction.setActionType(ActionType.TIMEFORCED);
|
||||
timeforcedAction.setForcedTime(timeForceTimeAt);
|
||||
final int knownHashCode = timeforcedAction.hashCode();
|
||||
assertThat(timeforcedAction.isForce()).isFalse();
|
||||
|
||||
// wait until timeforce time is hit
|
||||
Thread.sleep(sleepTime + 100);
|
||||
assertThat(timeforcedAction.isForce()).isTrue();
|
||||
assertThat(timeforcedAction.hashCode()).isNotEqualTo(knownHashCode);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,6 +8,8 @@
|
||||
*/
|
||||
package org.eclipse.hawkbit.repository;
|
||||
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
@@ -37,7 +39,7 @@ public class ArtifactManagementNoMongoDbTest extends AbstractIntegrationTest {
|
||||
System.setProperty("spring.data.mongodb.port", "1020");
|
||||
}
|
||||
|
||||
@Test(expected = ArtifactUploadFailedException.class)
|
||||
@Test
|
||||
@Description("Checks if the expected ArtifactUploadFailedException is thrown in case of MongoDB down")
|
||||
public void createLocalArtifactWithMongoDbDown() throws IOException {
|
||||
SoftwareModule sm = new SoftwareModule(softwareManagement.findSoftwareModuleTypeByKey("os"), "name 1",
|
||||
@@ -46,7 +48,12 @@ public class ArtifactManagementNoMongoDbTest extends AbstractIntegrationTest {
|
||||
|
||||
final byte random[] = RandomStringUtils.random(5 * 1024).getBytes();
|
||||
|
||||
artifactManagement.createLocalArtifact(new ByteArrayInputStream(random), sm.getId(), "file1", false);
|
||||
try {
|
||||
artifactManagement.createLocalArtifact(new ByteArrayInputStream(random), sm.getId(), "file1", false);
|
||||
fail("Should not have worked with MongoDb down.");
|
||||
} catch (final ArtifactUploadFailedException e) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -352,11 +352,16 @@ public class ArtifactManagementTest extends AbstractIntegrationTestWithMongoDB {
|
||||
artifactManagement.loadLocalArtifactBinary(result).getFileInputStream()));
|
||||
}
|
||||
|
||||
@Test(expected = InsufficientPermissionException.class)
|
||||
@Test
|
||||
@WithUser(allSpPermissions = true, removeFromAllPermission = { SpPermission.DOWNLOAD_REPOSITORY_ARTIFACT })
|
||||
@Description("Trys and fails to load an artifact without required permission. Checks if expected InsufficientPermissionException is thrown.")
|
||||
public void loadLocalArtifactBinaryWithoutDownloadArtifactThrowsPermissionDenied() {
|
||||
artifactManagement.loadLocalArtifactBinary(new LocalArtifact());
|
||||
try {
|
||||
artifactManagement.loadLocalArtifactBinary(new LocalArtifact());
|
||||
fail("Should not have worked with missing permission.");
|
||||
} catch (final InsufficientPermissionException e) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -43,7 +43,7 @@ public class ControllerManagementTest extends AbstractIntegrationTest {
|
||||
distributionSetManagement);
|
||||
Target savedTarget = targetManagement.createTarget(target);
|
||||
|
||||
final List<Target> toAssign = new ArrayList<Target>();
|
||||
final List<Target> toAssign = new ArrayList<>();
|
||||
toAssign.add(savedTarget);
|
||||
|
||||
assertThat(savedTarget.getTargetInfo().getUpdateStatus()).isEqualTo(TargetUpdateStatus.UNKNOWN);
|
||||
@@ -75,7 +75,7 @@ public class ControllerManagementTest extends AbstractIntegrationTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
@Description("Register a controller which not exist")
|
||||
@Description("Register a controller which does not exist")
|
||||
public void testfindOrRegisterTargetIfItDoesNotexist() {
|
||||
final Target target = controllerManagament.findOrRegisterTargetIfItDoesNotexist("AA", null);
|
||||
assertThat(target).as("target should not be null").isNotNull();
|
||||
@@ -84,11 +84,12 @@ public class ControllerManagementTest extends AbstractIntegrationTest {
|
||||
assertThat(target).as("Target should be the equals").isEqualTo(sameTarget);
|
||||
assertThat(targetRepository.count()).as("Only 1 target should be registred").isEqualTo(1L);
|
||||
|
||||
// throws exception
|
||||
try {
|
||||
controllerManagament.findOrRegisterTargetIfItDoesNotexist("", null);
|
||||
fail("target with empty controller id should not be registred");
|
||||
fail("should fail as target does not exist");
|
||||
} catch (final ConstraintViolationException e) {
|
||||
// ok
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -101,7 +102,7 @@ public class ControllerManagementTest extends AbstractIntegrationTest {
|
||||
final DistributionSet ds = TestDataUtil.generateDistributionSet("", softwareManagement,
|
||||
distributionSetManagement);
|
||||
Target savedTarget = targetManagement.createTarget(target);
|
||||
final List<Target> toAssign = new ArrayList<Target>();
|
||||
final List<Target> toAssign = new ArrayList<>();
|
||||
toAssign.add(savedTarget);
|
||||
savedTarget = deploymentManagement.assignDistributionSet(ds, toAssign).getAssignedTargets().iterator().next();
|
||||
Action savedAction = deploymentManagement.findActiveActionsByTarget(savedTarget).get(0);
|
||||
@@ -124,7 +125,7 @@ public class ControllerManagementTest extends AbstractIntegrationTest {
|
||||
final ActionStatus actionStatusMessage3 = new ActionStatus(savedAction, Action.Status.FINISHED,
|
||||
System.currentTimeMillis());
|
||||
actionStatusMessage3.addMessage("finish");
|
||||
savedAction = controllerManagament.addUpdateActionStatus(actionStatusMessage3, savedAction);
|
||||
controllerManagament.addUpdateActionStatus(actionStatusMessage3, savedAction);
|
||||
|
||||
targetManagement.findTargetByControllerID("Rabbit").getTargetInfo().getUpdateStatus();
|
||||
|
||||
|
||||
@@ -33,6 +33,7 @@ import org.eclipse.hawkbit.repository.model.DistributionSetTag;
|
||||
import org.eclipse.hawkbit.repository.model.DistributionSetType;
|
||||
import org.eclipse.hawkbit.repository.model.SoftwareModule;
|
||||
import org.eclipse.hawkbit.repository.model.Target;
|
||||
import org.fest.assertions.core.Condition;
|
||||
import org.junit.Test;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.PageRequest;
|
||||
@@ -44,15 +45,12 @@ import ru.yandex.qatools.allure.annotations.Features;
|
||||
import ru.yandex.qatools.allure.annotations.Stories;
|
||||
|
||||
/**
|
||||
* {@link SoftwareManagement} test focused on {@link DistributionSet} and
|
||||
* {@link DistributionSetType} related stuff.
|
||||
*
|
||||
*
|
||||
* {@link DistributionSetManagement} tests.
|
||||
*
|
||||
*/
|
||||
@Features("Component Tests - Repository")
|
||||
@Stories("Software Management")
|
||||
public class SoftwareManagementForDSTest extends AbstractIntegrationTest {
|
||||
@Stories("DistributionSet Management")
|
||||
public class DistributionSetManagementTest extends AbstractIntegrationTest {
|
||||
|
||||
@Test
|
||||
@Description("Tests the successfull module update of unused distribution set type which is in fact allowed.")
|
||||
@@ -102,7 +100,7 @@ public class SoftwareManagementForDSTest extends AbstractIntegrationTest {
|
||||
.isEqualTo("test123");
|
||||
}
|
||||
|
||||
@Test(expected = EntityReadOnlyException.class)
|
||||
@Test
|
||||
@Description("Tests the unsuccessfull update of used distribution set type (module addition).")
|
||||
public void addModuleToAssignedDistributionSetTypeFails() {
|
||||
final DistributionSetType nonUpdatableType = distributionSetManagement
|
||||
@@ -113,10 +111,17 @@ public class SoftwareManagementForDSTest extends AbstractIntegrationTest {
|
||||
.createDistributionSet(new DistributionSet("newtypesoft", "1", "", nonUpdatableType, null));
|
||||
|
||||
nonUpdatableType.addMandatoryModuleType(osType);
|
||||
distributionSetManagement.updateDistributionSetType(nonUpdatableType);
|
||||
|
||||
try {
|
||||
distributionSetManagement.updateDistributionSetType(nonUpdatableType);
|
||||
fail("Should not have worked as DS is in use.");
|
||||
} catch (final EntityReadOnlyException e) {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Test(expected = EntityReadOnlyException.class)
|
||||
@Test
|
||||
@Description("Tests the unsuccessfull update of used distribution set type (module removal).")
|
||||
public void removeModuleToAssignedDistributionSetTypeFails() {
|
||||
DistributionSetType nonUpdatableType = distributionSetManagement
|
||||
@@ -130,7 +135,12 @@ public class SoftwareManagementForDSTest extends AbstractIntegrationTest {
|
||||
.createDistributionSet(new DistributionSet("newtypesoft", "1", "", nonUpdatableType, null));
|
||||
|
||||
nonUpdatableType.removeModuleType(osType.getId());
|
||||
nonUpdatableType = distributionSetManagement.updateDistributionSetType(nonUpdatableType);
|
||||
try {
|
||||
distributionSetManagement.updateDistributionSetType(nonUpdatableType);
|
||||
fail("Should not have worked as DS is in use.");
|
||||
} catch (final EntityReadOnlyException e) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -152,22 +162,68 @@ public class SoftwareManagementForDSTest extends AbstractIntegrationTest {
|
||||
.createDistributionSetType(new DistributionSetType("softdeleted", "to be deletd", ""));
|
||||
|
||||
assertThat(distributionSetTypeRepository.findAll()).contains(softDelete);
|
||||
final DistributionSet dsNewType = distributionSetManagement
|
||||
.createDistributionSet(new DistributionSet("newtypesoft", "1", "", softDelete, null));
|
||||
distributionSetManagement.createDistributionSet(new DistributionSet("newtypesoft", "1", "", softDelete, null));
|
||||
|
||||
distributionSetManagement.deleteDistributionSetType(softDelete);
|
||||
assertThat(distributionSetManagement.findDistributionSetTypeByKey("softdeleted").isDeleted()).isEqualTo(true);
|
||||
}
|
||||
|
||||
// TODO: kzimmerm: test N+1
|
||||
|
||||
@Test(expected = EntityAlreadyExistsException.class)
|
||||
@Test
|
||||
@Description("Ensures that it is not possible to create a DS that already exists (unique constraint is on name,version for DS).")
|
||||
public void createDuplicateDistributionSetsFailsWithException() {
|
||||
TestDataUtil.generateDistributionSet("a", softwareManagement, distributionSetManagement);
|
||||
|
||||
TestDataUtil.generateDistributionSet("a", softwareManagement, distributionSetManagement);
|
||||
try {
|
||||
TestDataUtil.generateDistributionSet("a", softwareManagement, distributionSetManagement);
|
||||
fail("Should not have worked as DS with same UK already exists.");
|
||||
} catch (final EntityAlreadyExistsException e) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@Description("Verfies that a DS is of default type if not specified explicitly at creation time.")
|
||||
public void createDistributionSetWithImplicitType() {
|
||||
final DistributionSet set = distributionSetManagement
|
||||
.createDistributionSet(new DistributionSet("newtypesoft", "1", "", null, null));
|
||||
|
||||
assertThat(set.getType()).as("Type should be equal to default type of tenant")
|
||||
.isEqualTo(systemManagement.getTenantMetadata().getDefaultDsType());
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
@Description("Verfies that multiple DS are of default type if not specified explicitly at creation time.")
|
||||
public void createMultipleDistributionSetsWithImplicitType() {
|
||||
|
||||
List<DistributionSet> sets = new ArrayList<>();
|
||||
for (int i = 0; i < 10; i++) {
|
||||
sets.add(new DistributionSet("another DS" + i, "X" + i, "", null, null));
|
||||
}
|
||||
|
||||
sets = distributionSetManagement.createDistributionSets(sets);
|
||||
|
||||
assertThat(sets).as("Type should be equal to default type of tenant").are(new Condition<DistributionSet>() {
|
||||
@Override
|
||||
public boolean matches(final DistributionSet value) {
|
||||
return value.getType().equals(systemManagement.getTenantMetadata().getDefaultDsType());
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
@Description("Verfies that a DS entity cannot be used for creation.")
|
||||
public void createDistributionSetFailsOnExistingEntity() {
|
||||
final DistributionSet set = distributionSetManagement
|
||||
.createDistributionSet(new DistributionSet("newtypesoft", "1", "", null, null));
|
||||
|
||||
try {
|
||||
distributionSetManagement.createDistributionSet(set);
|
||||
fail("Should not have worked to create based on a persisted entity.");
|
||||
} catch (final EntityAlreadyExistsException e) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -244,17 +300,22 @@ public class SoftwareManagementForDSTest extends AbstractIntegrationTest {
|
||||
}
|
||||
}
|
||||
|
||||
@Test(expected = DistributionSetTypeUndefinedException.class)
|
||||
@Test
|
||||
@Description("Ensures that it is not possible to add a software module to a set that has no type defined.")
|
||||
public void updateDistributionSetModuleWithUndefinedTypeFails() {
|
||||
final DistributionSet testSet = new DistributionSet();
|
||||
final SoftwareModule module = new SoftwareModule(appType, "agent-hub2", "1.0.5", null, "");
|
||||
|
||||
// update data
|
||||
testSet.addModule(module);
|
||||
try {
|
||||
testSet.addModule(module);
|
||||
fail("Should not have worked as DS type is undefined.");
|
||||
} catch (final DistributionSetTypeUndefinedException e) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@Test(expected = UnsupportedSoftwareModuleForThisDistributionSetException.class)
|
||||
@Test
|
||||
@Description("Ensures that it is not possible to add a software module that is not defined of the DS's type.")
|
||||
public void updateDistributionSetUnsupportedModuleFails() {
|
||||
final DistributionSet set = new DistributionSet("agent-hub2", "1.0.5", "desc",
|
||||
@@ -262,7 +323,12 @@ public class SoftwareManagementForDSTest extends AbstractIntegrationTest {
|
||||
final SoftwareModule module = new SoftwareModule(appType, "agent-hub2", "1.0.5", null, "");
|
||||
|
||||
// update data
|
||||
set.addModule(module);
|
||||
try {
|
||||
set.addModule(module);
|
||||
fail("Should not have worked as module type is not in DS type.");
|
||||
} catch (final UnsupportedSoftwareModuleForThisDistributionSetException e) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -561,7 +627,7 @@ public class SoftwareManagementForDSTest extends AbstractIntegrationTest {
|
||||
.findDistributionSetsByFilters(pageReq, distributionSetFilterBuilder.build()).getContent()).hasSize(0);
|
||||
|
||||
// combine deleted and complete and type
|
||||
expected = new ArrayList<DistributionSet>();
|
||||
expected = new ArrayList<>();
|
||||
expected.addAll(ds100Group1);
|
||||
expected.addAll(ds100Group2);
|
||||
distributionSetFilterBuilder = getDistributionSetFilterBuilder().setIsDeleted(Boolean.FALSE)
|
||||
@@ -570,7 +636,7 @@ public class SoftwareManagementForDSTest extends AbstractIntegrationTest {
|
||||
.findDistributionSetsByFilters(pageReq, distributionSetFilterBuilder.build()).getContent()).hasSize(200)
|
||||
.containsOnly(expected.toArray(new DistributionSet[0]));
|
||||
|
||||
expected = new ArrayList<DistributionSet>();
|
||||
expected = new ArrayList<>();
|
||||
expected.add(dsDeleted);
|
||||
distributionSetFilterBuilder = getDistributionSetFilterBuilder().setIsComplete(Boolean.TRUE)
|
||||
.setType(standardDsType).setIsDeleted(Boolean.TRUE);
|
||||
@@ -583,7 +649,7 @@ public class SoftwareManagementForDSTest extends AbstractIntegrationTest {
|
||||
assertThat(distributionSetManagement
|
||||
.findDistributionSetsByFilters(pageReq, distributionSetFilterBuilder.build()).getContent()).hasSize(0);
|
||||
|
||||
expected = new ArrayList<DistributionSet>();
|
||||
expected = new ArrayList<>();
|
||||
expected.add(dsNewType);
|
||||
distributionSetFilterBuilder = getDistributionSetFilterBuilder().setIsComplete(Boolean.TRUE).setType(newType);
|
||||
assertThat(distributionSetManagement
|
||||
@@ -591,7 +657,7 @@ public class SoftwareManagementForDSTest extends AbstractIntegrationTest {
|
||||
.containsOnly(expected.toArray(new DistributionSet[0]));
|
||||
|
||||
// combine deleted and complete and type and text
|
||||
expected = new ArrayList<DistributionSet>();
|
||||
expected = new ArrayList<>();
|
||||
expected.addAll(ds100Group2);
|
||||
distributionSetFilterBuilder = getDistributionSetFilterBuilder().setIsComplete(Boolean.TRUE)
|
||||
.setType(standardDsType).setSearchText("%test2");
|
||||
@@ -615,7 +681,7 @@ public class SoftwareManagementForDSTest extends AbstractIntegrationTest {
|
||||
.findDistributionSetsByFilters(pageReq, distributionSetFilterBuilder.build()).getContent()).hasSize(0);
|
||||
|
||||
// combine deleted and complete and type and text and tag
|
||||
expected = new ArrayList<DistributionSet>();
|
||||
expected = new ArrayList<>();
|
||||
expected.addAll(ds100Group2);
|
||||
distributionSetFilterBuilder = getDistributionSetFilterBuilder().setIsComplete(true).setType(standardDsType)
|
||||
.setSearchText("%test2").setTagNames(Lists.newArrayList(dsTagA.getName()));
|
||||
@@ -637,7 +703,7 @@ public class SoftwareManagementForDSTest extends AbstractIntegrationTest {
|
||||
|
||||
private List<Target> sendUpdateActionStatusToTargets(final DistributionSet dsA, final Iterable<Target> targs,
|
||||
final Status status, final String... msgs) {
|
||||
final List<Target> result = new ArrayList<Target>();
|
||||
final List<Target> result = new ArrayList<>();
|
||||
for (final Target t : targs) {
|
||||
final List<Action> findByTarget = actionRepository.findByTarget(t);
|
||||
for (final Action action : findByTarget) {
|
||||
@@ -730,7 +796,7 @@ public class SoftwareManagementForDSTest extends AbstractIntegrationTest {
|
||||
dsAssigned.getVersion());
|
||||
final Target target = new Target("4712");
|
||||
final Target savedTarget = targetManagement.createTarget(target);
|
||||
final List<Target> toAssign = new ArrayList<Target>();
|
||||
final List<Target> toAssign = new ArrayList<>();
|
||||
toAssign.add(savedTarget);
|
||||
deploymentManagement.assignDistributionSet(dsAssigned, toAssign);
|
||||
|
||||
@@ -744,38 +810,6 @@ public class SoftwareManagementForDSTest extends AbstractIntegrationTest {
|
||||
.getTotalElements()).isEqualTo(2);
|
||||
}
|
||||
|
||||
/**
|
||||
* helper method which re-orders a list as expected. Re-orders the given
|
||||
* distribution set in the order as given and returns a new list with the
|
||||
* new order.
|
||||
*
|
||||
* @param dsThree
|
||||
* @param buildDistributionSets
|
||||
* @return
|
||||
*/
|
||||
private List<DistributionSet> reOrderDSList(final Iterable<DistributionSet> buildDistributionSets,
|
||||
final DistributionSet... ds) {
|
||||
final List<DistributionSet> reOrderedList = new ArrayList<>();
|
||||
|
||||
final Iterator<DistributionSet> iterator = buildDistributionSets.iterator();
|
||||
while (iterator.hasNext()) {
|
||||
final DistributionSet next = iterator.next();
|
||||
int reorder = -1;
|
||||
for (int index = 0; index < ds.length; index++) {
|
||||
if (next.equals(ds[index])) {
|
||||
reorder = index;
|
||||
}
|
||||
}
|
||||
if (reorder >= 0) {
|
||||
reOrderedList.add(reorder, next);
|
||||
} else {
|
||||
reOrderedList.add(next);
|
||||
}
|
||||
}
|
||||
|
||||
return reOrderedList;
|
||||
}
|
||||
|
||||
private Target sendUpdateActionStatusToTarget(final Status status, final Action updActA, final Target t,
|
||||
final String... msgs) {
|
||||
updActA.setStatus(status);
|
||||
@@ -10,11 +10,11 @@ package org.eclipse.hawkbit.repository;
|
||||
|
||||
import static org.fest.assertions.api.Assertions.assertThat;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
@@ -24,14 +24,18 @@ import org.eclipse.hawkbit.AbstractIntegrationTestWithMongoDB;
|
||||
import org.eclipse.hawkbit.RandomGeneratedInputStream;
|
||||
import org.eclipse.hawkbit.TestDataUtil;
|
||||
import org.eclipse.hawkbit.WithUser;
|
||||
import org.eclipse.hawkbit.repository.exception.EntityAlreadyExistsException;
|
||||
import org.eclipse.hawkbit.repository.exception.EntityNotFoundException;
|
||||
import org.eclipse.hawkbit.repository.model.Action;
|
||||
import org.eclipse.hawkbit.repository.model.Artifact;
|
||||
import org.eclipse.hawkbit.repository.model.CustomSoftwareModule;
|
||||
import org.eclipse.hawkbit.repository.model.DistributionSet;
|
||||
import org.eclipse.hawkbit.repository.model.DistributionSetTag;
|
||||
import org.eclipse.hawkbit.repository.model.DistributionSetType;
|
||||
import org.eclipse.hawkbit.repository.model.LocalArtifact;
|
||||
import org.eclipse.hawkbit.repository.model.SoftwareModule;
|
||||
import org.eclipse.hawkbit.repository.model.SoftwareModuleMetadata;
|
||||
import org.eclipse.hawkbit.repository.model.SoftwareModuleType;
|
||||
import org.eclipse.hawkbit.repository.model.SwMetadataCompositeKey;
|
||||
import org.eclipse.hawkbit.repository.model.Target;
|
||||
import org.eclipse.hawkbit.repository.model.TargetUpdateStatus;
|
||||
import org.junit.Test;
|
||||
@@ -51,6 +55,165 @@ import ru.yandex.qatools.allure.annotations.Stories;
|
||||
@Stories("Software Management")
|
||||
public class SoftwareManagementTest extends AbstractIntegrationTestWithMongoDB {
|
||||
|
||||
@Test
|
||||
@Description("Try to update non updatable fields results in repository doing nothing.")
|
||||
public void updateTypeNonUpdateableFieldsFails() {
|
||||
final SoftwareModuleType created = softwareManagement
|
||||
.createSoftwareModuleType(new SoftwareModuleType("test-key", "test-name", "test-desc", 1));
|
||||
|
||||
created.setName("a new name");
|
||||
final SoftwareModuleType updated = softwareManagement.updateSoftwareModuleType(created);
|
||||
|
||||
assertThat(updated.getOptLockRevision())
|
||||
.as("Expected version number of updated entitity to be equal to created version")
|
||||
.isEqualTo(created.getOptLockRevision());
|
||||
}
|
||||
|
||||
@Test
|
||||
@Description("Calling update without changing fields results in no recorded change in the repository including unchanged audit fields.")
|
||||
public void updateNothingResultsInUnchangedRepositoryForType() {
|
||||
final SoftwareModuleType created = softwareManagement
|
||||
.createSoftwareModuleType(new SoftwareModuleType("test-key", "test-name", "test-desc", 1));
|
||||
|
||||
final SoftwareModuleType updated = softwareManagement.updateSoftwareModuleType(created);
|
||||
|
||||
assertThat(updated.getOptLockRevision())
|
||||
.as("Expected version number of updated entitity to be equal to created version")
|
||||
.isEqualTo(created.getOptLockRevision());
|
||||
}
|
||||
|
||||
@Test
|
||||
@Description("Calling update for changed fields results in change in the repository.")
|
||||
public void updateSoftareModuleTypeFieldsToNewValue() {
|
||||
final SoftwareModuleType created = softwareManagement
|
||||
.createSoftwareModuleType(new SoftwareModuleType("test-key", "test-name", "test-desc", 1));
|
||||
|
||||
created.setDescription("changed");
|
||||
created.setColour("changed");
|
||||
|
||||
final SoftwareModuleType updated = softwareManagement.updateSoftwareModuleType(created);
|
||||
|
||||
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("Try to update non updatable fields results in repository doing nothing.")
|
||||
public void updateNonUpdateableFieldsFails() {
|
||||
final SoftwareModule ah = softwareManagement
|
||||
.createSoftwareModule(new SoftwareModule(appType, "agent-hub", "1.0.1", null, ""));
|
||||
|
||||
ah.setName("a new name");
|
||||
final SoftwareModule updated = softwareManagement.updateSoftwareModule(ah);
|
||||
|
||||
assertThat(updated.getOptLockRevision())
|
||||
.as("Expected version number of updated entitity to be equal to created version")
|
||||
.isEqualTo(ah.getOptLockRevision());
|
||||
}
|
||||
|
||||
@Test
|
||||
@Description("Calling update without changing fields results in no recorded change in the repository including unchanged audit fields.")
|
||||
public void updateNothingResultsInUnchangedRepository() {
|
||||
final SoftwareModule ah = softwareManagement
|
||||
.createSoftwareModule(new SoftwareModule(appType, "agent-hub", "1.0.1", null, ""));
|
||||
|
||||
final SoftwareModule updated = softwareManagement.updateSoftwareModule(ah);
|
||||
|
||||
assertThat(updated.getOptLockRevision())
|
||||
.as("Expected version number of updated entitity to be equal to created version")
|
||||
.isEqualTo(ah.getOptLockRevision());
|
||||
}
|
||||
|
||||
@Test
|
||||
@Description("Calling update for changed fields results in change in the repository.")
|
||||
public void updateSoftareModuleFieldsToNewValue() {
|
||||
final SoftwareModule ah = softwareManagement
|
||||
.createSoftwareModule(new SoftwareModule(appType, "agent-hub", "1.0.1", "test desc", "test vendor"));
|
||||
|
||||
ah.setDescription("changed");
|
||||
ah.setVendor("changed");
|
||||
final SoftwareModule updated = softwareManagement.updateSoftwareModule(ah);
|
||||
|
||||
assertThat(updated.getOptLockRevision()).as("Expected version number of updated entitity is")
|
||||
.isEqualTo(ah.getOptLockRevision() + 1);
|
||||
assertThat(updated.getDescription()).as("Updated description is").isEqualTo("changed");
|
||||
assertThat(updated.getVendor()).as("Updated vendor is").isEqualTo("changed");
|
||||
}
|
||||
|
||||
@Test
|
||||
@Description("Create Software Module call fails when called for existing entity.")
|
||||
public void createModuleCallFailsForExistingModule() {
|
||||
final SoftwareModule ah = softwareManagement
|
||||
.createSoftwareModule(new SoftwareModule(appType, "agent-hub", "1.0.1", "test desc", "test vendor"));
|
||||
try {
|
||||
softwareManagement.createSoftwareModule(ah);
|
||||
fail("Should not have worked as module already exists.");
|
||||
} catch (final EntityAlreadyExistsException e) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@Description("Create Software Modules call fails when called for existing entities.")
|
||||
public void createModulesCallFailsForExistingModule() {
|
||||
final List<SoftwareModule> modules = softwareManagement.createSoftwareModule(
|
||||
Lists.newArrayList(new SoftwareModule(appType, "agent-hub", "1.0.1", "test desc", "test vendor"),
|
||||
new SoftwareModule(appType, "agent-hub", "1.0.2", "test desc", "test vendor")));
|
||||
try {
|
||||
softwareManagement.createSoftwareModule(modules);
|
||||
fail("Should not have worked as module already exists.");
|
||||
} catch (final EntityAlreadyExistsException e) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@Description("Create Software Module Type call fails when called for existing entity.")
|
||||
public void createModuleTypeCallFailsForExistingType() {
|
||||
final SoftwareModuleType created = softwareManagement
|
||||
.createSoftwareModuleType(new SoftwareModuleType("test-key", "test-name", "test-desc", 1));
|
||||
|
||||
try {
|
||||
softwareManagement.createSoftwareModuleType(created);
|
||||
fail("Should not have worked as module already exists.");
|
||||
} catch (final EntityAlreadyExistsException e) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@Description("Create Software Module Types call fails when called for existing entities.")
|
||||
public void createModuleTypesCallFailsForExistingTypes() {
|
||||
final List<SoftwareModuleType> created = softwareManagement.createSoftwareModuleType(
|
||||
Lists.newArrayList(new SoftwareModuleType("test-key-bumlux", "test-name", "test-desc", 1),
|
||||
new SoftwareModuleType("test-key-bumlux2", "test-name2", "test-desc", 1)));
|
||||
|
||||
try {
|
||||
softwareManagement.createSoftwareModuleType(created);
|
||||
fail("Should not have worked as module already exists.");
|
||||
} catch (final EntityAlreadyExistsException e) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@Description("Calling update for changing fields to null results in change in the repository.")
|
||||
public void eraseSoftareModuleFields() {
|
||||
final SoftwareModule ah = softwareManagement
|
||||
.createSoftwareModule(new SoftwareModule(appType, "agent-hub", "1.0.1", "test desc", "test vendor"));
|
||||
|
||||
ah.setDescription(null);
|
||||
ah.setVendor(null);
|
||||
final SoftwareModule updated = softwareManagement.updateSoftwareModule(ah);
|
||||
|
||||
assertThat(updated.getOptLockRevision()).as("Expected version number of updated entitity is")
|
||||
.isEqualTo(ah.getOptLockRevision() + 1);
|
||||
assertThat(updated.getDescription()).as("Updated description is").isNull();
|
||||
assertThat(updated.getVendor()).as("Updated vendor is").isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
@Description("searched for software modules based on the various filter options, e.g. name,desc,type, version.")
|
||||
public void findSoftwareModuleByFilters() {
|
||||
@@ -105,7 +268,7 @@ public class SoftwareManagementTest extends AbstractIntegrationTestWithMongoDB {
|
||||
|
||||
@Test
|
||||
@Description("Searches for software modules based on a list of IDs.")
|
||||
public void findSoftwareModulesByIdAndType() {
|
||||
public void findSoftwareModulesById() {
|
||||
|
||||
final List<Long> modules = new ArrayList<Long>();
|
||||
|
||||
@@ -118,6 +281,54 @@ public class SoftwareManagementTest extends AbstractIntegrationTestWithMongoDB {
|
||||
assertThat(softwareManagement.findSoftwareModulesById(modules)).hasSize(2);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Description("Searches for software modules by type.")
|
||||
public void findSoftwareModulesByType() {
|
||||
// found in test
|
||||
final SoftwareModule one = softwareManagement
|
||||
.createSoftwareModule(new SoftwareModule(osType, "one", "one", null, ""));
|
||||
final SoftwareModule two = softwareManagement
|
||||
.createSoftwareModule(new SoftwareModule(osType, "two", "two", null, ""));
|
||||
// ignored
|
||||
softwareManagement.deleteSoftwareModule(
|
||||
softwareManagement.createSoftwareModule(new SoftwareModule(osType, "deleted", "deleted", null, "")));
|
||||
softwareManagement.createSoftwareModule(new SoftwareModule(appType, "three", "3.0.2", null, ""));
|
||||
|
||||
assertThat(softwareManagement.findSoftwareModulesByType(pageReq, osType).getContent())
|
||||
.as("Expected to find the following number of modules:").hasSize(2).as("with the following elements")
|
||||
.contains(two, one);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Description("Counts all software modules in the repsitory that are not marked as deleted.")
|
||||
public void countSoftwareModulesAll() {
|
||||
// found in test
|
||||
softwareManagement.createSoftwareModule(new SoftwareModule(osType, "one", "one", null, ""));
|
||||
softwareManagement.createSoftwareModule(new SoftwareModule(appType, "two", "two", null, ""));
|
||||
// ignored
|
||||
softwareManagement.deleteSoftwareModule(
|
||||
softwareManagement.createSoftwareModule(new SoftwareModule(osType, "deleted", "deleted", null, "")));
|
||||
|
||||
assertThat(softwareManagement.countSoftwareModulesAll()).as("Expected to find the following number of modules:")
|
||||
.isEqualTo(2);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Description("Counts for software modules by type.")
|
||||
public void countSoftwareModulesByType() {
|
||||
// found in test
|
||||
softwareManagement.createSoftwareModule(new SoftwareModule(osType, "one", "one", null, ""));
|
||||
softwareManagement.createSoftwareModule(new SoftwareModule(osType, "two", "two", null, ""));
|
||||
|
||||
// ignored
|
||||
softwareManagement.deleteSoftwareModule(
|
||||
softwareManagement.createSoftwareModule(new SoftwareModule(osType, "deleted", "deleted", null, "")));
|
||||
softwareManagement.createSoftwareModule(new SoftwareModule(appType, "three", "3.0.2", null, ""));
|
||||
|
||||
assertThat(softwareManagement.countSoftwareModulesByType(osType))
|
||||
.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() {
|
||||
@@ -419,32 +630,194 @@ public class SoftwareManagementTest extends AbstractIntegrationTestWithMongoDB {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param findAll
|
||||
* @return
|
||||
*/
|
||||
@SuppressWarnings("rawtypes")
|
||||
private Collection iterable2Collection(final Iterable iterable) {
|
||||
final Collection<Object> col = new ArrayList<Object>();
|
||||
for (final Object o : iterable) {
|
||||
col.add(o);
|
||||
}
|
||||
return col;
|
||||
@Test
|
||||
@Description("Test verfies that results are returned based on given filter parameters and in the specified order.")
|
||||
public void findSoftwareModuleOrderByDistributionModuleNameAscModuleVersionAsc() {
|
||||
// test meta data
|
||||
final SoftwareModuleType testType = softwareManagement
|
||||
.createSoftwareModuleType(new SoftwareModuleType("thetype", "thename", "desc", 100));
|
||||
final DistributionSetType testDsType = distributionSetManagement
|
||||
.createDistributionSetType(new DistributionSetType("key", "name", "desc").addMandatoryModuleType(osType)
|
||||
.addOptionalModuleType(testType));
|
||||
|
||||
// found in test
|
||||
final SoftwareModule unassigned = softwareManagement
|
||||
.createSoftwareModule(new SoftwareModule(testType, "asis", "found", null, ""));
|
||||
final SoftwareModule one = softwareManagement
|
||||
.createSoftwareModule(new SoftwareModule(testType, "found", "b", null, ""));
|
||||
final SoftwareModule two = softwareManagement
|
||||
.createSoftwareModule(new SoftwareModule(testType, "found", "c", null, ""));
|
||||
final SoftwareModule differentName = softwareManagement
|
||||
.createSoftwareModule(new SoftwareModule(testType, "differentname", "d", null, ""));
|
||||
|
||||
// ignored
|
||||
final SoftwareModule deleted = softwareManagement
|
||||
.createSoftwareModule(new SoftwareModule(testType, "deleted", "deleted", null, ""));
|
||||
final SoftwareModule four = softwareManagement
|
||||
.createSoftwareModule(new SoftwareModule(osType, "sdfjhsdj", "e", null, ""));
|
||||
|
||||
final DistributionSet set = distributionSetManagement.createDistributionSet(new DistributionSet("set", "1",
|
||||
"desc", testDsType, Lists.newArrayList(one, two, deleted, four, differentName)));
|
||||
softwareManagement.deleteSoftwareModule(deleted);
|
||||
|
||||
// with filter on name, version and module type
|
||||
assertThat(softwareManagement.findSoftwareModuleOrderBySetAssignmentAndModuleNameAscModuleVersionAsc(pageReq,
|
||||
set.getId(), "found", testType).getContent())
|
||||
.as("Found modules with given name, given module type and the assigned ones first")
|
||||
.containsExactly(new CustomSoftwareModule(one, true), new CustomSoftwareModule(two, true),
|
||||
new CustomSoftwareModule(unassigned, false));
|
||||
|
||||
// with filter on module type only
|
||||
assertThat(softwareManagement.findSoftwareModuleOrderBySetAssignmentAndModuleNameAscModuleVersionAsc(pageReq,
|
||||
set.getId(), null, testType).getContent())
|
||||
.as("Found modules with given module type and the assigned ones first").containsExactly(
|
||||
new CustomSoftwareModule(differentName, true), new CustomSoftwareModule(one, true),
|
||||
new CustomSoftwareModule(two, true), new CustomSoftwareModule(unassigned, false));
|
||||
|
||||
// without any filter
|
||||
assertThat(softwareManagement.findSoftwareModuleOrderBySetAssignmentAndModuleNameAscModuleVersionAsc(pageReq,
|
||||
set.getId(), null, null).getContent()).as("Found modules with the assigned ones first").containsExactly(
|
||||
new CustomSoftwareModule(differentName, true), new CustomSoftwareModule(one, true),
|
||||
new CustomSoftwareModule(two, true), new CustomSoftwareModule(four, true),
|
||||
new CustomSoftwareModule(unassigned, false));
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private void printDSTags() {
|
||||
System.out.println("==============================================================================");
|
||||
for (final DistributionSet d : distributionSetRepository.findAll()) {
|
||||
System.out.printf("%s\t[", d.getName());
|
||||
for (final DistributionSetTag t : d.getTags()) {
|
||||
System.out.printf("%s ", t.getName());
|
||||
}
|
||||
System.out.println("]");
|
||||
@Test
|
||||
@Description("Checks that number of modules is returned as expected based on given filters.")
|
||||
public void countSoftwareModuleByFilters() {
|
||||
|
||||
// test meta data
|
||||
final SoftwareModuleType testType = softwareManagement
|
||||
.createSoftwareModuleType(new SoftwareModuleType("thetype", "thename", "desc", 100));
|
||||
final DistributionSetType testDsType = distributionSetManagement
|
||||
.createDistributionSetType(new DistributionSetType("key", "name", "desc").addMandatoryModuleType(osType)
|
||||
.addOptionalModuleType(testType));
|
||||
|
||||
// test modules
|
||||
softwareManagement.createSoftwareModule(new SoftwareModule(testType, "asis", "found", null, ""));
|
||||
final SoftwareModule one = softwareManagement
|
||||
.createSoftwareModule(new SoftwareModule(testType, "found", "b", null, ""));
|
||||
final SoftwareModule two = softwareManagement
|
||||
.createSoftwareModule(new SoftwareModule(testType, "found", "c", null, ""));
|
||||
final SoftwareModule differentName = softwareManagement
|
||||
.createSoftwareModule(new SoftwareModule(testType, "differentname", "d", null, ""));
|
||||
final SoftwareModule four = softwareManagement
|
||||
.createSoftwareModule(new SoftwareModule(osType, "found", "3.0.2", null, ""));
|
||||
|
||||
// one soft deleted
|
||||
final SoftwareModule deleted = softwareManagement
|
||||
.createSoftwareModule(new SoftwareModule(testType, "deleted", "deleted", null, ""));
|
||||
distributionSetManagement.createDistributionSet(new DistributionSet("set", "1", "desc", testDsType,
|
||||
Lists.newArrayList(one, two, deleted, four, differentName)));
|
||||
softwareManagement.deleteSoftwareModule(deleted);
|
||||
|
||||
// test
|
||||
assertThat(softwareManagement.countSoftwareModuleByFilters("found", testType))
|
||||
.as("Number of modules with given name or version and type").isEqualTo(3);
|
||||
assertThat(softwareManagement.countSoftwareModuleByFilters(null, testType))
|
||||
.as("Number of modules with given type").isEqualTo(4);
|
||||
assertThat(softwareManagement.countSoftwareModuleByFilters(null, null)).as("Number of modules overall")
|
||||
.isEqualTo(5);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Description("Verfies that all undeleted software modules are found in the repository.")
|
||||
public void countSoftwareModuleTypesAll() {
|
||||
final SoftwareModuleType testType = softwareManagement
|
||||
.createSoftwareModuleType(new SoftwareModuleType("thetype", "thename", "desc", 100));
|
||||
final DistributionSetType testDsType = distributionSetManagement
|
||||
.createDistributionSetType(new DistributionSetType("key", "name", "desc").addMandatoryModuleType(osType)
|
||||
.addOptionalModuleType(testType));
|
||||
final SoftwareModule four = softwareManagement
|
||||
.createSoftwareModule(new SoftwareModule(osType, "found", "3.0.2", null, ""));
|
||||
|
||||
// one soft deleted
|
||||
final SoftwareModule deleted = softwareManagement
|
||||
.createSoftwareModule(new SoftwareModule(testType, "deleted", "deleted", null, ""));
|
||||
distributionSetManagement.createDistributionSet(
|
||||
new DistributionSet("set", "1", "desc", testDsType, Lists.newArrayList(deleted, four)));
|
||||
softwareManagement.deleteSoftwareModule(deleted);
|
||||
|
||||
assertThat(softwareManagement.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() {
|
||||
final SoftwareModuleType found = softwareManagement
|
||||
.createSoftwareModuleType(new SoftwareModuleType("thetype", "thename", "desc", 100));
|
||||
softwareManagement.createSoftwareModuleType(new SoftwareModuleType("thetype2", "anothername", "desc", 100));
|
||||
|
||||
assertThat(softwareManagement.findSoftwareModuleTypeByName("thename")).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(new SoftwareModuleType("thetype", "thename", "desc", 100));
|
||||
try {
|
||||
softwareManagement.createSoftwareModuleType(created);
|
||||
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(new SoftwareModuleType("thetype", "thename", "desc", 100));
|
||||
try {
|
||||
softwareManagement.createSoftwareModuleType(
|
||||
Lists.newArrayList(created, new SoftwareModuleType("anothertype", "anothername", "desc", 100)));
|
||||
fail("should not have worked as module type already exists");
|
||||
} catch (final EntityAlreadyExistsException e) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@Description("Verfies that multiple types are created as requested.")
|
||||
public void createMultipleoftwareModuleTypes() {
|
||||
final List<SoftwareModuleType> created = softwareManagement
|
||||
.createSoftwareModuleType(Lists.newArrayList(new SoftwareModuleType("thetype", "thename", "desc", 100),
|
||||
new SoftwareModuleType("thetype2", "thename2", "desc2", 100)));
|
||||
|
||||
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 sofwtare modules are resturned that are assigned to given DS.")
|
||||
public void findSoftwareModuleByAssignedTo() {
|
||||
// test meta data
|
||||
final SoftwareModuleType testType = softwareManagement
|
||||
.createSoftwareModuleType(new SoftwareModuleType("thetype", "thename", "desc", 100));
|
||||
final DistributionSetType testDsType = distributionSetManagement
|
||||
.createDistributionSetType(new DistributionSetType("key", "name", "desc").addMandatoryModuleType(osType)
|
||||
.addOptionalModuleType(testType));
|
||||
|
||||
// test modules
|
||||
softwareManagement.createSoftwareModule(new SoftwareModule(testType, "asis", "found", null, ""));
|
||||
final SoftwareModule one = softwareManagement
|
||||
.createSoftwareModule(new SoftwareModule(testType, "found", "b", null, ""));
|
||||
final SoftwareModule two = softwareManagement
|
||||
.createSoftwareModule(new SoftwareModule(testType, "found", "c", null, ""));
|
||||
|
||||
// one soft deleted
|
||||
final SoftwareModule deleted = softwareManagement
|
||||
.createSoftwareModule(new SoftwareModule(testType, "deleted", "deleted", null, ""));
|
||||
final DistributionSet set = distributionSetManagement.createDistributionSet(
|
||||
new DistributionSet("set", "1", "desc", testDsType, Lists.newArrayList(one, deleted)));
|
||||
softwareManagement.deleteSoftwareModule(deleted);
|
||||
|
||||
assertThat(softwareManagement.findSoftwareModuleByAssignedTo(pageReq, set).getContent())
|
||||
.as("Found this number of modules").hasSize(2);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -479,6 +852,27 @@ public class SoftwareManagementTest extends AbstractIntegrationTestWithMongoDB {
|
||||
assertThat(softwareModuleMetadata.get(0).getSoftwareModule().getId()).isEqualTo(ah.getId());
|
||||
}
|
||||
|
||||
@Test
|
||||
@Description("Checks that metadata for a software module cannot be created for an existing key.")
|
||||
public void createSoftwareModuleMetadataFailsIfKeyExists() {
|
||||
|
||||
final String knownKey1 = "myKnownKey1";
|
||||
final String knownValue1 = "myKnownValue1";
|
||||
final String knownValue2 = "myKnownValue2";
|
||||
|
||||
final SoftwareModule ah = softwareManagement
|
||||
.createSoftwareModule(new SoftwareModule(appType, "agent-hub", "1.0.1", null, ""));
|
||||
|
||||
softwareManagement.createSoftwareModuleMetadata(new SoftwareModuleMetadata(knownKey1, ah, knownValue1));
|
||||
|
||||
try {
|
||||
softwareManagement.createSoftwareModuleMetadata(new SoftwareModuleMetadata(knownKey1, ah, knownValue2));
|
||||
fail("should not have worked as module metadata already exists");
|
||||
} catch (final EntityAlreadyExistsException e) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@WithUser(allSpPermissions = true)
|
||||
@Description("Checks that metadata for a software module can be updated.")
|
||||
@@ -525,6 +919,47 @@ public class SoftwareManagementTest extends AbstractIntegrationTestWithMongoDB {
|
||||
assertThat(updated.getSoftwareModule().getId()).isEqualTo(ah.getId());
|
||||
}
|
||||
|
||||
@Test
|
||||
@Description("Verfies that existing metadata can be deleted.")
|
||||
public void deleteSoftwareModuleMetadata() {
|
||||
final String knownKey1 = "myKnownKey1";
|
||||
final String knownValue1 = "myKnownValue1";
|
||||
|
||||
SoftwareModule ah = softwareManagement
|
||||
.createSoftwareModule(new SoftwareModule(appType, "agent-hub", "1.0.1", null, ""));
|
||||
|
||||
ah = softwareManagement.createSoftwareModuleMetadata(new SoftwareModuleMetadata(knownKey1, ah, knownValue1))
|
||||
.getSoftwareModule();
|
||||
|
||||
assertThat(softwareManagement.findSoftwareModuleById(ah.getId()).getMetadata())
|
||||
.as("Contains the created metadata element")
|
||||
.containsExactly(new SoftwareModuleMetadata(knownKey1, ah, knownValue1));
|
||||
|
||||
softwareManagement.deleteSoftwareModuleMetadata(new SwMetadataCompositeKey(ah, knownKey1));
|
||||
assertThat(softwareManagement.findSoftwareModuleById(ah.getId()).getMetadata()).as("Metadata elemenets are")
|
||||
.isEmpty();
|
||||
}
|
||||
|
||||
@Test
|
||||
@Description("Verfies that non existing metadata find results in exception.")
|
||||
public void findSoftwareModuleMetadataFailsIfEntryDoesNotExist() {
|
||||
final String knownKey1 = "myKnownKey1";
|
||||
final String knownValue1 = "myKnownValue1";
|
||||
|
||||
SoftwareModule ah = softwareManagement
|
||||
.createSoftwareModule(new SoftwareModule(appType, "agent-hub", "1.0.1", null, ""));
|
||||
|
||||
ah = softwareManagement.createSoftwareModuleMetadata(new SoftwareModuleMetadata(knownKey1, ah, knownValue1))
|
||||
.getSoftwareModule();
|
||||
|
||||
try {
|
||||
softwareManagement.findSoftwareModuleMetadata(new SwMetadataCompositeKey(ah, "doesnotexist"));
|
||||
fail("should not have worked as module metadata with that key does not exist");
|
||||
} catch (final EntityNotFoundException e) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@Description("Queries and loads the metadata related to a given software module.")
|
||||
public void findAllSoftwareModuleMetadataBySwId() {
|
||||
|
||||
@@ -12,7 +12,10 @@ import static org.fest.assertions.api.Assertions.assertThat;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.eclipse.hawkbit.AbstractIntegrationTest;
|
||||
import org.eclipse.hawkbit.TestDataUtil;
|
||||
@@ -20,9 +23,11 @@ import org.eclipse.hawkbit.repository.DistributionSetFilter.DistributionSetFilte
|
||||
import org.eclipse.hawkbit.repository.exception.EntityAlreadyExistsException;
|
||||
import org.eclipse.hawkbit.repository.model.DistributionSet;
|
||||
import org.eclipse.hawkbit.repository.model.DistributionSetTag;
|
||||
import org.eclipse.hawkbit.repository.model.DistributionSetTagAssignmentResult;
|
||||
import org.eclipse.hawkbit.repository.model.Tag;
|
||||
import org.eclipse.hawkbit.repository.model.Target;
|
||||
import org.eclipse.hawkbit.repository.model.TargetTag;
|
||||
import org.eclipse.hawkbit.repository.model.TargetTagAssignmentResult;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.slf4j.LoggerFactory;
|
||||
@@ -158,6 +163,98 @@ public class TagManagementTest extends AbstractIntegrationTest {
|
||||
return new DistributionSetFilterBuilder();
|
||||
}
|
||||
|
||||
@Test
|
||||
@Description("Verifies the toogle mechanism by means on assigning tag if at least on DS in the list does not have"
|
||||
+ "the tag yet. Unassign if all of them have the tag already.")
|
||||
public void assignAndUnassignDistributionSetTags() {
|
||||
final List<DistributionSet> groupA = TestDataUtil.generateDistributionSets(20, softwareManagement,
|
||||
distributionSetManagement);
|
||||
final List<DistributionSet> groupB = TestDataUtil.generateDistributionSets("unassigned", 20, softwareManagement,
|
||||
distributionSetManagement);
|
||||
|
||||
final DistributionSetTag tag = tagManagement
|
||||
.createDistributionSetTag(new DistributionSetTag("tag1", "tagdesc1", ""));
|
||||
|
||||
// toggle A only -> A is now assigned
|
||||
DistributionSetTagAssignmentResult result = distributionSetManagement.toggleTagAssignment(groupA, tag);
|
||||
assertThat(result.getAlreadyAssigned()).isEqualTo(0);
|
||||
assertThat(result.getAssigned()).isEqualTo(20);
|
||||
assertThat(result.getAssignedDs()).containsAll(distributionSetManagement.findDistributionSetListWithDetails(
|
||||
groupA.stream().map(set -> set.getId()).collect(Collectors.toList())));
|
||||
assertThat(result.getUnassigned()).isEqualTo(0);
|
||||
assertThat(result.getUnassignedDs()).isEmpty();
|
||||
assertThat(result.getDistributionSetTag()).isEqualTo(tag);
|
||||
|
||||
// toggle A+B -> A is still assigned and B is assigned as well
|
||||
result = distributionSetManagement.toggleTagAssignment(concat(groupA, groupB), tag);
|
||||
assertThat(result.getAlreadyAssigned()).isEqualTo(20);
|
||||
assertThat(result.getAssigned()).isEqualTo(20);
|
||||
assertThat(result.getAssignedDs()).containsAll(distributionSetManagement.findDistributionSetListWithDetails(
|
||||
groupB.stream().map(set -> set.getId()).collect(Collectors.toList())));
|
||||
assertThat(result.getUnassigned()).isEqualTo(0);
|
||||
assertThat(result.getUnassignedDs()).isEmpty();
|
||||
assertThat(result.getDistributionSetTag()).isEqualTo(tag);
|
||||
|
||||
// toggle A+B -> both unassigned
|
||||
result = distributionSetManagement.toggleTagAssignment(concat(groupA, groupB), tag);
|
||||
assertThat(result.getAlreadyAssigned()).isEqualTo(0);
|
||||
assertThat(result.getAssigned()).isEqualTo(0);
|
||||
assertThat(result.getAssignedDs()).isEmpty();
|
||||
assertThat(result.getUnassigned()).isEqualTo(40);
|
||||
assertThat(result.getUnassignedDs()).containsAll(distributionSetManagement.findDistributionSetListWithDetails(
|
||||
concat(groupB, groupA).stream().map(set -> set.getId()).collect(Collectors.toList())));
|
||||
assertThat(result.getDistributionSetTag()).isEqualTo(tag);
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
@Description("Verifies the toogle mechanism by means on assigning tag if at least on target in the list does not have"
|
||||
+ "the tag yet. Unassign if all of them have the tag already.")
|
||||
public void assignAndUnassignTargetTags() {
|
||||
final List<Target> groupA = targetManagement.createTargets(TestDataUtil.generateTargets(20, ""));
|
||||
final List<Target> groupB = targetManagement.createTargets(TestDataUtil.generateTargets(20, "groupb"));
|
||||
|
||||
final TargetTag tag = tagManagement.createTargetTag(new TargetTag("tag1", "tagdesc1", ""));
|
||||
|
||||
// toggle A only -> A is now assigned
|
||||
TargetTagAssignmentResult result = targetManagement.toggleTagAssignment(groupA, tag);
|
||||
assertThat(result.getAlreadyAssigned()).isEqualTo(0);
|
||||
assertThat(result.getAssigned()).isEqualTo(20);
|
||||
assertThat(result.getAssignedTargets()).containsAll(targetManagement.findTargetsByControllerIDsWithTags(
|
||||
groupA.stream().map(target -> target.getControllerId()).collect(Collectors.toList())));
|
||||
assertThat(result.getUnassigned()).isEqualTo(0);
|
||||
assertThat(result.getUnassignedTargets()).isEmpty();
|
||||
assertThat(result.getTargetTag()).isEqualTo(tag);
|
||||
|
||||
// toggle A+B -> A is still assigned and B is assigned as well
|
||||
result = targetManagement.toggleTagAssignment(concat(groupA, groupB), tag);
|
||||
assertThat(result.getAlreadyAssigned()).isEqualTo(20);
|
||||
assertThat(result.getAssigned()).isEqualTo(20);
|
||||
assertThat(result.getAssignedTargets()).containsAll(targetManagement.findTargetsByControllerIDsWithTags(
|
||||
groupB.stream().map(target -> target.getControllerId()).collect(Collectors.toList())));
|
||||
assertThat(result.getUnassigned()).isEqualTo(0);
|
||||
assertThat(result.getUnassignedTargets()).isEmpty();
|
||||
assertThat(result.getTargetTag()).isEqualTo(tag);
|
||||
|
||||
// toggle A+B -> both unassigned
|
||||
result = targetManagement.toggleTagAssignment(concat(groupA, groupB), tag);
|
||||
assertThat(result.getAlreadyAssigned()).isEqualTo(0);
|
||||
assertThat(result.getAssigned()).isEqualTo(0);
|
||||
assertThat(result.getAssignedTargets()).isEmpty();
|
||||
assertThat(result.getUnassigned()).isEqualTo(40);
|
||||
assertThat(result.getUnassignedTargets()).containsAll(targetManagement.findTargetsByControllerIDsWithTags(
|
||||
concat(groupB, groupA).stream().map(target -> target.getControllerId()).collect(Collectors.toList())));
|
||||
assertThat(result.getTargetTag()).isEqualTo(tag);
|
||||
|
||||
}
|
||||
|
||||
@SafeVarargs
|
||||
private final <T> List<T> concat(final List<T>... targets) {
|
||||
final List<T> result = new ArrayList<>();
|
||||
Arrays.asList(targets).forEach(result::addAll);
|
||||
return result;
|
||||
}
|
||||
|
||||
@Test
|
||||
@Description("Ensures that all tags are retrieved through repository.")
|
||||
public void findAllTargetTags() {
|
||||
@@ -266,47 +363,58 @@ public class TagManagementTest extends AbstractIntegrationTest {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@Description("Ensures that a tag cannot be created if one exists already with that name (ecpects EntityAlreadyExistsException).")
|
||||
public void failedDuplicateTargetTagNameException() {
|
||||
tagManagement.createTargetTag(new TargetTag("A"));
|
||||
|
||||
try {
|
||||
tagManagement.createTargetTag(new TargetTag("A"));
|
||||
fail("Expected EntityAlreadyExistsException");
|
||||
fail("should not have worked as tag already exists");
|
||||
} catch (final EntityAlreadyExistsException e) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@Description("Ensures that a tag cannot be updated to a name that already exists on another tag (ecpects EntityAlreadyExistsException).")
|
||||
public void failedDuplicateTargetTagNameExceptionAfterUpdate() {
|
||||
tagManagement.createTargetTag(new TargetTag("A"));
|
||||
final TargetTag tag = tagManagement.createTargetTag(new TargetTag("B"));
|
||||
tag.setName("A");
|
||||
|
||||
try {
|
||||
tagManagement.updateTargetTag(tag);
|
||||
fail("Expected EntityAlreadyExistsException");
|
||||
fail("should not have worked as tag already exists");
|
||||
} catch (final EntityAlreadyExistsException e) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@Description("Ensures that a tag cannot be created if one exists already with that name (ecpects EntityAlreadyExistsException).")
|
||||
public void failedDuplicateDsTagNameException() {
|
||||
tagManagement.createDistributionSetTag(new DistributionSetTag("A"));
|
||||
try {
|
||||
tagManagement.createDistributionSetTag(new DistributionSetTag("A"));
|
||||
fail("Expected EntityAlreadyExistsException");
|
||||
fail("should not have worked as tag already exists");
|
||||
} catch (final EntityAlreadyExistsException e) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@Description("Ensures that a tag cannot be updated to a name that already exists on another tag (ecpects EntityAlreadyExistsException).")
|
||||
public void failedDuplicateDsTagNameExceptionAfterUpdate() {
|
||||
tagManagement.createDistributionSetTag(new DistributionSetTag("A"));
|
||||
final DistributionSetTag tag = tagManagement.createDistributionSetTag(new DistributionSetTag("B"));
|
||||
tag.setName("A");
|
||||
|
||||
try {
|
||||
tagManagement.updateDistributionSetTag(tag);
|
||||
fail("Expected EntityAlreadyExistsException");
|
||||
fail("should not have worked as tag already exists");
|
||||
} catch (final EntityAlreadyExistsException e) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
package org.eclipse.hawkbit.repository;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
import org.eclipse.hawkbit.AbstractIntegrationTest;
|
||||
import org.eclipse.hawkbit.repository.exception.EntityAlreadyExistsException;
|
||||
@@ -22,10 +23,7 @@ import ru.yandex.qatools.allure.annotations.Stories;
|
||||
/**
|
||||
* Test class for {@link TargetFilterQueryManagement}.
|
||||
*
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
@Features("Component Tests - Repository")
|
||||
@Stories("Target Filter Query Management")
|
||||
public class TargetFilterQueryManagenmentTest extends AbstractIntegrationTest {
|
||||
@@ -40,15 +38,20 @@ public class TargetFilterQueryManagenmentTest extends AbstractIntegrationTest {
|
||||
targetFilterQueryManagement.findTargetFilterQueryByName(filterName));
|
||||
}
|
||||
|
||||
@Test(expected = EntityAlreadyExistsException.class)
|
||||
@Test
|
||||
@Description("Checks if the EntityAlreadyExistsException is thrown if a targetfilterquery with the same name are created more than once.")
|
||||
public void createDuplicateTargetFilterQuery() {
|
||||
final String filterName = "new target filter duplicate";
|
||||
targetFilterQueryManagement
|
||||
.createTargetFilterQuery(new TargetFilterQuery(filterName, "name==PendingTargets001"));
|
||||
|
||||
targetFilterQueryManagement
|
||||
.createTargetFilterQuery(new TargetFilterQuery(filterName, "name==PendingTargets001"));
|
||||
try {
|
||||
targetFilterQueryManagement
|
||||
.createTargetFilterQuery(new TargetFilterQuery(filterName, "name==PendingTargets001"));
|
||||
fail("should not have worked as query already exists");
|
||||
} catch (final EntityAlreadyExistsException e) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -11,28 +11,34 @@ package org.eclipse.hawkbit.repository;
|
||||
import static org.fest.assertions.api.Assertions.assertThat;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.eclipse.hawkbit.AbstractIntegrationTest;
|
||||
import org.eclipse.hawkbit.TestDataUtil;
|
||||
import org.eclipse.hawkbit.repository.model.Action;
|
||||
import org.eclipse.hawkbit.repository.model.Action.Status;
|
||||
import org.eclipse.hawkbit.repository.model.ActionStatus;
|
||||
import org.eclipse.hawkbit.repository.model.TenantAwareBaseEntity;
|
||||
import org.eclipse.hawkbit.repository.model.DistributionSet;
|
||||
import org.eclipse.hawkbit.repository.model.Target;
|
||||
import org.eclipse.hawkbit.repository.model.TargetFilterQuery;
|
||||
import org.eclipse.hawkbit.repository.model.TargetIdName;
|
||||
import org.eclipse.hawkbit.repository.model.TargetTag;
|
||||
import org.eclipse.hawkbit.repository.model.TargetUpdateStatus;
|
||||
import org.eclipse.hawkbit.repository.model.TenantAwareBaseEntity;
|
||||
import org.eclipse.hawkbit.repository.specifications.TargetSpecifications;
|
||||
import org.junit.Test;
|
||||
import org.springframework.data.domain.PageRequest;
|
||||
import org.springframework.data.domain.Slice;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.primitives.Ints;
|
||||
|
||||
import ru.yandex.qatools.allure.annotations.Description;
|
||||
import ru.yandex.qatools.allure.annotations.Features;
|
||||
import ru.yandex.qatools.allure.annotations.Step;
|
||||
import ru.yandex.qatools.allure.annotations.Stories;
|
||||
|
||||
@Features("Component Tests - Repository")
|
||||
@@ -40,152 +46,626 @@ import ru.yandex.qatools.allure.annotations.Stories;
|
||||
public class TargetManagementSearchTest extends AbstractIntegrationTest {
|
||||
|
||||
@Test
|
||||
@Description("Tests different parameter combinations for target search operations. That includes both the test itself as a count operation with the same filters.")
|
||||
@Description("Tests different parameter combinations for target search operations. "
|
||||
+ "That includes both the test itself, as a count operation with the same filters "
|
||||
+ "and query definitions by RSQL (named and un-named).")
|
||||
public void targetSearchWithVariousFilterCombinations() {
|
||||
final TargetTag targTagA = tagManagement.createTargetTag(new TargetTag("TargTag-A"));
|
||||
final TargetTag targTagB = tagManagement.createTargetTag(new TargetTag("TargTag-B"));
|
||||
final TargetTag targTagC = tagManagement.createTargetTag(new TargetTag("TargTag-C"));
|
||||
final TargetTag targTagD = tagManagement.createTargetTag(new TargetTag("TargTag-D"));
|
||||
|
||||
// TODO kaizimmerm: test also installedDS (not only assignedDS)
|
||||
final TargetTag targTagX = tagManagement.createTargetTag(new TargetTag("TargTag-X"));
|
||||
final TargetTag targTagY = tagManagement.createTargetTag(new TargetTag("TargTag-Y"));
|
||||
final TargetTag targTagZ = tagManagement.createTargetTag(new TargetTag("TargTag-Z"));
|
||||
final TargetTag targTagW = tagManagement.createTargetTag(new TargetTag("TargTag-W"));
|
||||
|
||||
final DistributionSet setA = TestDataUtil.generateDistributionSet("", softwareManagement,
|
||||
distributionSetManagement);
|
||||
|
||||
final DistributionSet installedSet = TestDataUtil.generateDistributionSet("another", softwareManagement,
|
||||
distributionSetManagement);
|
||||
|
||||
final String targetDsAIdPref = "targ-A";
|
||||
List<Target> targAs = targetManagement.createTargets(
|
||||
TestDataUtil.buildTargetFixtures(100, targetDsAIdPref, targetDsAIdPref.concat(" description")));
|
||||
targAs = targetManagement.toggleTagAssignment(targAs, targTagA).getAssignedTargets();
|
||||
targAs = targetManagement.toggleTagAssignment(targAs, targTagX).getAssignedTargets();
|
||||
|
||||
final String targetDsBIdPref = "targ-B";
|
||||
List<Target> targBs = targetManagement.createTargets(
|
||||
TestDataUtil.buildTargetFixtures(100, targetDsBIdPref, targetDsBIdPref.concat(" description")));
|
||||
targBs = targetManagement.toggleTagAssignment(targBs, targTagB).getAssignedTargets();
|
||||
targBs = targetManagement.toggleTagAssignment(targBs, targTagD).getAssignedTargets();
|
||||
targBs = targetManagement.toggleTagAssignment(targBs, targTagY).getAssignedTargets();
|
||||
targBs = targetManagement.toggleTagAssignment(targBs, targTagW).getAssignedTargets();
|
||||
|
||||
final String targetDsCIdPref = "targ-C";
|
||||
List<Target> targCs = targetManagement.createTargets(
|
||||
TestDataUtil.buildTargetFixtures(100, targetDsCIdPref, targetDsCIdPref.concat(" description")));
|
||||
targCs = targetManagement.toggleTagAssignment(targCs, targTagC).getAssignedTargets();
|
||||
targCs = targetManagement.toggleTagAssignment(targCs, targTagD).getAssignedTargets();
|
||||
targCs = targetManagement.toggleTagAssignment(targCs, targTagZ).getAssignedTargets();
|
||||
targCs = targetManagement.toggleTagAssignment(targCs, targTagW).getAssignedTargets();
|
||||
|
||||
final String targetDsDIdPref = "targ-D";
|
||||
final Iterable<Target> targDs = targetManagement.createTargets(
|
||||
final List<Target> targDs = targetManagement.createTargets(
|
||||
TestDataUtil.buildTargetFixtures(100, targetDsDIdPref, targetDsDIdPref.concat(" description")));
|
||||
|
||||
deploymentManagement.assignDistributionSet(setA.getId(), targCs.iterator().next().getControllerId());
|
||||
deploymentManagement.assignDistributionSet(setA.getId(), targAs.iterator().next().getControllerId());
|
||||
deploymentManagement.assignDistributionSet(setA.getId(), targBs.iterator().next().getControllerId());
|
||||
final String assignedC = targCs.iterator().next().getControllerId();
|
||||
deploymentManagement.assignDistributionSet(setA.getId(), assignedC);
|
||||
final String assignedA = targAs.iterator().next().getControllerId();
|
||||
deploymentManagement.assignDistributionSet(setA.getId(), assignedA);
|
||||
final String assignedB = targBs.iterator().next().getControllerId();
|
||||
deploymentManagement.assignDistributionSet(setA.getId(), assignedB);
|
||||
final String installedC = targCs.iterator().next().getControllerId();
|
||||
final Long actionId = deploymentManagement.assignDistributionSet(installedSet.getId(), assignedC).getActions()
|
||||
.get(0);
|
||||
|
||||
final List<TargetUpdateStatus> unknown = new ArrayList<TargetUpdateStatus>();
|
||||
// set one installed DS also
|
||||
final Action action = deploymentManagement.findActionWithDetails(actionId);
|
||||
action.setStatus(Status.FINISHED);
|
||||
controllerManagament.addUpdateActionStatus(
|
||||
new ActionStatus(action, Status.FINISHED, System.currentTimeMillis(), "message"), action);
|
||||
deploymentManagement.assignDistributionSet(setA.getId(), installedC);
|
||||
|
||||
final List<TargetUpdateStatus> unknown = new ArrayList<>();
|
||||
unknown.add(TargetUpdateStatus.UNKNOWN);
|
||||
|
||||
final List<TargetUpdateStatus> pending = new ArrayList<TargetUpdateStatus>();
|
||||
final List<TargetUpdateStatus> pending = new ArrayList<>();
|
||||
pending.add(TargetUpdateStatus.PENDING);
|
||||
|
||||
final List<TargetUpdateStatus> both = new ArrayList<TargetUpdateStatus>();
|
||||
final List<TargetUpdateStatus> both = new ArrayList<>();
|
||||
both.add(TargetUpdateStatus.UNKNOWN);
|
||||
both.add(TargetUpdateStatus.PENDING);
|
||||
|
||||
final PageRequest pageReq = new PageRequest(0, 500);
|
||||
// try to find several targets with different filter settings
|
||||
verifyThatRepositoryContains400Targets();
|
||||
verifyThat200TargetsHaveTagD(targTagW, concat(targBs, targCs));
|
||||
verifyThat100TargetsContainsGivenTextAndHaveTagAssigned(targTagY, targTagW, targBs);
|
||||
verifyThat1TargetHasTagHasDescOrNameAndDs(targTagW, setA, targetManagement.findTargetByControllerID(assignedC));
|
||||
verifyThat0TargetsWithTagAndDescOrNameHasDS(targTagW, setA);
|
||||
verifyThat0TargetsWithNameOrdescAndDSHaveTag(targTagX, setA);
|
||||
verifyThat3TargetsHaveDSAssigned(setA,
|
||||
targetManagement.findTargetByControllerID(Lists.newArrayList(assignedA, assignedB, assignedC)));
|
||||
verifyThat1TargetWithDescOrNameHasDS(setA, targetManagement.findTargetByControllerID(assignedA));
|
||||
List<Target> expected = concat(targAs, targBs, targCs, targDs);
|
||||
expected.removeAll(
|
||||
targetManagement.findTargetByControllerID(Lists.newArrayList(assignedA, assignedB, assignedC)));
|
||||
verifyThat397TargetsAreInStatusUnknown(unknown, expected);
|
||||
expected = concat(targBs, targCs);
|
||||
expected.removeAll(targetManagement.findTargetByControllerID(Lists.newArrayList(assignedB, assignedC)));
|
||||
verifyThat198TargetsAreInStatusUnknownAndHaveGivenTags(targTagY, targTagW, unknown, expected);
|
||||
verfyThat0TargetsAreInStatusUnknownAndHaveDSAssigned(setA, unknown);
|
||||
expected = concat(targAs);
|
||||
expected.remove(targetManagement.findTargetByControllerID(assignedA));
|
||||
verifyThat99TargetsWithNameOrDescriptionAreInGivenStatus(unknown, expected);
|
||||
expected = concat(targBs);
|
||||
expected.remove(targetManagement.findTargetByControllerID(assignedB));
|
||||
verifyThat99TargetsWithGivenNameOrDescAndTagAreInStatusUnknown(targTagW, unknown, expected);
|
||||
verifyThat3TargetsAreInStatusPending(pending,
|
||||
targetManagement.findTargetByControllerID(Lists.newArrayList(assignedA, assignedB, assignedC)));
|
||||
verifyThat3TargetsWithGivenDSAreInPending(setA, pending,
|
||||
targetManagement.findTargetByControllerID(Lists.newArrayList(assignedA, assignedB, assignedC)));
|
||||
verifyThat1TargetWithGivenNameOrDescAndDSIsInPending(setA, pending,
|
||||
targetManagement.findTargetByControllerID(assignedA));
|
||||
verifyThat1TargetWithGivenNameOrDescAndTagAndDSIsInPending(targTagW, setA, pending,
|
||||
targetManagement.findTargetByControllerID(assignedB));
|
||||
verifyThat2TargetsWithGivenTagAndDSIsInPending(targTagW, setA, pending,
|
||||
targetManagement.findTargetByControllerID(Lists.newArrayList(assignedB, assignedC)));
|
||||
verifyThat2TargetsWithGivenTagAreInPending(targTagW, pending,
|
||||
targetManagement.findTargetByControllerID(Lists.newArrayList(assignedB, assignedC)));
|
||||
verifyThat200targetsWithGivenTagAreInStatusPendingorUnknown(targTagW, both, concat(targBs, targCs));
|
||||
verfiyThat1TargetAIsInStatusPendingAndHasDSInstalled(installedSet, pending,
|
||||
targetManagement.findTargetByControllerID(installedC));
|
||||
}
|
||||
|
||||
// TODO kaizimmerm: comment and check also the content itself, not only
|
||||
// the numbers
|
||||
// (containsOnly)
|
||||
assertThat(targetManagement.countTargetsAll()).isEqualTo(400);
|
||||
@Step
|
||||
private void verfiyThat1TargetAIsInStatusPendingAndHasDSInstalled(final DistributionSet installedSet,
|
||||
final List<TargetUpdateStatus> pending, final Target expected) {
|
||||
final TargetIdName expectedIdName = convertToIdName(expected);
|
||||
final String query = "updatestatus==pending and installedds.name==" + installedSet.getName();
|
||||
|
||||
assertThat(targetManagement.findTargetByFilters(pageReq, null, null, null, Boolean.FALSE, targTagD.getName())
|
||||
.getNumberOfElements()).isEqualTo(200).isEqualTo(Ints.saturatedCast(
|
||||
targetManagement.countTargetByFilters(null, null, null, Boolean.FALSE, targTagD.getName())));
|
||||
assertThat(targetManagement
|
||||
.findTargetByFilters(pageReq, pending, null, installedSet.getId(), Boolean.FALSE, new String[0])
|
||||
.getContent()).as("has number of elements").hasSize(1)
|
||||
.as("that number is also returned by count query")
|
||||
.hasSize(Ints.saturatedCast(targetManagement.countTargetByFilters(pending, null,
|
||||
installedSet.getId(), Boolean.FALSE, new String[0])))
|
||||
.as("and contains the following elements").containsExactly(expected)
|
||||
.as("and filter query returns the same result")
|
||||
.containsAll(targetManagement.findTargetsAll(query, pageReq).getContent())
|
||||
.as("and NAMED filter query returns the same result").containsAll(targetManagement
|
||||
.findTargetsAll(new TargetFilterQuery("test", query), pageReq).getContent());
|
||||
|
||||
Slice<Target> x = targetManagement.findTargetByFilters(pageReq, null, "%targ-B%", null, Boolean.FALSE,
|
||||
targTagB.getName(), targTagD.getName());
|
||||
assertThat(x.getNumberOfElements()).isEqualTo(100).isEqualTo(Ints.saturatedCast(targetManagement
|
||||
.countTargetByFilters(null, "%targ-B%", null, Boolean.FALSE, targTagB.getName(), targTagD.getName())));
|
||||
|
||||
x = targetManagement.findTargetByFilters(pageReq, null, "%targ-C%", setA.getId(), Boolean.FALSE,
|
||||
targTagD.getName());
|
||||
assertThat(x.getNumberOfElements()).isEqualTo(1).isEqualTo(Ints.saturatedCast(targetManagement
|
||||
.countTargetByFilters(null, "%targ-C%", setA.getId(), Boolean.FALSE, targTagD.getName())));
|
||||
|
||||
x = targetManagement.findTargetByFilters(pageReq, null, "%targ-A%", setA.getId(), Boolean.FALSE,
|
||||
targTagD.getName());
|
||||
assertThat(x.getNumberOfElements()).isEqualTo(0).isEqualTo(Ints.saturatedCast(targetManagement
|
||||
.countTargetByFilters(null, "%targ-A%", setA.getId(), Boolean.FALSE, targTagD.getName())));
|
||||
|
||||
x = targetManagement.findTargetByFilters(pageReq, null, "%targ-C%", setA.getId(), Boolean.FALSE,
|
||||
targTagA.getName());
|
||||
assertThat(x.getNumberOfElements()).isEqualTo(0).isEqualTo(Ints.saturatedCast(targetManagement
|
||||
.countTargetByFilters(null, "%targ-C%", setA.getId(), Boolean.FALSE, targTagA.getName())));
|
||||
|
||||
x = targetManagement.findTargetByFilters(pageReq, null, null, setA.getId(), Boolean.FALSE, null);
|
||||
assertThat(x.getNumberOfElements()).isEqualTo(3).isEqualTo(Ints
|
||||
.saturatedCast(targetManagement.countTargetByFilters(null, null, setA.getId(), Boolean.FALSE, null)));
|
||||
|
||||
x = targetManagement.findTargetByFilters(pageReq, null, "%targ-A%", setA.getId(), Boolean.FALSE, null);
|
||||
assertThat(x.getNumberOfElements()).isEqualTo(1).isEqualTo(Ints.saturatedCast(
|
||||
targetManagement.countTargetByFilters(null, "%targ-A%", setA.getId(), Boolean.FALSE, null)));
|
||||
|
||||
x = targetManagement.findTargetByFilters(pageReq, unknown, null, null, Boolean.FALSE, null);
|
||||
assertThat(x.getNumberOfElements()).isEqualTo(397).isEqualTo(
|
||||
Ints.saturatedCast(targetManagement.countTargetByFilters(unknown, null, null, Boolean.FALSE, null)));
|
||||
|
||||
x = targetManagement.findTargetByFilters(pageReq, unknown, null, null, Boolean.FALSE, targTagB.getName(),
|
||||
targTagD.getName());
|
||||
assertThat(x.getNumberOfElements()).isEqualTo(198).isEqualTo(Ints.saturatedCast(targetManagement
|
||||
.countTargetByFilters(unknown, null, null, Boolean.FALSE, targTagB.getName(), targTagD.getName())));
|
||||
|
||||
x = targetManagement.findTargetByFilters(pageReq, unknown, null, setA.getId(), Boolean.FALSE, null);
|
||||
assertThat(x.getNumberOfElements()).isEqualTo(0).isEqualTo(Ints.saturatedCast(
|
||||
targetManagement.countTargetByFilters(unknown, null, setA.getId(), Boolean.FALSE, null)));
|
||||
|
||||
x = targetManagement.findTargetByFilters(pageReq, unknown, "%targ-A%", null, Boolean.FALSE, null);
|
||||
assertThat(x.getNumberOfElements()).isEqualTo(99).isEqualTo(Ints
|
||||
.saturatedCast(targetManagement.countTargetByFilters(unknown, "%targ-A%", null, Boolean.FALSE, null)));
|
||||
|
||||
x = targetManagement.findTargetByFilters(pageReq, unknown, "%targ-B%", null, Boolean.FALSE, targTagD.getName());
|
||||
assertThat(x.getNumberOfElements()).isEqualTo(99).isEqualTo(Ints.saturatedCast(
|
||||
targetManagement.countTargetByFilters(unknown, "%targ-B%", null, Boolean.FALSE, targTagD.getName())));
|
||||
|
||||
x = targetManagement.findTargetByFilters(pageReq, unknown, null, null, Boolean.FALSE, targTagD.getName());
|
||||
assertThat(x.getNumberOfElements()).isEqualTo(198).isEqualTo(Ints.saturatedCast(
|
||||
targetManagement.countTargetByFilters(unknown, null, null, Boolean.FALSE, targTagD.getName())));
|
||||
|
||||
x = targetManagement.findTargetByFilters(pageReq, pending, null, null, Boolean.FALSE, null);
|
||||
assertThat(x.getNumberOfElements()).isEqualTo(3).isEqualTo(
|
||||
Ints.saturatedCast(targetManagement.countTargetByFilters(pending, null, null, Boolean.FALSE, null)));
|
||||
|
||||
x = targetManagement.findTargetByFilters(pageReq, pending, null, setA.getId(), Boolean.FALSE, null);
|
||||
assertThat(x.getNumberOfElements()).isEqualTo(3).isEqualTo(Ints.saturatedCast(
|
||||
targetManagement.countTargetByFilters(pending, null, setA.getId(), Boolean.FALSE, null)));
|
||||
|
||||
x = targetManagement.findTargetByFilters(pageReq, pending, "%targ-A%", setA.getId(), Boolean.FALSE, null);
|
||||
assertThat(x.getNumberOfElements()).isEqualTo(1).isEqualTo(Ints.saturatedCast(
|
||||
targetManagement.countTargetByFilters(pending, "%targ-A%", setA.getId(), Boolean.FALSE, null)));
|
||||
|
||||
x = targetManagement.findTargetByFilters(pageReq, pending, "%targ-B%", setA.getId(), Boolean.FALSE,
|
||||
targTagD.getName());
|
||||
assertThat(x.getNumberOfElements()).isEqualTo(1).isEqualTo(Ints.saturatedCast(targetManagement
|
||||
.countTargetByFilters(pending, "%targ-B%", setA.getId(), Boolean.FALSE, targTagD.getName())));
|
||||
|
||||
x = targetManagement.findTargetByFilters(pageReq, pending, null, setA.getId(), Boolean.FALSE,
|
||||
targTagD.getName());
|
||||
assertThat(x.getNumberOfElements()).isEqualTo(2).isEqualTo(Ints.saturatedCast(
|
||||
targetManagement.countTargetByFilters(pending, null, setA.getId(), Boolean.FALSE, targTagD.getName())));
|
||||
|
||||
x = targetManagement.findTargetByFilters(pageReq, pending, null, null, Boolean.FALSE, targTagD.getName());
|
||||
assertThat(x.getNumberOfElements()).isEqualTo(2).isEqualTo(Ints.saturatedCast(
|
||||
targetManagement.countTargetByFilters(pending, null, null, Boolean.FALSE, targTagD.getName())));
|
||||
|
||||
// Both status: 2 pending and 198 unknown
|
||||
assertThat(targetManagement.findTargetByFilters(pageReq, both, null, null, Boolean.FALSE, targTagD.getName())
|
||||
.getNumberOfElements()).isEqualTo(200).isEqualTo(Ints.saturatedCast(
|
||||
targetManagement.countTargetByFilters(both, null, null, Boolean.FALSE, targTagD.getName())));
|
||||
assertThat(targetManagement.findAllTargetIdsByFilters(pageReq, pending, null, installedSet.getId(),
|
||||
Boolean.FALSE, new String[0])).as("has number of elements").hasSize(1)
|
||||
.as("and contains the following elements").containsExactly(expectedIdName)
|
||||
.as("and NAMED filter query returns the same result").containsAll(targetManagement
|
||||
.findAllTargetIdsByTargetFilterQuery(pageReq, new TargetFilterQuery("test", query)));
|
||||
|
||||
}
|
||||
|
||||
@Step
|
||||
private void verifyThat200targetsWithGivenTagAreInStatusPendingorUnknown(final TargetTag targTagW,
|
||||
final List<TargetUpdateStatus> both, final List<Target> expected) {
|
||||
final List<TargetIdName> expectedIdNames = convertToIdNames(expected);
|
||||
|
||||
final String query = "(updatestatus==pending or updatestatus==unknown) and tag==" + targTagW.getName();
|
||||
|
||||
assertThat(targetManagement.findTargetByFilters(pageReq, both, null, null, Boolean.FALSE, targTagW.getName())
|
||||
.getContent()).as("has number of elements").hasSize(200)
|
||||
.as("that number is also returned by count query")
|
||||
.hasSize(Ints.saturatedCast(targetManagement.countTargetByFilters(both, null, null,
|
||||
Boolean.FALSE, targTagW.getName())))
|
||||
.as("and contains the following elements").containsAll(expected)
|
||||
.as("and filter query returns the same result")
|
||||
.containsAll(targetManagement.findTargetsAll(query, pageReq).getContent())
|
||||
.as("and NAMED filter query returns the same result").containsAll(targetManagement
|
||||
.findTargetsAll(new TargetFilterQuery("test", query), pageReq).getContent());
|
||||
|
||||
assertThat(targetManagement.findAllTargetIdsByFilters(pageReq, both, null, null, Boolean.FALSE,
|
||||
targTagW.getName())).as("has number of elements").hasSize(200).as("and contains the following elements")
|
||||
.containsAll(expectedIdNames).as("and NAMED filter query returns the same result")
|
||||
.containsAll(targetManagement.findAllTargetIdsByTargetFilterQuery(pageReq,
|
||||
new TargetFilterQuery("test", query)));
|
||||
}
|
||||
|
||||
private static List<TargetIdName> convertToIdNames(final List<Target> expected) {
|
||||
return expected.stream()
|
||||
.map(target -> new TargetIdName(target.getId(), target.getControllerId(), target.getName()))
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
private static TargetIdName convertToIdName(final Target target) {
|
||||
return new TargetIdName(target.getId(), target.getControllerId(), target.getName());
|
||||
}
|
||||
|
||||
@Step
|
||||
private void verifyThat2TargetsWithGivenTagAreInPending(final TargetTag targTagW,
|
||||
final List<TargetUpdateStatus> pending, final List<Target> expected) {
|
||||
final List<TargetIdName> expectedIdNames = convertToIdNames(expected);
|
||||
final String query = "updatestatus==pending and tag==" + targTagW.getName();
|
||||
|
||||
assertThat(targetManagement.findTargetByFilters(pageReq, pending, null, null, Boolean.FALSE, targTagW.getName())
|
||||
.getContent()).as("has number of elements").hasSize(2)
|
||||
.as("that number is also returned by count query")
|
||||
.hasSize(Ints.saturatedCast(targetManagement.countTargetByFilters(pending, null, null,
|
||||
Boolean.FALSE, targTagW.getName())))
|
||||
.as("and contains the following elements").containsAll(expected)
|
||||
.as("and filter query returns the same result")
|
||||
.containsAll(targetManagement.findTargetsAll(query, pageReq).getContent())
|
||||
.as("and NAMED filter query returns the same result").containsAll(targetManagement
|
||||
.findTargetsAll(new TargetFilterQuery("test", query), pageReq).getContent());
|
||||
|
||||
assertThat(targetManagement.findAllTargetIdsByFilters(pageReq, pending, null, null, Boolean.FALSE,
|
||||
targTagW.getName())).as("has number of elements").hasSize(2).as("and contains the following elements")
|
||||
.containsAll(expectedIdNames).as("and NAMED filter query returns the same result")
|
||||
.containsAll(targetManagement.findAllTargetIdsByTargetFilterQuery(pageReq,
|
||||
new TargetFilterQuery("test", query)));
|
||||
}
|
||||
|
||||
@Step
|
||||
private void verifyThat2TargetsWithGivenTagAndDSIsInPending(final TargetTag targTagW, final DistributionSet setA,
|
||||
final List<TargetUpdateStatus> pending, final List<Target> expected) {
|
||||
final List<TargetIdName> expectedIdNames = convertToIdNames(expected);
|
||||
final String query = "updatestatus==pending and (assignedds.name==" + setA.getName() + " or installedds.name=="
|
||||
+ setA.getName() + ") and tag==" + targTagW.getName();
|
||||
|
||||
assertThat(targetManagement
|
||||
.findTargetByFilters(pageReq, pending, null, setA.getId(), Boolean.FALSE, targTagW.getName())
|
||||
.getContent()).as("has number of elements").hasSize(2)
|
||||
.as("that number is also returned by count query")
|
||||
.hasSize(Ints.saturatedCast(targetManagement.countTargetByFilters(pending, null, setA.getId(),
|
||||
Boolean.FALSE, targTagW.getName())))
|
||||
.as("and contains the following elements").containsAll(expected)
|
||||
.as("and filter query returns the same result")
|
||||
.containsAll(targetManagement.findTargetsAll(query, pageReq).getContent())
|
||||
.as("and NAMED filter query returns the same result").containsAll(targetManagement
|
||||
.findTargetsAll(new TargetFilterQuery("test", query), pageReq).getContent());
|
||||
|
||||
assertThat(targetManagement.findAllTargetIdsByFilters(pageReq, pending, null, null, Boolean.FALSE,
|
||||
targTagW.getName())).as("has number of elements").hasSize(2).as("and contains the following elements")
|
||||
.containsAll(expectedIdNames).as("and NAMED filter query returns the same result")
|
||||
.containsAll(targetManagement.findAllTargetIdsByTargetFilterQuery(pageReq,
|
||||
new TargetFilterQuery("test", query)));
|
||||
}
|
||||
|
||||
@Step
|
||||
private void verifyThat1TargetWithGivenNameOrDescAndTagAndDSIsInPending(final TargetTag targTagW,
|
||||
final DistributionSet setA, final List<TargetUpdateStatus> pending, final Target expected) {
|
||||
final TargetIdName expectedIdName = convertToIdName(expected);
|
||||
final String query = "updatestatus==pending and (assignedds.name==" + setA.getName() + " or installedds.name=="
|
||||
+ setA.getName() + ") and (name==*targ-B* or description==*targ-B*) and tag==" + targTagW.getName();
|
||||
|
||||
assertThat(targetManagement
|
||||
.findTargetByFilters(pageReq, pending, "%targ-B%", setA.getId(), Boolean.FALSE, targTagW.getName())
|
||||
.getContent()).as("has number of elements").hasSize(1)
|
||||
.as("that number is also returned by count query")
|
||||
.hasSize(Ints.saturatedCast(targetManagement.countTargetByFilters(pending, "%targ-B%",
|
||||
setA.getId(), Boolean.FALSE, targTagW.getName())))
|
||||
.as("and contains the following elements").containsExactly(expected)
|
||||
.as("and filter query returns the same result")
|
||||
.containsAll(targetManagement.findTargetsAll(query, pageReq).getContent())
|
||||
.as("and NAMED filter query returns the same result").containsAll(targetManagement
|
||||
.findTargetsAll(new TargetFilterQuery("test", query), pageReq).getContent());
|
||||
|
||||
assertThat(targetManagement.findAllTargetIdsByFilters(pageReq, pending, "%targ-B%", setA.getId(), Boolean.FALSE,
|
||||
targTagW.getName())).as("has number of elements").hasSize(1).as("and contains the following elements")
|
||||
.containsExactly(expectedIdName).as("and NAMED filter query returns the same result")
|
||||
.containsAll(targetManagement.findAllTargetIdsByTargetFilterQuery(pageReq,
|
||||
new TargetFilterQuery("test", query)));
|
||||
}
|
||||
|
||||
@Step
|
||||
private void verifyThat1TargetWithGivenNameOrDescAndDSIsInPending(final DistributionSet setA,
|
||||
final List<TargetUpdateStatus> pending, final Target expected) {
|
||||
final TargetIdName expectedIdName = convertToIdName(expected);
|
||||
final String query = "updatestatus==pending and (assignedds.name==" + setA.getName() + " or installedds.name=="
|
||||
+ setA.getName() + ") and (name==*targ-A* or description==*targ-A*)";
|
||||
|
||||
assertThat(targetManagement
|
||||
.findTargetByFilters(pageReq, pending, "%targ-A%", setA.getId(), Boolean.FALSE, new String[0])
|
||||
.getContent()).as("has number of elements").hasSize(1)
|
||||
.as("that number is also returned by count query")
|
||||
.hasSize(Ints.saturatedCast(targetManagement.countTargetByFilters(pending, "%targ-A%",
|
||||
setA.getId(), Boolean.FALSE, new String[0])))
|
||||
.as("and contains the following elements").containsExactly(expected)
|
||||
.as("and filter query returns the same result")
|
||||
.containsAll(targetManagement.findTargetsAll(query, pageReq).getContent())
|
||||
.as("and NAMED filter query returns the same result").containsAll(targetManagement
|
||||
.findTargetsAll(new TargetFilterQuery("test", query), pageReq).getContent());
|
||||
|
||||
assertThat(targetManagement.findAllTargetIdsByFilters(pageReq, pending, "%targ-A%", setA.getId(), Boolean.FALSE,
|
||||
new String[0])).as("has number of elements").hasSize(1).as("and contains the following elements")
|
||||
.containsExactly(expectedIdName).as("and NAMED filter query returns the same result")
|
||||
.containsAll(targetManagement.findAllTargetIdsByTargetFilterQuery(pageReq,
|
||||
new TargetFilterQuery("test", query)));
|
||||
}
|
||||
|
||||
@Step
|
||||
private void verifyThat3TargetsWithGivenDSAreInPending(final DistributionSet setA,
|
||||
final List<TargetUpdateStatus> pending, final List<Target> expected) {
|
||||
final List<TargetIdName> expectedIdNames = convertToIdNames(expected);
|
||||
final String query = "updatestatus==pending and (assignedds.name==" + setA.getName() + " or installedds.name=="
|
||||
+ setA.getName() + ")";
|
||||
|
||||
assertThat(targetManagement
|
||||
.findTargetByFilters(pageReq, pending, null, setA.getId(), Boolean.FALSE, new String[0]).getContent())
|
||||
.as("has number of elements").hasSize(3).as("that number is also returned by count query")
|
||||
.hasSize(Ints.saturatedCast(targetManagement.countTargetByFilters(pending, null, setA.getId(),
|
||||
Boolean.FALSE, new String[0])))
|
||||
.as("and contains the following elements").containsAll(expected)
|
||||
.as("and filter query returns the same result")
|
||||
.containsAll(targetManagement.findTargetsAll(query, pageReq).getContent())
|
||||
.as("and NAMED filter query returns the same result").containsAll(targetManagement
|
||||
.findTargetsAll(new TargetFilterQuery("test", query), pageReq).getContent());
|
||||
|
||||
assertThat(targetManagement.findAllTargetIdsByFilters(pageReq, pending, null, setA.getId(), Boolean.FALSE,
|
||||
new String[0])).as("has number of elements").hasSize(3).as("and contains the following elements")
|
||||
.containsAll(expectedIdNames).as("and NAMED filter query returns the same result")
|
||||
.containsAll(targetManagement.findAllTargetIdsByTargetFilterQuery(pageReq,
|
||||
new TargetFilterQuery("test", query)));
|
||||
}
|
||||
|
||||
@Step
|
||||
private void verifyThat3TargetsAreInStatusPending(final List<TargetUpdateStatus> pending,
|
||||
final List<Target> expected) {
|
||||
final List<TargetIdName> expectedIdNames = convertToIdNames(expected);
|
||||
final String query = "updatestatus==pending";
|
||||
|
||||
assertThat(targetManagement.findTargetByFilters(pageReq, pending, null, null, Boolean.FALSE, new String[0])
|
||||
.getContent()).as("has number of elements").hasSize(3)
|
||||
.as("that number is also returned by count query")
|
||||
.hasSize(Ints.saturatedCast(targetManagement.countTargetByFilters(pending, null, null,
|
||||
Boolean.FALSE, new String[0])))
|
||||
.as("and contains the following elements").containsAll(expected)
|
||||
.as("and filter query returns the same result")
|
||||
.containsAll(targetManagement.findTargetsAll(query, pageReq).getContent())
|
||||
.as("and NAMED filter query returns the same result").containsAll(targetManagement
|
||||
.findTargetsAll(new TargetFilterQuery("test", query), pageReq).getContent());
|
||||
|
||||
assertThat(
|
||||
targetManagement.findAllTargetIdsByFilters(pageReq, pending, null, null, Boolean.FALSE, new String[0]))
|
||||
.as("has number of elements").hasSize(3).as("and contains the following elements")
|
||||
.containsAll(expectedIdNames).as("and NAMED filter query returns the same result")
|
||||
.containsAll(targetManagement.findAllTargetIdsByTargetFilterQuery(pageReq,
|
||||
new TargetFilterQuery("test", query)));
|
||||
}
|
||||
|
||||
@Step
|
||||
private void verifyThat99TargetsWithGivenNameOrDescAndTagAreInStatusUnknown(final TargetTag targTagW,
|
||||
final List<TargetUpdateStatus> unknown, final List<Target> expected) {
|
||||
final List<TargetIdName> expectedIdNames = convertToIdNames(expected);
|
||||
final String query = "updatestatus==unknown and (name==*targ-B* or description==*targ-B*) and tag=="
|
||||
+ targTagW.getName();
|
||||
|
||||
assertThat(targetManagement
|
||||
.findTargetByFilters(pageReq, unknown, "%targ-B%", null, Boolean.FALSE, targTagW.getName())
|
||||
.getContent()).as("has number of elements").hasSize(99)
|
||||
.as("that number is also returned by count query")
|
||||
.hasSize(Ints.saturatedCast(targetManagement.countTargetByFilters(unknown, "%targ-B%", null,
|
||||
Boolean.FALSE, targTagW.getName())))
|
||||
.as("and contains the following elements").containsAll(expected)
|
||||
.as("and filter query returns the same result")
|
||||
.containsAll(targetManagement.findTargetsAll(query, pageReq).getContent())
|
||||
.as("and NAMED filter query returns the same result").containsAll(targetManagement
|
||||
.findTargetsAll(new TargetFilterQuery("test", query), pageReq).getContent());
|
||||
|
||||
assertThat(targetManagement.findAllTargetIdsByFilters(pageReq, unknown, "%targ-B%", null, Boolean.FALSE,
|
||||
targTagW.getName())).as("has number of elements").hasSize(99).as("and contains the following elements")
|
||||
.containsAll(expectedIdNames).as("and NAMED filter query returns the same result")
|
||||
.containsAll(targetManagement.findAllTargetIdsByTargetFilterQuery(pageReq,
|
||||
new TargetFilterQuery("test", query)));
|
||||
}
|
||||
|
||||
@Step
|
||||
private void verifyThat99TargetsWithNameOrDescriptionAreInGivenStatus(final List<TargetUpdateStatus> unknown,
|
||||
final List<Target> expected) {
|
||||
final List<TargetIdName> expectedIdNames = convertToIdNames(expected);
|
||||
final String query = "updatestatus==unknown and (name==*targ-A* or description==*targ-A*)";
|
||||
|
||||
assertThat(targetManagement
|
||||
.findTargetByFilters(pageReq, unknown, "%targ-A%", null, Boolean.FALSE, new String[0]).getContent())
|
||||
.as("has number of elements").hasSize(99).as("that number is also returned by count query")
|
||||
.hasSize(Ints.saturatedCast(targetManagement.countTargetByFilters(unknown, "%targ-A%", null,
|
||||
Boolean.FALSE, new String[0])))
|
||||
.as("and contains the following elements").containsAll(expected)
|
||||
.as("and filter query returns the same result")
|
||||
.containsAll(targetManagement.findTargetsAll(query, pageReq).getContent())
|
||||
.as("and NAMED filter query returns the same result").containsAll(targetManagement
|
||||
.findTargetsAll(new TargetFilterQuery("test", query), pageReq).getContent());
|
||||
|
||||
assertThat(targetManagement.findAllTargetIdsByFilters(pageReq, unknown, "%targ-A%", null, Boolean.FALSE,
|
||||
new String[0])).as("has number of elements").hasSize(99).as("and contains the following elements")
|
||||
.containsAll(expectedIdNames).as("and NAMED filter query returns the same result")
|
||||
.containsAll(targetManagement.findAllTargetIdsByTargetFilterQuery(pageReq,
|
||||
new TargetFilterQuery("test", query)));
|
||||
}
|
||||
|
||||
@Step
|
||||
private void verfyThat0TargetsAreInStatusUnknownAndHaveDSAssigned(final DistributionSet setA,
|
||||
final List<TargetUpdateStatus> unknown) {
|
||||
final String query = "updatestatus==unknown and (assignedds.name==" + setA.getName() + " or installedds.name=="
|
||||
+ setA.getName() + ")";
|
||||
|
||||
assertThat(targetManagement
|
||||
.findTargetByFilters(pageReq, unknown, null, setA.getId(), Boolean.FALSE, new String[0]).getContent())
|
||||
.as("has number of elements").hasSize(0).as("that number is also returned by count query")
|
||||
.hasSize(Ints.saturatedCast(targetManagement.countTargetByFilters(unknown, null, setA.getId(),
|
||||
Boolean.FALSE, new String[0])))
|
||||
.as("and filter query returns the same result")
|
||||
.hasSize(targetManagement.findTargetsAll(query, pageReq).getContent().size())
|
||||
.as("and NAMED filter query returns the same result").hasSize(targetManagement
|
||||
.findTargetsAll(new TargetFilterQuery("test", query), pageReq).getContent().size());
|
||||
|
||||
assertThat(targetManagement.findAllTargetIdsByFilters(pageReq, unknown, null, setA.getId(), Boolean.FALSE,
|
||||
new String[0])).as("has number of elements").hasSize(0)
|
||||
.as("and NAMED filter query returns the same result").containsAll(targetManagement
|
||||
.findAllTargetIdsByTargetFilterQuery(pageReq, new TargetFilterQuery("test", query)));
|
||||
}
|
||||
|
||||
@Step
|
||||
private void verifyThat198TargetsAreInStatusUnknownAndHaveGivenTags(final TargetTag targTagY,
|
||||
final TargetTag targTagW, final List<TargetUpdateStatus> unknown, final List<Target> expected) {
|
||||
final List<TargetIdName> expectedIdNames = convertToIdNames(expected);
|
||||
final String query = "updatestatus==unknown and (tag==" + targTagY.getName() + " or tag==" + targTagW.getName()
|
||||
+ ")";
|
||||
|
||||
assertThat(targetManagement.findTargetByFilters(pageReq, unknown, null, null, Boolean.FALSE, targTagY.getName(),
|
||||
targTagW.getName()).getContent()).as("has number of elements").hasSize(198)
|
||||
.as("that number is also returned by count query")
|
||||
.hasSize(Ints.saturatedCast(targetManagement.countTargetByFilters(unknown, null, null,
|
||||
Boolean.FALSE, targTagY.getName(), targTagW.getName())))
|
||||
.as("and contains the following elements").containsAll(expected)
|
||||
.as("and filter query returns the same result")
|
||||
.containsAll(targetManagement.findTargetsAll(query, pageReq).getContent())
|
||||
.as("and NAMED filter query returns the same result").containsAll(targetManagement
|
||||
.findTargetsAll(new TargetFilterQuery("test", query), pageReq).getContent());
|
||||
|
||||
assertThat(targetManagement.findAllTargetIdsByFilters(pageReq, unknown, null, null, Boolean.FALSE,
|
||||
targTagY.getName(), targTagW.getName())).as("has number of elements").hasSize(198)
|
||||
.as("and contains the following elements").containsAll(expectedIdNames)
|
||||
.as("and NAMED filter query returns the same result").containsAll(targetManagement
|
||||
.findAllTargetIdsByTargetFilterQuery(pageReq, new TargetFilterQuery("test", query)));
|
||||
}
|
||||
|
||||
@Step
|
||||
private void verifyThat397TargetsAreInStatusUnknown(final List<TargetUpdateStatus> unknown,
|
||||
final List<Target> expected) {
|
||||
final List<TargetIdName> expectedIdNames = convertToIdNames(expected);
|
||||
final String query = "updatestatus==unknown";
|
||||
|
||||
assertThat(targetManagement.findTargetByFilters(pageReq, unknown, null, null, Boolean.FALSE, new String[0])
|
||||
.getContent()).as("has number of elements").hasSize(397)
|
||||
.as("that number is also returned by count query")
|
||||
.hasSize(Ints.saturatedCast(targetManagement.countTargetByFilters(unknown, null, null,
|
||||
Boolean.FALSE, new String[0])))
|
||||
.as("and contains the following elements").containsAll(expected)
|
||||
.as("and filter query returns the same result")
|
||||
.containsAll(targetManagement.findTargetsAll(query, pageReq).getContent())
|
||||
.as("and NAMED filter query returns the same result").containsAll(targetManagement
|
||||
.findTargetsAll(new TargetFilterQuery("test", query), pageReq).getContent());
|
||||
|
||||
assertThat(
|
||||
targetManagement.findAllTargetIdsByFilters(pageReq, unknown, null, null, Boolean.FALSE, new String[0]))
|
||||
.as("has number of elements").hasSize(397).as("and contains the following elements")
|
||||
.containsAll(expectedIdNames).as("and NAMED filter query returns the same result")
|
||||
.containsAll(targetManagement.findAllTargetIdsByTargetFilterQuery(pageReq,
|
||||
new TargetFilterQuery("test", query)));
|
||||
}
|
||||
|
||||
@Step
|
||||
private void verifyThat1TargetWithDescOrNameHasDS(final DistributionSet setA, final Target expected) {
|
||||
final TargetIdName expectedIdName = convertToIdName(expected);
|
||||
final String query = "(name==*targ-A* or description==*targ-A*) and (assignedds.name==" + setA.getName()
|
||||
+ " or installedds.name==" + setA.getName() + ")";
|
||||
|
||||
assertThat(targetManagement
|
||||
.findTargetByFilters(pageReq, null, "%targ-A%", setA.getId(), Boolean.FALSE, new String[0])
|
||||
.getContent()).as("has number of elements").hasSize(1)
|
||||
.as("that number is also returned by count query")
|
||||
.hasSize(Ints.saturatedCast(targetManagement.countTargetByFilters(null, "%targ-A%",
|
||||
setA.getId(), Boolean.FALSE, new String[0])))
|
||||
.as("and contains the following elements").containsExactly(expected)
|
||||
.as("and filter query returns the same result")
|
||||
.containsAll(targetManagement.findTargetsAll(query, pageReq).getContent())
|
||||
.as("and NAMED filter query returns the same result").containsAll(targetManagement
|
||||
.findTargetsAll(new TargetFilterQuery("test", query), pageReq).getContent());
|
||||
|
||||
assertThat(targetManagement.findAllTargetIdsByFilters(pageReq, null, "%targ-A%", setA.getId(), Boolean.FALSE,
|
||||
new String[0])).as("has number of elements").hasSize(1).as("and contains the following elements")
|
||||
.containsExactly(expectedIdName).as("and NAMED filter query returns the same result")
|
||||
.containsAll(targetManagement.findAllTargetIdsByTargetFilterQuery(pageReq,
|
||||
new TargetFilterQuery("test", query)));
|
||||
}
|
||||
|
||||
@Step
|
||||
private void verifyThat3TargetsHaveDSAssigned(final DistributionSet setA, final List<Target> expected) {
|
||||
final List<TargetIdName> expectedIdNames = convertToIdNames(expected);
|
||||
final String query = "assignedds.name==" + setA.getName() + " or installedds.name==" + setA.getName();
|
||||
|
||||
assertThat(targetManagement.findTargetByFilters(pageReq, null, null, setA.getId(), Boolean.FALSE, new String[0])
|
||||
.getContent()).as("has number of elements").hasSize(3)
|
||||
.as("that number is also returned by count query")
|
||||
.hasSize(Ints.saturatedCast(targetManagement.countTargetByFilters(null, null, setA.getId(),
|
||||
Boolean.FALSE, new String[0])))
|
||||
.as("and contains the following elements").containsAll(expected)
|
||||
.as("and filter query returns the same result")
|
||||
.containsAll(targetManagement.findTargetsAll(query, pageReq).getContent())
|
||||
.as("and NAMED filter query returns the same result").containsAll(targetManagement
|
||||
.findTargetsAll(new TargetFilterQuery("test", query), pageReq).getContent());
|
||||
|
||||
assertThat(targetManagement.findAllTargetIdsByFilters(pageReq, null, null, setA.getId(), Boolean.FALSE,
|
||||
new String[0])).as("has number of elements").hasSize(3).as("and contains the following elements")
|
||||
.containsAll(expectedIdNames).as("and NAMED filter query returns the same result")
|
||||
.containsAll(targetManagement.findAllTargetIdsByTargetFilterQuery(pageReq,
|
||||
new TargetFilterQuery("test", query)));
|
||||
}
|
||||
|
||||
@Step
|
||||
private void verifyThat0TargetsWithNameOrdescAndDSHaveTag(final TargetTag targTagX, final DistributionSet setA) {
|
||||
final String query = "(name==*targ-C* or description==*targ-C*) and tag==" + targTagX.getName()
|
||||
+ " and (assignedds.name==" + setA.getName() + " or installedds.name==" + setA.getName() + ")";
|
||||
assertThat(targetManagement
|
||||
.findTargetByFilters(pageReq, null, "%targ-C%", setA.getId(), Boolean.FALSE, targTagX.getName())
|
||||
.getContent()).as("has number of elements").hasSize(0)
|
||||
.as("that number is also returned by count query")
|
||||
.hasSize(Ints.saturatedCast(targetManagement.countTargetByFilters(null, "%targ-C%",
|
||||
setA.getId(), Boolean.FALSE, targTagX.getName())))
|
||||
.as("and filter query returns the same result")
|
||||
.hasSize(targetManagement.findTargetsAll(query, pageReq).getContent().size())
|
||||
.as("and NAMED filter query returns the same result").hasSize(targetManagement
|
||||
.findTargetsAll(new TargetFilterQuery("test", query), pageReq).getContent().size());
|
||||
|
||||
assertThat(targetManagement.findAllTargetIdsByFilters(pageReq, null, "%targ-C%", setA.getId(), Boolean.FALSE,
|
||||
targTagX.getName())).as("has number of elements").hasSize(0)
|
||||
.as("and NAMED filter query returns the same result").containsAll(targetManagement
|
||||
.findAllTargetIdsByTargetFilterQuery(pageReq, new TargetFilterQuery("test", query)));
|
||||
}
|
||||
|
||||
@Step
|
||||
private void verifyThat0TargetsWithTagAndDescOrNameHasDS(final TargetTag targTagW, final DistributionSet setA) {
|
||||
final String query = "(name==*targ-A* or description==*targ-A*) and tag==" + targTagW.getName()
|
||||
+ " and (assignedds.name==" + setA.getName() + " or installedds.name==" + setA.getName() + ")";
|
||||
assertThat(targetManagement
|
||||
.findTargetByFilters(pageReq, null, "%targ-A%", setA.getId(), Boolean.FALSE, targTagW.getName())
|
||||
.getContent()).as("has number of elements").hasSize(0)
|
||||
.as("that number is also returned by count query")
|
||||
.hasSize(Ints.saturatedCast(targetManagement.countTargetByFilters(null, "%targ-A%",
|
||||
setA.getId(), Boolean.FALSE, targTagW.getName())))
|
||||
.as("and filter query returns the same result")
|
||||
.hasSize(targetManagement.findTargetsAll(query, pageReq).getContent().size())
|
||||
.as("and NAMED filter query returns the same result").hasSize(targetManagement
|
||||
.findTargetsAll(new TargetFilterQuery("test", query), pageReq).getContent().size());
|
||||
|
||||
assertThat(targetManagement.findAllTargetIdsByFilters(pageReq, null, "%targ-A%", setA.getId(), Boolean.FALSE,
|
||||
targTagW.getName())).as("has number of elements").hasSize(0)
|
||||
.as("and NAMED filter query returns the same result").containsAll(targetManagement
|
||||
.findAllTargetIdsByTargetFilterQuery(pageReq, new TargetFilterQuery("test", query)));
|
||||
}
|
||||
|
||||
@Step
|
||||
private void verifyThat1TargetHasTagHasDescOrNameAndDs(final TargetTag targTagW, final DistributionSet setA,
|
||||
final Target expected) {
|
||||
final TargetIdName expectedIdName = convertToIdName(expected);
|
||||
final String query = "(name==*targ-c* or description==*targ-C*) and tag==" + targTagW.getName()
|
||||
+ " and (assignedds.name==" + setA.getName() + " or installedds.name==" + setA.getName() + ")";
|
||||
assertThat(targetManagement
|
||||
.findTargetByFilters(pageReq, null, "%targ-C%", setA.getId(), Boolean.FALSE, targTagW.getName())
|
||||
.getContent()).as("has number of elements").hasSize(1)
|
||||
.as("that number is also returned by count query")
|
||||
.hasSize(Ints.saturatedCast(targetManagement.countTargetByFilters(null, "%targ-C%",
|
||||
setA.getId(), Boolean.FALSE, targTagW.getName())))
|
||||
.as("and contains the following elements").containsExactly(expected)
|
||||
.as("and filter query returns the same result")
|
||||
.containsAll(targetManagement.findTargetsAll(query, pageReq).getContent())
|
||||
.as("and NAMED filter query returns the same result").containsAll(targetManagement
|
||||
.findTargetsAll(new TargetFilterQuery("test", query), pageReq).getContent());
|
||||
|
||||
assertThat(targetManagement.findAllTargetIdsByFilters(pageReq, null, "%targ-C%", setA.getId(), Boolean.FALSE,
|
||||
targTagW.getName())).as("has number of elements").hasSize(1).as("and contains the following elements")
|
||||
.containsExactly(expectedIdName).as("and NAMED filter query returns the same result")
|
||||
.containsAll(targetManagement.findAllTargetIdsByTargetFilterQuery(pageReq,
|
||||
new TargetFilterQuery("test", query)));
|
||||
}
|
||||
|
||||
@Step
|
||||
private void verifyThat100TargetsContainsGivenTextAndHaveTagAssigned(final TargetTag targTagY,
|
||||
final TargetTag targTagW, final List<Target> expected) {
|
||||
final List<TargetIdName> expectedIdNames = convertToIdNames(expected);
|
||||
final String query = "(name==*targ-B* or description==*targ-B*) and (tag==" + targTagY.getName() + " or tag=="
|
||||
+ targTagW.getName() + ")";
|
||||
assertThat(targetManagement.findTargetByFilters(pageReq, null, "%targ-B%", null, Boolean.FALSE,
|
||||
targTagY.getName(), targTagW.getName()).getContent()).as("has number of elements").hasSize(100)
|
||||
.as("that number is also returned by count query")
|
||||
.hasSize(Ints.saturatedCast(targetManagement.countTargetByFilters(null, "%targ-B%", null,
|
||||
Boolean.FALSE, targTagY.getName(), targTagW.getName())))
|
||||
.as("and contains the following elements").containsAll(expected)
|
||||
.as("and filter query returns the same result")
|
||||
.containsAll(targetManagement.findTargetsAll(query, pageReq).getContent())
|
||||
.as("and NAMED filter query returns the same result").containsAll(targetManagement
|
||||
.findTargetsAll(new TargetFilterQuery("test", query), pageReq).getContent());
|
||||
|
||||
assertThat(targetManagement.findAllTargetIdsByFilters(pageReq, null, "%targ-B%", null, Boolean.FALSE,
|
||||
targTagY.getName(), targTagW.getName())).as("has number of elements").hasSize(100)
|
||||
.as("and contains the following elements").containsAll(expectedIdNames)
|
||||
.as("and NAMED filter query returns the same result").containsAll(targetManagement
|
||||
.findAllTargetIdsByTargetFilterQuery(pageReq, new TargetFilterQuery("test", query)));
|
||||
|
||||
}
|
||||
|
||||
@SafeVarargs
|
||||
private final List<Target> concat(final List<Target>... targets) {
|
||||
final List<Target> result = new ArrayList<>();
|
||||
Arrays.asList(targets).forEach(result::addAll);
|
||||
return result;
|
||||
}
|
||||
|
||||
@Step
|
||||
private void verifyThat200TargetsHaveTagD(final TargetTag targTagD, final List<Target> expected) {
|
||||
final List<TargetIdName> expectedIdNames = convertToIdNames(expected);
|
||||
final String query = "tag==" + targTagD.getName();
|
||||
assertThat(targetManagement.findTargetByFilters(pageReq, null, null, null, Boolean.FALSE, targTagD.getName())
|
||||
.getContent()).as("Expected number of results is").hasSize(200)
|
||||
.as("and is expected number of results is equal to ")
|
||||
.hasSize(Ints.saturatedCast(targetManagement.countTargetByFilters(null, null, null,
|
||||
Boolean.FALSE, targTagD.getName())))
|
||||
.as("and contains the following elements").containsAll(expected)
|
||||
.as("and filter query returns the same result")
|
||||
.containsAll(targetManagement.findTargetsAll(query, pageReq).getContent())
|
||||
.as("and NAMED filter query returns the same result").containsAll(targetManagement
|
||||
.findTargetsAll(new TargetFilterQuery("test", query), pageReq).getContent());
|
||||
|
||||
assertThat(targetManagement.findAllTargetIdsByFilters(pageReq, null, null, null, Boolean.FALSE,
|
||||
targTagD.getName())).as("has number of elements").hasSize(200).as("and contains the following elements")
|
||||
.containsAll(expectedIdNames).as("and NAMED filter query returns the same result")
|
||||
.containsAll(targetManagement.findAllTargetIdsByTargetFilterQuery(pageReq,
|
||||
new TargetFilterQuery("test", query)));
|
||||
|
||||
}
|
||||
|
||||
@Step
|
||||
private void verifyThatRepositoryContains400Targets() {
|
||||
assertThat(targetManagement.findTargetByFilters(pageReq, null, null, null, null, new String[0]).getContent())
|
||||
.as("Overall we expect that many targets in the repository").hasSize(400)
|
||||
.as("which is also reflected by repository count")
|
||||
.hasSize(Ints.saturatedCast(targetManagement.countTargetsAll()))
|
||||
.as("which is also reflected by call without specification")
|
||||
.containsAll(targetManagement.findTargetsAll(pageReq).getContent());
|
||||
|
||||
}
|
||||
|
||||
// TODO kaizimmerm: add filter tests
|
||||
@Test
|
||||
@Description("Tests the correct order of targets based on selected distribution set. The system expects to have an order based on installed, assigned DS.")
|
||||
public void targetSearchWithVariousFilterCombinationsAndOrderByDistributionSet() {
|
||||
@@ -205,7 +685,7 @@ public class TargetManagementSearchTest extends AbstractIntegrationTest {
|
||||
targInstalled = sendUpdateActionStatusToTargets(ds, targInstalled, Status.FINISHED, "installed");
|
||||
|
||||
final Slice<Target> result = targetManagement.findTargetsAllOrderByLinkedDistributionSet(pageReq, ds.getId(),
|
||||
null, null, null, Boolean.FALSE, null);
|
||||
null, null, null, Boolean.FALSE, new String[0]);
|
||||
|
||||
final Comparator<TenantAwareBaseEntity> byId = (e1, e2) -> Long.compare(e2.getId(), e1.getId());
|
||||
|
||||
@@ -222,6 +702,103 @@ public class TargetManagementSearchTest extends AbstractIntegrationTest {
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
@Description("Verfies that targets with given assigned DS are returned from repository.")
|
||||
public void findTargetByAssignedDistributionSet() {
|
||||
final DistributionSet assignedSet = TestDataUtil.generateDistributionSet("", softwareManagement,
|
||||
distributionSetManagement);
|
||||
targetManagement.createTargets(TestDataUtil.generateTargets(10, "unassigned"));
|
||||
final List<Target> assignedtargets = targetManagement
|
||||
.createTargets(TestDataUtil.generateTargets(10, "assigned"));
|
||||
|
||||
deploymentManagement.assignDistributionSet(assignedSet, assignedtargets);
|
||||
|
||||
assertThat(targetManagement.findTargetByAssignedDistributionSet(assignedSet.getId(), pageReq))
|
||||
.as("Contains the assigned targets").containsAll(assignedtargets)
|
||||
.as("and that means the following expected amount").hasSize(10);
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
@Description("Verfies that targets with given assigned DS and additonal specification are returned from repository.")
|
||||
public void findTargetByAssignedDistributionSetWithAdditonalSpecification() {
|
||||
final DistributionSet assignedSet = TestDataUtil.generateDistributionSet("", softwareManagement,
|
||||
distributionSetManagement);
|
||||
final DistributionSet installedSet = TestDataUtil.generateDistributionSet("another", softwareManagement,
|
||||
distributionSetManagement);
|
||||
targetManagement.createTargets(TestDataUtil.generateTargets(10, "unassigned"));
|
||||
final List<Target> assignedtargets = targetManagement
|
||||
.createTargets(TestDataUtil.generateTargets(10, "assigned"));
|
||||
|
||||
// set on installed and assign another one
|
||||
deploymentManagement.assignDistributionSet(installedSet, assignedtargets).getActions().forEach(actionId -> {
|
||||
final Action action = deploymentManagement.findActionWithDetails(actionId);
|
||||
action.setStatus(Status.FINISHED);
|
||||
controllerManagament.addUpdateActionStatus(
|
||||
new ActionStatus(action, Status.FINISHED, System.currentTimeMillis(), "message"), action);
|
||||
});
|
||||
deploymentManagement.assignDistributionSet(assignedSet, assignedtargets);
|
||||
|
||||
assertThat(targetManagement.findTargetByAssignedDistributionSet(assignedSet.getId(),
|
||||
TargetSpecifications.hasInstalledDistributionSet(installedSet.getId()), pageReq))
|
||||
.as("Contains the assigned targets").containsAll(assignedtargets)
|
||||
.as("and that means the following expected amount").hasSize(10);
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
@Description("Verfies that targets with given installed DS are returned from repository.")
|
||||
public void findTargetByInstalledDistributionSet() {
|
||||
final DistributionSet assignedSet = TestDataUtil.generateDistributionSet("", softwareManagement,
|
||||
distributionSetManagement);
|
||||
final DistributionSet installedSet = TestDataUtil.generateDistributionSet("another", softwareManagement,
|
||||
distributionSetManagement);
|
||||
targetManagement.createTargets(TestDataUtil.generateTargets(10, "unassigned"));
|
||||
final List<Target> installedtargets = targetManagement
|
||||
.createTargets(TestDataUtil.generateTargets(10, "assigned"));
|
||||
|
||||
// set on installed and assign another one
|
||||
deploymentManagement.assignDistributionSet(installedSet, installedtargets).getActions().forEach(actionId -> {
|
||||
final Action action = deploymentManagement.findActionWithDetails(actionId);
|
||||
action.setStatus(Status.FINISHED);
|
||||
controllerManagament.addUpdateActionStatus(
|
||||
new ActionStatus(action, Status.FINISHED, System.currentTimeMillis(), "message"), action);
|
||||
});
|
||||
deploymentManagement.assignDistributionSet(assignedSet, installedtargets);
|
||||
|
||||
assertThat(targetManagement.findTargetByInstalledDistributionSet(installedSet.getId(), pageReq))
|
||||
.as("Contains the assigned targets").containsAll(installedtargets)
|
||||
.as("and that means the following expected amount").hasSize(10);
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
@Description("Verfies that targets with given installed DS and additonal specification are returned from repository.")
|
||||
public void findTargetByInstalledDistributionSetWithAdditonalSpecification() {
|
||||
final DistributionSet assignedSet = TestDataUtil.generateDistributionSet("", softwareManagement,
|
||||
distributionSetManagement);
|
||||
final DistributionSet installedSet = TestDataUtil.generateDistributionSet("another", softwareManagement,
|
||||
distributionSetManagement);
|
||||
targetManagement.createTargets(TestDataUtil.generateTargets(10, "unassigned"));
|
||||
final List<Target> installedtargets = targetManagement
|
||||
.createTargets(TestDataUtil.generateTargets(10, "assigned"));
|
||||
|
||||
// set on installed and assign another one
|
||||
deploymentManagement.assignDistributionSet(installedSet, installedtargets).getActions().forEach(actionId -> {
|
||||
final Action action = deploymentManagement.findActionWithDetails(actionId);
|
||||
action.setStatus(Status.FINISHED);
|
||||
controllerManagament.addUpdateActionStatus(
|
||||
new ActionStatus(action, Status.FINISHED, System.currentTimeMillis(), "message"), action);
|
||||
});
|
||||
deploymentManagement.assignDistributionSet(assignedSet, installedtargets);
|
||||
|
||||
assertThat(targetManagement.findTargetByInstalledDistributionSet(installedSet.getId(),
|
||||
TargetSpecifications.hasAssignedDistributionSet(assignedSet.getId()), pageReq))
|
||||
.as("Contains the assigned targets").containsAll(installedtargets)
|
||||
.as("and that means the following expected amount").hasSize(10);
|
||||
|
||||
}
|
||||
|
||||
private List<Target> sendUpdateActionStatusToTargets(final DistributionSet dsA, final Iterable<Target> targs,
|
||||
final Status status, final String... msgs) {
|
||||
final List<Target> result = new ArrayList<Target>();
|
||||
|
||||
@@ -60,8 +60,9 @@ public class TargetManagementTest extends AbstractIntegrationTest {
|
||||
public void createTargetForTenantWhichDoesNotExistThrowsTenantNotExistException() {
|
||||
try {
|
||||
targetManagement.createTarget(new Target("targetId123"));
|
||||
fail("tenant not exist");
|
||||
fail("should not be possible as the tenant does not exist");
|
||||
} catch (final TenantNotExistException e) {
|
||||
// ok
|
||||
}
|
||||
}
|
||||
|
||||
@@ -206,6 +207,12 @@ public class TargetManagementTest extends AbstractIntegrationTest {
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
@Description("Ensures that repositoy returns null if given controller ID does not exist without exception.")
|
||||
public void findTargetByControllerIDWithDetailsReturnsNullForNonexisting() {
|
||||
assertThat(targetManagement.findTargetByControllerIDWithDetails("dsfsdfsdfsd")).as("Expected as").isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
@Description("Checks if the EntityAlreadyExistsException is thrown if the targets with the same controller ID are created twice.")
|
||||
public void createMultipleTargetsDuplicate() {
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
package org.eclipse.hawkbit.repository;
|
||||
|
||||
import static org.fest.assertions.api.Assertions.assertThat;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
import java.time.Duration;
|
||||
import java.util.Arrays;
|
||||
@@ -91,13 +92,19 @@ public class TenantConfigurationManagementTest extends AbstractIntegrationTestWi
|
||||
.isEqualTo(value2);
|
||||
}
|
||||
|
||||
@Test(expected = TenantConfigurationValidatorException.class)
|
||||
@Test
|
||||
@Description("Tests that the get configuration throws exception in case the value cannot be automatically converted from String to Boolean")
|
||||
public void wrongTenantConfigurationValueTypeThrowsException() {
|
||||
final TenantConfigurationKey configKey = TenantConfigurationKey.AUTHENTICATION_MODE_HEADER_ENABLED;
|
||||
final String value1 = "thisIsNotABoolean";
|
||||
|
||||
// add value as String
|
||||
tenantConfigurationManagement.addOrUpdateConfiguration(configKey, value1);
|
||||
try {
|
||||
tenantConfigurationManagement.addOrUpdateConfiguration(configKey, value1);
|
||||
fail("should not have worked as string is not a boolean");
|
||||
} catch (final TenantConfigurationValidatorException e) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -128,46 +135,71 @@ public class TenantConfigurationManagementTest extends AbstractIntegrationTestWi
|
||||
assertThat(tenantConfigurationManagement.getConfigurationValue(configKey, String.class).getValue()).isNull();
|
||||
}
|
||||
|
||||
@Test(expected = TenantConfigurationValidatorException.class)
|
||||
@Test
|
||||
@Description("Test that an Exception is thrown, when an integer is stored but a string expected.")
|
||||
public void storesIntegerWhenStringIsExpected() {
|
||||
final TenantConfigurationKey configKey = TenantConfigurationKey.AUTHENTICATION_MODE_GATEWAY_SECURITY_TOKEN_NAME;
|
||||
final Integer wrongDataype = 123;
|
||||
tenantConfigurationManagement.addOrUpdateConfiguration(configKey, wrongDataype);
|
||||
try {
|
||||
tenantConfigurationManagement.addOrUpdateConfiguration(configKey, wrongDataype);
|
||||
fail("should not have worked as integer is not a string");
|
||||
} catch (final TenantConfigurationValidatorException e) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@Test(expected = TenantConfigurationValidatorException.class)
|
||||
@Test
|
||||
@Description("Test that an Exception is thrown, when an integer is stored but a boolean expected.")
|
||||
public void storesIntegerWhenBooleanIsExpected() {
|
||||
final TenantConfigurationKey configKey = TenantConfigurationKey.AUTHENTICATION_MODE_GATEWAY_SECURITY_TOKEN_ENABLED;
|
||||
final Integer wrongDataype = 123;
|
||||
tenantConfigurationManagement.addOrUpdateConfiguration(configKey, wrongDataype);
|
||||
try {
|
||||
tenantConfigurationManagement.addOrUpdateConfiguration(configKey, wrongDataype);
|
||||
fail("should not have worked as integer is not a boolean");
|
||||
} catch (final TenantConfigurationValidatorException e) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@Test(expected = TenantConfigurationValidatorException.class)
|
||||
@Test
|
||||
@Description("Test that an Exception is thrown, when an integer is stored as PollingTime.")
|
||||
public void storesIntegerWhenPollingIntervalIsExpected() {
|
||||
final TenantConfigurationKey configKey = TenantConfigurationKey.POLLING_TIME_INTERVAL;
|
||||
final Integer wrongDataype = 123;
|
||||
tenantConfigurationManagement.addOrUpdateConfiguration(configKey, wrongDataype);
|
||||
try {
|
||||
tenantConfigurationManagement.addOrUpdateConfiguration(configKey, wrongDataype);
|
||||
fail("should not have worked as integer is not a time field");
|
||||
} catch (final TenantConfigurationValidatorException e) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@Test(expected = TenantConfigurationValidatorException.class)
|
||||
@Test
|
||||
@Description("Test that an Exception is thrown, when an invalid formatted string is stored as PollingTime.")
|
||||
public void storesWrongFormattedStringAsPollingInterval() {
|
||||
final TenantConfigurationKey configKey = TenantConfigurationKey.POLLING_TIME_INTERVAL;
|
||||
final String wrongFormatted = "wrongFormatted";
|
||||
tenantConfigurationManagement.addOrUpdateConfiguration(configKey, wrongFormatted);
|
||||
try {
|
||||
tenantConfigurationManagement.addOrUpdateConfiguration(configKey, wrongFormatted);
|
||||
fail("should not have worked as string is not a time field");
|
||||
} catch (final TenantConfigurationValidatorException e) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@Test(expected = TenantConfigurationValidatorException.class)
|
||||
@Test
|
||||
@Description("Test that an Exception is thrown, when an invalid formatted string is stored as PollingTime.")
|
||||
public void storesTooSmallDurationAsPollingInterval() {
|
||||
final TenantConfigurationKey configKey = TenantConfigurationKey.POLLING_TIME_INTERVAL;
|
||||
|
||||
final String tooSmallDuration = DurationHelper
|
||||
.durationToFormattedString(DurationHelper.getDurationByTimeValues(0, 0, 1));
|
||||
tenantConfigurationManagement.addOrUpdateConfiguration(configKey, tooSmallDuration);
|
||||
try {
|
||||
tenantConfigurationManagement.addOrUpdateConfiguration(configKey, tooSmallDuration);
|
||||
fail("should not have worked as string has an invalid format");
|
||||
} catch (final TenantConfigurationValidatorException e) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -35,18 +35,18 @@ public class RSQLDistributionSetFieldTest extends AbstractIntegrationTest {
|
||||
@Before
|
||||
public void seuptBeforeTest() {
|
||||
|
||||
final DistributionSet ds = TestDataUtil.generateDistributionSet("DS", softwareManagement,
|
||||
distributionSetManagement);
|
||||
DistributionSet ds = TestDataUtil.generateDistributionSet("DS", softwareManagement, distributionSetManagement);
|
||||
ds.setDescription("DS");
|
||||
ds.getMetadata().add(new DistributionSetMetadata("metaKey", ds, "metaValue"));
|
||||
distributionSetManagement.updateDistributionSet(ds);
|
||||
ds = distributionSetManagement.updateDistributionSet(ds);
|
||||
distributionSetManagement
|
||||
.createDistributionSetMetadata(new DistributionSetMetadata("metaKey", ds, "metaValue"));
|
||||
|
||||
final DistributionSet ds2 = TestDataUtil
|
||||
DistributionSet ds2 = TestDataUtil
|
||||
.generateDistributionSets("NewDS", 3, softwareManagement, distributionSetManagement).get(0);
|
||||
|
||||
ds2.setDescription("DS%");
|
||||
ds2.getMetadata().add(new DistributionSetMetadata("metaKey", ds2, "value"));
|
||||
distributionSetManagement.updateDistributionSet(ds2);
|
||||
ds2 = distributionSetManagement.updateDistributionSet(ds2);
|
||||
distributionSetManagement.createDistributionSetMetadata(new DistributionSetMetadata("metaKey", ds2, "value"));
|
||||
|
||||
final DistributionSetTag targetTag = tagManagement.createDistributionSetTag(new DistributionSetTag("Tag1"));
|
||||
tagManagement.createDistributionSetTag(new DistributionSetTag("Tag2"));
|
||||
|
||||
@@ -10,6 +10,9 @@ package org.eclipse.hawkbit.repository.rsql;
|
||||
|
||||
import static org.fest.assertions.api.Assertions.assertThat;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.eclipse.hawkbit.AbstractIntegrationTest;
|
||||
import org.eclipse.hawkbit.TestDataUtil;
|
||||
import org.eclipse.hawkbit.repository.DistributionSetMetadataFields;
|
||||
@@ -35,13 +38,13 @@ public class RSQLDistributionSetMetadataFieldsTest extends AbstractIntegrationTe
|
||||
final DistributionSet distributionSet = TestDataUtil.generateDistributionSet("DS", softwareManagement,
|
||||
distributionSetManagement);
|
||||
distributionSetId = distributionSet.getId();
|
||||
|
||||
final List<DistributionSetMetadata> metadata = new ArrayList<>();
|
||||
for (int i = 0; i < 5; i++) {
|
||||
final DistributionSetMetadata distributionSetMetadata = new DistributionSetMetadata("" + i, distributionSet,
|
||||
"" + i);
|
||||
distributionSet.getMetadata().add(distributionSetMetadata);
|
||||
metadata.add(new DistributionSetMetadata("" + i, distributionSet, "" + i));
|
||||
}
|
||||
|
||||
distributionSetManagement.updateDistributionSet(distributionSet);
|
||||
distributionSetManagement.createDistributionSetMetadata(metadata);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -28,8 +28,7 @@ import ru.yandex.qatools.allure.annotations.Stories;
|
||||
public class RSQLSoftwareModuleFieldTest extends AbstractIntegrationTest {
|
||||
|
||||
@Before
|
||||
public void seuptBeforeTest() {
|
||||
|
||||
public void setupBeforeTest() {
|
||||
final SoftwareModule ah = softwareManagement
|
||||
.createSoftwareModule(new SoftwareModule(appType, "agent-hub", "1.0.1", "agent-hub", ""));
|
||||
softwareManagement.createSoftwareModule(new SoftwareModule(runtimeType, "oracle-jre", "1.7.2", "aa", ""));
|
||||
@@ -40,14 +39,9 @@ public class RSQLSoftwareModuleFieldTest extends AbstractIntegrationTest {
|
||||
|
||||
final SoftwareModuleMetadata softwareModuleMetadata = new SoftwareModuleMetadata("metaKey", ah, "metaValue");
|
||||
softwareManagement.createSoftwareModuleMetadata(softwareModuleMetadata);
|
||||
ah.getMetadata().add(softwareModuleMetadata);
|
||||
softwareManagement.updateSoftwareModule(ah);
|
||||
|
||||
final SoftwareModuleMetadata softwareModuleMetadata2 = new SoftwareModuleMetadata("metaKey", ah2, "value");
|
||||
softwareManagement.createSoftwareModuleMetadata(softwareModuleMetadata2);
|
||||
ah2.getMetadata().add(softwareModuleMetadata2);
|
||||
softwareManagement.updateSoftwareModule(ah2);
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -10,6 +10,9 @@ package org.eclipse.hawkbit.repository.rsql;
|
||||
|
||||
import static org.fest.assertions.api.Assertions.assertThat;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.eclipse.hawkbit.AbstractIntegrationTest;
|
||||
import org.eclipse.hawkbit.TestDataUtil;
|
||||
import org.eclipse.hawkbit.repository.SoftwareModuleMetadataFields;
|
||||
@@ -37,13 +40,13 @@ public class RSQLSoftwareModuleMetadataFieldsTest extends AbstractIntegrationTes
|
||||
"application", "1.0.0", "Desc", "vendor Limited, California"));
|
||||
softwareModuleId = softwareModule.getId();
|
||||
|
||||
final List<SoftwareModuleMetadata> metadata = new ArrayList<>();
|
||||
for (int i = 0; i < 5; i++) {
|
||||
final SoftwareModuleMetadata metadata = new SoftwareModuleMetadata("" + i, softwareModule, "" + i);
|
||||
softwareModule.getMetadata().add(metadata);
|
||||
softwareModuleMetadataRepository.save(metadata);
|
||||
metadata.add(new SoftwareModuleMetadata("" + i, softwareModule, "" + i));
|
||||
}
|
||||
|
||||
softwareManagement.updateSoftwareModule(softwareModule);
|
||||
softwareManagement.createSoftwareModuleMetadata(metadata);
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
Reference in New Issue
Block a user