-
1. Re: Injecting Spring MVC Controller from .war included in the .ear into Arquillian test
jmnarloch Oct 8, 2013 12:22 PM (in response to kokovoj)Hi,
Sorry for late replay.
I admit that I didn't test such solution, but as far as I'm concerned the only requirement for the usage of @SpringWebConfiguration is to configure the ContextLoaderListener. You do not need to define your beans in it's scope, but it is mandatary for the integration to work correctly, without it the extension is not being able to access the ApplicationContext of the particular DispatcherServlet.
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>If it happens that you were using it in your application and nevertheless the test didn't work, would mind raising a JIRA (issues.jboss.org/browse/ARQ) issue for that?
-
2. Re: Injecting Spring MVC Controller from .war included in the .ear into Arquillian test
kokovoj Jan 7, 2014 3:35 PM (in response to kokovoj)Finally had time to go back to this issue.
The issue is solved (ie. largeController correctly injected into my test class, and not being null) by explicitly adding the test class itself into the .war included in the .ear. This works for both managed and embedded container types (I got it working with JBoss AS 4.2, JBoss AS 6.0). This is done by using below code
@RunWith(Arquillian.class)
@SpringWebConfiguration(servletName = "myservlet")
public class Test_JBoss_Managed_4_2_3
@Autowired
private LargeController largeController;
@OverProtocol( "Servlet 2.5" )
@Deployment
public static EnterpriseArchive createDeployment() {
// Create an Archive from the existing .ear build on the file system (not manually constructed in this method)
EnterpriseArchive ear = ShrinkWrap
.create( ZipImporter.class, "myLarge.ear" )
.importFrom( new File( "/Users/kokovoj/EarAndItsVariousComponents/An-Overall-EAR-folder/myLarge.ear" ) )
.as( EnterpriseArchive.class );
System.out.println( ear.toString( true ) );
// CRITICAL: For .ear deployments (ie. when this method returns EnterpriseArchive which gets deployed to JBoss)
// need to explicitly add this test class (ie. Test_JBoss_Managed_4_2_3) into the deployed artifact (ie. .war)
// so that it's visible during deployment.
WebArchive web = ear.getAsType( WebArchive.class, "myLarge-web.war" );
// Add this class (Test_JBoss_Managed_4_2_3) so that it will be included as part of the deployed .war (inside of an .ear).
web.addClasses(Test_JBoss_Managed_4_2_3.class );
return ear;
}
@Test
public void testControllerInjected() throws Exception {
assertNotNull( "largeController is invalid", largeController );
}