简体   繁体   中英

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. I'm using Tomcat 7 embedded, and I got to a point where everything works. 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. The problem is when running the same test using maven (clean install) (surefire plugin) it tells me an error occurred. 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.

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. I'm checking the generated WAR package, and the only class present is MyWebAppInitializer2 (the testing one), and not MyWebAppInitializer.

Am I missing something?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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