[cargo] r3980 - in core/trunk: api/module/src/main/java/org/codehaus/cargo/module/webapp/jboss containers/jboss/src/main/java/org/codehaus/cargo/container/jboss/deployable containers/jboss/src/test/java/org/codehaus/cargo/container/jboss/deployable containers/jboss/src/test/resources/org/codehaus/cargo/container/jboss

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

[cargo] r3980 - in core/trunk: api/module/src/main/java/org/codehaus/cargo/module/webapp/jboss containers/jboss/src/main/java/org/codehaus/cargo/container/jboss/deployable containers/jboss/src/test/java/org/codehaus/cargo/container/jboss/deployable containers/jboss/src/test/resources/org/codehaus/cargo/container/jboss

alitokmen-2
Author: alitokmen
Date: 2015-04-03 12:38:03 -0500 (Fri, 03 Apr 2015)
New Revision: 3980

Added:
   core/trunk/containers/jboss/src/test/resources/org/codehaus/cargo/container/jboss/jboss-virtualhost.war
Modified:
   core/trunk/api/module/src/main/java/org/codehaus/cargo/module/webapp/jboss/JBossWebXml.java
   core/trunk/api/module/src/main/java/org/codehaus/cargo/module/webapp/jboss/JBossWebXmlTag.java
   core/trunk/api/module/src/main/java/org/codehaus/cargo/module/webapp/jboss/JBossWebXmlType.java
   core/trunk/containers/jboss/src/main/java/org/codehaus/cargo/container/jboss/deployable/JBossWAR.java
   core/trunk/containers/jboss/src/test/java/org/codehaus/cargo/container/jboss/deployable/JBossWARTest.java
Log:
Fix CARGO-1313: Add support for JBoss virtual-host statements

Modified: core/trunk/api/module/src/main/java/org/codehaus/cargo/module/webapp/jboss/JBossWebXml.java
===================================================================
--- core/trunk/api/module/src/main/java/org/codehaus/cargo/module/webapp/jboss/JBossWebXml.java 2015-03-29 19:49:07 UTC (rev 3979)
+++ core/trunk/api/module/src/main/java/org/codehaus/cargo/module/webapp/jboss/JBossWebXml.java 2015-04-03 17:38:03 UTC (rev 3980)
@@ -68,6 +68,16 @@
     }
 
     /**
+     * @return the virtual host element found in the <code>jboss-web.xml</code> file or null if not
+     * defined
+     */
+    public String getVirtualHost()
+    {
+        return getNestedText(
+            getRootElement(), getDescriptorType().getTagByName(JBossWebXmlTag.VIRTUAL_HOST));
+    }
+
+    /**
      * {@inheritDoc}
      * @see org.codehaus.cargo.module.Descriptor#getFileName()
      */

Modified: core/trunk/api/module/src/main/java/org/codehaus/cargo/module/webapp/jboss/JBossWebXmlTag.java
===================================================================
--- core/trunk/api/module/src/main/java/org/codehaus/cargo/module/webapp/jboss/JBossWebXmlTag.java 2015-03-29 19:49:07 UTC (rev 3979)
+++ core/trunk/api/module/src/main/java/org/codehaus/cargo/module/webapp/jboss/JBossWebXmlTag.java 2015-04-03 17:38:03 UTC (rev 3980)
@@ -36,6 +36,11 @@
     public static final String CONTEXT_ROOT = "context-root";
 
     /**
+     * Element name 'virtual-host'.
+     */
+    public static final String VIRTUAL_HOST = "virtual-host";
+
+    /**
      * Element name 'ejb-ref'.
      */
     public static final String EJB_REF = "ejb-ref";

