You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tomee.apache.org by db...@apache.org on 2010/07/23 22:24:47 UTC

svn commit: r967244 [2/2] - in /openejb/branches/openejb-3.1.x: ./ container/openejb-activemq4/src/test/java/org/apache/openejb/core/mdb/ container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/ container/openejb-core/src/main/java/or...

Modified: openejb/branches/openejb-3.1.x/container/openejb-jee/src/test/java/org/apache/openejb/jee/JeeTest.java
URL: http://svn.apache.org/viewvc/openejb/branches/openejb-3.1.x/container/openejb-jee/src/test/java/org/apache/openejb/jee/JeeTest.java?rev=967244&r1=967243&r2=967244&view=diff
==============================================================================
--- openejb/branches/openejb-3.1.x/container/openejb-jee/src/test/java/org/apache/openejb/jee/JeeTest.java (original)
+++ openejb/branches/openejb-3.1.x/container/openejb-jee/src/test/java/org/apache/openejb/jee/JeeTest.java Fri Jul 23 20:24:46 2010
@@ -17,16 +17,12 @@
  */
 package org.apache.openejb.jee;
 
-import java.io.BufferedInputStream;
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.File;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Properties;
+import junit.framework.TestCase;
+import org.xml.sax.Attributes;
+import org.xml.sax.InputSource;
+import org.xml.sax.SAXException;
+import org.xml.sax.XMLReader;
+import org.xml.sax.helpers.XMLFilterImpl;
 
 import javax.xml.bind.JAXBContext;
 import javax.xml.bind.JAXBElement;
@@ -37,16 +33,19 @@ import javax.xml.bind.ValidationEventHan
 import javax.xml.parsers.SAXParser;
 import javax.xml.parsers.SAXParserFactory;
 import javax.xml.transform.sax.SAXSource;
