You are viewing a plain text version of this content. The canonical link for it is here.
Posted to pluto-scm@portals.apache.org by es...@apache.org on 2006/08/05 23:26:36 UTC

svn commit: r429058 - in /portals/pluto/branches/pluto-1.0.2/descriptors/src: conf/org/apache/pluto/descriptors/servlet/ java/org/apache/pluto/descriptors/services/impl/ java/org/apache/pluto/descriptors/servlet/ test/org/apache/pluto/descriptors/servi...

Author: esm
Date: Sat Aug  5 14:26:35 2006
New Revision: 429058

URL: http://svn.apache.org/viewvc?rev=429058&view=rev
Log:
[PLUTO-216]: Improving support for Servlet 2.4 web.xml descriptors.  Includes unit tests.

The 'maven deploy' goal now works with both servlet 2.3 and servlet 2.4 web.xml descriptors, whether or not a xml namespace is used.

The Pluto admin portlet will work with both servlet 2.3 and servlet 2.4 web.xml descriptors, but only when xml namespaces are not used.


Added:
    portals/pluto/branches/pluto-1.0.2/descriptors/src/conf/org/apache/pluto/descriptors/servlet/web-2.3.xml   (with props)
    portals/pluto/branches/pluto-1.0.2/descriptors/src/java/org/apache/pluto/descriptors/servlet/ServletVersionCastorFieldHandler.java   (with props)
    portals/pluto/branches/pluto-1.0.2/descriptors/src/test/org/apache/pluto/descriptors/services/impl/FileWebAppDescriptorServiceImplTest.java   (with props)
    portals/pluto/branches/pluto-1.0.2/descriptors/src/test/org/apache/pluto/descriptors/servlet/WebAppDDVersionTest.java   (with props)
Modified:
    portals/pluto/branches/pluto-1.0.2/descriptors/src/conf/org/apache/pluto/descriptors/servlet/castor-web-xml-mapping.xml
    portals/pluto/branches/pluto-1.0.2/descriptors/src/java/org/apache/pluto/descriptors/services/impl/AbstractCastorDescriptorService.java
    portals/pluto/branches/pluto-1.0.2/descriptors/src/java/org/apache/pluto/descriptors/services/impl/AbstractWebAppDescriptorService.java
    portals/pluto/branches/pluto-1.0.2/descriptors/src/java/org/apache/pluto/descriptors/services/impl/FileWebAppDescriptorServiceImpl.java
    portals/pluto/branches/pluto-1.0.2/descriptors/src/java/org/apache/pluto/descriptors/servlet/WebAppDD.java

Modified: portals/pluto/branches/pluto-1.0.2/descriptors/src/conf/org/apache/pluto/descriptors/servlet/castor-web-xml-mapping.xml
URL: http://svn.apache.org/viewvc/portals/pluto/branches/pluto-1.0.2/descriptors/src/conf/org/apache/pluto/descriptors/servlet/castor-web-xml-mapping.xml?rev=429058&r1=429057&r2=429058&view=diff
==============================================================================
--- portals/pluto/branches/pluto-1.0.2/descriptors/src/conf/org/apache/pluto/descriptors/servlet/castor-web-xml-mapping.xml (original)
+++ portals/pluto/branches/pluto-1.0.2/descriptors/src/conf/org/apache/pluto/descriptors/servlet/castor-web-xml-mapping.xml Sat Aug  5 14:26:35 2006
@@ -49,6 +49,12 @@
     -->
   <class name="org.apache.pluto.descriptors.servlet.WebAppDD">
     <map-to xml="web-app"/>
+     
+    <field name="ServletVersion" 
+           handler="org.apache.pluto.descriptors.servlet.ServletVersionCastorFieldHandler" 
+           type="java.lang.String">
+        <bind-xml name="version" node="attribute"/>
+    </field>
       
     <field name="Icon"
            type="org.apache.pluto.descriptors.common.IconDD"/>

