9 Replies Latest reply on Jun 9, 2017 2:43 PM by Brad Maxwell

    Arquillian customize standalone.xml

    aqtwrdnr aqtwrdnr Newbie

      Hi,

       

      is it possible to change the standalone.xml file in JBoss before tests are started?

        • 1. Re: Arquillian customize standalone.xml
          Karel Piwko Master

          Hey,

           

          yes, there are a few options:

           

          1/ You can manually copy and modify standalone.xml and point Arquillian to modified configuration (via serverConfig property - see JBoss AS 7.1, JBoss EAP 6.0 - Managed - Arquillian - Project Documentation Editor)

           

          2/ You can use maven resource filtering to modify standalone.xml - just place placeholders there

           

          3/ You can use @ServletTask, get Management Client and call code that will modify standalone.xml, for instance here I'm adding subsystem for PicketLink:

           

          public class InstallPicketLinkFileBasedSetupTask implements ServerSetupTask {
          
              private static final Logger log = Logger.getLogger(InstallPicketLinkFileBasedSetupTask.class.getSimpleName());
          
              private static final String JBOSSAS_CONTAINER = "jbossas";
          
              @Override
              public void setup(ManagementClient managementClient, String containerId) throws Exception {
                  if (!containerId.startsWith(JBOSSAS_CONTAINER)) {
                      return;
                  }
          
                  File workingDir = File.createTempFile("pl-idm", "workingdir");
                  workingDir.delete();
                  if (workingDir.mkdirs()) {
                      workingDir.deleteOnExit();
                  } else {
                      throw new AssertionError("Spoofing malicious security operation");
                  }
          
                  log.log(Level.INFO, "Installing File Based Partition Manager into AS/EAP container using working dir {0}",
                          workingDir.getAbsolutePath());
          
                  ModelNode step1 = ModelUtil.createOpNode("subsystem=picketlink/identity-management=picketlink-files", "add");
                  step1.get("alias").set("picketlink-files");
                  step1.get("jndi-name").set("java:jboss/picketlink/FileBasedPartitionManager");
          
                  ModelNode step2 = ModelUtil.createOpNode(
                          "subsystem=picketlink/identity-management=picketlink-files/identity-configuration=picketlink-files", "add");
                  step2.get("name").set("picketlink-files");
          
                  ModelNode step3 = ModelUtil
                          .createOpNode(
                                  "subsystem=picketlink/identity-management=picketlink-files/identity-configuration=picketlink-files/file-store=file-store",
                                  "add");
                  step3.get("always-create-files").set(true);
                  step3.get("async-write").set(true);
                  step3.get("async-write-thread-pool").set(10);
                  step3.get("support-attribute").set(true);
                  step3.get("working-dir").set(workingDir.getAbsolutePath());
          
                  ModelNode step4 = ModelUtil
                          .createOpNode(
                                  "subsystem=picketlink/identity-management=picketlink-files/identity-configuration=picketlink-files/file-store=file-store/supportedTypes=supportedTypes",
                                  "add");
                  step4.get("supportsAll").set(true);
          
                  ModelNode op = ModelUtil.createCompositeNode(step1, step2, step3, step4);
          
                  // add picketlink subsystem
                  boolean success = ModelUtil.execute(managementClient, op);
                  log.log(success ? Level.INFO : Level.WARNING, "Installing File Based Partition Manager into AS/EAP container {0}",
                          new Object[] { success ? "passed" : "failed" });
          
                  // FIXME reload is not working due to https://bugzilla.redhat.com/show_bug.cgi?id=900065
                  // managementClient.getControllerClient().execute(ModelUtil.createOpNode(null, "reload"));
              }
          
              @Override
              public void tearDown(ManagementClient managementClient, String containerId) throws Exception {
          
                  if (!containerId.startsWith(JBOSSAS_CONTAINER)) {
                      return;
                  }
          
                  log.log(Level.INFO, "Deinstalling File Based Partition Manager from AS/EAP container");
          
                  ModelNode op = ModelUtil.createOpNode("subsystem=picketlink/identity-management=picketlink-files", "remove");
          
                  // remove picketlink subsystem
                  boolean success = ModelUtil.execute(managementClient, op);
                  log.log(success ? Level.INFO : Level.WARNING, "Deinstalling File Based Partition Manager into AS/EAP container {0}",
                          new Object[] { success ? "passed" : "failed" });
          
                  // FIXME reload is not working due to https://bugzilla.redhat.com/show_bug.cgi?id=900065
                  // managementClient.getControllerClient().execute(ModelUtil.createOpNode(null, "reload"));
              }
          }
          

           

          @RunWith(Arquillian.class)
          @ServerSetup(InstallPicketLinkFileBasedSetupTask.class)
          public class FileBasedStoreTest {
          
              @Deployment(testable = false)
              @TargetsContainer("jbossas")
              public static WebArchive getJBossASDeployment() {
                  ...
              }
          
              @Test
              public void yourTest() {
                  ....
              }
          }
          
          • 2. Re: Arquillian customize standalone.xml
            aqtwrdnr aqtwrdnr Newbie

            I cannot find ModelUtil.execute() method, am I targeting the correct package org.jboss.as.test.integration.management.util.ModelUtil?

            • 3. Re: Re: Arquillian customize standalone.xml
              Karel Piwko Master

              Ahh, my fault. Very likely I've grabbed the class from the package you mentioned. However, I'm not sure whether I haven't modified it:

               

              Anyway, here is what I use in my tests:

               

              /**
               * @author Dominik Pospisil <dpospisi@redhat.com>
               */
              public class ModelUtil {
              
                  private static final Logger log = Logger.getLogger(ModelUtil.class.getName());
              
                  public static List<String> modelNodeAsStringList(ModelNode node) {
                      List<String> ret = new LinkedList<String>();
                      for (ModelNode n : node.asList())
                          ret.add(n.asString());
                      return ret;
                  }
              
                  public static ModelNode createCompositeNode(ModelNode... steps) {
                      ModelNode comp = new ModelNode();
                      comp.get("operation").set("composite");
                      for (ModelNode step : steps) {
                          comp.get("steps").add(step);
                      }
                      return comp;
                  }
              
                  public static boolean execute(ManagementClient client, ModelNode operation) {
                      try {
                          ModelNode result = client.getControllerClient().execute(operation);
                          return getOperationResult(result);
                      } catch (IOException e) {
                          log.log(Level.SEVERE, "Failed execution of operation " + operation.toJSONString(false), e);
                          return false;
                      }
                  }
              
                  private static boolean getOperationResult(ModelNode node) {
              
                      boolean success = "success".equalsIgnoreCase(node.get("outcome").asString());
                      if (!success) {
                          log.log(Level.WARNING, "Operation failed with \n{0}", node.toJSONString(false));
                      }
              
                      return success;
              
                  }
              
                  public static ModelNode createOpNode(String address, String operation) {
                      ModelNode op = new ModelNode();
              
                      // set address
                      ModelNode list = op.get("address").setEmptyList();
                      if (address != null) {
                          String[] pathSegments = address.split("/");
                          for (String segment : pathSegments) {
                              String[] elements = segment.split("=");
                              list.add(elements[0], elements[1]);
                          }
                      }
                      op.get("operation").set(operation);
                      return op;
                  }
              }
              
              • 4. Re: Arquillian customize standalone.xml
                Joe Punk Newbie

                It looks like there is org.jboss.as.test.integration.management.ManagementOperations class for that. But it does bassically the same .

                • 5. Re: Arquillian customize standalone.xml
                  Karel Piwko Master

                  You're right. I've copied the class to my project (both are using Apache Licence) avoid having another Maven dependency ;-)

                  • 6. Re: Arquillian customize standalone.xml
                    Rafael Pestano Novice

                    1/ You can manually copy and modify standalone.xml and point Arquillian to modified configuration (via serverConfig property - see JBoss AS 7.1, JBoss EAP 6.0 - Managed - Arquillian - Project Documentation Editor)

                    for us it was the best option, we can use customized standalone for tests which has different datasources for example(we had lots of trouble with org.jboss.msc.service.DuplicateServiceException already registered).

                     

                    with vm-args you can start jboss pointing to a standalone.xml inside test code, here is our setup:

                     

                    arquillian.xml:

                     

                    <container qualifier="jbossas-managed"  default="true" >

                      <configuration>

                      <property name="jbossHome">${arquillian.jbossHome}</property>

                      <property name="outputToConsole">true</property>

                      <property name="allowConnectingToRunningServer">true</property>

                      <property name="javaVmArguments">-Xmx512m -XX:MaxPermSize=256m -Djboss.bind.address=${arquillian.localAddress}

                                    -Dserver-config=${project.basedir}/src/test/resources/test-standalone.xml

                                </property>

                      </configuration>

                      </container>

                     

                    I hope that helps someone.

                    • 7. Re: Arquillian customize standalone.xml
                      Brad Maxwell Newbie

                      Is there a way to pass a String CLI command instead of the ModelNode?  Such as the syntax that a user enters via jboss-cli.sh 

                      org.jboss.as.cli.scriptsupport.CLI can do this, but it does not look like way to go from ManagementClient to a CLI object

                      • 9. Re: Arquillian customize standalone.xml
                        Brad Maxwell Newbie

                        Thanks that looks like what I need!