-
-import junit.framework.TestCase;
-
-import org.xml.sax.Attributes;
-import org.xml.sax.InputSource;
-import org.xml.sax.SAXException;
-import org.xml.sax.XMLReader;
-import org.xml.sax.helpers.XMLFilterImpl;
+import java.io.BufferedInputStream;
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Properties;
 
 /**
+ * @version $Revision$ $Date$
  */
 public class JeeTest extends TestCase {
     public void testEjbJar() throws Exception {
@@ -91,7 +90,7 @@ public class JeeTest extends TestCase {
         String fileName = "ejb-jar-mdb-2.0.xml";
         InputStream in = this.getClass().getClassLoader().getResourceAsStream(fileName);
 
-        Object o = JaxbJavaee.unmarshalJavaee(EjbJar.class, in);
+        Object o = JaxbJavaee.unmarshal(EjbJar.class, in);
 
         EjbJar ejbJar = (EjbJar) o;
 
@@ -115,92 +114,97 @@ public class JeeTest extends TestCase {
     }
 
     public void testApplication() throws Exception {
-        marshalAndUnmarshal(Application.class, "application-example.xml", null);
+        marshalAndUnmarshal(Application.class, "application-example.xml");
     }
 
     public void testApplicationClient() throws Exception {
-        marshalAndUnmarshal(ApplicationClient.class, "application-client-example.xml", null);
+        marshalAndUnmarshal(ApplicationClient.class, "application-client-example.xml");
     }
 
-//    public void testWar() throws Exception {
-//        marshalAndUnmarshal(WebApp.class, "web-example.xml", "web-example-expected.xml");
-//    }
+    public void testWar() throws Exception {
+        marshalAndUnmarshal(WebApp.class, "web-example.xml");
+    }
 
-//    public void testWar2_3() throws Exception {
-//        marshalAndUnmarshal(WebApp.class, "web_2.3-example.xml", "web_2.3-example-expected.xml");
-//    }
+    public void testWar2_3() throws Exception {
+        marshalAndUnmarshal(WebApp.class, "web_2.3-example.xml");
+    }
 
     public void testTld() throws Exception {
-        marshalAndUnmarshal(TldTaglib.class, "tld-example.xml", null);
+        marshalAndUnmarshal(TldTaglib.class, "tld-example.xml");
     }
 
     public void testRar10() throws Exception {
-        Connector10 c10 = marshalAndUnmarshal(Connector10.class, "connector-1.0-example.xml", null);
-        Connector c = Connector.newConnector(c10);
-        JAXBContext ctx = JAXBContextFactory.newInstance(Connector.class);
-        Marshaller marshaller = ctx.createMarshaller();
-        marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
-
-        ByteArrayOutputStream baos = new ByteArrayOutputStream();
-        marshaller.marshal(c, baos);
-
-        byte[] bytes = baos.toByteArray();
-        String actual = new String(bytes);
-
-        String expected;
-            InputStream in2 = this.getClass().getClassLoader().getResourceAsStream("connector-1.0-example-expected-1.6.xml");
-            expected = readContent(in2);
-
-        try {
-            StaxCompare.compare(expected, actual);
-        } catch (Exception e) {
-//            System.out.append(actual);
-            writeToTmpFile(bytes, "connector-1.0-example.xml");
-            throw e;
-        }
+        marshalAndUnmarshal(Connector10.class, "connector-1.0-example.xml");
     }
 
     public void testRar15() throws Exception {
-        marshalAndUnmarshal(Connector.class, "connector-1.5-example.xml", null);
+        marshalAndUnmarshal(Connector.class, "connector-1.5-example.xml");
     }
 
     public void testRar16() throws Exception {
-        marshalAndUnmarshal(Connector.class, "connector-1.6-example.xml", null);
+        marshalAndUnmarshal(Connector.class, "connector-1.6-example.xml");
     }
 
-    public static <T> T marshalAndUnmarshal(Class<T> type, String sourceXmlFile, String expectedXmlFile) throws Exception {
-        InputStream in = JeeTest.class.getClassLoader().getResourceAsStream(sourceXmlFile);
-        T object = (T)JaxbJavaee.unmarshalJavaee(type, in);
-        in.close();
-        assertTrue(object.getClass().isAssignableFrom(type));
+    /**
+     * This test requires that there are three managed beans in faces-config.xml. It will ask JaxbJavaee to load faces-config.xml
+     * and then assert if it found the three managed beans and checks if the class names are correct
+     *
+     * @throws Exception
+     */
+    public void testFacesConfig() throws Exception {
+        List<String> managedBeanClasses = new ArrayList<String>();
+        managedBeanClasses.add("org.apache.openejb.faces.EmployeeBean");
+        managedBeanClasses.add("org.apache.openejb.faces.OneBean");
+        managedBeanClasses.add("org.apache.openejb.faces.TwoBean");
+        InputStream inputStream = this.getClass().getClassLoader().getResourceAsStream("faces-config.xml");
+        JAXBElement<FacesConfig> element = (JAXBElement<FacesConfig>) JaxbJavaee.unmarshal(FacesConfig.class, inputStream);
+        FacesConfig facesConfig = element.getValue();
+        List<FacesManagedBean> managedBean = facesConfig.getManagedBean();
+
+        for (FacesManagedBean bean : managedBean) {
+            assertTrue(managedBeanClasses.contains(bean.getManagedBeanClass().trim()));
+        }
+        assertEquals(3, managedBean.size());
+
+        marshalAndUnmarshal(FacesConfig.class, "faces-config.xml");
+    }
+
+    private <T> void marshalAndUnmarshal(Class<T> type, String xmlFileName) throws Exception {
+        SAXParserFactory factory = SAXParserFactory.newInstance();
+        factory.setNamespaceAware(true);
+        factory.setValidating(false);
+        SAXParser parser = factory.newSAXParser();
 
         JAXBContext ctx = JAXBContextFactory.newInstance(type);
+        Unmarshaller unmarshaller = ctx.createUnmarshaller();
+
+        NamespaceFilter xmlFilter = new NamespaceFilter(parser.getXMLReader());
+        xmlFilter.setContentHandler(unmarshaller.getUnmarshallerHandler());
+        unmarshaller.setEventHandler(new TestValidationEventHandler());
+
+        InputStream in = this.getClass().getClassLoader().getResourceAsStream(xmlFileName);
+        String expected = readContent(in);
+
+        SAXSource source = new SAXSource(xmlFilter, new InputSource(new ByteArrayInputStream(expected.getBytes())));
+
+        Object object = unmarshaller.unmarshal(source);
+
         Marshaller marshaller = ctx.createMarshaller();
         marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
 
         ByteArrayOutputStream baos = new ByteArrayOutputStream();
         marshaller.marshal(object, baos);
 
-        byte[] bytes = baos.toByteArray();
-        String actual = new String(bytes);
-
-        String expected;
-        if (expectedXmlFile == null) {
-            InputStream in2 = JeeTest.class.getClassLoader().getResourceAsStream(sourceXmlFile);
-            expected = readContent(in2);
-        } else {
-            InputStream in2 = JeeTest.class.getClassLoader().getResourceAsStream(expectedXmlFile);
-            expected = readContent(in2);
-        }
-
-        try {
-            StaxCompare.compare(expected, actual);
-        } catch (Exception e) {
-//            System.out.append(actual);
-            writeToTmpFile(bytes, sourceXmlFile);
-            throw e;
-        }
-        return object;
+//        byte[] bytes = baos.toByteArray();
+//        String actual = new String(bytes);
+//
+//        try {
+//            Diff myDiff = new Diff(expected, actual);
+//            assertTrue("Files are similar " + myDiff, myDiff.similar());
+//        } catch (AssertionFailedError e) {
+//            writeToTmpFile(bytes, xmlFileName);
+//            throw e;
+//        }
     }
 
     public static class NamespaceFilter extends XMLFilterImpl {
@@ -219,7 +223,7 @@ public class JeeTest extends TestCase {
         }
     }
 
-    private static void writeToTmpFile(byte[] bytes, String xmlFileName) {
+    private void writeToTmpFile(byte[] bytes, String xmlFileName) {
         try {
             File tempFile = File.createTempFile("jaxb-output", "xml");
             FileOutputStream out = new FileOutputStream(tempFile);
@@ -231,17 +235,13 @@ public class JeeTest extends TestCase {
         }
     }
 
-    private static String readContent(InputStream in) throws IOException {
+    private String readContent(InputStream in) throws IOException {
         StringBuffer sb = new StringBuffer();
         in = new BufferedInputStream(in);
-        try {
-            int i = in.read();
-            while (i != -1) {
-                sb.append((char) i);
-                i = in.read();
-            }
-        } finally {
-            in.close();
+        int i = in.read();
+        while (i != -1) {
+            sb.append((char) i);
+            i = in.read();
         }
         String content = sb.toString();
         return content;
@@ -250,7 +250,6 @@ public class JeeTest extends TestCase {
     private static class TestValidationEventHandler implements ValidationEventHandler {
         public boolean handleEvent(ValidationEvent validationEvent) {
             System.out.println(validationEvent.getMessage());
-            System.out.println(validationEvent.getLocator());
             return false; // if an error occurs we must be aware of
         }
     }

Modified: openejb/branches/openejb-3.1.x/container/openejb-jee/src/test/resources/connector-1.0-example.xml
URL: http://svn.apache.org/viewvc/openejb/branches/openejb-3.1.x/container/openejb-jee/src/test/resources/connector-1.0-example.xml?rev=967244&r1=967243&r2=967244&view=diff
==============================================================================
--- openejb/branches/openejb-3.1.x/container/openejb-jee/src/test/resources/connector-1.0-example.xml (original)
+++ openejb/branches/openejb-3.1.x/container/openejb-jee/src/test/resources/connector-1.0-example.xml Fri Jul 23 20:24:46 2010
@@ -1,7 +1,7 @@
 <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
 <!DOCTYPE connector PUBLIC
-        "-//Sun Microsystems, Inc.//DTD Connector 1.0//EN"
-        "http://java.sun.com/dtd/connector_1_0.dtd">
+	"-//Sun Microsystems, Inc.//DTD Connector 1.0//EN"
+	"http://java.sun.com/dtd/connector_1_0.dtd">
 <!--
 
     Licensed to the Apache Software Foundation (ASF) under one or more
@@ -38,24 +38,35 @@
         <license-required>true</license-required>
     </license>
     <resourceadapter id="ID025">
-        <managedconnectionfactory-class>managedconnectionfactory-class0</managedconnectionfactory-class>
+        <!--<resourceadapter-class>resourceadapter-class0</resourceadapter-class>-->
+        <!--<config-property id="ID029">-->
+            <!--<description xml:lang="" id="ID031">description2</description>-->
+            <!--<config-property-name>config-property-name0</config-property-name>-->
+            <!--<config-property-type>java.lang.Boolean</config-property-type>-->
+            <!--<config-property-value>config-property-value0</config-property-value>-->
+        <!--</config-property>-->
+        <!--<outbound-resourceadapter id="ID039">-->
+            <!--<connection-definition id="ID041">-->
+                <managedconnectionfactory-class>managedconnectionfactory-class0</managedconnectionfactory-class>
         <connectionfactory-interface>connectionfactory-interface0</connectionfactory-interface>
         <connectionfactory-impl-class>connectionfactory-impl-class0</connectionfactory-impl-class>
         <connection-interface>connection-interface0</connection-interface>
         <connection-impl-class>connection-impl-class0</connection-impl-class>
         <transaction-support>NoTransaction</transaction-support>
-        <config-property id="ID045">
-            <description xml:lang="en-US" id="ID047">description3</description>
-            <config-property-name>config-property-name1</config-property-name>
-            <config-property-type>java.lang.Boolean</config-property-type>
-            <config-property-value>config-property-value1</config-property-value>
-        </config-property>
-        <authentication-mechanism id="ID109">
-            <description xml:lang="en-US" id="ID111">description6</description>
-            <authentication-mechanism-type>authentication-mechanism-type0</authentication-mechanism-type>
-            <credential-interface>javax.resource.spi.security.PasswordCredential</credential-interface>
-        </authentication-mechanism>
-        <reauthentication-support>true</reauthentication-support>
+                <config-property id="ID045">
+                    <description xml:lang="en-US" id="ID047">description3</description>
+                    <config-property-name>config-property-name1</config-property-name>
+                    <config-property-type>java.lang.Boolean</config-property-type>
+                    <config-property-value>config-property-value1</config-property-value>
+                </config-property>
+            <!--</connection-definition>-->
+            <authentication-mechanism id="ID109">
+                <description xml:lang="en-US" id="ID111">description6</description>
+                <authentication-mechanism-type>authentication-mechanism-type0</authentication-mechanism-type>
+                <credential-interface>javax.resource.spi.security.PasswordCredential</credential-interface>
+            </authentication-mechanism>
+            <reauthentication-support>true</reauthentication-support>
+        <!--</outbound-resourceadapter>-->
         <security-permission id="ID181">
             <description xml:lang="" id="ID183">description11</description>
             <security-permission-spec>security-permission-spec0</security-permission-spec>

Modified: openejb/branches/openejb-3.1.x/container/openejb-jee/src/test/resources/web_2.3-example.xml
URL: http://svn.apache.org/viewvc/openejb/branches/openejb-3.1.x/container/openejb-jee/src/test/resources/web_2.3-example.xml?rev=967244&r1=967243&r2=967244&view=diff
==============================================================================
--- openejb/branches/openejb-3.1.x/container/openejb-jee/src/test/resources/web_2.3-example.xml (original)
+++ openejb/branches/openejb-3.1.x/container/openejb-jee/src/test/resources/web_2.3-example.xml Fri Jul 23 20:24:46 2010
@@ -17,9 +17,9 @@
 
     <!-- $Rev$ $Date$ -->
 
-<!DOCTYPE web-app
-    PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
-    "http://java.sun.com/dtd/web-app_2_3.dtd">
+<!--<!DOCTYPE web-app -->
+<!--    PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" -->
+<!--    "http://java.sun.com/dtd/web-app_2_3.dtd">-->
 
 <web-app id="ID001">
     <icon id="ID967">

Propchange: openejb/branches/openejb-3.1.x/examples/alternate-descriptors/src/main/resources/META-INF/test.ejb-jar.xml
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Fri Jul 23 20:24:46 2010
@@ -1,2 +1,2 @@
 /openejb/branches/openejb-3.1.1/examples/alternate-descriptors/src/main/resources/META-INF/ejb-jar.xml:779593
-/openejb/trunk/openejb3/examples/alternate-descriptors/src/main/resources/META-INF/test.ejb-jar.xml:943472,943862,943965,944757,945989,946399,946485,946489,946705,946792,946805,946814,946861,946863-946864,947010,947017,947042,948022,948241,948243,948548,949014,949233,950391,950801,951611,953191,953196,953556,955104,955496,957463,962382,962750
+/openejb/trunk/openejb3/examples/alternate-descriptors/src/main/resources/META-INF/test.ejb-jar.xml:943472,943862,943965,944757,945989,946399,946485,946489,946705,946792,946805,946814,946861,946863-946864,947010,947017,947042,948022,948241,948243,948548,949014,949233,950391,950801,951611,953191,953196,953556,955104,955496,962382,962750