Code development platform for open source projects from the European Union institutions

Skip to content
Snippets Groups Projects
Commit d03618e8 authored by Jaime Pérez-Lozana's avatar Jaime Pérez-Lozana
Browse files

Merge branch 'feature/SOAPI-SIMPL-4502' into 'develop'

test for simpl 4502: Unsuccessful Identity Attribute enablement

See merge request simpl/pso/pso-test/pso-test-automation!150
parents 63537a6c df1143c0
No related branches found
No related tags found
No related merge requests found
......@@ -71,6 +71,7 @@ public class RequestHandler {
}
public JsonObject sendRequest(HttpMethod method, String endpoint, String bodyRequest) {
logger.logToScenario("Request Body", bodyRequest);
return sendRequest(method, endpoint, bodyRequest, MediaType.JSON);
}
......@@ -89,7 +90,6 @@ public class RequestHandler {
JsonObject jsonResponse = null;
if (responseBody != null && !responseBody.isEmpty()) {
logger.logToScenario("Request Body", responseBody);
jsonResponse = JsonParser.parseString(responseBody).getAsJsonObject();
}
......
......@@ -31,4 +31,13 @@ public final class Utils {
return value;
}
public static String modifyId(String originalId) {
if (originalId == null || originalId.isEmpty()) {
throw new IllegalArgumentException("Original ID is null or empty");
}
char lastChar = originalId.charAt(originalId.length() - 1);
char newChar = (lastChar != '0') ? '0' : '1';
return originalId.substring(0, originalId.length() - 1) + newChar;
}
}
......@@ -34,7 +34,7 @@ Feature: Authority API scenarios
@TCA03_API @SIMPL-3335 @SIMPL-3343
Scenario: User with IATTR_M role updates an Identity Attribute
Given a user with role "IATTR_M" is logged in to governance authority
And an "Identity Attribute" is already created
And an "Identity Attribute" is already created and assigned
When the user updates the Identity Attribute with the new data:
| Code | UPDATED_CODE |
| Enabled | false |
......@@ -46,7 +46,7 @@ Feature: Authority API scenarios
And the user searches for the identity attribute by ID
Then the response body contains the expected Identity Attribute's details
@TCA04_API @SIMPL-4072
@TCA04_API @SIMPL-4072 @skip
Scenario: Attempt to Delete Assigned Identity Attribute via API - Deletion forbidden
Given a user with role "IATTR_M" is logged in to governance authority
When the user searches for the identity attribute
......@@ -67,9 +67,16 @@ Feature: Authority API scenarios
@TCA06_API @SIMPL-4532
Scenario: Disable an Identity Attribute
Given a user with role "IATTR_M" is logged in to governance authority
And an "Identity Attribute" is already created
And an "Identity Attribute" is already created and assigned
When the user sets the Identity Attribute as assignable to "false"
And the operation is completed successfully
And the user searches for the identity attribute by ID
Then the response body contains updated Identity Attribute data:
| assignable to roles | false |
@TCA07_API @SIMPL-4502 @bug:SIMPL-10207
Scenario: Unsuccessful Identity Attribute enablement
Given a user with role "IATTR_M" is logged in to governance authority
And an "Identity Attribute" is already created and assigned
When the user attempts to set the Identity Attribute as assignable to "true" with a modified ID
And the system indicates bad request
......@@ -15,12 +15,14 @@ import io.cucumber.java.Scenario;
import io.cucumber.java.en.Given;
import io.cucumber.java.en.Then;
import io.cucumber.java.en.When;
import org.junit.Assume;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import static framework.common.Utils.modifyId;
import static org.junit.Assert.*;
public class AuthoritySteps {
......@@ -34,6 +36,10 @@ public class AuthoritySteps {
@Before("@AuthorityAPI")
public void setUp(Scenario scenario) {
if (scenario.getSourceTagNames().contains("@skip")) {
System.out.println("Skipping scenario: " + scenario.getName());
Assume.assumeTrue(false);
}
ApiSetup setup = new ApiSetup();
setup.setUp(BaseUrl.AUTHORITY, scenario);
requestHandler = new RequestHandler(BaseUrl.AUTHORITY, setup.getApiContext(), scenario);
......@@ -47,7 +53,7 @@ public class AuthoritySteps {
requestHandler.addHeader("Authorization", "Bearer " + token);
}
@Given("an {string} is already created")
@Given("an {string} is already created and assigned")
public void anIdentityAttributeIsAlreadyCreated(String endpointName) {
identityAttributeEndpoint = ApiEndpoint.fromString(endpointName);
......@@ -143,20 +149,32 @@ public class AuthoritySteps {
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();
@When("the user sets the Identity Attribute as assignable to {string}")
public void theUserChangesTheIdentityAttributeAssignableToFalse(String isAssignable) {
if (!isAssignable.equalsIgnoreCase("true") && !isAssignable.equalsIgnoreCase("false")) {
throw new IllegalArgumentException("Invalid value for assignable: " + isAssignable + ". Expected 'true' or 'false'.");
}
JsonArray idArray = new JsonArray();
idArray.add(identityAttribute.getId());
assertEquals("Mismatch in status code", expectedStatusCode, actualStatusCode);
String endpoint = ApiEndpoint.IDENTITY_ATTRIBUTE.getPath() + "/assignable/" + isAssignable.toLowerCase();
requestHandler.sendRequest(HttpMethod.PUT, endpoint, idArray.toString());
}
@When("the user sets the Identity Attribute as assignable to \"false\"")
public void theUserChangesTheIdentityAttributeAssignableToFalse() {
@When("the user attempts to set the Identity Attribute as assignable to {string} with a modified ID")
public void theUserAttemptsToSetIdentityAttributeWithModifiedId(String isAssignable) {
if (!isAssignable.equalsIgnoreCase("true") && !isAssignable.equalsIgnoreCase("false")) {
throw new IllegalArgumentException("Invalid value for assignable: " + isAssignable + ". Expected 'true' or 'false'.");
}
String modifiedId = modifyId(identityAttribute.getId());
JsonArray idArray = new JsonArray();
idArray.add(modifiedId);
idArray.add(identityAttribute.getId());
requestHandler.sendRequest(HttpMethod.PUT, ApiEndpoint.IDENTITY_ATTRIBUTE.getPath() + "/" + "assignable/false", idArray.toString());
String endpoint = ApiEndpoint.IDENTITY_ATTRIBUTE.getPath() + "/assignable/" + isAssignable.toLowerCase();
requestHandler.sendRequest(HttpMethod.PUT, endpoint, idArray.toString());
}
@When("the operation is completed successfully")
......@@ -167,6 +185,22 @@ public class AuthoritySteps {
assertEquals("Mismatch in status code", expectedStatusCode, actualStatusCode);
}
@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 system indicates bad request")
public void theSystemIndicatesBadRequest() {
int actualStatusCode = requestHandler.getLastStatusCode();
int expectedStatusCode = HttpStatus.BAD_REQUEST.getCode();
assertEquals("Mismatch in status code", expectedStatusCode, actualStatusCode);
}
@Then("the response body contains updated Identity Attribute data:")
public void theResponseBodyContainsUpdatedIdentityAttributeData(DataTable dataTable) {
Gson gson = new Gson();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment