Refactor DS Management (#2591)

Signed-off-by: Avgustin Marinov <Avgustin.Marinov@bosch.com>
This commit is contained in:
Avgustin Marinov
2025-08-05 15:45:41 +03:00
committed by GitHub
parent 049add05ac
commit 6aa8ccaa9c
39 changed files with 365 additions and 776 deletions

View File

@@ -14,8 +14,10 @@ import static org.eclipse.hawkbit.repository.test.util.SecurityContextSwitch.run
import static org.eclipse.hawkbit.repository.test.util.SecurityContextSwitch.withUser;
import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Optional;
import java.util.Set;
import java.util.concurrent.Callable;
import java.util.stream.StreamSupport;
@@ -50,9 +52,13 @@ import org.eclipse.hawkbit.repository.jpa.repository.TargetRepository;
import org.eclipse.hawkbit.repository.jpa.repository.TargetTagRepository;
import org.eclipse.hawkbit.repository.jpa.repository.TargetTypeRepository;
import org.eclipse.hawkbit.repository.jpa.repository.TenantMetaDataRepository;
import org.eclipse.hawkbit.repository.jpa.specifications.DistributionSetSpecification;
import org.eclipse.hawkbit.repository.jpa.specifications.TargetSpecifications;
import org.eclipse.hawkbit.repository.model.Action;
import org.eclipse.hawkbit.repository.model.DistributionSet;
import org.eclipse.hawkbit.repository.model.DistributionSetFilter;
import org.eclipse.hawkbit.repository.model.DistributionSetTag;
import org.eclipse.hawkbit.repository.model.DistributionSetType;
import org.eclipse.hawkbit.repository.model.Rollout;
import org.eclipse.hawkbit.repository.model.RolloutGroup;
import org.eclipse.hawkbit.repository.model.SoftwareModule;
@@ -67,10 +73,15 @@ import org.eclipse.hawkbit.tenancy.configuration.TenantConfigurationProperties;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.orm.jpa.JpaProperties;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Slice;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.orm.jpa.vendor.Database;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.TestPropertySource;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;
import org.springframework.util.ObjectUtils;
@Slf4j
@ContextConfiguration(classes = { JpaRepositoryConfiguration.class, TestConfiguration.class })
@@ -86,9 +97,6 @@ public abstract class AbstractJpaIntegrationTest extends AbstractIntegrationTest
SpPermission.UPDATE_REPOSITORY, SpPermission.DELETE_REPOSITORY, SpPermission.READ_TARGET, SpPermission.CREATE_TARGET,
SpPermission.UPDATE_TARGET, SpPermission.DELETE_TARGET);
@PersistenceContext
protected EntityManager entityManager;
@Autowired
protected TargetRepository targetRepository;
@Autowired
@@ -307,4 +315,43 @@ public abstract class AbstractJpaIntegrationTest extends AbstractIntegrationTest
private JpaRollout refresh(final Rollout rollout) {
return rolloutRepository.findById(rollout.getId()).get();
}
protected Slice<JpaDistributionSet> findDsByDistributionSetFilter(final DistributionSetFilter distributionSetFilter, final Pageable pageable) {
final List<Specification<JpaDistributionSet>> specList = buildDistributionSetSpecifications(distributionSetFilter);
return JpaManagementHelper.findAllWithoutCountBySpec(distributionSetRepository, specList, pageable);
}
private static List<Specification<JpaDistributionSet>> buildDistributionSetSpecifications(
final DistributionSetFilter distributionSetFilter) {
final List<Specification<JpaDistributionSet>> specList = new ArrayList<>(10);
if (distributionSetFilter.getIsComplete() != null) {
specList.add(DistributionSetSpecification.isCompleted(distributionSetFilter.getIsComplete()));
}
if (distributionSetFilter.getIsDeleted() != null) {
specList.add(DistributionSetSpecification.isDeleted(distributionSetFilter.getIsDeleted()));
}
if (distributionSetFilter.getIsValid() != null) {
specList.add(DistributionSetSpecification.isValid(distributionSetFilter.getIsValid()));
}
if (distributionSetFilter.getTypeId() != null) {
specList.add(DistributionSetSpecification.byType(distributionSetFilter.getTypeId()));
}
if (!ObjectUtils.isEmpty(distributionSetFilter.getSearchText())) {
final String[] dsFilterNameAndVersionEntries = JpaManagementHelper
.getFilterNameAndVersionEntries(distributionSetFilter.getSearchText().trim());
specList.add(DistributionSetSpecification.likeNameAndVersion(dsFilterNameAndVersionEntries[0], dsFilterNameAndVersionEntries[1]));
}
if (hasTagsFilterActive(distributionSetFilter)) {
specList.add(DistributionSetSpecification.hasTags(
distributionSetFilter.getTagNames(), distributionSetFilter.getSelectDSWithNoTag()));
}
return specList;
}
private static boolean hasTagsFilterActive(final DistributionSetFilter distributionSetFilter) {
final boolean isNoTagActive = Boolean.TRUE.equals(distributionSetFilter.getSelectDSWithNoTag());
final boolean isAtLeastOneTagActive = !CollectionUtils.isEmpty(distributionSetFilter.getTagNames());
return isNoTagActive || isAtLeastOneTagActive;
}
}

View File

