How to use ObjectMapper method of com.consol.citrus.remote.plugin.RunTestMojo class

Best Citrus code snippet using com.consol.citrus.remote.plugin.RunTestMojo.ObjectMapper

Source:RunTestMojo.java Github

copy

Full Screen

...20import com.consol.citrus.remote.model.RemoteResult;21import com.consol.citrus.remote.plugin.config.RunConfiguration;22import com.consol.citrus.report.*;23import com.consol.citrus.util.FileUtils;24import com.fasterxml.jackson.databind.ObjectMapper;25import org.apache.http.*;26import org.apache.http.client.methods.RequestBuilder;27import org.apache.http.client.utils.HttpClientUtils;28import org.apache.http.entity.ContentType;29import org.apache.http.entity.StringEntity;30import org.apache.http.message.BasicHeader;31import org.apache.http.util.EntityUtils;32import org.apache.maven.plugin.MojoExecutionException;33import org.apache.maven.plugin.MojoFailureException;34import org.apache.maven.plugins.annotations.*;35import java.io.*;36import java.net.URLEncoder;37import java.util.List;38import java.util.stream.Collectors;39import java.util.stream.Stream;40/**41 * @author Christoph Deppisch42 * @since 2.7.443 */44@Mojo(name = "test", defaultPhase = LifecyclePhase.INTEGRATION_TEST, requiresDependencyResolution = ResolutionScope.TEST)45public class RunTestMojo extends AbstractCitrusRemoteMojo {46 /** Global url encoding */47 private static final String ENCODING = "UTF-8";48 @Parameter(property = "citrus.remote.skip.test", defaultValue = "false")49 protected boolean skipRun;50 /**51 * Run configuration for test execution on remote server.52 */53 @Parameter54 private RunConfiguration run;55 /**56 * Object mapper for JSON response to object conversion.57 */58 private ObjectMapper objectMapper = new ObjectMapper();59 @Override60 public void doExecute() throws MojoExecutionException, MojoFailureException {61 if (skipRun) {62 return;63 }64 if (run == null) {65 run = new RunConfiguration();66 }67 if (!run.hasClasses() && !run.hasPackages()) {68 runAllTests();69 }70 if (run.hasClasses()) {71 runClasses(run.getClasses());72 }73 if (run.hasPackages()) {74 runPackages(run.getPackages());75 }76 }77 private void runPackages(List<String> packages) throws MojoExecutionException {78 TestRunConfiguration runConfiguration = new TestRunConfiguration();79 runConfiguration.setPackages(packages);80 if (run.getIncludes() != null) {81 runConfiguration.setIncludes(run.getIncludes().toArray(new String[run.getIncludes().size()]));82 }83 if (run.getSystemProperties() != null) {84 runConfiguration.addDefaultProperties(run.getSystemProperties());85 }86 runTests(runConfiguration);87 }88 private void runClasses(List<String> classes) throws MojoExecutionException {89 TestRunConfiguration runConfiguration = new TestRunConfiguration();90 runConfiguration.setTestClasses(classes.stream()91 .map(TestClass::fromString)92 .collect(Collectors.toList()));93 if (run.getSystemProperties() != null) {94 runConfiguration.addDefaultProperties(run.getSystemProperties());95 }96 runTests(runConfiguration);97 }98 private void runAllTests() throws MojoExecutionException {99 TestRunConfiguration runConfiguration = new TestRunConfiguration();100 if (run.getIncludes() != null) {101 runConfiguration.setIncludes(run.getIncludes().toArray(new String[run.getIncludes().size()]));102 }103 if (run.getSystemProperties() != null) {104 runConfiguration.addDefaultProperties(run.getSystemProperties());105 }106 runTests(runConfiguration);107 }108 /**109 * Invokes run tests remote service and provide response message. If async mode is used the service is called with request method PUT110 * that creates a new run job on the server. The test results are then polled with multiple requests instead of processing the single synchronous response.111 *112 * @param runConfiguration113 * @return114 * @throws MojoExecutionException115 */116 private void runTests(TestRunConfiguration runConfiguration) throws MojoExecutionException {117 HttpResponse response = null;118 try {119 RequestBuilder requestBuilder;120 if (run.isAsync()) {121 requestBuilder = RequestBuilder.put(getServer().getUrl() + "/run");122 } else {123 requestBuilder = RequestBuilder.post(getServer().getUrl() + "/run");124 }125 requestBuilder.addHeader(new BasicHeader(HttpHeaders.ACCEPT, ContentType.APPLICATION_JSON.getMimeType()));126 StringEntity body = new StringEntity(new ObjectMapper().writeValueAsString(runConfiguration), ContentType.APPLICATION_JSON);127 requestBuilder.setEntity(body);128 response = getHttpClient().execute(requestBuilder.build());129 if (HttpStatus.SC_OK != response.getStatusLine().getStatusCode()) {130 throw new MojoExecutionException("Failed to run tests on remote server: " + EntityUtils.toString(response.getEntity()));131 }132 if (run.isAsync()) {133 HttpClientUtils.closeQuietly(response);134 handleTestResults(pollTestResults());135 } else {136 handleTestResults(objectMapper.readValue(response.getEntity().getContent(), RemoteResult[].class));137 }138 } catch (IOException e) {139 throw new MojoExecutionException("Failed to run tests on remote server", e);140 } finally {...

Full Screen

Full Screen

ObjectMapper

Using AI Code Generation

copy

Full Screen

1public class TestRunner {2 public void test() {3 Citrus citrus = Citrus.newInstance();4 TestRunner runner = citrus.createTestRunner();5 runner.http()6 .client()7 .send()

Full Screen

Full Screen

ObjectMapper

Using AI Code Generation

copy

Full Screen

1public String runTest(String testFile, String testClass, String testMethod, String testArgs, String testReportDir) throws Exception {2 String testReport = runTest(testFile, testClass, testMethod, testArgs);3 String testReportFile = testReportDir + "/" + testMethod + ".md";4 Files.write(Paths.get(testReportFile), testReport.getBytes());5 return testReportFile;6}7< plugin > < groupId >com.consol.citrus</ groupId > < artifactId >citrus-remote-plugin</ artifactId > < version >2.7.10</ version > < executions > < execution > < id >run-test</ id > < goals > < goal >run-test</ goal > </ goals > < configuration > < testFile >${project.basedir}/src/test/resources/citrus/citrus-test.xml</ testFile > < testClass >com.consol.citrus.remote.plugin.RunTestMojoTest</ testClass > < testMethod >runTest</ testMethod > < testArgs >${project.basedir}/src/test/resources/citrus/citrus-test.xml com.consol.citrus.remote.plugin.RunTestMojoTest runTest ${project.basedir}/src/test/resources/citrus/citrus-test.xml ${project.build.directory}/citrus-reports</ testArgs > </ configuration > </ execution > </ executions > </ plugin >

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 Citrus 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