A weird problem when running Arquillian test. If I try to use an EJB annotated with #Stateless, I get this error:
org.jboss.weld.exceptions.DeploymentException: WELD-001408 Unsatisfied dependencies for type [MyEjbRemote] with qualifiers [#Default] at injection point [[field] #Inject private com.org.app.ejb.InjectionTest.ejb]
I have the following test class + deployment for the Arquillian:
#RunWith(Arquillian.class)
public class InjectionTest extends TestCase {
#Inject
private MyEjbRemote ejb;
#Deployment
public static JavaArchive createDeployment() {
JavaArchive jar = ShrinkWrap.create(JavaArchive.class, "test.jar").addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml"));
jar.addClass(MyEjbRemote.class);
jar.addClass(MyEjb.class);
}
#Test
public void checkInjection() {
TestCase.assertNotNull(ejb);
}
}
The EJB looks like this:
#Stateless
#Default
public class MyEjb implements MyEjbRemote {
public MyEjb() {
}
}
The remote interface just has #Remote annotation.
If I change the #Stateless to #Named, it works. But I wan to use the #Stateless.
pom.xml:
<dependencies>
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-api</artifactId>
<version>7.0</version>
</dependency>
<dependency>
<groupId>org.jboss.arquillian.junit</groupId>
<artifactId>arquillian-junit-container</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.jboss.arquillian</groupId>
<artifactId>arquillian-bom</artifactId>
<version>1.1.9.Final</version>
<scope>import</scope>
<type>pom</type>
</dependency>
</dependencies>
</dependencyManagement>
In order to test injection of Stateless EJBs that are not Singletons you need to deploy to an embedded container.
I had the same issue and this blog post pointed me in the right direction.
https://blog.payara.fish/how-to-test-applications-with-payara-server-micro-with-arquillian
My working pom.xml
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.jboss.arquillian</groupId>
<artifactId>arquillian-bom</artifactId>
<version>1.6.0.Final</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>org.jboss.arquillian.junit</groupId>
<artifactId>arquillian-junit-container</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jboss.arquillian.container</groupId>
<artifactId>arquillian-glassfish-embedded-3.1</artifactId>
<version>1.0.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>fish.payara.extras</groupId>
<artifactId>payara-embedded-all</artifactId>
<version>5.2020.4</version>
<scope>test</scope>
</dependency>
</dependencies>
Related
I am new in selenium.
I want to generate extend report using cucumber. But I am always getting error
"cucumber.runtime.CucumberException: Couldn't load plugin class: com.cucumber.listener.ExtentCucumberFormatter"
I tried every version Below code I have
POM XML File:
<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>CucumberFramwork</groupId>
<artifactId>ExtendReport</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>ExtendReport</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.vimalselvam</groupId>
<artifactId>cucumber-extentsreport</artifactId>
<version>3.1.1</version>
</dependency>
<dependency>
<groupId>com.aventstack</groupId>
<artifactId>extentreports</artifactId>
<version>3.1.1</version>
</dependency>
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-junit</artifactId>
<version>4.2.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.aventstack</groupId>
<artifactId>extentreports-cucumber4-adapter</artifactId>
<version>1.0.7</version>
</dependency>
<!-- >dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-junit</artifactId>
<version>4.2.6</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-picocontainer</artifactId>
<version>4.2.6</version>
<scope>test</scope>
</dependency -->
<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-java</artifactId>
<version>1.2.5</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-jvm</artifactId>
<version>1.2.5</version>
<type>pom</type>
</dependency>
<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-junit</artifactId>
<version>1.2.5</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.5.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
</project>
Java Code:
package runners;
import java.io.File;
import org.junit.AfterClass;
import org.junit.runner.RunWith;
import com.vimalselvam.cucumber.listener.Reporter;
import cucumber.api.CucumberOptions;
import cucumber.api.junit.Cucumber;
#RunWith(Cucumber.class)
#CucumberOptions(features = "src/test/resources/functionalTests",
glue = { "stepDefinitions" }, plugin = {
"com.cucumber.listener.ExtentCucumberFormatter:target/cucumber-reports/report.html" },
monochrome = true)
public class TestRunner {
#AfterClass
public static void writeExtentReport() {
try {
Reporter.loadXMLConfig(new File("C:\\Software\\WprkSpace\\ExtendReport\\Configs\\extent-config.xml"));
}
catch (Exception e) {
e.printStackTrace();
}
//Reporter.loadXMLConfig("/ExtendReport/Configs/extent-config.xml");
}
}
Every time I am geting below error:
cucumber.runtime.CucumberException: Couldn't load plugin class:
com.cucumber.listener.ExtentCucumberFormatter
at cucumber.runtime.formatter.PluginFactory.loadClass(PluginFactory.java:180)
at cucumber.runtime.formatter.PluginFactory.pluginClass(PluginFactory.java:165)
at cucumber.runtime.formatter.PluginFactory.getPluginClass(PluginFactory.java:222)
at cucumber.runtime.formatter.PluginFactory.isStepDefinitionReporterName(PluginFactory.java:205)
at cucumber.runtime.RuntimeOptions$ParsedPluginData.addPluginName(RuntimeOptions.java:357)
at cucumber.runtime.RuntimeOptions.parse(RuntimeOptions.java:159)
at cucumber.runtime.RuntimeOptions.(RuntimeOptions.java:90)
at cucumber.runtime.RuntimeOptions.(RuntimeOptions.java:85)
at cucumber.runtime.RuntimeOptionsFactory.create(RuntimeOptionsFactory.java:23)
at cucumber.api.junit.Cucumber.(Cucumber.java:84)
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native
Method)
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:488)
at org.junit.internal.builders.AnnotatedBuilder.buildRunner(AnnotatedBuilder.java:29)
at org.junit.internal.builders.AnnotatedBuilder.runnerForClass(AnnotatedBuilder.java:21)
at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:59)
at org.junit.internal.builders.AllDefaultPossibilitiesBuilder.runnerForClass(AllDefaultPossibilitiesBuilder.java:26)
at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:59)
at org.junit.internal.requests.ClassRequest.getRunner(ClassRequest.java:26)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader.createUnfilteredTest(JUnit4TestLoader.java:90)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader.createTest(JUnit4TestLoader.java:76)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader.loadTests(JUnit4TestLoader.java:49)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:525)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:763)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:463)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:209)
Caused by: java.lang.ClassNotFoundException: com.cucumber.listener.ExtentCucumberFormatter
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:582)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:185)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:496)
at cucumber.runtime.formatter.PluginFactory.loadClass(PluginFactory.java:173)
... 26 more
Problem Statement Analysis -
Using vimal, avenstack and adapter dependencies all together in pom.xml which is not advisable and expected. One shall use vimal or avenstack or both together in specific use case or use adapter dependency only. Please follow below instructions.
Adding direct & transitive dependencies together from info.cukes & io.cucumber dependencies. Doing so can cause unpredictable outcome. Now let's move.
Vimal Selvam Library: Below is the required maven dependency and a sample test to demonstrate how configuration set up is done.
Maven Dependency
<dependency>
<groupId>com.vimalselvam</groupId>
<artifactId>cucumber-extentsreport</artifactId>
<version>3.1.1</version>
</dependency>
<dependency>
<groupId>com.aventstack</groupId>
<artifactId>extentreports</artifactId>
<version>4.0.9</version>
</dependency>
Please note that Java 8+ and adding the dependency of ExtentReport v3.1.1+ is mandatory.
Cucumber Runner File
#RunWith(Cucumber.class)
#CucumberOptions(
features = {"src/test/resources/features"},
glue = {"com.cucumber.stepdefinitions"},
plugin = {"com.cucumber.listener.ExtentCucumberFormatter:output/report.html"}
)
public class RunCukesTest {
#AfterClass
public static void teardown() {
Reporter.loadXMLConfig(new File("src/test/resources/extent-config.xml"));
Reporter.setSystemInfo("user", System.getProperty("user.name"));
Reporter.setSystemInfo("os", "Mac OSX");
Reporter.setTestRunnerOutput("Sample test runner output message");
}
}
The above setup will generate the report in output directory with the name of report.html.
Please remove adapter dependency from pom.xml. We shall use vimal/avenstack or extent adapter but not all together.
Extent Adapter: Beauty is, you do not need to write any code any where to generate report this way except from setting adapter in runner below.
Maven Dependency
<dependency>
<groupId>com.aventstack</groupId>
<artifactId>extentreports-cucumber4-adapter</artifactId>
<version>1.0.6</version>
</dependency>
Add the com.aventstack.extentreports.cucumber.adapter.ExtentCucumberAdapter plugin to the runner.
#RunWith(Cucumber.class)
#CucumberOptions(plugin = {"com.aventstack.extentreports.cucumber.adapter.ExtentCucumberAdapter:"})
public class RunCukesTest {
// ..
}
Report Output Directory - ../Project Directory/test-output/HtmlReport
Additional Note: In future, we would request you to use Cucumber v>=4.0.0 as you are using pretty old dependency(v1.2.5) of Cucumber.
For doing so, you can add below set of cucumber minimal dependencies.
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-junit</artifactId>
<version>4.2.6</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-picocontainer</artifactId>
<version>4.2.6</version>
<scope>test</scope>
</dependency>
Since you are using cucumber 4 version, you should be using the plugin - "com.aventstack.extentreports.cucumber.adapter.ExtentCucumberAdapter:"
cucumber-java & cucumber-junit dependency should be 4.2.6 version on your POM.
see adapter documentation- http://extentreports.com/docs/versions/4/java/cucumber4.html for more details & examples.
I'm trying to connect an API witha postgres database. And for that, I'm using Spring Boot.
When testing the api, i keep getting the error
Consider defining a bean of type 'javax.servlet.ServletContext' in your configuration.
I understand that i need a #Bean for ServletController, but I donw know exactly what this bean should do. When i made a generic one, but then the console told me to revisit it. I have no idea what to do here, and stackoverflow hasn't helped either.
Here's my Application file:
#SpringBootApplication
#SwaggerDefinition
#EnableSwagger2
#EnableConfigurationProperties(XXXXConfiguracaoApplication.class)
public class FonumS3ApiApplication {
public static void main(String[] args) {
SpringApplication.run(XXXXApiApplication.class, args);
}
#Bean
public Docket api() {
return new Docket(DocumentationType.SWAGGER_2)
.select()
.apis(RequestHandlerSelectors.any())
.paths(PathSelectors.any())
.build()
.apiInfo(apiInfo());
}
private ApiInfo apiInfo() {
return new ApiInfo(
"API XXXX",
"API XXXX para integrações entre sistemas.",
"API V1",
"Terms of service",
new Contact("XXXX", "www.XXXX.com", "XXXX.XXXX#XXXX.com"),
"License of XXX", "API license URL", Collections.emptyList());
}
}
}
(the annotations are there, but for some reason, the stackoverflow did not accept them) and my pom is
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.4.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-validator</artifactId>
<version>6.0.13.Final</version>
</dependency>
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-api</artifactId>
<version>7.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>2.8.0</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>2.8.0</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
As you have excluded Tomcat from web and added Tomcat provided scope so I assume you are trying to create war and deploy on external Tomcat, so you have to extend SpringBootServletInitializer and override configure method.
#SpringBootApplication
#SwaggerDefinition
#EnableSwagger2
#EnableConfigurationProperties(XXXXConfiguracaoApplication.class)
public class FonumS3ApiApplication extends SpringBootServletInitializer {
public static void main(String[] args) {
SpringApplication.run(XXXXApiApplication.class, args);
}
#Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
return application.sources(Application.class);
}
#Bean
public Docket api() {
return new Docket(DocumentationType.SWAGGER_2)
.select()
.apis(RequestHandlerSelectors.any())
.paths(PathSelectors.any())
.build()
.apiInfo(apiInfo());
}
private ApiInfo apiInfo() {
return new ApiInfo(
"API XXXX",
"API XXXX para integrações entre sistemas.",
"API V1",
"Terms of service",
new Contact("XXXX", "www.XXXX.com", "XXXX.XXXX#XXXX.com"),
"License of XXX", "API license URL", Collections.emptyList());
}
}
}
Or if you are running with embedded Tomcat then don't change anything in main class and remove exclusion from web and remove Tomcat jar:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
and remove Tomcat jar below:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
I'm trying to hook into Cucumber-Serenity libraries that are running using AspectJ but my pointcuts don't seem to be getting triggered.
SerenityAOP.java:
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import gherkin.ast.Feature;
import gherkin.ast.ScenarioDefinition;
import net.thucydides.core.model.TestStep;
import net.thucydides.core.steps.StepEventBus;
#Aspect
public class SerenityAOP {
#Pointcut("execution(void cucumber.runtime.formatter.SerenityReporter.startOfScenarioLifeCycle(..))")
public void beforeStartScenario() {}
#Pointcut("execution(void cucumber.runtime.SerenityObjectFactory.stop())")
public static void beforeStop(){}
#Before("beforeStartScenario()")
public void beforeStartScenarioAdvice(JoinPoint joinPoint) {
Object[] signatureArgs = joinPoint.getArgs();
Feature currentFeature = (Feature)signatureArgs[0];
String scenarioName = signatureArgs[1].toString();
ScenarioDefinition scenarioDefinition = (ScenarioDefinition)signatureArgs[2];
System.out.println("ASPECT: Starting test case for feature "+currentFeature+" with scneario: "+scenarioName);
}
#Before("beforeStop()")
public void beforeStopAdvice() {
boolean status = StepEventBus.getEventBus().aStepInTheCurrentTestHasFailed();
String stepDescription = StepEventBus.getEventBus().getCurrentStep()
.transform(TestStep::getDescription)
.get();
System.out.println("ASPECT: Testcase: "+stepDescription+" status = "+status);
}
}
Relevant Dependencies:
<dependency>
<groupId>net.thucydides</groupId>
<artifactId>thucydides-junit</artifactId>
<version>0.9.275</version>
</dependency>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjrt</artifactId>
<version>1.9.1</version>
</dependency>
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<version>3.9.0</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.6</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.7.5</version>
</dependency>
<dependency>
<groupId>net.serenity-bdd</groupId>
<artifactId>serenity-core</artifactId>
<version>${serenity.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>net.serenity-bdd</groupId>
<artifactId>serenity-junit</artifactId>
<version>${serenity.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>net.serenity-bdd</groupId>
<artifactId>serenity-cucumber</artifactId>
<version>${serenity.cucumber.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<scope>test</scope>
<version>3.8.1</version>
</dependency>
But I'm not seeing my printlines anywhere during execution.
Is there some way I need to hook into these internal library calls differently? Or are my pointcut selectors wrong?
EDIT:
Adding a comment in case the current answer gets removed
With the cucumber hooks I'm not able to detect when a new feature is started. I need to get the name of the feature and scenario when they each start. I haven't found a way to do that with event bus.
I am trying to test with Arquillian + WELD EE in an (ShrinkWrap)EnterpriseArchive.
But I am getting a NullPointerException when I start invoking the method.
My pom.xml
<profile>
<id>arquillian-weld-ee-embedded</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<dependencies>
<dependency>
<groupId>org.jboss.spec</groupId>
<artifactId>jboss-javaee-7.0</artifactId>
<version>1.0.3.Final</version>
<type>pom</type>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.jboss.arquillian.container</groupId>
<artifactId>arquillian-weld-ee-embedded-1.1</artifactId>
<version>1.0.0.CR9</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jboss.weld</groupId>
<artifactId>weld-core</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jboss.weld</groupId>
<artifactId>weld-api</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jboss.weld</groupId>
<artifactId>weld-spi</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>1.6.4</version>
<scope>test</scope>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.jboss.weld</groupId>
<artifactId>weld-core-bom</artifactId>
<version>2.3.3.Final</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<build>
<plugins>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
</plugin>
</plugins>
</build>
</profile>
My testclass
#RunWith(Arquillian.class)
public class NewSessionBeanTest {
public NewSessionBeanTest() {
}
#Deployment
public static Archive<?> createDeployment() {
final JavaArchive ejbJar = ShrinkWrap
.create(JavaArchive.class, "ejb-jar.jar")
.addClass(NewSessionBean.class)
.addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml");
final WebArchive testWar = ShrinkWrap.create(WebArchive.class, "test.war")
.addClass(NewSessionBeanTest.class)
.addAsManifestResource("META-INF/test-web-beans.xml", "beans.xml")
;
final EnterpriseArchive ear = ShrinkWrap.create(EnterpriseArchive.class)
.setApplicationXML("META-INF/test-application.xml")
.addAsModule(ejbJar)
.addAsModule(testWar);
return ear;
}
#Inject
NewSessionBean sessionBean;
#Test
public void testBusinessMethod() throws Exception {
assertNotNull(sessionBean);
// With Weld-EE it gives NullPointerException here
sessionBean.businessMethod();
}
}
It fails at sessionBean.businessMethod();, there is an proxy inserted so assertNotNull passes. When I use arquillian-weld-se-embedded-1.1 (SE), then I get an error could not inject members.
This works perfectly when I test this with a wildfly-embedded container.
UPDATE: My NewSessionBean class is #Stateless + #LocalBean (also tested without #LocalBean. When I test this with #ApplicationScoped it works, but it's not what I want.
Also if I test it #Named or with #LocalBean it works. But these are non-EJB specifications.
Found test on: http://www.programcreek.com/java-api-examples/index.php?source_dir=arquillian-container-weld-master/weld-ee-embedded-1.1/src/test/java/org/jboss/arquillian/container/weld/ee/embedded_1_1/WeldEmbeddedIntegrationEARTestCase.java
UPDATE 2: I have found a workaround for this. Changing to WELD SE and adding ear.merge(ejbJar) to the Test works for the weld profile and Wildfly Managed profile.
Still I don't consider this as a solution, because I think it should be supported by WELD-EE.
I have a very strange problem.
Previously, for bigger projects we used EAR packaging (one EJB + JPA + JAX-WS project with one JSF + JAX-RS project).
No we have a smaller project, where we only needed some (5) services and no UI, so we decided to go with WAR packaging in one project (EJB + JPA + JAX-WS + JAX-RS).
Maven dependencies:
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-web-api</artifactId>
<version>7.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-api</artifactId>
<version>7.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>javax.ws.rs</groupId>
<artifactId>javax.ws.rs-api</artifactId>
<version>2.0.1</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.eclipse.persistence</groupId>
<artifactId>org.eclipse.persistence.moxy</artifactId>
<version>${moxy.version}</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.7</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.1.2</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.core</groupId>
<artifactId>jersey-client</artifactId>
<version>${jersey.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.core</groupId>
<artifactId>jersey-common</artifactId>
<version>${jersey.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.media</groupId>
<artifactId>jersey-media-json-jackson</artifactId>
<version>${jersey.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.media</groupId>
<artifactId>jersey-media-moxy</artifactId>
<version>${jersey.version}</version>
</dependency>
<dependency>
<groupId>org.glassfish</groupId>
<artifactId>jsonp-jaxrs</artifactId>
<version>1.0</version>
</dependency>
So, most of what we do is we create a simple interface:
#WebService
#SOAPBinding( style = Style.DOCUMENT )
public interface ILog extends Serializable{
#WebMethod public long createEventLog(EventLog log);
}
We put an EJB over it, for implementation:
#Stateless
#LocalBean
#WebService (endpointInterface = "....interfaces.ILog")
public class LogService implements ILog {
public long createEventLog(EventLog log) {
em.persist(log);
em.flush();
return log.getId();
}
}
Then we have a JAX-RS class over it, which calls the upper EJB method.
#Path("/log")...
First we create the EJB + WS combos, and create simple test client codes, to make sure they work:
private URL url;
private QName qname;
private Service wsService;
private ILog logService;
#Before
public void init() throws MalformedURLException{
url = new URL("http://localhost:8080/LogServiceService/LogService?wsdl");
qname = new QName("http://.../","LogServiceService");
wsService = Service.create(url, qname);
logService = wsService.getPort(ILog.class);
}
Everything is rendered / generated for us by glassfish 4.1, so we don't create any more configuration class, or anything (the above code just works...).
So this works at this step. After these, we introduced the JAX-RS services (with JSON formatting), that meant the REST services are working, but now I think the above API-s doesn't like each other very much, and now the JAX-WS code isn't working, and giving the following error for all the JAX-WS services:
2015-09-18T14:15:36.712+0200|Severe: Cannot initialize endpoint : error is :
javax.xml.ws.WebServiceException: class ....interfaces.jaxws.CreateEventLog do not have a property of the name arg0
at com.sun.xml.ws.server.sei.EndpointArgumentsBuilder$DocLit.<init>(EndpointArgumentsBuilder.java:610)
at com.sun.xml.ws.server.sei.TieHandler.createArgumentsBuilder(TieHandler.java:143)
at com.sun.xml.ws.server.sei.TieHandler.<init>(TieHandler.java:115)
at com.sun.xml.ws.db.DatabindingImpl.<init>(DatabindingImpl.java:116)
at com.sun.xml.ws.db.DatabindingProviderImpl.create(DatabindingProviderImpl.java:74)
at com.sun.xml.ws.db.DatabindingProviderImpl.create(DatabindingProviderImpl.java:58)
at com.sun.xml.ws.db.DatabindingFactoryImpl.createRuntime(DatabindingFactoryImpl.java:120)
at com.sun.xml.ws.server.EndpointFactory.createSEIModel(EndpointFactory.java:521)
at com.sun.xml.ws.server.EndpointFactory.create(EndpointFactory.java:300)
at com.sun.xml.ws.server.EndpointFactory.createEndpoint(EndpointFactory.java:164)
at com.sun.xml.ws.api.server.WSEndpoint.create(WSEndpoint.java:577)
at com.sun.xml.ws.api.server.WSEndpoint.create(WSEndpoint.java:560)
at com.sun.xml.ws.api.server.WSEndpoint.create(WSEndpoint.java:639)
at org.glassfish.webservices.EjbRuntimeEndpointInfo.prepareInvocation(EjbRuntimeEndpointInfo.java:275)
at org.glassfish.webservices.EjbRuntimeEndpointInfo.initRuntimeInfo(EjbRuntimeEndpointInfo.java:352)
at org.glassfish.webservices.WebServiceEjbEndpointRegistry.registerEndpoint(WebServiceEjbEndpointRegistry.java:127)
at com.sun.ejb.containers.BaseContainer.initializeHome(BaseContainer.java:1247)
at com.sun.ejb.containers.StatelessSessionContainer.initializeHome(StatelessSessionContainer.java:190)
at com.sun.ejb.containers.StatelessContainerFactory.createContainer(StatelessContainerFactory.java:63)
at org.glassfish.ejb.startup.EjbApplication.loadContainers(EjbApplication.java:221)
at org.glassfish.ejb.startup.EjbDeployer.load(EjbDeployer.java:291)
at org.glassfish.ejb.startup.EjbDeployer.load(EjbDeployer.java:99)
at org.glassfish.internal.data.ModuleInfo.load(ModuleInfo.java:206)
at org.glassfish.internal.data.ApplicationInfo.load(ApplicationInfo.java:313)
at com.sun.enterprise.v3.server.ApplicationLifecycle.deploy(ApplicationLifecycle.java:496)
at com.sun.enterprise.v3.server.ApplicationLoaderService.processApplication(ApplicationLoaderService.java:406)
at com.sun.enterprise.v3.server.ApplicationLoaderService.postConstruct(ApplicationLoaderService.java:243)
at org.jvnet.hk2.internal.ClazzCreator.postConstructMe(ClazzCreator.java:329)
at org.jvnet.hk2.internal.ClazzCreator.create(ClazzCreator.java:377)
at org.jvnet.hk2.internal.SystemDescriptor.create(SystemDescriptor.java:461)
at org.glassfish.hk2.runlevel.internal.AsyncRunLevelContext.findOrCreate(AsyncRunLevelContext.java:227)
at org.glassfish.hk2.runlevel.RunLevelContext.findOrCreate(RunLevelContext.java:84)
at org.jvnet.hk2.internal.Utilities.createService(Utilities.java:2258)
at org.jvnet.hk2.internal.ServiceHandleImpl.getService(ServiceHandleImpl.java:105)
at org.jvnet.hk2.internal.ServiceHandleImpl.getService(ServiceHandleImpl.java:87)
at org.glassfish.hk2.runlevel.internal.CurrentTaskFuture$QueueRunner.oneJob(CurrentTaskFuture.java:1162)
at org.glassfish.hk2.runlevel.internal.CurrentTaskFuture$QueueRunner.run(CurrentTaskFuture.java:1147)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:724)
Caused by: javax.xml.bind.JAXBException: arg0 is not a valid property on class ....interfaces.jaxws.CreateEventLog
at com.sun.xml.bind.v2.runtime.JAXBContextImpl.getElementPropertyAccessor(JAXBContextImpl.java:969)
at com.sun.xml.ws.db.glassfish.JAXBRIContextWrapper.getElementPropertyAccessor(JAXBRIContextWrapper.java:120)
at com.sun.xml.ws.server.sei.EndpointArgumentsBuilder$DocLit.<init>(EndpointArgumentsBuilder.java:598)
... 39 more
Now I don't know what could I do to make the two types of Services work together (I wouldn't like to go back to EAR packaging with two projects, this service interface is way too small for that).
Can anyone help me?
Thank You!