1

我有一个使用 arquillian 1.1.1.Final 的项目,并且我有一些使用石墨烯和其他扩展的工作测试。现在我想用 warp 添加一些测试。但我得到一个 NoClassDefFoundError。例外是:

 class br.com.sample.view.LoginTest$1 in Module "deployment.login.war:main" from Service Module Loader: java.lang.LinkageError: Failed to link br/com/sample/view/LoginTest$1 (Module "deployment.login.war:main" from Service Module Loader)
  at org.jboss.modules.ModuleClassLoader.defineClass(ModuleClassLoader.java:396) [jboss-modules.jar:1.1.1.GA]
  at org.jboss.modules.ModuleClassLoader.loadClassLocal(ModuleClassLoader.java:243) [jboss-modules.jar:1.1.1.GA]
  at org.jboss.modules.ModuleClassLoader$1.loadClassLocal(ModuleClassLoader.java:73) [jboss-modules.jar:1.1.1.GA]
  at org.jboss.modules.Module.loadModuleClass(Module.java:517) [jboss-modules.jar:1.1.1.GA]
  at org.jboss.modules.ModuleClassLoader.findClass(ModuleClassLoader.java:182) [jboss-modules.jar:1.1.1.GA]
  at org.jboss.modules.ConcurrentClassLoader.performLoadClassUnchecked(ConcurrentClassLoader.java:468) [jboss-modules.jar:1.1.1.GA]
  at org.jboss.modules.ConcurrentClassLoader.performLoadClassChecked(ConcurrentClassLoader.java:456) [jboss-modules.jar:1.1.1.GA]
  at org.jboss.modules.ConcurrentClassLoader.performLoadClass(ConcurrentClassLoader.java:398) [jboss-modules.jar:1.1.1.GA]
  at org.jboss.modules.ConcurrentClassLoader.loadClass(ConcurrentClassLoader.java:120) [jboss-modules.jar:1.1.1.GA]
  at org.jboss.as.jpa.hibernate4.HibernateAnnotationScanner.getPackagesInJar(HibernateAnnotationScanner.java:171)
  at org.hibernate.ejb.Ejb3Configuration.addScannedEntries(Ejb3Configuration.java:489) [hibernate-entitymanager-4.0.1.Final.jar:4.0.1.Final]
  at org.hibernate.ejb.Ejb3Configuration.scanForClasses(Ejb3Configuration.java:851) [hibernate-entitymanager-4.0.1.Final.jar:4.0.1.Final]
  at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:596) [hibernate-entitymanager-4.0.1.Final.jar:4.0.1.Final]
  at org.hibernate.ejb.HibernatePersistence.createContainerEntityManagerFactory(HibernatePersistence.java:72) [hibernate-entitymanager-4.0.1.Final.jar:4.0.1.Final]
  at org.jboss.as.jpa.service.PersistenceUnitServiceImpl.createContainerEntityManagerFactory(PersistenceUnitServiceImpl.java:162) [jboss-as-jpa-7.1.1.Final.jar:7.1.1.Final]
  at org.jboss.as.jpa.service.PersistenceUnitServiceImpl.start(PersistenceUnitServiceImpl.java:85) [jboss-as-jpa-7.1.1.Final.jar:7.1.1.Final]
  at org.jboss.msc.service.ServiceControllerImpl$StartTask.startService(ServiceControllerImpl.java:1811) [jboss-msc-1.0.2.GA.jar:1.0.2.GA]
  at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1746) [jboss-msc-1.0.2.GA.jar:1.0.2.GA]
  at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) [rt.jar:1.7.0_25]
  at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) [rt.jar:1.7.0_25]
  at java.lang.Thread.run(Thread.java:724) [rt.jar:1.7.0_25]
Caused by: java.lang.NoClassDefFoundError: org/jboss/arquillian/warp/Activity
  at java.lang.ClassLoader.defineClass1(Native Method) [rt.jar:1.7.0_25]
  at java.lang.ClassLoader.defineClass(ClassLoader.java:788) [rt.jar:1.7.0_25]
  at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142) [rt.jar:1.7.0_25]
  at org.jboss.modules.ModuleClassLoader.doDefineOrLoadClass(ModuleClassLoader.java:327) [jboss-modules.jar:1.1.1.GA]
  at org.jboss.modules.ModuleClassLoader.defineClass(ModuleClassLoader.java:391) [jboss-modules.jar:1.1.1.GA]
  ... 20 more
Caused by: java.lang.ClassNotFoundException: org.jboss.arquillian.warp.Activity from [Module "deployment.login.war:main" from Service Module Loader]
  at org.jboss.modules.ModuleClassLoader.findClass(ModuleClassLoader.java:190) [jboss-modules.jar:1.1.1.GA]
  at org.jboss.modules.ConcurrentClassLoader.performLoadClassUnchecked(ConcurrentClassLoader.java:468) [jboss-modules.jar:1.1.1.GA]
  at org.jboss.modules.ConcurrentClassLoader.performLoadClassChecked(ConcurrentClassLoader.java:456) [jboss-modules.jar:1.1.1.GA]
  at org.jboss.modules.ConcurrentClassLoader.performLoadClass(ConcurrentClassLoader.java:398) [jboss-modules.jar:1.1.1.GA]
  at org.jboss.modules.ConcurrentClassLoader.loadClass(ConcurrentClassLoader.java:120) [jboss-modules.jar:1.1.1.GA]
  ... 25 more


13:26:07,636 ERROR [org.jboss.msc.service.fail] (MSC service thread 1-7) MSC00001: Failed to start service jboss.persistenceunit."login.war#test-ds": org.jboss.msc.service.StartException in service jboss.persistenceunit."login.war#test-ds": Failed to start service
  at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1767) [jboss-msc-1.0.2.GA.jar:1.0.2.GA]
  at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) [rt.jar:1.7.0_25]
  at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) [rt.jar:1.7.0_25]
  at java.lang.Thread.run(Thread.java:724) [rt.jar:1.7.0_25]
Caused by: java.lang.RuntimeException: error trying to scan <jar-file>: vfs:/content/login.war/WEB-INF/classes/
  at org.hibernate.ejb.Ejb3Configuration.scanForClasses(Ejb3Configuration.java:854)
  at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:596)
  at org.hibernate.ejb.HibernatePersistence.createContainerEntityManagerFactory(HibernatePersistence.java:72)
  at org.jboss.as.jpa.service.PersistenceUnitServiceImpl.createContainerEntityManagerFactory(PersistenceUnitServiceImpl.java:162)
  at org.jboss.as.jpa.service.PersistenceUnitServiceImpl.start(PersistenceUnitServiceImpl.java:85)
  at org.jboss.msc.service.ServiceControllerImpl$StartTask.startService(ServiceControllerImpl.java:1811) [jboss-msc-1.0.2.GA.jar:1.0.2.GA]
  at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1746) [jboss-msc-1.0.2.GA.jar:1.0.2.GA]
  ... 3 more
Caused by: java.lang.RuntimeException: JBAS011431: Could not load entity class 'br.com.sample.view.LoginTest$1' with PersistenceUnitInfo.getClassLoader()
  at org.jboss.as.jpa.hibernate4.HibernateAnnotationScanner.getPackagesInJar(HibernateAnnotationScanner.java:175)
  at org.hibernate.ejb.Ejb3Configuration.addScannedEntries(Ejb3Configuration.java:489)
  at org.hibernate.ejb.Ejb3Configuration.scanForClasses(Ejb3Configuration.java:851)
  ... 9 more
Caused by: java.lang.ClassNotFoundException: br.com.sample.view.LoginTest$1 from [Module "deployment.login.war:main" from Service Module Loader]
  at org.jboss.modules.ModuleClassLoader.findClass(ModuleClassLoader.java:190) [jboss-modules.jar:1.1.1.GA]
  at org.jboss.modules.ConcurrentClassLoader.performLoadClassUnchecked(ConcurrentClassLoader.java:468) [jboss-modules.jar:1.1.1.GA]
  at org.jboss.modules.ConcurrentClassLoader.performLoadClassChecked(ConcurrentClassLoader.java:456) [jboss-modules.jar:1.1.1.GA]
  at org.jboss.modules.ConcurrentClassLoader.performLoadClass(ConcurrentClassLoader.java:398) [jboss-modules.jar:1.1.1.GA]
  at org.jboss.modules.ConcurrentClassLoader.loadClass(ConcurrentClassLoader.java:120) [jboss-modules.jar:1.1.1.GA]
  at org.jboss.as.jpa.hibernate4.HibernateAnnotationScanner.getPackagesInJar(HibernateAnnotationScanner.java:171)
  ... 11 more

