0 Replies Latest reply on Nov 5, 2014 5:24 PM by Eric George

    Difficulty with Spring Autowiring in TestNG Arquillian test

    Eric George Newbie

      I have an Arquillian TestNG test that needs an autowired spring element in order to test spring security authentication.  For some reason, the auto wiring does not seem to be working, though.  I know that Arquillian is building the components because I can see their traces in the log, but the injection just isn't happening.

       

      I am testing an ear-deployed application with Wildfly 8.1, and the deployment and injection for ordinary EJBs works fine, but not the spring injection.

       

      What am I doing wrong here?

       

       

      My application context looks like this:

      <beans:bean class="foo.bar.CustomApacheDSConfigurator">

        <beans:constructor-arg value="/tmp/apache-ds-test/" />

        <beans:constructor-arg type="java.lang.Integer"  value="44489" />

      </beans:bean>

       

      <ldap-server ldif="classpath:/myusers.ldif"  root="dc=bar,dc=foo" />

      <ldap-server id="testLdapServer" url="ldap://localhost:44489/dc=bar,dc=foo" />

       

      <beans:bean id='testUserDetailsContextMapper' class="foo.bar.UserService" >

             <beans:constructor-arg value="ldap://localhost:44489" />

      </beans:bean>

       

      <authentication-manager alias="testAuthMan" erase-credentials="false">

      <ldap-authentication-provider server-ref="testLdapServer"

            user-search-filter="(uid={0})" group-search-filter="(uniqueMember={0})"

            user-context-mapper-ref="testUserDetailsContextMapper" />

      </authentication-manager>


      My test looks like this:


      @SpringConfiguration("applicationContext.xml")

      public class AuthenticatedTest extends Arquillian {

           @Autowired

            // @Qualifier("testAuthMan") //I have tried with and without this

           AuthenticationManager am;

       

            @Deployment

           public static EnterpriseArchive createDeployment() {

                  // Create EAR with all the libs.

                  EnterpriseArchive ear = ShrinkWrap.create(EnterpriseArchive.class, "FooBar.ear");

                  // packaging of app code omitted.

       

                  // Build the Jar with the tests and the applicationContext.xml

                  JavaArchive testEjb =  ShrinkWrap.create(JavaArchive.class, "testEjb.jar").merge(

                       ShrinkWrap.create(GenericArchive.class)

                            .as(ExplodedImporter.class).importDirectory("target/test-classes")

                            .as(GenericArchive.class));

                  ear.addAsModule(testEjb);

       

                  WebArchive war = ShrinkWrap.create(WebArchive.class, "test.war");

                  ear.addAsModule(Testable.archiveToTest(war));


                 return ear;

          }


          @Test

          public void testAuthManWired() {

             System.out.println("Testing Autowiring");

             AssertJUnit.assertNotNull("AuthenticationManager not available", am);

          }

      }

       

      My pom looks like this:

       

      <dependencies>

        <dependency>

             <groupId>org.testng</groupId>

             <artifactId>testng</artifactId>

             <version>6.8.8</version>

        </dependency>

       

        <dependency>

             <groupId>org.jboss.arquillian.testng</groupId>

             <artifactId>arquillian-testng-container</artifactId>

             <version>1.1.5.Final</version>

        </dependency>

        <dependency>

             <groupId>org.wildfly</groupId>

             <artifactId>wildfly-arquillian-testng-integration</artifactId>

             <version>8.1.0.Final</version>

        </dependency>

       

        <dependency>

             <groupId>org.jboss.spec</groupId>

             <artifactId>jboss-javaee-all-7.0</artifactId>

             <version>1.0.1.Final</version>

        </dependency>

        <dependency>

             <groupId>org.wildfly</groupId>

             <artifactId>wildfly-arquillian-container-managed</artifactId>

             <version>8.1.0.Final</version>

        </dependency>

       

        <dependency>

             <groupId>org.jboss.arquillian.extension</groupId>

             <artifactId>arquillian-service-integration-spring-inject</artifactId>

             <version>1.0.0.Beta3</version>

        </dependency>

        <dependency>

             <groupId>org.jboss.arquillian.extension</groupId>

             <artifactId>arquillian-service-deployer-spring-3</artifactId>

             <version>1.0.0.Beta3</version>

        </dependency>

        <dependency>

             <groupId>org.jboss.arquillian.extension</groupId>

             <artifactId>arquillian-service-integration-spring</artifactId>

             <version>1.0.0.Beta3</version>

        </dependency>

      </dependencies>

       

      My arquillian.xml looks like this:

      <extension qualifier="spring-deployer"> <!-- I am not sure if this is right or even necessary -->

           <property name="springVersion">3.0.0.RELEASE</property>

      </extension>   

      <container qualifier="jbossas-managed" default="true">

           <configuration>

               <property name="jbossHome">/myhome/wildfly-8.1.0.Final</property>

           </configuration>

      </container>