Added: portals/pluto/branches/pluto-1.0.2/descriptors/src/conf/org/apache/pluto/descriptors/servlet/web-2.3.xml
URL: http://svn.apache.org/viewvc/portals/pluto/branches/pluto-1.0.2/descriptors/src/conf/org/apache/pluto/descriptors/servlet/web-2.3.xml?rev=429058&view=auto
==============================================================================
--- portals/pluto/branches/pluto-1.0.2/descriptors/src/conf/org/apache/pluto/descriptors/servlet/web-2.3.xml (added)
+++ portals/pluto/branches/pluto-1.0.2/descriptors/src/conf/org/apache/pluto/descriptors/servlet/web-2.3.xml Sat Aug  5 14:26:35 2006
@@ -0,0 +1,45 @@
+<?xml version="1.0" encoding="ISO-8859-1"?>
+<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" 
+    "http://java.sun.com/dtd/web-app_2_3.dtd">
+<!--
+Copyright 2004 The Apache Software Foundation
+Licensed  under the  Apache License,  Version 2.0  (the "License");
+you may not use  this file  except in  compliance with the License.
+You may obtain a copy of the License at
+
+http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed  under the  License is distributed on an "AS IS" BASIS,
+WITHOUT  WARRANTIES OR CONDITIONS  OF ANY KIND, either  express  or
+implied.
+
+See the License for the specific language governing permissions and
+limitations under the License.
+-->
+<web-app>
+    <display-name>A web application deployment descriptor conforming to Servlet Specification 2.3</display-name>
+    <context-param>
+        <param-name>test-contextparam-name-one</param-name>
+        <param-value>test-contextparam-value-one</param-value>
+        <description>The first context parameter</description>
+    </context-param>
+    <context-param>
+        <param-name>test-contextparam-name-two</param-name>
+        <param-value>test-contextparam-value-two</param-value>
+        <description>The second context parameter</description>
+    </context-param>
+    <servlet>
+        <servlet-name>a-servlet-name</servlet-name>
+        <servlet-class>test.class.one</servlet-class>
+        <load-on-startup>1</load-on-startup>
+    </servlet>
+    <servlet>
+        <servlet-name>another-servlet-name</servlet-name>
+        <servlet-class>test.class.two</servlet-class>
+    </servlet>
+    <servlet-mapping>
+        <servlet-name>another-servlet-name</servlet-name>
+        <url-pattern>/somerequestpath</url-pattern>
+    </servlet-mapping>
+</web-app>

Propchange: portals/pluto/branches/pluto-1.0.2/descriptors/src/conf/org/apache/pluto/descriptors/servlet/web-2.3.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: portals/pluto/branches/pluto-1.0.2/descriptors/src/java/org/apache/pluto/descriptors/services/impl/AbstractCastorDescriptorService.java
URL: http://svn.apache.org/viewvc/portals/pluto/branches/pluto-1.0.2/descriptors/src/java/org/apache/pluto/descriptors/services/impl/AbstractCastorDescriptorService.java?rev=429058&r1=429057&r2=429058&view=diff
==============================================================================
--- portals/pluto/branches/pluto-1.0.2/descriptors/src/java/org/apache/pluto/descriptors/services/impl/AbstractCastorDescriptorService.java (original)
+++ portals/pluto/branches/pluto-1.0.2/descriptors/src/java/org/apache/pluto/descriptors/services/impl/AbstractCastorDescriptorService.java Sat Aug  5 14:26:35 2006
@@ -34,6 +34,7 @@
  * and writing deployment descriptors using Castor.
  *
  * @author <a href="ddewolf@apache.org">David H. DeWolf</a>
+ * @author <a href="esm@apache.org">Elliot Metsger</a>
  * @version $Id$
  * @since Mar 5, 2005
  */
@@ -95,24 +96,36 @@
         of.setLineWidth(600);
         of.setDoctype(getPublicId(), getDTDUri());
 
-        OutputStreamWriter writer =
-            new OutputStreamWriter(getOutputStream());
-        XMLSerializer serializer = new XMLSerializer(writer, of);
+	writeInternal(object, of);
+    }
 
