12 Replies Latest reply on Mar 7, 2012 11:26 AM by tomjenkinson

    Testing a JBoss module using Arquillian

    paul.robinson

      Hello,

       

      First of all, let me apologize if this already exists or has been discussed elsewhere. searching for anything to do with 'JBoss modules' always returns a lot of false positives ;-)

       

      I'm creating a new JBossAS7 feature that will eventually ship with JBossAS. It will ship as a JBoss module with a small amount of subsystem code to integrate into the deployment process. My integration tests use Arquillian. In the prototype stages I simply shipped my module code with the application that used it. This was great as I had the rapid development cycle that Arquillian gives you. However, now I build a jboss module and place it in the modules directory structure. My integration test applications have a dependency on this module. The problem I now have is that my development cycle is as follows:

       

      1. Change module code
      2. Build module
      3. Copy module jar over old one.
      4. reboot the AS
      5. Run the arquillian test

       

      So, I'm basically back to the old dev cycle that Arquillian improves upon. Ideally, I would like arquillian to ensure the new version of my module code is used, without me having to do a build and reboot the AS.

       

      First of all, is there already a solution to my problem?

       

      If not, what would you suggest the best approach is?

       

      I think I should take the following approach:

       

      1. Check that JBoss Modules can be reloaded at run-time, if they can...
      2. Create a 'module' JavaArchive type as an extension. In a similar fashion to how the weld tests create a bean archive: https://github.com/weld/core/tree/master/tests-arquillian/src/main/java/org/jboss/shrinkwrap
      3. Somehow, get Arquilian to install this as a module (don't know if this is possible)

       

      what do you guys think?

       

      Paul.

        • 1. Re: Testing a JBoss module using Arquillian
          aslak

          If you run on a clean jboss-as, you should be able to deploy your module as part of the test. (deploying when it already exists will probably cause problems, unless you just rename it for the sake of the test)

           

          Something like:

           

           

          @RunWith(Arquillian.class)
          public class TestClass {
          
          
            @Deployment(name = "mymodule", order = 1, testable = false)
            public static JavaArchive createModule() {
                    return ShrinkWrap.create(JavaArchive.class)
                                        .addXXXXX()
                                        .setManifest(new StringAsset(
                                                  "... module description\n module-name:XXXX..."));
            }
          
          
            @Deployment(name = "myapp", order = 2)
            public static ? createApp() {
                     return ShrinkWrap.create(?)
                                        .setManifest(new StringAsset(
                                                  "...Dependencies: XXXX..."));
            }
          
          
            @Test
            public void shouldDoWhatItShouldDo() {}
          
          
          }
          
          
          1 of 1 people found this helpful
          • 2. Re: Testing a JBoss module using Arquillian
            paul.robinson

            Thanks Aslak,

             

            That looks like a nice simple solution. I have a couple of concerens, which hopefully I should be able to overcome:

             

            1. This never tests the real module that will live in the AS. This is fine during development, but not during CI, QE etc. I'll need to figure out a way of turning off the module @Deployment for these tests, when not run in dev mode.
            2. The real module has a module.xml that brings in some other dependencies. I'de need to make sure I can use that in the module @Deployment
            3. A clean JBossAS (hopefully) will eventually have my module installed, so I will need a way to have them co-existing. Your idea of naming the @Deployment module differently should work (I think), but that would meen specifying a different dependency in my testable @Deployment. This would need switching back, somehow, whne the test are run on CI.

             

            If you have any ideas, off the top of your head, I'd be interested to know. But if you havn't, it's not a problem, I can see what I can come up with.

             

            Paul.

            • 3. Re: Testing a JBoss module using Arquillian
              paul.robinson

              Alsak,

               

              I don't think I can create a full JBoss module, using the shrinkwrap deployment you suggest. By a 'full deployment', I mean one that contains a module.xml and offers all the features available in the module.xml. I think your suggestion just allows me to update the java code, which is probably enough in most scenarios. CI would need to use the module that ships with JBossAS, but that shouldn't be too difficult to work around.

               

              If I understand your suggestion correctly, doesn't the following provide me with the same functionality, in a simpler manor?

               

              @RunWith(Arquillian.class)
              public class TestClass {
               
                @Deployment
                public static ? createApp() {
                         return ShrinkWrap.create(?)
                                            .addPackages(module packages...) //this is where I'm ading the changed module code
                                            .addPackages(test packages...)
              
                                            .setManifest(new StringAsset(
                                                      "...Dependencies: XXXX..."));
                }
               
               
                @Test
                public void shouldDoWhatItShouldDo() {}
               
              }
              

               

               

              Thanks,

               

              Paul.

              • 4. Re: Testing a JBoss module using Arquillian
                tomjenkinson

                Hi Paul,

                 

                I *think* there is a unit test in AS7 that appears to do the scaffolding you need already:

                 

                [tom@tomsfc16 jboss-as]$ find . -name \module.xml | grep test

                ./testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/extension/remove/module.xml

                 

                gedit testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/extension/remove/*

                 

                Seems to deploy a real module (i.e. a filesystem using module.xml), then enables it using:

                ModelControllerClient client = ModelControllerClient.Factory.create(InetAddress.getByName("localhost"), 9999, getCallbackHandler());

                 

                Hope this is on topic and is of use to you,

                Tom

                1 of 1 people found this helpful
                • 5. Re: Testing a JBoss module using Arquillian
                  tomjenkinson

                  Hi Paul,


                  Did that pointer I suggested help at all?

                   

                  Thanks,
                  Tom

                  • 6. Re: Testing a JBoss module using Arquillian
                    paul.robinson

                    Tom,

                     

                    Thanks for the link. I took a quick look on Friday and it certainly looks like it could be what I want. I've been on PTO, so not had chance to take a proper look.

                     

                    Thanks,

                     

                    Paul.

                    • 7. Re: Testing a JBoss module using Arquillian
                      paul.robinson

                      Tom,

                       

                      I've spoke to Kabir, and this approach should work, providing you use a different module name each time the test is ran. It doesn't look like it's possible to re-load a particular module. However, I've now realized there are (at least) two fundamental problems with what I am trying to achieve:

                       

                      1) You can't update the code used by existing dependants. For example, I boot the AS with a sub-system that depends on Module A. I also have an application that depends on Module A. I can change the code used by the application by deploying Module A' and have the application depend on that. However, the sub-system will still depend on Module A.

                       

                      2) If I want to change the contents of the module.xml, I can have the test application see this change, as it will depend on Module A'. However, existing sub-systems will still see the old module.xml from Module A.

                       

                      I'm thinking the simplest approach is to just add the module code in my test archive during development (as suggested in https://community.jboss.org/message/719411#719411). The only problem is that I can't modify the module.xml without re-booting the AS. This is not a major problem as it is done so infrequently.

                       

                      Paul.

                      • 8. Re: Testing a JBoss module using Arquillian
                        tomjenkinson

                        I see, thanks for getting back to me on this. Perhaps different tests would benefit from the different approaches?

                        • 9. Re: Testing a JBoss module using Arquillian
                          paul.robinson

                          What "different tests" where you thinking of?

                          • 10. Re: Testing a JBoss module using Arquillian
                            tomjenkinson

                            If you have a module that is only depended upon my applications then the approach I outlined would give you the most freedom.

                             

                            Without knowing more of the specifics of your module I am not clear if other subsystems do have a dependency upon your module - though I presume from your concern, then other subsystems will do.

                             

                            Can you use the approach I suggested to offline configure the AS (i.e. put the files in place), then boot up the AS to run the tests with all subsystems now using the new module?

                             

                            I think arq lets you do work before it boots the server iirc?

                            • 11. Re: Testing a JBoss module using Arquillian
                              paul.robinson

                              Tom,

                              If you have a module that is only depended upon my applications then the approach I outlined would give you the most freedom.

                              Agreed.

                              Without knowing more of the specifics of your module I am not clear if other subsystems do have a dependency upon your module - though I presume from your concern, then other subsystems will do.

                              I do have a subsystem that also depends on this module, so it is a concern.

                              Can you use the approach I suggested to offline configure the AS (i.e. put the files in place), then boot up the AS to run the tests with all subsystems now using the new module?

                               

                              I think arq lets you do work before it boots the server iirc?

                              Yes, I was thinking about this; it would only work for managed mode though, as remote leaves the server running.

                               

                              Paul.

                              • 12. Re: Testing a JBoss module using Arquillian
                                tomjenkinson

                                Good point re managed vs remote - I hadnt thought through that far, there isn't an AS7 admin command to remotely bounce the server is there?