5 Replies Latest reply on Jan 16, 2013 7:30 AM by kpiwko

    Getting Resource URL in Multi-Deployment Tests

    btsaunde

      We are trying to code some functional tests for our application and are running in to some issues developing the test. Essentially we have an application with several SOAP endpoints and we want to be able to deploy two or more of these Servers and have them communicate via the SOAP endpoints. We are able to create two deployments inside the test class, without a problem. Lets call them Deployment A and B. From inside our test case for Deployment A we are able to get the URL for Deployment A and call its SOAP endpoints, however, we can not figure our how to get the URL for Deployment B inside our test case that is written to operate on Deployment A. The reason we need the URL for B in the test case for A is because we need to pass it to our SOAP endpoint on Deployment A.

       

      I do not have our actual code with me, but here is some psuedo code of what we are trying to do.

       

      {code}

      @RunWith(Arquillian.class)

      public class TestClass {

               

                @Deployment(order = 1, name = "serverA")

                public static WebArchive createTestDeployment() { }


           @Deployment(order = 2, name = "serverB")

           public static WebArchive createTestDeployment2() { }


           @Test

                @OperateOnDeployment("serverA")

           @RunAsClient

                public void callServerA(@ArquillianResource serverAUrl) throws Exception {

                     // Call SOAP Endpoint

                     // Need the URL for serverB Here

           }

       

           @Test

                @OperateOnDeployment("serverB")

                @RunAsClient

                public void callActive1() throws Exception { }

      }

      {code}

        • 1. Re: Getting Resource URL in Multi-Deployment Tests
          kpiwko

          Hi Bryan,

           

          Aslak to confirm, but I think that's not possible without a workaround now. Can you file a JIRA for that feature at issues.jboss.org/browse/ARQ?

           

          The workaround would be similar to following:

           

           

          @RunWith(Arquillian.class)
          public class TestClass {
                    
               @Deployment(order = 1, name = "serverA")
               public static WebArchive createTestDeployment() { }
          
               @Deployment(order = 2, name = "serverB")
               public static WebArchive createTestDeployment2() { }
          
               private static URL deployment1URL; // note static, it is required here because JUnit creates new instance per test method
               private static URL deployment2URL; // note static, it is required here
          
               
               @Test
               @OperateOnDeployment("serverA")
               @RunAsClient
               @InSequence(1)
          
               public void getURLA(@ArquillianResource URL serverAUrl) throws Exception {
                   deployment1URL = serverAUrl;
               }
          
          
          
          
               @Test
               @OperateOnDeployment("serverB")
               @RunAsClient
               @InSequence(2)
          
               public void getURLB(@ArquillianResource URL serverBUrl) throws Exception {
                   deployment2URL = serverBUrl;
               }
          
          
          
             
          
               @Test
               @OperateOnDeployment("serverA")
               @RunAsClient
               @InSequence(3)
               public void callServerA() throws Exception {
                  // deployment1URL and deployment2URL are available here
               }
          
          }
          

           

          Regards,

           

          Karel

          • 2. Re: Getting Resource URL in Multi-Deployment Tests
            aslak

            You can use @OperatesOnDeployment as a Qualifier on the @ArquillianResource injection to 'cross' contexts.

             

            See the Container TCK for example: https://github.com/arquillian/arquillian-tck/blob/master/container/src/test/java/org/arquillian/tck/container/servlet_3_0/MultipleWebContextLookupMultiWarTestCase.java

            • 3. Re: Getting Resource URL in Multi-Deployment Tests
              kpiwko

              Pretty nice. Can the same qualifier be used for @Inject annotation as well?

              • 4. Re: Getting Resource URL in Multi-Deployment Tests
                aslak

                No. That would involve something like:

                 

                - override CDI injection in dep a

                - from dep a call to client

                  - from client call dep b

                  - from incontainer dep b lookup the Bean and serialize it back to the client

                  - from client responde to dep a with the serialized Bean from dep b

                  - from incontainer dep a inject deserialized bean

                 

                Possible.. but.. at this point you would have a new Bean from a different BeanManager in a different Deployment. Not sure why you would want that?

                • 5. Re: Getting Resource URL in Multi-Deployment Tests
                  kpiwko

                  ARQ-1255 would profit from that.