Remove swagger and minor feature extensions and bug fixes

- Various Bug fixes and improvements
- Management API extended
- Swagger removed
- Guava Upgraded to 19
This commit is contained in:
Kai Zimmermann
2016-01-21 13:42:38 +01:00
parent fb9dfd204c
commit 64deaeea3c
813 changed files with 9787 additions and 4929 deletions

View File

@@ -12,7 +12,6 @@ import static org.fest.assertions.api.Assertions.assertThat;
import java.util.List;
import java.util.Properties;
import java.util.concurrent.Callable;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
@@ -87,7 +86,7 @@ import org.springframework.web.context.WebApplicationContext;
public abstract class AbstractIntegrationTest implements EnvironmentAware {
protected static Logger LOG = null;
protected final Pageable pageReq = new PageRequest(0, 400);
protected static final Pageable pageReq = new PageRequest(0, 400);
@PersistenceContext
protected EntityManager entityManager;
@@ -210,7 +209,7 @@ public abstract class AbstractIntegrationTest implements EnvironmentAware {
/*
* (non-Javadoc)
*
*
* @see org.springframework.context.EnvironmentAware#setEnvironment(org.
* springframework.core.env. Environment)
*/
@@ -221,42 +220,26 @@ public abstract class AbstractIntegrationTest implements EnvironmentAware {
@Before
public void before() throws Exception {
mvc = MockMvcBuilders
.webAppContextSetup(context)
.addFilter(
new DosFilter(100, 10, "127\\.0\\.0\\.1|\\[0:0:0:0:0:0:0:1\\]", "(^192\\.168\\.)",
"X-Forwarded-For"))
.addFilter(
new ExcludePathAwareShallowETagFilter(
"/rest/v1/softwaremodules/{smId}/artifacts/{artId}/download",
"/*/controller/artifacts/**")).build();
mvc = MockMvcBuilders.webAppContextSetup(context)
.addFilter(new DosFilter(100, 10, "127\\.0\\.0\\.1|\\[0:0:0:0:0:0:0:1\\]", "(^192\\.168\\.)",
"X-Forwarded-For"))
.addFilter(new ExcludePathAwareShallowETagFilter(
"/rest/v1/softwaremodules/{smId}/artifacts/{artId}/download", "/*/controller/artifacts/**"))
.build();
standardDsType = securityRule.runAsPrivileged(new Callable<DistributionSetType>() {
@Override
public DistributionSetType call() throws Exception {
return systemManagement.getTenantMetadata().getDefaultDsType();
}
});
standardDsType = securityRule.runAsPrivileged(() -> systemManagement.getTenantMetadata().getDefaultDsType());
osType = securityRule.runAsPrivileged(new Callable<SoftwareModuleType>() {
@Override
public SoftwareModuleType call() throws Exception {
return softwareManagement.findSoftwareModuleTypeByKey("os");
}
});
osType = securityRule.runAsPrivileged(() -> softwareManagement.findSoftwareModuleTypeByKey("os"));
osType.setDescription("Updated description to have lastmodified available in tests");
osType = securityRule.runAsPrivileged(() -> softwareManagement.updateSoftwareModuleType(osType));
appType = securityRule.runAsPrivileged(new Callable<SoftwareModuleType>() {
@Override
public SoftwareModuleType call() throws Exception {
return softwareManagement.findSoftwareModuleTypeByKey("application");
}
});
runtimeType = securityRule.runAsPrivileged(new Callable<SoftwareModuleType>() {
@Override
public SoftwareModuleType call() throws Exception {
return softwareManagement.findSoftwareModuleTypeByKey("runtime");
}
});
appType = securityRule.runAsPrivileged(() -> softwareManagement.findSoftwareModuleTypeByKey("application"));
appType.setDescription("Updated description to have lastmodified available in tests");
appType = securityRule.runAsPrivileged(() -> softwareManagement.updateSoftwareModuleType(appType));
runtimeType = securityRule.runAsPrivileged(() -> softwareManagement.findSoftwareModuleTypeByKey("runtime"));
runtimeType.setDescription("Updated description to have lastmodified available in tests");
runtimeType = securityRule.runAsPrivileged(() -> softwareManagement.updateSoftwareModuleType(runtimeType));
}
@BeforeClass
@@ -297,20 +280,12 @@ public abstract class AbstractIntegrationTest implements EnvironmentAware {
@Transactional
protected void deleteAllRepos() throws Exception {
final List<String> tenants = securityRule.runAs(WithSpringAuthorityRule.withUser(false),
new Callable<List<String>>() {
@Override
public List<String> call() throws Exception {
return systemManagement.findTenants();
}
});
() -> systemManagement.findTenants());
tenants.forEach(tenant -> {
try {
securityRule.runAs(WithSpringAuthorityRule.withUser(false), new Callable<Void>() {
@Override
public Void call() throws Exception {
systemManagement.deleteTenant(tenant);
return null;
}
securityRule.runAs(WithSpringAuthorityRule.withUser(false), () -> {
systemManagement.deleteTenant(tenant);
return null;
});
} catch (final Exception e) {
e.printStackTrace();

View File

View File

View File

View File

View File

View File

@@ -26,6 +26,7 @@ import org.eclipse.hawkbit.Constants;
import org.eclipse.hawkbit.TestDataUtil;
import org.eclipse.hawkbit.eventbus.event.CancelTargetAssignmentEvent;
import org.eclipse.hawkbit.eventbus.event.TargetAssignDistributionSetEvent;
import org.eclipse.hawkbit.repository.exception.ForceQuitActionNotAllowedException;
import org.eclipse.hawkbit.repository.exception.IncompleteDistributionSetException;
import org.eclipse.hawkbit.repository.model.Action;
import org.eclipse.hawkbit.repository.model.Action.ActionType;
@@ -43,16 +44,16 @@ import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Sort.Direction;
import com.google.common.collect.Iterables;
import com.google.common.collect.Lists;
import com.google.common.eventbus.EventBus;
import com.google.common.eventbus.Subscribe;
import ru.yandex.qatools.allure.annotations.Description;
import ru.yandex.qatools.allure.annotations.Features;
import ru.yandex.qatools.allure.annotations.Issue;
import ru.yandex.qatools.allure.annotations.Stories;
import com.google.common.collect.Iterables;
import com.google.common.collect.Lists;
import com.google.common.eventbus.EventBus;
import com.google.common.eventbus.Subscribe;
/**
* Test class testing the functionality of triggering a deployment of
* {@link DistributionSet}s to {@link Target}s.
@@ -84,6 +85,42 @@ public class DeploymentManagementTest extends AbstractIntegrationTest {
assertThat(findActionsWithStatusCountByTarget.get(0).getActionStatusCount()).isEqualTo(3L);
}
@Test
@Description("Ensures that distribution sets can assigned and unassigned to a distribution set tag. Not exists distribution set will be ignored for the assignment.")
public void assignAndUnassignDistributionSetToTag() {
final List<Long> assignDS = new ArrayList<Long>();
for (int i = 0; i < 4; i++) {
assignDS.add(TestDataUtil.generateDistributionSet("DS" + i, "1.0", softwareManagement,
distributionSetManagement, new ArrayList<DistributionSetTag>()).getId());
}
// not exists
assignDS.add(Long.valueOf(100));
final DistributionSetTag tag = tagManagement.createDistributionSetTag(new DistributionSetTag("Tag1"));
final List<DistributionSet> assignedDS = distributionSetManagement.assignTag(assignDS, tag);
assertThat(assignedDS.size()).isEqualTo(4);
assignedDS.forEach(ds -> assertThat(ds.getTags().size()).isEqualTo(1));
DistributionSetTag findDistributionSetTag = tagManagement.findDistributionSetTag("Tag1");
assertThat(assignedDS.size()).isEqualTo(findDistributionSetTag.getAssignedToDistributionSet().size());
assertThat(distributionSetManagement.unAssignTag(Long.valueOf(100), findDistributionSetTag)).isNull();
final DistributionSet unAssignDS = distributionSetManagement.unAssignTag(assignDS.get(0),
findDistributionSetTag);
assertThat(unAssignDS.getId()).isEqualTo(assignDS.get(0));
assertThat(unAssignDS.getTags().size()).isEqualTo(0);
findDistributionSetTag = tagManagement.findDistributionSetTag("Tag1");
assertThat(findDistributionSetTag.getAssignedToDistributionSet().size()).isEqualTo(3);
final List<DistributionSet> unAssignTargets = distributionSetManagement
.unAssignAllDistributionSetsByTag(findDistributionSetTag);
findDistributionSetTag = tagManagement.findDistributionSetTag("Tag1");
assertThat(findDistributionSetTag.getAssignedToDistributionSet().size()).isEqualTo(0);
assertThat(unAssignTargets.size()).isEqualTo(3);
unAssignTargets.forEach(target -> assertThat(target.getTags().size()).isEqualTo(0));
}
@Test
@Description("Test verifies that an assignment with automatic cancelation works correctly even if the update is split into multiple partitions on the database.")
@Issue("MECS-674")
@@ -92,19 +129,21 @@ public class DeploymentManagementTest extends AbstractIntegrationTest {
final DistributionSet cancelDs = TestDataUtil.generateDistributionSet("Canceled DS", "1.0", softwareManagement,
distributionSetManagement, new ArrayList<DistributionSetTag>());
final DistributionSet cancelDs2 = TestDataUtil.generateDistributionSet("Canceled DS", "1.2", softwareManagement,
distributionSetManagement, new ArrayList<DistributionSetTag>());
final DistributionSet cancelDs2 = TestDataUtil.generateDistributionSet("Canceled DS", "1.2",
softwareManagement, distributionSetManagement, new ArrayList<DistributionSetTag>());
List<Target> targets = targetManagement
.createTargets(TestDataUtil.generateTargets(Constants.MAX_ENTRIES_IN_STATEMENT + 10));
List<Target> targets = targetManagement.createTargets(TestDataUtil
.generateTargets(Constants.MAX_ENTRIES_IN_STATEMENT + 10));
targets = deploymentManagement.assignDistributionSet(cancelDs, targets).getAssignedTargets();
targets = deploymentManagement.assignDistributionSet(cancelDs2, targets).getAssignedTargets();
targetManagement.findAllTargetIds().forEach(targetIdName -> {
assertThat(deploymentManagement.findActiveActionsByTarget(
targetManagement.findTargetByControllerID(targetIdName.getControllerId()))).hasSize(2);
});
targetManagement.findAllTargetIds().forEach(
targetIdName -> {
assertThat(
deploymentManagement.findActiveActionsByTarget(targetManagement
.findTargetByControllerID(targetIdName.getControllerId()))).hasSize(2);
});
}
@Test
@@ -125,8 +164,8 @@ public class DeploymentManagementTest extends AbstractIntegrationTest {
target = targetManagement.createTarget(target);
// check initial status
assertThat(targetManagement.findTargetByControllerID("4712").getTargetInfo().getUpdateStatus())
.isEqualTo(TargetUpdateStatus.UNKNOWN);
assertThat(targetManagement.findTargetByControllerID("4712").getTargetInfo().getUpdateStatus()).isEqualTo(
TargetUpdateStatus.UNKNOWN);
// assign the two sets in a row
Action firstAction = assignSet(target, dsFirst);
@@ -145,8 +184,8 @@ public class DeploymentManagementTest extends AbstractIntegrationTest {
new ActionStatus(secondAction, Status.CANCELED, System.currentTimeMillis()), secondAction);
assertThat(actionStatusRepository.findAll()).hasSize(4);
assertThat(targetManagement.findTargetByControllerID("4712").getAssignedDistributionSet()).isEqualTo(dsFirst);
assertThat(targetManagement.findTargetByControllerID("4712").getTargetInfo().getUpdateStatus())
.isEqualTo(TargetUpdateStatus.PENDING);
assertThat(targetManagement.findTargetByControllerID("4712").getTargetInfo().getUpdateStatus()).isEqualTo(
TargetUpdateStatus.PENDING);
// we cancel first -> back to installed
deploymentManagement.cancelAction(firstAction,
@@ -157,10 +196,10 @@ public class DeploymentManagementTest extends AbstractIntegrationTest {
controllerManagement.addCancelActionStatus(
new ActionStatus(firstAction, Status.CANCELED, System.currentTimeMillis()), firstAction);
assertThat(actionStatusRepository.findAll()).hasSize(6);
assertThat(targetManagement.findTargetByControllerID("4712").getAssignedDistributionSet())
.isEqualTo(dsInstalled);
assertThat(targetManagement.findTargetByControllerID("4712").getTargetInfo().getUpdateStatus())
.isEqualTo(TargetUpdateStatus.IN_SYNC);
assertThat(targetManagement.findTargetByControllerID("4712").getAssignedDistributionSet()).isEqualTo(
dsInstalled);
assertThat(targetManagement.findTargetByControllerID("4712").getTargetInfo().getUpdateStatus()).isEqualTo(
TargetUpdateStatus.IN_SYNC);
}
@Test
@@ -181,8 +220,8 @@ public class DeploymentManagementTest extends AbstractIntegrationTest {
target = targetManagement.createTarget(target);
// check initial status
assertThat(targetManagement.findTargetByControllerID("4712").getTargetInfo().getUpdateStatus())
.isEqualTo(TargetUpdateStatus.UNKNOWN);
assertThat(targetManagement.findTargetByControllerID("4712").getTargetInfo().getUpdateStatus()).isEqualTo(
TargetUpdateStatus.UNKNOWN);
// assign the two sets in a row
Action firstAction = assignSet(target, dsFirst);
@@ -201,8 +240,8 @@ public class DeploymentManagementTest extends AbstractIntegrationTest {
new ActionStatus(firstAction, Status.CANCELED, System.currentTimeMillis()), firstAction);
assertThat(actionStatusRepository.findAll()).hasSize(4);
assertThat(targetManagement.findTargetByControllerID("4712").getAssignedDistributionSet()).isEqualTo(dsSecond);
assertThat(targetManagement.findTargetByControllerID("4712").getTargetInfo().getUpdateStatus())
.isEqualTo(TargetUpdateStatus.PENDING);
assertThat(targetManagement.findTargetByControllerID("4712").getTargetInfo().getUpdateStatus()).isEqualTo(
TargetUpdateStatus.PENDING);
// we cancel second -> remain assigned until finished cancellation
deploymentManagement.cancelAction(secondAction,
@@ -215,17 +254,90 @@ public class DeploymentManagementTest extends AbstractIntegrationTest {
controllerManagement.addCancelActionStatus(
new ActionStatus(secondAction, Status.CANCELED, System.currentTimeMillis()), secondAction);
// cancelled success -> back to dsInstalled
assertThat(targetManagement.findTargetByControllerID("4712").getAssignedDistributionSet())
.isEqualTo(dsInstalled);
assertThat(targetManagement.findTargetByControllerID("4712").getTargetInfo().getUpdateStatus())
.isEqualTo(TargetUpdateStatus.IN_SYNC);
assertThat(targetManagement.findTargetByControllerID("4712").getAssignedDistributionSet()).isEqualTo(
dsInstalled);
assertThat(targetManagement.findTargetByControllerID("4712").getTargetInfo().getUpdateStatus()).isEqualTo(
TargetUpdateStatus.IN_SYNC);
}
@Test
@Description("Force Quit an Assignment. Expected behaviour is that the action is canceled and is marked as deleted. The assigned Software module")
public void forceQuitSetActionToInactive() throws InterruptedException {
Target target = new Target("4712");
final DistributionSet dsInstalled = TestDataUtil.generateDistributionSet("installed", softwareManagement,
distributionSetManagement, true);
target.getTargetInfo().setInstalledDistributionSet(dsInstalled);
target = targetManagement.createTarget(target);
final DistributionSet ds = TestDataUtil.generateDistributionSet("newDS", softwareManagement,
distributionSetManagement, true).setRequiredMigrationStep(true);
// verify initial status
assertThat(targetManagement.findTargetByControllerID("4712").getTargetInfo().getUpdateStatus()).isEqualTo(
TargetUpdateStatus.UNKNOWN);
Action assigningAction = assignSet(target, ds);
// verify assignment
assertThat(actionRepository.findAll()).hasSize(1);
assertThat(actionStatusRepository.findAll()).hasSize(1);
target = targetManagement.findTargetByControllerID(target.getControllerId());
// force quit assignment
deploymentManagement.cancelAction(assigningAction, target);
assigningAction = deploymentManagement.findActionWithDetails(assigningAction.getId());
deploymentManagement.forceQuitAction(assigningAction, target);
assigningAction = deploymentManagement.findActionWithDetails(assigningAction.getId());
// verify
assertThat(assigningAction.getStatus()).isEqualTo(Status.CANCELED);
assertThat(targetManagement.findTargetByControllerID("4712").getAssignedDistributionSet()).isEqualTo(
dsInstalled);
assertThat(targetManagement.findTargetByControllerID("4712").getTargetInfo().getUpdateStatus()).isEqualTo(
TargetUpdateStatus.IN_SYNC);
}
@Test
@Description("Force Quit an not canceled Assignment. Expected behaviour is that the action can not be force quit and there is thrown an exception.")
public void forceQuitNotAllowedThrowsException() {
Target target = new Target("4712");
final DistributionSet dsInstalled = TestDataUtil.generateDistributionSet("installed", softwareManagement,
distributionSetManagement, true);
target.getTargetInfo().setInstalledDistributionSet(dsInstalled);
target = targetManagement.createTarget(target);
final DistributionSet ds = TestDataUtil.generateDistributionSet("newDS", softwareManagement,
distributionSetManagement, true).setRequiredMigrationStep(true);
// verify initial status
assertThat(targetManagement.findTargetByControllerID("4712").getTargetInfo().getUpdateStatus()).isEqualTo(
TargetUpdateStatus.UNKNOWN);
final Action assigningAction = assignSet(target, ds);
// verify assignment
assertThat(actionRepository.findAll()).hasSize(1);
assertThat(actionStatusRepository.findAll()).hasSize(1);
// force quit assignment
try {
deploymentManagement.forceQuitAction(assigningAction,
targetManagement.findTargetByControllerID(target.getControllerId()));
fail("expected ForceQuitActionNotAllowedException");
} catch (final ForceQuitActionNotAllowedException ex) {
}
}
private Action assignSet(final Target target, final DistributionSet ds) {
deploymentManagement.assignDistributionSet(ds.getId(), new String[] { target.getControllerId() });
assertThat(
targetManagement.findTargetByControllerID(target.getControllerId()).getTargetInfo().getUpdateStatus())
.isEqualTo(TargetUpdateStatus.PENDING);
.isEqualTo(TargetUpdateStatus.PENDING);
assertThat(targetManagement.findTargetByControllerID(target.getControllerId()).getAssignedDistributionSet())
.isEqualTo(ds);
final Action action = actionRepository.findByTargetAndDistributionSet(pageReq, target, ds).getContent().get(0);
@@ -248,12 +360,12 @@ public class DeploymentManagementTest extends AbstractIntegrationTest {
eventBus.register(eventHandlerMock);
final String myCtrlIDPref = "myCtrlID";
final Iterable<Target> savedNakedTargets = targetManagement
.createTargets(TestDataUtil.buildTargetFixtures(10, myCtrlIDPref, "first description"));
final Iterable<Target> savedNakedTargets = targetManagement.createTargets(TestDataUtil.buildTargetFixtures(10,
myCtrlIDPref, "first description"));
final String myDeployedCtrlIDPref = "myDeployedCtrlID";
final List<Target> savedDeployedTargets = targetManagement
.createTargets(TestDataUtil.buildTargetFixtures(20, myDeployedCtrlIDPref, "first description"));
final List<Target> savedDeployedTargets = targetManagement.createTargets(TestDataUtil.buildTargetFixtures(20,
myDeployedCtrlIDPref, "first description"));
final DistributionSet ds = TestDataUtil.generateDistributionSet("", softwareManagement,
distributionSetManagement);
@@ -297,15 +409,15 @@ public class DeploymentManagementTest extends AbstractIntegrationTest {
final List<Target> targets = targetManagement.createTargets(TestDataUtil.generateTargets(10));
final SoftwareModule ah = softwareManagement
.createSoftwareModule(new SoftwareModule(appType, "agent-hub", "1.0.1", null, ""));
final SoftwareModule jvm = softwareManagement
.createSoftwareModule(new SoftwareModule(runtimeType, "oracle-jre", "1.7.2", null, ""));
final SoftwareModule os = softwareManagement
.createSoftwareModule(new SoftwareModule(osType, "poky", "3.0.2", null, ""));
final SoftwareModule ah = softwareManagement.createSoftwareModule(new SoftwareModule(appType, "agent-hub",
"1.0.1", null, ""));
final SoftwareModule jvm = softwareManagement.createSoftwareModule(new SoftwareModule(runtimeType,
"oracle-jre", "1.7.2", null, ""));
final SoftwareModule os = softwareManagement.createSoftwareModule(new SoftwareModule(osType, "poky", "3.0.2",
null, ""));
final DistributionSet incomplete = distributionSetManagement.createDistributionSet(
new DistributionSet("incomplete", "v1", "", standardDsType, Lists.newArrayList(ah, jvm)));
final DistributionSet incomplete = distributionSetManagement.createDistributionSet(new DistributionSet(
"incomplete", "v1", "", standardDsType, Lists.newArrayList(ah, jvm)));
try {
deploymentManagement.assignDistributionSet(incomplete, targets);
@@ -375,18 +487,18 @@ public class DeploymentManagementTest extends AbstractIntegrationTest {
final Iterable<Target> undeployedTargetsFromDB = targetRepository.findAll(undeployedTargetIDs);
// test that number of Targets
assertThat(allFoundTargets.spliterator().getExactSizeIfKnown())
.isEqualTo(deployedTargetsFromDB.spliterator().getExactSizeIfKnown()
assertThat(allFoundTargets.spliterator().getExactSizeIfKnown()).isEqualTo(
deployedTargetsFromDB.spliterator().getExactSizeIfKnown()
+ undeployedTargetsFromDB.spliterator().getExactSizeIfKnown());
assertThat(deployedTargetsFromDB.spliterator().getExactSizeIfKnown()).isEqualTo(noOfDeployedTargets);
assertThat(undeployedTargetsFromDB.spliterator().getExactSizeIfKnown()).isEqualTo(noOfUndeployedTargets);
// test the content of different lists
assertThat(allFoundTargets).containsAll(deployedTargetsFromDB).containsAll(undeployedTargetsFromDB);
assertThat(deployedTargetsFromDB).containsAll(savedDeployedTargets)
.doesNotContain(Iterables.toArray(undeployedTargetsFromDB, Target.class));
assertThat(undeployedTargetsFromDB).containsAll(savedNakedTargets)
.doesNotContain(Iterables.toArray(deployedTargetsFromDB, Target.class));
assertThat(deployedTargetsFromDB).containsAll(savedDeployedTargets).doesNotContain(
Iterables.toArray(undeployedTargetsFromDB, Target.class));
assertThat(undeployedTargetsFromDB).containsAll(savedNakedTargets).doesNotContain(
Iterables.toArray(deployedTargetsFromDB, Target.class));
// For each of the 4 targets 1 distribution sets gets assigned
eventHandlerMock.getEvents(10, TimeUnit.SECONDS);
@@ -420,18 +532,21 @@ public class DeploymentManagementTest extends AbstractIntegrationTest {
// verifying the correctness of the assignments
for (final Target t : deployResWithDsA.getDeployedTargets()) {
assertThat(t.getAssignedDistributionSet().getId()).isEqualTo(dsA.getId());
assertThat(targetManagement.findTargetByControllerID(t.getControllerId()).getTargetInfo()
.getInstalledDistributionSet()).isNull();
assertThat(
targetManagement.findTargetByControllerID(t.getControllerId()).getTargetInfo()
.getInstalledDistributionSet()).isNull();
}
for (final Target t : deployResWithDsB.getDeployedTargets()) {
assertThat(t.getAssignedDistributionSet().getId()).isEqualTo(dsB.getId());
assertThat(targetManagement.findTargetByControllerID(t.getControllerId()).getTargetInfo()
.getInstalledDistributionSet()).isNull();
assertThat(
targetManagement.findTargetByControllerID(t.getControllerId()).getTargetInfo()
.getInstalledDistributionSet()).isNull();
}
for (final Target t : deployResWithDsC.getDeployedTargets()) {
assertThat(t.getAssignedDistributionSet().getId()).isEqualTo(dsC.getId());
assertThat(targetManagement.findTargetByControllerID(t.getControllerId()).getTargetInfo()
.getInstalledDistributionSet()).isNull();
assertThat(
targetManagement.findTargetByControllerID(t.getControllerId()).getTargetInfo()
.getInstalledDistributionSet()).isNull();
assertThat(targetManagement.findTargetByControllerID(t.getControllerId()).getTargetInfo().getUpdateStatus())
.isEqualTo(TargetUpdateStatus.PENDING);
}
@@ -444,8 +559,9 @@ public class DeploymentManagementTest extends AbstractIntegrationTest {
for (final Target t_ : updatedTsDsA) {
final Target t = targetManagement.findTargetByControllerID(t_.getControllerId());
assertThat(t.getAssignedDistributionSet()).isEqualTo(dsA);
assertThat(targetManagement.findTargetByControllerID(t.getControllerId()).getTargetInfo()
.getInstalledDistributionSet()).isEqualTo(dsA);
assertThat(
targetManagement.findTargetByControllerID(t.getControllerId()).getTargetInfo()
.getInstalledDistributionSet()).isEqualTo(dsA);
assertThat(targetManagement.findTargetByControllerID(t.getControllerId()).getTargetInfo().getUpdateStatus())
.isEqualTo(TargetUpdateStatus.IN_SYNC);
assertThat(deploymentManagement.findActiveActionsByTarget(t)).hasSize(0);
@@ -455,8 +571,8 @@ public class DeploymentManagementTest extends AbstractIntegrationTest {
// remove updActB from
// activeActions, add a corresponding cancelAction and another
// UpdateAction for dsA
final Iterable<Target> deployed2DS = deploymentManagement
.assignDistributionSet(dsA, deployResWithDsB.getDeployedTargets()).getAssignedTargets();
final Iterable<Target> deployed2DS = deploymentManagement.assignDistributionSet(dsA,
deployResWithDsB.getDeployedTargets()).getAssignedTargets();
final Action updActA2 = actionRepository.findByDistributionSet(pageRequest, dsA).getContent().get(1);
assertThat(deployed2DS).containsAll(deployResWithDsB.getDeployedTargets());
@@ -465,8 +581,9 @@ public class DeploymentManagementTest extends AbstractIntegrationTest {
for (final Target t_ : deployed2DS) {
final Target t = targetManagement.findTargetByControllerID(t_.getControllerId());
assertThat(t.getAssignedDistributionSet()).isEqualTo(dsA);
assertThat(targetManagement.findTargetByControllerID(t.getControllerId()).getTargetInfo()
.getInstalledDistributionSet()).isNull();
assertThat(
targetManagement.findTargetByControllerID(t.getControllerId()).getTargetInfo()
.getInstalledDistributionSet()).isNull();
assertThat(targetManagement.findTargetByControllerID(t.getControllerId()).getTargetInfo().getUpdateStatus())
.isEqualTo(TargetUpdateStatus.PENDING);
@@ -523,8 +640,8 @@ public class DeploymentManagementTest extends AbstractIntegrationTest {
"blabla alles gut");
}
// try to delete again
distributionSetManagement.deleteDistributionSet(deploymentResult.getDistributionSetIDs()
.toArray(new Long[deploymentResult.getDistributionSetIDs().size()]));
distributionSetManagement.deleteDistributionSet(deploymentResult.getDistributionSetIDs().toArray(
new Long[deploymentResult.getDistributionSetIDs().size()]));
// verify that the result is the same, even though distributionSet dsA
// has been installed
// successfully and no activeAction is referring to created distribution
@@ -559,8 +676,8 @@ public class DeploymentManagementTest extends AbstractIntegrationTest {
assertThat(targetManagement.countTargetsAll()).isNotZero();
assertThat(actionStatusRepository.count()).isNotZero();
targetManagement
.deleteTargets(deploymentResult.getUndeployedTargetIDs().toArray(new Long[noOfUndeployedTargets]));
targetManagement.deleteTargets(deploymentResult.getUndeployedTargetIDs().toArray(
new Long[noOfUndeployedTargets]));
targetManagement.deleteTargets(deploymentResult.getDeployedTargetIDs().toArray(new Long[noOfDeployedTargets]));
assertThat(targetManagement.countTargetsAll()).isZero();
@@ -651,8 +768,8 @@ public class DeploymentManagementTest extends AbstractIntegrationTest {
targ = targs.iterator().next();
assertEquals(1, deploymentManagement.findActiveActionsByTarget(targ).size());
assertEquals(TargetUpdateStatus.PENDING,
targetManagement.findTargetByControllerID(targ.getControllerId()).getTargetInfo().getUpdateStatus());
assertEquals(TargetUpdateStatus.PENDING, targetManagement.findTargetByControllerID(targ.getControllerId())
.getTargetInfo().getUpdateStatus());
assertEquals(dsB, targ.getAssignedDistributionSet());
assertEquals(dsA.getId(), targetManagement.findTargetByControllerIDWithDetails(targ.getControllerId())
.getTargetInfo().getInstalledDistributionSet().getId());
@@ -691,8 +808,8 @@ public class DeploymentManagementTest extends AbstractIntegrationTest {
final DistributionSet ds = TestDataUtil.generateDistributionSet("a", softwareManagement,
distributionSetManagement);
// assign ds to create an action
final DistributionSetAssignmentResult assignDistributionSet = deploymentManagement
.assignDistributionSet(ds.getId(), ActionType.SOFT, Action.NO_FORCE_TIME, target.getControllerId());
final DistributionSetAssignmentResult assignDistributionSet = deploymentManagement.assignDistributionSet(
ds.getId(), ActionType.SOFT, Action.NO_FORCE_TIME, target.getControllerId());
final Action action = assignDistributionSet.getActions().get(0);
// verify preparation
Action findAction = deploymentManagement.findAction(action.getId());
@@ -714,8 +831,8 @@ public class DeploymentManagementTest extends AbstractIntegrationTest {
final DistributionSet ds = TestDataUtil.generateDistributionSet("a", softwareManagement,
distributionSetManagement);
// assign ds to create an action
final DistributionSetAssignmentResult assignDistributionSet = deploymentManagement
.assignDistributionSet(ds.getId(), ActionType.FORCED, Action.NO_FORCE_TIME, target.getControllerId());
final DistributionSetAssignmentResult assignDistributionSet = deploymentManagement.assignDistributionSet(
ds.getId(), ActionType.FORCED, Action.NO_FORCE_TIME, target.getControllerId());
final Action action = assignDistributionSet.getActions().get(0);
// verify perparation
Action findAction = deploymentManagement.findAction(action.getId());
@@ -757,11 +874,11 @@ public class DeploymentManagementTest extends AbstractIntegrationTest {
private DeploymentResult prepareComplexRepo(final String undeployedTargetPrefix, final int noOfUndeployedTargets,
final String deployedTargetPrefix, final int noOfDeployedTargets, final int noOfDistributionSets,
final String distributionSetPrefix) {
final Iterable<Target> nakedTargets = targetManagement.createTargets(
TestDataUtil.buildTargetFixtures(noOfUndeployedTargets, undeployedTargetPrefix, "first description"));
final Iterable<Target> nakedTargets = targetManagement.createTargets(TestDataUtil.buildTargetFixtures(
noOfUndeployedTargets, undeployedTargetPrefix, "first description"));
List<Target> deployedTargets = targetManagement.createTargets(
TestDataUtil.buildTargetFixtures(noOfDeployedTargets, deployedTargetPrefix, "first description"));
List<Target> deployedTargets = targetManagement.createTargets(TestDataUtil.buildTargetFixtures(
noOfDeployedTargets, deployedTargetPrefix, "first description"));
// creating 10 DistributionSets
final List<DistributionSet> dsList = TestDataUtil.generateDistributionSets(distributionSetPrefix,
@@ -790,10 +907,10 @@ public class DeploymentManagementTest extends AbstractIntegrationTest {
found = true;
final List<Action> activeActionsByTarget = deploymentManagement.findActiveActionsByTarget(myt);
assertThat(activeActionsByTarget).isNotEmpty();
assertThat(event.getActionId()).isEqualTo(activeActionsByTarget.get(0).getId())
.as("Action id in database and event do not match");
assertThat(event.getSoftwareModules())
.containsOnly(ds.getModules().toArray(new SoftwareModule[ds.getModules().size()]));
assertThat(event.getActionId()).isEqualTo(activeActionsByTarget.get(0).getId()).as(
"Action id in database and event do not match");
assertThat(event.getSoftwareModules()).containsOnly(
ds.getModules().toArray(new SoftwareModule[ds.getModules().size()]));
}
}
assertThat(found).isTrue().as("No event found for controller " + myt.getControllerId());
@@ -819,14 +936,6 @@ public class DeploymentManagementTest extends AbstractIntegrationTest {
private final String deployedTargetPrefix;
private final String distributionSetPrefix;
/**
* @param deployedTargetPrefix
* @param undeployedTargetPrefix
* @param distributionSetPrefix
* @param savedDeployedTargets
* @param savedNakedTargets
* @param distributionSets
*/
public DeploymentResult(final Iterable<Target> deployedTs, final Iterable<Target> undeployedTs,
final Iterable<DistributionSet> dss, final String deployedTargetPrefix,
final String undeployedTargetPrefix, final String distributionSetPrefix) {
@@ -969,8 +1078,8 @@ public class DeploymentManagementTest extends AbstractIntegrationTest {
latch.await(timeout, unit);
final List<TargetAssignDistributionSetEvent> handledEvents = new LinkedList<TargetAssignDistributionSetEvent>(
events);
assertThat(handledEvents).hasSize(expectedNumberOfEvents)
.as("Did not receive the expected amount of events (" + expectedNumberOfEvents
assertThat(handledEvents).hasSize(expectedNumberOfEvents).as(
"Did not receive the expected amount of events (" + expectedNumberOfEvents
+ ") within timeout. Received events are " + handledEvents);
return handledEvents;
}
@@ -997,8 +1106,8 @@ public class DeploymentManagementTest extends AbstractIntegrationTest {
throws InterruptedException {
latch.await(timeout, unit);
final List<CancelTargetAssignmentEvent> handledEvents = new LinkedList<CancelTargetAssignmentEvent>(events);
assertThat(handledEvents).hasSize(expectedNumberOfEvents)
.as("Did not receive the expected amount of events (" + expectedNumberOfEvents
assertThat(handledEvents).hasSize(expectedNumberOfEvents).as(
"Did not receive the expected amount of events (" + expectedNumberOfEvents
+ ") within timeout. Received events are " + handledEvents);
return handledEvents;
}

View File

@@ -10,43 +10,144 @@ package org.eclipse.hawkbit.repository;
import static org.fest.assertions.api.Assertions.assertThat;
import java.util.concurrent.Callable;
import java.io.ByteArrayInputStream;
import java.util.List;
import java.util.Random;
import org.eclipse.hawkbit.AbstractIntegrationTest;
import org.eclipse.hawkbit.AbstractIntegrationTestWithMongoDB;
import org.eclipse.hawkbit.TestDataUtil;
import org.eclipse.hawkbit.WithSpringAuthorityRule;
import org.eclipse.hawkbit.report.model.TenantUsage;
import org.eclipse.hawkbit.repository.model.DistributionSet;
import org.eclipse.hawkbit.repository.model.SoftwareModule;
import org.eclipse.hawkbit.repository.model.Target;
import org.eclipse.hawkbit.repository.model.TenantConfiguration;
import org.eclipse.hawkbit.tenancy.configuration.TenantConfigurationKey;
import org.junit.Test;
import org.springframework.core.convert.ConversionFailedException;
import ru.yandex.qatools.allure.annotations.Description;
import ru.yandex.qatools.allure.annotations.Features;
import ru.yandex.qatools.allure.annotations.Stories;
/**
*
*
*
*/
public class SystemManagementTest extends AbstractIntegrationTest {
@Features("Component Tests - Repository")
@Stories("System Management")
public class SystemManagementTest extends AbstractIntegrationTestWithMongoDB {
@Test
@Description("Ensures that findTenants returns all tenants and not only restricted to the tenant which currently is logged in")
public void findTenantsReturnsAllTenantsNotOnlyWhichLoggedIn() throws Exception {
final String knownTenant1 = "knownTenant1";
final String knownTenant2 = "knownTenant2";
securityRule.runAs(WithSpringAuthorityRule.withUserAndTenant("bumlux", knownTenant1), new Callable<Void>() {
@Override
public Void call() throws Exception {
systemManagement.getTenantMetadata(knownTenant1);
return null;
}
});
assertThat(systemManagement.findTenants()).hasSize(1);
createTestTenantsForSystemStatistics(2, 0, 0, 0);
assertThat(systemManagement.findTenants()).hasSize(3);
}
@Test
@Description("Checks that the system report calculates correctly the artifact size of all tenants in the system. It ignores deleted software modules with their artifacts.")
public void systemUsageReportCollectsArtifactsOfAllTenants() throws Exception {
// Prepare tenants
createTestTenantsForSystemStatistics(2, 1234, 0, 0);
// overall data
assertThat(systemManagement.getSystemUsageStatistics().getOverallArtifacts()).isEqualTo(2);
assertThat(systemManagement.getSystemUsageStatistics().getOverallArtifactVolumeInBytes()).isEqualTo(1234 * 2);
// per tenant data
final List<TenantUsage> tenants = systemManagement.getSystemUsageStatistics().getTenants();
assertThat(tenants).hasSize(3);
assertThat(tenants).containsOnly(new TenantUsage("default"),
new TenantUsage("tenant0").setArtifacts(1).setOverallArtifactVolumeInBytes(1234),
new TenantUsage("tenant1").setArtifacts(1).setOverallArtifactVolumeInBytes(1234));
}
@Test
@Description("Checks that the system report calculates correctly the targets size of all tenants in the system")
public void systemUsageReportCollectsTargetsOfAllTenants() throws Exception {
// Prepare tenants
createTestTenantsForSystemStatistics(2, 0, 100, 0);
// overall data
assertThat(systemManagement.getSystemUsageStatistics().getOverallTargets()).isEqualTo(200);
assertThat(systemManagement.getSystemUsageStatistics().getOverallActions()).isEqualTo(0);
// per tenant data
final List<TenantUsage> tenants = systemManagement.getSystemUsageStatistics().getTenants();
assertThat(tenants).hasSize(3);
assertThat(tenants).containsOnly(new TenantUsage("default"), new TenantUsage("tenant0").setTargets(100),
new TenantUsage("tenant1").setTargets(100));
}
@Test
@Description("Checks that the system report calculates correctly the actions size of all tenants in the system")
public void systemUsageReportCollectsActionsOfAllTenants() throws Exception {
// Prepare tenants
createTestTenantsForSystemStatistics(2, 0, 100, 2);
// 2 tenants, 100 targets each, 2 deployments per target => 400
assertThat(systemManagement.getSystemUsageStatistics().getOverallActions()).isEqualTo(400);
// per tenant data
final List<TenantUsage> tenants = systemManagement.getSystemUsageStatistics().getTenants();
assertThat(tenants).hasSize(3);
assertThat(tenants).containsOnly(new TenantUsage("default"),
new TenantUsage("tenant0").setTargets(100).setActions(200),
new TenantUsage("tenant1").setTargets(100).setActions(200));
}
private byte[] createTestTenantsForSystemStatistics(final int tenants, final int artifactSize, final int targets, final int updates)
throws Exception {
final Random randomgen = new Random();
final byte random[] = new byte[artifactSize];
randomgen.nextBytes(random);
for (int i = 0; i < tenants; i++) {
final String tenantname = "tenant" + i;
securityRule.runAs(WithSpringAuthorityRule.withUserAndTenant("bumlux", tenantname), () -> {
systemManagement.getTenantMetadata(tenantname);
if (artifactSize > 0) {
createTestArtifact(random);
createDeletedTestArtifact(random);
}
if (targets > 0) {
final List<Target> createdTargets = createTestTargets(targets);
if (updates > 0) {
for (int x = 0; x < updates; x++) {
final DistributionSet ds = TestDataUtil.generateDistributionSet("to be deployed" + x,
softwareManagement, distributionSetManagement, true);
deploymentManagement.assignDistributionSet(ds, createdTargets);
}
}
}
securityRule.runAs(WithSpringAuthorityRule.withUserAndTenant("bumlux", knownTenant2), new Callable<Void>() {
@Override
public Void call() throws Exception {
systemManagement.getTenantMetadata(knownTenant2);
return null;
}
});
}
return random;
}
private List<Target> createTestTargets(final int targets) {
return targetManagement
.createTargets(TestDataUtil.buildTargetFixtures(targets, "testTargetOfTenant", "testTargetOfTenant"));
}
private void createTestArtifact(final byte[] random) {
SoftwareModule sm = new SoftwareModule(softwareManagement.findSoftwareModuleTypeByKey("os"), "name 1",
"version 1", null, null);
sm = softwareModuleRepository.save(sm);
artifactManagement.createLocalArtifact(new ByteArrayInputStream(random), sm.getId(), "file1", false);
}
private void createDeletedTestArtifact(final byte[] random) {
final DistributionSet ds = TestDataUtil.generateDistributionSet("deleted garbage", softwareManagement,
distributionSetManagement, true);
ds.getModules().stream().forEach(module -> {
artifactManagement.createLocalArtifact(new ByteArrayInputStream(random), module.getId(), "file1", false);
softwareManagement.deleteSoftwareModule(module);
});
}

View File

@@ -25,12 +25,12 @@ import org.eclipse.hawkbit.repository.model.TargetTag;
import org.junit.Test;
import org.slf4j.LoggerFactory;
import com.google.common.collect.Lists;
import ru.yandex.qatools.allure.annotations.Description;
import ru.yandex.qatools.allure.annotations.Features;
import ru.yandex.qatools.allure.annotations.Stories;
import com.google.common.collect.Lists;
/**
* Test class for {@link TagManagement}.
*
@@ -90,34 +90,32 @@ public class TagManagementTest extends AbstractIntegrationTest {
DistributionSetFilterBuilder distributionSetFilterBuilder;
// search for not deleted
distributionSetFilterBuilder = getDistributionSetFilterBuilder().setIsComplete(true)
.setTagNames(Lists.newArrayList(tagA.getName()));
assertEquals(
dsAs.spliterator().getExactSizeIfKnown() + dsABs.spliterator().getExactSizeIfKnown()
+ dsACs.spliterator().getExactSizeIfKnown() + dsABCs.spliterator().getExactSizeIfKnown(),
distributionSetFilterBuilder = getDistributionSetFilterBuilder().setIsComplete(true).setTagNames(
Lists.newArrayList(tagA.getName()));
assertEquals(dsAs.spliterator().getExactSizeIfKnown() + dsABs.spliterator().getExactSizeIfKnown()
+ dsACs.spliterator().getExactSizeIfKnown() + dsABCs.spliterator().getExactSizeIfKnown(),
distributionSetManagement.findDistributionSetsByFilters(pageReq, distributionSetFilterBuilder.build())
.getTotalElements());
distributionSetFilterBuilder = getDistributionSetFilterBuilder().setIsComplete(true)
.setTagNames(Lists.newArrayList(tagB.getName()));
assertEquals(
dsBs.spliterator().getExactSizeIfKnown() + dsABs.spliterator().getExactSizeIfKnown()
+ dsBCs.spliterator().getExactSizeIfKnown() + dsABCs.spliterator().getExactSizeIfKnown(),
distributionSetFilterBuilder = getDistributionSetFilterBuilder().setIsComplete(true).setTagNames(
Lists.newArrayList(tagB.getName()));
assertEquals(dsBs.spliterator().getExactSizeIfKnown() + dsABs.spliterator().getExactSizeIfKnown()
+ dsBCs.spliterator().getExactSizeIfKnown() + dsABCs.spliterator().getExactSizeIfKnown(),
distributionSetManagement.findDistributionSetsByFilters(pageReq, distributionSetFilterBuilder.build())
.getTotalElements());
distributionSetFilterBuilder = getDistributionSetFilterBuilder().setIsComplete(true)
.setTagNames(Lists.newArrayList(tagC.getName()));
assertEquals(
dsCs.spliterator().getExactSizeIfKnown() + dsACs.spliterator().getExactSizeIfKnown()
+ dsBCs.spliterator().getExactSizeIfKnown() + dsABCs.spliterator().getExactSizeIfKnown(),
distributionSetFilterBuilder = getDistributionSetFilterBuilder().setIsComplete(true).setTagNames(
Lists.newArrayList(tagC.getName()));
assertEquals(dsCs.spliterator().getExactSizeIfKnown() + dsACs.spliterator().getExactSizeIfKnown()
+ dsBCs.spliterator().getExactSizeIfKnown() + dsABCs.spliterator().getExactSizeIfKnown(),
distributionSetManagement.findDistributionSetsByFilters(pageReq, distributionSetFilterBuilder.build())
.getTotalElements());
distributionSetFilterBuilder = getDistributionSetFilterBuilder().setIsComplete(true)
.setTagNames(Lists.newArrayList(tagX.getName()));
assertEquals(0, distributionSetManagement
.findDistributionSetsByFilters(pageReq, distributionSetFilterBuilder.build()).getTotalElements());
distributionSetFilterBuilder = getDistributionSetFilterBuilder().setIsComplete(true).setTagNames(
Lists.newArrayList(tagX.getName()));
assertEquals(0,
distributionSetManagement.findDistributionSetsByFilters(pageReq, distributionSetFilterBuilder.build())
.getTotalElements());
assertEquals(5, distributionSetTagRepository.findAll().spliterator().getExactSizeIfKnown());
@@ -129,24 +127,23 @@ public class TagManagementTest extends AbstractIntegrationTest {
tagManagement.deleteDistributionSetTag(tagB.getName());
assertEquals(2, distributionSetTagRepository.findAll().spliterator().getExactSizeIfKnown());
distributionSetFilterBuilder = getDistributionSetFilterBuilder().setIsComplete(Boolean.TRUE)
.setTagNames(Lists.newArrayList(tagA.getName()));
assertEquals(
dsAs.spliterator().getExactSizeIfKnown() + dsABs.spliterator().getExactSizeIfKnown()
+ dsACs.spliterator().getExactSizeIfKnown() + dsABCs.spliterator().getExactSizeIfKnown(),
distributionSetFilterBuilder = getDistributionSetFilterBuilder().setIsComplete(Boolean.TRUE).setTagNames(
Lists.newArrayList(tagA.getName()));
assertEquals(dsAs.spliterator().getExactSizeIfKnown() + dsABs.spliterator().getExactSizeIfKnown()
+ dsACs.spliterator().getExactSizeIfKnown() + dsABCs.spliterator().getExactSizeIfKnown(),
distributionSetManagement.findDistributionSetsByFilters(pageReq, distributionSetFilterBuilder.build())
.getTotalElements());
distributionSetFilterBuilder = getDistributionSetFilterBuilder().setIsComplete(Boolean.TRUE)
.setTagNames(Lists.newArrayList(tagB.getName()));
assertEquals(0, distributionSetManagement
.findDistributionSetsByFilters(pageReq, distributionSetFilterBuilder.build()).getTotalElements());
distributionSetFilterBuilder = getDistributionSetFilterBuilder().setIsComplete(Boolean.TRUE).setTagNames(
Lists.newArrayList(tagB.getName()));
assertEquals(0,
distributionSetManagement.findDistributionSetsByFilters(pageReq, distributionSetFilterBuilder.build())
.getTotalElements());
distributionSetFilterBuilder = getDistributionSetFilterBuilder().setIsComplete(Boolean.TRUE)
.setTagNames(Lists.newArrayList(tagC.getName()));
assertEquals(
dsCs.spliterator().getExactSizeIfKnown() + dsACs.spliterator().getExactSizeIfKnown()
+ dsBCs.spliterator().getExactSizeIfKnown() + dsABCs.spliterator().getExactSizeIfKnown(),
distributionSetFilterBuilder = getDistributionSetFilterBuilder().setIsComplete(Boolean.TRUE).setTagNames(
Lists.newArrayList(tagC.getName()));
assertEquals(dsCs.spliterator().getExactSizeIfKnown() + dsACs.spliterator().getExactSizeIfKnown()
+ dsBCs.spliterator().getExactSizeIfKnown() + dsABCs.spliterator().getExactSizeIfKnown(),
distributionSetManagement.findDistributionSetsByFilters(pageReq, distributionSetFilterBuilder.build())
.getTotalElements());
}
@@ -209,8 +206,8 @@ public class TagManagementTest extends AbstractIntegrationTest {
// check
for (final Target target : targetRepository.findAll()) {
assertThat(targetManagement.findTargetByControllerID(target.getControllerId()).getTags())
.doesNotContain(toDelete);
assertThat(targetManagement.findTargetByControllerID(target.getControllerId()).getTags()).doesNotContain(
toDelete);
}
assertThat(targetTagRepository.findOne(toDelete.getId())).isNull();
assertThat(tagManagement.findAllTargetTags()).hasSize(19);
@@ -281,8 +278,8 @@ public class TagManagementTest extends AbstractIntegrationTest {
final DistributionSetTag toDelete = tags.iterator().next();
for (final DistributionSet set : distributionSetRepository.findAll()) {
assertThat(distributionSetManagement.findDistributionSetByIdWithDetails(set.getId()).getTags())
.contains(toDelete);
assertThat(distributionSetManagement.findDistributionSetByIdWithDetails(set.getId()).getTags()).contains(
toDelete);
}
// delete
@@ -290,7 +287,7 @@ public class TagManagementTest extends AbstractIntegrationTest {
// check
assertThat(distributionSetTagRepository.findOne(toDelete.getId())).isNull();
assertThat(tagManagement.findDistributionSetTagsAll()).hasSize(19);
assertThat(tagManagement.findAllDistributionSetTags()).hasSize(19);
for (final DistributionSet set : distributionSetRepository.findAll()) {
assertThat(distributionSetManagement.findDistributionSetByIdWithDetails(set.getId()).getTags())
.doesNotContain(toDelete);
@@ -329,13 +326,13 @@ public class TagManagementTest extends AbstractIntegrationTest {
tagManagement.updateDistributionSetTag(savedAssigned);
// check data
assertThat(tagManagement.findDistributionSetTagsAll()).hasSize(tags.size());
assertThat(tagManagement.findAllDistributionSetTags()).hasSize(tags.size());
assertThat(distributionSetTagRepository.findOne(savedAssigned.getId()).getName()).isEqualTo("test123");
}
/**
* Test method for
* {@link org.eclipse.hawkbit.repository.TagManagement#findDistributionSetTagsAll()}
* {@link org.eclipse.hawkbit.repository.TagManagement#findAllDistributionSetTags()}
* .
*/
@Test
@@ -345,7 +342,7 @@ public class TagManagementTest extends AbstractIntegrationTest {
final List<DistributionSetTag> tags = createDsSetsWithTags();
// test
assertThat(tagManagement.findDistributionSetTagsAll()).hasSize(tags.size());
assertThat(tagManagement.findAllDistributionSetTags()).hasSize(tags.size());
assertThat(distributionSetTagRepository.findAll()).hasSize(20);
}
@@ -362,11 +359,11 @@ public class TagManagementTest extends AbstractIntegrationTest {
final List<DistributionSet> sets = TestDataUtil.generateDistributionSets(20, softwareManagement,
distributionSetManagement);
final Iterable<DistributionSetTag> tags = tagManagement
.createDistributionSetTags(TestDataUtil.generateDistributionSetTags(20));
final Iterable<DistributionSetTag> tags = tagManagement.createDistributionSetTags(TestDataUtil
.generateDistributionSetTags(20));
tags.forEach(tag -> distributionSetManagement.toggleTagAssignment(sets, tag));
return tagManagement.findDistributionSetTagsAll();
return tagManagement.findAllDistributionSetTags();
}
}

View File

@@ -65,6 +65,40 @@ public class TargetManagementTest extends AbstractIntegrationTest {
}
}
@Test
@Description("Ensures that targets can assigned and unassigned to a target tag. Not exists target will be ignored for the assignment.")
public void assignAndUnassignTargetsToTag() {
final List<String> assignTarget = new ArrayList<String>();
assignTarget.add(targetManagement.createTarget(new Target("targetId123")).getControllerId());
assignTarget.add(targetManagement.createTarget(new Target("targetId1234")).getControllerId());
assignTarget.add(targetManagement.createTarget(new Target("targetId1235")).getControllerId());
assignTarget.add(targetManagement.createTarget(new Target("targetId1236")).getControllerId());
assignTarget.add("NotExist");
final TargetTag targetTag = tagManagement.createTargetTag(new TargetTag("Tag1"));
final List<Target> assignedTargets = targetManagement.assignTag(assignTarget, targetTag);
assertThat(assignedTargets.size()).isEqualTo(4);
assignedTargets.forEach(target -> assertThat(target.getTags().size()).isEqualTo(1));
TargetTag findTargetTag = tagManagement.findTargetTag("Tag1");
assertThat(assignedTargets.size()).isEqualTo(findTargetTag.getAssignedToTargets().size());
assertThat(targetManagement.unAssignTag("NotExist", findTargetTag)).isNull();
final Target unAssignTarget = targetManagement.unAssignTag("targetId123", findTargetTag);
assertThat(unAssignTarget.getControllerId()).isEqualTo("targetId123");
assertThat(unAssignTarget.getTags().size()).isEqualTo(0);
findTargetTag = tagManagement.findTargetTag("Tag1");
assertThat(findTargetTag.getAssignedToTargets().size()).isEqualTo(3);
final List<Target> unAssignTargets = targetManagement.unAssignAllTargetsByTag(findTargetTag);
findTargetTag = tagManagement.findTargetTag("Tag1");
assertThat(findTargetTag.getAssignedToTargets().size()).isEqualTo(0);
assertThat(unAssignTargets.size()).isEqualTo(3);
unAssignTargets.forEach(target -> assertThat(target.getTags().size()).isEqualTo(0));
}
@Test
@Description("Ensures that targets can deleted e.g. test all cascades")
public void deleteAndCreateTargets() {

View File

@@ -19,15 +19,16 @@ hawkbit.server.security.dos.maxStatusEntriesPerAction=100
hawkbit.server.security.dos.maxAttributeEntriesPerTarget=10
spring.jpa.database=H2
flyway.enabled=true
flyway.initOnMigrate=true
flyway.sqlMigrationSuffix=${spring.jpa.database}.sql
spring.datasource.url=jdbc:h2:mem:sp-db;DB_CLOSE_ON_EXIT=FALSE
spring.datasource.driverClassName=org.h2.Driver
spring.datasource.username=sa
spring.datasource.password=sa
flyway.enabled=true
flyway.initOnMigrate=true
flyway.sqlMigrationSuffix=${spring.jpa.database}.sql
#spring.jpa.show-sql=true
# SP Controller configuration
hawkbit.controller.pollingTime=00:01:00
hawkbit.controller.pollingOverdueTime=00:01:00