Showing posts with label arquillian. Show all posts
Showing posts with label arquillian. Show all posts

Saturday, May 23, 2015

Arquillian is looking for com/opera/core/systems/OperaDriver

On last week when I was unit testing with Arquillian, I got this error causing my unit test failed.
java.lang.NoClassDefFoundError: com/opera/core/systems/OperaDriver
 at java.lang.Class.getDeclaredMethods0(Native Method)
 at java.lang.Class.privateGetDeclaredMethods(Class.java:2575)
 at java.lang.Class.getDeclaredMethods(Class.java:1857)
 at org.jboss.arquillian.core.impl.Reflections.getObserverMethods(Reflections.java:52)
 at org.jboss.arquillian.core.impl.ExtensionImpl.of(ExtensionImpl.java:51)
 at org.jboss.arquillian.core.impl.ManagerImpl.inject(ManagerImpl.java:198)
 at org.jboss.arquillian.core.impl.InjectorImpl.inject(InjectorImpl.java:58)
 at org.jboss.arquillian.core.impl.loadable.ServiceRegistryLoader.createServiceInstance(ServiceRegistryLoader.java:108)
 at org.jboss.arquillian.core.impl.loadable.ServiceRegistryLoader.all(ServiceRegistryLoader.java:55)
 at org.jboss.arquillian.drone.impl.DroneRegistrar.registerConfigurators(DroneRegistrar.java:84)
 at org.jboss.arquillian.drone.impl.DroneRegistrar.register(DroneRegistrar.java:77)
 at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
 at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
 at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
 at java.lang.reflect.Method.invoke(Method.java:622)
 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.createSuiteContext(TestContextHandler.java:60)
 at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
 at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
 at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
 at java.lang.reflect.Method.invoke(Method.java:622)
 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:135)
 at org.jboss.arquillian.core.impl.ManagerImpl.fire(ManagerImpl.java:115)
 at org.jboss.arquillian.test.impl.EventTestRunnerAdaptor.beforeSuite(EventTestRunnerAdaptor.java:68)
 at org.jboss.arquillian.junit.Arquillian.run(Arquillian.java:97)
 at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
 at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
 at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
 at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
 at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
 at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
Caused by: java.lang.ClassNotFoundException: com.opera.core.systems.OperaDriver
 at java.net.URLClassLoader$1.run(URLClassLoader.java:217)
 at java.security.AccessController.doPrivileged(Native Method)
 at java.net.URLClassLoader.findClass(URLClassLoader.java:205)
 at java.lang.ClassLoader.loadClass(ClassLoader.java:323)
 at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:294)
 at java.lang.ClassLoader.loadClass(ClassLoader.java:268)
 ... 35 more
While spotting the error on the Maven configuration, I found out that grahene-webdriver and arquillian-drone-webdriver were both declare in POM.
        <dependency>
         <groupid>org.jboss.arquillian.graphene</groupid>
         <artifactid>graphene-webdriver</artifactid>
         <version>2.0.0.Alpha1</version>
         <type>pom</type>
         <scope>test</scope>
        </dependency>
        
        <dependency>
         <groupid>org.jboss.arquillian.graphene</groupid>
         <artifactid>graphene-webdriver-drone</artifactid>
         <version>2.0.0.Alpha3</version>
         <scope>test</scope>
        </dependency>
        
        <dependency>
         <groupid>org.jboss.arquillian.extension</groupid>
         <artifactid>arquillian-drone-webdriver</artifactid>
         <scope>test</scope>
        </dependency>
        
        <dependency>
         <groupid>org.jboss.arquillian.extension</groupid>
         <artifactid>arquillian-drone-webdriver-depchain</artifactid>
         <type>pom</type>
         <scope>test</scope>
        </dependency>
Why both web driver were declare? That was my first question come into my mind. Is that necessary? Is there any difference? As according to the Arquillian guide, I'm suppose to have graphene-webdriver with version 2.0.3.Final. And the other 3 dependencies are not needed. This has my problem resolved.

Saturday, May 16, 2015

Now I have Tomcat with Arquillian

