我正在尝试对植根于 JSF API 的数据模型执行 arquillian 测试。我收到此错误:
Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 0.046 sec <<< FAILURE!
initializationError(mypackage.GenericLazyModelTest) Time elapsed: 0.003 sec <<< ERROR!
java.lang.ClassFormatError: Absent Code attribute in method that is not native
or abstract in class file javax/faces/model/DataModel
简单的 arquillian 测试,不涉及 JSF,但 JPA 和 EJB API 运行良好。
对网络的研究表明,造成这种情况的一个常见原因是使用了此处和此处所述的 sun 的存根 EE API 。
我绝对不会使用它们。这是我的依赖部分pom
:
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.jboss.bom</groupId>
<artifactId>jboss-javaee-6.0-with-tools</artifactId>
<version>${javaee6.with.tools.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependency>
<groupId>javax.enterprise</groupId>
<artifactId>cdi-api</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.faces</groupId>
<artifactId>jsf-api</artifactId>
<version>2.1</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.jboss.spec.javax.annotation</groupId>
<artifactId>jboss-annotations-api_1.1_spec</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.jboss.spec.javax.ws.rs</groupId>
<artifactId>jboss-jaxrs-api_1.1_spec</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.hibernate.javax.persistence</groupId>
<artifactId>hibernate-jpa-2.0-api</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.jboss.spec.javax.ejb</groupId>
<artifactId>jboss-ejb-api_3.1_spec</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-validator</artifactId>
<version>4.2.0.Final</version>
<scope>provided</scope>
<exclusions>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-jpamodelgen</artifactId>
<version>1.1.1.Final</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.primefaces</groupId>
<artifactId>primefaces</artifactId>
<version>3.3.1</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
</dependency>
<dependency>
<groupId>org.jboss.arquillian.junit</groupId>
<artifactId>arquillian-junit-container</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jboss.arquillian.protocol</groupId>
<artifactId>arquillian-protocol-servlet</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jboss.shrinkwrap.resolver</groupId>
<artifactId>shrinkwrap-resolver-impl-maven</artifactId>
<scope>test</scope>
</dependency>
我还尝试使用内部 JBoss JSF API 进行测试,但对错误没有影响:
<dependency>
<groupId>org.jboss.spec.javax.faces</groupId>
<artifactId>jboss-jsf-api_2.1_spec</artifactId>
<version>2.0.0.Beta1</version>
<scope>test</scope>
</dependency>
我的模型来源于primefacesLazyDataModel
public class GenericLazyModel<T> extends LazyDataModel<T>
LazyDataModel
反过来又来源于javax.faces.model.DataModel
public abstract class LazyDataModel<T> extends DataModel<T> implements SelectableDataModel<T>, Serializable
测试大部分是空的,我要求注入我的模型并检查null
:
编辑ShrinkWrap 初始化现在包括faces-config.xml
stefanglase 提出的。虽然没有改变错误输出。
@RunWith(Arquillian.class)
public class GenericLazyModelTest {
@Deployment
public static Archive<?> createTestArchive() {
return ShrinkWrap
.create(WebArchive.class, "genericLazyModelTest.war")
.addClasses(GenericLazyModel.class, Submitter.class, SubmitterPK.class,
Ordering.class)
.addClasses(GenericDao.class, Resources.class)
.addAsResource("META-INF/persistence.xml", "META-INF/persistence.xml")
.addAsWebInfResource(new StringAsset("<faces-config version=\"2.0\"/>"), "faces-config.xml")
.addAsWebInfResource(EmptyAsset.INSTANCE, "beans.xml");
}
@Inject
GenericLazyModel<Submitter> model;
@Before
public void before() {
Assert.assertNotNull(model);
model.setKlazz(Submitter.class);
}
我在 Jboss 7.1.0.Final 上运行它。
关于可能是什么问题以及如何解决它的任何想法?
谢谢