Untitled
unknown
plain_text
23 days ago
7.2 kB
5
Indexable
@When("I make a successful IPVS lineupv1 call with {string} and {string}") public void call_api_smarttv_lineupv1 (String account, String mso) { ResponseData.setData("accountId", account); ResponseData.setData("mso", mso); ServiceApiResponse response = restIPVS().apiSmarttvLineupV1(account,mso,"1.2.3.4").get(); ResponseData.setResponse("apiSmarttvLineupV1", Objects.requireNonNull(response.json())); assertTrue(response.status().isSuccess(), response.uri() + " call is failing with " + response.status() + " and TXID: " + response.txId()); assertNotNull(response.json().get("market"), "Required field 'market' not found"); assertNotNull(response.json().get("lineupId"), "Required field 'lineupID' not found"); assertNotNull(response.json().get("headend"), "Required field 'headend' not found"); assertNotNull(response.json().get("vodId"), "Required field 'vodId' not found"); } @Then("the IPVS lineupv1 response should match the SAINT apicustomer response") public void match_lineupv1_with_saint_customer_call() { JSON ipvsResponse = ResponseData.getResponse("apiSmarttvLineupV1"); ServiceApiResponse saintResponse = restSAINT().apiCustomer("1.2.3.4", ResponseData.getData("accountId"), "marketlineup", ResponseData.getData("mso")).get(); assertTrue(saintResponse.status().isSuccess(), saintResponse.uri() + " call is failing with " + saintResponse.status() + " and TXID: " + saintResponse.txId()); MarketLineup saintLineup = new GsonBuilder().create().fromJson(saintResponse.json().get("marketLineup").toString(), MarketLineup.class); assertNotNull(saintLineup.market, "Required field 'market' not found"); assertNotNull(saintLineup.lineupId, "Required field 'lineupID' not found"); assertEquals(ipvsResponse.get("market").toString(), saintLineup.market, "Market value does not match; Saint response ID: " + saintResponse.txId()); assertEquals(ipvsResponse.get("vodId").toString(), saintLineup.market, "Market value does not match; Saint response ID: " + saintResponse.txId()); assertEquals(ipvsResponse.get("lineupId").toString(), saintLineup.lineupId.toString(), "Market value does not match; Saint response ID: " + saintResponse.txId()); assertEquals(ipvsResponse.get("headend").toString(), saintLineup.market+"_"+saintLineup.lineupId, "Market value does not match; Saint response ID: " + saintResponse.txId()); } public IPVSApiController apiSmarttvLineupV1 (String xAccountId, String xMso, String xPiForwardedFor) { request.reset(); request.path(API); request.path(SMARTTV); request.path(LINEUP); request.path(V1); headerXAccountid(xAccountId); headerXMso(xMso); headerXPiForwardedFor(xPiForwardedFor); return this; } package sth; import org.apache.commons.io.IOUtils; import org.testng.Assert; import sth.http.ServiceResponse; import sth.http.client.Request; import sth.http.client.Response; import sth.http.common.HttpStatus; import sth.json.JSON; import sth.xml.XML; import java.io.IOException; import java.nio.charset.StandardCharsets; /** * A wrapper around the Request/Response dialog between HTTP client and server. For specific * use cases further methods could be added (for example to deserialize proprietary formats). */ public class ServiceApiResponse implements ServiceResponse { private Request request; private Response response; public ServiceApiResponse(Request request, Response response) { this.request = request; this.response = response; } public String txId() {return request.getHeader("x-request-id");} /** * Get the {@link Request} object that was executed to create the {@link Response} */ public Request request() { return request; } /** * Get the underlying {@link Response} object */ public Response response() { return response; } /** * True if the response status code is in the success range (200-299) */ public boolean isSuccess() { return response.status().isSuccess(); } /** * Assert that the response status code was in the success range (200-299) */ public ServiceApiResponse assertSuccess() { String errorMessage = "Request failed with status code " + response.status() + "\nRequest URL: " + request.uri() + "\nTime: " + System.currentTimeMillis() + " ; TxId: " + header("x-trace-id"); if (response.getHeader("X-Failure-Message") != null) errorMessage = errorMessage + "\nX-Failure-Message: " + header("X-Failure-Message"); if (response.getHeader("Failure-Trace") != null) errorMessage = errorMessage + "\nFailure-Trace: " + header("Failure-Trace"); try { if (response.getBody() != null) errorMessage = errorMessage + "\nBody: " + IOUtils.toString(response.bodyInputStream(), StandardCharsets.UTF_8).replaceAll("<.*?>", ""); } catch (IOException e){System.out.println("VSIERROR, IOUtils.toString: " + e.getMessage());} Assert.assertTrue(isSuccess(), errorMessage); return this; } /** * True if the response status code is in the error range (>=400) */ public boolean isError() { return response.status().isError(); } /** * Parse the response body to a JSON object */ public JSON json() { return response.as(JSON.class); } /** * Parse the response body to an XML object */ public XML xml() { return response.as(XML.class); } /** * Get the response body as a String */ public String responseString() { return response.as(String.class); } /** * Get HTTP status from response */ public HttpStatus status() { return response.status(); } /** * Get the HTTP status code of the response */ public int statusCode() { return response.status().code(); } /** * Get the request URI that was executed */ public String uri() { return request.uri().toString(); } /** * Get a response header */ public String header(String headerName) { return response.header(headerName); } @Override public String toString() { String contentType = response.header("content-type"); if (contentType.contains("json")) { return json().toString(3); } else if (contentType.contains("xml")) { return xml().toString(3); } else { return responseString(); } } } feature file: @Integration @API Scenario Outline: lineups/v1 - EMC When I make a successful IPVS lineupv1 call with "<account>" and "<MSO>" Then the IPVS lineupv1 response should match the SAINT apicustomer response Examples: | account | MSO | | LNK.8347:8347100040106596 | TWC | | CHARTER.8286:8286101621622343 | CHARTER |
Editor is loading...
Leave a Comment