2 Replies Latest reply on Nov 7, 2010 1:49 AM by Iván Pazmiño

    Accessing container's resources

    Iván Pazmiño Novice

      Hello,

      Is there a way to access the containers resources? Let's say I need to check my log was written correctly. Can I make something like

       

      @Container

      private Container container;

      ...

      @Test

      public void testLog() {

      assertNotNull(container.getLog("custom.log"));

      }

        • 1. Re: Accessing container's resources
          Aslak Knutsen Master

          Not sure what you mean by Containers Resources, but.. you can reach anything on the Contianer side..

           

          Making your own TestEnricher that expose a Container abstraction is fully possible.

           

          Make a implementation of org.jboss.arquillian.spi.TestEnricher

           

          public class ContainerEnricher implements TestEnricher {
            public void enrich(Context context, Object testInstance)
            {
              // pesudo
              for each testInstance.getClass().getDeclaredFields()
                field.isAnnotationPresent(Container.class)
                  field.set(testInstance, new MyContainerAbstraction())
            }
          }
          

           

          Make a implementation of org.jboss.arquillian.spi.AuxiliaryArchiveAppender to package the TestEnricher

           

          public class ContainerPackager implement AuxiliaryArchiveAppener
          {
            public Archive<?> createAuxiliaryArchive()
            {
              return ShrinkWrap.create(JavaArchive.class, "container-enricher.jar")
                          .addClass(ContainerEnricher.class)
                          .addServiceProvider(TestEnricher.class, ContainerEnricher.class);
            }
          }
          

           

           

          Make a file in META-INF/services/org.jboss.arquillian.spi.AuxiliaryArchiveAppender that contain the fully qualified name for your ContainerPackager and you should be good to go.

          • 2. Re: Accessing container's resources
            Iván Pazmiño Novice

            Thanks, you caught the spirit of the question. What I meant exactly is for instance I'm making an EJB interceptor to log in a separate log file some operations made by a session bean. So, in order to test it's working I need a way to acces from the test class the container's log service. Mmm sure resource is not what I mean to say, but maybe service would suit better. Anyway, I haven't found the way to access the currently running DeployableContainer instance from my enricher, but I'll open another post in that matter.