我每次 运行 使用 Arquillian 进行测试时都会得到 "Error creating managed object for class: class org.jboss.weld.servlet.WeldListener"
I get "Error creating managed object for class: class org.jboss.weld.servlet.WeldListener" every time I run a test with Arquillian
我将 Eclipse Neon 用作 IDE 并且我在电脑上。我正在开发一个带有 primefaces 的网站,我想对我的 EJB 和 JPA 与数据库进行一些集成测试。
以下是一个简单测试的代码,包括在数据库中保存用户:
package test.integration.services;
import eu.unimib.srt.entities.User;
import eu.unimib.srt.services.UserRepositoryServiceBean;
import eu.unimib.srt.services.UserServiceBean;
import eu.unimib.srt.utilities.UserInfo;
import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.arquillian.junit.Arquillian;
import org.jboss.arquillian.junit.InSequence;
import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.asset.EmptyAsset;
import org.jboss.shrinkwrap.api.spec.JavaArchive;
import org.jboss.shrinkwrap.api.spec.WebArchive;
import org.junit.Test;
import org.junit.runner.RunWith;
import javax.ejb.EJB;
import javax.naming.NamingException;
import javax.persistence.criteria.CriteriaBuilder;
import static org.junit.Assert.*;
@RunWith(Arquillian.class)
public class UserRepositoryServiceBeanTest {
private static final String NOME_1 = "NomeUtente";
private static final String COGNOME_1 = "CognomeUtente";
private static final String USERNAME_1 = "srtUserTEST";
private static final String TELEFONO_1 = "023456789";
private static final String PASSWORD1 = "IloveArquillian";
private static final String COD_FISCALE_1 = "CDCFSC41E00W000W";
private static final String EMAIL_1 = "nome.cognome@arquillian.org";
private static UserInfo DBUSER_1 = null;
static {
DBUSER_1 = new UserInfo(NOME_1, COGNOME_1, USERNAME_1, TELEFONO_1, PASSWORD1, COD_FISCALE_1, EMAIL_1, null);
}
@Deployment
public static JavaArchive createDeployment() {
JavaArchive jar = ShrinkWrap.create(JavaArchive.class)
.addAsResource("test-persistence.xml", "META-INF/persistence.xml")
.addClass(UserRepositoryServiceBean.class)
.addPackage(User.class.getPackage())
.addClass(UserInfo.class)
.addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml");
System.out.println(jar.toString(true));
return jar;
}
@EJB
private UserRepositoryServiceBean ursb;
@Test
@InSequence(1)
public void addUserTest() throws NamingException {
ursb.addUser(DBUSER_1, PASSWORD1);
}
@Test
@InSequence(2)
public void verifyBindTest() {
boolean userFound = ursb.verifyBind(USERNAME_1,PASSWORD1);
assertTrue(userFound);
}
@Test
@InSequence(3)
public void removeUserTest() throws NamingException {
ursb.removeUser(USERNAME_1);
}
}
persistence.xml如下:
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.1"
xmlns="http://xmlns.jcp.org/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd">
<persistence-unit name="SRTPersistenceUnit"
transaction-type="JTA">
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
<jta-data-source>jdbc/SRT16DataSource</jta-data-source>
<class>eu.unimib.srt.entities.TestEntity</class>
<class>eu.unimib.srt.entities.Automobile</class>
<class>eu.unimib.srt.entities.Varco</class>
<class>eu.unimib.srt.entities.Sanzione</class>
<class>eu.unimib.srt.entities.Guidatore</class>
<properties>
<property name="eclipselink.ddl-generation" value="create-or-extend-tables" />
<property name="eclipselink.ddl-generation.output-mode"
value="database" />
</properties>
</persistence-unit>
</persistence>
测试-persistence.xml如下:
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.1"
xmlns="http://xmlns.jcp.org/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd">
<persistence-unit name="SRTPersistenceUnit"
transaction-type="JTA">
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
<jta-data-source>jdbc/arquillian</jta-data-source>
<properties>
<property name="eclipselink.ddl-generation" value="drop-and-create-tables"/>
<property name="eclipselink.logging.level.sql" value="FINE"/>
<property name="eclipselink.logging.parameters" value="true"/>
</properties>
</persistence-unit>
</persistence>
我得到以下异常:
...
bla bla bla
...
org.jboss.arquillian.test.impl.EventTestRunnerAdaptor.beforeClass(EventTestRunnerAdaptor.java:87)
at org.jboss.arquillian.junit.Arquillian.evaluate(Arquillian.java:201)
at org.jboss.arquillian.junit.Arquillian.multiExecute(Arquillian.java:426)
at org.jboss.arquillian.junit.Arquillian.access0(Arquillian.java:54)
at org.jboss.arquillian.junit.Arquillian.evaluate(Arquillian.java:218)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.jboss.arquillian.junit.Arquillian.run(Arquillian.java:166)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:86)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:678)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)
set 08, 2016 5:25:55 PM org.glassfish.api.ActionReport failure
GRAVE: Exception while loading the app
set 08, 2016 5:25:55 PM com.sun.enterprise.web.WebContainer unloadWebModule
GRAVE: Undeployment failed for context /test
set 08, 2016 5:25:55 PM org.glassfish.deployment.admin.DeployCommand execute
GRAVE: Exception while loading the app : java.lang.IllegalStateException: ContainerBase.addChild: start: org.apache.catalina.LifecycleException: java.lang.IllegalArgumentException: javax.servlet.ServletException: com.sun.enterprise.container.common.spi.util.InjectionException: Error creating managed object for class: class org.jboss.weld.servlet.WeldListener
PlainTextActionReporterFAILUREApplication test is not deployed on this target [server]JdbcRuntimeExtension, getAllSystemRAResourcesAndPools = [GlassFishConfigBean.org.glassfish.jdbc.config.JdbcResource, GlassFishConfigBean.org.glassfish.jdbc.config.JdbcResource, GlassFishConfigBean.org.glassfish.jdbc.config.JdbcConnectionPool, GlassFishConfigBean.org.glassfish.jdbc.config.JdbcConnectionPool, GlassFishConfigBean.org.glassfish.jdbc.config.JdbcConnectionPool, GlassFishConfigBean.org.glassfish.jdbc.config.JdbcResource]
set 08, 2016 5:26:06 PM com.sun.enterprise.v3.server.AppServerStartup stop
INFORMAZIONI: Shutdown procedure finished
问题是当我使用 Arquillian 进行测试时,Glassfish 的一个实例在后台 运行。解决方案是:
cd C:\Program Files\Glassfish4\bin
asadmin stop-domain domain1
...succesfull
注意,使用arquillian时,glassfish是否已经运行
我将 Eclipse Neon 用作 IDE 并且我在电脑上。我正在开发一个带有 primefaces 的网站,我想对我的 EJB 和 JPA 与数据库进行一些集成测试。
以下是一个简单测试的代码,包括在数据库中保存用户:
package test.integration.services;
import eu.unimib.srt.entities.User;
import eu.unimib.srt.services.UserRepositoryServiceBean;
import eu.unimib.srt.services.UserServiceBean;
import eu.unimib.srt.utilities.UserInfo;
import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.arquillian.junit.Arquillian;
import org.jboss.arquillian.junit.InSequence;
import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.asset.EmptyAsset;
import org.jboss.shrinkwrap.api.spec.JavaArchive;
import org.jboss.shrinkwrap.api.spec.WebArchive;
import org.junit.Test;
import org.junit.runner.RunWith;
import javax.ejb.EJB;
import javax.naming.NamingException;
import javax.persistence.criteria.CriteriaBuilder;
import static org.junit.Assert.*;
@RunWith(Arquillian.class)
public class UserRepositoryServiceBeanTest {
private static final String NOME_1 = "NomeUtente";
private static final String COGNOME_1 = "CognomeUtente";
private static final String USERNAME_1 = "srtUserTEST";
private static final String TELEFONO_1 = "023456789";
private static final String PASSWORD1 = "IloveArquillian";
private static final String COD_FISCALE_1 = "CDCFSC41E00W000W";
private static final String EMAIL_1 = "nome.cognome@arquillian.org";
private static UserInfo DBUSER_1 = null;
static {
DBUSER_1 = new UserInfo(NOME_1, COGNOME_1, USERNAME_1, TELEFONO_1, PASSWORD1, COD_FISCALE_1, EMAIL_1, null);
}
@Deployment
public static JavaArchive createDeployment() {
JavaArchive jar = ShrinkWrap.create(JavaArchive.class)
.addAsResource("test-persistence.xml", "META-INF/persistence.xml")
.addClass(UserRepositoryServiceBean.class)
.addPackage(User.class.getPackage())
.addClass(UserInfo.class)
.addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml");
System.out.println(jar.toString(true));
return jar;
}
@EJB
private UserRepositoryServiceBean ursb;
@Test
@InSequence(1)
public void addUserTest() throws NamingException {
ursb.addUser(DBUSER_1, PASSWORD1);
}
@Test
@InSequence(2)
public void verifyBindTest() {
boolean userFound = ursb.verifyBind(USERNAME_1,PASSWORD1);
assertTrue(userFound);
}
@Test
@InSequence(3)
public void removeUserTest() throws NamingException {
ursb.removeUser(USERNAME_1);
}
}
persistence.xml如下:
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.1"
xmlns="http://xmlns.jcp.org/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd">
<persistence-unit name="SRTPersistenceUnit"
transaction-type="JTA">
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
<jta-data-source>jdbc/SRT16DataSource</jta-data-source>
<class>eu.unimib.srt.entities.TestEntity</class>
<class>eu.unimib.srt.entities.Automobile</class>
<class>eu.unimib.srt.entities.Varco</class>
<class>eu.unimib.srt.entities.Sanzione</class>
<class>eu.unimib.srt.entities.Guidatore</class>
<properties>
<property name="eclipselink.ddl-generation" value="create-or-extend-tables" />
<property name="eclipselink.ddl-generation.output-mode"
value="database" />
</properties>
</persistence-unit>
</persistence>
测试-persistence.xml如下:
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.1"
xmlns="http://xmlns.jcp.org/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd">
<persistence-unit name="SRTPersistenceUnit"
transaction-type="JTA">
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
<jta-data-source>jdbc/arquillian</jta-data-source>
<properties>
<property name="eclipselink.ddl-generation" value="drop-and-create-tables"/>
<property name="eclipselink.logging.level.sql" value="FINE"/>
<property name="eclipselink.logging.parameters" value="true"/>
</properties>
</persistence-unit>
</persistence>
我得到以下异常:
...
bla bla bla
...
org.jboss.arquillian.test.impl.EventTestRunnerAdaptor.beforeClass(EventTestRunnerAdaptor.java:87)
at org.jboss.arquillian.junit.Arquillian.evaluate(Arquillian.java:201)
at org.jboss.arquillian.junit.Arquillian.multiExecute(Arquillian.java:426)
at org.jboss.arquillian.junit.Arquillian.access0(Arquillian.java:54)
at org.jboss.arquillian.junit.Arquillian.evaluate(Arquillian.java:218)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.jboss.arquillian.junit.Arquillian.run(Arquillian.java:166)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:86)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:678)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)
set 08, 2016 5:25:55 PM org.glassfish.api.ActionReport failure
GRAVE: Exception while loading the app
set 08, 2016 5:25:55 PM com.sun.enterprise.web.WebContainer unloadWebModule
GRAVE: Undeployment failed for context /test
set 08, 2016 5:25:55 PM org.glassfish.deployment.admin.DeployCommand execute
GRAVE: Exception while loading the app : java.lang.IllegalStateException: ContainerBase.addChild: start: org.apache.catalina.LifecycleException: java.lang.IllegalArgumentException: javax.servlet.ServletException: com.sun.enterprise.container.common.spi.util.InjectionException: Error creating managed object for class: class org.jboss.weld.servlet.WeldListener
PlainTextActionReporterFAILUREApplication test is not deployed on this target [server]JdbcRuntimeExtension, getAllSystemRAResourcesAndPools = [GlassFishConfigBean.org.glassfish.jdbc.config.JdbcResource, GlassFishConfigBean.org.glassfish.jdbc.config.JdbcResource, GlassFishConfigBean.org.glassfish.jdbc.config.JdbcConnectionPool, GlassFishConfigBean.org.glassfish.jdbc.config.JdbcConnectionPool, GlassFishConfigBean.org.glassfish.jdbc.config.JdbcConnectionPool, GlassFishConfigBean.org.glassfish.jdbc.config.JdbcResource]
set 08, 2016 5:26:06 PM com.sun.enterprise.v3.server.AppServerStartup stop
INFORMAZIONI: Shutdown procedure finished
问题是当我使用 Arquillian 进行测试时,Glassfish 的一个实例在后台 运行。解决方案是:
cd C:\Program Files\Glassfish4\bin
asadmin stop-domain domain1
...succesfull
注意,使用arquillian时,glassfish是否已经运行