How to use RunConfiguration class of com.consol.citrus.remote.plugin.config package

Best Citrus code snippet using com.consol.citrus.remote.plugin.config.RunConfiguration

Source:RunTestMojo.java Github

copy

Full Screen

...15 */16package com.consol.citrus.remote.plugin;17import com.consol.citrus.TestClass;18import com.consol.citrus.exceptions.CitrusRuntimeException;19import com.consol.citrus.main.TestRunConfiguration;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 {141 HttpClientUtils.closeQuietly(response);142 }143 }144 /**145 * When using async test execution mode the client does not synchronously wait for test results as it might lead to read timeouts. Instead146 * this method polls for test results and waits for the test execution to completely finish.147 *148 * @return149 * @throws MojoExecutionException150 */151 private RemoteResult[] pollTestResults() throws MojoExecutionException {152 HttpResponse response = null;153 try {154 do {155 HttpClientUtils.closeQuietly(response);156 response = getHttpClient().execute(RequestBuilder.get(getServer().getUrl() + "/results")157 .addHeader(new BasicHeader(HttpHeaders.ACCEPT, ContentType.APPLICATION_JSON.getMimeType()))158 .addParameter("timeout", String.valueOf(run.getPollingInterval()))159 .build());160 if (HttpStatus.SC_PARTIAL_CONTENT == response.getStatusLine().getStatusCode()) {161 getLog().info("Waiting for remote tests to finish ...");162 getLog().info(Stream.of(objectMapper.readValue(response.getEntity().getContent(), RemoteResult[].class))163 .map(RemoteResult::toTestResult).map(result -> result.isSkipped() ? "x" : (result.isSuccess() ? "+" : "-")).collect(Collectors.joining()));164 }165 } while (HttpStatus.SC_PARTIAL_CONTENT == response.getStatusLine().getStatusCode());166 if (HttpStatus.SC_OK != response.getStatusLine().getStatusCode()) {167 throw new MojoExecutionException("Failed to get test results from remote server: " + EntityUtils.toString(response.getEntity()));168 }169 return objectMapper.readValue(response.getEntity().getContent(), RemoteResult[].class);170 } catch (IOException e) {171 throw new MojoExecutionException("Failed to get test results from remote server", e);172 } finally {173 HttpClientUtils.closeQuietly(response);174 }175 }176 /**177 * Check test results for failures.178 * @param results179 * @throws IOException180 */181 private void handleTestResults(RemoteResult[] results) {182 StringWriter resultWriter = new StringWriter();183 resultWriter.append(String.format("%n"));184 OutputStreamReporter reporter = new OutputStreamReporter(resultWriter);185 Stream.of(results).forEach(result -> reporter.getTestResults().addResult(RemoteResult.toTestResult(result)));186 reporter.generateTestResults();187 getLog().info(resultWriter.toString());188 if (getReport().isHtmlReport()) {189 HtmlReporter htmlReporter = new HtmlReporter();190 htmlReporter.setReportDirectory(getOutputDirectory().getPath() + File.separator + getReport().getDirectory());191 Stream.of(results).forEach(result -> htmlReporter.getTestResults().addResult(RemoteResult.toTestResult(result)));192 htmlReporter.generateTestResults();193 }194 SummaryReporter summaryReporter = new SummaryReporter();195 Stream.of(results).forEach(result -> summaryReporter.getTestResults().addResult(RemoteResult.toTestResult(result)));196 summaryReporter.setReportDirectory(getOutputDirectory().getPath() + File.separator + getReport().getDirectory());197 summaryReporter.setReportFileName(getReport().getSummaryFile());198 summaryReporter.generateTestResults();199 getAndSaveReports();200 }201 private void getAndSaveReports() {202 if (!getReport().isSaveReportFiles()) {203 return;204 }205 HttpResponse response = null;206 String[] reportFiles = {};207 try {208 response = getHttpClient().execute(RequestBuilder.get(getServer().getUrl() + "/results/files")209 .addHeader(new BasicHeader(HttpHeaders.ACCEPT, ContentType.APPLICATION_XML.getMimeType()))210 .build());211 if (HttpStatus.SC_OK != response.getStatusLine().getStatusCode()) {212 getLog().warn("Failed to get test reports from remote server");213 }214 reportFiles = objectMapper.readValue(response.getEntity().getContent(), String[].class);215 } catch (IOException e) {216 getLog().warn("Failed to get test reports from remote server", e);217 } finally {218 HttpClientUtils.closeQuietly(response);219 }220 File citrusReportsDirectory = new File(getOutputDirectory() + File.separator + getReport().getDirectory());221 if (!citrusReportsDirectory.exists()) {222 if (!citrusReportsDirectory.mkdirs()) {223 throw new CitrusRuntimeException("Unable to create reports output directory: " + citrusReportsDirectory.getPath());224 }225 }226 File junitReportsDirectory = new File(citrusReportsDirectory, "junitreports");227 if (!junitReportsDirectory.exists()) {228 if (!junitReportsDirectory.mkdirs()) {229 throw new CitrusRuntimeException("Unable to create JUnit reports directory: " + junitReportsDirectory.getPath());230 }231 }232 JUnitReporter jUnitReporter = new JUnitReporter();233 loadAndSaveReportFile(new File(citrusReportsDirectory, String.format(jUnitReporter.getReportFileNamePattern(), jUnitReporter.getSuiteName())), getServer().getUrl() + "/results/suite", ContentType.APPLICATION_XML.getMimeType());234 Stream.of(reportFiles)235 .map(reportFile -> new File(junitReportsDirectory, reportFile))236 .forEach(reportFile -> {237 try {238 loadAndSaveReportFile(reportFile, getServer().getUrl() + "/results/file/" + URLEncoder.encode(reportFile.getName(), ENCODING), ContentType.APPLICATION_XML.getMimeType());239 } catch (IOException e) {240 getLog().warn("Failed to get report file: " + reportFile.getName(), e);241 }242 });243 }244 /**245 * Get report file content from server and save content to given file on local file system.246 * @param reportFile247 * @param serverUrl248 * @param contentType249 */250 private void loadAndSaveReportFile(File reportFile, String serverUrl, String contentType) {251 HttpResponse fileResponse = null;252 try {253 fileResponse = getHttpClient().execute(RequestBuilder.get(serverUrl)254 .addHeader(new BasicHeader(HttpHeaders.ACCEPT, contentType))255 .build());256 if (HttpStatus.SC_OK != fileResponse.getStatusLine().getStatusCode()) {257 getLog().warn("Failed to get report file: " + reportFile.getName());258 return;259 }260 getLog().info("Writing report file: " + reportFile);261 FileUtils.writeToFile(fileResponse.getEntity().getContent(), reportFile);262 } catch (IOException e) {263 getLog().warn("Failed to get report file: " + reportFile.getName(), e);264 } finally {265 HttpClientUtils.closeQuietly(fileResponse);266 }267 }268 /**269 * Sets the tests.270 *271 * @param tests272 */273 public void setTests(RunConfiguration tests) {274 this.run = tests;275 }276}...

