JPA Refactoring (3) (#2109)
Signed-off-by: Avgustin Marinov <Avgustin.Marinov@bosch.com>
This commit is contained in:
@@ -21,7 +21,6 @@ import io.qameta.allure.Feature;
|
||||
import io.qameta.allure.Story;
|
||||
import org.eclipse.hawkbit.repository.FilterParams;
|
||||
import org.eclipse.hawkbit.repository.Identifiable;
|
||||
import org.eclipse.hawkbit.repository.exception.EntityNotFoundException;
|
||||
import org.eclipse.hawkbit.repository.exception.InsufficientPermissionException;
|
||||
import org.eclipse.hawkbit.repository.jpa.acm.AccessController;
|
||||
import org.eclipse.hawkbit.repository.jpa.autoassign.AutoAssignChecker;
|
||||
@@ -76,7 +75,9 @@ class TargetAccessControllerTest extends AbstractAccessControllerTest {
|
||||
|
||||
// verify targetManagement#getByControllerID
|
||||
assertThat(targetManagement.getByControllerID(permittedTarget.getControllerId())).isPresent();
|
||||
assertThat(targetManagement.getByControllerID(hiddenTarget.getControllerId())).isEmpty();
|
||||
assertThatThrownBy(() -> targetManagement.getByControllerID(hiddenTarget.getControllerId()))
|
||||
.as("Missing read permissions for hidden target.")
|
||||
.isInstanceOf(InsufficientPermissionException.class);
|
||||
|
||||
// verify targetManagement#getByControllerID
|
||||
assertThat(targetManagement
|
||||
@@ -95,7 +96,7 @@ class TargetAccessControllerTest extends AbstractAccessControllerTest {
|
||||
assertThat(targetManagement.getControllerAttributes(permittedTarget.getControllerId())).isEmpty();
|
||||
assertThatThrownBy(() -> {
|
||||
assertThat(targetManagement.getControllerAttributes(hiddenTarget.getControllerId())).isEmpty();
|
||||
}).as("Target should not be found.").isInstanceOf(EntityNotFoundException.class);
|
||||
}).as("Target should not be found.").isInstanceOf(InsufficientPermissionException.class);
|
||||
|
||||
final TargetFilterQuery targetFilterQuery = targetFilterQueryManagement
|
||||
.create(entityFactory.targetFilterQuery().create().name("test").query("id==*"));
|
||||
@@ -176,7 +177,7 @@ class TargetAccessControllerTest extends AbstractAccessControllerTest {
|
||||
assertThatThrownBy(() -> {
|
||||
targetManagement.assignTag(Collections.singletonList(readOnlyTarget.getControllerId()), myTag.getId());
|
||||
}).as("Missing update permissions for target to toggle tag assignment.")
|
||||
.isInstanceOfAny(InsufficientPermissionException.class, EntityNotFoundException.class);
|
||||
.isInstanceOfAny(InsufficientPermissionException.class);
|
||||
|
||||
// assignment is denied for readOnlyTarget (read, but no update permissions)
|
||||
assertThatThrownBy(() -> {
|
||||
@@ -190,19 +191,18 @@ class TargetAccessControllerTest extends AbstractAccessControllerTest {
|
||||
.assignTag(Collections.singletonList(hiddenTarget.getControllerId()), myTag.getId())
|
||||
.size();
|
||||
}).as("Missing update permissions for target to toggle tag assignment.")
|
||||
.isInstanceOf(EntityNotFoundException.class);
|
||||
.isInstanceOf(InsufficientPermissionException.class);
|
||||
|
||||
// assignment is denied for hiddenTarget since it's hidden
|
||||
assertThatThrownBy(() -> {
|
||||
targetManagement.assignTag(Collections.singletonList(hiddenTarget.getControllerId()), myTag.getId());
|
||||
}).as("Missing update permissions for target to toggle tag assignment.")
|
||||
.isInstanceOf(EntityNotFoundException.class);
|
||||
.isInstanceOf(InsufficientPermissionException.class);
|
||||
|
||||
// assignment is denied for hiddenTarget since it's hidden
|
||||
assertThatThrownBy(() -> {
|
||||
targetManagement.unassignTag(hiddenTarget.getControllerId(), myTag.getId());
|
||||
}).as("Missing update permissions for target to toggle tag assignment.")
|
||||
.isInstanceOf(EntityNotFoundException.class);
|
||||
assertThatThrownBy(() -> targetManagement.unassignTag(hiddenTarget.getControllerId(), myTag.getId()))
|
||||
.as("Missing update permissions for target to toggle tag assignment.")
|
||||
.isInstanceOf(InsufficientPermissionException.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -57,7 +57,6 @@ public class TestAccessControlManger {
|
||||
"Access to " + ruleClass.getName() + "/" + entity + " not allowed by checker!");
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -68,8 +68,7 @@ public class ArtifactManagementTest 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 = SoftwareModuleCreatedEvent.class, count = 1) })
|
||||
@ExpectEvents({ @Expect(type = SoftwareModuleCreatedEvent.class, count = 1) })
|
||||
public void nonExistingEntityAccessReturnsNotPresent() {
|
||||
final SoftwareModule module = testdataFactory.createSoftwareModuleOs();
|
||||
|
||||
@@ -85,8 +84,7 @@ public class ArtifactManagementTest extends AbstractJpaIntegrationTest {
|
||||
@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) })
|
||||
@ExpectEvents({ @Expect(type = SoftwareModuleDeletedEvent.class, count = 0) })
|
||||
public void entityQueriesReferringToNotExistingEntitiesThrowsException() throws URISyntaxException {
|
||||
|
||||
final String artifactData = "test";
|
||||
|
||||
@@ -146,8 +146,7 @@ class DeploymentManagementTest extends AbstractJpaIntegrationTest {
|
||||
@Test
|
||||
@Description("Verifies that management get access react as specified on calls for non existing entities by means " +
|
||||
"of Optional not present.")
|
||||
@ExpectEvents({
|
||||
@Expect(type = TargetCreatedEvent.class, count = 0) })
|
||||
@ExpectEvents({ @Expect(type = TargetCreatedEvent.class, count = 0) })
|
||||
void nonExistingEntityAccessReturnsNotPresent() {
|
||||
assertThat(deploymentManagement.findAction(1234L)).isNotPresent();
|
||||
assertThat(deploymentManagement.findActionWithDetails(NOT_EXIST_IDL)).isNotPresent();
|
||||
@@ -156,8 +155,7 @@ class DeploymentManagementTest extends AbstractJpaIntegrationTest {
|
||||
@Test
|
||||
@Description("Verifies that management queries react as specified on calls for non existing entities " +
|
||||
" by means of throwing EntityNotFoundException.")
|
||||
@ExpectEvents({
|
||||
@Expect(type = TargetCreatedEvent.class, count = 1) })
|
||||
@ExpectEvents({ @Expect(type = TargetCreatedEvent.class, count = 1) })
|
||||
void entityQueriesReferringToNotExistingEntitiesThrowsException() {
|
||||
final Target target = testdataFactory.createTarget();
|
||||
final String dsName = "DistributionSet";
|
||||
|
||||
@@ -54,8 +54,7 @@ class DistributionSetTagManagementTest extends AbstractJpaIntegrationTest {
|
||||
|
||||
@Test
|
||||
@Description("Verifies that management get access reacts as specified on calls for non existing entities by means of Optional not present.")
|
||||
@ExpectEvents({
|
||||
@Expect(type = TargetCreatedEvent.class, count = 0) })
|
||||
@ExpectEvents({ @Expect(type = TargetCreatedEvent.class, count = 0) })
|
||||
void nonExistingEntityAccessReturnsNotPresent() {
|
||||
assertThat(distributionSetTagManagement.getByName(NOT_EXIST_ID)).isNotPresent();
|
||||
assertThat(distributionSetTagManagement.get(NOT_EXIST_IDL)).isNotPresent();
|
||||
|
||||
@@ -55,8 +55,7 @@ public class DistributionSetTypeManagementTest extends AbstractJpaIntegrationTes
|
||||
@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 = 0) })
|
||||
@ExpectEvents({ @Expect(type = DistributionSetCreatedEvent.class, count = 0) })
|
||||
public void nonExistingEntityAccessReturnsNotPresent() {
|
||||
assertThat(distributionSetTypeManagement.get(NOT_EXIST_IDL)).isNotPresent();
|
||||
assertThat(distributionSetTypeManagement.getByKey(NOT_EXIST_ID)).isNotPresent();
|
||||
|
||||
@@ -49,8 +49,7 @@ class RolloutGroupManagementTest extends AbstractJpaIntegrationTest {
|
||||
@Test
|
||||
@Description("Verifies that management get access reacts as specified on calls for non existing entities by means " +
|
||||
"of Optional not present.")
|
||||
@ExpectEvents({
|
||||
@Expect(type = TargetCreatedEvent.class, count = 0) })
|
||||
@ExpectEvents({ @Expect(type = TargetCreatedEvent.class, count = 0) })
|
||||
void nonExistingEntityAccessReturnsNotPresent() {
|
||||
assertThat(rolloutGroupManagement.get(NOT_EXIST_IDL)).isNotPresent();
|
||||
assertThat(rolloutGroupManagement.getWithDetailedStatus(NOT_EXIST_IDL)).isNotPresent();
|
||||
|
||||
@@ -283,8 +283,7 @@ class RolloutManagementTest extends AbstractJpaIntegrationTest {
|
||||
@Test
|
||||
@Description("Verifies that management get access reacts as specified on calls for non existing entities by means "
|
||||
+ "of Optional not present.")
|
||||
@ExpectEvents({
|
||||
@Expect(type = TargetCreatedEvent.class) })
|
||||
@ExpectEvents({ @Expect(type = TargetCreatedEvent.class) })
|
||||
void nonExistingEntityAccessReturnsNotPresent() {
|
||||
assertThat(rolloutManagement.get(NOT_EXIST_IDL)).isNotPresent();
|
||||
assertThat(rolloutManagement.getByName(NOT_EXIST_ID)).isNotPresent();
|
||||
|
||||
@@ -62,8 +62,7 @@ public class SoftwareModuleManagementTest extends AbstractJpaIntegrationTest {
|
||||
@Test
|
||||
@Description("Verifies that management get access reacts as specified on calls for non existing entities by means "
|
||||
+ "of Optional not present.")
|
||||
@ExpectEvents({
|
||||
@Expect(type = SoftwareModuleCreatedEvent.class, count = 1) })
|
||||
@ExpectEvents({ @Expect(type = SoftwareModuleCreatedEvent.class, count = 1) })
|
||||
public void nonExistingEntityAccessReturnsNotPresent() {
|
||||
final SoftwareModule module = testdataFactory.createSoftwareModuleApp();
|
||||
|
||||
@@ -78,8 +77,7 @@ public class SoftwareModuleManagementTest extends AbstractJpaIntegrationTest {
|
||||
@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) })
|
||||
@ExpectEvents({ @Expect(type = SoftwareModuleCreatedEvent.class, count = 1) })
|
||||
public void entityQueriesReferringToNotExistingEntitiesThrowsException() {
|
||||
final SoftwareModule module = testdataFactory.createSoftwareModuleApp();
|
||||
|
||||
|
||||
@@ -37,8 +37,7 @@ public class SoftwareModuleTypeManagementTest 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 = 0) })
|
||||
@ExpectEvents({ @Expect(type = SoftwareModuleCreatedEvent.class, count = 0) })
|
||||
public void nonExistingEntityAccessReturnsNotPresent() {
|
||||
|
||||
assertThat(softwareModuleTypeManagement.get(NOT_EXIST_IDL)).isNotPresent();
|
||||
@@ -49,8 +48,7 @@ public class SoftwareModuleTypeManagementTest extends AbstractJpaIntegrationTest
|
||||
@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 = 0) })
|
||||
@ExpectEvents({ @Expect(type = SoftwareModuleCreatedEvent.class, count = 0) })
|
||||
public void entityQueriesReferringToNotExistingEntitiesThrowsException() {
|
||||
verifyThrownExceptionBy(() -> softwareModuleTypeManagement.delete(NOT_EXIST_IDL), "SoftwareModuleType");
|
||||
|
||||
|
||||
@@ -66,8 +66,7 @@ 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) })
|
||||
@ExpectEvents({ @Expect(type = TargetCreatedEvent.class, count = 0) })
|
||||
public void nonExistingEntityAccessReturnsNotPresent() {
|
||||
assertThat(targetFilterQueryManagement.get(NOT_EXIST_IDL)).isNotPresent();
|
||||
assertThat(targetFilterQueryManagement.getByName(NOT_EXIST_ID)).isNotPresent();
|
||||
|
||||
@@ -96,8 +96,7 @@ class TargetManagementTest extends AbstractJpaIntegrationTest {
|
||||
@Test
|
||||
@Description("Verifies that management get access react as specified on calls for non existing entities by means "
|
||||
+ "of Optional not present.")
|
||||
@ExpectEvents({
|
||||
@Expect(type = TargetCreatedEvent.class, count = 1) })
|
||||
@ExpectEvents({ @Expect(type = TargetCreatedEvent.class, count = 1) })
|
||||
void nonExistingEntityAccessReturnsNotPresent() {
|
||||
final Target target = testdataFactory.createTarget();
|
||||
assertThat(targetManagement.getByControllerID(NOT_EXIST_ID)).isNotPresent();
|
||||
@@ -184,8 +183,7 @@ class TargetManagementTest extends AbstractJpaIntegrationTest {
|
||||
|
||||
@Test
|
||||
@Description("Ensures that retrieving the target security is only permitted with the necessary permissions.")
|
||||
@ExpectEvents({
|
||||
@Expect(type = TargetCreatedEvent.class, count = 1) })
|
||||
@ExpectEvents({ @Expect(type = TargetCreatedEvent.class, count = 1) })
|
||||
void getTargetSecurityTokenOnlyWithCorrectPermission() throws Exception {
|
||||
final Target createdTarget = targetManagement
|
||||
.create(entityFactory.target().create().controllerId("targetWithSecurityToken").securityToken("token"));
|
||||
@@ -221,8 +219,7 @@ class TargetManagementTest extends AbstractJpaIntegrationTest {
|
||||
|
||||
@Test
|
||||
@Description("Verify that a target with same controller ID than another device cannot be created.")
|
||||
@ExpectEvents({
|
||||
@Expect(type = TargetCreatedEvent.class, count = 1) })
|
||||
@ExpectEvents({ @Expect(type = TargetCreatedEvent.class, count = 1) })
|
||||
void createTargetThatViolatesUniqueConstraintFails() {
|
||||
targetManagement.create(entityFactory.target().create().controllerId("123"));
|
||||
|
||||
@@ -388,8 +385,7 @@ class TargetManagementTest extends AbstractJpaIntegrationTest {
|
||||
|
||||
@Test
|
||||
@Description("Checks if the EntityAlreadyExistsException is thrown if the targets with the same controller ID are created twice.")
|
||||
@ExpectEvents({
|
||||
@Expect(type = TargetCreatedEvent.class, count = 5) })
|
||||
@ExpectEvents({ @Expect(type = TargetCreatedEvent.class, count = 5) })
|
||||
void createMultipleTargetsDuplicate() {
|
||||
testdataFactory.createTargets(5, "mySimpleTargs", "my simple targets");
|
||||
try {
|
||||
@@ -402,8 +398,7 @@ class TargetManagementTest extends AbstractJpaIntegrationTest {
|
||||
|
||||
@Test
|
||||
@Description("Checks if the EntityAlreadyExistsException is thrown if a single target with the same controller ID are created twice.")
|
||||
@ExpectEvents({
|
||||
@Expect(type = TargetCreatedEvent.class, count = 1) })
|
||||
@ExpectEvents({ @Expect(type = TargetCreatedEvent.class, count = 1) })
|
||||
void createTargetDuplicate() {
|
||||
targetManagement.create(entityFactory.target().create().controllerId("4711"));
|
||||
try {
|
||||
@@ -743,8 +738,7 @@ class TargetManagementTest extends AbstractJpaIntegrationTest {
|
||||
|
||||
@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) })
|
||||
@ExpectEvents({ @Expect(type = TargetCreatedEvent.class, count = 12) })
|
||||
void verifyFindTargetAllById() {
|
||||
final List<Long> searchIds = Arrays.asList(testdataFactory.createTarget("target-4").getId(),
|
||||
testdataFactory.createTarget("target-5").getId(), testdataFactory.createTarget("target-6").getId());
|
||||
|
||||
@@ -90,8 +90,7 @@ class TargetTagManagementTest 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) })
|
||||
@ExpectEvents({ @Expect(type = TargetCreatedEvent.class) })
|
||||
void nonExistingEntityAccessReturnsNotPresent() {
|
||||
assertThat(targetTagManagement.getByName(NOT_EXIST_ID)).isNotPresent();
|
||||
assertThat(targetTagManagement.get(NOT_EXIST_IDL)).isNotPresent();
|
||||
|
||||
@@ -43,8 +43,7 @@ class TargetTypeManagementTest extends AbstractJpaIntegrationTest {
|
||||
@Test
|
||||
@Description("Verifies that management get access react as specified on calls for non existing entities by means "
|
||||
+ "of Optional not present.")
|
||||
@ExpectEvents({
|
||||
@Expect(type = TargetTypeCreatedEvent.class) })
|
||||
@ExpectEvents({ @Expect(type = TargetTypeCreatedEvent.class) })
|
||||
void nonExistingEntityAccessReturnsNotPresent() {
|
||||
assertThat(targetTypeManagement.get(NOT_EXIST_IDL)).isNotPresent();
|
||||
assertThat(targetTypeManagement.getByName(NOT_EXIST_ID)).isNotPresent();
|
||||
@@ -53,8 +52,7 @@ class TargetTypeManagementTest extends AbstractJpaIntegrationTest {
|
||||
@Test
|
||||
@Description("Verifies that management queries react as specified on calls for non existing entities "
|
||||
+ " by means of throwing EntityNotFoundException.")
|
||||
@ExpectEvents({
|
||||
@Expect(type = TargetTypeUpdatedEvent.class) })
|
||||
@ExpectEvents({ @Expect(type = TargetTypeUpdatedEvent.class) })
|
||||
void entityQueriesReferringToNotExistingEntitiesThrowsException() {
|
||||
verifyThrownExceptionBy(() -> targetTypeManagement.delete(NOT_EXIST_IDL), "TargetType");
|
||||
verifyThrownExceptionBy(() -> targetTypeManagement.update(entityFactory.targetType().update(NOT_EXIST_IDL)),
|
||||
|
||||
Reference in New Issue
Block a user