6 Replies Latest reply on Aug 31, 2012 7:56 AM by goc

    CDI injection problem during arquillian tests (including custom Java transformer)

    goc

      I facing a problem during the deployment of my application.

      I prepared a simple demo application. There a webservice calls another service with a different interface. So transformator is needed.

      When I deploy the application I can access any WS operation.

       

      Starting an arquillian test, the deployment crashes.

      12:36:48,919 ERROR [org.jboss.msc.service.fail] (MSC service thread 1-3) MSC000001: Failed to start service jboss.deployment.unit."arquillian_test.war".WeldService: org.jboss.msc.service.StartException in service jboss.deployment.unit."arquillian_test.war".WeldService: org.jboss.weld.exceptions.DeploymentException: WELD-001408 Unsatisfied dependencies for type [WsRoutingService] with qualifiers [@Default] at injection point [[field] @Inject com.objectbay.switchyard.example.ws.TestWs.service]

          at org.jboss.as.weld.services.WeldService.start(WeldService.java:83)

          at org.jboss.msc.service.ServiceControllerImpl$StartTask.startService(ServiceControllerImpl.java:1811) [jboss-msc-1.0.2.GA-redhat-1.jar:1.0.2.GA-redhat-1]

          at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1746) [jboss-msc-1.0.2.GA-redhat-1.jar:1.0.2.GA-redhat-1]

          at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886) [classes.jar:1.6.0_33]

          at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908) [classes.jar:1.6.0_33]

          at java.lang.Thread.run(Thread.java:680) [classes.jar:1.6.0_33]

      Caused by: org.jboss.weld.exceptions.DeploymentException: WELD-001408 Unsatisfied dependencies for type [WsRoutingService] with qualifiers [@Default] at injection point [[field] @Inject com.objectbay.switchyard.example.ws.TestWs.service]

          at org.jboss.weld.bootstrap.Validator.validateInjectionPoint(Validator.java:311)

          at org.jboss.weld.bootstrap.Validator.validateInjectionPoint(Validator.java:280)

          at org.jboss.weld.bootstrap.Validator.validateBean(Validator.java:143)

          at org.jboss.weld.bootstrap.Validator.validateRIBean(Validator.java:163)

          at org.jboss.weld.bootstrap.Validator.validateBeans(Validator.java:382)

          at org.jboss.weld.bootstrap.Validator.validateDeployment(Validator.java:367)

          at org.jboss.weld.bootstrap.WeldBootstrap.validateBeans(WeldBootstrap.java:380)

          at org.jboss.as.weld.WeldContainer.start(WeldContainer.java:83)

          at org.jboss.as.weld.services.WeldService.start(WeldService.java:76)

          ... 5 more


      Any suggestions ...

       

      Christoph

        • 1. Re: CDI injection problem during arquillian tests (including custom Java transformer)
          kcbabo

          Just to make sure I understand correctly here - the application works as expected when you deploy it to AS7.  What's not working is when you try to test/deploy via Arquillian.  Is that right?

          • 2. Re: CDI injection problem during arquillian tests (including custom Java transformer)
            goc

            Sorry for my bad explaination, but you're correct.

            When I deploy it to AS7 de deployment works fine:

            13:55:32,749 INFO  [org.jboss.as.webservices] (MSC service thread 1-3) JBAS015540: Stopping service jboss.ws.endpoint."test-service.jar".TestWs

            13:55:32,746 INFO  [org.jboss.as.osgi] (MSC service thread 1-1) JBAS011908: Unregister module: Module "deployment.test-service.jar:main" from Service Module Loader

            13:55:32,754 INFO  [org.jboss.ws.common.management.DefaultEndpointRegistry] (MSC service thread 1-3) remove: jboss.ws:context=test-service,endpoint=TestWs

            13:55:32,771 INFO  [org.jboss.weld.deployer] (MSC service thread 1-1) JBAS016009: Stopping weld service for deployment test-service.jar

            13:55:32,777 INFO  [org.jboss.as.webservices] (MSC service thread 1-2) JBAS015540: Stopping service jboss.ws.port-component-link

            13:55:32,796 INFO  [org.jboss.as.server.deployment] (MSC service thread 1-3) JBAS015877: Stopped deployment test-service.jar in 67ms

            13:55:32,797 INFO  [org.jboss.as.server.deployment] (MSC service thread 1-3) JBAS015876: Starting deployment of "test-service.jar"

            13:55:32,849 INFO  [org.jboss.weld.deployer] (MSC service thread 1-2) JBAS016002: Processing weld deployment test-service.jar

            13:55:32,850 INFO  [org.jboss.as.ejb3.deployment.processors.EjbJndiBindingsDeploymentUnitProcessor] (MSC service thread 1-2) JNDI bindings for session bean named TestWs in deployment unit deployment "test-service.jar" are as follows:

             

             

            13:55:32,884 INFO  [org.jboss.weld.deployer] (MSC service thread 1-2) JBAS016005: Starting Services for CDI deployment: test-service.jar

            13:55:32,890 INFO  [org.jboss.wsf.stack.cxf.metadata.MetadataBuilder] (MSC service thread 1-2) Add Service

            id=TestWs

            address=http://localhost:8080/test-service/TestWs

            implementor=com.objectbay.switchyard.example.ws.TestWs

            invoker=org.jboss.wsf.stack.cxf.JBossWSInvoker

            serviceName={http://ws.example.switchyard.objectbay.com/}TestWsService

            portName={http://ws.example.switchyard.objectbay.com/}TestWsPort

            wsdlLocation=null

            mtomEnabled=false

            properties=[org.jboss.as.webservices.metadata.modelEjbComponentViewName -> service jboss.deployment.unit."test-service.jar".component.TestWs.VIEW."com.objectbay.switchyard.example.ws.TestWs".SERVICE_ENDPOINT]

            13:55:33,084 INFO  [org.apache.cxf.service.factory.ReflectionServiceFactoryBean] (MSC service thread 1-2) Creating Service {http://ws.example.switchyard.objectbay.com/}TestWsService from class com.objectbay.switchyard.example.ws.TestWs

            13:55:33,116 INFO  [org.apache.cxf.endpoint.ServerImpl] (MSC service thread 1-2) Setting the server's publish address to be http://localhost:8080/test-service/TestWs

            13:55:33,125 INFO  [org.jboss.wsf.stack.cxf.deployment.WSDLFilePublisher] (MSC service thread 1-2) WSDL published to: file:/Users/cgostner/jboss-eap-6.0.0/standalone/data/wsdl/test-service.jar/TestWsService.wsdl

            13:55:33,126 INFO  [org.jboss.as.webservices] (MSC service thread 1-4) JBAS015539: Starting service jboss.ws.port-component-link

            13:55:33,127 INFO  [org.switchyard] (MSC service thread 1-2) Deploying SwitchYard application 'test-service.jar'

            13:55:33,128 INFO  [org.jboss.as.webservices] (MSC service thread 1-4) JBAS015539: Starting service jboss.ws.endpoint."test-service.jar".TestWs

            13:55:33,128 INFO  [org.jboss.as.osgi] (MSC service thread 1-1) JBAS011907: Register module: Module "deployment.test-service.jar:main" from Service Module Loader

            13:55:33,129 INFO  [org.jboss.ws.common.management.DefaultEndpointRegistry] (MSC service thread 1-4) register: jboss.ws:context=test-service,endpoint=TestWs

            13:55:33,130 INFO  [org.jboss.weld.deployer] (MSC service thread 1-2) JBAS016008: Starting weld service for deployment test-service.jar

            13:55:33,213 INFO  [org.switchyard] (MSC service thread 1-2) Starting SwitchYard service

            13:55:33,216 INFO  [org.jboss.web] (MSC service thread 1-4) JBAS018210: Registering web context: /test-service

            13:55:33,341 INFO  [org.jboss.as.server] (DeploymentScanner-threads - 1) JBAS018565: Replaced deployment "test-service.jar" with deployment "test-service.jar"

            Also a test using SoapUI is successful.

             

            Only the Arquillian Test fails ...

            • 3. Re: CDI injection problem during arquillian tests (including custom Java transformer)
              goc

              Hm, I found a solution/workaround. I had to add the switchyard.xml file as extra test resource.

              In my project this file is generated by maven and not by myself. So that requires another maven-dependency-plugin (unpack) or maven-resources-plugin (copy) to solve this issue.

               

              Should work, but it's not really fancy.

              • 4. Re: CDI injection problem during arquillian tests (including custom Java transformer)
                kcbabo

                Can you share your Arquillian test and config?  I don't see it in the original attachment.  I noticed that the initial stack trace from Arquillian indicates a WAR deployment and your subsequent post shows a JAR deployment. Things can get a bit tricky with packaging for a WAR deployment because you need to copy the switchyard.xml into WEB-INF vs. META-INF.  That might be the source of your problem.

                 

                To be honest, we have not focused much on Arquillian outside of our own release test framework.  Most SY functionality can be tested with our standalone test framework and test runner.  Of course, this would not be in-container testing and if you're dealing with other AS resources, then Arqullian is a great option.  I'm very interested to hear experience and feedback w/r/t Arquillian and SY.

                • 5. Re: CDI injection problem during arquillian tests (including custom Java transformer)
                  goc

                  You're right, WAR - JAR. That's a little bit inconsistent.

                  But the example from my original post is complete. You can assume that here is an empty Arquillian configuration - and the test has  only one reason - to cause a deployment process.

                   

                  And you're right, the problem relied in the lack of the switchyard.xml file. All the switchyard services (as in the example) are in an extra project. The way, the archive is created, causes that the switchyard services jar is attached in the lib folder.

                  Obviously the switchyard.xml in that archive is not recognized - my fault.

                   

                  So - now I configured an extra maven plugin. The maven plugin copies the generated switchyard.xml to the target folder of the integration project. But that's not enough.

                  I also had to add the file to the archive. So the only (source-)modification was in IntegrationTest.java:

                  public static WebArchive createSimpleDeployment(Class<?>... testClasses) {

                      MavenDependencyResolver resolver = DependencyResolvers.use(MavenDependencyResolver.class)

                              .loadMetadataFromPom("pom.xml")

                              .includeDependenciesFromPom("pom.xml");

                      try {

                          WebArchive war = ShrinkWrap.create(WebArchive.class, "arquillian_test.war")

                                  .addAsLibraries(resolver.artifact("com.objectbay.switchyard:transformer-example-services:1.0.0-SNAPSHOT").resolveAsFiles())

                                  .addClasses(testClasses).addClass(IntegrationTest.class)

                                  .addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml")

                                  .addAsManifestResource(new File(System.getProperty("user.dir") + "/src/test/resources/META-INF/switchyard.xml"));

                          return war;

                      } catch (Exception e) {

                          e.printStackTrace();

                          return null;

                      }

                  }

                  Oviously the solution is not really good - but hey, it works!

                  Perhaps I find a better solution - I will report

                  • 6. Re: CDI injection problem during arquillian tests (including custom Java transformer)
                    goc

                    A much better way is to generate an EAR including the services under test. I implemented a simple helper class - EarBuilder.

                    Using this class, my deployment-method looks like this:

                         public static Archive<?> createSimpleDeployment(Class<?>... testClasses) {

                            final JavaArchive extraClasses = ShrinkWrap.create(JavaArchive.class, "extra-classes.jar")

                                    .addClass(IntegrationTest.class)

                                    .addClasses(testClasses);

                     

                            EarBuilder builder = new EarBuilder("arquillian-test.ear");

                            builder.loadPom("pom.xml");

                     

                            builder.addArtifactAndDependenciesAsLibrary("org.jboss.shrinkwrap.resolver:shrinkwrap-resolver-api-maven:1.0.0-beta-7", JavaArchive.class);

                            builder.addArtifactAsModule("com.objectbay.switchyard:transformer-example-services", JavaArchive.class);

                            builder.addAsModule(extraClasses);

                     

                            try {

                                builder.generateApplicationXml();

                            } catch (IOException e) {

                                throw new RuntimeException(e);

                            }

                            return builder.getEar();

                        }

                    The services are located in com.objectbay.switchyard:transformer-example-services - the test classes in extraClasses.

                    Defining both in the application.xml (done by EarBuilder), CDI works fine and the test is running.

                     

                    Edit: The solution has one drawback, now it's not possible to execute the tests if the application's ear is deployed.