Arquillian热缩包装 [英] Arquillian ShrinkWrap

查看:112
本文介绍了Arquillian热缩包装的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在使用pom.xml依赖关系创建JUnit测试时遇到了麻烦.

I'm having trouble creating a JUnit test using a pom.xml dependency.

正在与Arquillian一起进行测试

The test are being run with Arquillian

@RunWith(Arquillian.class)

@RunWith(Arquillian.class)

在这种方法中

@Deployment
public static JavaArchive createDeployment() {

首先,我使用要测试的项目的软件包创建一个JavaArchive

First, I create a JavaArchive with the package of the project I'm testing

   JavaArchive merge =  ShrinkWrap.create(JavaArchive.class).
            addPackages(true,
                    "migrazioneGeaPersistenzaTampone",
                    "migrazioneGeaPersistenza",
                    "it.**.mistral.importGEA4.task",
                    "migrazioneGeaPersistenzaAccess"
            ).
           addClasses(java.sql.Connection.class)
            .addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml");

然后,当我启动测试时,缺少一些依赖项

Then when I launch the test, there are some missing dependencies

Unable to resolve any beans for Types: [class it.**.**.be.service.EnvironmentRootService]

存在于此依赖项

      <dependency>
        <groupId>it.**.mistral</groupId>
        <artifactId>mistral-be</artifactId>
        <version>0.1.0</version>
        <scope>compile</scope>  
     </dependency>

我已经尝试了许多其他方法来添加这些依赖项,最好的似乎是使用ShrinkWrap解析器(

I have tried lots of different things to add these dependencies, the best one seems to be using the ShrinkWrap Resolvers (https://github.com/shrinkwrap/resolver/blob/master/README.asciidoc, particullarry this paragraph https://github.com/shrinkwrap/resolver/blob/master/README.asciidoc#resolution-of-artifacts-defined-in-pom-files)

a)

JavaArchive []存档= Maven.resolver().loadPomFromFile(path_to_pom_file). importDependencies(ScopeType.TEST,ScopeType.COMPILE). resolve().withTransitivity().as(JavaArchive.class);

JavaArchive[] archives = Maven.resolver().loadPomFromFile(path_to_pom_file). importDependencies(ScopeType.TEST,ScopeType.COMPILE). resolve().withTransitivity().as(JavaArchive.class);

Maven.resolver().loadPomFromFile("/path/to/pom.xml").importRuntimeDependencies() .resolve().withTransitivity().asFile();

Maven.resolver().loadPomFromFile("/path/to/pom.xml").importRuntimeDependencies() .resolve().withTransitivity().asFile();

以任何一种方式都将忽略依赖项(我缺少了什么?)

The dependency is ignored in either way (i'm missing something?)

b)

JavaArchive [] mistral_be = Maven.configureResolver(). workOffline (). resolve("it.**.mistral:mistral-be:0.1.0").withTransitivity().as(JavaArchive.class);
for(int i = 0; i< mistral_be.length; i ++){
merge = merge.merge(mistral_be [i]);
}

JavaArchive[] mistral_be = Maven.configureResolver().workOffline(). resolve("it.**.mistral:mistral-be:0.1.0").withTransitivity().as(JavaArchive.class);
for (int i = 0; i < mistral_be.length ; i++) {
merge = merge.merge(mistral_be[i]);
}

简单的

System.out.println(merge.toString(true));

我可以看到依赖项中的所有文件都存在!无论如何,我使用本地存储库 workoffline () 也许我缺少一些依赖项?

I can see that all files from dependencies are present! Anyway I use local repository workoffline() Maybe I am missing some dependencies?

但是用a退出方法

return merge;

引发"java.lang.NoClassDefFoundError:com/google/protobuf/GeneratedMessage....由以下原因引起:java.lang.ClassNotFoundException:com.google.protobuf.GeneratedMessage"错误.

throws a "java.lang.NoClassDefFoundError: com/google/protobuf/GeneratedMessage....Caused by: java.lang.ClassNotFoundException: com.google.protobuf.GeneratedMessage" error.

然后我再次尝试添加缺少的依赖项

Then again i tried to add the missing dependecies

//尝试添加protobuf依赖项 JavaArchive [] prto_buf = Maven.configureResolver().withMavenCentralRepo(true).resolve("com.google.protobuf:protobuf-java:2.3.0").withTransitivity().as(JavaArchive.class);

// Tryn'g to add protobuf dependencies JavaArchive[] prto_buf = Maven.configureResolver().withMavenCentralRepo(true).resolve("com.google.protobuf:protobuf-java:2.3.0").withTransitivity().as(JavaArchive.class);

       for (int i = 0; i < prto_buf.length ; i++) {
           projectPackages = projectPackages.merge(prto_buf[i]);
       }

引发sameException ... 再次,用一个简单的

Throws sameException... Again , with a simple

System.out.println(merge.toString(true));

我可以看到com.Google.protobuf.GeneratedMessage存在

I can see that com.Google.protobuf.GeneratedMessage is present

依赖项提取:

   <dependency>
        <groupId>org.jboss.spec</groupId>
        <artifactId>jboss-javaee-6.0</artifactId>
        <version>1.0.0.Final</version>
        <type>pom</type>
        <scope>provided</scope>
    </dependency>

    <dependency>
        <groupId>org.jboss.arquillian.junit</groupId>
        <artifactId>arquillian-junit-container</artifactId>
        <scope>test</scope>
    </dependency>

    <dependency>
        <groupId>org.jboss.arquillian.container</groupId>
        <artifactId>arquillian-weld-ee-embedded-1.1</artifactId>
        <version>1.0.0.CR3</version>
        <scope>test</scope>
    </dependency>

    <dependency>
        <groupId>org.jboss.shrinkwrap.resolver</groupId>
        <artifactId>shrinkwrap-resolver-depchain</artifactId>
        <version>2.1.0</version>
        <scope>test</scope>
    </dependency>


</dependencies>


<dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>org.jboss.arquillian</groupId>
            <artifactId>arquillian-bom</artifactId>
            <version>1.1.5.Final</version>
            <scope>import</scope>
            <type>pom</type>
        </dependency>
    </dependencies>
</dependencyManagement>

有人可以帮我解决这个问题吗?

Can anybody help me solve this issue?

推荐答案

在我看来,这就像类加载问题.尤其要考虑到您正在使用嵌入式容器的事实,该容器基本上从项目类路径中获取其中的所有内容.

This smells to me like a classloading issue. Especially considering the fact that you are using embedded container which basically takes everything what's in there from your project classpath.

您要在其上部署应用程序的目标容器是什么?也许,如果您尝试在此处而不是嵌入式容器中运行测试,则至少会看到这是否确实是问题所在,或者您的部署工件仍然存在问题.

What is your target container you are deploying your application on? Maybe if you try to run your test there instead of embedded container you will at least see if that is really the problem, or there is still something wrong with your deployment artifact.

这篇关于Arquillian热缩包装的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