3 days ago I completed the Arquillian "getting started" guide and decided that this would be a good thing to use for unit testing of my part of a CQRS system.
Unfortunately this has proved a little less than straight forwards. I have googled for the past 3 days and the issue it not resolved by any of the solutions that have worked for others.
I am coming to the conclusion that the problem is with my code though I dont see how.
My task is to write an event listener that listens to an ActiveMQ topic for events and then updates the "view" in a Mongo DB.
There will be many events in the system so it seemed reasonable to me to create an abstract base class that all event listeners extend.
This base class contains the Mongo client and registers to listen to the topic. It uses an over loaded getter for the listener name which it uses as a bean reference in a camel route. The listener client ID is generated from a static long which is incremented on each listener registration. This ensures that every listener get to see every event posted to the topic. Intention is to later add a filter to reduce the number of event received.
I have built this code and driven it from a timer generating event topic posts and it all works fine.
The trouble with that is a quality requirement to have cobertura report 80% code coverage by unit tests.
My test application is not a unit test so my code coverage is 0%.
I have come to Arquillian via a couple of other methods of unit testing in CDI but Arquillian does seem to be the best option if I could only get it to work.
The error I am getting is:
java.lang.IllegalStateException: Could not find beans for Type=class org.apache.deltaspike.core.impl.scope.window.WindowBeanHolder and qualifiers:[]
I have included deltaspike in the pom, I have added it to the shrinkwrap deployment
POM extract
<dependency>
<groupId>org.apache.deltaspike.core</groupId>
<artifactId>deltaspike-core-api</artifactId>
<version>${deltaspike.version}</version>
</dependency>
<dependency>
<groupId>org.apache.deltaspike.core</groupId>
<artifactId>deltaspike-core-impl</artifactId>
<version>${deltaspike.version}</version>
</dependency>
<dependency>
<groupId>org.jboss.shrinkwrap.resolver</groupId>
<artifactId>shrinkwrap-resolver-impl-maven</artifactId>
<version>2.0.0</version>
</dependency>
Test class @RunWith(Arquillian.class) public class ListenerTest {
AbstractEventListener listener = null ;
WindowBeanHolder w = new WindowBeanHolder();
@Deployment
public static WebArchive createDeployment() {
return ShrinkWrap.create(WebArchive.class).addAsLibraries(Maven.resolver().loadPomFromFile("pom.xml")
.resolve("org.apache.deltaspike.core:deltaspike-core-api",
"org.apache.deltaspike.core:deltaspike-core-impl")
.withoutTransitivity().asFile())
.addAsWebInfResource("beans.xml");
}
@Test
public void testExecute() {
Assert.assertNotNull(listener);
}
}
My beams.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/beans_1_1.xsd"
bean-discovery-mode="all">
</beans>
As you can see I have even tried adding the WindowBeanHolder to the code.
I have made many changes to the code over the last few days. I have not included the full pom etc as this may not be needed but can add if required.
If you have any suggestion as to where I can go from here many thanks in advance.