maven surefire test plugin runs tests even if they are excluded: - maven

i exclude all tests in plugin except my test suite:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.11</version>
<configuration>
<!--
<testFailureIgnore>true</testFailureIgnore>
<skipTests>true</skipTests>
-->
<parallel>both</parallel>
<threadCount>10</threadCount>
<forkMode>once</forkMode>
<configuration>
<excludes>
<exclude>**/Test*.java</exclude>
<exclude>**/*Test.java</exclude>
<exclude>**/*TestCase.java</exclude>
</excludes>
<includes>
<include>ru.csbi.registry.CategorizedTestsSuite.java</include>
</includes>
</configuration>
<!--
<configuration>
<groups>ru.csbi.registry.IntegrationTestsNotRequiringContainerCategory</groups>
<groups>ru.csbi.registry.UnitTestsCategory</groups>
</configuration>
-->
</configuration>
<dependencies>
<dependency>
<groupId>org.apache.maven.surefire</groupId>
<artifactId>surefire-junit47</artifactId>
<version>2.12</version>
</dependency>
</dependencies>
</plugin>
but all tests are executed.
Even if i delete my the only include in config it still runs all tests:
<configuration>
<excludes>
<exclude>**/Test*.java</exclude>
<exclude>**/*Test.java</exclude>
<exclude>**/*TestCase.java</exclude>
</excludes>
<!--
<includes>
<include>ru.csbi.registry.CategorizedTestsSuite.java</include>
</includes>
-->
</configuration>
Here is the logs:
------------------------------------------------------- T E S T S
------------------------------------------------------- Concurrency config is parallel='both',perCoreThreadCount=true,
threadCount=10, useUnlimitedThreads=false
Running javalangtests.AnnotationTest
Tests run: 2, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0 sec
Running ru.csbi.registry.services.JdbcServiceTest
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0 sec
Running ru.csbi.registry.services.reflection.ClassServiceTest
Tests run: 2, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0 sec
Running ru.csbi.registry.services.reflection.FieldServiceTest
Tests run: 2, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0 sec
Running
ru.csbi.registry.services.reflection.hibernate.relation.RelationServiceTest
Tests run: 7, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.016
sec
Effective pom:
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.12</version>
<executions>
<execution>
<id>default-test</id>
<phase>test</phase>
<goals>
<goal>test</goal>
</goals>
<configuration>
<configuration>
<includes>
<include>ru.csbi.registry.CategorizedTestsSuite.java</include>
</includes>
</configuration>
</configuration>
</execution>
</executions>
<configuration>
<configuration>
<includes>
<include>ru.csbi.registry.CategorizedTestsSuite.java</include>
</includes>
</configuration>
</configuration>
</plugin>

You need to remove configuration block from configuration block.
Like this:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.11</version>
<configuration>
<!--
<testFailureIgnore>true</testFailureIgnore>
<skipTests>true</skipTests>
-->
<parallel>both</parallel>
<threadCount>10</threadCount>
<forkMode>once</forkMode>
<excludes>
<exclude>**/Test*.java</exclude>
<exclude>**/*Test.java</exclude>
<exclude>**/*TestCase.java</exclude>
</excludes>
<includes>
<include>ru.csbi.registry.CategorizedTestsSuite.java</include>
</includes>
</configuration>
<dependencies>
<dependency>
<groupId>org.apache.maven.surefire</groupId>
<artifactId>surefire-junit47</artifactId>
<version>2.12</version>
</dependency>
</dependencies>
</plugin>
Nested configuration element makes no sense. As well as package name in your include (ru.csbi.registry.CategorizedTestsSuite.java).

Related

Maven results on Run and Tests Run are not same

