diff --git a/src/test/java/features/api/simplOpen/Authority.feature b/src/test/java/features/api/simplOpen/Authority.feature index 3f72a32e85dc20c8e0795ff7028b06269d152f09..f5c3d2f85d4d6aa93a3f85e90a121317ef2c9608 100644 --- a/src/test/java/features/api/simplOpen/Authority.feature +++ b/src/test/java/features/api/simplOpen/Authority.feature @@ -51,7 +51,15 @@ Feature: Authority API scenarios Given a user with role "IATTR_M" is logged in to governance authority When the user searches for the identity attribute And the user saves an ID of the first found identity attribute - And the user deletes the Identity Attribute he found + And the user deletes "the found" Identity Attribute Then the system doesn't allow to do that And the response body contains appropriate response message: | error | The deletion of an assigned identity attribute is not allowed. | + + @TCA05_API @SIMPL-4096 + Scenario: Attempt to Delete random Identity Attribute + Given a user with role "IATTR_M" is logged in to governance authority + When the user deletes "a random" Identity Attribute + Then the system indicates absence of such resource + And the response body contains appropriate response message: + | error | Identity attribute with id [ random_id ] not found | diff --git a/src/test/java/stepDefinitions/api/simplOpen/AuthoritySteps.java b/src/test/java/stepDefinitions/api/simplOpen/AuthoritySteps.java index dc383ea2e0c620573dbd52a235c68c7c0781780d..a058af1f07afc17110259bd5c4cb3be74ecd9fef 100644 --- a/src/test/java/stepDefinitions/api/simplOpen/AuthoritySteps.java +++ b/src/test/java/stepDefinitions/api/simplOpen/AuthoritySteps.java @@ -19,6 +19,7 @@ import io.cucumber.java.en.When; import java.util.ArrayList; import java.util.List; import java.util.Map; +import java.util.UUID; import static org.junit.Assert.*; @@ -29,6 +30,7 @@ public class AuthoritySteps { private IdentityAttribute identityAttribute = new IdentityAttribute(); private String savedIdentityAttributeId; private final List<String> createdIdentityAttributesIDs = new ArrayList<>(); + private String randomIdentityAttributeId; @Before("@AuthorityAPI") public void setUp(Scenario scenario) { @@ -125,9 +127,28 @@ public class AuthoritySteps { savedIdentityAttributeId = firstIdentityAttribute.getId(); } - @When("the user deletes the Identity Attribute he found") - public void theUserDeletesTheIdentityAttribute() { - requestHandler.sendRequest(HttpMethod.DELETE, ApiEndpoint.IDENTITY_ATTRIBUTE.getPath() + "/" + savedIdentityAttributeId); + @When("the user deletes {string} Identity Attribute") + public void theUserDeletesIdentityAttribute(String attributeType) { + String identityAttributeId; + + if (attributeType.equalsIgnoreCase("the found")) { + identityAttributeId = savedIdentityAttributeId; + } else if (attributeType.equalsIgnoreCase("a random")) { + randomIdentityAttributeId = UUID.randomUUID().toString(); + identityAttributeId = randomIdentityAttributeId; + } else { + throw new IllegalArgumentException("Unknown attribute type: " + attributeType); + } + + requestHandler.sendRequest(HttpMethod.DELETE, ApiEndpoint.IDENTITY_ATTRIBUTE.getPath() + "/" + identityAttributeId); + } + + @Then("the system indicates absence of such resource") + public void theSystemIndicatesAbsenceOfSuchResource() { + int actualStatusCode = requestHandler.getLastStatusCode(); + int expectedStatusCode = HttpStatus.NOT_FOUND.getCode(); + + assertEquals("Mismatch in status code", expectedStatusCode, actualStatusCode); } @Then("the update is performed successfully") @@ -214,8 +235,14 @@ public class AuthoritySteps { String expectedKey = entry.getKey(); String expectedValue = entry.getValue(); + if (expectedValue.contains("random_id")) { + expectedValue = expectedValue.replace("random_id", randomIdentityAttributeId); + } + assertTrue("Response does not contain key: " + expectedKey, jsonResponse.has(expectedKey)); - assertEquals("Mismatch in response value for key: " + expectedKey, expectedValue, jsonResponse.get(expectedKey).getAsString()); + assertEquals("Mismatch in response value for key: " + expectedKey, + expectedValue, + jsonResponse.get(expectedKey).getAsString()); } }