4 Replies Latest reply on Jul 20, 2012 11:00 AM by Julien Viet

    Dynamic deployment URL

    Julien Viet Apprentice

      Hi,

       

      I am trying to use the Arquillian Deployer but it's quite not easy to get an URL for the deployment. I think the main issue is that I want to have my test to follow this pattern:

       

       

      public class MyTestCase {
      
         @Deployment(testable = false, managed = false, name = "my") public static WebArchive create() { ... }
         @ArquillianResource Deployer deployer;
      
         @Test
         public void testA() {
            deployer.deploy("my");
            URL url = ....
            deployer.undeploy("my");
         }
      }
      

       

      I think the main issue is that the URL cannot be known until the deployment is performed and therefore it cannot be injected as an @ArquillianResource URL .

       

      Of course this is a simplified view of my use case.

       

      Is it possible to make it work ?

       

      Julien

        • 1. Re: Dynamic deployment URL
          Aslak Knutsen Master

          Your summary is correct. A URL injection is not proxied in any way, so it needs to be known before injection.

           

          A workaround would be to split up the scenario in multiple Test methods, by makeing the Test Class the full scenario not the Test method and use Test Method Argument injection. e.g. :

           

           

          public class MyTestCase {
          
             @Deployment(testable = false, managed = false, name = "my") public static WebArchive create() { ... }
          
             @ArquillianResource Deployer deployer;
          
             @Test @InSequence(1)
             public void manualDeploy() {
                deployer.deploy("my");
             }
          
          
             @Test @InSequence(2)
             public void shouldXXX(@ArquillianResource URL url) {
                doStuffWith(url)
             }
          
          
             @Test @InSequence(3)
             public void manualUnDeploy() {
                deployer.undeploy("my");
             }
          }
          
          

           

           

          A manual ArquillianResource API has been dicussed, but not currenlty implemented. That would allow for something like:

           

          public class MyTestCase {
          
             @Deployment(testable = false, managed = false, name = "my") public static WebArchive create() { ... }
          
             @ArquillianResource Deployer deployer;
          
             @ArquillianResource ArquillianResources resources;
          
             @Test
             public void shouldXXX() {
                deployer.deploy("my");
          
                URL url = resources.lookup(URL.class)
          
                deployer.undeploy("my");
             }
          }
          
          
          • 2. Re: Dynamic deployment URL
            Julien Viet Apprentice

            what about modifying Deployer and do : "URL deploy(java.lang.String s);" that simply returns the URL that was deployed ?

             

            it would allow me to do:

             

            URL deploymentURL = deployer.deploy("my");

            • 3. Re: Dynamic deployment URL
              Aslak Knutsen Master

              A deployment can create/expose more Resources then just a single URL even tho URL might be the most common usecase.

               

              JMX connection information, Multiple URLs in a EAR, Multiple URLs in a 'domain server group' deployment etc.

               

              The Deployer could possible chain the ArquillianResources tho, and basically act as a filter to mean this current deployment: e.g.

               

              URL deploymentUrl = deployer.deploy("my").lookup(URL.class)

              ( or lookup(URL.class, MyServlet.class) or lookup(URL.class, PortalURL.class) )

              • 4. Re: Dynamic deployment URL
                Julien Viet Apprentice

                yes I was thinking of that as well, even a simple map would do (although it would not provide a type safe API).