@@ -58,7 +58,6 @@ class DistributionSetAccessControllerTest extends AbstractJpaIntegrationTest {
final DistributionSet hidden = testdataFactory.createDistributionSet();
final Action permittedAction = testdataFactory.performAssignment(permitted);
final Action hiddenAction = testdataFactory.performAssignment(hidden);
runAs(withUser("user",
READ_REPOSITORY,
@@ -74,15 +73,6 @@ class DistributionSetAccessControllerTest extends AbstractJpaIntegrationTest {
assertThat(distributionSetManagement.findByRsql("name==*", Pageable.unpaged()).get().map(Identifiable::getId)
.toList()).containsOnly(permittedActionId);
// verify distributionSetManagement#findByCompleted
assertThat(distributionSetManagement.findByCompleted(true, Pageable.unpaged()).get().map(Identifiable::getId)
.toList()).containsOnly(permittedActionId);
// verify distributionSetManagement#findByDistributionSetFilter
assertThat(distributionSetManagement
.findByDistributionSetFilter(DistributionSetFilter.builder().isDeleted(false).build(), Pageable.unpaged())
.get().map(Identifiable::getId).toList()).containsOnly(permittedActionId);
// verify distributionSetManagement#get
assertThat(distributionSetManagement.get(permittedActionId)).isPresent();
final Long hiddenId = hidden.getId();
@@ -92,11 +82,6 @@ class DistributionSetAccessControllerTest extends AbstractJpaIntegrationTest {
assertThat(distributionSetManagement.getWithDetails(permittedActionId)).isPresent();
assertThat(distributionSetManagement.getWithDetails(hiddenId)).isEmpty();
// verify distributionSetManagement#get
assertThat(distributionSetManagement.getValid(permittedActionId).getId()).isEqualTo(permittedActionId);
assertThatThrownBy(() -> distributionSetManagement.getValid(hiddenId))
.as("Distribution set should not be found.").isInstanceOf(EntityNotFoundException.class);
// verify distributionSetManagement#get
final List<Long> allActionIds = Arrays.asList(permittedActionId, hiddenId);
assertThatThrownBy(() -> distributionSetManagement.get(allActionIds))
@@ -105,12 +90,6 @@ class DistributionSetAccessControllerTest extends AbstractJpaIntegrationTest {
// verify distributionSetManagement#getByNameAndVersion
assertThat(distributionSetManagement.findByNameAndVersion(permitted.getName(), permitted.getVersion())).isPresent();
assertThat(distributionSetManagement.findByNameAndVersion(hidden.getName(), hidden.getVersion())).isEmpty();
// verify distributionSetManagement#getByAction
assertThat(distributionSetManagement.findByAction(permittedAction.getId())).isPresent();
final Long hiddenActionId = hiddenAction.getId();
assertThatThrownBy(() -> distributionSetManagement.findByAction(hiddenActionId))
.as("Action is hidden.").isInstanceOf(InsufficientPermissionException.class);
});
}
@@ -254,9 +233,9 @@ class DistributionSetAccessControllerTest extends AbstractJpaIntegrationTest {
final DistributionSet readOnly = testdataFactory.createDistributionSet();
final DistributionSet hidden = testdataFactory.createDistributionSet();
// has to lock them, otherwise implicit lock shall be made which require DistributionSet update permissions
distributionSetManagement.lock(permitted.getId());
distributionSetManagement.lock(readOnly.getId());
distributionSetManagement.lock(hidden.getId());
distributionSetManagement.lock(permitted);
distributionSetManagement.lock(readOnly);
distributionSetManagement.lock(hidden);
final TargetFilterQuery targetFilterQuery = targetFilterQueryManagement
.create(TargetFilterQueryManagement.Create.builder().name("test").query("id==*").build());

View File

@@ -196,8 +196,8 @@ class TargetAccessControllerTest extends AbstractJpaIntegrationTest {
*/
@Test
void verifyTargetAssignment() {
final Long dsId = testdataFactory.createDistributionSet("myDs").getId();
distributionSetManagement.lock(dsId);
final DistributionSet ds = testdataFactory.createDistributionSet("myDs");
distributionSetManagement.lock(ds);
final Target permittedTarget = targetManagement
.create(entityFactory.target().create().controllerId("device01").status(TargetUpdateStatus.REGISTERED));
@@ -214,6 +214,7 @@ class TargetAccessControllerTest extends AbstractJpaIntegrationTest {
READ_TARGET + "/controllerId==" + permittedTarget.getControllerId(),
UPDATE_TARGET + "/controllerId==" + permittedTarget.getControllerId(),
READ_REPOSITORY), () -> {
final Long dsId = ds.getId();
assertThat(assignDistributionSet(dsId, permittedTarget.getControllerId()).getAssigned()).isEqualTo(1);
// assigning of not allowed target behaves as not found
assertThatThrownBy(() -> assignDistributionSet(dsId, hiddenTargetControllerId)).isInstanceOf(AssertionError.class);
@@ -233,10 +234,10 @@ class TargetAccessControllerTest extends AbstractJpaIntegrationTest {
*/
@Test
void verifyTargetAssignmentOnNonUpdatableTarget() {
final Long firstDsId = testdataFactory.createDistributionSet("myDs").getId();
distributionSetManagement.lock(firstDsId);
final DistributionSet firstDs = testdataFactory.createDistributionSet("myDs");
distributionSetManagement.lock(firstDs);
final DistributionSet secondDs = testdataFactory.createDistributionSet("anotherDs");
distributionSetManagement.lock(secondDs.getId());
distributionSetManagement.lock(secondDs);
final Target manageableTarget = targetManagement
.create(entityFactory.target().create().controllerId("device01").status(TargetUpdateStatus.REGISTERED));
@@ -247,6 +248,7 @@ class TargetAccessControllerTest extends AbstractJpaIntegrationTest {
READ_TARGET + "/controllerId==" + manageableTarget.getControllerId() + " or controllerId==" + readOnlyTarget.getControllerId(),
UPDATE_TARGET + "/controllerId==" + manageableTarget.getControllerId(),
READ_REPOSITORY), () -> {
final Long firstDsId = firstDs.getId();
// assignment is permitted for manageableTarget
assertThat(assignDistributionSet(firstDsId, manageableTarget.getControllerId()).getAssigned()).isEqualTo(1);
@@ -267,7 +269,7 @@ class TargetAccessControllerTest extends AbstractJpaIntegrationTest {
@Test
void verifyRolloutTargetScope() {
final DistributionSet ds = testdataFactory.createDistributionSet("myDs");
distributionSetManagement.lock(ds.getId());
distributionSetManagement.lock(ds);
final String[] updateTargetControllerIds = { "update1", "update2", "update3" };
final List<Target> updateTargets = testdataFactory.createTargets(updateTargetControllerIds);
@@ -307,7 +309,7 @@ class TargetAccessControllerTest extends AbstractJpaIntegrationTest {
@Test
void verifyAutoAssignmentTargetScope() {
final DistributionSet distributionSet = testdataFactory.createDistributionSet();
distributionSetManagement.lock(distributionSet.getId());
distributionSetManagement.lock(distributionSet);
final String[] updateTargetControllerIds = { "update1", "update2", "update3" };
final List<Target> updateTargets = testdataFactory.createTargets(updateTargetControllerIds);

View File

@@ -63,7 +63,7 @@ class DeploymentManagementSecurityTest extends AbstractJpaIntegrationTest {
*/
@Test
void offlineAssignedDistributionSetsWithInitiatedByPermissionsCheck() {
assertPermissions(() -> deploymentManagement.offlineAssignedDistributionSets(List.of(), "initiator"),
assertPermissions(() -> deploymentManagement.offlineAssignedDistributionSets("initiator", List.of()),
List.of(SpPermission.READ_REPOSITORY, SpPermission.UPDATE_TARGET));
}

View File

@@ -1356,7 +1356,7 @@ class DeploymentManagementTest extends AbstractJpaIntegrationTest {
}
// verify that deleted attribute is used correctly
List<? extends DistributionSet> allFoundDS = distributionSetManagement.findByCompleted(true, PAGE).getContent();
List<? extends DistributionSet> allFoundDS = distributionSetManagement.findAll(PAGE).getContent();
assertThat(allFoundDS).as("no ds should be founded").isEmpty();
assertThat(distributionSetRepository.findAll(SpecificationsBuilder.combineWithAnd(Arrays
@@ -1368,16 +1368,13 @@ class DeploymentManagementTest extends AbstractJpaIntegrationTest {
// try to delete again
distributionSetManagement.delete(deploymentResult.getDistributionSetIDs());
// verify that the result is the same, even though distributionSet dsA
// has been installed
// successfully and no activeAction is referring to created distribution
// sets
allFoundDS = distributionSetManagement.findByCompleted(true, pageRequest).getContent();
// verify that the result is the same, even though distributionSet dsA has been installed
// successfully and no activeAction is referring to created distribution sets
allFoundDS = distributionSetManagement.findAll(pageRequest).getContent();
assertThat(allFoundDS).as("no ds should be founded").isEmpty();
assertThat(distributionSetRepository.findAll(SpecificationsBuilder.combineWithAnd(Arrays
.asList(DistributionSetSpecification.isDeleted(true), DistributionSetSpecification.isCompleted(true))),
PAGE).getContent()).as("wrong size of founded ds").hasSize(noOfDistributionSets);
}
/**

View File

@@ -14,11 +14,8 @@ import java.util.Map;
import org.eclipse.hawkbit.im.authentication.SpPermission;
import org.eclipse.hawkbit.repository.DistributionSetManagement;
import org.eclipse.hawkbit.repository.DistributionSetTypeManagement;
import org.eclipse.hawkbit.repository.jpa.AbstractRepositoryManagementSecurityTest;
import org.eclipse.hawkbit.repository.model.DistributionSet;
import org.eclipse.hawkbit.repository.model.DistributionSetFilter;
import org.eclipse.hawkbit.repository.model.DistributionSetType;
import org.junit.jupiter.api.Test;
/**
@@ -119,10 +116,8 @@ class DistributionSetManagementSecurityTest
*/
@Test
void lockPermissionsCheck() {
assertPermissions(() -> {
distributionSetManagement.lock(1L);
return null;
}, List.of(SpPermission.UPDATE_REPOSITORY));
final DistributionSet ds = testdataFactory.createDistributionSet();
assertPermissions(() -> distributionSetManagement.lock(ds), List.of(SpPermission.UPDATE_REPOSITORY));
}
/**
@@ -130,18 +125,8 @@ class DistributionSetManagementSecurityTest
*/
@Test
void unlockPermissionsCheck() {
assertPermissions(() -> {
distributionSetManagement.unlock(1L);
return null;
}, List.of(SpPermission.UPDATE_REPOSITORY));
}
/**
* Tests ManagementAPI PreAuthorized method with correct and insufficient permissions.
*/
@Test
void getByActionPermissionsCheck() {
assertPermissions(() -> distributionSetManagement.findByAction(1L), List.of(SpPermission.READ_REPOSITORY));
final DistributionSet ds = testdataFactory.createDistributionSet();
assertPermissions(() -> distributionSetManagement.unlock(ds), List.of(SpPermission.UPDATE_REPOSITORY));
}
/**
@@ -168,14 +153,6 @@ class DistributionSetManagementSecurityTest
assertPermissions(() -> distributionSetManagement.getValidAndComplete(1L), List.of(SpPermission.READ_REPOSITORY));
}
/**
* Tests ManagementAPI PreAuthorized method with correct and insufficient permissions.
*/
@Test
void getValidPermissionsCheck() {
assertPermissions(() -> distributionSetManagement.getValid(1L), List.of(SpPermission.READ_REPOSITORY));
}
/**
* Tests ManagementAPI PreAuthorized method with correct and insufficient permissions.
*/
@@ -184,40 +161,6 @@ class DistributionSetManagementSecurityTest
assertPermissions(() -> distributionSetManagement.getOrElseThrowException(1L), List.of(SpPermission.READ_REPOSITORY));
}
/**
* Tests ManagementAPI PreAuthorized method with correct and insufficient permissions.
*/
@Test
void findByCompletedPermissionsCheck() {
assertPermissions(() -> distributionSetManagement.findByCompleted(true, PAGE), List.of(SpPermission.READ_REPOSITORY));
}
/**
* Tests ManagementAPI PreAuthorized method with correct and insufficient permissions.
*/
@Test
void countByCompletedPermissionsCheck() {
assertPermissions(() -> distributionSetManagement.countByCompleted(true), List.of(SpPermission.READ_REPOSITORY));
}
/**
* Tests ManagementAPI PreAuthorized method with correct and insufficient permissions.
*/
@Test
void findByDistributionSetFilterPermissionsCheck() {
assertPermissions(() -> distributionSetManagement.findByDistributionSetFilter(DistributionSetFilter.builder().build(), PAGE),
List.of(SpPermission.READ_REPOSITORY));
}
/**
* Tests ManagementAPI PreAuthorized method with correct and insufficient permissions.
*/
@Test
void countByDistributionSetFilterPermissionsCheck() {
assertPermissions(() -> distributionSetManagement.countByDistributionSetFilter(DistributionSetFilter.builder().build()),
List.of(SpPermission.READ_REPOSITORY));
}
/**
* Tests ManagementAPI PreAuthorized method with correct and insufficient permissions.
*/
@@ -234,14 +177,6 @@ class DistributionSetManagementSecurityTest
assertPermissions(() -> distributionSetManagement.findByRsqlAndTag("rsql", 1L, PAGE), List.of(SpPermission.READ_REPOSITORY));
}
/**
* Tests ManagementAPI PreAuthorized method with correct and insufficient permissions.
*/
@Test
void isInUsePermissionsCheck() {
assertPermissions(() -> distributionSetManagement.isInUse(1L), List.of(SpPermission.READ_REPOSITORY));
}
/**
* Tests ManagementAPI PreAuthorized method with correct and insufficient permissions.
*/
@@ -250,14 +185,6 @@ class DistributionSetManagementSecurityTest
assertPermissions(() -> distributionSetManagement.unassignSoftwareModule(1L, 1L), List.of(SpPermission.UPDATE_REPOSITORY));
}
/**
* Tests ManagementAPI PreAuthorized method with correct and insufficient permissions.
*/
@Test
void countByTypeIdPermissionsCheck() {
assertPermissions(() -> distributionSetManagement.countByTypeId(1L), List.of(SpPermission.READ_REPOSITORY));
}
/**
* Tests ManagementAPI PreAuthorized method with correct and insufficient permissions.
*/
@@ -287,13 +214,8 @@ class DistributionSetManagementSecurityTest
*/
@Test
void invalidatePermissionsCheck() {
final DistributionSetType dsType = distributionSetTypeManagement.create(DistributionSetTypeManagement.Create.builder()
.key("type").name("name").build());
final DistributionSet ds = distributionSetManagement.create(DistributionSetManagement.Create.builder()
.type(dsType).name("test").version("1.0.0").build());
assertPermissions(() -> {
((DistributionSetManagement) distributionSetManagement).invalidate(ds);
return null;
}, List.of(SpPermission.UPDATE_REPOSITORY, SpPermission.READ_REPOSITORY));
final DistributionSet ds = testdataFactory.createDistributionSet();
assertPermissions(() -> distributionSetManagement.invalidate(ds),
List.of(SpPermission.UPDATE_REPOSITORY, SpPermission.READ_REPOSITORY));
}
}

View File

@@ -42,7 +42,6 @@ import org.eclipse.hawkbit.repository.event.remote.entity.DistributionSetUpdated
import org.eclipse.hawkbit.repository.event.remote.entity.SoftwareModuleCreatedEvent;
import org.eclipse.hawkbit.repository.exception.AssignmentQuotaExceededException;
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.IncompleteDistributionSetException;
import org.eclipse.hawkbit.repository.exception.InvalidDistributionSetException;
@@ -117,8 +116,6 @@ class DistributionSetManagementTest extends AbstractJpaIntegrationTest {
verifyThrownExceptionBy(
() -> distributionSetManagement.assignSoftwareModules(set.getId(), singletonList(NOT_EXIST_IDL)), "SoftwareModule");
verifyThrownExceptionBy(() -> distributionSetManagement.countByTypeId(NOT_EXIST_IDL), "DistributionSet");
verifyThrownExceptionBy(() -> distributionSetManagement.unassignSoftwareModule(NOT_EXIST_IDL, module.getId()), "DistributionSet");
verifyThrownExceptionBy(() -> distributionSetManagement.unassignSoftwareModule(set.getId(), NOT_EXIST_IDL), "SoftwareModule");
@@ -143,27 +140,17 @@ class DistributionSetManagementTest extends AbstractJpaIntegrationTest {
verifyThrownExceptionBy(() -> distributionSetManagement.deleteMetadata(NOT_EXIST_IDL, "xxx"), "DistributionSet");
verifyThrownExceptionBy(() -> distributionSetManagement.deleteMetadata(set.getId(), NOT_EXIST_ID), "DistributionSet");
verifyThrownExceptionBy(() -> distributionSetManagement.findByAction(NOT_EXIST_IDL), "Action");
verifyThrownExceptionBy(() -> distributionSetManagement.getMetadata(NOT_EXIST_IDL).get("xxx"), "DistributionSet");
verifyThrownExceptionBy(() -> distributionSetManagement.getMetadata(NOT_EXIST_IDL).get(PAGE), "DistributionSet");
assertThatThrownBy(() -> distributionSetManagement.isInUse(NOT_EXIST_IDL))
.isInstanceOf(EntityNotFoundException.class).hasMessageContaining(NOT_EXIST_ID)
.hasMessageContaining("DistributionSet");
verifyThrownExceptionBy(() -> distributionSetManagement.getMetadata(NOT_EXIST_IDL), "DistributionSet");
verifyThrownExceptionBy(
() -> distributionSetManagement.update(DistributionSetManagement.Update.builder().id(NOT_EXIST_IDL).build()),
"DistributionSet");
verifyThrownExceptionBy(() -> distributionSetManagement.createMetadata(NOT_EXIST_IDL, "xxx", "xxx"), "DistributionSet");
verifyThrownExceptionBy(() -> distributionSetManagement.getOrElseThrowException(NOT_EXIST_IDL), "DistributionSet");
verifyThrownExceptionBy(() -> distributionSetManagement.getValidAndComplete(NOT_EXIST_IDL), "DistributionSet");
verifyThrownExceptionBy(() -> distributionSetManagement.getValid(NOT_EXIST_IDL), "DistributionSet");
}
/**
@@ -305,7 +292,7 @@ class DistributionSetManagementTest extends AbstractJpaIntegrationTest {
.as("ds has wrong tag size")
.hasSize(1));
final DistributionSetTag findDistributionSetTag = getOrThrow(distributionSetTagManagement.findByName(TAG1_NAME));
final DistributionSetTag findDistributionSetTag = getOrThrow(distributionSetTagManagement.get(tag.getId()));
assertThat(assignedDS)
.as("assigned ds has wrong size")
@@ -315,7 +302,7 @@ class DistributionSetManagementTest extends AbstractJpaIntegrationTest {
.unassignTag(List.of(assignDS.get(0)), findDistributionSetTag.getId()).get(0);
assertThat(unAssignDS.getId()).as("unassigned ds is wrong").isEqualTo(assignDS.get(0));
assertThat(unAssignDS.getTags()).as("unassigned ds has wrong tag size").isEmpty();
assertThat(distributionSetTagManagement.findByName(TAG1_NAME)).isPresent();
assertThat(distributionSetTagManagement.get(tag.getId())).isPresent();
assertThat(distributionSetManagement.findByTag(tag.getId(), PAGE).getNumberOfElements())
.as("ds tag ds has wrong ds size").isEqualTo(3);
@@ -534,7 +521,7 @@ class DistributionSetManagementTest extends AbstractJpaIntegrationTest {
assertThat(reloadedDS.getLastModifiedAt()).isPositive();
// verify updated meta data is the updated value
assertThat(distributionSetManagement.getMetadata(ds.getId()).get(knownKey)).isEqualTo(knownUpdateValue);
assertThat(distributionSetManagement.getMetadata(ds.getId())).containsEntry(knownKey, knownUpdateValue);
}
/**
@@ -578,11 +565,11 @@ class DistributionSetManagementTest extends AbstractJpaIntegrationTest {
dsDeleted = getOrThrow(distributionSetManagement.get(dsDeleted.getId()));
dsGroup1 = assignTag(dsGroup1, dsTagA);
dsTagA = getOrThrow(distributionSetTagRepository.findByNameEquals(dsTagA.getName()));
dsTagA = getOrThrow(distributionSetTagRepository.findById(dsTagA.getId()));
dsGroup1 = assignTag(dsGroup1, dsTagB);
dsTagA = getOrThrow(distributionSetTagRepository.findByNameEquals(dsTagA.getName()));
dsTagA = getOrThrow(distributionSetTagRepository.findById(dsTagA.getId()));
dsGroup2 = assignTag(dsGroup2, dsTagA);
dsTagA = getOrThrow(distributionSetTagRepository.findByNameEquals(dsTagA.getName()));
dsTagA = getOrThrow(distributionSetTagRepository.findById(dsTagA.getId()));
final List<? extends DistributionSet> allDistributionSets = Stream
.of(dsGroup1, dsGroup2, Arrays.asList(dsDeleted, dsInComplete, dsNewType)).flatMap(Collection::stream)
@@ -607,33 +594,19 @@ class DistributionSetManagementTest extends AbstractJpaIntegrationTest {
validateDeletedAndCompletedAndTypeAndSearchTextAndTag(dsGroup2, dsTagA, dsGroup2Prefix);
}
/**
* Simple DS load without the related data that should be loaded lazy.
*/
@Test
void findDistributionSetsWithoutLazy() {
testdataFactory.createDistributionSets(20);
assertThat(distributionSetManagement.findByCompleted(true, PAGE)).hasSize(20);
}
/**
* Locks a DS.
*/
@Test
void lockDistributionSet() {
final DistributionSet distributionSet = testdataFactory.createDistributionSet("ds-1");
assertThat(
distributionSetManagement.get(distributionSet.getId()).map(DistributionSet::isLocked).orElse(true))
.isFalse();
distributionSetManagement.lock(distributionSet.getId());
assertThat(
distributionSetManagement.get(distributionSet.getId()).map(DistributionSet::isLocked).orElse(false))
.isTrue();
assertThat(distributionSetManagement.get(distributionSet.getId()).map(DistributionSet::isLocked).orElse(true)).isFalse();
distributionSetManagement.lock(distributionSet);
assertThat(distributionSetManagement.get(distributionSet.getId()).map(DistributionSet::isLocked).orElse(false)).isTrue();
// assert software modules are locked
assertThat(distributionSet.getModules().size()).isNotZero();
distributionSetManagement.getWithDetails(distributionSet.getId()).map(DistributionSet::getModules)
.orElseThrow().forEach(module -> assertThat(module.isLocked()).isTrue());
distributionSetManagement.getWithDetails(distributionSet.getId()).map(DistributionSet::getModules).orElseThrow()
.forEach(module -> assertThat(module.isLocked()).isTrue());
}
/**
@@ -642,11 +615,8 @@ class DistributionSetManagementTest extends AbstractJpaIntegrationTest {
@Test
void deleteUnassignedLockedDistributionSet() {
final DistributionSet distributionSet = testdataFactory.createDistributionSet("ds-1");
distributionSetManagement.lock(distributionSet.getId());
assertThat(
distributionSetManagement.get(distributionSet.getId()).map(DistributionSet::isLocked)
.orElse(false))
.isTrue();
distributionSetManagement.lock(distributionSet);
assertThat(distributionSetManagement.get(distributionSet.getId()).map(DistributionSet::isLocked).orElse(false)).isTrue();
distributionSetManagement.delete(distributionSet.getId());
assertThat(distributionSetManagement.get(distributionSet.getId())).isEmpty();
@@ -658,11 +628,8 @@ class DistributionSetManagementTest extends AbstractJpaIntegrationTest {
@Test
void deleteAssignedLockedDistributionSet() {
final DistributionSet distributionSet = testdataFactory.createDistributionSet("ds-1");
distributionSetManagement.lock(distributionSet.getId());
assertThat(
distributionSetManagement.get(distributionSet.getId()).map(DistributionSet::isLocked)
.orElse(false))
.isTrue();
distributionSetManagement.lock(distributionSet);
assertThat(distributionSetManagement.get(distributionSet.getId()).map(DistributionSet::isLocked).orElse(false)).isTrue();
final Target target = testdataFactory.createTarget();
assignDistributionSet(distributionSet.getId(), target.getControllerId());
@@ -676,21 +643,15 @@ class DistributionSetManagementTest extends AbstractJpaIntegrationTest {
*/
@Test
void unlockDistributionSet() {
final DistributionSet distributionSet = testdataFactory.createDistributionSet("ds-1");
distributionSetManagement.lock(distributionSet.getId());
assertThat(
distributionSetManagement.get(distributionSet.getId()).map(DistributionSet::isLocked)
.orElse(false))
.isTrue();
distributionSetManagement.unlock(distributionSet.getId());
assertThat(
distributionSetManagement.get(distributionSet.getId()).map(DistributionSet::isLocked)
.orElse(true))
.isFalse();
DistributionSet distributionSet = testdataFactory.createDistributionSet("ds-1");
distributionSet = distributionSetManagement.lock(distributionSet);
assertThat(distributionSetManagement.get(distributionSet.getId()).map(DistributionSet::isLocked).orElse(false)).isTrue();
distributionSet = distributionSetManagement.unlock(distributionSet);
assertThat(distributionSetManagement.get(distributionSet.getId()).map(DistributionSet::isLocked).orElse(true)).isFalse();
// assert software modules are not unlocked
assertThat(distributionSet.getModules().size()).isNotZero();
distributionSetManagement.getWithDetails(distributionSet.getId()).map(DistributionSet::getModules)
.orElseThrow().forEach(module -> assertThat(module.isLocked()).isTrue());
distributionSetManagement.getWithDetails(distributionSet.getId()).map(DistributionSet::getModules).orElseThrow()
.forEach(module -> assertThat(module.isLocked()).isTrue());
}
/**
@@ -701,8 +662,8 @@ class DistributionSetManagementTest extends AbstractJpaIntegrationTest {
final DistributionSet distributionSet = testdataFactory.createDistributionSet("ds-1");
final int softwareModuleCount = distributionSet.getModules().size();
assertThat(softwareModuleCount).isNotZero();
distributionSetManagement.lock(distributionSet);
final Long distributionSetId = distributionSet.getId();
distributionSetManagement.lock(distributionSetId);
assertThat(distributionSetManagement.get(distributionSetId).map(DistributionSet::isLocked).orElse(false)).isTrue();
// try add
@@ -710,16 +671,16 @@ class DistributionSetManagementTest extends AbstractJpaIntegrationTest {
assertThatExceptionOfType(LockedException.class)
.as("Attempt to modify a locked DS software modules should throw an exception")
.isThrownBy(() -> distributionSetManagement.assignSoftwareModules(distributionSetId, moduleIds));
assertThat(distributionSetManagement.getWithDetails(distributionSetId).get().getModules())
assertThat(distributionSetManagement.getWithDetails(distributionSetId).orElseThrow().getModules())
.as("Software module shall not be added to a locked DS.")
.hasSize(softwareModuleCount);
// try remove
final Long fisrtModuleId = distributionSet.getModules().stream().findFirst().get().getId();
final Long firstModuleId = distributionSet.getModules().stream().findFirst().orElseThrow().getId();
assertThatExceptionOfType(LockedException.class)
.as("Attempt to modify a locked DS software modules should throw an exception")
.isThrownBy(() -> distributionSetManagement.unassignSoftwareModule(distributionSetId, fisrtModuleId));
assertThat(distributionSetManagement.getWithDetails(distributionSetId).get().getModules())
.isThrownBy(() -> distributionSetManagement.unassignSoftwareModule(distributionSetId, firstModuleId));
assertThat(distributionSetManagement.getWithDetails(distributionSetId).orElseThrow().getModules())
.as("Software module shall not be removed from a locked DS.")
.hasSize(softwareModuleCount);
}
@@ -729,11 +690,11 @@ class DistributionSetManagementTest extends AbstractJpaIntegrationTest {
*/
@SuppressWarnings("rawtypes")
@Test
void isImplicitLockApplicableForDistributionSet() {
void shouldLockImplicitlyForDistributionSet() {
final JpaDistributionSetManagement distributionSetManagement = (JpaDistributionSetManagement) (DistributionSetManagement) this.distributionSetManagement;
final DistributionSet distributionSet = testdataFactory.createDistributionSet("ds-non-skip");
// assert that implicit lock is applicable for non skip tags
assertThat(distributionSetManagement.isImplicitLockApplicable(distributionSet)).isTrue();
assertThat(distributionSetManagement.shouldLockImplicitly(distributionSet)).isTrue();
assertThat(repositoryProperties.getSkipImplicitLockForTags().size()).isNotZero();
final List<? extends DistributionSetTag> skipTags = distributionSetTagManagement.create(
@@ -750,7 +711,7 @@ class DistributionSetManagementTest extends AbstractJpaIntegrationTest {
distributionSetManagement.assignTag(List.of(distributionSetWithSkipTag.getId()), skipTag.getId());
distributionSetWithSkipTag = distributionSetManagement.get(distributionSetWithSkipTag.getId()).orElseThrow();
// assert that implicit lock isn't applicable for skip tags
assertThat(distributionSetManagement.isImplicitLockApplicable(distributionSetWithSkipTag)).isFalse();
assertThat(distributionSetManagement.shouldLockImplicitly(distributionSetWithSkipTag)).isFalse();
});
}
@@ -759,12 +720,12 @@ class DistributionSetManagementTest extends AbstractJpaIntegrationTest {
*/
@Test
void lockIncompleteDistributionSetFails() {
final long incompleteDistributionSetId = testdataFactory.createIncompleteDistributionSet().getId();
final DistributionSet incompleteDistributionSet = testdataFactory.createIncompleteDistributionSet();
assertThatExceptionOfType(IncompleteDistributionSetException.class)
.as("Locking an incomplete distribution set should throw an exception")
.isThrownBy(() -> distributionSetManagement.lock(incompleteDistributionSetId));
.isThrownBy(() -> distributionSetManagement.lock(incompleteDistributionSet));
assertThat(
distributionSetManagement.get(incompleteDistributionSetId).map(DistributionSet::isLocked).orElse(true))
distributionSetManagement.get(incompleteDistributionSet.getId()).map(DistributionSet::isLocked).orElse(true))
.isFalse();
}
@@ -781,7 +742,6 @@ class DistributionSetManagementTest extends AbstractJpaIntegrationTest {
distributionSetManagement.delete(ds1.getId());
// not assigned so not marked as deleted but fully deleted
assertThat(distributionSetRepository.findAll()).hasSize(1);
assertThat(distributionSetManagement.findByCompleted(true, PAGE)).hasSize(1);
}
/**
@@ -851,7 +811,6 @@ class DistributionSetManagementTest extends AbstractJpaIntegrationTest {
// not assigned so not marked as deleted
assertThat(distributionSetRepository.findAll()).hasSize(4);
assertThat(distributionSetManagement.findByCompleted(true, PAGE)).hasSize(2);
assertThat(distributionSetManagement.findAll(PAGE)).hasSize(2);
assertThat(distributionSetManagement.findByRsql("name==*", PAGE)).hasSize(2);
assertThat(distributionSetManagement.count()).isEqualTo(2);
@@ -887,10 +846,6 @@ class DistributionSetManagementTest extends AbstractJpaIntegrationTest {
@Test
void verifyGetValid() {
final Long distributionSetId = testdataFactory.createAndInvalidateDistributionSet().getId();
assertThatExceptionOfType(InvalidDistributionSetException.class)
.as("Invalid distributionSet should throw an exception")
.isThrownBy(() -> distributionSetManagement.getValid(distributionSetId));
assertThatExceptionOfType(InvalidDistributionSetException.class)
.as("Invalid distributionSet should throw an exception")
.isThrownBy(() -> distributionSetManagement.getValidAndComplete(distributionSetId));
@@ -1098,7 +1053,6 @@ class DistributionSetManagementTest extends AbstractJpaIntegrationTest {
}
private void validateDeleted(final DistributionSet deletedDistributionSet, final int notDeletedSize) {
assertThatFilterContainsOnlyGivenDistributionSets(DistributionSetFilter.builder().isDeleted(Boolean.TRUE),
singletonList(deletedDistributionSet));
@@ -1107,7 +1061,6 @@ class DistributionSetManagementTest extends AbstractJpaIntegrationTest {
}
private void validateCompleted(final DistributionSet dsIncomplete, final int completedSize) {
assertThatFilterHasSizeAndDoesNotContainDistributionSet(
DistributionSetFilter.builder().isComplete(Boolean.TRUE), completedSize, dsIncomplete);
@@ -1115,8 +1068,7 @@ class DistributionSetManagementTest extends AbstractJpaIntegrationTest {
DistributionSetFilter.builder().isComplete(Boolean.FALSE), singletonList(dsIncomplete));
}
private void validateType(final DistributionSetType newType, final DistributionSet dsNewType,
final int standardDsTypeSize) {
private void validateType(final DistributionSetType newType, final DistributionSet dsNewType, final int standardDsTypeSize) {
assertThatFilterContainsOnlyGivenDistributionSets(DistributionSetFilter.builder().typeId(newType.getId()),
singletonList(dsNewType));
assertThatFilterHasSizeAndDoesNotContainDistributionSet(
@@ -1277,19 +1229,17 @@ class DistributionSetManagementTest extends AbstractJpaIntegrationTest {
private void assertThatFilterContainsOnlyGivenDistributionSets(final DistributionSetFilterBuilder filterBuilder,
final List<? extends DistributionSet> distributionSets) {
final int expectedDsSize = distributionSets.size();
assertThat(((DistributionSetManagement)distributionSetManagement).findByDistributionSetFilter(filterBuilder.build(), PAGE).getContent())
.hasSize(expectedDsSize).containsOnly(distributionSets.toArray(new DistributionSet[expectedDsSize]));
assertThat(findDsByDistributionSetFilter(filterBuilder.build(), PAGE).getContent())
.hasSize(expectedDsSize).containsOnly(distributionSets.toArray(new JpaDistributionSet[expectedDsSize]));
}
private void assertThatFilterDoesNotContainAnyDistributionSet(final DistributionSetFilterBuilder filterBuilder) {
assertThat(distributionSetManagement.findByDistributionSetFilter(filterBuilder.build(), PAGE).getContent())
.isEmpty();
assertThat(findDsByDistributionSetFilter(filterBuilder.build(), PAGE).getContent()).isEmpty();
}
private void assertThatFilterHasSizeAndDoesNotContainDistributionSet(
final DistributionSetFilterBuilder filterBuilder, final int size, final DistributionSet ds) {
assertThat(((DistributionSetManagement)distributionSetManagement).findByDistributionSetFilter(filterBuilder.build(), PAGE).getContent())
.hasSize(size).doesNotContain(ds);
assertThat((List)findDsByDistributionSetFilter(filterBuilder.build(), PAGE).getContent()).hasSize(size).doesNotContain(ds);
}
// can be removed with java-11

View File

@@ -41,32 +41,4 @@ class DistributionSetTagManagementSecurityTest
protected DistributionSetTagManagement.Update getUpdateObject() {
return DistributionSetTagManagement.Update.builder().id(1L).name("tag").build();
}
/**
* Tests ManagementAPI PreAuthorized method with correct and insufficient permissions.
*/
@Test
void getByNameWitPermissionWorks() {
assertPermissions(() -> distributionSetTagManagement.findByName("tagName"), List.of(SpPermission.READ_REPOSITORY));
}
/**
* Tests ManagementAPI PreAuthorized method with correct and insufficient permissions.
*/
@Test
void findByDistributionSetPermissionsCheck() {
assertPermissions(() -> distributionSetTagManagement.findByDistributionSet(1L, Pageable.unpaged()),
List.of(SpPermission.READ_REPOSITORY));
}
/**
* Tests ManagementAPI PreAuthorized method with correct and insufficient permissions.
*/
@Test
void deleteDistributionSetTagPermissionsCheck() {
assertPermissions(() -> {
distributionSetTagManagement.delete("tagName");
return null;
}, List.of(SpPermission.DELETE_REPOSITORY));
}
}

View File

@@ -45,15 +45,12 @@ import org.springframework.data.domain.Pageable;
*/
class DistributionSetTagManagementTest extends AbstractJpaIntegrationTest {
private static final Random RND = new Random();
/**
* Verifies that management get access reacts as specified on calls for non existing entities by means of Optional not present.
*/
@Test
@ExpectEvents({ @Expect(type = TargetCreatedEvent.class, count = 0) })
void nonExistingEntityAccessReturnsNotPresent() {
assertThat(distributionSetTagManagement.findByName(NOT_EXIST_ID)).isNotPresent();
assertThat(distributionSetTagManagement.get(NOT_EXIST_IDL)).isNotPresent();
}
@@ -66,8 +63,7 @@ class DistributionSetTagManagementTest extends AbstractJpaIntegrationTest {
@Expect(type = DistributionSetTagUpdatedEvent.class, count = 0),
@Expect(type = TargetTagUpdatedEvent.class, count = 0) })
void entityQueriesReferringToNotExistingEntitiesThrowsException() {
verifyThrownExceptionBy(() -> distributionSetTagManagement.delete(NOT_EXIST_ID), "DistributionSetTag");
verifyThrownExceptionBy(() -> distributionSetTagManagement.findByDistributionSet(NOT_EXIST_IDL, PAGE), "DistributionSet");
verifyThrownExceptionBy(() -> distributionSetTagManagement.delete(NOT_EXIST_IDL), "DistributionSetTag");
verifyThrownExceptionBy(() -> distributionSetTagManagement.update(
DistributionSetTagManagement.Update.builder().id(NOT_EXIST_IDL).build()), "DistributionSetTag");
}
@@ -95,18 +91,18 @@ class DistributionSetTagManagementTest extends AbstractJpaIntegrationTest {
assignTag(dsBs, tagB);
assignTag(dsCs, tagC);
assignTag(dsABs, distributionSetTagManagement.findByName(tagA.getName()).get());
assignTag(dsABs, distributionSetTagManagement.findByName(tagB.getName()).get());
assignTag(dsABs, distributionSetTagManagement.get(tagA.getId()).orElseThrow());
assignTag(dsABs, distributionSetTagManagement.get(tagB.getId()).orElseThrow());
assignTag(dsACs, distributionSetTagManagement.findByName(tagA.getName()).get());
assignTag(dsACs, distributionSetTagManagement.findByName(tagC.getName()).get());
assignTag(dsACs, distributionSetTagManagement.get(tagA.getId()).orElseThrow());
assignTag(dsACs, distributionSetTagManagement.get(tagC.getId()).orElseThrow());
assignTag(dsBCs, distributionSetTagManagement.findByName(tagB.getName()).get());
assignTag(dsBCs, distributionSetTagManagement.findByName(tagC.getName()).get());
assignTag(dsBCs, distributionSetTagManagement.get(tagB.getId()).orElseThrow());
assignTag(dsBCs, distributionSetTagManagement.get(tagC.getId()).orElseThrow());
assignTag(dsABCs, distributionSetTagManagement.findByName(tagA.getName()).get());
assignTag(dsABCs, distributionSetTagManagement.findByName(tagB.getName()).get());
assignTag(dsABCs, distributionSetTagManagement.findByName(tagC.getName()).get());
assignTag(dsABCs, distributionSetTagManagement.get(tagA.getId()).orElseThrow());
assignTag(dsABCs, distributionSetTagManagement.get(tagB.getId()).orElseThrow());
assignTag(dsABCs, distributionSetTagManagement.get(tagC.getId()).orElseThrow());
// search for not deleted
final DistributionSetFilter.DistributionSetFilterBuilder distributionSetFilterBuilder = getDistributionSetFilterBuilder()
@@ -121,11 +117,11 @@ class DistributionSetTagManagementTest extends AbstractJpaIntegrationTest {
Stream.empty());
assertThat(distributionSetTagRepository.findAll()).hasSize(5);
distributionSetTagManagement.delete(tagY.getName());
distributionSetTagManagement.delete(tagY.getId());
assertThat(distributionSetTagRepository.findAll()).hasSize(4);
distributionSetTagManagement.delete(tagX.getName());
distributionSetTagManagement.delete(tagX.getId());
assertThat(distributionSetTagRepository.findAll()).hasSize(3);
distributionSetTagManagement.delete(tagB.getName());
distributionSetTagManagement.delete(tagB.getId());
assertThat(distributionSetTagRepository.findAll()).hasSize(2);
verifyExpectedFilteredDistributionSets(distributionSetFilterBuilder.tagNames(Arrays.asList(tagA.getName())),
@@ -217,11 +213,11 @@ class DistributionSetTagManagementTest extends AbstractJpaIntegrationTest {
final Tag tag = distributionSetTagManagement
.create(DistributionSetTagManagement.Create.builder().name("kai1").description("kai2").colour("colour").build());
assertThat(distributionSetTagRepository.findByNameEquals("kai1").get().getDescription()).as("wrong tag found")
assertThat(distributionSetTagRepository.findById(tag.getId()).orElseThrow().getDescription()).as("wrong tag found")
.isEqualTo("kai2");
assertThat(distributionSetTagManagement.findByName("kai1").get().getColour()).as("wrong tag found")
assertThat(distributionSetTagManagement.get(tag.getId()).orElseThrow().getColour()).as("wrong tag found")
.isEqualTo("colour");
assertThat(distributionSetTagManagement.get(tag.getId()).get().getColour()).as("wrong tag found")
assertThat(distributionSetTagManagement.get(tag.getId()).orElseThrow().getColour()).as("wrong tag found")
.isEqualTo("colour");
}
@@ -240,7 +236,7 @@ class DistributionSetTagManagementTest extends AbstractJpaIntegrationTest {
}
// delete
distributionSetTagManagement.delete(tags.iterator().next().getName());
distributionSetTagManagement.delete(tags.iterator().next().getId());
// check
assertThat(distributionSetTagRepository.findById(toDelete.getId())).as("Deleted tag should be null")
@@ -321,8 +317,7 @@ class DistributionSetTagManagementTest extends AbstractJpaIntegrationTest {
private void verifyExpectedFilteredDistributionSets(final DistributionSetFilter.DistributionSetFilterBuilder distributionSetFilterBuilder,
final Stream<Collection<DistributionSet>> expectedFilteredDistributionSets) {
final Collection<Long> retrievedFilteredDsIds = distributionSetManagement
.findByDistributionSetFilter(distributionSetFilterBuilder.build(), PAGE).stream()
final Collection<Long> retrievedFilteredDsIds = findDsByDistributionSetFilter(distributionSetFilterBuilder.build(), PAGE).stream()
.map(DistributionSet::getId).toList();
final Collection<Long> expectedFilteredDsIds = expectedFilteredDistributionSets.flatMap(Collection::stream)
.map(DistributionSet::getId).toList();

View File

@@ -1424,11 +1424,11 @@ class RolloutManagementTest extends AbstractJpaIntegrationTest {
* Verify the creation and the start of a rollout.
*/
@Test
void createScheduledRollout() throws Exception {
void createScheduledRollout() {
final String rolloutName = "scheduledRolloutTest";
testdataFactory.createTargets(50, rolloutName + "-", rolloutName);
final DistributionSet distributionSet = testdataFactory.createDistributionSet("dsFor" + rolloutName);
distributionSetManagement.lock(distributionSet.getId());
distributionSetManagement.lock(distributionSet);
final WithUser userWithoutHandleRollout = SecurityContextSwitch.withUser(
"user_without_handle_rollout",

View File

@@ -194,18 +194,16 @@ class SoftwareModuleManagementTest extends AbstractJpaIntegrationTest {
assertThat(softwareModuleManagement.findByTextAndType("oracle", runtimeType.getId(), PAGE).getContent())
.hasSize(1);
assertThat(
softwareModuleManagement.findByTextAndType("oracle", runtimeType.getId(), PAGE).getContent().get(0))
.isEqualTo(jvm);
softwareModuleManagement.findByTextAndType("oracle", runtimeType.getId(), PAGE).getContent().get(0)).isEqualTo(jvm);
assertThat(softwareModuleManagement.findByTextAndType(":1.0.1", appType.getId(), PAGE).getContent()).hasSize(1)
.first().isEqualTo(ah);
assertThat(softwareModuleManagement.findByTextAndType(":1.0", appType.getId(), PAGE).getContent()).hasSize(2);
distributionSetManagement.unlock(ds.getId()); // otherwise delete will be rejected as a part of a locked DS
distributionSetManagement.unlock(ds); // otherwise delete will be rejected as a part of a locked DS
softwareModuleManagement.delete(ah2.getId());
assertThat(softwareModuleManagement.findByTextAndType(":1.0", appType.getId(), PAGE).getContent()).hasSize(1);
assertThat(softwareModuleManagement.findByTextAndType(":1.0", appType.getId(), PAGE).getContent().get(0))
.isEqualTo(ah);
assertThat(softwareModuleManagement.findByTextAndType(":1.0", appType.getId(), PAGE).getContent().get(0)).isEqualTo(ah);
}
/**
@@ -429,16 +427,16 @@ class SoftwareModuleManagementTest extends AbstractJpaIntegrationTest {
final Artifact artifactY = moduleY.getArtifacts().iterator().next();
// [STEP3]: Assign SoftwareModuleX to DistributionSetX and to target
final DistributionSet disSetX = testdataFactory.createDistributionSet(Set.of(moduleX), "X");
assignDistributionSet(disSetX, Collections.singletonList(target));
final DistributionSet disSetX = assignDistributionSet(testdataFactory.createDistributionSet(Set.of(moduleX), "X"), List.of(target))
.getDistributionSet();
// [STEP4]: Assign SoftwareModuleY to DistributionSet and to target
final DistributionSet disSetY = testdataFactory.createDistributionSet(Set.of(moduleY), "Y");
assignDistributionSet(disSetY, Collections.singletonList(target));
final DistributionSet disSetY = assignDistributionSet(testdataFactory.createDistributionSet(Set.of(moduleY), "Y"), List.of(target))
.getDistributionSet();
// [STEP5]: Delete SoftwareModuleX
distributionSetManagement.unlock(disSetX.getId()); // otherwise delete will be rejected as a part of a locked DS
distributionSetManagement.unlock(disSetY.getId()); // otherwise delete will be rejected as a part of a locked DS
distributionSetManagement.unlock(disSetX); // otherwise delete will be rejected as a part of a locked DS
distributionSetManagement.unlock(disSetY); // otherwise delete will be rejected as a part of a locked DS
softwareModuleManagement.delete(moduleX.getId());
// [STEP6]: Delete SoftwareModuleY
@@ -757,10 +755,8 @@ class SoftwareModuleManagementTest extends AbstractJpaIntegrationTest {
// try to delete while DS is not locked
softwareModuleManagement.delete(modules.get(0).getId());
distributionSetManagement.lock(distributionSet.getId());
assertThat(
distributionSetManagement.get(distributionSet.getId()).map(DistributionSet::isLocked).orElse(false))
.isTrue();
distributionSetManagement.lock(distributionSet);
assertThat(distributionSetManagement.get(distributionSet.getId()).map(DistributionSet::isLocked).orElse(false)).isTrue();
// try to delete SM of a locked DS
final Long moduleId = modules.get(1).getId();
@@ -772,7 +768,7 @@ class SoftwareModuleManagementTest extends AbstractJpaIntegrationTest {
private Action assignSet(final JpaTarget target, final JpaDistributionSet ds) {
assignDistributionSet(ds.getId(), target.getControllerId());
implicitLock(ds);
assertThat(targetManagement.getByControllerID(target.getControllerId()).get().getUpdateStatus())
assertThat(targetManagement.getByControllerID(target.getControllerId()).orElseThrow().getUpdateStatus())
.isEqualTo(TargetUpdateStatus.PENDING);
final Optional<DistributionSet> assignedDistributionSet = deploymentManagement
.getAssignedDistributionSet(target.getControllerId());

View File

@@ -28,9 +28,8 @@ import org.junit.jupiter.api.extension.ExtendWith;
import org.springframework.data.domain.Slice;
/**
* Multi-Tenancy tests which testing the CRUD operations of entities that all
* CRUD-Operations are tenant aware and cannot access or delete entities not
* belonging to the current tenant.
* Multi-Tenancy tests which testing the CRUD operations of entities that all CRUD-Operations are tenant aware and cannot access
* or delete entities not belonging to the current tenant.
* <p/>
* Feature: Component Tests - Repository<br/>
* Story: Multi Tenancy
@@ -201,6 +200,6 @@ class MultiTenancyEntityTest extends AbstractJpaIntegrationTest {
}
private Slice<? extends DistributionSet> findDistributionSetForTenant(final String tenant) throws Exception {
return runAsTenant(tenant, () -> distributionSetManagement.findByCompleted(true, PAGE));
return runAsTenant(tenant, () -> distributionSetManagement.findAll(PAGE));
}
}