76 lines
2.7 KiB
Java
76 lines
2.7 KiB
Java
package apitestsuites;
|
|
|
|
import com.utopiadeals.api.RestWebCall;
|
|
import com.utopiadeals.utils.config.Constants;
|
|
import io.restassured.response.Response;
|
|
import org.junit.jupiter.api.Tag;
|
|
import org.junit.jupiter.api.Test;
|
|
|
|
import java.util.List;
|
|
|
|
import static org.hamcrest.MatcherAssert.assertThat;
|
|
import static org.hamcrest.Matchers.*;
|
|
|
|
@Tag("access-mgmt-api")
|
|
public class AccessManagementApiTest {
|
|
private static final String BASE_URL = Constants.getApiBaseUrl();
|
|
private static final String USERS_ENDPOINT = "/api/access-management/users";
|
|
private RestWebCall apiClient;
|
|
private static String emailId = "";
|
|
private static Integer userId;
|
|
|
|
@Test
|
|
public void addUser_WithValidData_ShouldReturnSuccess() {
|
|
// Arrange
|
|
apiClient = new RestWebCall(BASE_URL, Constants.getApiTestUserName(), Constants.getApiTestPassword());
|
|
emailId = "new.user+" + System.currentTimeMillis() + "@example.com";
|
|
|
|
String requestBody = """
|
|
{
|
|
"email": "%s",
|
|
"firstName": "Test",
|
|
"lastName": "User0081",
|
|
"enabled": true,
|
|
"roles": [
|
|
0
|
|
],
|
|
"permissions": [
|
|
0
|
|
]
|
|
}
|
|
""".formatted(emailId);
|
|
|
|
/*End Point for Add / update user is same. To add user the API expects user id as 0.*/
|
|
// Act
|
|
Response response = apiClient.post(USERS_ENDPOINT + "/0", requestBody);
|
|
|
|
// Assert
|
|
assertThat(response.getStatusCode(), is(200));
|
|
assertThat(response.getBody().asString(), equalTo("success"));
|
|
}
|
|
|
|
@Test
|
|
public void getUsers_WithValidEmailId_ShouldReturnSuccess() {
|
|
// Act
|
|
apiClient = new RestWebCall(BASE_URL, Constants.getApiTestUserName(), Constants.getApiTestPassword());
|
|
Response response = apiClient.get(USERS_ENDPOINT, "size", "100");
|
|
assertThat(response.getStatusCode(), is(200));
|
|
List<String> emails = response.jsonPath().getList("data.email");
|
|
assertThat(emails, hasItem(emailId));
|
|
userId = response.jsonPath().getInt("data.find { it.email == '" + emailId + "' }.id");
|
|
assertThat(userId, notNullValue());
|
|
}
|
|
|
|
@Test
|
|
public void getUsers_WithValidId_ShouldReturnSuccess() {
|
|
// Act
|
|
apiClient = new RestWebCall(BASE_URL, Constants.getApiTestUserName(), Constants.getApiTestPassword());
|
|
Response response = apiClient.get(USERS_ENDPOINT + "/" + userId);
|
|
assertThat(response.getStatusCode(), is(200));
|
|
int actualUserId = response.jsonPath().getInt("user.id");
|
|
assertThat(userId, equalTo(actualUserId));
|
|
}
|
|
|
|
|
|
}
|