Mockserver maven plugin: init mockserver expectations from file - maven-failsafe-plugin

I'm using Mockserver maven plugin to mock some requests for integration tests.
My pom.xml looks like:
...
<plugin>
<groupId>org.mock-server</groupId>
<artifactId>mockserver-maven-plugin</artifactId>
<version>5.5.1</version>
<configuration>
<serverPort>1080</serverPort>
<logLevel>DEBUG</logLevel>
<initializationClass>com.mycompany.ExampleInitializationClass</initializationClass>
</configuration>
<executions>
<execution>
<id>run-mockserver</id>
<phase>pre-integration-test</phase>
<goals>
<goal>start</goal>
</goals>
</execution>
<execution>
<id>stop-mockserver</id>
<phase>post-integration-test</phase>
<goals>
<goal>stop</goal>
</goals>
</execution>
</executions>
</plugin>
...
Problem here is that I have to provide expectations using a class (com.mycompany.ExampleInitializationClass) and I want to provide expectations using a JSON file like described here:
http://www.mock-server.com/mock_server/initializing_expectations.html
I didn't find any way in the plugin configuration to initialize the Mockserver with the property:
-Dmockserver.initializationJsonPath
Is there any way to achieve that? Thanks in advance.

You just have to define initializationJson property specifying path to JSON file with expectations:
<plugin>
<groupId>org.mock-server</groupId>
<artifactId>mockserver-maven-plugin</artifactId>
<version>5.5.1</version>
<configuration>
<serverPort>1080</serverPort>
<logLevel>DEBUG</logLevel>
<initializationJson>expectations.json</initializationJson>
</configuration>
<executions>
...
</executions>
</plugin>
The catch here is that the file path is relative to testClasspath directory (e.g. ${project.basedir}/target/test-classes/), so you have to copy the expectation file there. You may use e.g. maven-antrun-plugin for this (as below) or
maven-resources-plugin.
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>run</goal>
</goals>
<configuration>
<tasks>
<copy file="your/expectations.json" todir="${project.basedir}/target/test-classes/"/>
</tasks>
</configuration>
</execution>
</executions>
</plugin>

Related

Make Maven Spotless plugin format Kotlin source code

How do I get the Spotless Maven plugin to format all Kotlin source files?
<plugin>
<groupId>com.diffplug.spotless</groupId>
<artifactId>spotless-maven-plugin</artifactId>
<executions>
<execution>
<id>spotless-apply</id>
<phase>compile</phase>
<configuration>
<kotlin>
<ktlint/>
</kotlin>
</configuration>
<goals>
<goal>apply</goal>
</goals>
</execution>
</executions>
</plugin>
Not sure why your current configuration doesn't work, maybe its because the config is inside the execution block? If you move it up one level and then replace the apply with check it will work.
<plugin>
<groupId>com.diffplug.spotless</groupId>
<artifactId>spotless-maven-plugin</artifactId>
<configuration>
<kotlin>
<ktlint />
</kotlin>
</configuration>
<executions>
<execution>
<phase>compile</phase>
<goals>
<goal>check</goal>
</goals>
</execution>
</executions>
</plugin>

Is it possible to generate multiple HTML reports with different configuration after the same execution? jmeter-maven-plugin

I'm using jmeter's maven plugin and I would like to generate two different HTML reports from the same execution log. Is it even possible to do this using this plugin?
This is my pom.xml and I'm not sure how to create a second report with a different output folder and title for example.
<build>
<plugins>
<plugin>
<groupId>com.lazerycode.jmeter</groupId>
<artifactId>jmeter-maven-plugin</artifactId>
<version>${jmeter.plugin.version}</version>
<executions>
<execution>
<id>configuration</id>
<goals>
<goal>configure</goal>
</goals>
</execution>
<execution>
<id>tests</id>
<goals>
<goal>jmeter</goal>
</goals>
</execution>
<execution>
<id>check-results</id>
<goals>
<goal>results</goal>
</goals>
</execution>
</executions>
<configuration>
<propertiesUser>
<thread.number>${thread.number}</thread.number>
<rampup>${rampup}</rampup>
<jmeter.reportgenerator.report_title>CA Dashboard</jmeter.reportgenerator.report_title>
</propertiesUser>
<ignoreResultFailures>true</ignoreResultFailures>
<generateReports>true</generateReports>
</configuration>
</plugin>
</plugins>
</build>
Currently no, the report generation happens at the same time the test is run.
When the following issues have been fixed it may be an option:
https://github.com/jmeter-maven-plugin/jmeter-maven-plugin/issues/328
https://github.com/jmeter-maven-plugin/jmeter-maven-plugin/issues/391
https://github.com/jmeter-maven-plugin/jmeter-maven-plugin/issues/316

Moving a resource in maven with wildcard

I was trying to move a file to an existing one with a variable (cache busted) part:
file.js should be copied over an existing file-0123456789abcdef.js (of which the last part 16 hex digits is variable)
The copy-rename-maven-plugin results in an extra file: file-*.js:
<plugin>
<groupId>com.coderplus.maven.plugins</groupId>
<artifactId>copy-rename-maven-plugin</artifactId>
<executions>
<execution>
<id>move-file</id>
<phase>prepare-package</phase>
<goals>
<goal>copy</goal>
</goals>
<configuration>
<sourceFile>${project.build.directory}/unpacked/file.js</sourceFile>
<destinationFile>${project.build.directory}/unpacked/file-*.js</destinationFile>
</configuration>
</execution>
</executions>
</plugin>
I would like to end up with one file: file-0123456789abcdef.js with the content of file.js.
A simple terminal command can easily do what I want but I would like to avoid using the ant plugin.
Help will be much appreciated!
I found out that the exec-maven-plugin could do the trick in combination with a find -exec:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<executions>
<execution>
<id>move-configuration</id>
<phase>prepare-package</phase>
<goals>
<goal>exec</goal>
</goals>
</execution>
</executions>
<configuration>
<executable>find</executable>
<arguments>
<argument>${project.build.directory}/unpacked/>
<argument>-name</argument>
<argument>file-*.js</argument>
<argument>-exec</argument>
<argument>mv</argument>
<argument>${project.build.directory}/unpacked/file.js</argument>
<argument>{}</argument>
<argument>;</argument>
</arguments>
</configuration>
</plugin>