-        try {
-            Marshaller marshaller =
-                new Marshaller(serializer.asDocumentHandler());
-            marshaller.setMapping(getCastorMapping());
-            marshaller.marshal(object);
-        } catch(IOException io) {
-            throw io;
-        } catch (Exception e) {
-            throw new IOException(e.getMessage());
-        }
-        finally {
+    /**
+     * Write the object graph to its descriptor, using the supplied <code>OutputFormat</code>
+     * @param object
+     * @param outputFormat
+     * @throws IOException
+     * @since Aug 5, 2006
+     */
+    protected void writeInternal(Object object, OutputFormat outputFormat) throws IOException {
+       OutputStream os = getOutputStream();
+       if (os == null)
+           System.out.println("outputstream is null");
+       OutputStreamWriter writer =  new OutputStreamWriter(os);
+       XMLSerializer serializer = new XMLSerializer(writer, outputFormat);
+
+       try {
+           Marshaller marshaller =
+               new Marshaller(serializer.asDocumentHandler());
+           marshaller.setMapping(getCastorMapping());
+           marshaller.marshal(object);
+       } catch(IOException io) {
+           throw io;
+       } catch (Exception e) {
+           throw new IOException(e.getMessage());
+       } finally {
             writer.flush();
             writer.close();
-        }
+       }
     }
 
     protected boolean getIgnoreExtraElements() {

Modified: portals/pluto/branches/pluto-1.0.2/descriptors/src/java/org/apache/pluto/descriptors/services/impl/AbstractWebAppDescriptorService.java
URL: http://svn.apache.org/viewvc/portals/pluto/branches/pluto-1.0.2/descriptors/src/java/org/apache/pluto/descriptors/services/impl/AbstractWebAppDescriptorService.java?rev=429058&r1=429057&r2=429058&view=diff
==============================================================================
--- portals/pluto/branches/pluto-1.0.2/descriptors/src/java/org/apache/pluto/descriptors/services/impl/AbstractWebAppDescriptorService.java (original)
+++ portals/pluto/branches/pluto-1.0.2/descriptors/src/java/org/apache/pluto/descriptors/services/impl/AbstractWebAppDescriptorService.java Sat Aug  5 14:26:35 2006
@@ -21,6 +21,7 @@
 import org.apache.pluto.descriptors.services.Constants;
 import org.apache.pluto.descriptors.services.WebAppDescriptorService;
 import org.apache.pluto.descriptors.servlet.WebAppDD;
+import org.apache.xml.serialize.OutputFormat;
 import org.exolab.castor.mapping.Mapping;
 import org.exolab.castor.mapping.MappingException;
 
@@ -88,7 +89,16 @@
      * @throws IOException
      */
     public void write(WebAppDD webApp) throws IOException {
-        writeInternal(webApp);
+        String servletVersion = webApp.getServletVersion();
+        if (servletVersion != null && servletVersion.equals("2.4")) {
+            OutputFormat of = new OutputFormat( );
+            of.setIndenting(true);
+            of.setIndent(2);
+            of.setLineWidth(600);
+            writeInternal(webApp,of);
+        } else {
+            writeInternal(webApp);
+        }
     }
 
     /**

Modified: portals/pluto/branches/pluto-1.0.2/descriptors/src/java/org/apache/pluto/descriptors/services/impl/FileWebAppDescriptorServiceImpl.java
URL: http://svn.apache.org/viewvc/portals/pluto/branches/pluto-1.0.2/descriptors/src/java/org/apache/pluto/descriptors/services/impl/FileWebAppDescriptorServiceImpl.java?rev=429058&r1=429057&r2=429058&view=diff
==============================================================================
--- portals/pluto/branches/pluto-1.0.2/descriptors/src/java/org/apache/pluto/descriptors/services/impl/FileWebAppDescriptorServiceImpl.java (original)
+++ portals/pluto/branches/pluto-1.0.2/descriptors/src/java/org/apache/pluto/descriptors/services/impl/FileWebAppDescriptorServiceImpl.java Sat Aug  5 14:26:35 2006
@@ -25,6 +25,7 @@
 /**
  *
  * @author <a href="ddewolf@apache.org">David H. DeWolf</a>
+ * @author <a href="esm@apache.org">Elliot Metsger</a>
  * @version $Id$
  * @since Mar 5, 2005
  */
@@ -37,6 +38,22 @@
     public FileWebAppDescriptorServiceImpl(File file) {
         super(file.getName());
         this.file = new File(file, WEB_XML_FILE);
+    }
+     
+    /**
+     * A constructor which allows the client to specify a context and the path
+     * to the web application deployment descriptor (web.xml).
+     * 
+     * This constructer was created to facilitate testing.
+     * 
+     * @param context the context path
+     * @param webXml the path to the web application deployment descriptor
+     * @see org.apache.pluto.descriptor.services.impl.FileWebAppDescriptorServiceImplTest
+     * @since Aug 5, 2006
+     */
+    public FileWebAppDescriptorServiceImpl(String context, String webXml) {
+        super(context);
+        this.file = new File(webXml);
     }
 
     protected InputStream getInputStream() throws IOException {

Added: portals/pluto/branches/pluto-1.0.2/descriptors/src/java/org/apache/pluto/descriptors/servlet/ServletVersionCastorFieldHandler.java
URL: http://svn.apache.org/viewvc/portals/pluto/branches/pluto-1.0.2/descriptors/src/java/org/apache/pluto/descriptors/servlet/ServletVersionCastorFieldHandler.java?rev=429058&view=auto
==============================================================================
--- portals/pluto/branches/pluto-1.0.2/descriptors/src/java/org/apache/pluto/descriptors/servlet/ServletVersionCastorFieldHandler.java (added)
+++ portals/pluto/branches/pluto-1.0.2/descriptors/src/java/org/apache/pluto/descriptors/servlet/ServletVersionCastorFieldHandler.java Sat Aug  5 14:26:35 2006
@@ -0,0 +1,52 @@
+/*
+ * Created on Feb 27, 2006
+ */
+package org.apache.pluto.descriptors.servlet;
+
+import org.exolab.castor.mapping.AbstractFieldHandler;
+
+public class ServletVersionCastorFieldHandler extends AbstractFieldHandler {
+
+    public Object getValue( Object webAppDD ) throws IllegalStateException {
+        if (! (webAppDD instanceof WebAppDD)) {
+            throw new ClassCastException("Error: the passed in type must be a org.apache.pluto.descriptors.servlet.WebAppDD");
+        }        
+        WebAppDD webApp = (WebAppDD)webAppDD;
+        if (webApp.getServletVersion().equals("2.3")) {
+            return null;
+        } else {
+            return webApp.getServletVersion();
+        }
+    }
+
+    public Object newInstance( Object arg0 ) throws IllegalStateException {
+        // Do nothing.
+        return null;
+    }
+
+    public Object newInstance( Object arg0, Object[] arg1 )
+            throws IllegalStateException {
+        // Do nothing.
+        return null;
+    }
+
+    public void resetValue( Object arg0 ) throws IllegalStateException,
+            IllegalArgumentException {
+        // Do nothing.
+
+    }
+
+    public void setValue( Object webAppDD, Object servletVersionValue )
+            throws IllegalStateException, IllegalArgumentException {
+        if (! (webAppDD instanceof WebAppDD)) {
+            throw new ClassCastException("Error: the passed in type must be a org.apache.pluto.descriptors.servlet.WebAppDD");
+        }
+        
+        if (! (servletVersionValue instanceof String)) {
+            throw new ClassCastException("Error: the passed in type must be a java.lang.String");
+        }
+
+        ((WebAppDD) webAppDD).setServletVersion((String) servletVersionValue);
+    }
+
+}

Propchange: portals/pluto/branches/pluto-1.0.2/descriptors/src/java/org/apache/pluto/descriptors/servlet/ServletVersionCastorFieldHandler.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: portals/pluto/branches/pluto-1.0.2/descriptors/src/java/org/apache/pluto/descriptors/servlet/ServletVersionCastorFieldHandler.java
------------------------------------------------------------------------------
    svn:keywords = Id

Modified: portals/pluto/branches/pluto-1.0.2/descriptors/src/java/org/apache/pluto/descriptors/servlet/WebAppDD.java
URL: http://svn.apache.org/viewvc/portals/pluto/branches/pluto-1.0.2/descriptors/src/java/org/apache/pluto/descriptors/servlet/WebAppDD.java?rev=429058&r1=429057&r2=429058&view=diff
==============================================================================
--- portals/pluto/branches/pluto-1.0.2/descriptors/src/java/org/apache/pluto/descriptors/servlet/WebAppDD.java (original)
+++ portals/pluto/branches/pluto-1.0.2/descriptors/src/java/org/apache/pluto/descriptors/servlet/WebAppDD.java Sat Aug  5 14:26:35 2006
@@ -31,6 +31,8 @@
  */
 public class WebAppDD {
 
+    // default to 2.3
+    private String servletVersion = "2.3";
     private IconDD icon;
     private String displayName;
     private String description;
@@ -269,6 +271,14 @@
             }
         }
         return null;
+    }
+
+    public String getServletVersion( ) {
+        return servletVersion;
+    }
+
+    public void setServletVersion( String servletVersion ) {
+        this.servletVersion = servletVersion;
     }
 }
 

