Skip to content

Commit

Permalink
Merge pull request #100 from ELEVATE-Project/Jubedhalocal
Browse files Browse the repository at this point in the history
CURDOperations for Single entity
  • Loading branch information
Jubedhashaik authored Nov 12, 2024
2 parents 378acde + b155e2f commit 67e9c8f
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 6 deletions.
2 changes: 2 additions & 0 deletions Elevate_QA_API.xml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@
<methods>
<include name="testAddingValidEntity"/>
<include name="testAddingInvalidEntity"/>
<include name="testUpdatingEntity"/>

</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 @@ -22,4 +22,6 @@ elevate.qa.automation.entitytype.name=Automation_Entitytype
elevate.qa.automation.entitytype.Id=671ada4002fe677644c86979
elevate.qa.fetchentity.endpoint=entity-management/v1/entities/find
elevate.qa.entityadd.endpoint=entity-management/v1/entities/add
elevate.qa.entityupdate.endpoint=entity-management/v1/entities/update/


Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@
import org.apache.commons.lang3.RandomStringUtils;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.json.simple.JSONArray;
import org.json.simple.JSONObject;
import org.shikshalokam.backend.PropertyLoader;
import org.testng.Assert;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;

import java.util.HashMap;
import java.util.Map;

import static io.restassured.RestAssured.given;

public class TestElevateEntityCRUDOperations extends ElevateProjectBaseTest {
Expand All @@ -33,17 +33,25 @@ public void testAddingValidEntity() {
Assert.assertEquals(response.jsonPath().getString("message"), "ENTITY_ADDED");
logger.info("Validation of entity addition is successful.");
}

@Test(description = "Adding a valid entity")
@Test(description = "Adding a invalid entity")
public void testAddingInvalidEntity() {
Response response = addEntity("", PropertyLoader.PROP_LIST.getProperty("elevate.qa.automation.entitytype.Id"), "", PropertyLoader.PROP_LIST.getProperty("elevate.qa.automation.entitytype.name"));
Assert.assertEquals(response.getStatusCode(), 400);
Assert.assertTrue(response.asString().contains("The name field cannot be empty."));
logger.info("Validation of invalidentity addition is successful.");
}

@Test(description = "Updating the entity with a random name",dependsOnMethods ="testAddingValidEntity" )
public void testUpdatingEntity() {
getSystemId(randomExternalId);
Response response = updateEntity( entity_Id,randomEntityName +"123",randomExternalId + "dfdf7gd");
Assert.assertEquals(response.getStatusCode(), 200);
Assert.assertTrue(response.asString().contains(randomEntityName),"entity not found");
logger.info("Entity updated successfully to: " + randomEntityName);
}

// Method to add the entity
private Response addEntity(String entityName, String entityTypeId, String externalId, String entitytypename) {
private Response addEntity(String entityName, String entityTypeId, String externalId, String entityTypeName) {
Map<String, Object> requestBody = new HashMap<>();
requestBody.put("name", entityName);
requestBody.put("entityType", entityTypeId);
Expand All @@ -53,11 +61,31 @@ private Response addEntity(String entityName, String entityTypeId, String extern
.header("x-auth-token", X_AUTH_TOKEN)
.header("Content-Type", "application/json")
.body(requestBody)
.queryParam("type", entitytypename)
.queryParam("type", entityTypeName)
.post(PropertyLoader.PROP_LIST.getProperty("elevate.qa.entityadd.endpoint"));
response.prettyPrint();
return response;
}

// Method to update an entity by its ID
private Response updateEntity(String entityid ,String updatedEntityName, String updatedExternalId) {
JSONObject requestBody = new JSONObject();

requestBody.put("metaInformation.externalId", updatedExternalId);
requestBody.put("metaInformation.name", updatedEntityName);
requestBody.put("childHierarchyPath", new JSONArray());
requestBody.put("createdBy", "user123");
requestBody.put("updatedBy", "user123");
Response response = given()
.header("internal-access-token", INTERNAL_ACCESS_TOKEN)
.header("x-auth-token", X_AUTH_TOKEN)
.header("Content-Type", "application/json")
.body(requestBody)
.pathParam("_id",entityid )
.post(PropertyLoader.PROP_LIST.getProperty("elevate.qa.entityupdate.endpoint") + "{_id}");
response.prettyPrint();
return response;
}
}


Expand All @@ -68,3 +96,9 @@ private Response addEntity(String entityName, String entityTypeId, String extern









0 comments on commit 67e9c8f

Please sign in to comment.