1 Reply Latest reply on Oct 24, 2016 10:18 AM by Matous Jobanek

    Arquillian InvocationException What to do?

    Markus Hofmann Newbie

      Hi everybody,

       

      I have a question about to come in Arquillian.

       

      The class which I want to test seems to be very simple. It takes a gross value, calucate a net value but has a dependency to the money lib.

       

      import java.math.BigDecimal;

       

      public interface GrossNetValueCalculation {

          BigDecimal calculateNetValue(BigDecimal grossValue, Integer marketId);

      }

       

      import java.math.BigDecimal;

       

      import javax.ejb.Local;

      import javax.ejb.Stateless;

       

      import org.javamoney.moneta.Money;

       

      @Stateless

      @Local(GrossNetValueCalculation.class)

      public class GrossNetValueCalculationBean implements GrossNetValueCalculation {

          private static final long VAT = 20;

          private static final long BASE = 100;

          private static final String CURRENCY = "EUR";

       

          @Override

          public BigDecimal calculateNetValue(BigDecimal iGrossValue, Integer marketId) {

              Money grossValue = Money.of(iGrossValue, CURRENCY);

              Money netValue = grossValue.multiply(BASE).divide(BASE + GERMAN_VAT);

       

              return netValue.getNumber().numberValue(BigDecimal.class);

          }

      }

       

      After Aquillian complained about the missing libray money library I tried to load it.

       

      import java.io.File;

      import java.math.BigDecimal;

       

      import javax.inject.Inject;

       

      import org.jboss.arquillian.container.test.api.Deployment;

      import org.jboss.arquillian.junit.Arquillian;

      import org.jboss.shrinkwrap.api.Archive;

      import org.jboss.shrinkwrap.api.ShrinkWrap;

      import org.jboss.shrinkwrap.api.asset.EmptyAsset;

      import org.jboss.shrinkwrap.api.spec.JavaArchive;

      import org.jboss.shrinkwrap.api.spec.WebArchive;

      import org.jboss.shrinkwrap.resolver.api.maven.Maven;

      import org.junit.Assert;

      import org.junit.Test;

      import org.junit.runner.RunWith;

       

      import com.example.GrossNetValueCalculation;

      import com.example.GrossNetValueCalculationBean;

       

      @RunWith(Arquillian.class)

      public class ArquillianTest {

       

          // @Deployment

          // public static Archive<?> deploy() {

          // return ShrinkWrap.create(WebArchive.class, "test.war");

          // }

       

          // @Test

          // public void emptyInContainerTest() {

          // System.out.println("=========================================");

          // System.out.println("This test should run inside the container");

          // System.out.println("=========================================");

          // }

       

          @Inject

          private GrossNetValueCalculation bean;

       

          @Deployment

          public static Archive<?> createDeployment() {

              WebArchive archive = ShrinkWrap.create(WebArchive.class, "test.war")

                      .addClasses(GrossNetValueCalculation.class, GrossNetValueCalculationBean.class)

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

       

              // PomEquippedResolveStage pom = Maven.resolver().loadPomFromFile(pathPrefix + "pom.xml");

              // File[] moneyLib = pom.resolve("org.javamoney:moneta").withTransitivity().asFile();

              // File[] appApi = pom.resolve("be.myapp:myapp-api").withTransitivity().asFile();

       

              try {

                  JavaArchive[] archs = Maven.resolver()

                          .loadPomFromFile("pom.xml")

                          .importRuntimeAndTestDependencies()

                          .resolve().withoutTransitivity()

                          .as(JavaArchive.class);

       

                  for (JavaArchive a : archs) {

                      System.out.println("Library: " + a.toString());

                      archive.addAsLibrary(a);

                  }

       

                  // File[] files = Maven.resolver().resolve("org.javamoney:moneta").withTransitivity().asFile();

                  File[] files = Maven.resolver().loadPomFromFile("pom.xml")

                          .importCompileAndRuntimeDependencies().resolve("org.javamoney:moneta")

                          .withTransitivity()

                          .asFile();

                  if (files.length == 0) {

                      System.out.println("Is empty");

                  }

       

                  for (File file : files) {

                      System.out.println("Library 2: " + file.toString());

                      // archive = archive.merge(lib);

                      archive.addAsLibrary(file);

                  }

       

              } catch (Exception e) {

                  System.out.println("Exception.");

                  e.printStackTrace();

              }

       

              System.out.println(archive.toString(true));

       

              return archive;

          }

       

          @Test

          public void calculateNetValue() {

              System.out.println("Begin calculateNetValue");

              BigDecimal result = bean.calculateNetValue(new BigDecimal(119), new Integer(20));

       

              Assert.assertEquals(new BigDecimal(100), result);

              System.out.println("End calculateNetValue");

          }

      }

       

      The code runs always in the following exception:

       

      Running com.example.ArquillianTest

      Exception.

      org.jboss.shrinkwrap.resolver.api.Invokable$InvocationException: Unable to invoke onlyOne([Ljava.lang.Class;@3f792b9b) on object org.jboss.shrinkwrap.resolver.spi.loader.ServiceRegistry with parameters [Ljava.lang.Object;@7b8233cd

          at org.jboss.shrinkwrap.resolver.api.Invokable.invokeMethod(Invokable.java:109)

          at org.jboss.shrinkwrap.resolver.api.ResolverSystemFactory.createFromUserView(ResolverSystemFactory.java:93)

          at org.jboss.shrinkwrap.resolver.api.ResolverSystemFactory.createFromUserView(ResolverSystemFactory.java:54)

          at org.jboss.shrinkwrap.resolver.api.Resolvers.use(Resolvers.java:75)

          at org.jboss.shrinkwrap.resolver.api.maven.Maven.resolver(Maven.java:36)

          at com.oneandone.ocis.business.billing.businessfacade.service.BillingFacadeServiceBeanArquillianTest.createDeployment(BillingFacadeServiceBeanArquillianTest.java:56)

          at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

          at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)

          at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)

          at java.lang.reflect.Method.invoke(Method.java:498)

          at org.jboss.arquillian.container.test.impl.client.deployment.AnnotationDeploymentScenarioGenerator.invoke(AnnotationDeploymentScenarioGenerator.java:177)

          at org.jboss.arquillian.container.test.impl.client.deployment.AnnotationDeploymentScenarioGenerator.generateDeployment(AnnotationDeploymentScenarioGenerator.java:103)

          at org.jboss.arquillian.container.test.impl.client.deployment.AnnotationDeploymentScenarioGenerator.generate(AnnotationDeploymentScenarioGenerator.java:64)

          at org.jboss.arquillian.container.test.impl.client.deployment.DeploymentGenerator.generateDeployment(DeploymentGenerator.java:79)

          at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

          at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)

          at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)

          at java.lang.reflect.Method.invoke(Method.java:498)

          at org.jboss.arquillian.core.impl.ObserverImpl.invoke(ObserverImpl.java:94)

          at org.jboss.arquillian.core.impl.EventContextImpl.invokeObservers(EventContextImpl.java:99)

          at org.jboss.arquillian.core.impl.EventContextImpl.proceed(EventContextImpl.java:81)

          at org.jboss.arquillian.core.impl.ManagerImpl.fire(ManagerImpl.java:145)

          at org.jboss.arquillian.core.impl.ManagerImpl.fire(ManagerImpl.java:116)

          at org.jboss.arquillian.core.impl.EventImpl.fire(EventImpl.java:67)

          at org.jboss.arquillian.container.test.impl.client.ContainerEventController.execute(ContainerEventController.java:100)

          at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

          at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)

          at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)

          at java.lang.reflect.Method.invoke(Method.java:498)

          at org.jboss.arquillian.core.impl.ObserverImpl.invoke(ObserverImpl.java:94)

          at org.jboss.arquillian.core.impl.EventContextImpl.invokeObservers(EventContextImpl.java:99)

          at org.jboss.arquillian.core.impl.EventContextImpl.proceed(EventContextImpl.java:81)

          at org.jboss.arquillian.test.impl.TestContextHandler.createClassContext(TestContextHandler.java:92)

          at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

          at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)

          at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)

          at java.lang.reflect.Method.invoke(Method.java:498)

          at org.jboss.arquillian.core.impl.ObserverImpl.invoke(ObserverImpl.java:94)

          at org.jboss.arquillian.core.impl.EventContextImpl.proceed(EventContextImpl.java:88)

          at org.jboss.arquillian.test.impl.TestContextHandler.createSuiteContext(TestContextHandler.java:73)

          at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

          at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)

          at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)

          at java.lang.reflect.Method.invoke(Method.java:498)

          at org.jboss.arquillian.core.impl.ObserverImpl.invoke(ObserverImpl.java:94)

          at org.jboss.arquillian.core.impl.EventContextImpl.proceed(EventContextImpl.java:88)

          at org.jboss.arquillian.core.impl.ManagerImpl.fire(ManagerImpl.java:145)

          at org.jboss.arquillian.core.impl.ManagerImpl.fire(ManagerImpl.java:116)

          at org.jboss.arquillian.test.impl.EventTestRunnerAdaptor.beforeClass(EventTestRunnerAdaptor.java:87)

          at org.jboss.arquillian.junit.Arquillian$2.evaluate(Arquillian.java:201)

          at org.jboss.arquillian.junit.Arquillian.multiExecute(Arquillian.java:426)

          at org.jboss.arquillian.junit.Arquillian.access$200(Arquillian.java:54)

          at org.jboss.arquillian.junit.Arquillian$3.evaluate(Arquillian.java:218)

          at org.junit.runners.ParentRunner.run(ParentRunner.java:363)

          at org.jboss.arquillian.junit.Arquillian.run(Arquillian.java:166)

          at org.apache.maven.surefire.junit4.JUnit4Provider.execute(JUnit4Provider.java:367)

          at org.apache.maven.surefire.junit4.JUnit4Provider.executeWithRerun(JUnit4Provider.java:274)

          at org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:238)

          at org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:161)

          at org.apache.maven.surefire.booter.ForkedBooter.invokeProviderInSameClassLoader(ForkedBooter.java:290)

          at org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:242)

          at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:121)

      Caused by: java.lang.reflect.InvocationTargetException

          at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

          at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)

          at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)

          at java.lang.reflect.Method.invoke(Method.java:498)

          at org.jboss.shrinkwrap.resolver.api.Invokable.invokeMethod(Invokable.java:100)

          ... 61 more

      Caused by: java.lang.RuntimeException: Could not create new service instance

          at org.jboss.shrinkwrap.resolver.spi.loader.SpiServiceLoader.createInstance(SpiServiceLoader.java:251)

          at org.jboss.shrinkwrap.resolver.spi.loader.SpiServiceLoader.createInstances(SpiServiceLoader.java:211)

          at org.jboss.shrinkwrap.resolver.spi.loader.SpiServiceLoader.all(SpiServiceLoader.java:79)

          at org.jboss.shrinkwrap.resolver.spi.loader.SpiServiceLoader.onlyOne(SpiServiceLoader.java:85)

          at org.jboss.shrinkwrap.resolver.spi.loader.ServiceRegistry.onlyOne(ServiceRegistry.java:102)

          ... 66 more

      Caused by: java.lang.reflect.InvocationTargetException

          at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)

          at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)

          at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)

          at java.lang.reflect.Constructor.newInstance(Constructor.java:423)

          at org.jboss.shrinkwrap.resolver.spi.loader.SpiServiceLoader.createInstance(SpiServiceLoader.java:247)

          ... 70 more

      Caused by: java.lang.NoClassDefFoundError: org/eclipse/aether/resolution/DependencyResolutionException

          at org.jboss.shrinkwrap.resolver.impl.maven.MavenResolverSystemImpl.<init>(MavenResolverSystemImpl.java:43)

          ... 75 more

      Caused by: java.lang.ClassNotFoundException: org.eclipse.aether.resolution.DependencyResolutionException

          at java.net.URLClassLoader.findClass(URLClassLoader.java:381)

          at java.lang.ClassLoader.loadClass(ClassLoader.java:424)

          at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)

          at java.lang.ClassLoader.loadClass(ClassLoader.java:357)

          ... 76 more

      test.war:

      /WEB-INF/

      /WEB-INF/classes/

      /WEB-INF/classes/com/

      /WEB-INF/classes/com/example/

      /WEB-INF/classes/com/example/GrossNetValueCalculation.class

      /WEB-INF/classes/com/example/GrossNetValueCalculationBean.class

      /META-INF/

      /META-INF/beans.xml

      Begin calculateNetValue

      Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 10.389 sec <<< FAILURE! - in com.example.ArquillianTest

      calculateNetValue(com.example.service.ArquillianTest)  Time elapsed: 0.431 sec  <<< ERROR!

      javax.ejb.EJBException: WFLYEJB0442: Unexpected Error

          at com.example.ArquillianTest.calculateNetValue(ArquillianTest.java:95)

      Caused by: java.lang.NoClassDefFoundError: org/javamoney/moneta/Money

          at com.example.ArquillianTest.calculateNetValue(ArquillianTest.java:95)

      Caused by: java.lang.ClassNotFoundException: org.javamoney.moneta.Money from [Module "deployment.test.war:main" from Service Module Loader]

          at com.example.BeanArquillianTest.calculateNetValue(ArquillianTest.java:95)

       

      How could I solve it?

       

      Thanks in advance,

      Markus