Skip to content

Commit

Permalink
Merge pull request #116 from ELEVATE-Project/Suhas_local
Browse files Browse the repository at this point in the history
Suhas local
  • Loading branch information
SuhasVMM authored Dec 20, 2024
2 parents c7129ae + 8f6bc69 commit cdc579f
Show file tree
Hide file tree
Showing 5 changed files with 77 additions and 12 deletions.
5 changes: 4 additions & 1 deletion Elevate_QA_API.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
<listeners>
<listener class-name="org.shikshalokam.Listerners.SLCustomListener"/>
</listeners>

<test name="Test">

<classes>
<class name="org.shikshalokam.backend.ep.TestElevateLogin">
<methods>
Expand Down Expand Up @@ -57,7 +59,8 @@
<include name="testInvalidRelatedEntitiesBasedOnEntity"/>
<include name="testValidEntityDetails"/>
<include name="testInvalidEntityDetails"/>
<include name="testFetchEntitySubListUsingParentEntityID"/>
<include name="testfetchEntityDetailByLocationId"/>
<include name="testFetchSublistOfEntitiesByEntityId"/>
</methods>
</class>
</classes>
Expand Down
2 changes: 2 additions & 0 deletions src/main/resources/config/Automation_ElevateAPI_QA.properties
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ elevate.qa.targetedroles.endpoint=entity-management/v1/entities/targetedRoles/
elevate.qa.entity.realated.entities=entity-management/v1/entities/relatedEntities/
elevate.qa.entity.detailsbasedon.entityid.endpoint=entity-management/v1/entities/details/
elevate.qa.entity.sublist.endpoint=entity-management/v1/entities/subEntityList/
elevate.qa.entities.listbylocatioId=entity-management/v1/entities/listByLocationIds

#need to add validations for the below
#org.shikshalokam.backend.ep.TestElevateEntityCRUDOperations.testValidRelatedEntitiesBasedOnEntity
#The method testFetchEntitySubListUsingParentEntityID under entity crud operations is not in xml file due to thepagination issue
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import org.shikshalokam.backend.MentorBase;
import org.shikshalokam.backend.PropertyLoader;
import org.testng.Assert;
import org.testng.annotations.Test;

