Java client
Overview
To use our Java API to generate and download reports, use our classes as explained in Create the Java Results API client.
First instantiate a ResultsAPIClient providing a URL and API key.
Then call method GenerateReport() to generate a report, and method DownloadReport() to download a report.
Configure the project
To configure your Java project, it is recommended to use Maven.
x.y.z stands for the latest version of the dependency.
Maven projects
In a Java Maven project, you need to add a dependency to the Maven settings file (pom.xml) using the examples below:
- Repository
<repositories><repository><id>neotys-public-releases</id><url>http://maven.neotys.com/content/repositories/releases/</url><releases><enabled>true</enabled></releases><snapshots><enabled>false</enabled></snapshots></repository></repositories>- Dependency
<dependencies><dependency><groupId>com.neotys.rest</groupId><artifactId>neotys-rest-api-results-client-olingo</artifactId><version>x.y.z</version></dependency></dependencies>Non-Maven projects
If your project is not developed using Maven, it is necessary to include the JAR files available in the \api folder of the NeoLoad installation directory:
- in the <install-dir>\api\Results API Client\Java folder
- in the <install-dir>\api\Common\Java folder
Create the Java Results API client
Example 1
In this example, we generate a PDF report for test result name “MyFirstTest”, we wait 3 seconds for the generation, and then we retrieve the byte array.
import com.neotys.rest.data.BinaryData;import com.neotys.rest.results.client.ResultsAPIClient;import com.neotys.rest.results.client.ResultsAPIClientFactory;import com.neotys.rest.results.model.DownloadReportParams;import com.neotys.rest.results.model.Format;import com.neotys.rest.results.model.GenerateReportParams;public class GenerateAndDownloadReportExample {public static void main(String[] args) throws Exception {// Instanciate ResultsAPIClient by specifying the connection URLfinal ResultsAPIClient client = ResultsAPIClientFactory.newClient("http://localhost:7400/Results/v1/Service.svc/");// Create the params to generate a report, based on test result "MyFirstTest" and format PDFfinal GenerateReportParams generateReportParams = GenerateReportParams.newBuilder().testResultName("MyFirstTest").format(Format.PDF).build();// Trigger the generation of the report and retrieve the report Idfinal String reportId = client.generateReport(generateReportParams);// Wait few seconds for the report being generated...Thread.sleep(3000);// Download the report from the idfinal BinaryData reportBinary = client.downloadReport(new DownloadReportParams(reportId));}}
Example 2
In this example, we generate a RTF comparison report for test result name “MyTest1” and “MyTest2”, we wait 3 seconds for the generation, and then we download the file on disk (folder C:\tmp).
import com.neotys.rest.results.client.ResultsAPIClient;import com.neotys.rest.results.client.ResultsAPIClientFactory;import com.neotys.rest.results.model.DownloadReportParams;import com.neotys.rest.results.model.Format;import com.neotys.rest.results.model.GenerateReportParams;public class GenerateAndDownloadComparisonReportExample {public static void main(String[] args) throws Exception {// Instanciate ResultsAPIClient by specifying the connection URLfinal ResultsAPIClient client = ResultsAPIClientFactory.newClient("http://localhost:7400/Results/v1/Service.svc/");// Create the params to generate a report, based on test result "MyFirstTest" and format PDFfinal GenerateReportParams generateReportParams = GenerateReportParams.newBuilder().testResultName("MyTest1").otherTestResultName("MyTest2").format(Format.RTF).build();// Trigger the generation of the report and retrieve the report Idfinal String reportId = client.generateReport(generateReportParams);// Wait few seconds for the report being generated...Thread.sleep(3000);// Download the report from the idfinal String destinationFolder = "C:\\tmp";client.downloadReport(new DownloadReportParams(reportId), destinationFolder);}}
Home