2 Replies Latest reply on Jul 13, 2016 10:04 AM by bmajsak

    Arquillian: listen for Deploy events

    luis_1980

      Hi all.

       

      Is there any chance to listen for Deploy events?

      I need to execute some code after deploy finishes.

       

      thanks

        • 1. Re: Arquillian: listen for Deploy events
          bmajsak

          I believe you can do that through your custom extension. But it really depends on what kind of code you would like to execute. The solution below will work on the client side (so if you run your test in the container this is not a valid approach)

           

          You will need following bits

           

          Listener itself:

           

          public class DeploymentListener {
          
          
              void observeDeployment(@Observes(precedence = xxx) EventContext<DeployManagedDeployments> eventContext) {
                  // do something before
                  eventContext.proceed();
                  // or after
              }
          
          void observeUndeploy(@Observes(precedence = yyy) EventContext<UnDeployManagedDeployments> eventContext) {
                  // do something before
                  eventContext.proceed();
                  // or after
              }
          
          
          }
          
          

           

          The precedence is arbitrary number which let's you hook in before or after other event listneres of the same type. In your case it should probably be a positive number (but cannot really tell you if 100 or 1000 or anything else - would need to investigate in the core itself for the exact answer, but I belive this is not really necessary).

           

          Registering the listener:

          import org.jboss.arquillian.core.spi.LoadableExtension;
          import org.jboss.arquillian.test.impl.enricher.resource.ArquillianResourceTestEnricher;
          import org.jboss.arquillian.test.spi.TestEnricher;
          
          
          public class DeploymentListenerExtension implements LoadableExtension {
              @Override
              public void register(final ExtensionBuilder builder) {
                  builder.observer(DeploymentListener.class);
              }
          }
          
          

           

          Making Arquillian aware of the extension, so that it will be loaded automatically by the framework. You should register your loadable extension through SPI in resources/META-INF/services/org.jboss.arquillian.core.spi.LoadableExtension file with following content

          yourpackage.DeploymentListenerExtension

           

          More sample extensions, which can help you getting familiar with the topic, can be found here:

          https://github.com/arquillian/arquillian-showcase/tree/master/extensions

           

          And obviously I'm around to help further.

           

          Cheers,

          Bartosz

          1 of 1 people found this helpful
          • 2. Re: Arquillian: listen for Deploy events
            bmajsak

            Moved to general Arquillian space.


            Can we assume this thread is closed? Or is there anything else you would like to know?