I'm doing a unit test class and I'm using Arquillian because of the CDI, in this case I'm testing a Web Service for authentication of company users. Here is the source of the test class:
@RunWith(Arquillian.class)
public class UsuarioWebServiceTest {
/**
* Criando o arquivo de deploy do arquillian.
*
* @return JavaArchive
*/
@Deployment
public static WebArchive createTestArchive() {
return ShrinkWrap.create(WebArchive.class, "consisanet-aut-web.war")
.addPackages(true, Usuario.class.getPackage())
.addPackages(true, UsuarioDAO.class.getPackage())
.addPackages(true, JPAUsuarioDAOImpl.class.getPackage())
.addPackages(true, UsuarioWebService.class.getPackage())
.addAsResource("test-persistence.xml", "META-INF/persistence.xml")
.addAsWebInfResource(EmptyAsset.INSTANCE, "beans.xml")
.addAsWebInfResource("sun-jaxws.xml")
.setWebXML("web.xml");
}
/**
* UsuarioWebServiceService.
*/
private static UsuarioWebServiceService service;
/**
* Método responsável pela configuração da classe de teste.
*/
@BeforeClass
public static void setup() {
service = new UsuarioWebServiceService();
}
/**
* Método responsável por testar webservice de usuários.
*/
@Test
public void testeUsuarioAutenticacao() {
Usuario usuario = service.getUsuarioWebServicePort().autenticarUsuario("55550001", "senha");
Assert.assertNotNull(usuario);
}
/**
* Método responsável por testar método do webservice que retornar o perfil do usuário pelo seu identificador.
*/
@Test
public void testeUsuarioConsultaPerfil() {
Usuario usuario = service.getUsuarioWebServicePort().consultarUsuario("99202931");
Assert.assertNotNull(usuario);
}
/**
* Método responsável por testar o método que retorna uma lista de usuários pelo seu grupo.
*/
@Test
public void testeUsuarioConsultaGrupo() {
int grupousuarioAdiministrador = 1;
Usuario[] usuarios = service.getUsuarioWebServicePort().consultarUsuariosPorGrupo(grupousuarioAdiministrador);
System.out.println(usuarios.length);
Assert.assertNotNull(usuarios);
}
So that's fine, the test runs, the Web Service is called and gives the answer that I expected. But after each test method runs, the following stacktrace
is printed:
Advertência: Error invoking requestDestroyed method on ServletRequestListener org.jboss.weld.servlet.WeldListener
java.lang.IllegalStateException: A request must be associated with the context in order to load the known conversations
at org.jboss.weld.context.AbstractConversationContext.getCurrentConversation(AbstractConversationContext.java:390)
at org.jboss.weld.servlet.ConversationContextActivator.deactivateConversationContext(ConversationContextActivator.java:148)
at org.jboss.weld.servlet.WeldListener.requestDestroyed(WeldListener.java:143)
at org.apache.catalina.core.StandardContext.fireRequestDestroyedEvent(StandardContext.java:5261)
at org.apache.catalina.core.StandardHostValve.postInvoke(StandardHostValve.java:255)
at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:359)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:260)
at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:246)
at org.glassfish.grizzly.http.server.HttpHandler.runService(HttpHandler.java:191)
at org.glassfish.grizzly.http.server.HttpHandler.doHandle(HttpHandler.java:168)
at org.glassfish.grizzly.http.server.HttpServerFilter.handleRead(HttpServerFilter.java:189)
at org.glassfish.grizzly.filterchain.ExecutorResolver$9.execute(ExecutorResolver.java:119)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeFilter(DefaultFilterChain.java:288)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeChainPart(DefaultFilterChain.java:206)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.execute(DefaultFilterChain.java:136)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.process(DefaultFilterChain.java:114)
at org.glassfish.grizzly.ProcessorExecutor.execute(ProcessorExecutor.java:77)
at org.glassfish.grizzly.nio.transport.TCPNIOTransport.fireIOEvent(TCPNIOTransport.java:838)
at org.glassfish.grizzly.strategies.AbstractIOStrategy.fireIOEvent(AbstractIOStrategy.java:113)
at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.run0(WorkerThreadIOStrategy.java:115)
at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.access$100(WorkerThreadIOStrategy.java:55)
at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy$WorkerThreadRunnable.run(WorkerThreadIOStrategy.java:135)
at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:564)
at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.run(AbstractThreadPool.java:544)
at java.lang.Thread.run(Thread.java:744)
And here, my Arquillian dependencies
<dependency>
<groupId>org.jboss.arquillian.junit</groupId>
<artifactId>arquillian-junit-container</artifactId>
<version>1.0.0.CR6</version>
</dependency>
<dependency>
<groupId>org.jboss.arquillian.container</groupId>
<artifactId>arquillian-glassfish-embedded-3.1</artifactId>
<version>1.0.0.CR4</version>
</dependency>
<dependency>
<groupId>org.glassfish.main.extras</groupId>
<artifactId>glassfish-embedded-all</artifactId>
<version>4.0-b83</version>
</dependency>