9 Replies Latest reply: Aug 1, 2011 4:05 AM by Aslak Knutsen RSS

    Programmatic configuration - arquillian.xml

    Kristoffer Sjögren Newbie

      Hi

       

      Is it possible to provide a arquillian.xml programmatically at runtime from my testcase?

       

      Cheers,

      -Kristoffer

        • 1. Re: Programmatic configuration - arquillian.xml
          Aslak Knutsen Master

          Not from your test case..

           

          How would you have wanted this to work? What is your use case?

           

          -aslak-

          • 2. Re: Programmatic configuration - arquillian.xml
            Kristoffer Sjögren Newbie

            I use a remote application server for the testcase and i dont know its ip address, it needs to be discovered.

             

            I visualize a factory class that produces configuration that override arquillian.xml at runtime. This class could be given to arquillian in different ways..

             

            - In @Deployment (maybe a bit intrusive)

            - A property or attribute in arquillian.xml.

            - An environment variable.

            - Service factory.

             

            What do you think?

             

            Cheers,

            -Kristoffer

            • 3. Re: Programmatic configuration - arquillian.xml
              Aslak Knutsen Master

              How do you discover it's ip runtime?

               

              If you know the ip at config time, but want access to the containers IP during runtime you can use the @ArquillianResource to inject a URL.

               

              @ArquillianResource

              private URL baseURL;

               

              That will give you the base url to the WebContext that has been deployed, e.g. ip:port/mywar.

              • 4. Re: Programmatic configuration - arquillian.xml
                Kristoffer Sjögren Newbie

                We have virtual machines that are allocated dynamically and configures themselves on our infrastructure. We do have control over this mechanism, so a machine could (for example) register itself in a database when it is ready, then developers lease a machine exclusively for a period of time.

                 

                So i would have to lookup the machine and its ip address in a database - and tell arquillian where the machine is so that the testcase uploads the jar and executes tests on the correct machine.

                • 5. Re: Programmatic configuration - arquillian.xml
                  Aslak Knutsen Master

                  Right, this is similar to what we're doing with the JClouds Extension..

                   

                  You should be able to do what you want by writing a Arquillian Extension.

                   

                   

                  Something in the lines of this should in theory work..

                   

                   

                  import org.jboss.arquillian.config.descriptor.api.ContainerDef;
                  import org.jboss.arquillian.config.descriptor.impl.ContainerDefImpl;
                  import org.jboss.arquillian.container.spi.ContainerRegistry;
                  import org.jboss.arquillian.core.api.annotation.Observes;
                  import org.jboss.arquillian.core.spi.LoadableExtension;
                  import org.jboss.arquillian.core.spi.ServiceLoader;
                  
                  
                  // PesudoExample class it self should not be used, just a example to combine the other classes in one file..  
                  public class PesudoExample
                  {
                  
                  
                     // register this as a SPI under META-INF/services/org.jboss.arquillian.core.spi.LoadableExtension
                     public static class AutoDiscoverInstanceExtension implements LoadableExtension
                     {
                        @Override
                        public void register(ExtensionBuilder builder)
                        {
                           builder.observer(LoadContainerConfiguration.class);
                        }
                     }
                     
                     public static class LoadContainerConfiguration 
                     {
                        public void registerInstance(@Observes ContainerRegistry registry, ServiceLoader serviceLoader)
                        {
                           VMImage image = findAvailableImage();
                           
                           // same value as you would put in arquillian.xml container/configuration
                           ContainerDef definition = new ContainerDefImpl("not_used_for_anything")
                                             .setContainerName("name")
                                             .setDefault()
                                             .property("host", image.ip)
                                             .property("port", image.port);
                           
                           registry.create(definition, serviceLoader);
                        }
                        
                        private VMImage findAvailableImage()
                        {
                           // Lookup in database or what ever you need to find the info
                           return null;
                        }
                     }
                     
                     public static class VMImage {
                        public String ip;
                        public String port;
                     }
                  }
                  
                  
                  • 6. Re: Programmatic configuration - arquillian.xml
                    Kristoffer Sjögren Newbie

                    I will try this out. Arquillian is everything i wanted from in-container testing (and more). It fits my needs exactly!

                     

                    I pay my respect on deephacks.

                     

                    Thank you.

                    • 7. Re: Programmatic configuration - arquillian.xml
                      Aslak Knutsen Master

                      Thank you for the kind words!

                       

                      I've added your blog to the External Blog/Article Feed at http://www.jboss.org/arquillian

                       

                      Ping back if you're having problems getting it to run..

                       

                      -aslak-

                      • 8. Re: Programmatic configuration - arquillian.xml
                        Kristoffer Sjögren Newbie

                        Thanks for the link! :-) Much appreciated. I just recently changed my blog to stoffe.deephacks.org. Could you be so kind to update that link to http://stoffe.deephacks.org/2011/07/15/container-love?

                         

                        Cheers,

                        -Kristoffer