Commit eb910a8b authored by Rakesh Mareddy's avatar Rakesh Mareddy

Update ProfileAPISteps.java

parent 99a14140
...@@ -7,18 +7,18 @@ import io.cucumber.java.en.Given; ...@@ -7,18 +7,18 @@ import io.cucumber.java.en.Given;
import io.cucumber.java.en.Then; import io.cucumber.java.en.Then;
import io.cucumber.java.en.When; import io.cucumber.java.en.When;
import io.restassured.response.Response; import io.restassured.response.Response;
import org.apache.log4j.Logger;
import org.junit.Assert;
import java.net.URISyntaxException; import java.net.URISyntaxException;
import java.time.Instant; import java.time.Instant;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import org.apache.log4j.Logger;
import org.junit.Assert;
/* /*
* API Code * API Code
*/ */
public class ProfileAPISteps { public class ProfileAPISteps {
ApiEngine api = new ApiEngine(); ApiEngine api = new ApiEngine();
private static final Logger log = Logger.getLogger(ProfileAPISteps.class); private static final Logger log = Logger.getLogger(ProfileAPISteps.class);
public static String webUrl = EnvVariables.getEnvVariables().get("webURL"); public static String webUrl = EnvVariables.getEnvVariables().get("webURL");
...@@ -38,46 +38,45 @@ public class ProfileAPISteps { ...@@ -38,46 +38,45 @@ public class ProfileAPISteps {
private void set_header_param(String dictionaryKey, String value) throws Throwable { private void set_header_param(String dictionaryKey, String value) throws Throwable {
String[] paramCategory = dictionaryKey.split("\\."); String[] paramCategory = dictionaryKey.split("\\.");
switch (paramCategory[0]) { switch(paramCategory[0]) {
case "headers": case "headers":
Globals.headers.put(paramCategory[1], value); Globals.headers.put(paramCategory[1],value);
break; break;
case "base_url": case "base_url":
Globals.globalVariables.put(paramCategory[1], value); Globals.globalVariables.put(paramCategory[1],value);
break; break;
} }
} }
@Given("I have all the data required for a profile creation") @Given("I have all the data required for a profile creation")
public void iHaveAllTheDataRequiredForAProfileCreation(Map<String, String> userinfo) { public void iHaveAllTheDataRequiredForAProfileCreation(Map<String,String> userinfo) {
HashMap<String, String> userdata = new HashMap<String, String>(); HashMap<String, String> userdata = new HashMap<String, String>();
userdata.putAll(userinfo); userdata.putAll(userinfo);
String randomizeEmail = new StringBuilder().append(Instant.now().toEpochMilli()) String randomizeEmail = new StringBuilder().append(Instant.now().toEpochMilli()).append(userinfo.get("emailAddress")).toString();
.append(userinfo.get("emailAddress")).toString();
userdata.replace("emailAddress", randomizeEmail); userdata.replace("emailAddress", randomizeEmail);
Gson gson = new Gson(); Gson gson = new Gson();
this.body = gson.toJson(userdata); this.body = gson.toJson(userdata);
} }
@When("^I (GET|PUT|POST|PATCH) the request to (.*) profile$") @When("^I (GET|PUT|POST|PATCH) the request to (.*) profile$")
public void iHitTheAPIRequestToPOSTCreateProfile(String apiType, String requestType) public void iHitTheAPIRequestToPOSTCreateProfile(String apiType, String requestType) throws URISyntaxException {
throws URISyntaxException { String URI;
String URI = switch (requestType) { switch (requestType){
case "create" -> customerURI; case "create":
case "search" -> customerSearchURI; URI = customerURI; break;
default -> "NOPATHYET"; case "search":
}; URI = customerSearchURI; break;
Response rs = api.callAPI(apiType, Globals.headers, body.toString(), default:
Globals.globalVariables.get("url").toString() + customerURI); URI = "NOPATHYET";
Globals.globalVariables.put(requestType, rs); }
Response rs = api.callAPI(apiType, Globals.headers, body.toString(), Globals.globalVariables.get("url").toString() + customerURI);
Globals.globalVariables.put(requestType,rs);
} }
@Then("I should see (.*) profile succeeded") @Then("I should see (.*) profile succeeded")
public void iShouldSeeAPIRequestSucceeded(String requestType) { public void iShouldSeeAPIRequestSucceeded(String requestType) {
Response rs = (Response) Globals.globalVariables.get(requestType); Response rs = (Response) Globals.globalVariables.get(requestType);
Assert.assertTrue( Assert.assertTrue("Actual Response Code is " + rs.getStatusCode() + " vs Expected Response Code 200", String.valueOf(rs.getStatusCode()).equals("200"));
"Actual Response Code is " + rs.getStatusCode() + " vs Expected Response Code 200",
String.valueOf(rs.getStatusCode()).equals("200"));
} }
@Given("I have a profile with <emailId> emailid") @Given("I have a profile with <emailId> emailid")
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment