我有一个使用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>
有人可以帮忙吗?
答案 0 :(得分:1)
这里的问题是两个因素的结合:
Hibernate扫描web存档中的类,无法加载匿名类Activity并失败(即使它应该忽略这样的失败 - 与CDI / Weld一样)
Warp不会从包中删除活动
作为一种解决方法,我相信它可以帮助:archive.addClass(Activity.class)。
答案 1 :(得分:0)
Arquillian为每个测试进行微部署,需要加载所有测试需求才能运行.Libraries,resources等。
在我的测试中,我使用了以下配置,这一切都运行良好:
{
'work': list(work_queryset),
'holiday': list(holiday_queryset)
}
}