我尝试使用默认可见性测试方法。测试和方法的类在同一个包中,如果我将访问修饰符更改为public
,它就可以工作。
我检查了生成的war文件以确定包名称,两者都是相同的。
例外:
org.jboss.arquillian.test.spi.ArquillianProxyException: org.jboss.weld.exceptions.WeldException : Class org.jboss.weld.util.reflection.Reflections can not access a member of class mypackage.CertificateService with modifiers "" [Proxied because : Original exception caused: class java.lang.ClassNotFoundException: org.jboss.weld.exceptions.WeldException]
所以,我的服务方法是这样的:
// CertificateService
@Inject
private CertificateRepository repository;
CertificateDTO createOrUpdate(final CertificateDTO dto, LocalDate date) {
repository.createOrUpdate(dto,date);
}
在我的 IT 课程中:
// CertificateServiceIT
@Inject
private CertificateRepository repository;
@Deployment
public static Archive<?> createDeployment() {
return Deployments.createWarDeployment(CertificateServiceIT.class.getSimpleName());
}
@Test (expected = BusinessException.class)
@Transactional(TransactionMode.ROLLBACK)
public void CertificateServiceITTest001() throws Exception {
...
repository.createOrUpdate(dto, localdate);
}
班级部署:
public static WebArchive createWarDeployment(final String packageId) {
final WebArchive war = DeploymentUtil.createWarDeployment(packageId,
"myPackage:model",
"myPackage:my-commons-keycloak");
final File modelJar = Maven.resolver().loadPomFromFile("pom.xml")
.resolve("myPackage:model")
.withoutTransitivity().asSingle(File.class);
final JavaArchive modelArchive = ShrinkWrap.create(ZipImporter.class, "model.jar")
.importFrom(modelJar).as(JavaArchive.class);
modelArchive.delete("META-INF/persistence.xml");
return war.addPackages(true, "myPackage.business")
.addPackages(true, "myPackage.api")
.addAsLibraries(modelArchive)
.addAsWebInfResource("jboss-deployment-structure.xml")
.addAsWebInfResource("META-INF/ejb-jar.xml", "ejb-jar.xml")
.addAsResource("test-persistence.xml", "META-INF/persistence.xml")
.addAsResource("Messages.properties")
.addAsResource("META-INF/beans.xml")
.addAsResource("certificate01.p12")
.addAsResource("certificate02.pfx");
}
两个类( CertificateService 和 CertificateServiceIT )都部署在同一个包中。
有什么想法吗?