Commit 3c03a258 authored by Rakesh Mareddy's avatar Rakesh Mareddy

Update ProfileAPISteps.java

parent 848fee14
package com.nisum.napt.projects.demo.apidemo.steps;
import com.google.gson.Gson; import com.google.gson.Gson;
import com.napt.framework.api.runner.EnvVariables; import com.napt.framework.api.runner.EnvVariables;
import com.nisum.api.ApiEngine; import com.nisum.api.ApiEngine;
...@@ -7,88 +9,88 @@ import io.cucumber.java.en.Given; ...@@ -7,88 +9,88 @@ 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();
private static final Logger log = Logger.getLogger(ProfileAPISteps.class);
public static String webUrl = EnvVariables.getEnvVariables().get("webURL");
private static Response response;
private String customerURI = "/resources/customers";
private String customerSearchURI = "/resources/customers/search";
private String userEmailId = "";
private String body;
@Given("I have all the profile headers configured") ApiEngine api = new ApiEngine();
public void iHaveAllTheProfileHeadersConfigured() throws Throwable { private static final Logger log = Logger.getLogger(ProfileAPISteps.class);
set_header_param("headers.Content-Type", "application/json"); public static String webUrl = EnvVariables.getEnvVariables().get("webURL");
set_header_param("headers.Accept", "application/json"); private static Response response;
set_header_param("headers.Authorization", "Basic cHJlZWNvbXdzY2xpZW50OlBAc3N3b3JkJDE="); private String customerURI = "/resources/customers";
set_header_param("base_url.url", "http://ws-profile.vdev.gid.gap.com"); private String customerSearchURI = "/resources/customers/search";
} private String userEmailId = "";
private String body;
private void set_header_param(String dictionaryKey, String value) throws Throwable { @Given("I have all the profile headers configured")
String[] paramCategory = dictionaryKey.split("\\."); public void iHaveAllTheProfileHeadersConfigured() throws Throwable {
switch(paramCategory[0]) { set_header_param("headers.Content-Type", "application/json");
case "headers": set_header_param("headers.Accept", "application/json");
Globals.headers.put(paramCategory[1],value); set_header_param("headers.Authorization", "Basic cHJlZWNvbXdzY2xpZW50OlBAc3N3b3JkJDE=");
break; set_header_param("base_url.url", "http://ws-profile.vdev.gid.gap.com");
case "base_url": }
Globals.globalVariables.put(paramCategory[1],value);
break;
}
}
@Given("I have all the data required for a profile creation") private void set_header_param(String dictionaryKey, String value) throws Throwable {
public void iHaveAllTheDataRequiredForAProfileCreation(Map<String,String> userinfo) { String[] paramCategory = dictionaryKey.split("\\.");
HashMap<String, String> userdata = new HashMap<String, String>(); switch (paramCategory[0]) {
userdata.putAll(userinfo); case "headers":
String randomizeEmail = new StringBuilder().append(Instant.now().toEpochMilli()).append(userinfo.get("emailAddress")).toString(); Globals.headers.put(paramCategory[1], value);
userdata.replace("emailAddress", randomizeEmail); break;
Gson gson = new Gson(); case "base_url":
this.body = gson.toJson(userdata); Globals.globalVariables.put(paramCategory[1], value);
break;
} }
}
@When("^I (GET|PUT|POST|PATCH) the request to (.*) profile$") @Given("I have all the data required for a profile creation")
public void iHitTheAPIRequestToPOSTCreateProfile(String apiType, String requestType) throws URISyntaxException { public void iHaveAllTheDataRequiredForAProfileCreation(Map<String, String> userinfo) {
String URI; HashMap<String, String> userdata = new HashMap<>(userinfo);
switch (requestType){ String randomizeEmail = Instant.now().toEpochMilli()
case "create": + userinfo.get("emailAddress");
URI = customerURI; break; userdata.replace("emailAddress", randomizeEmail);
case "search": Gson gson = new Gson();
URI = customerSearchURI; break; this.body = gson.toJson(userdata);
default: }
URI = "NOPATHYET";
}
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") @When("^I (GET|PUT|POST|PATCH) the request to (.*) profile$")
public void iShouldSeeAPIRequestSucceeded(String requestType) { public void iHitTheAPIRequestToPOSTCreateProfile(String apiType, String requestType)
Response rs = (Response) Globals.globalVariables.get(requestType); throws URISyntaxException {
Assert.assertTrue("Actual Response Code is " + rs.getStatusCode() + " vs Expected Response Code 200", String.valueOf(rs.getStatusCode()).equals("200")); String URI = switch (requestType) {
} case "create" -> customerURI;
case "search" -> customerSearchURI;
default -> "NOPATHYET";
};
Response rs = api.callAPI(apiType, Globals.headers, body.toString(),
Globals.globalVariables.get("url").toString() + customerURI);
Globals.globalVariables.put(requestType, rs);
}
@Given("I have a profile with <emailId> emailid") @Then("I should see (.*) profile succeeded")
public void iHaveAProfileWithEmailIdEmailid() { public void iShouldSeeAPIRequestSucceeded(String requestType) {
} Response rs = (Response) Globals.globalVariables.get(requestType);
Assert.assertTrue(
"Actual Response Code is " + rs.getStatusCode() + " vs Expected Response Code 200",
String.valueOf(rs.getStatusCode()).equals("200"));
}
@And("I prepare the request to POST retrieve profile") @Given("I have a profile with <emailId> emailid")
public void iPrepareTheRequestToPOSTRetrieveProfile() { public void iHaveAProfileWithEmailIdEmailid() {
} }
@Then("I should see the profile information retrieved") @And("I prepare the request to POST retrieve profile")
public void iShouldSeeTheProfileInformationRetrieved() { public void iPrepareTheRequestToPOSTRetrieveProfile() {
} }
@Then("I should see the profile information retrieved")
public void iShouldSeeTheProfileInformationRetrieved() {
}
} }
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