Complete repo exception tests (#452)

Signed-off-by: kaizimmerm <kai.zimmermann@bosch-si.com>
This commit is contained in:
Kai Zimmermann
2017-03-23 18:24:58 +01:00
committed by GitHub
parent c4d3ff5166
commit 081c3cccbf
26 changed files with 740 additions and 300 deletions

View File

@@ -111,7 +111,7 @@ public class JpaDeploymentManagement implements DeploymentManagement {
private ActionRepository actionRepository;
@Autowired
private DistributionSetRepository distributoinSetRepository;
private DistributionSetRepository distributionSetRepository;
@Autowired
private TargetRepository targetRepository;
@@ -165,7 +165,7 @@ public class JpaDeploymentManagement implements DeploymentManagement {
@Transactional(isolation = Isolation.READ_COMMITTED)
public DistributionSetAssignmentResult assignDistributionSet(final Long dsID,
final Collection<TargetWithActionType> targets, final String actionMessage) {
final JpaDistributionSet set = distributoinSetRepository.findOne(dsID);
final JpaDistributionSet set = distributionSetRepository.findOne(dsID);
if (set == null) {
throw new EntityNotFoundException(DistributionSet.class, dsID);
}
@@ -535,11 +535,14 @@ public class JpaDeploymentManagement implements DeploymentManagement {
@Override
public Slice<Action> findActionsByTarget(final String controllerId, final Pageable pageable) {
throwExceptionIfTargetDoesNotExist(controllerId);
return actionRepository.findByTargetControllerId(pageable, controllerId);
}
@Override
public List<ActionWithStatusCount> findActionsWithStatusCountByTargetOrderByIdDesc(final String controllerId) {
throwExceptionIfTargetDoesNotExist(controllerId);
final CriteriaBuilder cb = entityManager.getCriteriaBuilder();
final CriteriaQuery<JpaActionWithStatusCount> query = cb.createQuery(JpaActionWithStatusCount.class);
final Root<JpaAction> actionRoot = query.from(JpaAction.class);
@@ -564,6 +567,7 @@ public class JpaDeploymentManagement implements DeploymentManagement {
@Override
public Page<Action> findActionsByTarget(final String rsqlParam, final String controllerId,
final Pageable pageable) {
throwExceptionIfTargetDoesNotExist(controllerId);
final Specification<JpaAction> byTargetSpec = createSpecificationFor(controllerId, rsqlParam);
final Page<JpaAction> actions = actionRepository.findAll(byTargetSpec, pageable);
@@ -614,6 +618,12 @@ public class JpaDeploymentManagement implements DeploymentManagement {
}
}
private void throwExceptionIfDistributionSetDoesNotExist(final Long dsId) {
if (!distributionSetRepository.exists(dsId)) {
throw new EntityNotFoundException(DistributionSet.class, dsId);
}
}
@Override
@Modifying
@Transactional(isolation = Isolation.READ_UNCOMMITTED)
@@ -667,6 +677,8 @@ public class JpaDeploymentManagement implements DeploymentManagement {
@Override
public Slice<Action> findActionsByDistributionSet(final Pageable pageable, final Long dsId) {
throwExceptionIfDistributionSetDoesNotExist(dsId);
return actionRepository.findByDistributionSetId(pageable, dsId);
}
@@ -679,13 +691,13 @@ public class JpaDeploymentManagement implements DeploymentManagement {
public Optional<DistributionSet> getAssignedDistributionSet(final String controllerId) {
throwExceptionIfTargetDoesNotExist(controllerId);
return distributoinSetRepository.findAssignedToTarget(controllerId);
return distributionSetRepository.findAssignedToTarget(controllerId);
}
@Override
public Optional<DistributionSet> getInstalledDistributionSet(final String controllerId) {
throwExceptionIfTargetDoesNotExist(controllerId);
return distributoinSetRepository.findInstalledAtTarget(controllerId);
return distributionSetRepository.findInstalledAtTarget(controllerId);
}
}

View File

@@ -693,9 +693,7 @@ public class JpaDistributionSetManagement implements DistributionSetManagement {
@Override
public Page<DistributionSetMetadata> findDistributionSetMetadataByDistributionSetId(final Long distributionSetId,
final Pageable pageable) {
if (!distributionSetRepository.exists(distributionSetId)) {
throw new EntityNotFoundException(DistributionSet.class, distributionSetId);
}
throwExceptionIfDistributionSetDoesNotExist(distributionSetId);
return convertMdPage(distributionSetMetadataRepository
.findAll((Specification<JpaDistributionSetMetadata>) (root, query, cb) -> cb.equal(
@@ -708,9 +706,7 @@ public class JpaDistributionSetManagement implements DistributionSetManagement {
public Page<DistributionSetMetadata> findDistributionSetMetadataByDistributionSetId(final Long distributionSetId,
final String rsqlParam, final Pageable pageable) {
if (!distributionSetRepository.exists(distributionSetId)) {
throw new EntityNotFoundException(DistributionSet.class, distributionSetId);
}
throwExceptionIfDistributionSetDoesNotExist(distributionSetId);
final Specification<JpaDistributionSetMetadata> spec = RSQLUtility.parse(rsqlParam,
DistributionSetMetadataFields.class, virtualPropertyReplacer);
@@ -730,9 +726,10 @@ public class JpaDistributionSetManagement implements DistributionSetManagement {
}
@Override
public Optional<DistributionSetMetadata> findDistributionSetMetadata(final Long distributionSet, final String key) {
return Optional.ofNullable(
distributionSetMetadataRepository.findOne(new DsMetadataCompositeKey(distributionSet, key)));
public Optional<DistributionSetMetadata> findDistributionSetMetadata(final Long setId, final String key) {
throwExceptionIfDistributionSetDoesNotExist(setId);
return Optional.ofNullable(distributionSetMetadataRepository.findOne(new DsMetadataCompositeKey(setId, key)));
}
@Override
@@ -746,6 +743,8 @@ public class JpaDistributionSetManagement implements DistributionSetManagement {
@Override
public boolean isDistributionSetInUse(final Long setId) {
throwExceptionIfDistributionSetDoesNotExist(setId);
return actionRepository.countByDistributionSetId(setId) > 0;
}
@@ -903,11 +902,15 @@ public class JpaDistributionSetManagement implements DistributionSetManagement {
@Modifying
@Transactional(isolation = Isolation.READ_UNCOMMITTED)
public void deleteDistributionSet(final Long setId) {
throwExceptionIfDistributionSetDoesNotExist(setId);
deleteDistributionSet(Lists.newArrayList(setId));
}
private void throwExceptionIfDistributionSetDoesNotExist(final Long setId) {
if (!distributionSetRepository.exists(setId)) {
throw new EntityNotFoundException(DistributionSet.class, setId);
}
deleteDistributionSet(Lists.newArrayList(setId));
}
@Override

View File

@@ -301,14 +301,14 @@ public class JpaRolloutManagement extends AbstractRolloutManagement {
int readyGroups = 0;
int totalTargets = 0;
for (final RolloutGroup group : rolloutGroups) {
if (group.getStatus() != RolloutGroupStatus.CREATING) {
if (RolloutGroupStatus.READY.equals(group.getStatus())) {
readyGroups++;
totalTargets += group.getTotalTargets();
continue;
}
final RolloutGroup filledGroup = fillRolloutGroupWithTargets(rollout, group);
if (filledGroup.getStatus() == RolloutGroupStatus.READY) {
if (RolloutGroupStatus.READY.equals(filledGroup.getStatus())) {
readyGroups++;
totalTargets += filledGroup.getTotalTargets();
}
@@ -788,6 +788,11 @@ public class JpaRolloutManagement extends AbstractRolloutManagement {
@Modifying
public void deleteRollout(final long rolloutId) {
final JpaRollout jpaRollout = rolloutRepository.findOne(rolloutId);
if (jpaRollout == null) {
throw new EntityNotFoundException(Rollout.class, rolloutId);
}
if (RolloutStatus.DELETING.equals(jpaRollout.getStatus())) {
return;
}

View File

@@ -655,6 +655,8 @@ public class JpaSoftwareManagement implements SoftwareManagement {
@Override
public Optional<SoftwareModuleMetadata> findSoftwareModuleMetadata(final Long moduleId, final String key) {
throwExceptionIfSoftwareModuleDoesNotExist(moduleId);
return Optional.ofNullable(softwareModuleMetadataRepository.findOne(new SwMetadataCompositeKey(moduleId, key)));
}

View File

@@ -9,7 +9,6 @@
package org.eclipse.hawkbit.repository.jpa;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
@@ -327,21 +326,25 @@ public class JpaTargetManagement implements TargetManagement {
@Override
@Modifying
@Transactional(isolation = Isolation.READ_UNCOMMITTED)
public TargetTagAssignmentResult toggleTagAssignment(final Collection<String> targetIds, final String tagName) {
public TargetTagAssignmentResult toggleTagAssignment(final Collection<String> controllerIds, final String tagName) {
final TargetTag tag = targetTagRepository.findByNameEquals(tagName)
.orElseThrow(() -> new EntityNotFoundException(TargetTag.class, tagName));
final List<JpaTarget> alreadyAssignedTargets = targetRepository.findByTagNameAndControllerIdIn(tagName,
targetIds);
final List<JpaTarget> allTargets = targetRepository
.findAll(TargetSpecifications.byControllerIdWithStatusAndTagsInJoin(targetIds));
.findAll(TargetSpecifications.byControllerIdWithStatusAndTagsInJoin(controllerIds));
if (allTargets.size() < controllerIds.size()) {
throw new EntityNotFoundException(Target.class, controllerIds,
allTargets.stream().map(Target::getControllerId).collect(Collectors.toList()));
}
final List<JpaTarget> alreadyAssignedTargets = targetRepository.findByTagNameAndControllerIdIn(tagName,
controllerIds);
// all are already assigned -> unassign
if (alreadyAssignedTargets.size() == allTargets.size()) {
alreadyAssignedTargets.forEach(target -> target.removeTag(tag));
final TargetTagAssignmentResult result = new TargetTagAssignmentResult(0, 0, alreadyAssignedTargets.size(),
Collections.emptyList(), Collections.unmodifiableList(alreadyAssignedTargets), tag);
return result;
return new TargetTagAssignmentResult(0, 0, alreadyAssignedTargets.size(), Collections.emptyList(),
Collections.unmodifiableList(alreadyAssignedTargets), tag);
}
allTargets.removeAll(alreadyAssignedTargets);
@@ -365,6 +368,11 @@ public class JpaTargetManagement implements TargetManagement {
final List<JpaTarget> allTargets = targetRepository
.findAll(TargetSpecifications.byControllerIdWithStatusAndTagsInJoin(controllerIds));
if (allTargets.size() < controllerIds.size()) {
throw new EntityNotFoundException(Target.class, controllerIds,
allTargets.stream().map(Target::getControllerId).collect(Collectors.toList()));
}
final JpaTargetTag tag = targetTagRepository.findById(tagId)
.orElseThrow(() -> new EntityNotFoundException(TargetTag.class, tagId));
@@ -402,13 +410,13 @@ public class JpaTargetManagement implements TargetManagement {
@Modifying
@Transactional(isolation = Isolation.READ_UNCOMMITTED)
public Target unAssignTag(final String controllerID, final Long targetTagId) {
final List<Target> allTargets = Collections.unmodifiableList(targetRepository
.findAll(TargetSpecifications.byControllerIdWithStatusAndTagsInJoin(Arrays.asList(controllerID))));
final Target target = targetRepository.findByControllerId(controllerID)
.orElseThrow(() -> new EntityNotFoundException(Target.class, controllerID));
final TargetTag tag = targetTagRepository.findById(targetTagId)
.orElseThrow(() -> new EntityNotFoundException(TargetTag.class, targetTagId));
final List<Target> unAssignTag = unAssignTag(allTargets, tag);
final List<Target> unAssignTag = unAssignTag(Lists.newArrayList(target), tag);
return unAssignTag.isEmpty() ? null : unAssignTag.get(0);
}

View File

@@ -15,7 +15,10 @@ import java.util.stream.Collectors;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import org.assertj.core.api.Assertions;
import org.assertj.core.api.ThrowableAssert.ThrowingCallable;
import org.eclipse.hawkbit.cache.TenantAwareCacheManager;
import org.eclipse.hawkbit.repository.exception.EntityNotFoundException;
import org.eclipse.hawkbit.repository.model.Action;
import org.eclipse.hawkbit.repository.model.DistributionSet;
import org.eclipse.hawkbit.repository.model.DistributionSetTag;
@@ -37,6 +40,9 @@ import com.google.common.collect.Lists;
org.eclipse.hawkbit.repository.jpa.RepositoryApplicationConfiguration.class })
public abstract class AbstractJpaIntegrationTest extends AbstractIntegrationTest {
protected static final String NOT_EXIST_ID = "1234";
protected static final long NOT_EXIST_IDL = Long.parseLong(NOT_EXIST_ID);
@PersistenceContext
protected EntityManager entityManager;
@@ -96,6 +102,11 @@ public abstract class AbstractJpaIntegrationTest extends AbstractIntegrationTest
return Lists.newArrayList(actionRepository.findByRolloutIdAndStatus(pageReq, rollout.getId(), actionStatus));
}
protected static void verifyThrownExceptionBy(final ThrowingCallable tc, final String objectType) {
Assertions.assertThatExceptionOfType(EntityNotFoundException.class).isThrownBy(tc)
.withMessageContaining(NOT_EXIST_ID).withMessageContaining(objectType);
}
protected TargetTagAssignmentResult toggleTagAssignment(final Collection<Target> targets, final TargetTag tag) {
return targetManagement.toggleTagAssignment(
targets.stream().map(target -> target.getControllerId()).collect(Collectors.toList()), tag.getName());

View File

@@ -9,7 +9,6 @@
package org.eclipse.hawkbit.repository.jpa;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
@@ -23,8 +22,8 @@ import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.RandomStringUtils;
import org.eclipse.hawkbit.im.authentication.SpPermission;
import org.eclipse.hawkbit.repository.ArtifactManagement;
import org.eclipse.hawkbit.repository.event.remote.SoftwareModuleDeletedEvent;
import org.eclipse.hawkbit.repository.event.remote.entity.SoftwareModuleCreatedEvent;
import org.eclipse.hawkbit.repository.exception.EntityNotFoundException;
import org.eclipse.hawkbit.repository.exception.InsufficientPermissionException;
import org.eclipse.hawkbit.repository.jpa.model.JpaArtifact;
import org.eclipse.hawkbit.repository.jpa.model.JpaSoftwareModule;
@@ -48,38 +47,41 @@ import ru.yandex.qatools.allure.annotations.Stories;
public class ArtifactManagementTest extends AbstractJpaIntegrationTest {
@Test
@Description("Verifies that management queries react as specfied on calls for non existing entities.")
@Description("Verifies that management get access react as specfied on calls for non existing entities by means "
+ "of Optional not present.")
@ExpectEvents({ @Expect(type = SoftwareModuleCreatedEvent.class, count = 1) })
public void nonExistingEntityQueries() throws URISyntaxException {
public void nonExistingEntityAccessReturnsNotPresent() {
final SoftwareModule module = testdataFactory.createSoftwareModuleOs();
assertThatThrownBy(() -> artifactManagement.createArtifact(IOUtils.toInputStream("test", "UTF-8"), 1234L, "xxx",
null, null, false, null)).isInstanceOf(EntityNotFoundException.class).hasMessageContaining("1234")
.hasMessageContaining("SoftwareModule");
assertThat(artifactManagement.findArtifact(NOT_EXIST_IDL)).isNotPresent();
assertThat(artifactManagement.findByFilenameAndSoftwareModule(NOT_EXIST_ID, module.getId()).isPresent())
.isFalse();
assertThatThrownBy(
() -> artifactManagement.createArtifact(IOUtils.toInputStream("test", "UTF-8"), 1234L, "xxx", false))
.isInstanceOf(EntityNotFoundException.class).hasMessageContaining("1234")
.hasMessageContaining("SoftwareModule");
assertThat(artifactManagement.findFirstArtifactBySHA1(NOT_EXIST_ID)).isNotPresent();
assertThat(artifactManagement.loadArtifactBinary(NOT_EXIST_ID)).isNotPresent();
}
assertThatThrownBy(() -> artifactManagement.deleteArtifact(1234L)).isInstanceOf(EntityNotFoundException.class)
.hasMessageContaining("1234").hasMessageContaining("Artifact");
@Test
@Description("Verifies that management queries react as specfied on calls for non existing entities "
+ " by means of throwing EntityNotFoundException.")
@ExpectEvents({ @Expect(type = SoftwareModuleDeletedEvent.class, count = 0) })
public void entityQueriesReferringToNotExistingEntitiesThrowsException() throws URISyntaxException {
assertThat(artifactManagement.findArtifact(1234L)).isNotPresent();
assertThatThrownBy(() -> artifactManagement.findArtifactBySoftwareModule(pageReq, 1234L))
.isInstanceOf(EntityNotFoundException.class).hasMessageContaining("1234")
.hasMessageContaining("SoftwareModule");
assertThat(artifactManagement.findArtifactByFilename("1234")).isNotPresent();
verifyThrownExceptionBy(() -> artifactManagement.createArtifact(IOUtils.toInputStream("test", "UTF-8"),
NOT_EXIST_IDL, "xxx", null, null, false, null), "SoftwareModule");
assertThatThrownBy(() -> artifactManagement.findByFilenameAndSoftwareModule("xxx", 1234L))
.isInstanceOf(EntityNotFoundException.class).hasMessageContaining("1234")
.hasMessageContaining("SoftwareModule");
verifyThrownExceptionBy(
() -> artifactManagement.createArtifact(IOUtils.toInputStream("test", "UTF-8"), 1234L, "xxx", false),
"SoftwareModule");
assertThat(artifactManagement.findByFilenameAndSoftwareModule("1234", module.getId())).isNotPresent();
verifyThrownExceptionBy(() -> artifactManagement.deleteArtifact(NOT_EXIST_IDL), "Artifact");
assertThat(artifactManagement.findFirstArtifactBySHA1("1234")).isNotPresent();
assertThat(artifactManagement.loadArtifactBinary("1234")).isNotPresent();
verifyThrownExceptionBy(() -> artifactManagement.findArtifactBySoftwareModule(pageReq, NOT_EXIST_IDL),
"SoftwareModule");
assertThat(artifactManagement.findArtifactByFilename(NOT_EXIST_ID).isPresent()).isFalse();
verifyThrownExceptionBy(() -> artifactManagement.findByFilenameAndSoftwareModule("xxx", NOT_EXIST_IDL),
"SoftwareModule");
}
@Test

View File

@@ -9,7 +9,6 @@
package org.eclipse.hawkbit.repository.jpa;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.eclipse.hawkbit.im.authentication.SpPermission.SpringEvalExpressions.CONTROLLER_ROLE_ANONYMOUS;
import static org.junit.Assert.fail;
@@ -33,7 +32,6 @@ import org.eclipse.hawkbit.repository.event.remote.entity.SoftwareModuleUpdatedE
import org.eclipse.hawkbit.repository.event.remote.entity.TargetCreatedEvent;
import org.eclipse.hawkbit.repository.event.remote.entity.TargetUpdatedEvent;
import org.eclipse.hawkbit.repository.exception.CancelActionNotAllowedException;
import org.eclipse.hawkbit.repository.exception.EntityNotFoundException;
import org.eclipse.hawkbit.repository.model.Action;
import org.eclipse.hawkbit.repository.model.ActionStatus;
import org.eclipse.hawkbit.repository.model.Artifact;
@@ -58,77 +56,67 @@ import ru.yandex.qatools.allure.annotations.Stories;
@Features("Component Tests - Repository")
@Stories("Controller Management")
public class ControllerManagementTest extends AbstractJpaIntegrationTest {
@Autowired
private RepositoryProperties repositoryProperties;
@Test
@Description("Verifies that management queries react as specfied on calls for non existing entities.")
@Description("Verifies that management get access react as specfied on calls for non existing entities by means "
+ "of Optional not present.")
@ExpectEvents({ @Expect(type = TargetCreatedEvent.class, count = 1),
@Expect(type = SoftwareModuleCreatedEvent.class, count = 1) })
public void nonExistingEntityQueries() throws URISyntaxException {
public void nonExistingEntityAccessReturnsNotPresent() {
final Target target = testdataFactory.createTarget();
final SoftwareModule module = testdataFactory.createSoftwareModuleOs();
assertThatThrownBy(() -> controllerManagement
.addCancelActionStatus(entityFactory.actionStatus().create(1234L).status(Action.Status.FINISHED)))
.isInstanceOf(EntityNotFoundException.class).hasMessageContaining("1234")
.hasMessageContaining("Action");
assertThatThrownBy(() -> controllerManagement
.addInformationalActionStatus(entityFactory.actionStatus().create(1234L).status(Action.Status.RUNNING)))
.isInstanceOf(EntityNotFoundException.class).hasMessageContaining("1234")
.hasMessageContaining("Action");
assertThatThrownBy(() -> controllerManagement
.addUpdateActionStatus(entityFactory.actionStatus().create(1234L).status(Action.Status.FINISHED)))
.isInstanceOf(EntityNotFoundException.class).hasMessageContaining("1234")
.hasMessageContaining("Action");
assertThat(controllerManagement.findActionWithDetails(1234L)).isNotPresent();
assertThat(controllerManagement.findByControllerId("1234")).isNotPresent();
assertThat(controllerManagement.findByTargetId(1234L)).isNotPresent();
assertThatThrownBy(() -> controllerManagement.findOldestActiveActionByTarget("1234"))
.isInstanceOf(EntityNotFoundException.class).hasMessageContaining("1234")
.hasMessageContaining("Target");
assertThatThrownBy(() -> controllerManagement
.getActionForDownloadByTargetAndSoftwareModule(target.getControllerId(), 1234L))
.isInstanceOf(EntityNotFoundException.class).hasMessageContaining("1234")
.hasMessageContaining("SoftwareModule");
assertThatThrownBy(
() -> controllerManagement.getActionForDownloadByTargetAndSoftwareModule("1234", module.getId()))
.isInstanceOf(EntityNotFoundException.class).hasMessageContaining("1234")
.hasMessageContaining("Target");
assertThat(controllerManagement
.getActionForDownloadByTargetAndSoftwareModule(target.getControllerId(), module.getId()).isPresent())
.isFalse();
assertThatThrownBy(() -> controllerManagement.hasTargetArtifactAssigned(1234L, "XXX"))
.isInstanceOf(EntityNotFoundException.class).hasMessageContaining("1234")
.hasMessageContaining("Target");
assertThatThrownBy(() -> controllerManagement.hasTargetArtifactAssigned("1234", "XXX"))
.isInstanceOf(EntityNotFoundException.class).hasMessageContaining("1234")
.hasMessageContaining("Target");
assertThat(controllerManagement.findActionWithDetails(NOT_EXIST_IDL)).isNotPresent();
assertThat(controllerManagement.findByControllerId(NOT_EXIST_ID)).isNotPresent();
assertThat(controllerManagement.findByTargetId(NOT_EXIST_IDL)).isNotPresent();
assertThat(controllerManagement.getActionForDownloadByTargetAndSoftwareModule(target.getControllerId(),
module.getId())).isNotPresent();
assertThat(controllerManagement.hasTargetArtifactAssigned(target.getControllerId(), "XXX")).isFalse();
assertThat(controllerManagement.hasTargetArtifactAssigned(target.getId(), "XXX")).isFalse();
}
assertThatThrownBy(() -> controllerManagement.registerRetrieved(1234L, "test message"))
.isInstanceOf(EntityNotFoundException.class).hasMessageContaining("1234")
.hasMessageContaining("Action");
@Test
@Description("Verifies that management queries react as specfied on calls for non existing entities "
+ " by means of throwing EntityNotFoundException.")
@ExpectEvents({ @Expect(type = TargetCreatedEvent.class, count = 1),
@Expect(type = SoftwareModuleCreatedEvent.class, count = 1) })
public void entityQueriesReferringToNotExistingEntitiesThrowsException() throws URISyntaxException {
final Target target = testdataFactory.createTarget();
final SoftwareModule module = testdataFactory.createSoftwareModuleOs();
assertThatThrownBy(() -> controllerManagement.updateControllerAttributes("1234", Maps.newHashMap()))
.isInstanceOf(EntityNotFoundException.class).hasMessageContaining("1234")
.hasMessageContaining("Target");
verifyThrownExceptionBy(() -> controllerManagement.addCancelActionStatus(
entityFactory.actionStatus().create(NOT_EXIST_IDL).status(Action.Status.FINISHED)), "Action");
assertThatThrownBy(() -> controllerManagement.updateLastTargetQuery("1234", new URI("http://test.com")))
.isInstanceOf(EntityNotFoundException.class).hasMessageContaining("1234")
.hasMessageContaining("Target");
verifyThrownExceptionBy(() -> controllerManagement.addInformationalActionStatus(
entityFactory.actionStatus().create(NOT_EXIST_IDL).status(Action.Status.RUNNING)), "Action");
verifyThrownExceptionBy(() -> controllerManagement.addUpdateActionStatus(
entityFactory.actionStatus().create(NOT_EXIST_IDL).status(Action.Status.FINISHED)), "Action");
verifyThrownExceptionBy(() -> controllerManagement.findOldestActiveActionByTarget(NOT_EXIST_ID), "Target");
verifyThrownExceptionBy(() -> controllerManagement
.getActionForDownloadByTargetAndSoftwareModule(target.getControllerId(), NOT_EXIST_IDL),
"SoftwareModule");
verifyThrownExceptionBy(
() -> controllerManagement.getActionForDownloadByTargetAndSoftwareModule(NOT_EXIST_ID, module.getId()),
"Target");
verifyThrownExceptionBy(() -> controllerManagement.hasTargetArtifactAssigned(NOT_EXIST_IDL, "XXX"), "Target");
verifyThrownExceptionBy(() -> controllerManagement.hasTargetArtifactAssigned(NOT_EXIST_ID, "XXX"), "Target");
verifyThrownExceptionBy(() -> controllerManagement.registerRetrieved(NOT_EXIST_IDL, "test message"), "Action");
verifyThrownExceptionBy(() -> controllerManagement.updateControllerAttributes(NOT_EXIST_ID, Maps.newHashMap()),
"Target");
verifyThrownExceptionBy(
() -> controllerManagement.updateLastTargetQuery(NOT_EXIST_ID, new URI("http://test.com")), "Target");
}
@Test

View File

@@ -24,6 +24,7 @@ import java.util.stream.Collectors;
import org.eclipse.hawkbit.repository.ActionStatusFields;
import org.eclipse.hawkbit.repository.event.remote.TargetAssignDistributionSetEvent;
import org.eclipse.hawkbit.repository.event.remote.entity.CancelTargetAssignmentEvent;
import org.eclipse.hawkbit.repository.event.remote.entity.TargetCreatedEvent;
import org.eclipse.hawkbit.repository.exception.EntityNotFoundException;
import org.eclipse.hawkbit.repository.exception.ForceQuitActionNotAllowedException;
import org.eclipse.hawkbit.repository.exception.IncompleteDistributionSetException;
@@ -42,6 +43,9 @@ import org.eclipse.hawkbit.repository.model.DistributionSetTag;
import org.eclipse.hawkbit.repository.model.SoftwareModule;
import org.eclipse.hawkbit.repository.model.Target;
import org.eclipse.hawkbit.repository.model.TargetUpdateStatus;
import org.eclipse.hawkbit.repository.model.TargetWithActionType;
import org.eclipse.hawkbit.repository.test.matcher.Expect;
import org.eclipse.hawkbit.repository.test.matcher.ExpectEvents;
import org.junit.Before;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
@@ -67,7 +71,6 @@ import ru.yandex.qatools.allure.annotations.Stories;
@Features("Component Tests - Repository")
@Stories("Deployment Management")
public class DeploymentManagementTest extends AbstractJpaIntegrationTest {
private EventHandlerStub eventHandlerStub;
private CancelEventHandlerStub cancelEventHandlerStub;
@@ -84,6 +87,49 @@ public class DeploymentManagementTest extends AbstractJpaIntegrationTest {
applicationContext.addApplicationListener(cancelEventHandlerStub);
}
@Test
@Description("Verifies that management get access react as specfied on calls for non existing entities by means "
+ "of Optional not present.")
@ExpectEvents({ @Expect(type = TargetCreatedEvent.class, count = 0) })
public void nonExistingEntityAccessReturnsNotPresent() {
assertThat(deploymentManagement.findAction(1234L)).isNotPresent();
assertThat(deploymentManagement.findActionWithDetails(NOT_EXIST_IDL)).isNotPresent();
}
@Test
@Description("Verifies that management queries react as specfied on calls for non existing entities "
+ " by means of throwing EntityNotFoundException.")
@ExpectEvents({ @Expect(type = TargetCreatedEvent.class, count = 1) })
public void entityQueriesReferringToNotExistingEntitiesThrowsException() {
final Target target = testdataFactory.createTarget();
verifyThrownExceptionBy(() -> deploymentManagement.assignDistributionSet(NOT_EXIST_IDL,
Lists.newArrayList(new TargetWithActionType(target.getControllerId()))), "DistributionSet");
verifyThrownExceptionBy(
() -> deploymentManagement.assignDistributionSet(NOT_EXIST_IDL,
Lists.newArrayList(new TargetWithActionType(target.getControllerId())), "xxx"),
"DistributionSet");
verifyThrownExceptionBy(() -> deploymentManagement.assignDistributionSet(NOT_EXIST_IDL, ActionType.FORCED,
System.currentTimeMillis(), Lists.newArrayList(target.getControllerId())), "DistributionSet");
verifyThrownExceptionBy(() -> deploymentManagement.cancelAction(NOT_EXIST_IDL), "Action");
verifyThrownExceptionBy(() -> deploymentManagement.countActionsByTarget(NOT_EXIST_ID), "Target");
verifyThrownExceptionBy(() -> deploymentManagement.countActionsByTarget("xxx", NOT_EXIST_ID), "Target");
verifyThrownExceptionBy(() -> deploymentManagement.findActionsByDistributionSet(pageReq, NOT_EXIST_IDL),
"DistributionSet");
verifyThrownExceptionBy(() -> deploymentManagement.findActionsByTarget(NOT_EXIST_ID, pageReq), "Target");
verifyThrownExceptionBy(() -> deploymentManagement.findActionsByTarget("id==*", NOT_EXIST_ID, pageReq),
"Target");
verifyThrownExceptionBy(
() -> deploymentManagement.findActionsWithStatusCountByTargetOrderByIdDesc(NOT_EXIST_ID), "Target");
verifyThrownExceptionBy(() -> deploymentManagement.findActiveActionsByTarget(NOT_EXIST_ID), "Target");
verifyThrownExceptionBy(() -> deploymentManagement.findInActiveActionsByTarget(NOT_EXIST_ID), "Target");
verifyThrownExceptionBy(() -> deploymentManagement.forceQuitAction(NOT_EXIST_IDL), "Action");
verifyThrownExceptionBy(() -> deploymentManagement.forceTargetAction(NOT_EXIST_IDL), "Action");
}
@Test
@Description("Test verifies that the repistory retrieves the action including all defined (lazy) details.")
public void findActionWithLazyDetails() {

View File

@@ -9,7 +9,7 @@
package org.eclipse.hawkbit.repository.jpa;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.fail;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import java.util.ArrayList;
import java.util.Collection;
@@ -22,8 +22,10 @@ import org.assertj.core.api.Condition;
import org.eclipse.hawkbit.repository.DistributionSetManagement;
import org.eclipse.hawkbit.repository.builder.DistributionSetCreate;
import org.eclipse.hawkbit.repository.event.remote.entity.DistributionSetCreatedEvent;
import org.eclipse.hawkbit.repository.event.remote.entity.DistributionSetTagCreatedEvent;
import org.eclipse.hawkbit.repository.event.remote.entity.SoftwareModuleCreatedEvent;
import org.eclipse.hawkbit.repository.exception.EntityAlreadyExistsException;
import org.eclipse.hawkbit.repository.exception.EntityNotFoundException;
import org.eclipse.hawkbit.repository.exception.EntityReadOnlyException;
import org.eclipse.hawkbit.repository.exception.UnsupportedSoftwareModuleForThisDistributionSetException;
import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSetMetadata;
@@ -58,32 +60,165 @@ import ru.yandex.qatools.allure.annotations.Stories;
@Features("Component Tests - Repository")
@Stories("DistributionSet Management")
public class DistributionSetManagementTest extends AbstractJpaIntegrationTest {
@Test
@Description("Verifies that management get access react as specfied on calls for non existing entities by means "
+ "of Optional not present.")
@ExpectEvents({ @Expect(type = DistributionSetCreatedEvent.class, count = 1),
@Expect(type = SoftwareModuleCreatedEvent.class, count = 3) })
public void nonExistingEntityAccessReturnsNotPresent() {
final DistributionSet set = testdataFactory.createDistributionSet();
assertThat(distributionSetManagement.findDistributionSetById(NOT_EXIST_IDL)).isNotPresent();
assertThat(distributionSetManagement.findDistributionSetByIdWithDetails(NOT_EXIST_IDL)).isNotPresent();
assertThat(distributionSetManagement.findDistributionSetByNameAndVersion(NOT_EXIST_ID, NOT_EXIST_ID))
.isNotPresent();
assertThat(distributionSetManagement.findDistributionSetMetadata(set.getId(), NOT_EXIST_ID)).isNotPresent();
assertThat(distributionSetManagement.findDistributionSetTypeById(NOT_EXIST_IDL)).isNotPresent();
assertThat(distributionSetManagement.findDistributionSetTypeByKey(NOT_EXIST_ID)).isNotPresent();
assertThat(distributionSetManagement.findDistributionSetTypeByName(NOT_EXIST_ID)).isNotPresent();
}
@Test
@Description("Verifies that management queries react as specfied on calls for non existing entities "
+ " by means of throwing EntityNotFoundException.")
@ExpectEvents({ @Expect(type = DistributionSetCreatedEvent.class, count = 1),
@Expect(type = DistributionSetTagCreatedEvent.class, count = 1),
@Expect(type = SoftwareModuleCreatedEvent.class, count = 4) })
public void entityQueriesReferringToNotExistingEntitiesThrowsException() {
final DistributionSet set = testdataFactory.createDistributionSet();
final DistributionSetTag dsTag = testdataFactory.createDistributionSetTags(1).get(0);
final SoftwareModule module = testdataFactory.createSoftwareModuleApp();
verifyThrownExceptionBy(() -> distributionSetManagement.assignMandatorySoftwareModuleTypes(NOT_EXIST_IDL,
Lists.newArrayList(osType.getId())), "DistributionSetType");
verifyThrownExceptionBy(() -> distributionSetManagement.assignMandatorySoftwareModuleTypes(
testdataFactory.findOrCreateDistributionSetType("xxx", "xxx").getId(),
Lists.newArrayList(NOT_EXIST_IDL)), "SoftwareModuleType");
verifyThrownExceptionBy(() -> distributionSetManagement.assignOptionalSoftwareModuleTypes(1234L,
Lists.newArrayList(osType.getId())), "DistributionSetType");
verifyThrownExceptionBy(() -> distributionSetManagement.assignOptionalSoftwareModuleTypes(
testdataFactory.findOrCreateDistributionSetType("xxx", "xxx").getId(),
Lists.newArrayList(NOT_EXIST_IDL)), "SoftwareModuleType");
verifyThrownExceptionBy(() -> distributionSetManagement.assignSoftwareModules(NOT_EXIST_IDL,
Lists.newArrayList(module.getId())), "DistributionSet");
verifyThrownExceptionBy(
() -> distributionSetManagement.assignSoftwareModules(set.getId(), Lists.newArrayList(NOT_EXIST_IDL)),
"SoftwareModule");
verifyThrownExceptionBy(() -> distributionSetManagement.unassignSoftwareModule(NOT_EXIST_IDL, module.getId()),
"DistributionSet");
verifyThrownExceptionBy(() -> distributionSetManagement.unassignSoftwareModule(set.getId(), NOT_EXIST_IDL),
"SoftwareModule");
verifyThrownExceptionBy(
() -> distributionSetManagement.assignTag(Lists.newArrayList(set.getId()), NOT_EXIST_IDL),
"DistributionSetTag");
verifyThrownExceptionBy(
() -> distributionSetManagement.assignTag(Lists.newArrayList(NOT_EXIST_IDL), dsTag.getId()),
"DistributionSet");
verifyThrownExceptionBy(
() -> distributionSetManagement.toggleTagAssignment(Lists.newArrayList(NOT_EXIST_IDL), dsTag.getName()),
"DistributionSet");
verifyThrownExceptionBy(
() -> distributionSetManagement.toggleTagAssignment(Lists.newArrayList(set.getId()), NOT_EXIST_ID),
"DistributionSetTag");
verifyThrownExceptionBy(() -> distributionSetManagement.unAssignAllDistributionSetsByTag(NOT_EXIST_IDL),
"DistributionSetTag");
verifyThrownExceptionBy(() -> distributionSetManagement.unAssignTag(set.getId(), NOT_EXIST_IDL),
"DistributionSetTag");
verifyThrownExceptionBy(() -> distributionSetManagement.unAssignTag(NOT_EXIST_IDL, dsTag.getId()),
"DistributionSet");
verifyThrownExceptionBy(() -> distributionSetManagement.countDistributionSetsByType(NOT_EXIST_IDL),
"DistributionSet");
verifyThrownExceptionBy(
() -> distributionSetManagement
.createDistributionSet(entityFactory.distributionSet().create().name("xxx").type(NOT_EXIST_ID)),
"DistributionSetType");
verifyThrownExceptionBy(() -> distributionSetManagement.createDistributionSetMetadata(NOT_EXIST_IDL,
Lists.newArrayList(entityFactory.generateMetadata("123", "123"))), "DistributionSet");
verifyThrownExceptionBy(
() -> distributionSetManagement.deleteDistributionSet(Lists.newArrayList(NOT_EXIST_IDL)),
"DistributionSet");
verifyThrownExceptionBy(() -> distributionSetManagement.deleteDistributionSet(NOT_EXIST_IDL),
"DistributionSet");
verifyThrownExceptionBy(() -> distributionSetManagement.deleteDistributionSetMetadata(NOT_EXIST_IDL, "xxx"),
"DistributionSet");
verifyThrownExceptionBy(
() -> distributionSetManagement.deleteDistributionSetMetadata(set.getId(), NOT_EXIST_ID),
"DistributionSetMetadata");
verifyThrownExceptionBy(() -> distributionSetManagement.deleteDistributionSetType(NOT_EXIST_IDL),
"DistributionSetType");
verifyThrownExceptionBy(() -> distributionSetManagement.findDistributionSetByAction(NOT_EXIST_IDL), "Action");
verifyThrownExceptionBy(() -> distributionSetManagement.findDistributionSetMetadata(NOT_EXIST_IDL, "xxx"),
"DistributionSet");
verifyThrownExceptionBy(
() -> distributionSetManagement.findDistributionSetMetadataByDistributionSetId(NOT_EXIST_IDL, pageReq),
"DistributionSet");
verifyThrownExceptionBy(() -> distributionSetManagement
.findDistributionSetMetadataByDistributionSetId(NOT_EXIST_IDL, "name==*", pageReq), "DistributionSet");
assertThatThrownBy(() -> distributionSetManagement.isDistributionSetInUse(NOT_EXIST_IDL))
.isInstanceOf(EntityNotFoundException.class).hasMessageContaining(NOT_EXIST_ID)
.hasMessageContaining("DistributionSet");
verifyThrownExceptionBy(
() -> distributionSetManagement
.updateDistributionSet(entityFactory.distributionSet().update(NOT_EXIST_IDL)),
"DistributionSet");
verifyThrownExceptionBy(() -> distributionSetManagement.updateDistributionSetMetadata(NOT_EXIST_IDL,
entityFactory.generateMetadata("xxx", "xxx")), "DistributionSet");
verifyThrownExceptionBy(() -> distributionSetManagement.updateDistributionSetMetadata(set.getId(),
entityFactory.generateMetadata(NOT_EXIST_ID, "xxx")), "DistributionSetMetadata");
verifyThrownExceptionBy(
() -> distributionSetManagement
.updateDistributionSetType(entityFactory.distributionSetType().update(NOT_EXIST_IDL)),
"DistributionSet");
}
@Test
@Description("Tests the successfull module update of unused distribution set type which is in fact allowed.")
public void updateUnassignedDistributionSetTypeModules() {
DistributionSetType updatableType = distributionSetManagement.createDistributionSetType(
final DistributionSetType updatableType = distributionSetManagement.createDistributionSetType(
entityFactory.distributionSetType().create().key("updatableType").name("to be deleted"));
assertThat(
distributionSetManagement.findDistributionSetTypeByKey("updatableType").get().getMandatoryModuleTypes())
.isEmpty();
// add OS
updatableType = distributionSetManagement.assignMandatorySoftwareModuleTypes(updatableType.getId(),
distributionSetManagement.assignMandatorySoftwareModuleTypes(updatableType.getId(),
Sets.newHashSet(osType.getId()));
assertThat(
distributionSetManagement.findDistributionSetTypeByKey("updatableType").get().getMandatoryModuleTypes())
.containsOnly(osType);
// add JVM
updatableType = distributionSetManagement.assignMandatorySoftwareModuleTypes(updatableType.getId(),
distributionSetManagement.assignMandatorySoftwareModuleTypes(updatableType.getId(),
Sets.newHashSet(runtimeType.getId()));
assertThat(
distributionSetManagement.findDistributionSetTypeByKey("updatableType").get().getMandatoryModuleTypes())
.containsOnly(osType, runtimeType);
// remove OS
updatableType = distributionSetManagement.unassignSoftwareModuleType(updatableType.getId(), osType.getId());
distributionSetManagement.unassignSoftwareModuleType(updatableType.getId(), osType.getId());
assertThat(
distributionSetManagement.findDistributionSetTypeByKey("updatableType").get().getMandatoryModuleTypes())
.containsOnly(runtimeType);
@@ -120,14 +255,8 @@ public class DistributionSetManagementTest extends AbstractJpaIntegrationTest {
distributionSetManagement.createDistributionSet(entityFactory.distributionSet().create().name("newtypesoft")
.version("1").type(nonUpdatableType.getKey()));
try {
distributionSetManagement.assignMandatorySoftwareModuleTypes(nonUpdatableType.getId(),
Sets.newHashSet(osType.getId()));
fail("Should not have worked as DS is in use.");
} catch (final EntityReadOnlyException e) {
}
assertThatThrownBy(() -> distributionSetManagement.assignMandatorySoftwareModuleTypes(nonUpdatableType.getId(),
Sets.newHashSet(osType.getId()))).isInstanceOf(EntityReadOnlyException.class);
}
@Test
@@ -144,12 +273,9 @@ public class DistributionSetManagementTest extends AbstractJpaIntegrationTest {
distributionSetManagement.createDistributionSet(entityFactory.distributionSet().create().name("newtypesoft")
.version("1").type(nonUpdatableType.getKey()));
try {
distributionSetManagement.unassignSoftwareModuleType(nonUpdatableType.getId(), osType.getId());
fail("Should not have worked as DS is in use.");
} catch (final EntityReadOnlyException e) {
}
final Long typeId = nonUpdatableType.getId();
assertThatThrownBy(() -> distributionSetManagement.unassignSoftwareModuleType(typeId, osType.getId()))
.isInstanceOf(EntityReadOnlyException.class);
}
@Test
@@ -186,12 +312,8 @@ public class DistributionSetManagementTest extends AbstractJpaIntegrationTest {
public void createDuplicateDistributionSetsFailsWithException() {
testdataFactory.createDistributionSet("a");
try {
testdataFactory.createDistributionSet("a");
fail("Should not have worked as DS with same UK already exists.");
} catch (final EntityAlreadyExistsException e) {
}
assertThatThrownBy(() -> testdataFactory.createDistributionSet("a"))
.isInstanceOf(EntityAlreadyExistsException.class);
}
@Test
@@ -261,22 +383,15 @@ public class DistributionSetManagementTest extends AbstractJpaIntegrationTest {
assignDistributionSet(ds.getId(), target.getControllerId());
ds = distributionSetManagement.findDistributionSetByIdWithDetails(ds.getId()).get();
final Long dsId = ds.getId();
// not allowed as it is assigned now
try {
ds = distributionSetManagement.assignSoftwareModules(ds.getId(), Sets.newHashSet(os2.getId()));
fail("Expected EntityReadOnlyException");
} catch (final EntityReadOnlyException e) {
}
assertThatThrownBy(() -> distributionSetManagement.assignSoftwareModules(dsId, Sets.newHashSet(os2.getId())))
.isInstanceOf(EntityReadOnlyException.class);
// not allowed as it is assigned now
try {
ds = distributionSetManagement.unassignSoftwareModule(ds.getId(),
ds.findFirstModuleByType(appType).get().getId());
fail("Expected EntityReadOnlyException");
} catch (final EntityReadOnlyException e) {
}
final Long appId = ds.findFirstModuleByType(appType).get().getId();
assertThatThrownBy(() -> distributionSetManagement.unassignSoftwareModule(dsId, appId))
.isInstanceOf(EntityReadOnlyException.class);
}
@Test
@@ -292,19 +407,15 @@ public class DistributionSetManagementTest extends AbstractJpaIntegrationTest {
entityFactory.softwareModule().create().name("agent-hub2").version("1.0.5").type(appType.getKey()));
// update data
try {
distributionSetManagement.assignSoftwareModules(set.getId(), Sets.newHashSet(module.getId()));
fail("Should not have worked as module type is not in DS type.");
} catch (final UnsupportedSoftwareModuleForThisDistributionSetException e) {
}
assertThatThrownBy(
() -> distributionSetManagement.assignSoftwareModules(set.getId(), Sets.newHashSet(module.getId())))
.isInstanceOf(UnsupportedSoftwareModuleForThisDistributionSetException.class);
}
@Test
@Description("Legal updates of a DS, e.g. name or description and module addition, removal while still unassigned.")
public void updateDistributionSet() {
// prepare data
final Target target = testdataFactory.createTarget();
DistributionSet ds = testdataFactory.createDistributionSet("");
final SoftwareModule os = testdataFactory.createSoftwareModuleOs();
@@ -722,7 +833,7 @@ public class DistributionSetManagementTest extends AbstractJpaIntegrationTest {
assignDistributionSet(dsToTargetAssigned.getId(), savedTarget.getControllerId());
// create assigned rollout
createRolloutByVariables("test", "test", 5, "name==*", dsToRolloutAssigned, "50", "5");
testdataFactory.createRolloutByVariables("test", "test", 5, "name==*", dsToRolloutAssigned, "50", "5");
// delete assigned ds
assertThat(distributionSetRepository.findAll()).hasSize(4);

View File

@@ -19,8 +19,6 @@ import java.util.concurrent.Callable;
import java.util.concurrent.TimeUnit;
import org.eclipse.hawkbit.repository.OffsetBasedPageRequest;
import org.eclipse.hawkbit.repository.RolloutGroupManagement;
import org.eclipse.hawkbit.repository.RolloutManagement;
import org.eclipse.hawkbit.repository.builder.RolloutCreate;
import org.eclipse.hawkbit.repository.builder.RolloutGroupCreate;
import org.eclipse.hawkbit.repository.event.remote.RolloutDeletedEvent;
@@ -54,15 +52,12 @@ import org.eclipse.hawkbit.repository.model.RolloutGroup.RolloutGroupStatus;
import org.eclipse.hawkbit.repository.model.RolloutGroup.RolloutGroupSuccessCondition;
import org.eclipse.hawkbit.repository.model.RolloutGroupConditionBuilder;
import org.eclipse.hawkbit.repository.model.RolloutGroupConditions;
import org.eclipse.hawkbit.repository.model.SoftwareModule;
import org.eclipse.hawkbit.repository.model.Target;
import org.eclipse.hawkbit.repository.model.TargetUpdateStatus;
import org.eclipse.hawkbit.repository.model.TotalTargetCountStatus;
import org.eclipse.hawkbit.repository.test.matcher.Expect;
import org.eclipse.hawkbit.repository.test.matcher.ExpectEvents;
import org.eclipse.hawkbit.repository.test.util.TestdataFactory;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Description;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Slice;
@@ -82,12 +77,44 @@ import ru.yandex.qatools.allure.annotations.Title;
@Features("Component Tests - Repository")
@Stories("Rollout Management")
public class RolloutManagementTest extends AbstractJpaIntegrationTest {
@Test
@Description("Verifies that management get access reacts as specfied on calls for non existing entities by means "
+ "of Optional not present.")
@ExpectEvents({ @Expect(type = TargetCreatedEvent.class, count = 0) })
public void nonExistingEntityAccessReturnsNotPresent() {
assertThat(rolloutManagement.findRolloutById(NOT_EXIST_IDL)).isNotPresent();
assertThat(rolloutManagement.findRolloutByName(NOT_EXIST_ID)).isNotPresent();
assertThat(rolloutManagement.findRolloutWithDetailedStatus(NOT_EXIST_IDL)).isNotPresent();
}
@Autowired
private RolloutManagement rolloutManagement;
@Test
@Description("Verifies that management queries react as specfied on calls for non existing entities "
+ " by means of throwing EntityNotFoundException.")
@ExpectEvents({ @Expect(type = RolloutDeletedEvent.class, count = 0),
@Expect(type = RolloutGroupCreatedEvent.class, count = 10),
@Expect(type = RolloutGroupUpdatedEvent.class, count = 20),
@Expect(type = DistributionSetCreatedEvent.class, count = 1),
@Expect(type = SoftwareModuleCreatedEvent.class, count = 3),
@Expect(type = RolloutUpdatedEvent.class, count = 1),
@Expect(type = TargetCreatedEvent.class, count = 10) })
public void entityQueriesReferringToNotExistingEntitiesThrowsException() {
final Rollout createdRollout = testdataFactory.createRollout("xxx");
@Autowired
private RolloutGroupManagement rolloutGroupManagement;
verifyThrownExceptionBy(() -> rolloutManagement.deleteRollout(NOT_EXIST_IDL), "Rollout");
verifyThrownExceptionBy(() -> rolloutManagement.getFinishedPercentForRunningGroup(NOT_EXIST_IDL, NOT_EXIST_IDL),
"Rollout");
verifyThrownExceptionBy(
() -> rolloutManagement.getFinishedPercentForRunningGroup(createdRollout.getId(), NOT_EXIST_IDL),
"RolloutGroup");
verifyThrownExceptionBy(() -> rolloutManagement.pauseRollout(NOT_EXIST_IDL), "Rollout");
verifyThrownExceptionBy(() -> rolloutManagement.resumeRollout(NOT_EXIST_IDL), "Rollout");
verifyThrownExceptionBy(() -> rolloutManagement.startRollout(NOT_EXIST_IDL), "Rollout");
verifyThrownExceptionBy(() -> rolloutManagement.updateRollout(entityFactory.rollout().update(NOT_EXIST_IDL)),
"Rollout");
}
@Test
@Description("Verifying that the rollout is created correctly, executing the filter and split up the targets in the correct group size.")
@@ -605,8 +632,8 @@ public class RolloutManagementTest extends AbstractJpaIntegrationTest {
final DistributionSet dsForRolloutTwo = testdataFactory.createDistributionSet("dsForRolloutTwo");
final Rollout rolloutTwo = createRolloutByVariables("rolloutTwo", "This is the description for rollout two", 1,
"controllerId==rollout-*", dsForRolloutTwo, "50", "80");
final Rollout rolloutTwo = testdataFactory.createRolloutByVariables("rolloutTwo",
"This is the description for rollout two", 1, "controllerId==rollout-*", dsForRolloutTwo, "50", "80");
changeStatusForAllRunningActions(rolloutOne, Status.FINISHED);
rolloutManagement.handleRollouts();
// Verify that 5 targets are finished, 5 are running and 5 are ready.
@@ -664,8 +691,9 @@ public class RolloutManagementTest extends AbstractJpaIntegrationTest {
assertThat(rolloutOne.getStatus()).isEqualTo(RolloutStatus.FINISHED);
final int amountGroupsForRolloutTwo = 1;
Rollout rolloutTwo = createRolloutByVariables("rolloutTwo", "This is the description for rollout two",
amountGroupsForRolloutTwo, "controllerId==rollout-*", distributionSet, "50", "80");
Rollout rolloutTwo = testdataFactory.createRolloutByVariables("rolloutTwo",
"This is the description for rollout two", amountGroupsForRolloutTwo, "controllerId==rollout-*",
distributionSet, "50", "80");
rolloutManagement.startRollout(rolloutTwo.getId());
@@ -1012,8 +1040,8 @@ public class RolloutManagementTest extends AbstractJpaIntegrationTest {
final DistributionSet distributionSet = testdataFactory.createDistributionSet("dsFor" + rolloutName);
try {
createRolloutByVariables(rolloutName, "desc", amountGroups, "id==notExisting", distributionSet,
successCondition, errorCondition);
testdataFactory.createRolloutByVariables(rolloutName, "desc", amountGroups, "id==notExisting",
distributionSet, successCondition, errorCondition);
fail("Was able to create a Rollout without targets.");
} catch (final ConstraintViolationException e) {
// OK
@@ -1033,11 +1061,11 @@ public class RolloutManagementTest extends AbstractJpaIntegrationTest {
testdataFactory.createTargets(amountTargetsForRollout, "dup-ro-", "rollout");
final DistributionSet distributionSet = testdataFactory.createDistributionSet("dsFor" + rolloutName);
createRolloutByVariables(rolloutName, "desc", amountGroups, "id==dup-ro-*", distributionSet, successCondition,
errorCondition);
testdataFactory.createRolloutByVariables(rolloutName, "desc", amountGroups, "id==dup-ro-*", distributionSet,
successCondition, errorCondition);
try {
createRolloutByVariables(rolloutName, "desc", amountGroups, "id==dup-ro-*", distributionSet,
testdataFactory.createRolloutByVariables(rolloutName, "desc", amountGroups, "id==dup-ro-*", distributionSet,
successCondition, errorCondition);
fail("Was able to create a duplicate Rollout.");
} catch (final EntityAlreadyExistsException e) {
@@ -1058,7 +1086,7 @@ public class RolloutManagementTest extends AbstractJpaIntegrationTest {
final DistributionSet distributionSet = testdataFactory.createDistributionSet("dsFor" + rolloutName);
testdataFactory.createTargets(amountTargetsForRollout, targetPrefixName + "-", targetPrefixName);
Rollout myRollout = createRolloutByVariables(rolloutName, "desc", amountGroups,
Rollout myRollout = testdataFactory.createRolloutByVariables(rolloutName, "desc", amountGroups,
"controllerId==" + targetPrefixName + "-*", distributionSet, successCondition, errorCondition);
assertThat(myRollout.getStatus()).isEqualTo(RolloutStatus.READY);
@@ -1107,7 +1135,7 @@ public class RolloutManagementTest extends AbstractJpaIntegrationTest {
final DistributionSet distributionSet = testdataFactory.createDistributionSet("dsFor" + rolloutName);
testdataFactory.createTargets(amountTargetsForRollout, targetPrefixName + "-", targetPrefixName);
Rollout myRollout = createRolloutByVariables(rolloutName, "desc", amountGroups,
Rollout myRollout = testdataFactory.createRolloutByVariables(rolloutName, "desc", amountGroups,
"controllerId==" + targetPrefixName + "-*", distributionSet, successCondition, errorCondition);
assertThat(myRollout.getStatus()).isEqualTo(RolloutStatus.READY);
@@ -1148,7 +1176,7 @@ public class RolloutManagementTest extends AbstractJpaIntegrationTest {
final DistributionSet distributionSet = testdataFactory.createDistributionSet("dsFor" + rolloutName);
testdataFactory.createTargets(amountTargetsForRollout, targetPrefixName + "-", targetPrefixName);
Rollout myRollout = createRolloutByVariables(rolloutName, "desc", amountGroups,
Rollout myRollout = testdataFactory.createRolloutByVariables(rolloutName, "desc", amountGroups,
"controllerId==" + targetPrefixName + "-*", distributionSet, successCondition, errorCondition);
assertThat(myRollout.getStatus()).isEqualTo(RolloutStatus.READY);
@@ -1508,17 +1536,12 @@ public class RolloutManagementTest extends AbstractJpaIntegrationTest {
private Rollout createSimpleTestRolloutWithTargetsAndDistributionSet(final int amountTargetsForRollout,
final int amountOtherTargets, final int groupSize, final String successCondition,
final String errorCondition) {
final SoftwareModule ah = testdataFactory.createSoftwareModule(TestdataFactory.SM_TYPE_APP);
final SoftwareModule jvm = testdataFactory.createSoftwareModule(TestdataFactory.SM_TYPE_RT);
final SoftwareModule os = testdataFactory.createSoftwareModule(TestdataFactory.SM_TYPE_OS);
final DistributionSet rolloutDS = testdataFactory.createDistributionSet("rolloutDS", "0.0.0", standardDsType,
Lists.newArrayList(os, jvm, ah));
final DistributionSet rolloutDS = testdataFactory.createDistributionSet("rolloutDS");
testdataFactory.createTargets(amountTargetsForRollout, "rollout-", "rollout");
testdataFactory.createTargets(amountOtherTargets, "others-", "rollout");
final String filterQuery = "controllerId==rollout-*";
return createRolloutByVariables("test-rollout-name-1", "test-rollout-description-1", groupSize, filterQuery,
rolloutDS, successCondition, errorCondition);
return testdataFactory.createRolloutByVariables("test-rollout-name-1", "test-rollout-description-1", groupSize,
filterQuery, rolloutDS, successCondition, errorCondition);
}
private Rollout createTestRolloutWithTargetsAndDistributionSet(final int amountTargetsForRollout,
@@ -1526,7 +1549,7 @@ public class RolloutManagementTest extends AbstractJpaIntegrationTest {
final String targetPrefixName) {
final DistributionSet dsForRolloutTwo = testdataFactory.createDistributionSet("dsFor" + rolloutName);
testdataFactory.createTargets(amountTargetsForRollout, targetPrefixName + "-", targetPrefixName);
return createRolloutByVariables(rolloutName, rolloutName + "description", groupSize,
return testdataFactory.createRolloutByVariables(rolloutName, rolloutName + "description", groupSize,
"controllerId==" + targetPrefixName + "-*", dsForRolloutTwo, successCondition, errorCondition);
}

View File

@@ -22,6 +22,7 @@ import javax.validation.ConstraintViolationException;
import org.apache.commons.lang3.RandomUtils;
import org.eclipse.hawkbit.repository.builder.SoftwareModuleTypeCreate;
import org.eclipse.hawkbit.repository.event.remote.entity.SoftwareModuleCreatedEvent;
import org.eclipse.hawkbit.repository.exception.EntityAlreadyExistsException;
import org.eclipse.hawkbit.repository.jpa.model.JpaArtifact;
import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSet;
@@ -38,6 +39,8 @@ import org.eclipse.hawkbit.repository.model.SoftwareModuleMetadata;
import org.eclipse.hawkbit.repository.model.SoftwareModuleType;
import org.eclipse.hawkbit.repository.model.Target;
import org.eclipse.hawkbit.repository.model.TargetUpdateStatus;
import org.eclipse.hawkbit.repository.test.matcher.Expect;
import org.eclipse.hawkbit.repository.test.matcher.ExpectEvents;
import org.eclipse.hawkbit.repository.test.util.WithUser;
import org.junit.Test;
import org.springframework.data.domain.Page;
@@ -54,6 +57,86 @@ import ru.yandex.qatools.allure.annotations.Stories;
@Stories("Software Management")
public class SoftwareManagementTest extends AbstractJpaIntegrationTest {
@Test
@Description("Verifies that management get access reacts as specfied on calls for non existing entities by means "
+ "of Optional not present.")
@ExpectEvents({ @Expect(type = SoftwareModuleCreatedEvent.class, count = 1) })
public void nonExistingEntityAccessReturnsNotPresent() {
final SoftwareModule module = testdataFactory.createSoftwareModuleApp();
assertThat(softwareManagement.findSoftwareModuleById(1234L)).isNotPresent();
assertThat(softwareManagement.findSoftwareModuleTypeById(NOT_EXIST_IDL)).isNotPresent();
assertThat(softwareManagement.findSoftwareModuleTypeByKey(NOT_EXIST_ID)).isNotPresent();
assertThat(softwareManagement.findSoftwareModuleTypeByName(NOT_EXIST_ID)).isNotPresent();
assertThat(softwareManagement.findSoftwareModuleByNameAndVersion(NOT_EXIST_ID, NOT_EXIST_ID, osType.getId()))
.isNotPresent();
assertThat(softwareManagement.findSoftwareModuleMetadata(module.getId(), NOT_EXIST_ID)).isNotPresent();
}
@Test
@Description("Verifies that management queries react as specfied on calls for non existing entities "
+ " by means of throwing EntityNotFoundException.")
@ExpectEvents({ @Expect(type = SoftwareModuleCreatedEvent.class, count = 1) })
public void entityQueriesReferringToNotExistingEntitiesThrowsException() {
final SoftwareModule module = testdataFactory.createSoftwareModuleApp();
verifyThrownExceptionBy(
() -> softwareManagement.createSoftwareModule(
Lists.newArrayList(entityFactory.softwareModule().create().name("xxx").type(NOT_EXIST_ID))),
"SoftwareModuleType");
verifyThrownExceptionBy(
() -> softwareManagement
.createSoftwareModule(entityFactory.softwareModule().create().name("xxx").type(NOT_EXIST_ID)),
"SoftwareModuleType");
verifyThrownExceptionBy(() -> softwareManagement.createSoftwareModuleMetadata(NOT_EXIST_IDL,
entityFactory.generateMetadata("xxx", "xxx")), "SoftwareModule");
verifyThrownExceptionBy(() -> softwareManagement.createSoftwareModuleMetadata(NOT_EXIST_IDL,
Lists.newArrayList(entityFactory.generateMetadata("xxx", "xxx"))), "SoftwareModule");
verifyThrownExceptionBy(() -> softwareManagement.deleteSoftwareModule(NOT_EXIST_IDL), "SoftwareModule");
verifyThrownExceptionBy(() -> softwareManagement.deleteSoftwareModules(Lists.newArrayList(NOT_EXIST_IDL)),
"SoftwareModule");
verifyThrownExceptionBy(() -> softwareManagement.deleteSoftwareModuleMetadata(NOT_EXIST_IDL, "xxx"),
"SoftwareModule");
verifyThrownExceptionBy(() -> softwareManagement.deleteSoftwareModuleMetadata(module.getId(), NOT_EXIST_ID),
"SoftwareModuleMetadata");
verifyThrownExceptionBy(() -> softwareManagement.updateSoftwareModuleMetadata(NOT_EXIST_IDL,
entityFactory.generateMetadata("xxx", "xxx")), "SoftwareModule");
verifyThrownExceptionBy(() -> softwareManagement.updateSoftwareModuleMetadata(module.getId(),
entityFactory.generateMetadata(NOT_EXIST_ID, "xxx")), "SoftwareModuleMetadata");
verifyThrownExceptionBy(() -> softwareManagement.deleteSoftwareModuleType(NOT_EXIST_IDL), "SoftwareModuleType");
verifyThrownExceptionBy(() -> softwareManagement.findSoftwareModuleByAssignedTo(pageReq, NOT_EXIST_IDL),
"DistributionSet");
verifyThrownExceptionBy(
() -> softwareManagement.findSoftwareModuleByNameAndVersion("xxx", "xxx", NOT_EXIST_IDL),
"SoftwareModuleType");
verifyThrownExceptionBy(() -> softwareManagement.findSoftwareModuleMetadata(NOT_EXIST_IDL, NOT_EXIST_ID),
"SoftwareModule");
verifyThrownExceptionBy(() -> softwareManagement.findSoftwareModuleMetadataBySoftwareModuleId(NOT_EXIST_IDL),
"SoftwareModule");
verifyThrownExceptionBy(() -> softwareManagement.findSoftwareModuleMetadataBySoftwareModuleId(NOT_EXIST_IDL,
"name==*", pageReq), "SoftwareModule");
verifyThrownExceptionBy(() -> softwareManagement.findSoftwareModulesByType(pageReq, NOT_EXIST_IDL),
"SoftwareModule");
verifyThrownExceptionBy(
() -> softwareManagement.updateSoftwareModule(entityFactory.softwareModule().update(NOT_EXIST_IDL)),
"SoftwareModule");
verifyThrownExceptionBy(
() -> softwareManagement.updateSoftwareModuleType(entityFactory.softwareModuleType().update(1234L)),
"SoftwareModuleType");
}
@Test
@Description("Calling update without changing fields results in no recorded change in the repository including unchanged audit fields.")
public void updateNothingResultsInUnchangedRepositoryForType() {

View File

@@ -19,6 +19,9 @@ import java.util.List;
import java.util.stream.Collectors;
import org.eclipse.hawkbit.repository.TagManagement;
import org.eclipse.hawkbit.repository.event.remote.entity.DistributionSetTagUpdateEvent;
import org.eclipse.hawkbit.repository.event.remote.entity.TargetCreatedEvent;
import org.eclipse.hawkbit.repository.event.remote.entity.TargetTagUpdateEvent;
import org.eclipse.hawkbit.repository.exception.EntityAlreadyExistsException;
import org.eclipse.hawkbit.repository.jpa.model.JpaTargetTag;
import org.eclipse.hawkbit.repository.model.DistributionSet;
@@ -29,7 +32,8 @@ 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.eclipse.hawkbit.repository.test.matcher.Expect;
import org.eclipse.hawkbit.repository.test.matcher.ExpectEvents;
import org.junit.Test;
import com.google.common.collect.Lists;
@@ -46,9 +50,30 @@ import ru.yandex.qatools.allure.annotations.Stories;
@Stories("Tag Management")
public class TagManagementTest extends AbstractJpaIntegrationTest {
@Before
public void setup() {
assertThat(targetTagRepository.findAll()).as("Not tags should be available").isEmpty();
@Test
@Description("Verifies that management get access reacts as specfied on calls for non existing entities by means "
+ "of Optional not present.")
@ExpectEvents({ @Expect(type = TargetCreatedEvent.class, count = 0) })
public void nonExistingEntityAccessReturnsNotPresent() {
assertThat(tagManagement.findDistributionSetTag(NOT_EXIST_ID)).isNotPresent();
assertThat(tagManagement.findDistributionSetTagById(NOT_EXIST_IDL)).isNotPresent();
assertThat(tagManagement.findTargetTag(NOT_EXIST_ID)).isNotPresent();
assertThat(tagManagement.findTargetTagById(NOT_EXIST_IDL)).isNotPresent();
}
@Test
@Description("Verifies that management queries react as specfied on calls for non existing entities "
+ " by means of throwing EntityNotFoundException.")
@ExpectEvents({ @Expect(type = DistributionSetTagUpdateEvent.class, count = 0),
@Expect(type = TargetTagUpdateEvent.class, count = 0) })
public void entityQueriesReferringToNotExistingEntitiesThrowsException() {
verifyThrownExceptionBy(() -> tagManagement.deleteDistributionSetTag(NOT_EXIST_ID), "DistributionSetTag");
verifyThrownExceptionBy(() -> tagManagement.deleteTargetTag(NOT_EXIST_ID), "TargetTag");
verifyThrownExceptionBy(() -> tagManagement.updateDistributionSetTag(entityFactory.tag().update(NOT_EXIST_IDL)),
"DistributionSetTag");
verifyThrownExceptionBy(() -> tagManagement.updateTargetTag(entityFactory.tag().update(NOT_EXIST_IDL)),
"TargetTag");
}
@Test

View File

@@ -20,11 +20,16 @@ import java.util.Iterator;
import java.util.List;
import org.eclipse.hawkbit.repository.TargetFilterQueryManagement;
import org.eclipse.hawkbit.repository.event.remote.entity.DistributionSetCreatedEvent;
import org.eclipse.hawkbit.repository.event.remote.entity.SoftwareModuleCreatedEvent;
import org.eclipse.hawkbit.repository.event.remote.entity.TargetCreatedEvent;
import org.eclipse.hawkbit.repository.exception.EntityAlreadyExistsException;
import org.eclipse.hawkbit.repository.exception.RSQLParameterUnsupportedFieldException;
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.test.matcher.Expect;
import org.eclipse.hawkbit.repository.test.matcher.ExpectEvents;
import org.junit.Test;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
@@ -41,6 +46,44 @@ import ru.yandex.qatools.allure.annotations.Stories;
@Stories("Target Filter Query Management")
public class TargetFilterQueryManagementTest extends AbstractJpaIntegrationTest {
@Test
@Description("Verifies that management get access reacts as specfied on calls for non existing entities by means "
+ "of Optional not present.")
@ExpectEvents({ @Expect(type = TargetCreatedEvent.class, count = 0) })
public void nonExistingEntityAccessReturnsNotPresent() {
assertThat(targetFilterQueryManagement.findTargetFilterQueryById(NOT_EXIST_IDL)).isNotPresent();
assertThat(targetFilterQueryManagement.findTargetFilterQueryByName(NOT_EXIST_ID)).isNotPresent();
}
@Test
@Description("Verifies that management queries react as specfied on calls for non existing entities "
+ " by means of throwing EntityNotFoundException.")
@ExpectEvents({ @Expect(type = DistributionSetCreatedEvent.class, count = 1),
@Expect(type = SoftwareModuleCreatedEvent.class, count = 3) })
public void entityQueriesReferringToNotExistingEntitiesThrowsException() {
final DistributionSet set = testdataFactory.createDistributionSet();
final TargetFilterQuery targetFilterQuery = targetFilterQueryManagement.createTargetFilterQuery(
entityFactory.targetFilterQuery().create().name("test filter").query("name==PendingTargets001"));
verifyThrownExceptionBy(() -> targetFilterQueryManagement.deleteTargetFilterQuery(NOT_EXIST_IDL),
"TargetFilterQuery");
verifyThrownExceptionBy(() -> targetFilterQueryManagement.findTargetFilterQueryByAutoAssignDS(pageReq,
NOT_EXIST_IDL, "name==*"), "DistributionSet");
verifyThrownExceptionBy(
() -> targetFilterQueryManagement
.updateTargetFilterQuery(entityFactory.targetFilterQuery().update(NOT_EXIST_IDL)),
"TargetFilterQuery");
verifyThrownExceptionBy(() -> targetFilterQueryManagement
.updateTargetFilterQueryAutoAssignDS(targetFilterQuery.getId(), NOT_EXIST_IDL), "DistributionSet");
verifyThrownExceptionBy(
() -> targetFilterQueryManagement.updateTargetFilterQueryAutoAssignDS(1234L, set.getId()),
"TargetFilterQuery");
verifyThrownExceptionBy(() -> targetFilterQueryManagement
.updateTargetFilterQueryAutoAssignDS(targetFilterQuery.getId(), NOT_EXIST_IDL), "DistributionSet");
}
@Test
@Description("Test creation of target filter query.")
public void createTargetFilterQuery() {

View File

@@ -8,12 +8,7 @@
*/
package org.eclipse.hawkbit.repository.jpa;
import static com.google.common.collect.Iterables.limit;
import static com.google.common.collect.Iterables.toArray;
import static com.google.common.collect.Lists.newArrayList;
import static java.util.stream.Collectors.toList;
import static org.assertj.core.api.Assertions.assertThat;
import static org.eclipse.hawkbit.im.authentication.SpPermission.SpringEvalExpressions.CONTROLLER_ROLE_ANONYMOUS;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.fail;
@@ -65,37 +60,73 @@ import ru.yandex.qatools.allure.annotations.Stories;
public class TargetManagementTest extends AbstractJpaIntegrationTest {
@Test
@Description("Ensures that an anonymous target update is not monitored by auditing.")
@WithUser(principal = "knownPrincipal", authorities = { SpPermission.READ_TARGET, SpPermission.UPDATE_TARGET,
SpPermission.CREATE_TARGET }, allSpPermissions = false)
@Description("Verifies that management get access react as specfied on calls for non existing entities by means "
+ "of Optional not present.")
@ExpectEvents({ @Expect(type = TargetCreatedEvent.class, count = 0) })
public void nonExistingEntityAccessReturnsNotPresent() {
assertThat(targetManagement.findTargetByControllerID(NOT_EXIST_ID)).isNotPresent();
assertThat(targetManagement.findTargetById(NOT_EXIST_IDL)).isNotPresent();
}
@Test
@Description("Verifies that management queries react as specfied on calls for non existing entities "
+ " by means of throwing EntityNotFoundException.")
@ExpectEvents({ @Expect(type = TargetCreatedEvent.class, count = 1),
@Expect(type = TargetUpdatedEvent.class, count = 2) })
public void controllerAccessDoesNotChangeAuditData() throws Exception {
// create target first with "knownPrincipal" user and audit data
final String knownTargetControllerId = "target1";
final String knownCreatedBy = "knownPrincipal";
testdataFactory.createTarget(knownTargetControllerId);
targetManagement.updateTarget(entityFactory.target().update(knownTargetControllerId).description("updated1"));
final Target findTargetByControllerID = targetManagement.findTargetByControllerID(knownTargetControllerId)
.get();
assertThat(findTargetByControllerID.getCreatedBy()).isEqualTo(knownCreatedBy);
assertThat(findTargetByControllerID.getCreatedAt()).isNotNull();
assertThat(findTargetByControllerID.getLastModifiedBy()).isEqualTo(knownCreatedBy);
assertThat(findTargetByControllerID.getLastModifiedAt()).isNotNull();
@Expect(type = TargetTagCreatedEvent.class, count = 1) })
public void entityQueriesReferringToNotExistingEntitiesThrowsException() {
final TargetTag tag = tagManagement.createTargetTag(entityFactory.tag().create().name("A"));
final Target target = testdataFactory.createTarget();
// make an update, audit information should not be changed, run as
// controller principal!
securityRule.runAs(WithSpringAuthorityRule.withController("controller", CONTROLLER_ROLE_ANONYMOUS), () -> {
targetManagement.updateTarget(entityFactory.target().update("target1").description("updated2"));
return null;
});
verifyThrownExceptionBy(
() -> targetManagement.assignTag(Lists.newArrayList(target.getControllerId()), NOT_EXIST_IDL),
"TargetTag");
verifyThrownExceptionBy(() -> targetManagement.assignTag(Lists.newArrayList(NOT_EXIST_ID), tag.getId()),
"Target");
// verify that audit information has not changed
final Target targetVerify = targetManagement.findTargetByControllerID(knownTargetControllerId).get();
assertThat(targetVerify.getCreatedBy()).isEqualTo(findTargetByControllerID.getCreatedBy());
assertThat(targetVerify.getCreatedAt()).isEqualTo(findTargetByControllerID.getCreatedAt());
assertThat(targetVerify.getLastModifiedBy()).isEqualTo(findTargetByControllerID.getLastModifiedBy());
assertThat(targetVerify.getLastModifiedAt()).isEqualTo(findTargetByControllerID.getLastModifiedAt());
verifyThrownExceptionBy(() -> targetManagement.countTargetByAssignedDistributionSet(NOT_EXIST_IDL),
"DistributionSet");
verifyThrownExceptionBy(() -> targetManagement.countTargetByInstalledDistributionSet(NOT_EXIST_IDL),
"DistributionSet");
verifyThrownExceptionBy(() -> targetManagement.countTargetByTargetFilterQuery(NOT_EXIST_IDL),
"TargetFilterQuery");
verifyThrownExceptionBy(
() -> targetManagement.countTargetsByTargetFilterQueryAndNonDS(NOT_EXIST_IDL, "name==*"),
"DistributionSet");
verifyThrownExceptionBy(() -> targetManagement.deleteTarget(NOT_EXIST_ID), "Target");
verifyThrownExceptionBy(() -> targetManagement.deleteTargets(Lists.newArrayList(NOT_EXIST_IDL)), "Target");
verifyThrownExceptionBy(
() -> targetManagement.findAllTargetsByTargetFilterQueryAndNonDS(pageReq, NOT_EXIST_IDL, "name==*"),
"DistributionSet");
verifyThrownExceptionBy(
() -> targetManagement.findAllTargetsInRolloutGroupWithoutAction(pageReq, NOT_EXIST_IDL),
"RolloutGroup");
verifyThrownExceptionBy(() -> targetManagement.findTargetByAssignedDistributionSet(NOT_EXIST_IDL, pageReq),
"DistributionSet");
verifyThrownExceptionBy(
() -> targetManagement.findTargetByAssignedDistributionSet(NOT_EXIST_IDL, "name==*", pageReq),
"DistributionSet");
verifyThrownExceptionBy(() -> targetManagement.findTargetByInstalledDistributionSet(NOT_EXIST_IDL, pageReq),
"DistributionSet");
verifyThrownExceptionBy(
() -> targetManagement.findTargetByInstalledDistributionSet(NOT_EXIST_IDL, "name==*", pageReq),
"DistributionSet");
verifyThrownExceptionBy(
() -> targetManagement.toggleTagAssignment(Lists.newArrayList(target.getControllerId()), NOT_EXIST_ID),
"TargetTag");
verifyThrownExceptionBy(
() -> targetManagement.toggleTagAssignment(Lists.newArrayList(NOT_EXIST_ID), tag.getName()), "Target");
verifyThrownExceptionBy(() -> targetManagement.unAssignAllTargetsByTag(NOT_EXIST_IDL), "TargetTag");
verifyThrownExceptionBy(() -> targetManagement.unAssignTag(NOT_EXIST_ID, tag.getId()), "Target");
verifyThrownExceptionBy(() -> targetManagement.unAssignTag(target.getControllerId(), NOT_EXIST_IDL),
"TargetTag");
verifyThrownExceptionBy(() -> targetManagement.updateTarget(entityFactory.target().update(NOT_EXIST_ID)),
"Target");
}
@Test
@@ -224,7 +255,6 @@ public class TargetManagementTest extends AbstractJpaIntegrationTest {
.getControllerId());
assignTarget.add(targetManagement.createTarget(entityFactory.target().create().controllerId("targetId1236"))
.getControllerId());
assignTarget.add("NotExist");
final TargetTag targetTag = tagManagement.createTargetTag(entityFactory.tag().create().name("Tag1"));
@@ -237,9 +267,6 @@ public class TargetManagementTest extends AbstractJpaIntegrationTest {
assertThat(assignedTargets.size()).as("Assigned targets are wrong")
.isEqualTo(findTargetTag.getAssignedToTargets().size());
assertThat(targetManagement.unAssignTag("NotExist", findTargetTag.getId())).as("Unassign target does not work")
.isNull();
final Target unAssignTarget = targetManagement.unAssignTag("targetId123", findTargetTag.getId());
assertThat(unAssignTarget.getControllerId()).as("Controller id is wrong").isEqualTo("targetId123");
assertThat(tagManagement.findAllTargetTags(pageReq, unAssignTarget.getControllerId())).as("Tag size is wrong")
@@ -478,7 +505,7 @@ public class TargetManagementTest extends AbstractJpaIntegrationTest {
firstList = firstList.stream()
.map(t -> targetManagement.updateTarget(
entityFactory.target().update(t.getControllerId()).name(t.getName().concat("\tchanged"))))
.collect(toList());
.collect(Collectors.toList());
// verify that all entries are found
_founds: for (final Target foundTarget : allFound) {
@@ -507,10 +534,10 @@ public class TargetManagementTest extends AbstractJpaIntegrationTest {
targetManagement.deleteTarget(extra.getControllerId());
final int numberToDelete = 50;
final Iterable<Target> targetsToDelete = limit(firstList, numberToDelete);
final Target[] deletedTargets = toArray(targetsToDelete, Target.class);
final List<Long> targetsIdsToDelete = newArrayList(targetsToDelete.iterator()).stream().map(Target::getId)
.collect(toList());
final Iterable<Target> targetsToDelete = Iterables.limit(firstList, numberToDelete);
final Target[] deletedTargets = Iterables.toArray(targetsToDelete, Target.class);
final List<Long> targetsIdsToDelete = Lists.newArrayList(targetsToDelete.iterator()).stream().map(Target::getId)
.collect(Collectors.toList());
targetManagement.deleteTargets(targetsIdsToDelete);
@@ -723,27 +750,23 @@ public class TargetManagementTest extends AbstractJpaIntegrationTest {
final String rsqlFilter = "tag==Targ-A-Tag,id==target-id-B-00001,id==target-id-B-00008";
final TargetTag targTagA = tagManagement.createTargetTag(entityFactory.tag().create().name("Targ-A-Tag"));
final List<String> targAs = testdataFactory.createTargets(25, "target-id-A", "first description").stream()
.map(Target::getControllerId).collect(toList());
.map(Target::getControllerId).collect(Collectors.toList());
targetManagement.toggleTagAssignment(targAs, targTagA.getName());
testdataFactory.createTargets(25, "target-id-B", "first description");
final Page<Target> foundTargets = targetManagement.findTargetsAll(rsqlFilter, new PageRequest(0, 100));
final Page<Target> foundTargets = targetManagement.findTargetsAll(rsqlFilter, pageReq);
assertThat(targetManagement.findTargetsAll(new PageRequest(0, 100)).getNumberOfElements()).as("Total targets")
.isEqualTo(50);
assertThat(targetManagement.countTargetsAll()).as("Total targets").isEqualTo(50L);
assertThat(foundTargets.getTotalElements()).as("Targets in RSQL filter").isEqualTo(27L);
}
@Test
@Description("Verify that the find all targets by ids method contains the entities that we are looking for")
@ExpectEvents({ @Expect(type = TargetCreatedEvent.class, count = 12) })
public void verifyFindTargetAllById() {
final List<Long> searchIds = new ArrayList<>();
searchIds.add(testdataFactory.createTarget("target-4").getId());
searchIds.add(testdataFactory.createTarget("target-5").getId());
searchIds.add(testdataFactory.createTarget("target-6").getId());
final List<Long> searchIds = Lists.newArrayList(testdataFactory.createTarget("target-4").getId(),
testdataFactory.createTarget("target-5").getId(), testdataFactory.createTarget("target-6").getId());
for (int i = 0; i < 9; i++) {
testdataFactory.createTarget("test" + i);
}

View File

@@ -104,7 +104,7 @@ public class RepositoryEntityEventTest extends AbstractJpaIntegrationTest {
final DistributionSet distributionSet = testdataFactory.createDistributionSet("dsFor" + rolloutName);
testdataFactory.createTargets(amountTargetsForRollout, targetPrefixName + "-", targetPrefixName);
final Rollout createdRollout = createRolloutByVariables(rolloutName, "desc", amountGroups,
final Rollout createdRollout = testdataFactory.createRolloutByVariables(rolloutName, "desc", amountGroups,
"controllerId==" + targetPrefixName + "-*", distributionSet, successCondition, errorCondition);
rolloutManagement.deleteRollout(createdRollout.getId());