I' trying to test 4 scenarios in a feature using the mvn clean test and all the tests are running as expected but the results shows as below
Maven Result
[INFO]   Run 1: PASS
[ERROR]   Run 2: MainRunner.runScenario » NoSuchIdentifiableElement Element fileExplorerButton ...
[INFO]   Run 3: PASS
[ERROR]   Run 4: MainRunner.runScenario » NoSuchIdentifiableElement Element fileExplorerButton ...
[INFO]
[INFO]
[ERROR] Tests run: 1, Failures: 1, Errors: 0, Skipped: 0
[INFO]
[ERROR] There are test failures.
Runner class
#CucumberOptions(
features = "classpath:cucumber-features/someTest.feature", glue = { "automatedtest.tests.steps",
"autotest.arch.steps" },
plugin = {
"pretty",
"html:target/cucumber-html-report/",
"json:target/cucumber-json-report/report.json", "io.qameta.allure.cucumber6jvm.AllureCucumber6Jvm"
}
)
public class MainRunner extends AbstractTestNGCucumberTests {}
I dont understand why is there a mismatch.
PARENT POM
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-framework-bom</artifactId>
<version>${spring.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies></dependencyManagement>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M3</version>
<configuration>
<includes>
<include>**/MainRunner.class</include>
</includes>
<printSummary>true</printSummary>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
POM under src/test/
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M3</version>
<configuration>
<includes>
<include>**/MainRunner.class</include>
</includes>
</configuration>
</plugin>
I tried to add
<forkCount>, <printSummary>,

maven plugin configuration to gradle

I'm trying to convert this plugin in pom to gradle. And I've added
compile 'org.codehaus.mojo:exec-maven-plugin:1.2.1' in the dependencies. There are some other parameters like "includeProjectDependencies" and so on. Just don't know what else to put in "JavaExec":
task executeJava(type:JavaExec) {
main = "com.abc.efg.func.DocumentGenerator"
classpath = sourceSets.main.runtimeClasspath
dependsOn = files('/lib/tool.jar')
args = [
"--api_list",
"metaapi#v1",
"campaign#v1",
"--output_directory",
"$project.buildDir"
]
}
Here's the plugin:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.2.1</version>
<executions>
<execution>
<goals>
<goal>java</goal>
</goals>
</execution>
</executions>
<configuration>
<includeProjectDependencies>true</includeProjectDependencies>
<includePluginDependencies>true</includePluginDependencies>
<mainClass>com.abc.efg.func.DocumentGenerator</mainClass>
<executableDependency>
<groupId>com.google.template</groupId>
<artifactId>tool</artifactId>
</executableDependency>
<arguments>
<argument>--api_list</argument>
<argument>metaapi#v1,campaign#v1</argument>
<argument>--output_directory</argument>
<argument>${project.build.directory}</argument>
</arguments>
</configuration>
<dependencies>
<dependency>
<groupId>com.google.template</groupId>
<artifactId>tool</artifactId>
<version>1.0</version>
<type>jar</type>
</dependency>
</dependencies>
</plugin>

DefaultChemObjectBuilder ClassNotFoundException occur when running jmh benchmark in terminal Intellij Idea

I can run the project as an application in IntelliJ IDEA by using main method. But when I'm trying to run it using terminal for benchmark, a class not found exception occurs.
public class MyBenchmark {
#Benchmark
public static void sdfIterativeReader() throws ClassNotFoundException, FileNotFoundException {
File sdfFile = new File("molecule.sdf");
IChemObjectBuilder builder = DefaultChemObjectBuilder.getInstance();
IteratingSDFReader reader = new IteratingSDFReader(new FileInputStream(sdfFile),builder);
while (reader.hasNext()) {
IAtomContainer molecule = (IAtomContainer) reader.next();
IMolecularFormula formula = MolecularFormulaManipulator.getMolecularFormula(molecule);
String molecularFromula = MolecularFormulaManipulator.getString(formula);
System.out.println(molecularFromula);
}
}
}
I used the command: mvn clean install then project is building successfully. When I run the command:
java -jar target/benchmarks.jar
it gives the following error:
Here, I have attached my pom.xml:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.chemid</groupId>
<artifactId>chemid-benchmark</artifactId>
<version>1.0</version>
<packaging>jar</packaging>
<name>JMH benchmark sample: Java</name>
<prerequisites>
<maven>3.0</maven>
</prerequisites>
<dependencies>
<!-- https://mvnrepository.com/artifact/org.openjdk.jmh/jmh-generator-annprocess -->
<dependency>
<groupId>org.openjdk.jmh</groupId>
<artifactId>jmh-core</artifactId>
<version>${jmh.version}</version>
</dependency>
<dependency>
<groupId>org.openjdk.jmh</groupId>
<artifactId>jmh-generator-annprocess</artifactId>
<version>${jmh.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>cdk</groupId>
<artifactId>cdk</artifactId>
<version>1.5.13</version>
<scope>system</scope>
<systemPath>${cdk.lib}/cdk-1.5.13 .jar</systemPath>
</dependency>
<dependency>
<groupId>net.sourceforge.streamsupport</groupId>
<artifactId>streamsupport</artifactId>
<version>1.5.1</version>
</dependency>
<dependency>
<groupId>org.openscience.cdk</groupId>
<artifactId>cdk-io</artifactId>
<version>1.5.13</version>
</dependency>
<dependency>
<groupId>org.openscience.cdk</groupId>
<artifactId>cdk</artifactId>
<version>1.5.13</version>
<type>pom</type>
</dependency>
<dependency>
<groupId>org.openscience.cdk</groupId>
<artifactId>cdk-core</artifactId>
<version>1.5.13</version>
</dependency>
</dependencies>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.7</maven.compiler.source>
<jmh.version>1.6.3</jmh.version>
<javac.target>1.8</javac.target>
<uberjar.name>benchmarks</uberjar.name>
<cdk.lib>${basedir}/libs</cdk.lib>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<compilerVersion>${javac.target}</compilerVersion>
<source>${javac.target}</source>
<target>${javac.target}</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>2.4.3</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<finalName>${uberjar.name}</finalName>
<transformers>
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>org.openjdk.jmh.Main</mainClass>
</transformer>
</transformers>
<filters>
<filter>
<!--
Shading signed JARs will fail without this.
http://stackoverflow.com/questions/999489/invalid-signature-file-when-attempting-to-run-a-jar
-->
<artifact>*:*</artifact>
<excludes>
<exclude>META-INF/*.SF</exclude>
<exclude>META-INF/*.DSA</exclude>
<exclude>META-INF/*.RSA</exclude>
</excludes>
</filter>
</filters>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
<pluginManagement>
<plugins>
<plugin>
<artifactId>maven-clean-plugin</artifactId>
<version>2.5</version>
</plugin>
<plugin>
<artifactId>maven-deploy-plugin</artifactId>
<version>2.8.1</version>
</plugin>
<plugin>
<artifactId>maven-install-plugin</artifactId>
<version>2.5.1</version>
</plugin>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<version>2.4</version>
</plugin>
<plugin>
<artifactId>maven-javadoc-plugin</artifactId>
<version>2.9.1</version>
</plugin>
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>2.6</version>
</plugin>
<plugin>
<artifactId>maven-site-plugin</artifactId>
<version>3.3</version>
</plugin>
<plugin>
<artifactId>maven-source-plugin</artifactId>
<version>2.2.1</version>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.17</version>
</plugin>
</plugins>
</pluginManagement>
</build>
Add to file MANIFEST.MF this line:
Class-Path: lib/cdk-1.5.13.jar
Or run you benchmark thought class with main method:
java -cp path/to/cdk/lib/cdk-1.5.13.jar:. com.your.main.ClassName
For more info read answers from this discussion.
And also this answer to understand system scope of Maven dependency that you've chose for cdk-1.5.13.jar.

Integrating security realm through Wildfly Maven plugin

It's kinda the same question as this one, but the answer didn't work for me. Also I don't know how he got the output of jboss-cli in his stacktrace, that would help a lot for debugging.
Anyway I'm trying to deploy a security realm in Wildfly 10 through Maven. It works fine when doing it through the console (with the commented lines in the code below) but not with Maven Wildfly plugin.
<configuration>
<!--add security domain-->
<before-deployment>
<commands>
<!--<command>./subsystem=security/security-domain=walbangSecureRealm:add(cache-type="default")</command>-->
<!--<command>cd ./subsystem=security/security-domain=walbangSecureRealm</command>-->
<!--<command>./authentication=classic:add(login-modules=[{code="Database",flag="required",module-options={dsJndiName="java:/walbangDbDS",principalsQuery="select password from usercredential uc where uc.username = ?",rolesQuery="select role, 'Roles' from users u where u.username = ?",unauthenticatedIdentity="guest"}}])</command>-->
<command>/subsystem=security/security-domain=walbangSecureRealm:add(cache-type=default)</command>
<command>/subsystem=security/security-domain=walbangSecureRealm/authentication=classic:add(login-modules=[{"code"=>"Database","flag"=>"required","module-options"=>[("dsJndiName"=>"java:/walbangDbDS"),("principalsQuery"=>"select password from usercredential uc where uc.username = ?"),("rolesQuery"=>"select role, 'Roles' from users u where u.username = ?"),("unauthenticatedIdentity"=>"guest")]}])</command>
<command>reload</command>
</commands>
</before-deployment>
</configuration>
The error in the stacktrace is :
12:18:54,236 ERROR [org.jboss.as.controller.management-operation] (management-handler-thread - 2) WFLYCTL0013: Operation ("deploy") failed - address: ([("deployment" => "walbang-0.0.1-SNAPSHOT.war")]) - failure description: {"WFLYCTL0180: Services with missing/unavailable dependencies" => [
"jboss.deployment.unit.\"walbang-0.0.1-SNAPSHOT.war\".component.ManageMatchServiceImpl.CREATE is missing [jboss.security.security-domain.walbangSecureRealm]",...
Here is more info of what I have in Maven:
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.3</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.6</version>
<configuration>
<warSourceDirectory>WebContent</warSourceDirectory>
<failOnMissingWebXml>true</failOnMissingWebXml>
</configuration>
</plugin>
<!--wildfly plugin-->
<plugin>
<groupId>org.wildfly.plugins</groupId>
<artifactId>wildfly-maven-plugin</artifactId>
<version>1.1.0.Alpha8</version>
<executions>
<!-- Deploy the JDBC driver -->
<execution>
<id>deploy-driver</id>
<phase>package</phase>
<configuration>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<name>mysql-connector</name>
</configuration>
<goals>
<goal>deploy-artifact</goal>
</goals>
</execution>
<!-- Add a data source -->
<execution>
<id>add-datasource</id>
<phase>package</phase>
<configuration>
<address>subsystem=datasources,data-source=java:/walbangDbDS</address>
<resources>
<resource>
<enableResource>true</enableResource>
<properties>
<connection-url>jdbc:mysql://localhost:3306/forumcs</connection-url>
<jndi-name>java:/walbangDbDS</jndi-name>
<enabled>true</enabled>
<enable>true</enable>
<user-name>root</user-name>
<password>123456</password>
<driver-name>mysql-connector</driver-name>
<use-ccm>false</use-ccm>
</properties>
</resource>
</resources>
</configuration>
<goals>
<goal>add-resource</goal>
</goals>
</execution>
<!-- Deploy the application on install -->
<execution>
<id>deploy</id>
<phase>install</phase>
<goals>
<goal>deploy</goal>
</goals>
</execution>
</executions>
<configuration>
<!--add security domain-->
<before-deployment>
<commands>
<!--<command>./subsystem=security/security-domain=walbangSecureRealm:add(cache-type="default")</command>-->
<!--<command>cd ./subsystem=security/security-domain=walbangSecureRealm</command>-->
<!--<command>./authentication=classic:add(login-modules=[{code="Database",flag="required",module-options={dsJndiName="java:/walbangDbDS",principalsQuery="select password from usercredential uc where uc.username = ?",rolesQuery="select role, 'Roles' from users u where u.username = ?",unauthenticatedIdentity="guest"}}])</command>-->
<command>/subsystem=security/security-domain=walbangSecureRealm:add(cache-type=default)</command>
<command>/subsystem=security/security-domain=walbangSecureRealm/authentication=classic:add(login-modules=[{"code"=>"Database","flag"=>"required","module-options"=>[("dsJndiName"=>"java:/walbangDbDS"),("principalsQuery"=>"select password from usercredential uc where uc.username = ?"),("rolesQuery"=>"select role, 'Roles' from users u where u.username = ?"),("unauthenticatedIdentity"=>"guest")]}])</command>
<command>reload</command>
</commands>
</before-deployment>
</configuration>
</plugin>
</plugins>

Installer jar is not getting executed using the following pom with izpack

I tried making an izpack installer using maven. The problem that I'm facing is that in the build the 'install.xml' and the other resources are just being copied to the install.jar. The XML file is not parsed and hence the install.jar is not getting executed.
Please help in rectifying the issue.
pom.xml
`<groupId>org.codehaus.izpack</groupId>
<version>5.0.0</version>
<modelVersion>4.0.0</modelVersion>
<artifactId>izpack-dist-test-harness</artifactId>
<name>IzPack dist module</name>
<packaging>jar</packaging>
<dependencies>
<dependency>
<groupId>org.codehaus.izpack</groupId>
<artifactId>izpack-standalone-compiler</artifactId>
<version>4.3.5</version>
</dependency>
<dependency>
<groupId>org.codehaus.izpack</groupId>
<artifactId>izpack-utils</artifactId>
<version>5.0.0-beta5</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.8.2</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<finalName>${project.name}</finalName>
<resources>
<resource>
<directory>src/main/izpack</directory>
</resource>
<resource>
<directory>src/main/resources</directory>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.codehaus.izpack</groupId>
<artifactId>izpack-maven-plugin</artifactId>
<version>1.0-alpha-5</version>
<executions>
<execution>
<id>install</id>
<phase>package</phase>
<goals>
<goal>izpack</goal>
</goals>
<configuration>
<izpackBasedir>${staging.dir}</izpackBasedir>
<descriptor>install.xml</descriptor>
<installerFile>${project.build.directory}/${project.build.finalName}-install.jar</installerFile>
</configuration>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>org.codehaus.izpack</groupId>
<artifactId>izpack-standalone-compiler</artifactId>
<version>4.3.5</version>
</dependency>
</dependencies>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.0</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
<showDeprecation>true</showDeprecation>
<showWarnings>true</showWarnings>
</configuration>
</plugin>
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>2.4.2</version>
<executions>
<execution>
<id>copy-install-xml-parsed</id>
<phase>prepare-package</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<encoding>UTF-8</encoding>
<overwrite>true</overwrite>
<outputDirectory>${staging.dir}</outputDirectory>
<delimiters>
<delimiter>#</delimiter>
</delimiters>
<resources>
<resource>
<directory>src/main/izpack/</directory>
<includes>
<include>install.xml</include>
</includes>
<filtering>true</filtering>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>${project.groupId}</groupId>
<artifactId>izpack-maven-plugin</artifactId>
<version>${project.version}</version>
<configuration>
</configuration>
</plugin>
</plugins>
</build>'
<properties>
<staging.dir>${basedir}/target/staging</staging.dir>
</properties>
</project>`
And the part of install.xml :
<?xml version='1.0' encoding='iso-8859-1' standalone='yes' ?>
<installation version='1.0'>
<info>
<!-- Info Params -->
</info>
<variables>
<variable name="RESOURCEROOT" value="src/main/izpack"></variable>
</variables>
<guiprefs resizable="no" width="500" height="500">
<modifier key="headingImageOnLeft" value="yes"/>
<modifier key="labelGap" value="2"/>
<modifier key="useHeadingPanel" value="yes"/>
<modifier key="headingBackgroundColor" value="0x00ffffff"/>
</guiprefs>
<locale>
<langpack iso3="eng"/>
<langpack iso3="fra"/>
<langpack iso3="spa"/>
</locale>
<resources>
<res id="HTMLLicencePanel.licence" src="License.txt"/>
<res id="InfoPanel.info" src="Readme.txt"/>
</resources>
<panels>
<panel classname="HelloPanel"/>
<panel classname="HTMLLicencePanel"/>
<panel classname="InfoPanel"/>
<panel classname="InstallPanel"/>
<panel classname="FinishPanel"/>
</panels>
<conditon type="java" id="installonwindows">
<java>
<class>com.izforge.izpack.util.OsVersion</class>
<field>IS_WINDOWS</field>
</java>
<returnvalue type="boolean">true</returnvalue>
</conditon>
<installerrequirements>
<installerrequiremnet conditon="installonwindows" message="This installer can install only on windows"/>
</installerrequirements>
<packs>
<pack name="Base" required="yes" preselected="yes">
<description>The Base Files</description>
<file src="Readme.txt" targetdir="$INSTALL_PATH" override="asktrue"/>
<file src="Licence.txt" targetdir="$INSTALL_PATH" override="asktrue"/>
</pack>
</packs>
Any Help would be highly appreciated! Thanks!

Resources