Web Service Testing with Arquillian

Asked

Viewed 333 times

3

I’m doing a unit test class and I’m using Arquillian because of CDI, in this case I’m testing a Web Service for authentication of company users. Follows 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 far so good, the test runs, the Web Service is called and gives the answer I expected. But after each test method is run, 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>
  • Welcome to Stack Overflow! What versions of Arquillian and Weld?

  • 1

    I edited my question to add the information about the versions of the project as you requested, when the Weld is not specified as dependency, what speak is the same glassfish, in case use glassfish 4

  • 1

    I did a lot of research and found nothing solid about the bug, other than bugs in specific versions of Weld. I saw in the GUJ version of the question you tried to update and other errors occurred. Perhaps it is the case to update "just a little bit", IE, instead of trying to put the latest version, select one or two releases after yours. The ideal would be to have the latest version and solve those problems that occurred. In the latter case create a simple project to reproduce the error and add to bug tracker of the tool.

1 answer

2


I managed to solve this problem, I just needed to update the versions of Arquillian and as utluiz said update just a little bit, I will post my dependencies for you to see how they looked

        <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>${junit.version}</version>
        <scope>test</scope>
    </dependency>

    <dependency>
        <groupId>org.jboss.arquillian.junit</groupId>
        <artifactId>arquillian-junit-container</artifactId>
        <version>${version.arquillian}</version>
        <scope>test</scope>
    </dependency>

    <dependency>
        <groupId>org.jboss.arquillian.container</groupId>
        <artifactId>arquillian-glassfish-embedded-3.1</artifactId>
        <version>${version.arquillian-glassfish-embedded}</version>
        <scope>test</scope>
    </dependency>

    <dependency>
        <groupId>org.glassfish.main.extras</groupId>
        <artifactId>glassfish-embedded-all</artifactId>
        <version>${version.glassfish}</version>
        <scope>test</scope>
    </dependency>

and here the versions of the dependencies I used

<junit.version>4.10</junit.version>
<version.glassfish>4.0</version.glassfish>
<version.arquillian>1.0.0.Final</version.arquillian>
<version.arquillian-glassfish-embedded>1.0.0.CR4</version.arquillian-glassfish-embedded>

thanks to everyone who got pregnant to help me, thank you

Browser other questions tagged

You are not signed in. Login or sign up in order to post.