Added: portals/pluto/branches/pluto-1.0.2/descriptors/src/test/org/apache/pluto/descriptors/services/impl/FileWebAppDescriptorServiceImplTest.java
URL: http://svn.apache.org/viewvc/portals/pluto/branches/pluto-1.0.2/descriptors/src/test/org/apache/pluto/descriptors/services/impl/FileWebAppDescriptorServiceImplTest.java?rev=429058&view=auto
==============================================================================
--- portals/pluto/branches/pluto-1.0.2/descriptors/src/test/org/apache/pluto/descriptors/services/impl/FileWebAppDescriptorServiceImplTest.java (added)
+++ portals/pluto/branches/pluto-1.0.2/descriptors/src/test/org/apache/pluto/descriptors/services/impl/FileWebAppDescriptorServiceImplTest.java Sat Aug  5 14:26:35 2006
@@ -0,0 +1,158 @@
+/*
+ * Created on Feb 27, 2006
+ */
+package org.apache.pluto.descriptors.services.impl;
+
+import java.io.File;
+import java.io.IOException;
+
+import junit.framework.TestCase;
+
+import org.apache.pluto.descriptors.services.WebAppDescriptorService;
+import org.apache.pluto.descriptors.servlet.WebAppDD;
+
+public class FileWebAppDescriptorServiceImplTest extends TestCase {
+    
+    private static final String SERVLET_23_WEB_XML = "web-2.3.xml";
+    private static final String SERVLET_24_WEB_XML = "web.xml";
+
+    /**
+     * Tests method for 'org.apache.pluto.descriptors.services.impl.FileWebAppDescriptorServiceImpl.read()'
+     * 
+     * This test uses the FileWebAppDescriptorServiceImpl implementation of the WebAppDescriptorService to
+     * read a web application deployment descriptor, and checks to see that the servlet version is correctly
+     * set to "2.3".
+     * 
+     * @throws Exception
+     */
+    public void testServlet23Read() throws Exception {
+        String webXmlPath = WebAppDD.class.getResource(SERVLET_23_WEB_XML).getPath();
+        WebAppDescriptorService descSvc = createService("/testcontext", webXmlPath);
+        WebAppDD webDD = null;
+        try {
+            // Use the FileWebAppDescriptorServiceImpl to read in our test servlet 2.3 web.xml file.
+            webDD = descSvc.read();
+        } catch (IOException ioe) {
+            String msg = "Encountered an IOException while trying to read " + webXmlPath;
+            System.out.println(msg);
+            ioe.printStackTrace();
+            throw ioe;
+        }
+        // make sure the test web.xml file was unmarshaled.
+        assertNotNull(webDD);
+        
+        // ensure that the Servlet Version is 2.3
+        assertEquals( "2.3", webDD.getServletVersion());       
+    }
+
+    /**
+     * Tests method for 'org.apache.pluto.descriptors.services.impl.FileWebAppDescriptorServiceImpl.write()'
+     * 
+     * This test uses the FileWebAppDescriptorServiceImpl implementation of the WebAppDescriptorService to
+     * write a web application deployment descriptor, and checks to see that the servlet version is correctly
+     * set to "2.3".
+     * 
+     * @throws Exception
+     */
+    public void testServlet23Write() throws Exception {
+        // Use an instance of the FileWebAppDescriptor service to read in our web.xml file.
+        // We use the read() method to create our WebAppDD object that we'll use below.        
+        String webXmlPath = WebAppDD.class.getResource(SERVLET_23_WEB_XML).getPath();
+        WebAppDescriptorService descSvc = createService("/testcontext", webXmlPath);
+        WebAppDD webDD = descSvc.read();
+        assertNotNull(webDD);
+        assertEquals("2.3", webDD.getServletVersion());        
+        
+        // Create a second instance of the FileWebAppDescriptorImpl service to write out a web.xml file.
+        // We don't use the same instance as above because the FileWebAppDescriptorImpl service uses the
+        // same InputStream for reading and writing and we'd overwrite our test web.xml.
+        String testOutputDir = WebAppDD.class.getResource(".").getPath();        
+        descSvc = createService("/testcontext", testOutputDir + "/testWeb23.xml");        
+        
+        // write out the file (it must exist before marshaling)
+        new File( testOutputDir + "/testWeb23.xml").createNewFile();
+        descSvc.write(webDD);
+        
+        // Ok, we've written out a test file; lets read it back in with yet another instance of a FileWebAppDescriptorImpl
+        // and make sure that we can recover the version of the WebAppDD object.
+        webDD = null;
+        descSvc = createService("/testcontext", testOutputDir + "/testWeb23.xml");
+        webDD = descSvc.read();
+                
+        // Servlet Version should be equal to "2.3"
+        assertNotNull(webDD);
+        assertEquals("2.3", webDD.getServletVersion());                              
+    }
+
+    /**
+     * Tests method for 'org.apache.pluto.descriptors.services.impl.FileWebAppDescriptorServiceImpl.read()'
+     * 
+     * This test uses the FileWebAppDescriptorServiceImpl implementation of the WebAppDescriptorService to
+     * read a web application deployment descriptor, and checks to see that the servlet version is correctly
+     * set to "2.4".
+     * 
+     * @throws Exception
+     */
+    public void testServlet24Read() throws Exception {
+        String webXmlPath = WebAppDD.class.getResource(SERVLET_24_WEB_XML).getPath();            
+        WebAppDescriptorService descSvc = createService("/testcontext", webXmlPath);
+        WebAppDD webDD = null;
+        try {
+            // Use the FileWebAppDescriptorServiceImpl to read in our test servlet 2.4 web.xml file.
+            webDD = descSvc.read();
+        } catch (IOException ioe) {
+            String msg = "Encountered an IOException while trying to read " + webXmlPath;
+            System.out.println(msg);
+            ioe.printStackTrace();
+            throw ioe;
+        }
+        
+        // make sure the test web.xml file was unmarshaled.
+        assertNotNull(webDD);        
+        // ensure that the Servlet Version is 2.4
+        assertEquals( "2.4", webDD.getServletVersion());
+    }
+
+    /**
+     * Tests method for 'org.apache.pluto.descriptors.services.impl.FileWebAppDescriptorServiceImpl.write()'
+     * 
+     * This test uses the FileWebAppDescriptorServiceImpl implementation of the WebAppDescriptorService to
+     * write a web application deployment descriptor, and checks to see that the servlet version is correctly
+     * set to "2.4".
+     * 
+     * @throws Exception
+     */
+    public void testServlet24Write( ) throws Exception {
+        // Use an instance of the FileWebAppDescriptor service to read in our web.xml file.
+        // We use the read() method to create our WebAppDD object that we'll write out below.
+        String webXmlPath = WebAppDD.class.getResource(SERVLET_24_WEB_XML).getPath();
+        WebAppDescriptorService descSvc = createService("/testcontext", webXmlPath);
+        WebAppDD webDD = descSvc.read();
+        
+        // Create a second instance of the FileWebAppDescriptorImpl service to write out a web.xml file.
+        // We don't use the same instance as above because the FileWebAppDescriptorImpl service uses the
+        // same InputStream for reading and writing and we'd overwrite our test web.xml.
+        String testOutputWebXmlPath = WebAppDD.class.getResource(".").getPath().concat("/testWeb24.xml");        
+        descSvc = createService("/testcontext", testOutputWebXmlPath);        
+        
+        // output file must exist first
+        new File(testOutputWebXmlPath).createNewFile();
+        // write out the file        
+        descSvc.write(webDD);
+        
+        // Ok, we've written out a test file; lets read it back in with yet another instance of a FileWebAppDescriptorImpl
+        // and make sure that we can recover the version of the WebAppDD object.
+        webDD = null;
+        descSvc = createService("/testcontext", testOutputWebXmlPath);
+        webDD = descSvc.read();
+                
+        // Servlet Version should be equal to "2.4"
+        assertEquals("2.4", webDD.getServletVersion()); 
+    }
+    
+    private WebAppDescriptorService createService(String context, String webXmlFilePath) {
+        FileWebAppDescriptorServiceImpl fileSvcImpl = new FileWebAppDescriptorServiceImpl(context, webXmlFilePath);
+        return fileSvcImpl;
+    }
+    
+}

