1 Reply Latest reply on Aug 16, 2007 12:13 PM by Maik Lehradt

    maven 2 dependencies and junit 4 tests

    Maik Lehradt Newbie

      I have strange problems with unit tests and maven dependencies. I read this forum but can't find any answers yet.

      We want to run our unit tests with embedded JBoss. Our project is divided in several subprojects which can be deployed seperately.

      common for utility classes
      domain for entity (JPA annotated) classes
      service-api for session bean interfaces
      service-impl with interface implementations

      I can start junit (4) tests from eclipse if I don't add the domain project as a maven dependency and instead add the resulting jar-file. If I do add the domain project as a dependency, I get these error messages:


      WARN 16-08 12:21:21,940 (UnifiedLoaderRepository3.java:addClassLoader:675) -Tried to add non-URLClassLoader. Ignored
      ERROR 16-08 12:21:22,315 (AbstractController.java:incrementState:456) -Error installing to Start: name=ResourcesToDeploy state=Create
      java.lang.NoSuchFieldError: factoryFinder
       at org.jboss.virtual.VFS.init(VFS.java:68)
       at org.jboss.virtual.VFS.<clinit>(VFS.java:51)
       at org.jboss.embedded.DeploymentGroup.getVirtualFile(DeploymentGroup.java:186)
       at org.jboss.embedded.DeploymentGroup.add(DeploymentGroup.java:176)
       at org.jboss.embedded.DeploymentGroup.addResource(DeploymentGroup.java:329)
       at org.jboss.embedded.DeploymentScanner.start(DeploymentScanner.java:85)
       at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
       at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
       at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
       at java.lang.reflect.Method.invoke(Method.java:585)
       at org.jboss.reflect.plugins.introspection.ReflectionUtils.invoke(ReflectionUtils.java:55)
       at org.jboss.reflect.plugins.introspection.ReflectMethodInfoImpl.invoke(ReflectMethodInfoImpl.java:108)
       at org.jboss.joinpoint.plugins.BasicMethodJoinPoint.dispatch(BasicMethodJoinPoint.java:66)
       at org.jboss.kernel.plugins.dependency.KernelControllerContextAction.dispatchJoinPoint(KernelControllerContextAction.java:103)
       at org.jboss.kernel.plugins.dependency.LifecycleAction.installActionInternal(LifecycleAction.java:145)
       at org.jboss.kernel.plugins.dependency.KernelControllerContextAction.installAction(KernelControllerContextAction.java:197)
       at org.jboss.kernel.plugins.dependency.KernelControllerContextAction.install(KernelControllerContextAction.java:136)
       at org.jboss.dependency.plugins.AbstractControllerContextActions.install(AbstractControllerContextActions.java:51)
       at org.jboss.dependency.plugins.AbstractControllerContext.install(AbstractControllerContext.java:233)
       at org.jboss.dependency.plugins.AbstractController.install(AbstractController.java:724)
       at org.jboss.dependency.plugins.AbstractController.incrementState(AbstractController.java:445)
       at org.jboss.dependency.plugins.AbstractController.resolveContexts(AbstractController.java:555)
       at org.jboss.dependency.plugins.AbstractController.resolveContexts(AbstractController.java:489)
       at org.jboss.dependency.plugins.AbstractController.install(AbstractController.java:289)
       at org.jboss.dependency.plugins.AbstractController.install(AbstractController.java:192)
       at org.jboss.kernel.plugins.deployment.AbstractKernelDeployer.deployBean(AbstractKernelDeployer.java:302)
       at org.jboss.kernel.plugins.deployment.AbstractKernelDeployer.deployBeans(AbstractKernelDeployer.java:272)
       at org.jboss.kernel.plugins.deployment.AbstractKernelDeployer.deploy(AbstractKernelDeployer.java:119)
       at org.jboss.kernel.plugins.deployment.xml.BeanXMLDeployer.deploy(BeanXMLDeployer.java:96)
       at org.jboss.embedded.Bootstrap.deployBaseBootstrapUrl(Bootstrap.java:150)
       at org.jboss.embedded.Bootstrap.bootstrapURL(Bootstrap.java:162)
       at org.jboss.embedded.Bootstrap.bootstrap(Bootstrap.java:201)
       at org.jboss.embedded.Bootstrap.bootstrap(Bootstrap.java:214)
       at de.ethalon.control.MyEjbTestCase.setUpClass(MyEjbTestCase.java:102)
       at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
       at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
       at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
       at java.lang.reflect.Method.invoke(Method.java:585)
       at org.junit.internal.runners.BeforeAndAfterRunner.invokeMethod(BeforeAndAfterRunner.java:74)
       at org.junit.internal.runners.BeforeAndAfterRunner.runBefores(BeforeAndAfterRunner.java:50)
       at org.junit.internal.runners.BeforeAndAfterRunner.runProtected(BeforeAndAfterRunner.java:33)
       at org.junit.internal.runners.TestClassRunner.run(TestClassRunner.java:52)
       at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:38)
       at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
       at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:460)
       at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:673)
       at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:386)
       at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)
      ERROR 16-08 12:21:22,488 (AbstractController.java:incrementState:456) -Error installing to Start: name=ResourcesToDeploy2 state=Create
      java.lang.NoClassDefFoundError
       at org.jboss.embedded.DeploymentGroup.getDeployerDirUrls(DeploymentGroup.java:532)
       at org.jboss.embedded.DeploymentGroup.getDeployerDirUrlsFromResource(DeploymentGroup.java:522)
       at org.jboss.embedded.DeploymentGroup.addDirectoryByResource(DeploymentGroup.java:470)
       at org.jboss.embedded.DeploymentScanner.start(DeploymentScanner.java:99)
       at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
       at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
       at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
       at java.lang.reflect.Method.invoke(Method.java:585)
       at org.jboss.reflect.plugins.introspection.ReflectionUtils.invoke(ReflectionUtils.java:55)
       at org.jboss.reflect.plugins.introspection.ReflectMethodInfoImpl.invoke(ReflectMethodInfoImpl.java:108)
       at org.jboss.joinpoint.plugins.BasicMethodJoinPoint.dispatch(BasicMethodJoinPoint.java:66)
       at org.jboss.kernel.plugins.dependency.KernelControllerContextAction.dispatchJoinPoint(KernelControllerContextAction.java:103)
       at org.jboss.kernel.plugins.dependency.LifecycleAction.installActionInternal(LifecycleAction.java:145)
       at org.jboss.kernel.plugins.dependency.KernelControllerContextAction.installAction(KernelControllerContextAction.java:197)
       at org.jboss.kernel.plugins.dependency.KernelControllerContextAction.install(KernelControllerContextAction.java:136)
       at org.jboss.dependency.plugins.AbstractControllerContextActions.install(AbstractControllerContextActions.java:51)
       at org.jboss.dependency.plugins.AbstractControllerContext.install(AbstractControllerContext.java:233)
       at org.jboss.dependency.plugins.AbstractController.install(AbstractController.java:724)
       at org.jboss.dependency.plugins.AbstractController.incrementState(AbstractController.java:445)
       at org.jboss.dependency.plugins.AbstractController.resolveContexts(AbstractController.java:555)
       at org.jboss.dependency.plugins.AbstractController.resolveContexts(AbstractController.java:489)
       at org.jboss.dependency.plugins.AbstractController.install(AbstractController.java:289)
       at org.jboss.dependency.plugins.AbstractController.install(AbstractController.java:192)
       at org.jboss.kernel.plugins.deployment.AbstractKernelDeployer.deployBean(AbstractKernelDeployer.java:302)
       at org.jboss.kernel.plugins.deployment.AbstractKernelDeployer.deployBeans(AbstractKernelDeployer.java:272)
       at org.jboss.kernel.plugins.deployment.AbstractKernelDeployer.deploy(AbstractKernelDeployer.java:119)
       at org.jboss.kernel.plugins.deployment.xml.BeanXMLDeployer.deploy(BeanXMLDeployer.java:96)
       at org.jboss.embedded.Bootstrap.deployBaseBootstrapUrl(Bootstrap.java:150)
       at org.jboss.embedded.Bootstrap.bootstrapURL(Bootstrap.java:162)
       at org.jboss.embedded.Bootstrap.bootstrap(Bootstrap.java:201)
       at org.jboss.embedded.Bootstrap.bootstrap(Bootstrap.java:214)
       at de.ethalon.control.MyEjbTestCase.setUpClass(MyEjbTestCase.java:102)
       at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
       at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
       at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
       at java.lang.reflect.Method.invoke(Method.java:585)
       at org.junit.internal.runners.BeforeAndAfterRunner.invokeMethod(BeforeAndAfterRunner.java:74)
       at org.junit.internal.runners.BeforeAndAfterRunner.runBefores(BeforeAndAfterRunner.java:50)
       at org.junit.internal.runners.BeforeAndAfterRunner.runProtected(BeforeAndAfterRunner.java:33)
       at org.junit.internal.runners.TestClassRunner.run(TestClassRunner.java:52)
       at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:38)
       at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
       at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:460)
       at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:673)
       at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:386)
       at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)
      ERROR 16-08 12:21:22,503 (AbstractController.java:incrementState:456) -Error installing to Start: name=ResourcesToDeploy3 state=Create
      java.lang.NoClassDefFoundError
       at org.jboss.embedded.DeploymentGroup.getDeployerDirUrls(DeploymentGroup.java:532)
       at org.jboss.embedded.DeploymentGroup.getDeployerDirUrlsFromResource(DeploymentGroup.java:522)
       at org.jboss.embedded.DeploymentGroup.addDirectoryByResource(DeploymentGroup.java:470)
       at org.jboss.embedded.DeploymentScanner.start(DeploymentScanner.java:99)
       at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
       at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
       at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
       at java.lang.reflect.Method.invoke(Method.java:585)
       at org.jboss.reflect.plugins.introspection.ReflectionUtils.invoke(ReflectionUtils.java:55)
       at org.jboss.reflect.plugins.introspection.ReflectMethodInfoImpl.invoke(ReflectMethodInfoImpl.java:108)
       at org.jboss.joinpoint.plugins.BasicMethodJoinPoint.dispatch(BasicMethodJoinPoint.java:66)
       at org.jboss.kernel.plugins.dependency.KernelControllerContextAction.dispatchJoinPoint(KernelControllerContextAction.java:103)
       at org.jboss.kernel.plugins.dependency.LifecycleAction.installActionInternal(LifecycleAction.java:145)
       at org.jboss.kernel.plugins.dependency.KernelControllerContextAction.installAction(KernelControllerContextAction.java:197)
       at org.jboss.kernel.plugins.dependency.KernelControllerContextAction.install(KernelControllerContextAction.java:136)
       at org.jboss.dependency.plugins.AbstractControllerContextActions.install(AbstractControllerContextActions.java:51)
       at org.jboss.dependency.plugins.AbstractControllerContext.install(AbstractControllerContext.java:233)
       at org.jboss.dependency.plugins.AbstractController.install(AbstractController.java:724)
       at org.jboss.dependency.plugins.AbstractController.incrementState(AbstractController.java:445)
       at org.jboss.dependency.plugins.AbstractController.resolveContexts(AbstractController.java:555)
       at org.jboss.dependency.plugins.AbstractController.resolveContexts(AbstractController.java:489)
       at org.jboss.dependency.plugins.AbstractController.install(AbstractController.java:289)
       at org.jboss.dependency.plugins.AbstractController.install(AbstractController.java:192)
       at org.jboss.kernel.plugins.deployment.AbstractKernelDeployer.deployBean(AbstractKernelDeployer.java:302)
       at org.jboss.kernel.plugins.deployment.AbstractKernelDeployer.deployBeans(AbstractKernelDeployer.java:272)
       at org.jboss.kernel.plugins.deployment.AbstractKernelDeployer.deploy(AbstractKernelDeployer.java:119)
       at org.jboss.kernel.plugins.deployment.xml.BeanXMLDeployer.deploy(BeanXMLDeployer.java:96)
       at org.jboss.embedded.Bootstrap.deployBaseBootstrapUrl(Bootstrap.java:150)
       at org.jboss.embedded.Bootstrap.bootstrapURL(Bootstrap.java:162)
       at org.jboss.embedded.Bootstrap.bootstrap(Bootstrap.java:201)
       at org.jboss.embedded.Bootstrap.bootstrap(Bootstrap.java:214)
       at de.ethalon.control.MyEjbTestCase.setUpClass(MyEjbTestCase.java:102)
       at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
       at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
       at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
       at java.lang.reflect.Method.invoke(Method.java:585)
       at org.junit.internal.runners.BeforeAndAfterRunner.invokeMethod(BeforeAndAfterRunner.java:74)
       at org.junit.internal.runners.BeforeAndAfterRunner.runBefores(BeforeAndAfterRunner.java:50)
       at org.junit.internal.runners.BeforeAndAfterRunner.runProtected(BeforeAndAfterRunner.java:33)
       at org.junit.internal.runners.TestClassRunner.run(TestClassRunner.java:52)
       at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:38)
       at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
       at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:460)
       at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:673)
       at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:386)
       at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)
      


      My Test class:
      public class MyEjbTestCase {
       private static AssembledDirectory jar;
      
       private static boolean globalSetup = false;
      
       private static void deploy() {
       jar = AssembledContextFactory.getInstance().create("service-impl-test.jar");
       jar.addClass(Node.class);
       jar.addClass(User.class);
       jar.addClass(Shift.class);
       jar.addClass(ShiftWeek.class);
       jar.addClass(Node2.class);
       jar.addClass(HelloWorld.class);
       jar.addClass(HelloWorldBean.class);
       jar.mkdir("META-INF").addResource("META-INF/persistence.xml", "persistence.xml");
       try {
       Bootstrap.getInstance().deploy(jar);
       } catch (DeploymentException e) {
       throw new RuntimeException("Unable to deploy", e);
       }
       }
      
       @Test
       public void testFindShiftByName() throws NamingException {
       InitialContext ctx = new InitialContext();
       HelloWorld service = (HelloWorld) ctx.lookup("HelloWorldBean/local");
       ShiftWeek shiftWeek = new ShiftWeek();
       shiftWeek.setName("test");
       shiftWeek.setDeleted(Boolean.FALSE);
       service.saveShiftWeek(shiftWeek);
       shiftWeek = service.findShiftWeek("test");
       }
      
       private static void undeploy() {
       try {
       if (jar != null) {
       Bootstrap.getInstance().undeploy(jar);
       AssembledContextFactory.getInstance().remove(jar);
       }
       } catch (DeploymentException e) {
       throw new RuntimeException("Unable to undeploy", e);
       }
       }
      
       @BeforeClass
       public static void setUpClass() throws Exception {
       globalSetup = true;
       org.jboss.net.protocol.URLStreamHandlerFactory factory = new org.jboss.net.protocol.URLStreamHandlerFactory();
       URL.setURLStreamHandlerFactory(factory);
       if (!Bootstrap.getInstance().isStarted()) {
       Bootstrap.getInstance().bootstrap();
       }
       deploy();
       }
      
       @AfterClass
       public static void tearDownClass() throws Exception {
       undeploy();
       if (System.getProperty("shutdown.embedded.jboss") != null) Bootstrap
       .getInstance().shutdown();
       }
      
       @Before
       public void setUp() throws Exception {
       if (globalSetup) return;
       Bootstrap.getInstance().bootstrap();
       deploy();
       }
      
       @After
       public void tearDown() throws Exception {
       if (globalSetup) return;
       undeploy();
       }
      
       @Test
       public void testSomething() throws Exception {
       InitialContext ctx = new InitialContext();
       HelloWorld hello = (HelloWorld) ctx.lookup("HelloWorldBean/local");
       String msg = hello.sayHello("world");
       System.out.println(msg);
       }
      
       @Test
       public void testFindNode() throws Exception {
       InitialContext ctx = new InitialContext();
       HelloWorld nodeService = (HelloWorld) ctx.lookup("HelloWorldBean/local");
       Node2 node1 = nodeService.createNode("test");
       assertNotNull(node1);
       assertNotNull(node1.getName());
      
       Node2 node2 = nodeService.findNode("test");
       assertNotNull(node2);
       assertEquals(node1.getName(), node2.getName());
       }
      
      }