Full Screen

Full Screen

Source:RunConfiguration.java Github

copy

Full Screen

...20/**21 * @author Christoph Deppisch22 * @since 2.7.423 */24public class RunConfiguration {25 @Parameter26 private List<String> classes;27 @Parameter28 private List<String> packages;29 @Parameter30 private List<String> includes;31 @Parameter32 private Map<String, String> systemProperties;33 @Parameter(property = "citrus.remote.run.async", defaultValue = "false")34 private boolean async;35 @Parameter(property = "citrus.remote.run.polling.interval", defaultValue = "10000")36 private long pollingInterval = 10000L;37 /**38 * Gets the classes....

Full Screen

Full Screen

RunConfiguration

Using AI Code Generation

copy

Full Screen

1package com.consol.citrus.remote.plugin.config;2import com.consol.citrus.remote.plugin.config.RunConfiguration;3import com.consol.citrus.remote.plugin.config.RunConfigurationBuilder;4public class RunConfigurationTest {5 public static void main(String[] args) {6 RunConfiguration runConfiguration = new RunConfigurationBuilder()7 .withName("test")8 .withDescription("test description")9 .withJavaHome("C:/Java/jdk1.8.0_181")10 .withClasspath("C:/Java/jdk1.8.0_181/bin")11 .withClasspath("C:/Java/jdk1.8.0_181/jre/lib")12 .withClasspath("C:/Java/jdk1.8.0_181/lib/tools.jar")13 .withClasspath("C:Users/username/Downloads/apache-maven-3.5.4/bin")14 .withClasspath("C:/Users/username/Downloads/apache-maven-3.5.4/lib")15 .withClasspath("C:/Users/username/Downloads/apache-maven-3.5.4/conf")16 .withClasspath("C:/Users/username/Downloads/apache-maven-3.5.4/lib/ext")17 .withClasspath("C:/Users/username/Downloads/apache-maven-3.5.4/lib/sisu")18 .withClasspath("C:/Users/username/Downloads/apache-maven-3.5.4/lib/sisu-guice")19 .withClasspath("C:/Users/username/Downloads/apache-maven-3.5.4/lib/sisu-inject-bean")20 .withClasspath("C:/Users/username/Downloads/apache-maven-3.5.4/lib/sisu-inject-cglib")21 .withClasspath("C:/Users/username/Downloads/apache-maven-3.5.4/lib/sisu-inject-jsr330")22 .withClasspath("C:/Users/username/Downloads/apache-maven-3.5.4/lib/sisu-inject-plexus")23 .withClasspath("C:/Users/username/Downloads/apache-maven-3.5.4/lib/sisu-inject-soft")24 .withClasspath("C:/Users/username/Downloads/apache-maven-3.5.4/lib/sisu-plexus")

Full Screen

Full Screen

RunConfiguration

Using AI Code Generation

copy

Full Screen

1import com.consol.citrus.remote.plugin.config.RunConfiguration;2import com.consol.citrus.remote.plugin.config.RunConfigurationFactoryBean;3import com.consol.citrus.remote.plugin.config.RunConfigurationFactoryBean;4import org.springframework.context.ApplicationContext;5import org.springframework.context.support.ClassPathXmlApplicationContext;6public class RunConfigurationTest {7 public static void main(String[] args) {8 ApplicationContext context = new ClassPathXmlApplicationContext("classpath:applicationContext.xml");9 RunConfigurationFactoryBean runConfigurationFactoryBean = context.getBean(RunConfigurationFactoryBean.class);10 RunConfiguration runConfiguration = runConfigurationFactoryBean.getObject();11 System.out.println(runConfiguration.getTestName());12 System.out.println(runConfiguration.getTestPackage());13 System.out.println(runConfiguration.getTestGroups());14 System.out.println(runConfiguration.getTestAuthor());15 System.out.println(runConfiguration.getTestDescription());16 System.out.println(runConfiguration.getTestType());17 System.out.println(runConfiguration.getTestStatus());18 }19}

Full Screen

Full Screen

RunConfiguration

Using AI Code Generation

copy

Full Screen

1public class 4 {2 public static void main(String[] args) {3 RunConfiguration runConfiguration = new RunConfiguration();4 runConfiguration.setProjectPath("path to project");5 runConfiguration.setProjectName("project name");6 runConfiguration.setTestName("test name");7 runConfiguration.setTestCaseName("test case name");8 runConfiguration.setTestPackage("test package");9 runConfiguration.setTestGroup("test group");10 runConfiguration.setTestAuthor("test author");11 runConfiguration.setTestDescription("test description");12 runConfiguration.setTestStatus("test status");13 runConfiguration.setTestType("test type");14 runConfiguration.setTestFramework("test framework");15 runConfiguration.setTestPriority("test priority");16 runConfiguration.setTestTags("test tags");17 runConfiguration.setTestStart("test start");18 runConfiguration.setTestEnd("test end");19 runConfiguration.setTestDuration("test duration");20 runConfiguration.setTestSuccess("test success");21 runConfiguration.setTestFailure("test failure");22 runConfiguration.setTestSkipped("test skipped");23 runConfiguration.setTestErrors("test errors");24 runConfiguration.setTestWarnings("test warnings");25 runConfiguration.setTestInfo("test info");26 runConfiguration.setTestDebug("test debug");27 runConfiguration.setTestTrace("test trace");28 runConfiguration.setTestOutput("test output");29 runConfiguration.setTestReport("test report");30 runConfiguration.setTestReportDir("test report directory");31 runConfiguration.setTestReportName("test report name");32 runConfiguration.setTestReportType("test report type");33 runConfiguration.setTestReportCss("test report css");34 runConfiguration.setTestReportJs("test report js");35 runConfiguration.setTestReportPdf("test report pdf");36 runConfiguration.setTestReportExcel("test report excel");37 runConfiguration.setTestReportWord("test report word");38 runConfiguration.setTestReportHtml("test report html");39 runConfiguration.setTestReportXml("test report xml");40 runConfiguration.setTestReportJson("test report json");41 runConfiguration.setTestReportCsv("test report csv");42 runConfiguration.setTestReportJunit("test report junit");43 runConfiguration.setTestReportTms("test report tms");44 runConfiguration.setTestReportTmsType("test report tms type");45 runConfiguration.setTestReportTmsUrl("test report tms url");

Full Screen

Full Screen

RunConfiguration

Using AI Code Generation

copy

Full Screen

1RunConfiguration runConfiguration = new RunConfiguration();2runConfiguration.setProjectPath("/home/user/citrus-samples");3runConfiguration.setTestPath("com.consol.citrus.remote.sample");4runConfiguration.setTestName("HelloWorldIT");5runConfiguration.setContextName("remoteContext");6runConfiguration.setContextFile("/home/user/citrus-samples/src/test/resources/citrus-remote-context.xml");7runConfiguration.setContextClasspath("/home/user/citrus-samples/target/classes");8runConfiguration.setContextConfigLocation("classpath:com/consol/citrus/remote/sample/citrus-remote-context.xml");9runConfiguration.setJavaHome("/usr/lib/jvm/java-8-openjdk-amd64");10runConfiguration.setJavaOptions("-Xmx512m -XX:MaxPermSize=256m");11runConfiguration.setEnvironment("test");12runConfiguration.setReportDirectory("/home/user/citrus-samples/target/citrus-reports");13runConfiguration.setReportName("citrus-remote-reports");14runConfiguration.setReportFormats("html");15runConfiguration.setFailFast(true);16runConfiguration.setVerbose(true);17runConfiguration.setDebug(true);18runConfiguration.setLogToFile(true);19runConfiguration.setLogToFileDirectory("/home/user/citrus-samples/target/citrus-logs");20runConfiguration.setLogToFilePrefix("citrus-remote-logs");21runConfiguration.setLogToFileSuffix(".log");22runConfiguration.setLogToFileDateFormat("yyyy-MM-dd");23runConfiguration.setLogToFileMaxHistory(30);24runConfiguration.setLogToFileMaxSize(1024);25runConfiguration.setLogToFileMaxSizeUnit("KB");26runConfiguration.setLogToFileCompress(true);27runConfiguration.setLogToFileCompressLevel(9);28runConfiguration.setLogToFileCompressSuffix(".gz");29runConfiguration.setLogToFileAppend(true);30runConfiguration.setLogToFileAppendDateFormat("yyyy-MM-dd-HH-mm");31runConfiguration.setLogToFileAppendSeparator("_");32runConfiguration.setLogToFileAppendSuffix(".log");33runConfiguration.setLogToConsole(true);34runConfiguration.setLogToConsoleLevel("INFO");35runConfiguration.setLogToConsoleDateFormat("yyyy-MM-dd");36runConfiguration.setLogToConsoleSeparator("_");37runConfiguration.setLogToConsoleSuffix(".log");38RunConfiguration runConfiguration = new RunConfiguration();39runConfiguration.setProjectPath("/home/user/citrus-samples");40runConfiguration.setTestPath("com.consol

Full Screen

Full Screen

RunConfiguration

Using AI Code Generation

copy

Full Screen

1package com.consol.citrus.remote.plugin;2import com.consol.citrus.remote.plugin.config.RunConfiguration;3public class RunConfigurationTest {4 public static void main(String[] args) {5 RunConfiguration runConfiguration = new RunConfiguration();6 runConfiguration.setProjectName("citrus-remote-plugin");7 runConfiguration.setProjectDirectory("C:\\Users\\user\\workspace\\citrus-remote-plugin");8 runConfiguration.setTestPackage("com.consol.citrus.remote.plugin");9 runConfiguration.setTestName("com.consol.citrus.remote.plugin.SampleTest");10 runConfiguration.setTestSuite("com.consol.citrus.remote.plugin.SampleTest");11 runConfiguration.setTestType("testng");12 runConfiguration.setTestReport("target/surefire-reports");13 runConfiguration.setTestReportType("xml");14 runConfiguration.setTestReportName("report");15 runConfiguration.setTestReportSuffix("xml");16 runConfiguration.setTestReportDir("target/surefire-reports");17 runConfiguration.setTestReportDirType("xml");18 runConfiguration.setTestReportDirName("report");19 runConfiguration.setTestReportDirSuffix("xml");20 runConfiguration.setTestReportDir("target/surefire-reports");21 runConfiguration.setTestReportDirType("xml");22 runConfiguration.setTestReportDirName("report");23 runConfiguration.setTestReportDirSuffix("xml");24 runConfiguration.setTestReportDir("target/surefire-reports");25 runConfiguration.setTestReportDirType("xml");26 runConfiguration.setTestReportDirName("report");27 runConfiguration.setTestReportDirSuffix("xml");28 runConfiguration.setTestReportDir("target/surefire-reports");29 runConfiguration.setTestReportDirType("xml");30 runConfiguration.setTestReportDirName("report");31 runConfiguration.setTestReportDirSuffix("xml");32 runConfiguration.setTestReportDir("target/surefire-reports");33 runConfiguration.setTestReportDirType("xml");34 runConfiguration.setTestReportDirName("report");35 runConfiguration.setTestReportDirSuffix("xml");36 runConfiguration.setTestReportDir("target/surefire-reports");37 runConfiguration.setTestReportDirType("xml");38 runConfiguration.setTestReportDirName("report");39 runConfiguration.setTestReportDirSuffix("xml");

Full Screen

Full Screen

RunConfiguration

Using AI Code Generation

copy

Full Screen

1package com.consol.citrus.remote.plugin;2import com.consol.citrus.remote.plugin.config.RunConfiguration;3import com.consol.citrus.remote.plugin.server.RemoteServer;4public class RemoteServerMain {5public static void main(String[] args) {6RunConfiguration configuration = new RunConfiguration();7configuration.setPort(8080);8configuration.setContextPath("/citrus");9configuration.setConfigFile("citrus-context.xml");10RemoteServer server = new RemoteServer(configuration);11server.start();12}13}14package com.consol.citrus.remote.plugin;15import com.consol.citrus.remote.plugin.config.RunConfiguration;16import com.consol.citrus.remote.plugin.client.RemoteClient;17import com.consol.citrus

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.

Test Your Web Or Mobile Apps On 3000+ Browsers

Signup for free

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful