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

Skip to content
Snippets Groups Projects
Commit 962f3a1a authored by Yevhen Povietkin's avatar Yevhen Povietkin Committed by Jaime Pérez-Lozana
Browse files

test for simpl-5233: user role creation

parent d03618e8
No related branches found
No related tags found
No related merge requests found
......@@ -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");
......
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;
}
}
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;
}
}
......@@ -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
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();
......
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