surefire overwrites reports with soapui maven plugin for many projects with same testsuite names

I have many SOAPUI Projects. Each SOAPUI project has many testsuites.
The testsuites have the same name in different projects.
Likewise, the testcases has the same name in differents projects
For example :
Project1 has testsuite1 and testsuite2.
Testsuite1 of project1 has testcase1.
Project2 has testsuite1 and testsuite2.
Testsuite1 of project2 has testcase1
When I launch soapui tests with soapui-maven-plugin, the surefire reports file name are built with the testsuite name and the testcase name. The problem is that I launch the plugin for each projects so the reports are overwritten. I need to keep these reports in order jenkins to be able to generate graphs.
Is there a way to avoid this overwriting?
Is it possible to prefix the name of the report files with soapui project name?
<build>
<plugins>
<plugin>
<groupId>com.smartbear.soapui</groupId>
<artifactId>soapui-maven-plugin</artifactId>
<version>5.0.0</version>
<executions>
<execution>
<id>TestFluxCourant</id>
<goals>
<goal>test</goal>
</goals>
<phase>integration-test</phase>
<configuration>
<projectFile>${project.basedir}/src/test/resources/project1.xml</projectFile>
</configuration>
</execution>
<execution>
<id>TestFluxHistorique</id>
<goals>
<goal>test</goal>
</goals>
<phase>integration-test</phase>
<configuration>
<projectFile>${project.basedir}/src/test/resources/project2.xml</projectFile>
</configuration>
</execution>
</executions>
<configuration>
<host>${integration}:${integrationPort}</host>
<outputFolder>${project.build.directory}/surefire-reports</outputFolder>
<junitReport>true</junitReport>
<printReport>false</printReport>
<exportAll>true</exportAll>
<testFailIgnore>true</testFailIgnore>
<settingsFile>${project.basedir}/src/test/resources/Soapui-maven-conf.xml</settingsFile>
</configuration>
</plugin>
</plugins>
</build>
According to documentation, configuration is per execution. If you correct your pom, it should be trivial:
<plugin>
<groupId>com.smartbear.soapui</groupId>
<artifactId>soapui-maven-plugin</artifactId>
<version>5.0.0</version>
<executions>
<execution>
<id>TestFluxCourant</id>
<goals>
<goal>test</goal>
</goals>
<phase>integration-test</phase>
<configuration>
<projectFile>${project.basedir}/src/test/resources/project1.xml</projectFile>
<host>${integration}:${integrationPort}</host>
<outputFolder>${project.build.directory}/project1</outputFolder>
<junitReport>true</junitReport>
<printReport>false</printReport>
<exportAll>true</exportAll>
<testFailIgnore>true</testFailIgnore>
<settingsFile>${project.basedir}/src/test/resources/Soapui-maven-conf.xml</settingsFile>
</configuration>
</execution>
<execution>
<id>TestFluxHistorique</id>
<goals>
<goal>test</goal>
</goals>
<phase>integration-test</phase>
<configuration>
<projectFile>${project.basedir}/src/test/resources/project2.xml</projectFile>
<host>${integration}:${integrationPort}</host>
<outputFolder>${project.build.directory}/project2</outputFolder>
<junitReport>true</junitReport>
<printReport>false</printReport>
<exportAll>true</exportAll>
<testFailIgnore>true</testFailIgnore>
<settingsFile>${project.basedir}/src/test/resources/Soapui-maven-conf.xml</settingsFile>
</configuration>
</execution>
</executions>
</plugin>
BTW: Not sure what surefire has to do with any of this.
Not sure if it works... But give this a try
<outputFolder>${project.build.directory}/surefire-reports/${projectFile}</outputFolder>

Multiple XSD schemas for castor with castor-maven-plugin

Is it possible to work with multiple xsd schemas with castor-maven-plugin simultaneously?
I use it in rotation (schema1 and schema2) in POM and it works:
<build>
...
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>castor-maven-plugin</artifactId>
<version>2.1</version>
<configuration>
<schema>src/main/castor/schema1.xsd</schema>
<dest>src/main/java</dest>
<packaging>com.path.to.schema1.beans</packaging>
</configuration>
<executions>
<execution>
<goals>
<goal>generate</goal>
</goals>
</execution>
</executions>
</plugin>
...
with a little problem: mvn:install collects all classes to target except chema2.crd (or schema1 if I use schema2). I have to copy file manually.
Can I fix it? Are there any ways to configure castor-maven-plugin ?
Try using multiple executions like this:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>castor-maven-plugin</artifactId>
<version>2.1</version>
<executions>
<execution>
<id>firstSchema</id>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<schema>src/main/castor/schema1.xsd</schema>
<dest>src/main/java</dest>
<packaging>com.path.to.schema1.beans</packaging>
</configuration>
</execution>
<execution>
<id>secondSchema</id>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<schema>src/main/castor/schema2.xsd</schema>
<dest>src/main/java</dest>
<packaging>com.path.to.schema2.beans</packaging>
</configuration>
</execution>
</executions>
</plugin>

Resources