How to use builder method of com.qaprosoft.carina.core.foundation.api.APIMethodPoller class

Best Carina code snippet using com.qaprosoft.carina.core.foundation.api.APIMethodPoller.builder

Source:AbstractApiMethodV2.java Github

copy

Full Screen

...19import java.net.URL;20import java.util.ArrayList;21import java.util.List;22import java.util.Properties;23import com.qaprosoft.apitools.builder.PropertiesProcessor;24import com.qaprosoft.apitools.validation.JsonComparatorContext;25import com.qaprosoft.apitools.validation.JsonKeywordsComparator;26import com.qaprosoft.apitools.validation.JsonValidator;27import com.qaprosoft.apitools.validation.XmlCompareMode;28import com.qaprosoft.apitools.validation.XmlValidator;29import com.qaprosoft.carina.core.foundation.api.log.LoggingOutputStream;30import org.json.JSONException;31import org.skyscreamer.jsonassert.JSONAssert;32import org.skyscreamer.jsonassert.JSONCompareMode;33import org.slf4j.Logger;34import org.slf4j.LoggerFactory;35import com.qaprosoft.apitools.builder.PropertiesProcessorMain;36import com.qaprosoft.apitools.message.TemplateMessage;37import com.qaprosoft.carina.core.foundation.api.annotation.ContentType;38import com.qaprosoft.carina.core.foundation.api.annotation.RequestTemplatePath;39import com.qaprosoft.carina.core.foundation.api.annotation.ResponseTemplatePath;40import com.qaprosoft.carina.core.foundation.api.annotation.SuccessfulHttpStatus;41import io.restassured.response.Response;42public abstract class AbstractApiMethodV2 extends AbstractApiMethod {43 private static final Logger LOGGER = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());44 45 private static final String ACCEPT_ALL_HEADER = "Accept=*/*";46 private Properties properties;47 private List<Class<? extends PropertiesProcessor>> ignoredPropertiesProcessorClasses;48 private String rqPath;49 private String rsPath;50 private String actualRsBody;51 /**52 * When this constructor is called then paths to request and expected response templates are taken from @RequestTemplatePath53 * and @ResponseTemplatePath if present54 */55 public AbstractApiMethodV2() {56 super();57 setHeaders(ACCEPT_ALL_HEADER);58 initPathsFromAnnotation();59 setProperties(new Properties());60 }61 public AbstractApiMethodV2(String rqPath, String rsPath, String propertiesPath) {62 super();63 setHeaders(ACCEPT_ALL_HEADER);64 setProperties(propertiesPath);65 this.rqPath = rqPath;66 this.rsPath = rsPath;67 }68 public AbstractApiMethodV2(String rqPath, String rsPath, Properties properties) {69 super();70 setHeaders(ACCEPT_ALL_HEADER);71 if (properties != null) {72 this.properties = PropertiesProcessorMain.processProperties(properties, ignoredPropertiesProcessorClasses);73 }74 this.rqPath = rqPath;75 this.rsPath = rsPath;76 }77 public AbstractApiMethodV2(String rqPath, String rsPath) {78 this(rqPath, rsPath, new Properties());79 }80 private void initPathsFromAnnotation() {81 RequestTemplatePath requestTemplatePath = this.getClass().getAnnotation(RequestTemplatePath.class);82 if (requestTemplatePath != null) {83 this.rqPath = requestTemplatePath.path();84 }85 ResponseTemplatePath responseTemplatePath = this.getClass().getAnnotation(ResponseTemplatePath.class);86 if (responseTemplatePath != null) {87 this.rsPath = responseTemplatePath.path();88 }89 }90 /**91 * Sets path to freemarker template for request body92 * 93 * @param path String94 */95 public void setRequestTemplate(String path) {96 this.rqPath = path;97 }98 /**99 * Sets path to freemarker template for expected response body100 * 101 * @param path String102 */103 public void setResponseTemplate(String path) {104 this.rsPath = path;105 }106 private void initBodyContent() {107 if (rqPath != null) {108 TemplateMessage tm = new TemplateMessage();109 tm.setIgnoredPropertiesProcessorClasses(ignoredPropertiesProcessorClasses);110 tm.setTemplatePath(rqPath);111 tm.setPropertiesStorage(properties);112 setBodyContent(tm.getMessageText());113 }114 }115 @Override116 public Response callAPI() {117 initBodyContent();118 Response rs = super.callAPI();119 actualRsBody = rs.asString();120 return rs;121 }122 @Override123 Response callAPI(LoggingOutputStream outputStream) {124 initBodyContent();125 Response rs = super.callAPI(outputStream);126 actualRsBody = rs.asString();127 return rs;128 }129 /**130 * Allows to create an api request with repetition, timeout and condition of successful response, as well as setting131 * a logging strategy132 *133 * @return APIMethodPoller object134 */135 public APIMethodPoller callAPIWithRetry() {136 initBodyContent();137 return APIMethodPoller.builder(this)138 .doAfterExecute(response -> actualRsBody = response.asString());139 }140 /**141 * Calls API expecting http status in response taken from @SuccessfulHttpStatus value142 * 143 * @return restassured Response object144 */145 public Response callAPIExpectSuccess() {146 SuccessfulHttpStatus successfulHttpStatus = this.getClass().getAnnotation(SuccessfulHttpStatus.class);147 if (successfulHttpStatus == null) {148 throw new RuntimeException("To use this method please declare @SuccessfulHttpStatus for your AbstractApiMethod class");149 }150 expectResponseStatus(successfulHttpStatus.status());151 return callAPI();...

Full Screen

Full Screen

Source:APIMethodPoller.java Github

copy

Full Screen

...20 ALL, LAST_ONLY, NONE21 }22 private APIMethodPoller(AbstractApiMethodV2 method) {23 this.method = method;24 this.actionPoller = ActionPoller.builder();25 }26 public static APIMethodPoller builder(AbstractApiMethodV2 method) {27 return new APIMethodPoller(method);28 }29 /**30 * Sets the repetition interval for the api calling31 *32 * @param period repetition interval33 * @param timeUnit time unit34 * @return APIMethodPoller object35 */36 public APIMethodPoller pollEvery(long period, TemporalUnit timeUnit) {37 this.actionPoller.pollEvery(period, timeUnit);38 return this;39 }40 /**...

Full Screen

Full Screen

builder

Using AI Code Generation

copy

Full Screen

1package com.qaprosoft.carina.demo.api;2import org.apache.log4j.Logger;3import org.testng.Assert;4import org.testng.annotations.Test;5import com.qaprosoft.carina.core.foundation.api.AbstractApiMethodV2;6import com.qaprosoft.carina.core.foundation.api.AbstractApiTest;7import com.qaprosoft.carina.core.foundation.api.http.HttpResponseStatusType;8import com.qaprosoft.carina.core.foundation.utils.R;9import com.qaprosoft.carina.core.foundation.utils.ownership.MethodOwner;10import com.qaprosoft.carina.demo.api.user.CreateUserMethod;11import com.qaprosoft.carina.demo.api.user.DeleteUserMethod;12import com.qaprosoft.carina.demo.api.user.GetUserMethod;13import com.qaprosoft.carina.demo.api.user.UpdateUserMethod;14public class APIMethodPollerTest extends AbstractApiTest {15 private static final Logger LOGGER = Logger.getLogger(APIMethodPollerTest.class);16 @MethodOwner(owner = "qpsdemo")17 public void testCreateUser() {18 CreateUserMethod createUserMethod = new CreateUserMethod();19 createUserMethod.expectResponseStatus(HttpResponseStatusType.OK_200);20 apiExecutor.expectStatus(createUserMethod, HttpResponseStatusType.OK_200);21 apiExecutor.callApiMethod(createUserMethod);22 apiExecutor.validateResponse(createUserMethod, HttpResponseStatusType.OK_200);23 Assert.assertTrue(createUserMethod.validateResponse(), "Response doesn't contain all required fields!");24 Assert.assertEquals(createUserMethod.getExpectedResponseStatus(), HttpResponseStatusType.OK_200, "Response status doesn't match!");25 int userId = createUserMethod.getUserId();26 Assert.assertTrue(userId > 0, "User id is not positive!");27 LOGGER.info("User id: " + userId);28 GetUserMethod getUserMethod = new GetUserMethod(userId);29 getUserMethod.expectResponseStatus(HttpResponseStatusType.OK_200);30 apiExecutor.expectStatus(getUserMethod, HttpResponseStatusType.OK_200);31 apiExecutor.callApiMethod(getUserMethod);32 apiExecutor.validateResponse(getUserMethod, HttpResponseStatusType.OK_200);33 Assert.assertTrue(getUserMethod.validateResponse(), "Response doesn't contain all required fields!");34 Assert.assertEquals(getUserMethod.getExpectedResponseStatus(), HttpResponseStatusType.OK_200, "Response status doesn't match!");35 Assert.assertEquals(getUserMethod.getUser().getId(), userId, "User id doesn't match!");36 Assert.assertEquals(getUserMethod.getUser().getUsername(), R.TEST

Full Screen

Full Screen

builder

Using AI Code Generation

copy

Full Screen

1import com.qaprosoft.carina.core.foundation.api.AbstractApiMethodV2;2import com.qaprosoft.carina.core.foundation.api.APIMethodPoller;3import com.qaprosoft.carina.core.foundation.api.http.HttpResponseStatusType;4import com.qaprosoft.carina.core.foundation.utils.Configuration;5import com.qaprosoft.carina.core.foundation.utils.R;6import com.qaprosoft.carina.core.foundation.utils.ownership.MethodOwner;7import com.qaprosoft.carina.core.foundation.utils.tag.Tag;8import com.qaprosoft.carina.core.foundation.utils.tag.TagType;9import com.qaprosoft.carina.core.foundation.webdriver.decorator.ExtendedWebElement;10import com.qaprosoft.carina.core.foundation.webdriver.decorator.PageOpeningStrategy;11import com.qaprosoft.carina.core.foundation.webdriver.decorator.PageOpeningStrategy.OpeningStrategy;12import com.qaprosoft.carina.core.foundation.webdriver.decorator.PageOpeningStrategy.ThreadStrategy;13import com.qaprosoft.carina.core.foundation.webdriver.decorator.Visible;14import com.qaprosoft.carina.core.foundation.webdriver.locator.ExtendedFindBy;15import com.qaprosoft.carina.core.foundation.webdriver.listener.EventFiringDecorator;16import com.qaprosoft.carina.core.foundation.webdriver.listener.EventFiringDecoratorImpl;17import com.qaprosoft.carina.core.foundation.webdriver.listener.EventListener;18import com.qaprosoft.carina.core.foundation.webdriver.listener.EventListenerImpl;19import com.qaprosoft.carina.core.foundation.webdriver.listener.ScreenshotOnFailureListener;20import com.qaprosoft.carina.core.foundation.webdriver.report.ReportContext;21import com.qaprosoft.carina.core.foundation.webdriver.report.ReportContext.ReportContextKey;22import com.qaprosoft.carina.core.foundation.webdriver.report.ReportContext.ReportContextValue;23import com.qaprosoft.carina.core.foundation.webdriver.report.ReportContext.ReportItemStatus;24import com.qaprosoft.carina.core.foundation.webdriver.report.ReportContext.ReportLevel;25import com.qaprosoft.carina.core.foundation.webdriver.report.ReportContext.ReportType;26import com.qaprosoft.carina.core.foundation.webdriver.report.ReportContext.ReportType.ReportTypeKey;27import com.qaprosoft.carina.core.foundation.webdriver.report.ReportContext.ReportType.ReportTypeValue;28import com.qaprosoft.carina.core.foundation.webdriver.report.ReportContext.ReportType.ReportTypeValue.ReportTypeValueKey;29import com.qaprosoft.carina.core.foundation.webdriver.report.ReportContext.ReportType.ReportTypeValue.ReportTypeValueValue;30import com.qaprosoft.carina.core.foundation.webdriver.report.ReportContext.ReportType.ReportTypeValue.ReportTypeValueValue

Full Screen

Full Screen

builder

Using AI Code Generation

copy

Full Screen

1package com.qaprosoft.carina.core.foundation.api;2import org.testng.Assert;3import org.testng.annotations.Test;4import com.qaprosoft.carina.core.foundation.api.http.HttpResponseStatusType;5public class APIMethodPollerTest {6 public void testPollMethod() {7 APIMethodPoller apiPoller = APIMethodPoller.builder().withMethod(new GetMethod()).withPollingInterval(2000)8 .withPollingTimeout(10000).withSuccessStatuses(HttpResponseStatusType.OK_200).build();9 apiPoller.pollMethod();10 Assert.assertTrue(apiPoller.isPollingSucceeded(), "API polling failed");11 }12}13package com.qaprosoft.carina.core.foundation.api;14import org.testng.Assert;15import org.testng.annotations.Test;16import com.qaprosoft.carina.core.foundation.api.http.HttpResponseStatusType;17import com.qaprosoft.carina.core.foundation.utils.Configuration;18public class GetMethodTest {19 public void testGet() {20 GetMethod getMethod = new GetMethod();21 getMethod.expectResponseStatus(HttpResponseStatusType.OK_200);22 getMethod.callAPI();23 getMethod.validateResponse();24 Assert.assertEquals(getMethod.getStatusCode(), HttpResponseStatusType.OK_200.getCode());25 }26 public void testGetWithParams() {27 GetMethod getMethod = new GetMethod();28 getMethod.expectResponseStatus(HttpResponseStatusType.OK_200);29 getMethod.addParameter("name", "value");30 getMethod.callAPI();31 getMethod.validateResponse();32 Assert.assertEquals(getMethod.getStatusCode(), HttpResponseStatusType.OK_200.getCode());33 }34 public void testGetWithParamsAndPath() {35 GetMethod getMethod = new GetMethod();36 getMethod.expectResponseStatus(HttpResponseStatusType.OK_200);37 getMethod.addParameter("name", "value");38 getMethod.addProperty("path", "path");39 getMethod.callAPI();40 getMethod.validateResponse();41 Assert.assertEquals(getMethod.getStatusCode(), HttpResponseStatusType.OK_200.getCode());42 }43 public void testGetWithParamsAndPathAndHeaders() {44 GetMethod getMethod = new GetMethod();45 getMethod.expectResponseStatus(HttpResponseStatusType.OK_200);46 getMethod.addParameter("name", "value");47 getMethod.addProperty("path", "path");48 getMethod.addHeader("header", "value");

Full Screen

Full Screen

builder

Using AI Code Generation

copy

Full Screen

1public class PollingAPI extends APIMethod {2private static final String METHOD = "GET";3public PollingAPI() {4 super(null, METHOD, URI, null, null);5}6public void executeAPI() {7 APIMethodPoller.poll(this, 1000, 10000, 3);8}9public void validateResponse() {10 Assert.assertEquals(getResponse().getStatusCode(), 200, "Response code is not 200!");11 Assert.assertTrue(getResponse().asString().contains("pulls"), "Response doesn't contain 'pulls'!");12}13}14public class PollingAPI extends AbstractApiMethod {15private static final String METHOD = "GET";16public PollingAPI() {17 super(null, METHOD, URI, null, null);18}19public void executeAPI() {20 poll(this, 1000, 10000, 3);21}22public void validateResponse() {23 Assert.assertEquals(getResponse().getStatusCode(), 200, "Response code is not 200!");24 Assert.assertTrue(getResponse().asString().contains("pulls"), "Response doesn't contain 'pulls'!");25}26}27public class PollingAPI extends AbstractApiMethod {28private static final String METHOD = "GET";29public PollingAPI() {30 super(null, METHOD, URI, null, null);31}32public void executeAPI() {33 poll(this, 1000, 10000, 3);34}35public void validateResponse() {36 Assert.assertEquals(getResponse().getStatusCode(), 200, "Response code is not 200!");37 Assert.assertTrue(getResponse().asString().contains("pulls"), "Response doesn't contain 'pulls'!");38}39}

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Carina automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful