[jboss-cvs] JBossAS SVN: r109069 - in trunk: testsuite/imports/sections and 5 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Tue Nov 2 10:29:53 EDT 2010


Author: jaikiran
Date: 2010-11-02 10:29:52 -0400 (Tue, 02 Nov 2010)
New Revision: 109069

Added:
   trunk/testsuite/src/main/org/jboss/test/jbas8528/
   trunk/testsuite/src/main/org/jboss/test/jbas8528/test/
   trunk/testsuite/src/main/org/jboss/test/jbas8528/test/ApplicationNamingUnitTestCase.java
   trunk/testsuite/src/resources/jbas8528/
   trunk/testsuite/src/resources/jbas8528/application.xml
   trunk/testsuite/src/resources/jbas8528/index.jsp
   trunk/testsuite/src/resources/jbas8528/jboss-service.xml
Modified:
   trunk/server/src/main/java/org/jboss/as/naming/javaee/NamingJavaEEApplicationInformer.java
   trunk/testsuite/imports/sections/web.xml
Log:
JBAS-8528 Take into account application-name specified in application.xml, while generating the application name for a deployment

Modified: trunk/server/src/main/java/org/jboss/as/naming/javaee/NamingJavaEEApplicationInformer.java
===================================================================
--- trunk/server/src/main/java/org/jboss/as/naming/javaee/NamingJavaEEApplicationInformer.java	2010-11-02 14:13:39 UTC (rev 109068)
+++ trunk/server/src/main/java/org/jboss/as/naming/javaee/NamingJavaEEApplicationInformer.java	2010-11-02 14:29:52 UTC (rev 109069)
@@ -2,6 +2,8 @@
 
 import org.jboss.deployers.structure.spi.DeploymentUnit;
 import org.jboss.metadata.ear.jboss.JBossAppMetaData;
+import org.jboss.metadata.ear.spec.Ear6xMetaData;
+import org.jboss.metadata.ear.spec.EarMetaData;
 import org.jboss.reloaded.naming.deployers.javaee.JavaEEApplicationInformer;
 import org.jboss.system.metadata.ServiceDeployment;
 
@@ -17,6 +19,13 @@
       if(!isJavaEEApplication(deploymentUnit))
          return null;
 
+      // JBAS-8528
+      String explicitAppName = this.getExplicitApplicationName(deploymentUnit);
+      if (explicitAppName != null)
+      {
+         return explicitAppName;
+      }
+      
       String name = deploymentUnit.getSimpleName();
       return name.substring(0, name.length() - 4);
    }
@@ -44,5 +53,27 @@
    public String[] getRequiredAttachments()
    {
       return REQUIRED_ATTACHMENTS;
-   }   
+   }
+   
+   /**
+    * Returns the application-name specified in the application.xml of a deployment.
+    * If no application-name is specified in the application.xml, then this method returns null.
+    * 
+    * @param deploymentUnit The deployment unit 
+    * @return
+    */
+   private String getExplicitApplicationName(DeploymentUnit deploymentUnit)
+   {
+      EarMetaData earMetaData = deploymentUnit.getAttachment(EarMetaData.class);
+      if (earMetaData != null && earMetaData.isEE6() && earMetaData instanceof Ear6xMetaData)
+      {
+         Ear6xMetaData ear6x = (Ear6xMetaData) earMetaData;
+         String explicitAppName = ear6x.getApplicationName();
+         if (explicitAppName != null && !explicitAppName.trim().isEmpty())
+         {
+            return explicitAppName;
+         }
+      }
+      return null;
+   }
 }

Modified: trunk/testsuite/imports/sections/web.xml
===================================================================
--- trunk/testsuite/imports/sections/web.xml	2010-11-02 14:13:39 UTC (rev 109068)
+++ trunk/testsuite/imports/sections/web.xml	2010-11-02 14:29:52 UTC (rev 109069)
@@ -927,5 +927,26 @@
            <include name="**"/>
          </fileset>
       </jar>
+      
+      
+        <!-- build jbas8528.war -->
+        <war warfile="${build.lib}/jbas8528.war" needxmlfile="false">
+            <fileset dir="${build.resources}/jbas8528">
+                <include name="**/*.jsp"/>
+            </fileset>
+        </war>
+        <!-- build jbas8528.ear -->
+        <ear earfile="${build.lib}/jbas8528.ear" appxml="${build.resources}/jbas8528/application.xml">
+         <fileset dir="${build.lib}">
+            <include name="jbas8528.war"/>
+         </fileset>
+        </ear>
+        <!--  build jbas8528.sar -->
+        <jar destfile="${build.lib}/jbas8528.sar">
+            <fileset dir="${build.resources}/jbas8528">
+                <include name="jboss-service.xml"/>
+            </fileset>
+        </jar>
+      
    </target>
 </project>

Added: trunk/testsuite/src/main/org/jboss/test/jbas8528/test/ApplicationNamingUnitTestCase.java
===================================================================
--- trunk/testsuite/src/main/org/jboss/test/jbas8528/test/ApplicationNamingUnitTestCase.java	                        (rev 0)
+++ trunk/testsuite/src/main/org/jboss/test/jbas8528/test/ApplicationNamingUnitTestCase.java	2010-11-02 14:29:52 UTC (rev 109069)
@@ -0,0 +1,99 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.test.jbas8528.test;
+
+import junit.framework.Test;
+
+import org.apache.commons.httpclient.HttpClient;
+import org.apache.commons.httpclient.HttpMethodBase;
+import org.apache.commons.httpclient.methods.GetMethod;
+import org.jboss.test.JBossTestCase;
+import org.jboss.test.util.web.HttpUtils;
+
+/**
+ * Tests that a deployment with application.xml with an explicitly specified
+ * application-name, uses that name instead of the .ear file name for naming 
+ * deployments.
+ * 
+ * @see https://jira.jboss.org/browse/JBAS-8528
+ * 
+ * @author Jaikiran Pai
+ * @version $Revision: $
+ */
+public class ApplicationNamingUnitTestCase extends JBossTestCase
+{
+
+   private HttpClient client = new HttpClient();
+
+   public ApplicationNamingUnitTestCase(String name)
+   {
+      super(name);
+   }
+
+   /**
+    * Test that the application deploys successfully and is accessible.
+    * 
+    * @throws Exception
+    */
+   public void testApplicationDeployment() throws Exception
+   {
+      // make sure there wasn't a deployment failure
+      serverFound(); // silly, method name!
+      
+      // now access the jsp and test the return value
+      String url = HttpUtils.getBaseURL() + "/jbas8528-webapp/index.jsp";
+      String response = this.getResponse(url);
+      assertTrue(response.equals("JBAS-8528 Application"));
+   }
+
+   
+
+   /**
+    *  Access the passed URL and return back the response 
+    */
+   private String getResponse(String url) throws Exception
+   {
+      HttpMethodBase request = new GetMethod(url);
+      client.executeMethod(request);
+
+      String responseBody = request.getResponseBodyAsString();
+      if (responseBody == null)
+      {
+         throw new Exception("Unable to get response from server for URL: " + url);
+      }
+
+      return responseBody;
+   }
+
+   /**
+    * Deploy a .sar and .ear file, both having the same name, but the .ear has an
+    * explicitly specified value for application-name in application.xml (to avoid
+    * naming conflicts).
+    *  
+    * @return
+    * @throws Exception
+    */
+   public static Test suite() throws Exception
+   {
+      return getDeploySetup(ApplicationNamingUnitTestCase.class, "jbas8528.ear,jbas8528.sar");
+   }
+}

Added: trunk/testsuite/src/resources/jbas8528/application.xml
===================================================================
--- trunk/testsuite/src/resources/jbas8528/application.xml	                        (rev 0)
+++ trunk/testsuite/src/resources/jbas8528/application.xml	2010-11-02 14:29:52 UTC (rev 109069)
@@ -0,0 +1,15 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<application xmlns="http://java.sun.com/xml/ns/javaee"
+    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee 
+      	http://java.sun.com/xml/ns/javaee/application_6.xsd"
+    version="6">
+    
+    <application-name>jbas8528-overridden-appname</application-name>
+    <module>
+        <web>
+            <web-uri>jbas8528.war</web-uri>
+            <context-root>jbas8528-webapp</context-root>
+        </web>
+    </module>
+</application>

Added: trunk/testsuite/src/resources/jbas8528/index.jsp
===================================================================
--- trunk/testsuite/src/resources/jbas8528/index.jsp	                        (rev 0)
+++ trunk/testsuite/src/resources/jbas8528/index.jsp	2010-11-02 14:29:52 UTC (rev 109069)
@@ -0,0 +1,3 @@
+<%
+	out.print(System.getProperty("jboss.jbas8528.application"));
+%>
\ No newline at end of file

Added: trunk/testsuite/src/resources/jbas8528/jboss-service.xml
===================================================================
--- trunk/testsuite/src/resources/jbas8528/jboss-service.xml	                        (rev 0)
+++ trunk/testsuite/src/resources/jbas8528/jboss-service.xml	2010-11-02 14:29:52 UTC (rev 109069)
@@ -0,0 +1,10 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE server>
+<server>
+    <mbean code="org.jboss.varia.property.SystemPropertiesService"
+        name="jboss:type=Service,name=JBAS-8528-Test-SystemProperties">
+
+        <attribute name="Properties">jboss.jbas8528.application=JBAS-8528 Application</attribute>
+
+    </mbean>
+</server>
\ No newline at end of file



More information about the jboss-cvs-commits mailing list