diff --git a/src/main/java/framework/api/enums/ApiEndpoint.java b/src/main/java/framework/api/enums/ApiEndpoint.java index 9d52a008519588adc5418a728aee2532d7074261..0243ea6c498ea8ff5b0a63f115fb3221efa26c27 100644 --- a/src/main/java/framework/api/enums/ApiEndpoint.java +++ b/src/main/java/framework/api/enums/ApiEndpoint.java @@ -5,6 +5,7 @@ import java.util.Map; public enum ApiEndpoint { IDENTITY_ATTRIBUTE("/sap-api/identity-attribute", "Identity Attribute"), + USER_ROLE("/user-api/role", "User Role"), PARTICIPANT_TYPE("/identity-api/participant", "Participant"), IDENTITY_ATTRIBUTE_LOCAL_AGENT_SEARCH("/user-api/identity-attribute/search", "Identity Attribute Local Agent Search"); diff --git a/src/main/java/framework/api/services/usersandroles/UserRolesRequestBuilder.java b/src/main/java/framework/api/services/usersandroles/UserRolesRequestBuilder.java new file mode 100644 index 0000000000000000000000000000000000000000..b5821ff1ed25c22503ffde2c87b1c2d2f483fccd --- /dev/null +++ b/src/main/java/framework/api/services/usersandroles/UserRolesRequestBuilder.java @@ -0,0 +1,38 @@ +package framework.api.services.usersandroles; + +import com.google.gson.JsonObject; +import framework.common.Utils; + +import java.util.Map; + +public class UserRolesRequestBuilder { + + private final JsonObject requestBody; + + public UserRolesRequestBuilder() { + this.requestBody = new JsonObject(); + } + + public UserRolesRequestBuilder fromMap(Map<String, String> data) { + String name = Utils.resolveRandomizedValue(data.get("name")); + String description = Utils.resolveRandomizedValue(data.get("description")); + + withName(name).withDescription(description); + + return this; + } + + public UserRolesRequestBuilder withName(String name) { + requestBody.addProperty("name", name); + return this; + } + + public UserRolesRequestBuilder withDescription(String description) { + requestBody.addProperty("description", description); + return this; + } + + public JsonObject build() { + return requestBody; + } +} diff --git a/src/main/java/framework/api/services/usersandroles/objects/UserRole.java b/src/main/java/framework/api/services/usersandroles/objects/UserRole.java new file mode 100644 index 0000000000000000000000000000000000000000..a73e517beae4cc6dbf2755a13f8d373746159f1d --- /dev/null +++ b/src/main/java/framework/api/services/usersandroles/objects/UserRole.java @@ -0,0 +1,33 @@ +package framework.api.services.usersandroles.objects; + +public class UserRole { + + private String id; + private String name; + private String description; + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } + +} diff --git a/src/test/java/features/api/simplOpen/Authority.feature b/src/test/java/features/api/simplOpen/Authority.feature index 8f3901d5cb67ad287c3c7f2ce5c726a4ec051d57..a0a35cb9291fcd573e455f6f2425397c500532f5 100644 --- a/src/test/java/features/api/simplOpen/Authority.feature +++ b/src/test/java/features/api/simplOpen/Authority.feature @@ -11,7 +11,7 @@ Feature: Authority API scenarios | Name | RANDOM_NAME | | Description | RANDOM_DESCRIPTION | | Participant Types | DATA_PROVIDER; CONSUMER | - Then the identity attribute is successfully created + Then the system indicates successful creation And the response body contains the expected Identity Attribute's details And the response body contains assigned Participant Types | DATA_PROVIDER | @@ -27,7 +27,7 @@ Feature: Authority API scenarios | Name | RANDOM_NAME | | Description | RANDOM_DESCRIPTION | | Participant Types | CONSUMER | - And the identity attribute is successfully created + Then the system indicates successful creation When the user searches for the identity attribute by ID Then the response body contains the expected Identity Attribute's details @@ -80,3 +80,13 @@ Feature: Authority API scenarios 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 + + + @TCA08_API @SIMPL-5233 + Scenario: Creation of New Tier1 Role with T1UAR_M Role - Role Successfully Created + Given a user with role "AUTHORITY_T1UAR_M" is logged in to governance authority + When the user creates "User Role" with the following data: + | name | RANDOM_NAME | + | description | RANDOM_DESCRIPTION | + Then the system indicates successful creation + And the response body contains the expected User Role's details diff --git a/src/test/java/stepDefinitions/api/simplOpen/AuthoritySteps.java b/src/test/java/stepDefinitions/api/simplOpen/AuthoritySteps.java index 24998574060041619a5d5cc15795f7c2a3763f72..b956fd06ed61e90a8d4fffc6f6c438b31732661b 100644 --- a/src/test/java/stepDefinitions/api/simplOpen/AuthoritySteps.java +++ b/src/test/java/stepDefinitions/api/simplOpen/AuthoritySteps.java @@ -1,12 +1,14 @@ package stepDefinitions.api.simplOpen; import com.google.gson.*; +import framework.api.services.usersandroles.UserRolesRequestBuilder; import framework.api.services.securityattributesprovider.objects.IdentityAttribute; import framework.api.services.securityattributesprovider.IdentityAttributeRequestBuilder; import framework.api.helpers.RequestHandler; import framework.api.enums.*; import framework.api.helpers.ApiSetup; +import framework.api.services.usersandroles.objects.UserRole; import framework.ui.helpers.Utils; import io.cucumber.datatable.DataTable; import io.cucumber.java.After; @@ -29,9 +31,12 @@ public class AuthoritySteps { private RequestHandler requestHandler; private ApiEndpoint identityAttributeEndpoint; + private ApiEndpoint userRoleEndpoint; private IdentityAttribute identityAttribute = new IdentityAttribute(); + private UserRole userRole = new UserRole(); private String savedIdentityAttributeId; private final List<String> createdIdentityAttributesIDs = new ArrayList<>(); + private final List<String> createdUserRoleIDs = new ArrayList<>(); private String randomIdentityAttributeId; @Before("@AuthorityAPI") @@ -88,6 +93,26 @@ public class AuthoritySteps { createdIdentityAttributesIDs.add(identityAttribute.getId()); } + @When("the user creates {string} with the following data:") + public void theUserCreatesRoleWithTheFollowingData(String endpointName, DataTable dataTable) { + Gson gson = new Gson(); + userRoleEndpoint = ApiEndpoint.fromString(endpointName); + + Map<String, String> data = dataTable.asMap(String.class, String.class); + JsonObject requestBody = new UserRolesRequestBuilder() + .fromMap(data) + .build(); + + requestHandler.sendRequest(HttpMethod.POST, userRoleEndpoint.getPath(), requestBody); + + JsonObject createdUserRole = requestHandler.getLastResponseBody(); + + userRole = gson.fromJson(requestBody, UserRole.class); + userRole.setId(createdUserRole.get("id").getAsString()); + + createdUserRoleIDs.add(userRole.getId()); + } + @When("the user updates the Identity Attribute with the new data:") public void theUserSendsAnUpdateRequestTheNewData(DataTable dataTable) { Gson gson = new Gson(); @@ -261,6 +286,16 @@ public class AuthoritySteps { } } + @Then("the response body contains the expected User Role's details") + public void theResponseBodyContainsTheExpectedUserRolesDetails() { + Gson gson = new Gson(); + UserRole userRoleRetrieved = gson.fromJson(requestHandler.getLastResponseBody(), UserRole.class); + + assertNotNull("Retrieved identity attribute is null", userRoleRetrieved); + assertEquals("Mismatch in 'name'", userRole.getName(), userRoleRetrieved.getName()); + assertEquals("Mismatch in 'description'", userRole.getDescription(), userRoleRetrieved.getDescription()); + } + @Then("the response body contains assigned Participant Types") public void theResponseBodyContainsAssignedParticipantTypes(DataTable dataTable) { List<String> expectedParticipantTypes = dataTable.asList(String.class); @@ -274,7 +309,7 @@ public class AuthoritySteps { } } - @Then("the identity attribute is successfully created") + @Then("the system indicates successful creation") public void validateSuccessfulCreation() { int actualStatusCode = requestHandler.getLastStatusCode(); int expectedStatusCode = HttpStatus.CREATED.getCode();