jboss - Arquillian-未部署战争时未找到测试类
问题描述
我正在尝试使用 Arquillian 运行我的单元测试。我用 Maven 配置它,同时拥有 Wildfly 托管和远程服务器。运行测试后,服务器启动并部署我的战争。在部署它后立即取消部署并删除因 ClassNotFound 异常而产生的战争,我在堆栈跟踪下方提供:
19:46:23,101 INFO [org.jboss.as.repository] (management-handler-thread - 3) JBAS014900:内容添加在位置 /home/remotedev/QSDev2/app-qs/target/wildfly-8.2.1.Final /standalone/data/content/29/401e4f9cd9cff55c2a0cd817a4163817b4d7c4/content 19:46:23,172 INFO [org.jboss.as.server.deployment](MSC 服务线程 1-2) JBAS015876:开始部署“testwar.war”(运行时-名称:“testwar.war”) 19:46:25,769 WARN [org.jboss.weld.deployer](MSC 服务线程 1-1)JBAS016012:部署部署“testwar.war”包含 CDI 注释,但未找到 bean 存档(没有 beans.xml 或带有 bean 定义注释的类)。19:46:26,590 INFO [org.wildfly.extension.undertow](MSC 服务线程 1-2)JBAS017534:注册的 Web 上下文:/testwar 19:46:26,736 INFO [org.jboss.as.server] (management-handler-thread - 3) JBAS018559:部署“testwar.war”(运行时名称:“testwar.war”)2021-03-23 19:46:28 调试 nio:429 - 启动通道线程“远程处理“端点”I/O-1',选择器 sun.nio.ch.EPollSelectorImpl@ 381d206c 2021-03-23 19:46:28 调试 VersionedConectionFactory:173 - 可用版本(版本 0x00 0x01) 2021-03-23 19:46:28 调试 VersionedConectionFactory:179 - 调用稳定服务器 2021-03-23 19:46 :28 DEBUG VersionedConectionFactory:131 - 选择版本 0x00 以接收完整版本列表。2021-03-23 19:46:28 调试 VersionedConectionFactory:173 - 可用版本(版本 0x01 0x02) 2021-03-23 19:46:28 调试 VersionedConectionFactory:179 - 调用稳定服务器 2021-03-23 19:46: 28 DEBUG VersionedConectionFactory:194 - 服务器版本 2.0.0.Final 19:46:29,576 INFO [org.wildfly.extension.undertow](MSC 服务线程 1-2)JBAS017535:未注册的 Web 上下文:/testwar 19:46:29,678 INFO [org.hibernate.validator.internal.util.Version](MSC 服务线程 1-1)HV000001:Hibernate Validator 5.1.3.Final 19:46:30,504 INFO [org .jboss.as.server.deployment](MSC 服务线程 1-1)JBAS015877:在 945 毫秒内停止部署 testwar.war(运行时名称:testwar.war) 19:46:30,543 INFO [org.jboss.as.repository] (管理处理程序线程 - 3)J BAS014901:从位置 /home/remotedev/QSDev2/app-qs/target/wildfly-8.2.1.Final/standalone/data/content/29/401e4f9cd9cff55c2a0cd817a4163817b4d7c4/content 中删除的内容 19:46:30,551 INFO [org.jboss.as.server] (management-handler-thread - 3) JBAS018558: Undeployed "testwar.war" (runtime-name: "testwar.war") 测试运行:1,失败: 0,错误:1,跳过:0,经过的时间:24.115 秒 <<< 失败!testSaveLeaveRequest(com.maestro.application.authentication.util.PasswordStrengthTest) 经过时间:0.343 秒 <<< 错误!java.lang.ClassNotFoundException: com.maestro.application.authentication.util.PasswordStrengthTest [来自服务模块加载器的模块“deployment.testwar.war:main”]
我无法弄清楚为什么它在部署后取消部署战争。谁能帮我找出问题所在?(发布在 Arquillian 论坛,尚未回复http://discuss.arquillian.org/t/test-class-not-found-as-the-war-is-undeployed/656)。谢谢
--皮疹
最新更新 - 2021 年 4 月 7 日
现在出现以下异常,CNFE 消失了:
原因:java.lang.Exception: { "JBAS014671: Failed services" => {"jboss.deployment.unit."test.war".INSTALL" => "org.jboss.msc.service.StartException in service jboss. deployment.unit.“test.war”.INSTALL:JBAS018733:无法处理部署“test.war”的安装阶段 原因:org.jboss.as.server.deployment.DeploymentUnitProcessingException:JBAS011047:组件类 com.maestro.ejb组件 LeaveRequestLocalHome 的 .dao.EntityManagerProvider 有错误:JBAS011440:在部署“test.war”中找不到名为 optimizeOneDefaultPersistenceUnit 的持久性单元},“JBAS014771:缺少/不可用依赖项的服务”=> [“jboss.deployment.unit ."test.war".weld.weldClassIntrospector 丢失 [jboss.deployment.unit."test.战争".beanmanager]"] }
测试代码如下所示:
@RunWith(Arquillian.class)
public class PasswordStrengthTest {
@Deployment
public static JavaArchive createDeployment() {
return ShrinkWrap
.create(JavaArchive.class)
.addClasses(LeaveRequestLocal.class,
LeaveRequestLocalHome.class, LeaveRequestInfo.class,
LeaveRequestManagerBean.class,
LeaveRequestController.class, LeaveRequestBean.class,
EntityManagerProvider.class, JpaEntity.class,
MaestroEntityBean.class, MaestroValueObject.class,
JpaDaoBean.class, GenericDao.class,
SearchManagerException.class, MaestroException.class,
NoSuchLeaveRequestException.class,
MaestroExceptionDetails.class,
MaestroRuntimeException.class, TableParameters.class,
SearchParameters.class, PagedList.class)
.addAsManifestResource("META-INF/persistence.xml")
.addAsResource(EmptyAsset.INSTANCE, "beans.xml");
}
@Inject
private LeaveRequestManagerBean leaveRequestManagerBean;
@Inject
private LeaveRequestLocalHome leaveRequestLocalHome;
@Inject
private LeaveRequestController leaveRequestController;
@Test
public void testSaveLeaveRequest() throws Exception {
String name = "abc";
String requestDetails = "req1";
leaveRequestManagerBean = (LeaveRequestManagerBean) EJBUtil
.getLocalEJBManager("LeaveRequestManager");
LeaveRequestInfo leaveReuestInfo = leaveRequestManagerBean.add();
leaveReuestInfo.setName(name);
leaveReuestInfo.setRequestDetails(requestDetails);
leaveRequestManagerBean.update(leaveReuestInfo);
}
}
POM 如下所示:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.quickschools</groupId>
<artifactId>app-qs</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>app-qs</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<version.org.jboss.arquillian>1.1.5.Final</version.org.jboss.arquillian>
<version.org.wildfly>8.2.1.Final</version.org.wildfly>
<version.junit>4.11</version.junit>
</properties>
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<systemProperties>
<property>
<name>java.util.logging.config.file</name>
<value>log4j.properties</value>
</property>
</systemProperties>
</configuration>
</plugin>
</plugins>
</build>
<dependencyManagement>
<dependencies>
<!-- Arquillian BOM (Bill Of Materials). -->
<dependency>
<groupId>org.jboss.arquillian</groupId>
<artifactId>arquillian-bom</artifactId>
<version>1.1.5.Final</version>
<scope>import</scope>
<type>pom</type>
</dependency>
<!-- JUnit regression testing framework. -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
</dependency>
</dependencies>
</dependencyManagement>
<profiles>
<!-- Arquillian WildFly managed profile -->
<profile>
<id>arq-wildfly-managed</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<dependencies>
<dependency>
<groupId>org.wildfly</groupId>
<artifactId>wildfly-arquillian-container-managed</artifactId>
<version>${version.org.wildfly}</version>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>sun.jdk</groupId>
<artifactId>jconsole</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
<build>
<testResources>
<testResource>
<directory>src/test/resources</directory>
</testResource>
</testResources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>unpack</id>
<phase>process-test-classes</phase>
<goals>
<goal>unpack</goal>
</goals>
<configuration>
<artifactItems>
<artifactItem>
<groupId>org.wildfly</groupId>
<artifactId>wildfly-dist</artifactId>
<version>${version.org.wildfly}</version>
<type>zip</type>
<overWrite>false</overWrite>
<outputDirectory>${project.build.directory}</outputDirectory>
</artifactItem>
</artifactItems>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
<!-- Arquillian WildFly remote profile -->
<profile>
<id>arq-widlfly-remote</id>
<!-- <activation> <activeByDefault>true</activeByDefault> </activation> -->
<dependencies>
<dependency>
<groupId>org.wildfly</groupId>
<artifactId>wildfly-arquillian-container-remote</artifactId>
<version>${version.org.wildfly}</version>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>sun.jdk</groupId>
<artifactId>jconsole</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
</profile>
</profiles>
<dependencies>
<dependency>
<groupId>com.quickschools</groupId>
<artifactId>sms-core</artifactId>
<version>1.0</version>
<scope>system</scope>
<systemPath>/home/remotedev/mnt/sms2/build/ear/01sms.jar</systemPath>
</dependency>
<dependency>
<groupId>com.quickschools</groupId>
<artifactId>gengo</artifactId>
<version>1.0</version>
<scope>system</scope>
<systemPath>/home/remotedev/ProgramFiles/wildfly-12.0.0.Final/modules/com/quickschools/libs/main/gengo.jar</systemPath>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.17</version>
</dependency>
<dependency>
<groupId>javax.mail</groupId>
<artifactId>mail</artifactId>
<version>1.4.7</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.0.1</version>
<scope>provided</scope>
</dependency>
<!-- for arqillian -->
<dependency>
<groupId>javax.ejb</groupId>
<artifactId>ejb-api</artifactId>
<version>3.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.ejb</groupId>
<artifactId>javax.ejb-api</artifactId>
<version>3.2</version>
</dependency>
<dependency> <!-- for arqillian -->
<groupId>org.jboss.arquillian.junit</groupId>
<artifactId>arquillian-junit-container</artifactId>
<version>1.1.5.Final</version>
<!-- <version>1.6.0.Final</version> -->
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jboss.arquillian.protocol</groupId>
<artifactId>arquillian-protocol-servlet</artifactId>
<version>1.1.5.Final</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-jpamodelgen</artifactId>
<version>1.3.0.Final</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-all</artifactId>
<version>1.3</version>
</dependency>
<dependency>
<groupId>io.rest-assured</groupId>
<artifactId>rest-assured</artifactId>
<version>3.0.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-module-junit4</artifactId>
<version>1.6.5</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-api-mockito</artifactId>
<version>1.6.5</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-all</artifactId>
<version>1.9.5</version>
</dependency>
<dependency>
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
<version>2.2.11</version>
</dependency>
<dependency>
<groupId>com.sun.xml.bind</groupId>
<artifactId>jaxb-core</artifactId>
<version>2.2.11</version>
</dependency>
<dependency>
<groupId>com.sun.xml.bind</groupId>
<artifactId>jaxb-impl</artifactId>
<version>2.2.11</version>
</dependency>
<dependency>
<groupId>javax.activation</groupId>
<artifactId>activation</artifactId>
<version>1.1.1</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.9.8</version>
</dependency>
<dependency>
<groupId>javax.persistence</groupId>
<artifactId>javax.persistence-api</artifactId>
<version>2.2</version>
<scope>runtime</scope>
</dependency>
</dependencies>
</project>
谢谢
更新 09-04-2021 进行 了相应的更改,现在部署代码如下所示:
return ShrinkWrap
.create(JavaArchive.class)
.addClasses(LeaveRequestLocal.class,
LeaveRequestLocalHome.class, LeaveRequestInfo.class,
LeaveRequestManagerBean.class,
LeaveRequestController.class, LeaveRequestBean.class,
EntityManagerProvider.class, JpaEntity.class,
MaestroEntityBean.class, MaestroValueObject.class,
JpaDaoBean.class, GenericDao.class,
SearchManagerException.class, MaestroException.class,
NoSuchLeaveRequestException.class,
MaestroExceptionDetails.class,
MaestroRuntimeException.class, TableParameters.class,
SearchParameters.class, PagedList.class)
.addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml")
.addAsManifestResource("persistence.xml");
删除persistence.xml路径中的META-INF后,现在找不到了,显示异常如下:
原因:java.lang.IllegalArgumentException:persistence.xml 不存在或无法在 org.jboss.shrinkwrap 的 org.jboss.shrinkwrap.impl.base.Validate.notNull(Validate.java:43) 上访问。 org.jboss.shrinkwrap.impl.base.container.ContainerBase.addAsManifestResource(ContainerBase.java:683) 的 impl.base.container.ContainerBase.fileFromResource(ContainerBase.java:1966)
我尝试在 /resources/META-INF 和 /test/resources/META-INF 中保留 beans.xml 和 presistence.xml,哪个路径是正确的?谢谢
解决方案
推荐阅读
- javascript - 语法错误意外令牌} nodejs
- sql-server - 兼容模式允许新命令?
- excel - 在 Excel 列表中标记剩余匹配项
- r - R中按组的时间序列描述性统计
- python - 在 Gtk.Treeview 中设置我自己的拖动图标
- reporting-services - 如何在 SSRS 中使用 Lookup 表达式和 IIF 表达式?
- jpa - 更改 OPENJPA_SEQUENCE_TABLE 的默认名称
- c# - System.InvalidCastException “对象必须实现 IConvertible。” 使用 BinaryFormatter 反序列化字典时
- c# - 如何从 X509Certificate2 获取 RFC-1779 中的颁发者名称?
- angular - angular 5 多个路由器插座和子模块