import java.net.URI;
import java.net.URISyntaxException;
Expand All @@ -31,6 +32,7 @@ public class ElevateProjectBaseTest extends MentorBase {
public static String entityType_Id = null;
public static String entity_Id = null;
public static String createdRoleID;
public static String location_Id = null;

// method to login with required parameters
public static Response loginToElevate(String email, String Password) {
Expand Down Expand Up @@ -73,7 +75,7 @@ public Response fetchSingleEntityType(String name) {
return response;
}

//Method to get entity type Id
//Method to get entity type ID
public String getEntitytype_Id(String entityName) {
Response response = fetchSingleEntityType(entityName);
response.prettyPrint();
Expand Down Expand Up @@ -141,4 +143,12 @@ public Response deleteUserRoleExtension(String roleID) {
response.prettyPrint();
return response;
}

public String getLocationID(String externalID) {
Response response = fetchEntitydetails(externalID);
location_Id = response.jsonPath().getString("result[0].registryDetails.locationId").replaceAll("[\\[\\]]", "");
Assert.assertTrue(response.asString().contains(externalID), "locationId not found");
logger.info("Location Id fetched successfully!! = " + location_Id);
return location_Id;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
import static org.testng.Assert.*;

public class TestCRUDUserRoleExtensionOperations extends ElevateProjectBaseTest {

public static final Logger logger = LogManager.getLogger(TestCRUDUserRoleExtensionOperations.class);
private String updatedRoleTitle = "Principal" + RandomStringUtils.randomAlphabetic(3).toLowerCase();
private String userRoleId = RandomStringUtils.randomAlphabetic(10);
Expand Down Expand Up @@ -53,7 +52,7 @@ public void testValidUpdateUserRoleExtension() {
Response response = updateUserRoleExtension(updatedRoleTitle, PROP_LIST.getProperty("elevate.qa.entityType"), PROP_LIST.getProperty("elevate.qa.entityTypeId"));
logger.info("Response Code: {}, Response Body: {}", response.getStatusCode(), response.getBody().asString());
assertEquals(response.getStatusCode(), 200, "User role extension update failed with " + response.getStatusCode());
assertEquals(response.jsonPath().getString("message"), "USER_ROLE_UPDATATED");
assertEquals(response.jsonPath().getString("message"), "USER_ROLE_UPDATED");
Response responseFind = findUserRoleExtension();
assertEquals(responseFind.getStatusCode(), 200, "User role extension update failed with " + response.getStatusCode());
assertTrue(responseFind.getBody().asString().contains(updatedRoleTitle));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import static io.restassured.RestAssured.given;

public class TestElevateEntityCRUDOperations extends ElevateProjectBaseTest {

private Logger logger = LogManager.getLogger(TestElevateEntityCRUDOperations.class);
private String randomEntityName = RandomStringUtils.randomAlphabetic(11);
private String randomExternalId = RandomStringUtils.randomAlphabetic(11);
Expand All @@ -28,6 +29,9 @@ public class TestElevateEntityCRUDOperations extends ElevateProjectBaseTest {
private String userRolenametitle = RandomStringUtils.randomAlphabetic(11);
private String userRoleId = RandomStringUtils.randomAlphabetic(11);
private String childEntity;
private String uniqueName = RandomStringUtils.randomAlphabetic(3) + randomEntityName;
private String uniqueId = RandomStringUtils.randomAlphabetic(3) + randomExternalId;


@BeforeMethod
public void login() {
Expand All @@ -38,13 +42,10 @@ public void login() {

@Test(description = "Adding a valid entity")
public void testAddingValidEntity() {
String uniqueName = RandomStringUtils.randomAlphabetic(3) + randomEntityName;
String uniqueId = RandomStringUtils.randomAlphabetic(3) + randomExternalId;
Response response = addEntity(uniqueName, uniqueId, PropertyLoader.PROP_LIST.getProperty("elevate.qa.automation.entitytype.name"));
Assert.assertEquals(response.getStatusCode(), 200);
Assert.assertEquals(response.jsonPath().getString("message"), "ENTITY_ADDED");
logger.info("Validation of entity addition is successful.");
getEntityId(randomExternalId);
}

@Test(description = "Adding a invalid entity")
Expand All @@ -65,7 +66,7 @@ public void testUpdateValidEntity() {

@Test(description = "Updating the entity to a different entity type", dependsOnMethods = "testAddingValidEntity")
public void testUpdateEntityToDifferentEntityType() {
getEntityId(randomExternalId);
getEntityId(uniqueId);
Response response = updateEntity(entity_Id, updatedEntityName, updatedEntityExternalId, PropertyLoader.PROP_LIST.getProperty("elevate.qa.update.entitytype.name"));
Assert.assertEquals(response.getStatusCode(), 200);
Assert.assertTrue(response.asString().contains(updatedEntityName), "entity not found");
Expand Down Expand Up @@ -97,7 +98,8 @@ public void testUpdateInvalidEntity() {

@Test(description = "fetching entity details based on externalId", dependsOnMethods = "testAddingValidEntity")
public void testFetchValidEntityDetails() {
Response response = fetchEntitydetails(randomExternalId);
getEntityId(uniqueId);
Response response = fetchEntitydetails(uniqueId);
Assert.assertEquals(response.getStatusCode(), 200);
Assert.assertTrue(response.jsonPath().getString("message").contains("ASSETS_FETCHED_SUCCESSFULLY"));
logger.info("Validations related to fetching the Valid single entity details is verified");
Expand Down Expand Up @@ -186,14 +188,14 @@ public void testInvalidEntityDetails() {
.get("entity-management/v1/entities/details");
response.prettyPrint();
Assert.assertEquals(response.getStatusCode(), 400);
Assert.assertTrue(response.asString().contains("required state location id"));
Assert.assertTrue(response.asString().contains("required id"));
logger.info("Validations related to getting entity details without path parameter is verified");
}

@Test(dependsOnMethods = "testBulkMappingEntities")
public void testFetchEntitySubListUsingParentEntityID() {
getEntityId(PropertyLoader.PROP_LIST.getProperty("elevate.qa.parent.entity.externalId"));
Response response = fetchEntitySubListBasedOnEntityId(entity_Id, "3", "300", PropertyLoader.PROP_LIST.getProperty("elevate.qa.automation.entitytype.name"));
Response response = fetchEntitySubListBasedOnEntityId(entity_Id, "4", "400", PropertyLoader.PROP_LIST.getProperty("elevate.qa.automation.entitytype.name"));
Assert.assertEquals(response.getStatusCode(), 200);
Assert.assertTrue(response.asString().contains("ENTITIES_FETCHED"));
int count = response.jsonPath().getInt("result.count");
Expand All @@ -202,6 +204,24 @@ public void testFetchEntitySubListUsingParentEntityID() {
logger.info("Validations related to fetching entity sublist is verified ");
}

@Test(description = "Test to get entities based on location ID")
public void testfetchEntityDetailByLocationId() {
getLocationID("Automation_ExternalId123");
Response response = fetchEntityBasedOnLocationId(location_Id);
Assert.assertEquals(response.getStatusCode(), 200);
Assert.assertTrue(response.asString().contains(location_Id), "Entity Details not fetched");
logger.info("Validations related to fetching entities by using location ID is verified");
}

@Test(description = "test to fetch sub list of entities based on entity Id")
public void testFetchSublistOfEntitiesByEntityId() {
getEntityId(PropertyLoader.PROP_LIST.getProperty("elevate.qa.parent.entity.externalId"));
Response response = listAllEntitiesBasedOnEntityId(entity_Id, "entityType");
Assert.assertEquals(response.getStatusCode(), 200);
Assert.assertTrue(response.asString().contains(entity_Id));
logger.info("Validations related to fetching the sub list of entities based on entity Id is verified");
}

// Method to add the entity
private Response addEntity(String entityName, String externalId, String entityTypeName) {
getEntitytype_Id(entityTypeName);
Expand All @@ -217,7 +237,6 @@ private Response addEntity(String entityName, String externalId, String entityTy
.queryParam("type", entityTypeName)
.post(PropertyLoader.PROP_LIST.getProperty("elevate.qa.entityadd.endpoint"));
response.prettyPrint();
//getEntityId(randomExternalId);
return response;
}

Expand Down Expand Up @@ -360,4 +379,36 @@ private Response fetchEntitySubListBasedOnEntityId(String entityid, String page,
response.prettyPrint();
return response;
}

private Response fetchEntityBasedOnLocationId(String locationId) {
JSONObject requestBody = new JSONObject();
requestBody.put("locationIds", new String[]{locationId});
Response response = given()
.header("internal-access-token", INTERNAL_ACCESS_TOKEN)
.header("x-auth-token", X_AUTH_TOKEN)
.header("Content-Type", "application/json")
.body(requestBody)
.post(PropertyLoader.PROP_LIST.getProperty("elevate.qa.entities.listbylocatioId"));
response.prettyPrint();
return response;
}

private Response listAllEntitiesBasedOnEntityId(String entityId, String requiredField) {
JSONObject requestBody = new JSONObject();
JSONArray entities = new JSONArray();
entities.add(entityId);
requestBody.put("entities", entities);
JSONArray field = new JSONArray();
field.add(requiredField);
requestBody.put("fields", field);
Response response = given()
.header("internal-access-token", INTERNAL_ACCESS_TOKEN)
.header("x-auth-token", X_AUTH_TOKEN)
.header("Content-Type", "application/json")
.body(requestBody)
.post("entity-management/v1/entities/listByIds");
response.prettyPrint();
return response;
}

}

0 comments on commit cdc579f

Please sign in to comment.