Beginning mid of April until now, I have already spent almost 27 hours on the alien tool, Arquillian. The major problem I'm facing with this tool is the setup, the setup guide didn't mention clearly which Arquillian version should correlated with JBoss version. End up I spent my whole day fighting on the version issue. As of today, I am still failing to make it work with JBoss. This has greatly jeopardize my progress.

This is what make me failed during the setup for JBoss.
        <dependency>
         <groupid>org.jboss.spec</groupid>
         <artifactid>jboss-javaee-6.0</artifactid>
         <version>3.0.2.Final</version>
         <type>pom</type>
         <scope>provided</scope>
        </dependency>
        <dependency>
         <groupid>org.jboss.as</groupid>
         <artifactid>jboss-as-arquillian-container-managed</artifactid>
         <scope>test</scope>
        </dependency>
And this is what I have for Arquillian:
        <dependency>
            <groupid>org.jboss.arquillian.junit</groupid>
            <artifactid>arquillian-junit-container</artifactid>
            <scope>test</scope>
        <dependency>
            <groupid>org.jboss.arquillian.protocol</groupid>
            <artifactid>arquillian-protocol-servlet</artifactid>
            <scope>test</scope>
        </dependency>
        <dependency>
         <groupid>org.jboss.arquillian.graphene</groupid>
         <artifactid>graphene-webdriver-drone</artifactid>
         <version>2.0.0.Alpha3</version>
         <scope>test</scope>
        </dependency>
        <dependency>
         <groupid>org.jboss.arquillian.extension</groupid>
         <artifactid>arquillian-drone-webdriver</artifactid>
         <scope>test</scope>
        </dependency>
        <dependency>
         <groupid>org.jboss.arquillian.extension</groupid>
         <artifactid>arquillian-drone-webdriver-depchain</artifactid>
         <type>pom</type>
         <scope>test</scope>
        </dependency>
So far I only manage to make it work on Tomcat, and this is what I have for Tomcat:
        <dependency>
         <groupId>org.jboss.arquillian.container</groupId>
         <artifactId>arquillian-tomcat-embedded-7</artifactId>
         <version>1.0.0.CR4</version>
         <scope>test</scope>
        </dependency>
        <dependency>
         <groupId>org.apache.tomcat.embed</groupId>
         <artifactId>tomcat-embed-core</artifactId>
         <version>7.0.42</version>
         <scope>test</scope>
        </dependency>
        <dependency>
         <groupId>org.apache.tomcat.embed</groupId>
         <artifactId>tomcat-embed-jasper</artifactId>
         <version>7.0.42</version>
         <scope>test</scope>
        </dependency>
        <dependency>
         <groupId>org.apache.tomcat.embed</groupId>
         <artifactId>tomcat-embed-logging-juli</artifactId>
         <version>7.0.42</version>
         <scope>test</scope>
        </dependency>
        <dependency>
         <groupId>org.eclipse.jdt.core.compiler</groupId>
         <artifactId>ecj</artifactId>
         <version>4.2.2</version>
         <scope>test</scope>
        </dependency>
When running on Tomcat, there is additional stuff is needed which is not mentioned in Arquillian documentation, but I found it in the forum mention that I must have org.jboss.weld.environment.servlet.Listener in web.xml. First the following library is require:
        <dependency>
         <groupId>org.jboss.weld.servlet</groupId>
         <artifactId>weld-servlet</artifactId>
         <version>2.0.3.Final</version>
         <scope>test</scope>
        </dependency>
And then create a new web.xml in src/test/resources with following content:
<web-app id="WebApp_ID" version="3.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemalocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">
 <display-name>WebEngineering3</display-name>
 <welcome-file-list>
  <welcome-file>index.xhtml</welcome-file>
 </welcome-file-list>
 
 <servlet>
  <servlet-name>Faces Servlet</servlet-name>
  <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
  <load-on-startup>1</load-on-startup>
 </servlet>
 <servlet-mapping>
  <servlet-name>Faces Servlet</servlet-name>
  <url-pattern>*.xhtml</url-pattern>
 </servlet-mapping>
 
 <listener>
  <listener-class>org.jboss.weld.environment.servlet.Listener</listener-class>
 </listener>
</web-app>

Friday, May 1, 2015

Arquillian throws IllegalArgumentException during packaging with ShrinkWrap

Just come across Arquillian and find it so cool that I am able to perform unit test on front end without the 'Selenium way'. The way the Selenium did was I have to leave my computer alone while the test is running otherwise the test result will not accurate.

Now with this creature, I am worry free. In 'Arquillian way', I'm no longer have the web deploy to the server and have the server up and running before the test run. All I have to do were done in programming, this will include package the content in war file and get it deploy to server. It wasn't an Ant build, it was using ShrinkWrap.

Assuming I have my classes put inside the package org.huahsin68, the first step in unit test was the war packaging. It was done with the piece shows below:
   @Deployment(testable=false)
   public static WebArchive createDeployments() {
      WebArchive war = ShrinkWrap.create(WebArchive.class, "ThePackage.war");
      war.setWebXML(new File(WEBAPP_SRC, "WEB-INF/web.xml"));
      war.addPackage(java.lang.Package.getPackage("org.huahsin"));
      war.addAsWebInfResource(EmptyAsset.INSTANCE, "beans.xml");
      war.addAsWebResource(new File(WEBAPP_SRC, "index.xhtml"));

      return war;
   }
Somehow there is an error with that piece when the test were run. Following stacktrace tells the whole story.
java.lang.RuntimeException: Could not invoke deployment method: public static org.jboss.shrinkwrap.api.spec.WebArchive org.huahsin68.IndexBeanTest.createDeployment()
 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:99)
 at org.jboss.arquillian.container.test.impl.client.deployment.AnnotationDeploymentScenarioGenerator.generate(AnnotationDeploymentScenarioGenerator.java:62)
 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:57)
 at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
 at java.lang.reflect.Method.invoke(Method.java:622)
 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:135)
 at org.jboss.arquillian.core.impl.ManagerImpl.fire(ManagerImpl.java:115)
 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:57)
 at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
 at java.lang.reflect.Method.invoke(Method.java:622)
 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:75)
 at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
 at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
 at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
 at java.lang.reflect.Method.invoke(Method.java:622)
 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:60)
 at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
 at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
 at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
 at java.lang.reflect.Method.invoke(Method.java:622)
 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:135)
 at org.jboss.arquillian.core.impl.ManagerImpl.fire(ManagerImpl.java:115)
 at org.jboss.arquillian.test.impl.EventTestRunnerAdaptor.beforeClass(EventTestRunnerAdaptor.java:80)
 at org.jboss.arquillian.junit.Arquillian$2.evaluate(Arquillian.java:182)
 at org.jboss.arquillian.junit.Arquillian.multiExecute(Arquillian.java:314)
 at org.jboss.arquillian.junit.Arquillian.access$100(Arquillian.java:46)
 at org.jboss.arquillian.junit.Arquillian$3.evaluate(Arquillian.java:199)
 at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
 at org.jboss.arquillian.junit.Arquillian.run(Arquillian.java:147)
 at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
 at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
 at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
 at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
 at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
 at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
Caused by: java.lang.reflect.InvocationTargetException
 at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
 at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
 at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
 at java.lang.reflect.Method.invoke(Method.java:622)
 at org.jboss.arquillian.container.test.impl.client.deployment.AnnotationDeploymentScenarioGenerator.invoke(AnnotationDeploymentScenarioGenerator.java:173)
 ... 50 more
Caused by: java.lang.IllegalArgumentException: Pack must be specified
 at org.jboss.shrinkwrap.impl.base.Validate.notNull(Validate.java:43)
 at org.jboss.shrinkwrap.impl.base.container.ContainerBase.addPackage(ContainerBase.java:1363)
 at org.huahsin68.IndexBeanTest.createDeployment(IndexBeanTest.java:42)
 ... 55 more
There is a lazy way to resolve this issue, just pick any of the class and retrieve the package name from that class. Thus I replace the code:

war.addPackage(java.lang.Package.getPackage("org.huahsin"));

with this:

war.addPackage(anyClass.class.getPackage());

But this is not the clean way because if the class will going to remove in one day and this could lead to a disaster.

Good luck!