0

I'd like to write a unit (component) test for a REST resource of my web application. This test should target the exposed REST interface and test its behaviour by issuing requests and checking the responses.

The web application is configured without the use of web.xml and applicationContext.xml by making use of Spring's WebApplicationInitializer. This works fine when I just run the application on my (Tomcat) server.

When starting my Arquillian test, the ShrinkWrap archive is deployed on the embedded Tomcat server. As the embedded server runs with the classpath of my web application, it also finds my WebApplicationInitializer class. This is problematic, as it loads lots of dependencies, and should just be activated for the test.

How can I deactivate my WebApplicationInitializer (and provide an alternative implementation) in the test?

When using XML configuration files this corresponds to hiding the real configuration files and using a specific (empty?) configuration which is used in the test.

C-Otto
  • 4,941
  • 3
  • 25
  • 60

1 Answers1

0

I worked around this issue by just disabling my WebApplicationInitializer instance using a static field which I set in Arquillian's @Deployment method.

You might also want to look into metadata-complete which causes Tomcat to not invoke the Spring part which delegates to the WebApplicationInitializer instance.

C-Otto
  • 4,941
  • 3
  • 25
  • 60
  • Yep, this is one of the issues with using an embedded container. You could also use a managed / remote container. – LightGuard Sep 16 '15 at 21:45