Modified: core/trunk/api/module/src/main/java/org/codehaus/cargo/module/webapp/jboss/JBossWebXmlType.java
===================================================================
--- core/trunk/api/module/src/main/java/org/codehaus/cargo/module/webapp/jboss/JBossWebXmlType.java 2015-03-29 19:49:07 UTC (rev 3979)
+++ core/trunk/api/module/src/main/java/org/codehaus/cargo/module/webapp/jboss/JBossWebXmlType.java 2015-04-03 17:38:03 UTC (rev 3980)
@@ -39,6 +39,7 @@
     private JBossWebXmlTag[] tags =
         new JBossWebXmlTag[] {
             new JBossWebXmlTag(this, JBossWebXmlTag.CONTEXT_ROOT, false),
+            new JBossWebXmlTag(this, JBossWebXmlTag.VIRTUAL_HOST, false),
             new JBossWebXmlTag(this, JBossWebXmlTag.EJB_LOCAL_REF),
             new JBossWebXmlTag(this, JBossWebXmlTag.EJB_REF),
             new JBossWebXmlTag(this, JBossWebXmlTag.EJB_REF_NAME),

Modified: core/trunk/containers/jboss/src/main/java/org/codehaus/cargo/container/jboss/deployable/JBossWAR.java
===================================================================
--- core/trunk/containers/jboss/src/main/java/org/codehaus/cargo/container/jboss/deployable/JBossWAR.java 2015-03-29 19:49:07 UTC (rev 3979)
+++ core/trunk/containers/jboss/src/main/java/org/codehaus/cargo/container/jboss/deployable/JBossWAR.java 2015-04-03 17:38:03 UTC (rev 3980)
@@ -59,36 +59,55 @@
     }
 
     /**
-     * @return the context defined in <code>jboss-web.xml</code> if any. If there is no
-     * <code>jboss-web.xml</code> or if it doesn't define any root context, then return
-     * {@link WAR#getContext()}.
+     * @return the context defined in <code>jboss-web.xml</code> if any (including, if present, the
+     * virtual host name as a prefix). If there is no <code>jboss-web.xml</code> or if it doesn't
+     * define any root context, then return {@link WAR#getContext()}.
      */
     @Override
     public synchronized String getContext()
     {
-        String result = parseJbossWebXml();
-        if (result == null)
+        String context = null;
+
+        if (this.warArchive.getJBossWebXml() != null)
         {
-            result = super.getContext();
+            context = this.warArchive.getJBossWebXml().getContextRoot();
+            if (context != null)
+            {
+                if ("".equals(context) || "/".equals(context))
+                {
+                    context = "ROOT";
+                }
+
+                String virtualHost = this.warArchive.getJBossWebXml().getVirtualHost();
+                if (virtualHost != null)
+                {
+                    context = virtualHost + '-' + context;
+                }
+            }
         }
 
-        return result;
+        if (context == null)
+        {
+            context = super.getContext();
+        }
+
+        return context;
     }
 
     /**
-     * @return the context from JBoss's <code>jboss-web.xml</code> if it is defined or
-     * <code>null</code> otherwise.
+     * @return the virtual host element found in the <code>jboss-web.xml</code> file or null if not
+     * defined
      */
-    private String parseJbossWebXml()
+    public String getVirtualHost()
     {
-        String context = null;
+        String virtualHost = null;
 
         if (this.warArchive.getJBossWebXml() != null)
         {
-            context = this.warArchive.getJBossWebXml().getContextRoot();
+            virtualHost = this.warArchive.getJBossWebXml().getVirtualHost();
         }
 
-        return context;
+        return virtualHost;
     }
 
     /**

Modified: core/trunk/containers/jboss/src/test/java/org/codehaus/cargo/container/jboss/deployable/JBossWARTest.java
===================================================================
--- core/trunk/containers/jboss/src/test/java/org/codehaus/cargo/container/jboss/deployable/JBossWARTest.java 2015-03-29 19:49:07 UTC (rev 3979)
+++ core/trunk/containers/jboss/src/test/java/org/codehaus/cargo/container/jboss/deployable/JBossWARTest.java 2015-04-03 17:38:03 UTC (rev 3980)
@@ -102,4 +102,18 @@
         war.setContext("context");
         assertEquals("testcontext", war.getContext());
     }
+
+    /**
+     * Test get JBoss WAR context and virtual host when context already setup and JBoss web.xml is
+     * present.
+     * @throws Exception If anything goes wrong.
+     */
+    public void testGetWarContextAndVirtualHostWhenContextAlreadySetupAndJBossWebXml()
+        throws Exception
+    {
+        JBossWAR war = new JBossWAR(getResourcePath(PACKAGE_PATH + "jboss-virtualhost.war"));
+        war.setContext("context");
+        assertEquals("testhost-testcontext", war.getContext());
+        assertEquals("testhost", war.getVirtualHost());
+    }
 }

Copied: core/trunk/containers/jboss/src/test/resources/org/codehaus/cargo/container/jboss/jboss-virtualhost.war (from rev 3979, core/trunk/containers/jboss/src/test/resources/org/codehaus/cargo/container/jboss/jboss-context.war)
===================================================================
(Binary files differ)


---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email