我的测试如下所示:

@RunWith(Arquillian.class)  
@WarpTest  
@RunAsClient  
public class LoginTest {  

  @Drone  
  private WebDriver browser;  

  @Page  
  private LoginPage loginPage;  


  @ArquillianResource  
  URL deploymentUrl;  


  @Deployment  
  public static WebArchive createDeployment() {  
  DatabaseUtils.createDatabase();  
  return Deployments.createDefaultDeployment();  
  }  

  private void insertDataAndGetLoginUrl() {  
  DatabaseUtils.setTestData("datasets/users.xml");  
  browser.get(deploymentUrl + "/login" + Constants.JSF_EXTENSION);  
  }  

  @Test  
  public void loginSuccessful() {  
  insertDataAndGetLoginUrl();  

  Warp.initiate(new Activity() {  
  @Override  
  public void perform() {  
  loginPage.login("admin", "Admin123");  

  }  
  });  

  String location = browser.getCurrentUrl();  


  assertThat(location, containsString("user/search" + Constants.JSF_EXTENSION));  
  }}  

在我的 pom 中,我有:

<dependency>
  <groupId>org.jboss.arquillian.extension</groupId>
  <artifactId>arquillian-warp-bom</artifactId>
  <version>1.0.0.Alpha4</version>
  <type>pom</type>
  <scope>import</scope>
</dependency>
<dependency>
  <groupId>org.jboss.arquillian.extension</groupId>
  <artifactId>arquillian-warp</artifactId>
  <version>1.0.0.Alpha4</version>
  <type>pom</type>
  <scope>test</scope>
</dependency>

有人可以帮忙吗?

4

2 回答 2

1

这里的问题是两个因素的组合:

  • Hibernate 扫描 web 存档中的类并且无法加载匿名类 Activity 并且失败(即使它应该忽略这样的失败 - 与 CDI/Weld 一样)

  • Warp 不会从包中删除活动

作为一种解决方法,我相信它可以帮助:archive.addClass(Activity.class)。

于 2013-10-09T13:05:34.683 回答
0

Arquillian 为每个测试做一个微部署,你需要加载所有测试需要运行的库、资源等。

在我的测试中,我使用了以下配置,并且运行良好:

@RunWith(Arquillian.class)
@DataSource("java:/analyticsTestDS")
@UsingDataSet("datasets/account/account-registration-activate.xml")
public class AccountRegistrationActivateServiceImplTest extends PostgresDBTestCase {


    @Deployment
    public static Archive<?> createTestArchive() {

        PomEquippedResolveStage pom = Maven.resolver().loadPomFromFile("pom.xml");
        File[] commonsLang = pom.resolve(
                "org.jadira.usertype:usertype.core",
                "org.hibernate:hibernate-validator",
                "edu.vt.middleware:vt-password",
                 "monetdb:monetdb-jdbc",
                "joda-time:joda-time"
        ).withTransitivity().asFile();

        WebArchive war = ShrinkWrap.create(WebArchive.class, "test.war")
                .addPackages(true, "com.atomsail.analytics.accounts")
                .addAsResource("META-INF/test-persistence.xml", "META-INF/persistence.xml")
                .addAsWebInfResource("ejb/account/account-registration-services-jboss-ejb3.xml", "jboss-ejb3.xml")
                .addAsWebInfResource("test-web.xml", "web.xml")
                .addAsResource("truncate_all_app.sql")
                .addAsLibraries(commonsLang);

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


        return war;
    }




@Test
@InSequence(1)
public void activationTest()  {



}

}

于 2016-10-07T14:39:24.223 回答