Propchange: portals/pluto/branches/pluto-1.0.2/descriptors/src/test/org/apache/pluto/descriptors/services/impl/FileWebAppDescriptorServiceImplTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: portals/pluto/branches/pluto-1.0.2/descriptors/src/test/org/apache/pluto/descriptors/services/impl/FileWebAppDescriptorServiceImplTest.java
------------------------------------------------------------------------------
    svn:keywords = Id

Added: portals/pluto/branches/pluto-1.0.2/descriptors/src/test/org/apache/pluto/descriptors/servlet/WebAppDDVersionTest.java
URL: http://svn.apache.org/viewvc/portals/pluto/branches/pluto-1.0.2/descriptors/src/test/org/apache/pluto/descriptors/servlet/WebAppDDVersionTest.java?rev=429058&view=auto
==============================================================================
--- portals/pluto/branches/pluto-1.0.2/descriptors/src/test/org/apache/pluto/descriptors/servlet/WebAppDDVersionTest.java (added)
+++ portals/pluto/branches/pluto-1.0.2/descriptors/src/test/org/apache/pluto/descriptors/servlet/WebAppDDVersionTest.java Sat Aug  5 14:26:35 2006
@@ -0,0 +1,222 @@
+/*
+ * Copyright 2006 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.pluto.descriptors.servlet;
+
+import java.io.FileWriter;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.net.URL;
+
+import junit.framework.TestCase;
+
+import org.apache.xml.serialize.OutputFormat;
+import org.apache.xml.serialize.XMLSerializer;
+import org.exolab.castor.mapping.Mapping;
+import org.exolab.castor.mapping.MappingException;
+import org.exolab.castor.xml.MarshalException;
+import org.exolab.castor.xml.Marshaller;
+import org.exolab.castor.xml.Unmarshaller;
+import org.exolab.castor.xml.ValidationException;
+
+
+/**
+ * Unit tests for PLUTO-216
+ *  
+ * @author <a href="mailto:emetsger@jhu.edu">Elliot Metsger</a>
+ * @version $Id$
+ * @since Feb 27, 2006
+ */
+public class WebAppDDVersionTest extends TestCase {
+    
+    boolean debug = false;
+
+    protected void setUp( ) throws Exception {
+        super.setUp( );
+        this.debug = false;
+    }
+    
+    public void testUnMarshalServletVersion2dot4( ) throws Exception {
+        WebAppDD config = unMarshalWebAppDD( "castor-web-xml-mapping.xml", "web.xml" );
+        assertEquals( "2.4", config.getServletVersion(  ) );        
+    }
+    
+    public void testUnMarshalServletVersion2dot3( ) throws Exception {
+        WebAppDD config = unMarshalWebAppDD( "castor-web-xml-mapping.xml", "web-2.3.xml" );
+        assertEquals( "2.3", config.getServletVersion( ) );
+    }
+    
+    /**
+     * This test attempts to unmarshal, marshal, and unmarshal a web application descriptor, testing
+     * to see if the <code>version</code> attribute of the <code>web-app</code> element is
+     * preserved.  This test uses a servlet descriptor purportedly conforming to Servlet
+     * Specification 2.4.
+     * 
+     * This test expects to find a <code>version</code> attribute equal to the string "2.4".
+     * 
+     * @throws Exception
+     */
+    public void testMarshalServletVersion2dot4( ) throws Exception {        
+        // first unmarshal the 2.4 web.xml
+        WebAppDD config = unMarshalWebAppDD( "castor-web-xml-mapping.xml", "web.xml" );        
+        assertEquals( "2.4", config.getServletVersion(  ) );
+        
+        // create a new OutputFormat for marshaling/serialization
+        OutputFormat of = new OutputFormat( );
+        of.setIndenting( true );
+        of.setIndent( 4 ); // 2-space indention
+        of.setLineWidth( 16384 ); // As large as needed to prevent linebreaks in text nodes
+        // marshal the web.xml
+        marshalWebAppDD( "castor-web-xml-mapping.xml", "testWeb24.xml", config, of );
+        
+        // unmarshal our test web.xml
+        WebAppDD testWebXml = unMarshalWebAppDD( "castor-web-xml-mapping.xml", "testWeb24.xml" );
+        
+        // test to see if the version attribute is preserved
+        assertEquals( "2.4", testWebXml.getServletVersion( ) );
+        
+        // null out references (is this required???)
+        config = null;
+        testWebXml = null;
+        of = null;        
+    }
+    
+    /**
+     * This test attempts to unmarshal, marshal, and unmarshal a web application descriptor, testing
+     * to see if the <code>version</code> attribute of the <code>web-app</code> element is
+     * preserved.  This test uses a servlet descriptor purportedly conforming to Servlet
+     * Specification 2.3.
+     * 
+     * This test expects to find a <code>version</code> attribute equal to "2.3".
+     * 
+     * @throws Exception
+     */
+    public void testMarshalServletVersion2dot3( ) throws Exception {
+        // first unmarshal the 2.3 web.xml        
+        WebAppDD config = unMarshalWebAppDD( "castor-web-xml-mapping.xml", "web-2.3.xml" );        
+        assertEquals( "2.3", config.getServletVersion( ) );
+        
+        // create a new OuputFormat for marshaling/serialization
+        OutputFormat of = new OutputFormat( );
+        of.setIndenting( true );
+        of.setIndent( 4 ); // 2-space indention
+        of.setLineWidth( 16384 ); // As large as needed to prevent linebreaks in text nodes
+        of.setDoctype(
+             "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN",
+             "http://java.sun.com/dtd/web-app_2_3.dtd");
+        
+        // marshal the web.xml
+        marshalWebAppDD( "castor-web-xml-mapping.xml", "testWeb23.xml", config, of );
+        
+        // unmarshal our test web.xml
+        WebAppDD testWebXml = unMarshalWebAppDD( "castor-web-xml-mapping.xml", "testWeb23.xml" );
+        
+        // test to see if the version attribute is preserved (in this case the version should be 
+        // equal to 2.3)
+        assertEquals( "2.3", testWebXml.getServletVersion( ) );
+        
+        // null out references (is this required???)
+        config = null;
+        testWebXml = null;
+        of = null;
+    }    
+    
+    /**
+     * Unmarshals a servlet web application deployment descriptor using the specified Castor
+     * mapping filename and web.xml file name.  The file names should not be absolute; the
+     * classpath will be searched for both files.
+     * 
+     * @param castorMappingFileName the Castor mapping to use; the classpath will be searched for the file name.
+     * @param webXmlFileName the web.xml file to unmarshal; the classpath will be searched for the file name.
+     * @return WebAppDD the unmarshaled web application deployment descriptor.
+     */
+    private WebAppDD unMarshalWebAppDD( String castorMappingFileName, String webXmlFileName ) throws Exception {        
+        URL webXmlMapping = null;
+        URL webXml = null;
+        WebAppDD config = null;
+        
+        // portions of this code scavenged from WebAppDDTest!
+        try {
+            webXmlMapping = getClass().getResource( castorMappingFileName );
+            Mapping mapping = new Mapping();
+            mapping.loadMapping(webXmlMapping);
+            webXml = getClass( ).getResource( webXmlFileName );            
+            InputStream webXmlIs = webXml.openStream( );
+            Unmarshaller unmarshaller = new Unmarshaller(mapping);
+            unmarshaller.setIgnoreExtraElements(false);
+            unmarshaller.setDebug(debug);
+            config = (WebAppDD)unmarshaller.unmarshal(new InputStreamReader(webXmlIs));
+            assertTrue(config!=null);
+        } catch ( MappingException me ) {
+            String msg = "Encountered mapping exception when unmarshaling " +
+                    webXml.getPath( ) + " with Castor mapping file " + webXmlMapping.getPath( );
+            System.out.println( msg );
+            me.printStackTrace( System.out );
+            throw me;
+        } catch ( MarshalException me ) {
+            String msg = "Encountered a marshaling exception when unmarshaling " +
+                webXml.getPath( ) + " with Castor mapping file " + webXmlMapping.getPath( );
+            System.out.println( msg );
+            me.printStackTrace( System.out );
+            throw me;
+        } catch ( ValidationException ve ) {
+            String msg = "Encountered a validation exception when unmarshaling " +
+                webXml.getPath( ) + " with Castor mapping file " + webXmlMapping.getPath( );
+            System.out.println( msg );
+            ve.printStackTrace( );
+            throw ve;
+        } catch ( IOException ioe ) {
+            String msg = "Encountered i/o exception when unmarshaling " +            
+                webXml.getPath( ) + " with Castor mapping file " + webXmlMapping.getPath( ) +
+                ".  Check to be sure the files exist!";
+            System.out.println( msg );
+            ioe.printStackTrace( System.out );
+            throw ioe;            
+        }
+        
+        return config;        
+    }    
+    
+    /**
+     * Marshals the supplied servlet web application deployment descriptor using the specified Castor
+     * mapping filename and OutputFormat  The marshaled output will be output to the file specified 
+     * by <code>outputWebXmlFileName</code>.
+     * 
+     * The classpath will be searched for the <code>castorMappingFileName</code>, but an absolute
+     * or relative path may be specified for <code>outputWebXmlFileName</code>.
+     * 
+     * @param castorMappingFileName the Castor mapping to use; the classpath will be searched for the file name.
+     * @param outputWebXmlFileName the unmarshaled web application deployment descriptor will be written here.
+     * @param webApp represents the web application deployment descriptor to be marshaled.
+     * @param of the <code>org.apache.xml.serialize.OutputFormat</code> used to serialize the web.xml file.
+     */
+    private void marshalWebAppDD( String castorMappingFileName, String outputWebXmlFileName, WebAppDD webApp, 
+            OutputFormat of ) throws Exception {
+        // portions of this code scavenged from WebAppDDTest!
+        URL webXmlMapping = getClass( ).getResource( castorMappingFileName );
+        Mapping mapping = new Mapping( );
+        mapping.loadMapping( webXmlMapping );
+        // the serialized webapp descriptor should go in the classpath so that 
+        // we can unmarshal it later using unMarshalWebAppDD()
+        FileWriter writer = new FileWriter( webApp.getClass().getResource(".").getPath().concat( "/" + outputWebXmlFileName ) );
+        XMLSerializer serializer = new XMLSerializer(writer, of);        
+        Marshaller marsh = new Marshaller(serializer.asDocumentHandler());
+        marsh.setDebug(debug);
+        marsh.setMapping(mapping);
+        marsh.marshal(webApp);             
+    }
+    
+}

Propchange: portals/pluto/branches/pluto-1.0.2/descriptors/src/test/org/apache/pluto/descriptors/servlet/WebAppDDVersionTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: portals/pluto/branches/pluto-1.0.2/descriptors/src/test/org/apache/pluto/descriptors/servlet/WebAppDDVersionTest.java
------------------------------------------------------------------------------
    svn:keywords = Id