Can not compile simple Vaadin widgetset. - maven

I created simple vaadin application and tried create my vaadin widget module.
File widget structure following:
client
TestConnector
TestWidget
Test
WidgetSet.gwt.xml
MyUI //vaadin UI
Content of this files following:
1) TestConnector
package test.client;
import test.Test;
import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.ui.Widget;
import com.vaadin.client.communication.RpcProxy;
import com.vaadin.client.ui.AbstractComponentConnector;
import com.vaadin.shared.ui.Connect;
#Connect(Test.class)
public class TestConnector extends AbstractComponentConnector {
private final TestServerRpc serverRpc = RpcProxy.create(TestServerRpc.class, this);
public TestConnector() {
registerRpc(TestClientRpc.class, new TestClientRpc() {
});
}
#Override
protected Widget createWidget() {
return GWT.create(TestWidget.class);
}
#Override
public TestWidget getWidget() {
return (TestWidget) super.getWidget();
}
#Override
public TestState getState() {
return (TestState) super.getState();
}
}
2) TestWidget
package test.client;
import com.google.gwt.user.client.ui.Label;
public class TestWidget extends Label {
public static final String CLASSNAME = "mycomponent";
public TestWidget() {
setText("This is MyComponent");
setStyleName(CLASSNAME);
}
}
3) Test
package test;
import test.client.TestClientRpc;
import test.client.TestServerRpc;
import test.client.TestState;
import com.vaadin.ui.AbstractComponent;
public class Test extends AbstractComponent {
public Test() {
registerRpc(new TestServerRpc() {
private TestClientRpc getClientRpc() {
return getRpcProxy(TestClientRpc.class);
}
});
}
#Override
protected TestState getState() {
return (TestState) super.getState();
}
}
4) WidgetSet.gwt.xml
<!DOCTYPE module PUBLIC "-//Google Inc.//DTD Google Web Toolkit 2.5.0//EN"
"http://gwtproject.org/doctype/2.5.0/gwt-module.dtd">
<module>
<inherits name="com.vaadin.DefaultWidgetSet"/>
</module>
5) MyUI
package test;
import javax.servlet.annotation.WebServlet;
import com.vaadin.annotations.Theme;
import com.vaadin.annotations.VaadinServletConfiguration;
import com.vaadin.server.VaadinRequest;
import com.vaadin.server.VaadinServlet;
import com.vaadin.ui.UI;
import com.vaadin.ui.VerticalLayout;
#Theme("mytheme")
public class MyUI extends UI {
#Override
protected void init(VaadinRequest vaadinRequest) {
final VerticalLayout layout = new VerticalLayout();
Test mywidget = new Test();
layout.addComponents(mywidget);
setContent(layout);
}
#WebServlet(urlPatterns = "/*", name = "MyUIServlet", asyncSupported = true)
#VaadinServletConfiguration(ui = MyUI.class, productionMode = false, widgetset = "Test")
public static class MyUIServlet extends VaadinServlet {
}
}
When I try to compile this I see:
[INFO] --- vaadin-maven-plugin:8.0.5:update-theme (default) # tests ---
[INFO] Updating theme VAADIN\themes\mytheme
[INFO] Widgetsets found from classpath:
[INFO] test.WidgetSet in file:/C:/Users/Alexey/IdeaProjects/tests/src/main/java
[INFO] com.vaadin.DefaultWidgetSet in jar:file:C:/Users/Alexey/.m2/repository/com/vaadin/vaadin-client/7.1-SNAPSHOT/vaadin-client-7.1-SNAPSHOT.jar!/
[INFO] Addon styles found from classpath:
[INFO]
[INFO] Search took 32ms
[INFO] Theme "VAADIN\themes\mytheme" updated
[INFO]
[INFO] --- vaadin-maven-plugin:8.0.5:update-widgetset (default) # tests ---
[INFO] auto discovered modules [test.WidgetSet]
[INFO] Updating widgetset test.WidgetSet
[INFO] Adding resource directory to command classpath: C:\Users\Alexey\IdeaProjects\tests\src\main\resources
[INFO] Using com.vaadin:vaadin-client-compiler version 8.0.5
[INFO] Widgetsets found from classpath:
[INFO] test.WidgetSet in file:/C:/Users/Alexey/IdeaProjects/tests/src/main/java
[INFO] com.vaadin.DefaultWidgetSet in jar:file:C:/Users/Alexey/.m2/repository/com/vaadin/vaadin-client/8.0.5/vaadin-client-8.0.5.jar!/
[INFO] Addon styles found from classpath:
[INFO]
[INFO] Search took 40ms
[INFO]
[INFO] --- vaadin-maven-plugin:8.0.5:compile-theme (default) # tests ---
[INFO] Updating theme VAADIN\themes\mytheme
[INFO] Theme "VAADIN\themes\mytheme" compiled
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) # tests ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 1 resource
[INFO]
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) # tests ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 7 source files to C:\Users\Alexey\IdeaProjects\tests\target\classes
[INFO] -------------------------------------------------------------
[ERROR] COMPILATION ERROR :
[INFO] -------------------------------------------------------------
[ERROR] /C:/Users/Alexey/IdeaProjects/tests/src/main/java/test/client/TestConnector.java:[14,8] cannot access com.google.gwt.event.shared.EventHandler
class file for com.google.gwt.event.shared.EventHandler not found
[ERROR] /C:/Users/Alexey/IdeaProjects/tests/src/main/java/test/client/TestWidget.java:[8,8] cannot access com.google.gwt.event.shared.HasHandlers
class file for com.google.gwt.event.shared.HasHandlers not found
[INFO] 2 errors
[INFO] -------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
I don't understand the reason of this error and don't know how to solve it. Why are com.google.gwt.event.shared.EventHandler and com.google.gwt.event.shared.HasHandlers needed in my program?
pom file:
<?xml version="1.0" encoding="UTF-8"?>
<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>test</groupId>
<artifactId>tests</artifactId>
<packaging>war</packaging>
<version>1.0-SNAPSHOT</version>
<name>tests</name>
<prerequisites>
<maven>3</maven>
</prerequisites>
<properties>
<vaadin.version>8.0.5</vaadin.version>
<vaadin.plugin.version>8.0.5</vaadin.plugin.version>
<jetty.plugin.version>9.3.9.v20160517</jetty.plugin.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<!-- If there are no local customisations, this can also be "fetch" or "cdn" -->
<vaadin.widgetset.mode>local</vaadin.widgetset.mode>
</properties>
<repositories>
<repository>
<id>vaadin-addons</id>
<url>http://maven.vaadin.com/vaadin-addons</url>
</repository>
</repositories>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>com.vaadin</groupId>
<artifactId>vaadin-bom</artifactId>
<version>${vaadin.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.0.1</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.vaadin</groupId>
<artifactId>vaadin-server</artifactId>
</dependency>
<dependency>
<groupId>com.vaadin</groupId>
<artifactId>vaadin-push</artifactId>
</dependency>
<dependency>
<groupId>com.vaadin</groupId>
<artifactId>vaadin-client-compiled</artifactId>
</dependency>
<dependency>
<groupId>com.vaadin</groupId>
<artifactId>vaadin-themes</artifactId>
</dependency>
<dependency>
<groupId>com.vaadin</groupId>
<artifactId>vaadin-client</artifactId>
<version>7.1-SNAPSHOT</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>3.0.0</version>
<configuration>
<failOnMissingWebXml>false</failOnMissingWebXml>
<!-- Exclude an unnecessary file generated by the GWT compiler. -->
<packagingExcludes>WEB-INF/classes/VAADIN/widgetsets/WEB-INF/**</packagingExcludes>
</configuration>
</plugin>
<plugin>
<groupId>com.vaadin</groupId>
<artifactId>vaadin-maven-plugin</artifactId>
<version>${vaadin.plugin.version}</version>
<executions>
<execution>
<goals>
<goal>update-theme</goal>
<goal>update-widgetset</goal>
<goal>compile</goal>
<!-- Comment out compile-theme goal to use on-the-fly theme compilation -->
<goal>compile-theme</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-clean-plugin</artifactId>
<version>3.0.0</version>
<!-- Clean up also any pre-compiled themes -->
<configuration>
<filesets>
<fileset>
<directory>src/main/webapp/VAADIN/themes</directory>
<includes>
<include>**/styles.css</include>
<include>**/styles.scss.cache</include>
</includes>
</fileset>
</filesets>
</configuration>
</plugin>
<!-- The Jetty plugin allows us to easily test the development build by
running jetty:run on the command line. -->
<plugin>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<version>${jetty.plugin.version}</version>
<configuration>
<scanIntervalSeconds>2</scanIntervalSeconds>
</configuration>
</plugin>
</plugins>
</build>
<profiles>
<profile>
<!-- Vaadin pre-release repositories -->
<id>vaadin-prerelease</id>
<activation>
<activeByDefault>false</activeByDefault>
</activation>
<repositories>
<repository>
<id>vaadin-prereleases</id>
<url>http://maven.vaadin.com/vaadin-prereleases</url>
</repository>
<repository>
<id>vaadin-snapshots</id>
<url>https://oss.sonatype.org/content/repositories/vaadin-snapshots/</url>
<releases>
<enabled>false</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>vaadin-prereleases</id>
<url>http://maven.vaadin.com/vaadin-prereleases</url>
</pluginRepository>
<pluginRepository>
<id>vaadin-snapshots</id>
<url>https://oss.sonatype.org/content/repositories/vaadin-snapshots/</url>
<releases>
<enabled>false</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</pluginRepository>
</pluginRepositories>
</profile>
</profiles>
</project>

Look like you are not using the 8.0.5 vaadin version in one of your dependencies, change the 7.1-SNAPSHOT to ${vaadin.version}
<dependency>
<groupId>com.vaadin</groupId>
<artifactId>vaadin-client</artifactId>
<version>${vaadin.version}</version>
</dependency>
And you can probably remove the following dependency as it is the same as one above:
<dependency>
<groupId>com.vaadin</groupId>
<artifactId>vaadin-client-compiled</artifactId>
</dependency>

Related

Maven does not see testng tests when testing Spring Boot Application is running

I setup simple Spring Boot project to serve basic HTML pages. I wrote a kind of integration tests with testNG. Now, I want to run my tests with maven does not see my tests.
STR:
Run mvn spring-boot:run
Run mvn test
Output:
[INFO] Scanning for projects...
[INFO]
[INFO] ---------------------------< vznd:selenium >----------------------------
[INFO] Building selenium 1.0
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] --- maven-resources-plugin:3.2.0:resources (default-resources) # selenium ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Using 'UTF-8' encoding to copy filtered properties files.
[INFO] Copying 0 resource
[INFO] Copying 27 resources
[INFO]
[INFO] --- maven-compiler-plugin:3.8.1:compile (default-compile) # selenium ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- maven-resources-plugin:3.2.0:testResources (default-testResources) # selenium ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Using 'UTF-8' encoding to copy filtered properties files.
[INFO] skip non existing resourceDirectory C:\Users\vladyslav.kovalenko\OneDrive - FORM.com\Documents\den\selenium-webdriver-tests\src\test\resources
[INFO]
[INFO] --- maven-compiler-plugin:3.8.1:testCompile (default-testCompile) # selenium ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- maven-surefire-plugin:3.0.0-M6:test (default-test) # selenium ---
[INFO] Using auto detected provider org.apache.maven.surefire.junitplatform.JUnitPlatformProvider
[INFO]
[INFO] -------------------------------------------------------
[INFO] T E S T S
[INFO] -------------------------------------------------------
[INFO]
[INFO] Results:
[INFO]
[INFO] Tests run: 0, Failures: 0, Errors: 0, Skipped: 0
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 3.963 s
[INFO] Finished at: 2022-05-09T13:03:51+01:00
[INFO] ------------------------------------------------------------------------
pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<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>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.6.3</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>vznd</groupId>
<artifactId>selenium</artifactId>
<version>1.0</version>
<properties>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<maven-surefire-plugin.version>3.0.0-M6</maven-surefire-plugin.version>
<testng.version>7.5</testng.version>
<selenium-java.version>3.141.59</selenium-java.version>
<commons-io.version>2.11.0</commons-io.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>${testng.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>${selenium-java.version}</version>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>${commons-io.version}</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>${maven-surefire-plugin.version}</version>
<configuration>
<systemPropertyVariables>
<webdriver.chrome.driver>/tmp/chromedriver/chromedriver</webdriver.chrome.driver>
</systemPropertyVariables>
<suiteXmlFiles>
<suiteXmlFile>testng.xml</suiteXmlFile>
</suiteXmlFiles>
</configuration>
</plugin>
</plugins>
</build>
</project>
testng.xml:
<!DOCTYPE suite SYSTEM "https://testng.org/testng-1.0.dtd" >
<suite name="SeleniumApp Tests" parallel="false">
<test name="Selenium Test">
<classes>
<class name="vznd.selenium.AlertsControllerTest"/>
<class name="vznd.selenium.GettingBrowserInformationTest"/>
<class name="vznd.selenium.FramesTest"/>
<class name="vznd.selenium.BrowserNavigationTest"/>
<class name="vznd.selenium.KeyboardActionsTest"/>
<class name="vznd.selenium.WindowsTest"/>
</classes>
</test>
</suite>
Test example:
package vznd.selenium;
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.testng.Assert;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
public class FramesTest extends BaseTest {
#BeforeMethod
public void openPageWithIframes() {
driver.get(HTMLPath.FRAMES);
}
#Test
public void switchToFrameUsingWebElement() {
WebElement greenFrame = driver.findElement(By.id("first-iframe"));
driver.switchTo().frame(greenFrame);
WebElement table = driver.findElement(By.cssSelector("table[id='green-table']"));
Assert.assertNotNull(table, "The table WebElement object was null!");
}
}
Spring Boot Application:
package vznd.selenium;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
#SpringBootApplication
public class SeleniumApp {
public static void main(String[] args) {
SpringApplication.run(SeleniumApp.class, args);
}
}
Controller example:
package vznd.selenium.controllers;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
#Controller
public class FramesController {
#GetMapping("/iframes")
public String iframes() {
return "iframes";
}
}
I tried to google about similar problems, but most answers is about naming test classes with *Test suffix and that is not my case.
The tests are executed in IDEA by right-click on the project -> Run -> All tests.
Please, advice me how I can get tests executed with maven.
If you see the logs surefire is not detecting TestNG.
Using auto detected provider org.apache.maven.surefire.junitplatform.JUnitPlatformProvider
If you remove SpringBoot will be: Using auto detected provider org.apache.maven.surefire.testng.TestNGProvider
Try adding TestNG dependency to surefire plugin:
<project>
...
<dependencies>
...
<dependency>
<groupId>org.apache.maven.surefire</groupId>
<artifactId>surefire-testng</artifactId>
<version>3.0.0-M5</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M5</version>
<configuration>
<systemPropertyVariables>
<webdriver.chrome.driver>/tmp/chromedriver/chromedriver</webdriver.chrome.driver>
</systemPropertyVariables>
<suiteXmlFiles>
<suiteXmlFile>testng.xml</suiteXmlFile>
</suiteXmlFiles>
</configuration>
<dependencies>
<dependency>
<groupId>org.apache.maven.surefire</groupId>
<artifactId>surefire-testng</artifactId>
<version>3.0.0-M5</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
</project>

mvn test command not running tests in a Spring Boot project

This is my pom file
<?xml version="1.0" encoding="UTF-8"?>
<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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.2.4.RELEASE</version>
<relativePath /> <!-- lookup parent from repository -->
</parent>
<groupId>com.ricardo</groupId>
<artifactId>cdh</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>cdh</name>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>1.8</java.version>
<azure.version>2.2.0</azure.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-mongodb</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-config</artifactId>
<version>2.0.1.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.ldap</groupId>
<artifactId>spring-ldap-core</artifactId>
<version>2.3.3.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-ui</artifactId>
<version>1.1.44</version>
</dependency>
<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-core</artifactId>
<version>1.1.44</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
</exclusion>
</exclusions>
</dependency>
<!-- https://mvnrepository.com/artifact/org.projectlombok/lombok -->
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.modelmapper</groupId>
<artifactId>modelmapper</artifactId>
<version>2.3.6</version>
</dependency>
<dependency>
<groupId>io.jsonwebtoken</groupId>
<artifactId>jjwt</artifactId>
<version>0.9.1</version>
</dependency>
<dependency>
<groupId>com.microsoft.azure</groupId>
<artifactId>azure-storage</artifactId>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.5</version>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
</dependency>
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<version>20190722</version>
</dependency>
<dependency>
<groupId>com.azure</groupId>
<artifactId>azure-security-keyvault-secrets</artifactId>
<version>4.0.0</version>
</dependency>
<dependency>
<groupId>com.azure</groupId>
<artifactId>azure-identity</artifactId>
<version>1.0.0</version>
</dependency>
<dependency>
<groupId>com.microsoft.azure</groupId>
<artifactId>azure-eventhubs</artifactId>
<version>2.3.0</version>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>com.microsoft.azure</groupId>
<artifactId>azure-spring-boot-bom</artifactId>
<version>${azure.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
<profiles>
<profile>
<id>local</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<properties>
<activatedProperties>local</activatedProperties>
</properties>
</profile>
<profile>
<id>dev</id>
<properties>
<activatedProperties>dev</activatedProperties>
</properties>
</profile>
<profile>
<id>test</id>
<properties>
<activatedProperties>test</activatedProperties>
</properties>
</profile>
</profiles>
</project>
When I run mvn test this is the output and none of the test run. However every test work as expected using the IDE Intellij.
[INFO] Building cdh 0.0.1-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] --- maven-clean-plugin:3.1.0:clean (default-clean) # cdh ---
[INFO] Deleting /Users/ricardochampa/mypath/target
[INFO]
[INFO] --- maven-resources-plugin:3.1.0:resources (default-resources) # cdh ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 4 resources
[INFO] Copying 4 resources
[INFO]
[INFO] --- maven-compiler-plugin:3.8.1:compile (default-compile) # cdh ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 140 source files to /Users/mypath/cdh-back/target/classes
[INFO] /Users/mypath/cdh-back/src/main/java/com/ricardo/cdh/mappers/OrdersMapper.java: Some input files use unchecked or unsafe operations.
[INFO] /Users/mypath/cdh-back/src/main/java/com/ricardo/cdh/mappers/OrdersMapper.java: Recompile with -Xlint:unchecked for details.
[INFO]
[INFO] --- maven-resources-plugin:3.1.0:testResources (default-testResources) # cdh ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory /Users/mypath/cdh-back/src/test/resources
[INFO]
[INFO] --- maven-compiler-plugin:3.8.1:testCompile (default-testCompile) # cdh ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 6 source files to /Users/mypath/cdh-back/target/test-classes
[INFO]
[INFO] --- maven-surefire-plugin:2.22.2:test (default-test) # cdh ---
[INFO]
[INFO] -------------------------< com.ricardo:cdh >--------------------------
[INFO] Building cdh 0.0.1-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] --- maven-resources-plugin:3.1.0:resources (default-resources) # cdh ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 4 resources
[INFO] Copying 4 resources
[INFO]
[INFO] --- maven-compiler-plugin:3.8.1:compile (default-compile) # cdh ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- maven-resources-plugin:3.1.0:testResources (default-testResources) # cdh ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory /Users/mypath/cdh-back/src/test/resources
[INFO]
[INFO] --- maven-compiler-plugin:3.8.1:testCompile (default-testCompile) # cdh ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- maven-surefire-plugin:2.22.2:test (default-test) # cdh ---
[INFO]
[INFO] -------------------------------------------------------
[INFO] T E S T S
[INFO] -------------------------------------------------------
[INFO]
[INFO] Results:
[INFO]
[INFO] Tests run: 0, Failures: 0, Errors: 0, Skipped: 0
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 2.484 s
[INFO] Finished at: 2020-09-30T22:18:05+02:00
[INFO] ------------------------------------------------------------------------
UPDATE
I've just try with the following pom.xml
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.2</version>
<configuration>
<includes>
<include>*Test.java</include>
</includes>
</configuration>
</plugin>
</plugins>
</build>
And I tried this as well.
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.2</version>
<configuration>
<includes>
<include>customWildcardPattern</include>
</includes>
</configuration>
</plugin>
</plugins>
</build>
And this...
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.2</version>
</plugin>
</plugins>
</build>
And this...
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M5</version>
</plugin>
</plugins>
</build>
None of them works :(
The project structure.
An example of test class: ProductsServiceTest
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.junit.Assert.assertEquals;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.*;
#RunWith(SpringJUnit4ClassRunner.class)
#SpringBootTest
public class ProductsServiceTest {
#Mock ProductsRepository productsRepository;
#Mock ResourceService resourceService;
#Autowired #InjectMocks ProductsService service;
private ProductsEntity productsEntity = new ProductsEntity();
private final String stubSearchText = "search this text with results";
private final String stubSearchTextNoResults = "search this text without results";
private final String notFoundStubID = "ID NOT EXISTS";
private final String stubID = "id";
private final String stubName = "name";
#Before
public void setUp() throws Exception {
MockitoAnnotations.initMocks(this);
productsEntity.setId(stubID);
productsEntity.setName(stubName);
when(productsRepository.findById(stubID)).thenReturn(Optional.of(productsEntity));
when(productsRepository.findById(notFoundStubID)).thenReturn(Optional.empty());
doNothing().when(resourceService).changeResourceStatus(any(String.class), any(String.class));
List<ProductsEntity> productsEntityList = new ArrayList<>();
productsEntityList.add(productsEntity);
when(productsRepository.searchProducts(stubSearchText)).thenReturn(productsEntityList);
}
#Test
public void whenGetProduct() throws CdhException {
ProductsDto productsDto = service.getProduct(stubID);
assertEquals(productsDto.getId(), stubID);
assertEquals(productsDto.getName(), stubName);
}
#Test
public void whenGetProductNotExist() {
assertThatThrownBy(() -> service.getProduct(notFoundStubID)).isInstanceOf(CdhException.class);
}
#Test
public void whenCreateProduct() {
ProductsDto dto = new ProductsDto();
dto.setId("fake id");
dto.setIdResource("fake id resource");
service.createProduct(dto);
verify(service.productsRepository).save(any(ProductsEntity.class));
}
#Test
public void whenDeleteProduct() throws CdhException {
service.deleteProduct(stubID);
verify(service.productsRepository).save(any(ProductsEntity.class));
}
}
I finally fix it.
My problems was JUnit4, according to docs https://maven.apache.org/surefire/maven-surefire-plugin/examples/junit.html I should add the plugin like this.
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M5</version>
<dependencies>
<dependency>
<groupId>org.apache.maven.surefire</groupId>
<artifactId>surefire-junit4</artifactId>
<version>3.0.0-M5</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
1. First potential root cause : Test class naming
Make sure that your test class name matchs one of those default Maven Surefire plugin patterns:
Test*.java
*Test.java
*Tests.java
*TestCase.java
If you need to customize it, you need to add :
<project>
[...]
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M5</version>
<configuration>
<includes>
<include>TO_BE_REPLACED_BY_YOUR_CUSTOM_WILDCARD_PATTERN</include>
</includes>
</configuration>
</plugin>
</plugins>
</build>
[...]
</project>
###UPDATE####:
2. Second potential root cause that may lead to not executing test is the exclusion part in your spring-boot-starter-test
Replace:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
</exclusion>
</exclusions>
</dependency>
by:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
maven surefire plugin is missing in your pom.xml.
Be sure to annotate your test methods with #Test:
import org.junit.jupiter.api.Test; // <-- or whatever you are using..
public class SomeTest {
...
#Test // <----
public void testSomething() {
...
}
...
}
The key here is to understand the test engines that Spring uses.
In my case, I coded API tests with #RunWith(SpringRunner.class), which is under JUnit4, which runs with junit-vintage-engine.
But the unit tests are coded with JUnit Jupiter, which is under JUnit5, which runs with junit-jupiter-engine.
The default engine of SpringBoot is the junit-jupiter-engine. So we have to tell to Spring that we also want to use junit-vintage-engine.
We can simply add the dependency in our pom.xml:
<dependency>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
<scope>test</scope>
</dependency>
Or, if we want to use maven-surefire, we can add the dependency inside the plugin:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M7</version>
<dependencies>
<dependency>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
<version>5.7.0</version>
</dependency>
</dependencies>
</plugin>

BeanDefinitionStoreException: Failed to parse configuration class ... because it does not exist

atlas-package runs without errors. But I got errors with Quick Reload.
Error is:
JiraRendererPlugin.class] cannot be opened because it does not exist
I imported this interface in java code. No errors while compilation still.
I changed dependency for jira-core in pom.xml. From "provided" to "runtime" => I got out of memory error while compilation. Added memory to maven - doesn't help.
Errors
[INFO] [talledLocalContainer] 2020-06-02 20:17:15,258 QuickReload - Plugin Installer INFO [c.a.plugin.loaders.ScanningPluginLoader] Removed plugin 'com.vladmak.ringcentral.jira-cmp-plgin'
[INFO] [talledLocalContainer] 2020-06-02 20:17:15,314 QuickReload - Plugin Installer INFO [c.a.plugin.util.WaitUntil] Plugins that have yet to be enabled: (1): [com.vladmak.ringcentral.jira-cmp-plgin], 300 seconds remaining
[INFO] [talledLocalContainer] 2020-06-02 20:17:15,337 ThreadPoolAsyncTaskExecutor::Thread 52 ERROR [c.a.p.osgi.factory.OsgiPlugin] Unable to start the plugin container for plugin 'com.vladmak.ringcentral.jira-cmp-plgin'
[INFO] [talledLocalContainer] org.springframework.beans.factory.BeanDefinitionStoreException: Failed to parse configuration class [com.vladmak.ringcentral.jiracmp.CMRRenderer]; nested exception is java.io.FileNotFoundException: class path resource [com/atlassian/jira/issue/fields/renderer/JiraRendererPlugin.class] cannot be opened because it does not exist
[INFO] [talledLocalContainer] at org.springframework.context.annotation.ConfigurationClassParser.parse(ConfigurationClassParser.java:182)
[INFO] [talledLocalContainer] at org.springframework.context.annotation.ConfigurationClassPostProcessor.processConfigBeanDefinitions(ConfigurationClassPostProcessor.java:321)
[INFO] [talledLocalContainer] at org.springframework.context.annotation.ConfigurationClassPostProcessor.postProcessBeanFactory(ConfigurationClassPostProcessor.java:261)
[INFO] [talledLocalContainer] at org.eclipse.gemini.blueprint.context.support.AbstractDelegatedExecutionApplicationContext.invokeBeanFactoryPostProcessors(AbstractDelegatedExecutionApplicationContext.java:444)
[INFO] [talledLocalContainer] at org.eclipse.gemini.blueprint.context.support.AbstractDelegatedExecutionApplicationContext.invokeBeanFactoryPostProcessors(AbstractDelegatedExecutionApplicationContext.java:414)
[INFO] [talledLocalContainer] at org.eclipse.gemini.blueprint.context.support.AbstractDelegatedExecutionApplicationContext.invokeBeanFactoryPostProcessors(AbstractDelegatedExecutionApplicationContext.java:362)
[INFO] [talledLocalContainer] at org.eclipse.gemini.blueprint.context.support.AbstractDelegatedExecutionApplicationContext$3.run(AbstractDelegatedExecutionApplicationContext.java:254)
[INFO] [talledLocalContainer] at org.eclipse.gemini.blueprint.util.internal.PrivilegedUtils.executeWithCustomTCCL(PrivilegedUtils.java:85)
[INFO] [talledLocalContainer] at org.eclipse.gemini.blueprint.context.support.AbstractDelegatedExecutionApplicationContext.startRefresh(AbstractDelegatedExecutionApplicationContext.java:220)
[INFO] [talledLocalContainer] at org.eclipse.gemini.blueprint.extender.internal.dependencies.startup.DependencyWaiterApplicationContextExecutor.stageOne(DependencyWaiterApplicationContextExecutor.java:224)
[INFO] [talledLocalContainer] at org.eclipse.gemini.blueprint.extender.internal.dependencies.startup.DependencyWaiterApplicationContextExecutor.refresh(DependencyWaiterApplicationContextExecutor.java:177)
[INFO] [talledLocalContainer] at org.eclipse.gemini.blueprint.context.support.AbstractDelegatedExecutionApplicationContext.refresh(AbstractDelegatedExecutionApplicationContext.java:157)
[INFO] [talledLocalContainer] at org.eclipse.gemini.blueprint.extender.internal.activator.LifecycleManager$1.run(LifecycleManager.java:207)
[INFO] [talledLocalContainer] at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
[INFO] [talledLocalContainer] at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
[INFO] [talledLocalContainer] at java.lang.Thread.run(Thread.java:748)
[INFO] [talledLocalContainer] Caused by: java.io.FileNotFoundException: class path resource [com/atlassian/jira/issue/fields/renderer/JiraRendererPlugin.class] cannot be opened because it does not exist
[INFO] [talledLocalContainer] at org.springframework.core.io.ClassPathResource.getInputStream(ClassPathResource.java:172)
[INFO] [talledLocalContainer] at org.springframework.core.type.classreading.SimpleMetadataReader.<init>(SimpleMetadataReader.java:50)
Class
package com.vladmak.ringcentral.jiracmp;
import com.atlassian.jira.issue.fields.renderer.wiki.AtlassianWikiRenderer;
import com.atlassian.event.api.EventPublisher;
//import com.atlassian.jira.issue.fields.renderer.IssueRenderContext;
//import com.atlassian.jira.plugin.renderer.JiraRendererModuleDescriptor;
import com.atlassian.jira.util.velocity.VelocityRequestContextFactory;
import com.atlassian.jira.config.properties.ApplicationProperties;
import com.atlassian.jira.config.FeatureManager;
import org.springframework.beans.factory.DisposableBean;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import com.atlassian.plugin.spring.scanner.annotation.imports.JiraImport;
import com.atlassian.jira.issue.fields.renderer.JiraRendererPlugin;
//import com.atlassian.plugin.spring.scanner.annotation.export.ExportAsService;
//import com.atlassian.jira.issue.fields.renderer.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
#Component
public class CMRRenderer extends AtlassianWikiRenderer implements InitializingBean, DisposableBean {
private static final Logger log = LoggerFactory.getLogger(CMRRenderer.class);
public static final String TYPE = "cmr-renderer";
#JiraImport
private final EventPublisher eventPublisher;
#Autowired
public CMRRenderer(#JiraImport EventPublisher eventPublisher_f,
ApplicationProperties applicationProperties,
VelocityRequestContextFactory velocityRequestContextFactory,
FeatureManager featureManager) {
super(eventPublisher_f, applicationProperties, velocityRequestContextFactory, featureManager);
this.eventPublisher = eventPublisher_f;
}
/**
* Called when the plugin has been enabled.
*
* #throws Exception
*/
#Override
public void afterPropertiesSet() throws Exception {
log.info("[CMP] Enabling plugin");
eventPublisher.register(this);
}
/**
* Called when the plugin is being disabled or removed.
*
* #throws Exception
*/
#Override
public void destroy() throws Exception {
log.info("[CMP] Disabling plugin");
eventPublisher.unregister(this);
}
public String getRendererType() {
return TYPE;
}
}
pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.vladmak.ringcentral</groupId>
<artifactId>jira-cmp-plgin</artifactId>
<version>1.0-SNAPSHOT</version>
<organization>
<name>VLADmak</name>
<url>https://www.linkedin.com/in/vladmak/</url>
</organization>
<name>JIRA CMP Plugin</name>
<description>Add panel with CMRs details</description>
<packaging>atlassian-plugin</packaging>
<dependencies>
<dependency>
<groupId>com.atlassian.jira</groupId>
<artifactId>jira-api</artifactId>
<version>${jira.version}</version>
<scope>provided</scope>
</dependency>
<!-- Add dependency on jira-core if you want access to JIRA implementation classes as well as the sanctioned API. -->
<!-- This is not normally recommended, but may be required eg when migrating a plugin originally developed against JIRA 4.x -->
<dependency>
<groupId>com.atlassian.jira</groupId>
<artifactId>jira-core</artifactId>
<version>${jira.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.10</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.atlassian.plugin</groupId>
<artifactId>atlassian-spring-scanner-annotation</artifactId>
<version>${atlassian.spring.scanner.version}</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.atlassian.plugin</groupId>
<artifactId>atlassian-spring-scanner-runtime</artifactId>
<version>${atlassian.spring.scanner.version}</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>javax.inject</groupId>
<artifactId>javax.inject</artifactId>
<version>1</version>
<scope>provided</scope>
</dependency>
<!-- WIRED TEST RUNNER DEPENDENCIES -->
<dependency>
<groupId>com.atlassian.plugins</groupId>
<artifactId>atlassian-plugins-osgi-testrunner</artifactId>
<version>${plugin.testrunner.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>javax.ws.rs</groupId>
<artifactId>jsr311-api</artifactId>
<version>1.1.1</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.2.2-atlassian-1</version>
</dependency>
<!-- Uncomment to use TestKit in your project. Details at https://bitbucket.org/atlassian/jira-testkit -->
<!-- You can read more about TestKit at https://developer.atlassian.com/display/JIRADEV/Plugin+Tutorial+-+Smarter+integration+testing+with+TestKit -->
<!--
<dependency>
<groupId>com.atlassian.jira.tests</groupId>
<artifactId>jira-testkit-client</artifactId>
<version>${testkit.version}</version>
<scope>test</scope>
</dependency>
-->
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-all</artifactId>
<version>1.8.5</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.atlassian.renderer</groupId>
<artifactId>atlassian-renderer</artifactId>
<version>8.0.9</version>
<scope>provided</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>com.atlassian.maven.plugins</groupId>
<artifactId>jira-maven-plugin</artifactId>
<version>${amps.version}</version>
<extensions>true</extensions>
<configuration>
<productVersion>${jira.version}</productVersion>
<productDataVersion>${jira.version}</productDataVersion>
<!-- Uncomment to install TestKit backdoor in JIRA. -->
<!--
<pluginArtifacts>
<pluginArtifact>
<groupId>com.atlassian.jira.tests</groupId>
<artifactId>jira-testkit-plugin</artifactId>
<version>${testkit.version}</version>
</pluginArtifact>
</pluginArtifacts>
-->
<enableQuickReload>true</enableQuickReload>
<!-- See here for an explanation of default instructions: -->
<!-- https://developer.atlassian.com/docs/advanced-topics/configuration-of-instructions-in-atlassian-plugins -->
<instructions>
<Atlassian-Plugin-Key>${atlassian.plugin.key}</Atlassian-Plugin-Key>
<!-- Add package to export here -->
<Export-Package>com.example.plugins.tutorial.api,</Export-Package>
<!-- Add package import here -->
<Import-Package>org.springframework.osgi.*;resolution:="optional", org.eclipse.gemini.blueprint.*;resolution:="optional", *</Import-Package>
<!-- Ensure plugin is spring powered -->
<Spring-Context>*</Spring-Context>
</instructions>
</configuration>
</plugin>
<plugin>
<groupId>com.atlassian.plugin</groupId>
<artifactId>atlassian-spring-scanner-maven-plugin</artifactId>
<version>${atlassian.spring.scanner.version}</version>
<executions>
<execution>
<goals>
<goal>atlassian-spring-scanner</goal>
</goals>
<phase>process-classes</phase>
</execution>
</executions>
<configuration>
<scannedDependencies>
<dependency>
<groupId>com.atlassian.plugin</groupId>
<artifactId>atlassian-spring-scanner-external-jar</artifactId>
</dependency>
</scannedDependencies>
<verbose>false</verbose>
</configuration>
</plugin>
</plugins>
</build>
<properties>
<jira.version>7.13.0</jira.version>
<amps.version>8.0.2</amps.version>
<plugin.testrunner.version>2.0.1</plugin.testrunner.version>
<atlassian.spring.scanner.version>1.2.13</atlassian.spring.scanner.version>
<!-- This property ensures consistency between the key in atlassian-plugin.xml and the OSGi bundle's key. -->
<atlassian.plugin.key>${project.groupId}.${project.artifactId}</atlassian.plugin.key>
<!-- TestKit version 6.x for JIRA 6.x -->
<testkit.version>6.3.11</testkit.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
</project>
This class JiraRendererPlugin is part of
<dependency>
<groupId>com.atlassian.jira</groupId>
<artifactId>jira-api</artifactId>
<version>${jira.version}</version>
<scope>provided</scope>
</dependency>
You are using the correct scope and everything else seems legit.
I suggest to erase your local copy jira-api, v7.13.0
C:\Applications\Atlassian\atlassian-plugin-sdk-8.0.16\repository\com\atlassian\jira\jira-api\7.13.0
After erasing, re run atlas-run or atlas-debug
I am not sure if this would fix it. Just a wild guess.

Jacoco + JUnit 5.0 DynamicTest not working

I am trying to generate a code coverage report using Jacoco with JUnit 5 and Spring Boot. And I"m trying to use the DynamicTest feature of JUnit 5. It runs successfully but the Dynamic Tests are not covered in the test coverage report generated by jacoco. Is JUnit 5 Dynamic Test not covered by Jacoco at the moment?
Here is the code:
#RunWith(JUnitPlatform.class)
#SelectPackages("com.troll.jpt.abc.model")
#SelectClasses({Status.class})
public class DynamicModelTester {
private Status status;
#BeforeEach
public void setUp() {
status = new Status();
}
#TestFactory
public Stream<DynamicTest> checkDynamicTestsFromStream() {
List<String> input = Arrays.asList("abc");
List<String> output = Arrays.asList("abc");
status.setCode(input.get(0));
return input.stream().map(str -> DynamicTest.dynamicTest("status test", () -> {
assertEquals(output.get(0), status.getCode());
}));
}
}
The jacoco plugin I'm using is as :
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.2-SNAPSHOT</version>
<executions>
<execution>
<id>prepare-agent</id>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>report</id>
<phase>prepare-package</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
<execution>
<id>post-unit-test</id>
<phase>test</phase>
<goals>
<goal>report</goal>
</goals>
<configuration>
<!-- Sets the path to the file which contains the execution data. -->
<dataFile>target/jacoco.exec</dataFile>
<!-- Sets the output directory for the code coverage report. -->
<outputDirectory>target/jacoco-ut</outputDirectory>
</configuration>
</execution>
</executions>
<configuration>
<systemPropertyVariables>
<jacoco-agent.destfile>target/jacoco.exec</jacoco-agent.destfile>
</systemPropertyVariables>
</configuration>
</plugin>
It runs successfully but the Dynamic Tests are not covered in the test coverage report generated by jacoco.
jacoco-maven-plugin:report doesn't display coverage in tests, it displays coverage of a target of a test - in your case target seems to be class Status, whose definition is completely absent. For future I highly recommend to read https://stackoverflow.com/help/mcve and follow its recommendations, especially part about "Complete":
Make sure all information necessary to reproduce the problem is included
Generic answer on questions like "does JaCoCo support JUnit 5 Dynamic Test?" is: JaCoCo records fact that code was executed independently from the way how it was executed - via JUnit 4 or JUnit 5, or even manually or whatever the other way of execution.
And generic answer on questions like "why some code is not marked as covered?" is: make sure that code is actually executed, in case of automatic tests this means - make sure that these tests are actually executed.
But let's give a try with JUnit 5 Dynamic Test. In absence of src/main/java/Status.java I'll assume that it is something like
public class Status {
private String code;
public void setCode(String code) {
this.code = code;
}
public String getCode() {
return code;
}
}
No idea why you need systemPropertyVariables, snapshot version of jacoco-maven-plugin, multiple executions of report and redundant specification of dataFile with its default value, so will also assume that complete pom.xml after slight cleanup looks like
<?xml version="1.0" encoding="UTF-8"?>
<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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.example</groupId>
<artifactId>example</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>5.2.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>5.2.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
<version>5.2.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-runner</artifactId>
<version>1.2.0</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.7.0</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.21.0</version>
</plugin>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.1</version>
<configuration>
<outputDirectory>target/jacoco-ut</outputDirectory>
</configuration>
<executions>
<execution>
<goals>
<goal>prepare-agent</goal>
<goal>report</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
After placing
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.DynamicTest;
import org.junit.jupiter.api.TestFactory;
import org.junit.platform.runner.JUnitPlatform;
import org.junit.platform.suite.api.SelectClasses;
import org.junit.platform.suite.api.SelectPackages;
import org.junit.runner.RunWith;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Stream;
import static org.junit.Assert.assertEquals;
#RunWith(JUnitPlatform.class)
#SelectPackages("com.troll.jpt.abc.model")
#SelectClasses({Status.class})
public class DynamicModelTester {
private Status status;
#BeforeEach
public void setUp() {
status = new Status();
}
#TestFactory
public Stream<DynamicTest> dynamicTestsFromStream() {
List<String> input = Arrays.asList("abc");
List<String> output = Arrays.asList("abc");
status.setCode(input.get(0));
return input.stream().map(str -> DynamicTest.dynamicTest("status test", () -> {
assertEquals(output.get(0), status.getCode());
}));
}
}
into src/test/java/DynamicModelTester.java and execution of mvn clean verify:
[INFO] --- maven-surefire-plugin:2.21.0:test (default-test) # example ---
[INFO]
[INFO] --- maven-jar-plugin:2.4:jar (default-jar) # example ---
[INFO] Building jar: /private/tmp/jacoco/target/example-1.0-SNAPSHOT.jar
[INFO]
[INFO] --- jacoco-maven-plugin:0.8.1:report (default) # example ---
[INFO] Skipping JaCoCo execution due to missing execution data file.
Last line is quite suspicious as well as absence of number of tests executed by maven-surefire-plugin together with absence of target/surefire-reports/.
Let's rename DynamicModelTester into DynamicModelTest and execute mvn clean verify again:
[INFO] --- maven-surefire-plugin:2.21.0:test (default-test) # example ---
[INFO]
[INFO] -------------------------------------------------------
[INFO] T E S T S
[INFO] -------------------------------------------------------
[INFO] Running DynamicModelTest
[INFO] Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.023 s - in DynamicModelTest
[INFO]
[INFO] Results:
[INFO]
[INFO] Tests run: 1, Failures: 0, Errors: 0, Skipped: 0
[INFO]
[INFO]
[INFO] --- maven-jar-plugin:2.4:jar (default-jar) # example ---
[INFO] Building jar: /private/tmp/jacoco/target/example-1.0-SNAPSHOT.jar
[INFO]
[INFO] --- jacoco-maven-plugin:0.8.1:report (default) # example ---
[INFO] Loading execution data file /private/tmp/jacoco/target/jacoco.exec
[INFO] Analyzed bundle 'example' with 1 classes
Compared to previous attempt test was executed this time. And coverage report target/jacoco-ut/default/Status.html looks like:
I believe that the reason of the fact that test is not executed lies in a default value of includes of maven-surefire-plugin :
A list of elements specifying the tests (by pattern) that
should be included in testing. When not specified and when the test
parameter is not specified, the default includes will be
<includes>
<include>**/Test*.java</include>
<include>**/*Test.java</include>
<include>**/*Tests.java</include>
<include>**/*TestCase.java</include>
</includes>
DynamicModelTester.java doesn't match any of these patters, while DynamicModelTest.java matches second, but I'll leave verification of this as a little exercise.

How to make a standalone JPA (with OpenJPA implementation) Maven project start with exec maven plugin?

I have a very simple JPA project. This is my directory layout..
/src
/main
/java
/biz
/tugay
/jpaExamples
App.java
/model
Person.java
/resources
/META-INF
persistence.xml
So it is pretty standard maven directory layout. This is 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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>biz.tugay</groupId>
<artifactId>jpa-examples</artifactId>
<packaging>jar</packaging>
<version>1.0-SNAPSHOT</version>
<name>jpa-examples</name>
<url>http://www.tugay.biz</url>
<dependencies>
<dependency>
<groupId>org.eclipse.persistence</groupId>
<artifactId>javax.persistence</artifactId>
<version>2.1.1</version>
</dependency>
<dependency>
<groupId>org.apache.openjpa</groupId>
<artifactId>openjpa</artifactId>
<version>2.4.2</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.apache.openjpa</groupId>
<artifactId>openjpa-persistence</artifactId>
<version>2.4.2</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<version>1.4.192</version>
</dependency>
</dependencies>
<build>
<finalName>bare-maven-project</finalName>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.2.1</version>
<configuration>
<mainClass>biz.tugay.jpaExamples.App</mainClass>
</configuration>
</plugin>
</plugins>
<resources>
<resource>
<directory>src/main/resources</directory>
</resource>
</resources>
</build>
<properties>
<maven.compiler.source>1.7</maven.compiler.source>
<maven.compiler.target>1.7</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
</project>
and persistence.xml
http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"
version="2.0">
<persistence-unit name="jpaExamples" transaction-type="RESOURCE_LOCAL">
<provider>org.apache.openjpa.persistence.PersistenceProviderImpl</provider>
<class>biz.tugay.jpaExamples.model.Person</class>
<properties>
<property name="javax.persistence.jdbc.driver" value="org.h2.Driver"/>
<property name="javax.persistence.jdbc.url" value="jdbc:h2:~/sampleh2db;TRACE_LEVEL_FILE=0"/>
<property name="javax.persistence.jdbc.user" value="test"/>
<property name="javax.persistence.jdbc.password" value="test"/>
<property name="openjpa.Log" value="DefaultLevel=ERROR, Tool=ERROR"/>
</properties>
</persistence-unit>
Finally, App.java
package biz.tugay.jpaExamples;
import biz.tugay.jpaExamples.model.Person;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;
import java.sql.*;
public class App {
private static final String PERSISTENCE_UNIT_NAME = "jpaExamples";
private static final EntityManagerFactory ENTITY_MANAGER_FACTORY = Persistence.createEntityManagerFactory(PERSISTENCE_UNIT_NAME);
public static void main(String[] args) throws ClassNotFoundException, SQLException {
final EntityManager entityManager = ENTITY_MANAGER_FACTORY.createEntityManager();
final Person person = entityManager.find(Person.class, 1L);
System.out.println(person);
entityManager.close();
ENTITY_MANAGER_FACTORY.close();
}
}
When I execute App.java from IntelliJ, all is fine. I will see the output:
Person{id=1, firstname='Koray', lastname='Tugay', address='Yıldız Cd. 43 / 30', city='İstanbul'}
This is what IntelliJ generates, when running main in App.java
"C:\Program Files\Java\jdk1.8.0_121\bin\java" -Didea.launcher.port=7534 "-Didea.launcher.bin.path=C:\Program Files (x86)\JetBrains\IntelliJ IDEA 2016.3.3\bin" -Dfile.encoding=UTF-8 -classpath "C:\Program Files\Java\jdk1.8.0_121\jre\lib\charsets.jar;C:\Program Files\Java\jdk1.8.0_121\jre\lib\deploy.jar;C:\Program Files\Java\jdk1.8.0_121\jre\lib\ext\access-bridge-64.jar;C:\Program Files\Java\jdk1.8.0_121\jre\lib\ext\cldrdata.jar;C:\Program Files\Java\jdk1.8.0_121\jre\lib\ext\dnsns.jar;C:\Program Files\Java\jdk1.8.0_121\jre\lib\ext\jaccess.jar;C:\Program Files\Java\jdk1.8.0_121\jre\lib\ext\jfxrt.jar;C:\Program Files\Java\jdk1.8.0_121\jre\lib\ext\localedata.jar;C:\Program Files\Java\jdk1.8.0_121\jre\lib\ext\nashorn.jar;C:\Program Files\Java\jdk1.8.0_121\jre\lib\ext\sunec.jar;C:\Program Files\Java\jdk1.8.0_121\jre\lib\ext\sunjce_provider.jar;C:\Program Files\Java\jdk1.8.0_121\jre\lib\ext\sunmscapi.jar;C:\Program Files\Java\jdk1.8.0_121\jre\lib\ext\sunpkcs11.jar;C:\Program Files\Java\jdk1.8.0_121\jre\lib\ext\zipfs.jar;C:\Program Files\Java\jdk1.8.0_121\jre\lib\javaws.jar;C:\Program Files\Java\jdk1.8.0_121\jre\lib\jce.jar;C:\Program Files\Java\jdk1.8.0_121\jre\lib\jfr.jar;C:\Program Files\Java\jdk1.8.0_121\jre\lib\jfxswt.jar;C:\Program Files\Java\jdk1.8.0_121\jre\lib\jsse.jar;C:\Program Files\Java\jdk1.8.0_121\jre\lib\management-agent.jar;C:\Program Files\Java\jdk1.8.0_121\jre\lib\plugin.jar;C:\Program Files\Java\jdk1.8.0_121\jre\lib\resources.jar;C:\Program Files\Java\jdk1.8.0_121\jre\lib\rt.jar;C:\Users\Koray Tugay\Desktop\jpa-examples\target\classes;C:\Users\Koray Tugay\.m2\repository\org\eclipse\persistence\javax.persistence\2.1.1\javax.persistence-2.1.1.jar;C:\Users\Koray Tugay\.m2\repository\org\apache\openjpa\openjpa\2.4.2\openjpa-2.4.2.jar;C:\Users\Koray Tugay\.m2\repository\commons-lang\commons-lang\2.6\commons-lang-2.6.jar;C:\Users\Koray Tugay\.m2\repository\commons-collections\commons-collections\3.2.2\commons-collections-3.2.2.jar;C:\Users\Koray Tugay\.m2\repository\net\sourceforge\serp\serp\1.15.1\serp-1.15.1.jar;C:\Users\Koray Tugay\.m2\repository\junit\junit\3.8.1\junit-3.8.1.jar;C:\Users\Koray Tugay\.m2\repository\org\apache\geronimo\specs\geronimo-jms_1.1_spec\1.1.1\geronimo-jms_1.1_spec-1.1.1.jar;C:\Users\Koray Tugay\.m2\repository\org\apache\geronimo\specs\geronimo-jta_1.1_spec\1.1.1\geronimo-jta_1.1_spec-1.1.1.jar;C:\Users\Koray Tugay\.m2\repository\commons-pool\commons-pool\1.6\commons-pool-1.6.jar;C:\Users\Koray Tugay\.m2\repository\org\apache\xbean\xbean-asm5-shaded\3.17\xbean-asm5-shaded-3.17.jar;C:\Users\Koray Tugay\.m2\repository\org\apache\geronimo\specs\geronimo-jpa_2.0_spec\1.1\geronimo-jpa_2.0_spec-1.1.jar;C:\Users\Koray Tugay\.m2\repository\org\apache\openjpa\openjpa-persistence\2.4.2\openjpa-persistence-2.4.2.jar;C:\Users\Koray Tugay\.m2\repository\org\apache\openjpa\openjpa-kernel\2.4.2\openjpa-kernel-2.4.2.jar;C:\Users\Koray Tugay\.m2\repository\org\apache\openjpa\openjpa-lib\2.4.2\openjpa-lib-2.4.2.jar;C:\Users\Koray Tugay\.m2\repository\com\h2database\h2\1.4.192\h2-1.4.192.jar;C:\Program Files (x86)\JetBrains\IntelliJ IDEA 2016.3.3\lib\idea_rt.jar" com.intellij.rt.execution.application.AppMain biz.tugay.jpaExamples.App
so I am pretty sure everything related to my persistence.xml configuration and dependencies are fine..
When I try mvn exec:java (after mvn clean install) I get:
[WARNING]
java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.codehaus.mojo.exec.ExecJavaMojo$1.run(ExecJavaMojo.java:297)
at java.lang.Thread.run(Thread.java:745)
Caused by: <openjpa-2.4.2-r422266:1777108 nonfatal user error> org.apache.openjpa.persistence.ArgumentException: This configuration disallows runtime optimization, but the following listed types were not enhanced at build time or at class load time with a javaagent: "
biz.tugay.jpaExamples.model.Person".
at org.apache.openjpa.enhance.ManagedClassSubclasser.prepareUnenhancedClasses(ManagedClassSubclasser.java:115)
at org.apache.openjpa.kernel.AbstractBrokerFactory.loadPersistentTypes(AbstractBrokerFactory.java:311)
at org.apache.openjpa.kernel.AbstractBrokerFactory.initializeBroker(AbstractBrokerFactory.java:235)
at org.apache.openjpa.kernel.AbstractBrokerFactory.newBroker(AbstractBrokerFactory.java:211)
at org.apache.openjpa.kernel.DelegatingBrokerFactory.newBroker(DelegatingBrokerFactory.java:154)
at org.apache.openjpa.persistence.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:226)
at org.apache.openjpa.persistence.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:153)
at org.apache.openjpa.persistence.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:59)
at biz.tugay.jpaExamples.App.main(App.java:16)
... 6 more
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.240 s
[INFO] Finished at: 2017-05-24T22:32:46+03:00
[INFO] Final Memory: 11M/139M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.codehaus.mojo:exec-maven-plugin:1.2.1:java (default-cli) on project jpa-examples: An exception occured while executing the Java class. null: InvocationTargetException: This configuration disallows runtime optimization, but the following listed types were not enhanced at build time or at class load time with a javaagent: "
[ERROR] biz.tugay.jpaExamples.model.Person".
How do I fix this? I think somehow OpenJPA is unable to find persistence.xml, but I can verify that it is found under target/classes.
Adding this to pom.xml worked:
<plugin>
<groupId>org.apache.openjpa</groupId>
<artifactId>openjpa-maven-plugin</artifactId>
<version>2.4.2</version>
<configuration>
<includes>**/model/*.class</includes>
<excludes>**/model/XML*.class</excludes>
<addDefaultConstructor>true</addDefaultConstructor>
<enforcePropertyRestrictions>true</enforcePropertyRestrictions>
</configuration>
<executions>
<execution>
<id>enhancer</id>
<phase>process-classes</phase>
<goals>
<goal>enhance</goal>
</goals>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>org.apache.openjpa</groupId>
<artifactId>openjpa</artifactId>
<!-- set the version to be the same as the level in your runtime -->
<version>2.4.2</version>
</dependency>
</dependencies>
</plugin>

Resources