简体   繁体   English

嵌入Arquillian Spring Tomcat 7-模拟@Configuration类

[英]Arquillian Spring Tomcat 7 embedded - mock @Configuration class

I'm working on a multi-module maven project, and I'm trying to integrate arquillian in it to ease development and create some integration tests. 我正在开发一个多模块Maven项目,并且正在尝试将Arquillian集成到其中,以简化开发并创建一些集成测试。 I'm using Tomcat 7 embedded, and I got to a point where everything works. 我使用的是嵌入式Tomcat 7,现在一切正常。 Now I want one of the classes that are injected in a service to be mocked. 现在,我希望模拟服务中注入的类之一。 When I'm debugging (using Intellij Idea) everything seems to be working nice... my test @Configuration class (ApplicationConfig2) is added to the WAR, it injects a Dummy object which is later used by the service. 当我调试(使用Intellij Idea)时,一切似乎都正常工作...将我的测试@Configuration类(ApplicationConfig2)添加到WAR中,它注入了一个Dummy对象,该对象稍后由服务使用。 The problem is when running the same test using maven (clean install) (surefire plugin) it tells me an error occurred. 问题是使用maven(全新安装)(surefire插件)运行相同的测试时,它告诉我发生了错误。 Here's my deployment: 这是我的部署:

@Deployment(testable = false)
public static WebArchive createTestArchive() {
    File[] files = Maven.resolver()
            .offline()
            .loadPomFromFile("pom.xml")
            .resolve("org.glassfish.jersey.containers:jersey-container-servlet-core:2.6",
                    "com.fasterxml.jackson.jaxrs:jackson-jaxrs-json-provider:2.3.1"
            )
            .withTransitivity()
            .asFile();

    return ShrinkWrap
            .create(WebArchive.class, "ROOT.war")
            .addClass(Controller.class)
            .addClass(Service.class)
            .addClass(SomeObjectInterface.class)
            .addClass(MockedSomeObjectImpl.class)
            .addClass(MyApplication2.class)
            .addClass(ApplicationConfig2.class)
            .addClass(MyWebAppInitializer2.class)
            .addAsLibraries(files)
            .setWebXML("in-container-web.xml");
}

Here's my web app initializer used in tests: 这是我在测试中使用的网络应用初始化程序:

@Order(Integer.MIN_VALUE)
public class MyWebAppInitializer2 implements WebApplicationInitializer {...}

I have another one named MyWebAppInitializer which is used by the "real" WAR module. 我还有一个名为MyWebAppInitializer的文件,由“真实” WAR模块使用。

The error that I get is : 我得到的错误是:

INFO: Spring WebApplicationInitializers detected on classpath: [foo.MyWebAppInitializer@1e194cf1, foo.MyWebAppInitializer2@f0a71a7, org.glassfish.jersey.server.spring.SpringWebApplicationInitializer@76ab92a7]
Aug 11, 2015 4:50:34 PM org.apache.catalina.core.ApplicationContext log

So, for some reason, even if I don't include the class MyWebAppInitializer in the web archive, it seems it is loaded by Tomcat even the same. 因此,由于某种原因,即使我没有在Web归档文件中包含类MyWebAppInitializer,它似乎也是由Tomcat加载的。 I'm checking the generated WAR package, and the only class present is MyWebAppInitializer2 (the testing one), and not MyWebAppInitializer. 我正在检查生成的WAR包,并且当前存在的唯一类是MyWebAppInitializer2(正在测试的类),而不是MyWebAppInitializer。

Am I missing something? 我想念什么吗?

从我发现的结果来看,没有人可以使用嵌入式容器,因为它们不可靠。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM