Add SM and SM type ACM tests (#2734)
Signed-off-by: Avgustin Marinov <Avgustin.Marinov@bosch.com>
This commit is contained in:
@@ -22,8 +22,8 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.assertj.core.api.Assertions;
|
||||
import org.eclipse.hawkbit.repository.DistributionSetManagement;
|
||||
import org.eclipse.hawkbit.repository.DistributionSetManagement.Create;
|
||||
import org.eclipse.hawkbit.repository.DistributionSetManagement.Update;
|
||||
import org.eclipse.hawkbit.repository.Identifiable;
|
||||
import org.eclipse.hawkbit.repository.exception.EntityNotFoundException;
|
||||
import org.eclipse.hawkbit.repository.exception.InsufficientPermissionException;
|
||||
@@ -59,18 +59,16 @@ class DistributionSetManagementTest extends AbstractAccessControllerTest {
|
||||
void verifyRead() {
|
||||
// permissions to read only type1 ds
|
||||
runAs(withAuthorities(READ_DISTRIBUTION_SET + "/type.id==" + dsType1.getId()), () -> {
|
||||
Assertions.<DistributionSet> assertThat(distributionSetManagement.findAll(UNPAGED)).hasSize(1).containsExactlyInAnyOrder(ds1Type1);
|
||||
Assertions.<DistributionSet> assertThat(distributionSetManagement.findAll(UNPAGED)).containsExactlyInAnyOrder(ds1Type1);
|
||||
assertThat(distributionSetManagement.count()).isEqualTo(1);
|
||||
|
||||
Assertions.<DistributionSet> assertThat(distributionSetManagement.findByRsql("name==*", UNPAGED)).hasSize(1).hasSize(1)
|
||||
.containsExactly(ds1Type1);
|
||||
Assertions.<DistributionSet> assertThat(distributionSetManagement.findByRsql("name==*", UNPAGED)).containsExactly(ds1Type1);
|
||||
assertThat(distributionSetManagement.countByRsql("name==*")).isEqualTo(1);
|
||||
|
||||
Assertions.<DistributionSet> assertThat(distributionSetManagement.findByTag(dsTag1.getId(), UNPAGED)).hasSize(1)
|
||||
.containsExactly(ds1Type1);
|
||||
Assertions.<DistributionSet> assertThat(distributionSetManagement.findByTag(dsTag1.getId(), UNPAGED)).containsExactly(ds1Type1);
|
||||
assertThat(distributionSetManagement.findByTag(dsTag2.getId(), UNPAGED)).isEmpty();
|
||||
|
||||
Assertions.<DistributionSet> assertThat(distributionSetManagement.findByRsqlAndTag("name==*", dsTag1.getId(), UNPAGED)).hasSize(1)
|
||||
Assertions.<DistributionSet> assertThat(distributionSetManagement.findByRsqlAndTag("name==*", dsTag1.getId(), UNPAGED))
|
||||
.containsExactly(ds1Type1);
|
||||
assertThat(distributionSetManagement.findByRsqlAndTag("name==*", dsTag2.getId(), UNPAGED)).isEmpty();
|
||||
|
||||
@@ -84,7 +82,7 @@ class DistributionSetManagementTest extends AbstractAccessControllerTest {
|
||||
assertThatThrownBy(() -> distributionSetManagement.getWithDetails(ds2Type2Id)).isInstanceOf(EntityNotFoundException.class);
|
||||
assertThat(distributionSetManagement.find(ds2Type2Id)).isEmpty();
|
||||
|
||||
Assertions.<DistributionSet> assertThat(distributionSetManagement.get(List.of(ds1Type1Id))).hasSize(1).contains(ds1Type1);
|
||||
Assertions.<DistributionSet> assertThat(distributionSetManagement.get(List.of(ds1Type1Id))).contains(ds1Type1);
|
||||
final List<Long> noPermissionsTestDataDsIdList = List.of(ds2Type2Id);
|
||||
assertThatThrownBy(() -> distributionSetManagement.get(noPermissionsTestDataDsIdList)).isInstanceOf(EntityNotFoundException.class);
|
||||
final List<Long> containingNoPermissionTestDataDsIsList = List.of(ds1Type1Id, ds2Type2Id);
|
||||
@@ -144,10 +142,8 @@ class DistributionSetManagementTest extends AbstractAccessControllerTest {
|
||||
assertThatThrownBy(() -> distributionSetManagement.deleteMetadata(ds2Type2Id, ds2MdKey))
|
||||
.isInstanceOf(InsufficientPermissionException.class);
|
||||
|
||||
final DistributionSetManagement.Update distributionSet1Update = DistributionSetManagement.Update.builder()
|
||||
.id(ds1Type1.getId()).description(randomString(16)).build();
|
||||
final DistributionSetManagement.Update distributionSet2Update = DistributionSetManagement.Update.builder()
|
||||
.id(ds2Type2Id).description(randomString(16)).build();
|
||||
final Update distributionSet1Update = Update.builder().id(ds1Type1.getId()).description(randomString(16)).build();
|
||||
final Update distributionSet2Update = Update.builder().id(ds2Type2Id).description(randomString(16)).build();
|
||||
DistributionSet ds1Type1 = distributionSetManagement.update(distributionSet1Update);
|
||||
assertThat(ds1Type1).extracting(NamedEntity::getDescription).isEqualTo(distributionSet1Update.getDescription());
|
||||
assertThatThrownBy(() -> distributionSetManagement.update(distributionSet2Update))
|
||||
@@ -176,27 +172,4 @@ class DistributionSetManagementTest extends AbstractAccessControllerTest {
|
||||
assertThatThrownBy(() -> distributionSetManagement.invalidate(ds2Type2)).isInstanceOf(InsufficientPermissionException.class);
|
||||
});
|
||||
}
|
||||
//
|
||||
// private TestData createCompleteDistributionSetWithNewType() {
|
||||
// // create type
|
||||
// final DistributionSetType distributionSetType = testdataFactory.findOrCreateDistributionSetType(randomString(16), randomString(16),
|
||||
// List.of(osType), List.of(appType));
|
||||
//
|
||||
// final DistributionSetTag distributionSetTag = distributionSetTagManagement.create(
|
||||
// DistributionSetTagManagement.Create.builder().name(randomString(16)).build());
|
||||
//
|
||||
// final SoftwareModule moduleOs = testdataFactory.createSoftwareModuleOs();
|
||||
//
|
||||
// final Long distributionSetId = distributionSetManagement.create(
|
||||
// Create.builder().type(distributionSetType).name(randomString(16)).version("1.0")
|
||||
// .modules(Set.of(moduleOs)).build()).getId();
|
||||
//
|
||||
// final DistributionSetAssignmentResult assignmentResult = assignDistributionSet(distributionSetId, createTarget().getControllerId());
|
||||
// assertThat(assignmentResult.getAssignedEntity()).hasSize(1);
|
||||
//
|
||||
// return new TestData(distributionSetType,
|
||||
// distributionSetManagement.assignTag(Collections.singletonList(distributionSetId), distributionSetTag.getId()).get(0),
|
||||
// distributionSetTag, assignmentResult.getAssignedEntity().get(0));
|
||||
// }
|
||||
|
||||
}
|
||||
@@ -48,11 +48,11 @@ class DistributionSetTypeManagementTest extends AbstractAccessControllerTest {
|
||||
runAs(withAuthorities(READ_PREFIX + DISTRIBUTION_SET_TYPE + "/id==" + dsType1.getId()), () -> {
|
||||
// perform distributionSetTypeManagement#findAll and verify
|
||||
Assertions.<DistributionSetType> assertThat(distributionSetTypeManagement.findAll(UNPAGED))
|
||||
.hasSize(1).containsExactly(dsType1);
|
||||
.containsExactly(dsType1);
|
||||
assertThat(distributionSetTypeManagement.count()).isEqualTo(1);
|
||||
|
||||
Assertions.<DistributionSetType> assertThat(distributionSetTypeManagement.findByRsql("name==*", UNPAGED))
|
||||
.hasSize(1).containsExactly(dsType1);
|
||||
.containsExactly(dsType1);
|
||||
assertThat(distributionSetTypeManagement.countByRsql("name==*")).isEqualTo(1);
|
||||
|
||||
assertThat(distributionSetTypeManagement.exists(dsType1.getId())).isTrue();
|
||||
@@ -62,7 +62,7 @@ class DistributionSetTypeManagementTest extends AbstractAccessControllerTest {
|
||||
assertThat(distributionSetTypeManagement.find(dsType2.getId())).isEmpty();
|
||||
|
||||
Assertions.<DistributionSetType> assertThat(distributionSetTypeManagement.get(List.of(dsType1.getId())))
|
||||
.hasSize(1).contains(dsType1);
|
||||
.containsExactly(dsType1);
|
||||
final List<Long> noPermissionIdList = List.of(dsType2.getId());
|
||||
assertThatExceptionOfType(EntityNotFoundException.class).isThrownBy(() -> distributionSetTypeManagement.get(noPermissionIdList));
|
||||
final List<Long> allPermissionsIdList = List.of(dsType1.getId(), dsType2.getId());
|
||||
@@ -125,8 +125,8 @@ class DistributionSetTypeManagementTest extends AbstractAccessControllerTest {
|
||||
// soft delete since dsType1 is assigned to ds1Type1
|
||||
assertThat(distributionSetTypeManagement.find(dsType1.getId())).hasValueSatisfying(DistributionSetType::isDeleted);
|
||||
|
||||
final Long ds2Type2Id = dsType2.getId();
|
||||
assertThatThrownBy(() -> distributionSetTypeManagement.delete(ds2Type2Id)).isInstanceOf(InsufficientPermissionException.class);
|
||||
final Long dsType2Id = dsType2.getId();
|
||||
assertThatThrownBy(() -> distributionSetTypeManagement.delete(dsType2Id)).isInstanceOf(InsufficientPermissionException.class);
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -40,7 +40,7 @@ class RolloutExecutionTest extends AbstractAccessControllerTest {
|
||||
}));
|
||||
}
|
||||
|
||||
void verify(final Runnable run) {
|
||||
private void verify(final Runnable run) {
|
||||
final Target[] expectedTargets = new Target[] { target1Type1 };
|
||||
runAs(withAuthorities(
|
||||
READ_TARGET, UPDATE_TARGET + "/type.id==" + targetType1.getId(),
|
||||
|
||||
@@ -32,19 +32,17 @@ class RolloutManagementTest extends AbstractAccessControllerTest {
|
||||
rolloutManagement.start(rollout.getId());
|
||||
rolloutHandler.handleAll();
|
||||
|
||||
runAs(withAuthorities(READ_TARGET + "/type.id==" + targetType1.getId(), READ_ROLLOUT),
|
||||
() -> {
|
||||
assertThat(targetManagement.findAll(UNPAGED).stream().map(Identifiable::getId).toList())
|
||||
.as("Only readable targets should be returned")
|
||||
.containsExactly(target1Type1.getId());
|
||||
assertThat(rolloutManagement.getWithDetailedStatus(rollout.getId())).satisfies(rolloutWithDetails -> {
|
||||
assertThat(rolloutWithDetails.getTotalTargets()).as("All targets shall be returned").isEqualTo(3);
|
||||
assertThat(rolloutWithDetails.getRolloutGroupsCreated()).isEqualTo(rollout.getRolloutGroupsCreated());
|
||||
assertThat(rolloutWithDetails.getTotalTargetCountStatus().getFinishedPercent()).isZero();
|
||||
assertThat(rolloutWithDetails.getTotalTargetCountStatus().getTotalTargetCountByStatus(RUNNING)).isEqualTo(1);
|
||||
assertThat(rolloutWithDetails.getTotalTargetCountStatus().getTotalTargetCountByStatus(SCHEDULED)).isEqualTo(2);
|
||||
assertThat(rolloutWithDetails.getTotalTargetCountStatus().getTotalTargetCountByStatus(NOTSTARTED)).isZero();
|
||||
});
|
||||
});
|
||||
runAs(withAuthorities(READ_TARGET + "/type.id==" + targetType1.getId(), READ_ROLLOUT), () -> {
|
||||
assertThat(targetManagement.findAll(UNPAGED).stream().map(Identifiable::getId).toList())
|
||||
.as("Only readable targets should be returned").containsExactly(target1Type1.getId());
|
||||
assertThat(rolloutManagement.getWithDetailedStatus(rollout.getId())).satisfies(rolloutWithDetails -> {
|
||||
assertThat(rolloutWithDetails.getTotalTargets()).as("All targets shall be returned").isEqualTo(3);
|
||||
assertThat(rolloutWithDetails.getRolloutGroupsCreated()).isEqualTo(rollout.getRolloutGroupsCreated());
|
||||
assertThat(rolloutWithDetails.getTotalTargetCountStatus().getFinishedPercent()).isZero();
|
||||
assertThat(rolloutWithDetails.getTotalTargetCountStatus().getTotalTargetCountByStatus(RUNNING)).isEqualTo(1);
|
||||
assertThat(rolloutWithDetails.getTotalTargetCountStatus().getTotalTargetCountByStatus(SCHEDULED)).isEqualTo(2);
|
||||
assertThat(rolloutWithDetails.getTotalTargetCountStatus().getTotalTargetCountByStatus(NOTSTARTED)).isZero();
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,80 @@
|
||||
/**
|
||||
* Copyright (c) 2025 Contributors to the Eclipse Foundation
|
||||
*
|
||||
* This program and the accompanying materials are made
|
||||
* available under the terms of the Eclipse Public License 2.0
|
||||
* which is available at https://www.eclipse.org/legal/epl-2.0/
|
||||
*
|
||||
* SPDX-License-Identifier: EPL-2.0
|
||||
*/
|
||||
package org.eclipse.hawkbit.repository.jpa.acm;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||
import static org.assertj.core.api.Assertions.assertThatThrownBy;
|
||||
import static org.eclipse.hawkbit.im.authentication.SpPermission.READ_PREFIX;
|
||||
import static org.eclipse.hawkbit.im.authentication.SpPermission.SOFTWARE_MODULE;
|
||||
import static org.eclipse.hawkbit.im.authentication.SpPermission.UPDATE_PREFIX;
|
||||
import static org.eclipse.hawkbit.repository.test.util.SecurityContextSwitch.runAs;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import org.assertj.core.api.Assertions;
|
||||
import org.eclipse.hawkbit.repository.exception.EntityNotFoundException;
|
||||
import org.eclipse.hawkbit.repository.exception.InsufficientPermissionException;
|
||||
import org.eclipse.hawkbit.repository.model.SoftwareModule;
|
||||
import org.eclipse.hawkbit.repository.model.SoftwareModule.MetadataValueCreate;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
class SoftwareModuleManagementTest extends AbstractAccessControllerTest {
|
||||
|
||||
@Test
|
||||
void verifyRead() {
|
||||
runAs(withAuthorities(READ_PREFIX + SOFTWARE_MODULE + "/type.id==" + smType1.getId()), () -> {
|
||||
Assertions.<SoftwareModule> assertThat(softwareModuleManagement.findAll(UNPAGED)).containsExactly(sm1Type1);
|
||||
assertThat(softwareModuleManagement.count()).isEqualTo(1);
|
||||
|
||||
Assertions.<SoftwareModule> assertThat(softwareModuleManagement.findByRsql("name==*", UNPAGED)).containsExactly(sm1Type1);
|
||||
Assertions.assertThat(softwareModuleManagement.countByRsql("name==*")).isEqualTo(1);
|
||||
|
||||
final Long sm2Type2Id = sm2Type2.getId();
|
||||
Assertions.<SoftwareModule> assertThat(softwareModuleManagement.findByAssignedTo(sm2Type2Id, UNPAGED).toList())
|
||||
.containsExactly(sm1Type1); // no sm2Type2
|
||||
|
||||
assertThat(softwareModuleManagement.getMetadata(sm1Type1.getId())).isEmpty();
|
||||
assertThatExceptionOfType(EntityNotFoundException.class).isThrownBy(() -> softwareModuleManagement.getMetadata(sm2Type2Id));
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
void verifyUpdate() {
|
||||
runAs(withAuthorities(READ_PREFIX + SOFTWARE_MODULE, UPDATE_PREFIX + SOFTWARE_MODULE + "/type.id==" + smType1.getId()), () -> {
|
||||
final String metadataKey = "key.dot";
|
||||
final MetadataValueCreate metaDataCreate = new MetadataValueCreate(randomString(16), true);
|
||||
|
||||
final Long sm1Type1Id = sm1Type1.getId();
|
||||
softwareModuleManagement.createMetadata(sm1Type1Id, metadataKey, metaDataCreate);
|
||||
assertThat(softwareModuleManagement.getMetadata(sm1Type1Id, metadataKey))
|
||||
.satisfies(createdMetadata -> assertTrue(createdMetadata.isTargetVisible()));
|
||||
assertThat(softwareModuleManagement.getMetadata(sm1Type1Id)).hasSize(1);
|
||||
final Long sm2Type2Id = sm2Type2.getId();
|
||||
assertThatThrownBy(() -> softwareModuleManagement.createMetadata(sm2Type2Id, metadataKey, metaDataCreate))
|
||||
.isInstanceOf(InsufficientPermissionException.class);
|
||||
final Map<String, MetadataValueCreate> metaDataCreateMap = Map.of(metadataKey, metaDataCreate);
|
||||
assertThatThrownBy(() -> softwareModuleManagement.createMetadata(sm2Type2Id, metaDataCreateMap))
|
||||
.isInstanceOf(InsufficientPermissionException.class);
|
||||
|
||||
final MetadataValueCreate metadataUpdate = new MetadataValueCreate(randomString(16));
|
||||
softwareModuleManagement.createMetadata(sm1Type1Id, metadataKey, metadataUpdate);
|
||||
assertThat(softwareModuleManagement.getMetadata(sm1Type1Id, metadataKey))
|
||||
.satisfies(updatedMetadata -> assertFalse(updatedMetadata.isTargetVisible()));
|
||||
softwareModuleManagement.deleteMetadata(sm1Type1Id, metadataKey);
|
||||
assertThatThrownBy(() -> softwareModuleManagement.createMetadata(sm2Type2Id, metadataKey, metadataUpdate))
|
||||
.isInstanceOf(InsufficientPermissionException.class);
|
||||
assertThatThrownBy(() -> softwareModuleManagement.deleteMetadata(sm2Type2Id, metadataKey))
|
||||
.isInstanceOf(EntityNotFoundException.class);
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,102 @@
|
||||
/**
|
||||
* Copyright (c) 2025 Contributors to the Eclipse Foundation
|
||||
*
|
||||
* This program and the accompanying materials are made
|
||||
* available under the terms of the Eclipse Public License 2.0
|
||||
* which is available at https://www.eclipse.org/legal/epl-2.0/
|
||||
*
|
||||
* SPDX-License-Identifier: EPL-2.0
|
||||
*/
|
||||
package org.eclipse.hawkbit.repository.jpa.acm;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||
import static org.assertj.core.api.Assertions.assertThatThrownBy;
|
||||
import static org.eclipse.hawkbit.im.authentication.SpPermission.CREATE_PREFIX;
|
||||
import static org.eclipse.hawkbit.im.authentication.SpPermission.DELETE_PREFIX;
|
||||
import static org.eclipse.hawkbit.im.authentication.SpPermission.READ_PREFIX;
|
||||
import static org.eclipse.hawkbit.im.authentication.SpPermission.SOFTWARE_MODULE_TYPE;
|
||||
import static org.eclipse.hawkbit.im.authentication.SpPermission.UPDATE_PREFIX;
|
||||
import static org.eclipse.hawkbit.repository.test.util.SecurityContextSwitch.runAs;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.assertj.core.api.Assertions;
|
||||
import org.eclipse.hawkbit.repository.SoftwareModuleTypeManagement.Update;
|
||||
import org.eclipse.hawkbit.repository.exception.EntityNotFoundException;
|
||||
import org.eclipse.hawkbit.repository.exception.InsufficientPermissionException;
|
||||
import org.eclipse.hawkbit.repository.model.NamedEntity;
|
||||
import org.eclipse.hawkbit.repository.model.SoftwareModuleType;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
class SoftwareModuleTypeManagementTest extends AbstractAccessControllerTest {
|
||||
|
||||
@Test
|
||||
void verifyCreate() {
|
||||
// permissions to read only type1 sm types and create new type with name 'permitted'
|
||||
runAs(withAuthorities(READ_PREFIX + SOFTWARE_MODULE_TYPE, CREATE_PREFIX + SOFTWARE_MODULE_TYPE + "/key==permitted"), () -> {
|
||||
assertThat(testdataFactory.findOrCreateSoftwareModuleType("permitted")).isNotNull();
|
||||
assertThatThrownBy(() -> testdataFactory.findOrCreateSoftwareModuleType("not_permitted_2"))
|
||||
.isInstanceOf(InsufficientPermissionException.class);
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
void verifyRead() {
|
||||
// permissions to read only type1 sm types
|
||||
runAs(withAuthorities(READ_PREFIX + SOFTWARE_MODULE_TYPE + "/id==" + smType1.getId()), () -> {
|
||||
Assertions.<SoftwareModuleType> assertThat(softwareModuleTypeManagement.findAll(UNPAGED)).containsExactly(smType1);
|
||||
assertThat(softwareModuleTypeManagement.count()).isEqualTo(1);
|
||||
|
||||
Assertions.<SoftwareModuleType> assertThat(softwareModuleTypeManagement.findByRsql("name==*", UNPAGED)).containsExactly(smType1);
|
||||
assertThat(softwareModuleTypeManagement.countByRsql("name==*")).isEqualTo(1);
|
||||
|
||||
assertThat(softwareModuleTypeManagement.exists(smType1.getId())).isTrue();
|
||||
assertThat(softwareModuleTypeManagement.exists(smType2.getId())).isFalse();
|
||||
|
||||
assertThat(softwareModuleTypeManagement.find(smType1.getId()).map(SoftwareModuleType.class::cast)).hasValue(smType1);
|
||||
assertThat(softwareModuleTypeManagement.find(smType2.getId())).isEmpty();
|
||||
|
||||
Assertions.<SoftwareModuleType> assertThat(softwareModuleTypeManagement.get(List.of(smType1.getId()))).containsExactly(smType1);
|
||||
|
||||
final List<Long> noPermissionIdList = List.of(smType2.getId());
|
||||
assertThatExceptionOfType(EntityNotFoundException.class).isThrownBy(() -> softwareModuleTypeManagement.get(noPermissionIdList));
|
||||
final List<Long> allPermissionsIdList = List.of(smType1.getId(), smType2.getId());
|
||||
assertThatExceptionOfType(EntityNotFoundException.class).isThrownBy(() -> softwareModuleTypeManagement.get(allPermissionsIdList));
|
||||
|
||||
assertThat(softwareModuleTypeManagement.findByKey(smType1.getKey()).map(SoftwareModuleType.class::cast)).hasValue(smType1);
|
||||
final String noPermissionsTypeKey = smType2.getKey();
|
||||
assertThatThrownBy(() -> softwareModuleTypeManagement.findByKey(noPermissionsTypeKey))
|
||||
.isInstanceOf(InsufficientPermissionException.class);
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
void verifyUpdate() {
|
||||
// permissions to read only type1 sm types
|
||||
runAs(withAuthorities(READ_PREFIX + SOFTWARE_MODULE_TYPE, UPDATE_PREFIX + SOFTWARE_MODULE_TYPE + "/id==" + smType1.getId()), () -> {
|
||||
final String newDescription = randomString(16);
|
||||
assertThat(softwareModuleTypeManagement.update(Update.builder().id(smType1.getId()).description(newDescription).build()))
|
||||
.extracting(NamedEntity::getDescription)
|
||||
.isEqualTo(newDescription);
|
||||
|
||||
final Update descriptionUpdate = Update.builder().id(smType2.getId()).description(newDescription).build();
|
||||
assertThatThrownBy(() -> softwareModuleTypeManagement.update(descriptionUpdate))
|
||||
.isInstanceOf(InsufficientPermissionException.class);
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
void verifyDelete() {
|
||||
// permissions to read all and update only type1 sm types
|
||||
runAs(withAuthorities(READ_PREFIX + SOFTWARE_MODULE_TYPE, DELETE_PREFIX + SOFTWARE_MODULE_TYPE + "/id==" + smType1.getId()), () -> {
|
||||
assertThat(softwareModuleTypeManagement.find(smType1.getId())).isPresent();
|
||||
softwareModuleTypeManagement.delete(smType1.getId());
|
||||
// soft delete since smType1 is assigned to sm1Type1
|
||||
assertThat(softwareModuleTypeManagement.find(smType1.getId())).hasValueSatisfying(SoftwareModuleType::isDeleted);
|
||||
|
||||
final Long smType2Id = smType2.getId();
|
||||
assertThatThrownBy(() -> distributionSetTypeManagement.delete(smType2Id)).isInstanceOf(InsufficientPermissionException.class);
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -69,11 +69,11 @@ class TargetAccessControllerTest extends AbstractJpaIntegrationTest {
|
||||
runAs(withUser("user", READ_TARGET + "/controllerId==" + permittedTarget.getControllerId()), () -> {
|
||||
// verify targetManagement#findAll
|
||||
assertThat(targetManagement.findAll(Pageable.unpaged()).get().map(Identifiable::getId).toList())
|
||||
.containsOnly(permittedTarget.getId());
|
||||
.containsExactly(permittedTarget.getId());
|
||||
|
||||
// verify targetManagement#findByRsql
|
||||
assertThat(targetManagement.findByRsql("id==*", Pageable.unpaged()).get().map(Identifiable::getId).toList())
|
||||
.containsOnly(permittedTarget.getId());
|
||||
.containsExactly(permittedTarget.getId());
|
||||
|
||||
// verify targetManagement#getByControllerID
|
||||
assertThat(targetManagement.getByControllerId(permittedTarget.getControllerId())).isNotNull();
|
||||
@@ -88,7 +88,7 @@ class TargetAccessControllerTest extends AbstractJpaIntegrationTest {
|
||||
// verify targetManagement#getByControllerId
|
||||
assertThat(targetManagement
|
||||
.findByControllerId(List.of(permittedTarget.getControllerId(), hiddenTargetControllerId))
|
||||
.stream().map(Identifiable::getId).toList()).containsOnly(permittedTarget.getId());
|
||||
.stream().map(Identifiable::getId).toList()).containsExactly(permittedTarget.getId());
|
||||
|
||||
// verify targetManagement#get
|
||||
assertThat(targetManagement.find(permittedTarget.getId())).isPresent();
|
||||
@@ -131,11 +131,11 @@ class TargetAccessControllerTest extends AbstractJpaIntegrationTest {
|
||||
// verify targetManagement#findByTag
|
||||
assertThat(
|
||||
targetManagement.findByTag(myTagId, Pageable.unpaged()).get().map(Identifiable::getId).toList())
|
||||
.containsOnly(permittedTarget.getId(), readOnlyTarget.getId());
|
||||
.containsExactlyInAnyOrder(permittedTarget.getId(), readOnlyTarget.getId());
|
||||
|
||||
// verify targetManagement#findByRsqlAndTag
|
||||
assertThat(targetManagement.findByRsqlAndTag("id==*", myTagId, Pageable.unpaged()).get()
|
||||
.map(Identifiable::getId).toList()).containsOnly(permittedTarget.getId(), readOnlyTarget.getId());
|
||||
.map(Identifiable::getId).toList()).containsExactlyInAnyOrder(permittedTarget.getId(), readOnlyTarget.getId());
|
||||
|
||||
// verify targetManagement#assignTag on permitted target
|
||||
assertThat(targetManagement.assignTag(Collections.singletonList(permittedTarget.getControllerId()), myTagId)).hasSize(1);
|
||||
|
||||
@@ -50,11 +50,11 @@ class TargetTypeAccessControllerTest extends AbstractJpaIntegrationTest {
|
||||
runAs(withUser("user", READ_TARGET_TYPE + "/id==" + permittedTargetType.getId()), () -> {
|
||||
// verify targetTypeManagement#findAll
|
||||
assertThat(targetTypeManagement.findAll(Pageable.unpaged()).get().map(Identifiable::getId).toList())
|
||||
.containsOnly(permittedTargetType.getId());
|
||||
.containsExactly(permittedTargetType.getId());
|
||||
|
||||
// verify targetTypeManagement#findByRsql
|
||||
assertThat(targetTypeManagement.findByRsql("name==*", Pageable.unpaged()).get().map(Identifiable::getId).toList())
|
||||
.containsOnly(permittedTargetType.getId());
|
||||
.containsExactly(permittedTargetType.getId());
|
||||
|
||||
// verify targetTypeManagement#count
|
||||
assertThat(targetTypeManagement.count()).isEqualTo(1);
|
||||
|
||||
Reference in New Issue
Block a user