Author: hiranya
Date: Sat May  1 09:38:35 2010
New Revision: 939961

URL: http://svn.apache.org/viewvc?rev=939961&view=rev
Log:
Updated the local entry config test cases. Related to SYNAPSE-624.


Modified:
    
synapse/trunk/java/modules/core/src/test/java/org/apache/synapse/config/xml/LocalEntryConfigurationTest.java

Modified: 
synapse/trunk/java/modules/core/src/test/java/org/apache/synapse/config/xml/LocalEntryConfigurationTest.java
URL: 
http://svn.apache.org/viewvc/synapse/trunk/java/modules/core/src/test/java/org/apache/synapse/config/xml/LocalEntryConfigurationTest.java?rev=939961&r1=939960&r2=939961&view=diff
==============================================================================
--- 
synapse/trunk/java/modules/core/src/test/java/org/apache/synapse/config/xml/LocalEntryConfigurationTest.java
 (original)
+++ 
synapse/trunk/java/modules/core/src/test/java/org/apache/synapse/config/xml/LocalEntryConfigurationTest.java
 Sat May  1 09:38:35 2010
@@ -20,6 +20,7 @@
 package org.apache.synapse.config.xml;
 
 import org.apache.axiom.om.OMElement;
+import org.apache.axiom.om.util.AXIOMUtil;
 import org.apache.axiom.om.impl.builder.StAXOMBuilder;
 import org.apache.synapse.config.Entry;
 
@@ -30,118 +31,224 @@ import java.io.StringReader;
 
 public class LocalEntryConfigurationTest extends AbstractTestCase {
 
+    private String key = "myEntry";
+
     public void testSimpleTextEntry() {
-        String text = "Apache Synapse";
+        String text = "Apache Synapse - 2.0";
         String entrySrc = "<localEntry 
xmlns=\"http://synapse.apache.org/ns/2010/04/configuration\"; " +
-                "key=\"foo\"><![CDATA[" + text + "]]></localEntry>";
+                "key=\"" + key + "\">" + text + "</localEntry>";
+        String serializedSrc = "<localEntry 
xmlns=\"http://synapse.apache.org/ns/2010/04/configuration\"; " +
+                "key=\"" + key + "\"><![CDATA[" + text + "]]></localEntry>";
+
         try {
-            OMElement source = parseEntrySource(entrySrc);
-            Entry entry = EntryFactory.createEntry(source);
-            assertEquals(text, entry.getValue());
+            OMElement elem = AXIOMUtil.stringToOM(entrySrc);
+            Entry entry = EntryFactory.createEntry(elem);
+            assertEquals(key, entry.getKey());
+            assertEquals(Entry.INLINE_TEXT, entry.getType());
+            assertEquals(text, (String) entry.getValue());
 
             OMElement serialization = EntrySerializer.serializeEntry(entry, 
null);
-            assertTrue(compare(source, serialization));
+            OMElement expectedSerialization = parseWithCDATA(serializedSrc);
+            assertTrue(compare(expectedSerialization, serialization));
         } catch (XMLStreamException e) {
-            fail("Simple Text Entry test failed: " + e.getMessage());
+            fail("Error while parsing entry definition: " + e.getMessage());
         }
     }
 
-    public void testSimpleXMLEntry() {
+    public void testTextEntryWithMarkup() {
+        String text = "mc.setPayloadXML(<xml>data</xml>);";
         String entrySrc = "<localEntry 
xmlns=\"http://synapse.apache.org/ns/2010/04/configuration\"; " +
-                
"key=\"foo\"><project><id>001</id><name>Synapse</name></project></localEntry>";
+                "key=\"" + key + "\"><![CDATA[" + text + "]]></localEntry>";
+
         try {
-            OMElement source = parseEntrySource(entrySrc);
-            OMElement original = source.cloneOMElement();
-            Entry entry = EntryFactory.createEntry(source);
-            assertTrue(compare(original.getFirstElement(), (OMElement) 
entry.getValue()));
+            OMElement elem = AXIOMUtil.stringToOM(entrySrc);
+            Entry entry = EntryFactory.createEntry(elem);
+            assertEquals(key, entry.getKey());
+            assertEquals(Entry.INLINE_TEXT, entry.getType());
+            assertEquals(text, (String) entry.getValue());
 
             OMElement serialization = EntrySerializer.serializeEntry(entry, 
null);
-            assertTrue(compare(original, serialization));
+            OMElement expectedSerialization = parseWithCDATA(entrySrc);
+            assertTrue(compare(expectedSerialization, serialization));
         } catch (XMLStreamException e) {
-            fail("Simple XML Entry test failed: " + e.getMessage());
+            fail("Error while parsing entry definition: " + e.getMessage());
         }
     }
 
-    // TODO: Fix SYNAPSE-624
-    /*public void testLargeTextEntry() {
-        String largeText = "Apache Synapse is designed to be a simple, 
lightweight and high " +
-                "performance Enterprise Service Bus (ESB) from Apache. Based 
on a small " +
-                "asynchronous core, Apache Synapse has excellent support for 
XML and Web " +
-                "services - as well as binary and text formats. The Synapse 
engine is configured " +
-                "with a simple XML format and comes with a set of ready-to-use 
transports and " +
-                "mediators. We recommend you start by reading the QuickStart 
and then trying out " +
-                "the samples. Synapse is made available under the Apache 
Software License 2.0. " +
-                "For more detailsplease visit http://synapse.apache.org";;
+    public void testTextEntryWithNestedCDATA() {
+        String actualText = "mc.setPayloadXML(<xml><![CDATA[data]]></xml>);";
+        String escapedText = 
"mc.setPayloadXML(<xml><![CDATA[data]]]]><![CDATA[></xml>);";
+        String entrySrc = "<localEntry 
xmlns=\"http://synapse.apache.org/ns/2010/04/configuration\"; " +
+                "key=\"" + key + "\"><![CDATA[" + escapedText + 
"]]></localEntry>";
+
+        try {
+            OMElement elem = AXIOMUtil.stringToOM(entrySrc);
+            Entry entry = EntryFactory.createEntry(elem);
+            assertEquals(key, entry.getKey());
+            assertEquals(Entry.INLINE_TEXT, entry.getType());
+            assertEquals(actualText, (String) entry.getValue());
+
+            OMElement expectedSerialization = parseWithCDATA(entrySrc);
+            OMElement serialization = EntrySerializer.serializeEntry(entry, 
null);
+            assertTrue(compare(expectedSerialization, serialization));         
   
+
+        } catch (XMLStreamException e) {
+            fail("Error while parsing entry definition: " + e.getMessage());
+        }
+    }
 
+    public void testSimpleXMLEntry() {
+        String xml = "<m:project 
xmlns:m=\"http://testing.synapse.apache.org\";><m:id>001</m:id>" +
+                "<m:name>Synapse</m:name></m:project>";
         String entrySrc = "<localEntry 
xmlns=\"http://synapse.apache.org/ns/2010/04/configuration\"; " +
-                "key=\"foo\"><![CDATA[" + largeText + "]]></localEntry>";
+                "key=\"" + key + "\">" + xml + "</localEntry>";
+
         try {
-            OMElement source = parseEntrySource(entrySrc);
-            Entry entry = EntryFactory.createEntry(source);
-            assertEquals(largeText, entry.getValue());
+            OMElement elem = AXIOMUtil.stringToOM(entrySrc);
+            OMElement expectedSerialization = elem.cloneOMElement();
+            Entry entry = EntryFactory.createEntry(elem);
+            assertEquals(key, entry.getKey());
+            assertEquals(Entry.INLINE_XML, entry.getType());
+
+            OMElement valueElem = AXIOMUtil.stringToOM(xml);
+            assertTrue(compare(valueElem, (OMElement) entry.getValue()));
+
+            OMElement serialization = EntrySerializer.serializeEntry(entry, 
null);
+            assertTrue(compare(expectedSerialization, serialization));
         } catch (XMLStreamException e) {
-            fail("Simple Text Entry test failed: " + e.getMessage());
+            fail("Error while parsing entry definition: " + e.getMessage());
         }
-    }*/
+    }
 
-    public void testLargeXMLEntry() {
+    public void testXMLEntryWithCDATA() {
+        String xml = "<m:project 
xmlns:m=\"http://testing.synapse.apache.org\";>" +
+                "<![CDATA[<xml>data</xml>]]></m:project>";
+        String entrySrc = "<localEntry 
xmlns=\"http://synapse.apache.org/ns/2010/04/configuration\"; " +
+                "key=\"" + key + "\">" + xml + "</localEntry>";
+
+        try {
+            OMElement elem = AXIOMUtil.stringToOM(entrySrc);
+            OMElement expectedSerialization = elem.cloneOMElement();
+            Entry entry = EntryFactory.createEntry(elem);
+            assertEquals(key, entry.getKey());
+            assertEquals(Entry.INLINE_XML, entry.getType());
 
-        String entrySrc =
-                "<localEntry 
xmlns=\"http://synapse.apache.org/ns/2010/04/configuration\"; key=\"foo\">" +
-                "<wsdl:definitions name=\"Imported\"\n" +
-                "                  
targetNamespace=\"http://www.example.com/imported\"\n"; +
-                "                  
xmlns:tns=\"http://www.example.com/imported\"\n"; +
-                "                  
xmlns:s=\"http://www.example.com/schema\"\n"; +
-                "                  
xmlns:wsdl=\"http://schemas.xmlsoap.org/wsdl/\"\n"; +
-                "                  
xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\";>\n" +
+            OMElement valueElem = AXIOMUtil.stringToOM(xml);
+            assertTrue(compare(valueElem, (OMElement) entry.getValue()));
+
+            OMElement serialization = EntrySerializer.serializeEntry(entry, 
null);
+            assertTrue(compare(expectedSerialization, serialization));
+        } catch (XMLStreamException e) {
+            fail("Error while parsing entry definition: " + e.getMessage());
+        }
+    }
+
+    public void testLargeXMLEntry() {
+        String xml = "<wsdl:definitions 
xmlns:axis2=\"http://ws.apache.org/axis2\"; 
xmlns:mime=\"http://schemas.xmlsoap.org/wsdl/mime/\"; 
xmlns:ns0=\"http://ws.apache.org/axis2/xsd\"; 
xmlns:soap12=\"http://schemas.xmlsoap.org/wsdl/soap12/\"; 
xmlns:http=\"http://schemas.xmlsoap.org/wsdl/http/\"; 
xmlns:ns1=\"http://org.apache.axis2/xsd\"; 
xmlns:xs=\"http://www.w3.org/2001/XMLSchema\"; 
xmlns:soap=\"http://schemas.xmlsoap.org/wsdl/soap/\"; 
xmlns:wsdl=\"http://schemas.xmlsoap.org/wsdl/\"; 
targetNamespace=\"http://ws.apache.org/axis2\";>\n" +
+                "    <wsdl:documentation>\n" +
+                "        New web service to test esb\n" +
+                "    </wsdl:documentation>\n" +
                 "    <wsdl:types>\n" +
-                "        <xsd:schema 
targetNamespace=\"http://www.example.com/imported\";>\n" +
-                "            <xsd:import 
namespace=\"http://www.example.com/schema\"; 
schemaLocation=\"imported.xsd\"/>\n" +
-                "            <xsd:element name=\"getTestData\">\n" +
-                "                <xsd:complexType>\n" +
-                "                    <xsd:sequence>\n" +
-                "                        <xsd:element name=\"test\" 
type=\"s:SomeType\" minOccurs=\"1\" maxOccurs=\"1\"/>\n" +
-                "                    </xsd:sequence>\n" +
-                "                </xsd:complexType>\n" +
-                "            </xsd:element>\n" +
-                "            <xsd:element name=\"getTestDataResponse\">\n" +
-                "                <xsd:complexType>\n" +
-                "                    <xsd:sequence>\n" +
-                "                        <xsd:element name=\"test\" 
type=\"s:SomeType\" minOccurs=\"1\" maxOccurs=\"1\"/>\n" +
-                "                    </xsd:sequence>\n" +
-                "                </xsd:complexType>\n" +
-                "            </xsd:element>\n" +
-                "        </xsd:schema>\n" +
+                "        <xs:schema 
xmlns:ns=\"http://ws.apache.org/axis2/xsd\"; attributeFormDefault=\"qualified\" 
elementFormDefault=\"qualified\" 
targetNamespace=\"http://ws.apache.org/axis2/xsd\";>\n" +
+                "            <xs:element name=\"multiply\">\n" +
+                "                <xs:complexType>\n" +
+                "                    <xs:sequence>\n" +
+                "                        <xs:element name=\"x\" 
nillable=\"true\" type=\"xs:double\" />\n" +
+                "                        <xs:element name=\"y\" 
nillable=\"true\" type=\"xs:double\" />\n" +
+                "                    </xs:sequence>\n" +
+                "                </xs:complexType>\n" +
+                "            </xs:element>\n" +
+                "            <xs:element name=\"multiplyResponse\">\n" +
+                "                <xs:complexType>\n" +
+                "                    <xs:sequence>\n" +
+                "                        <xs:element name=\"return\" 
nillable=\"true\" type=\"xs:double\" />\n" +
+                "                    </xs:sequence>\n" +
+                "                </xs:complexType>\n" +
+                "            </xs:element>\n" +
+                "        </xs:schema>\n" +
                 "    </wsdl:types>\n" +
-                "    <wsdl:message name=\"getTestDataRequest\">\n" +
-                "        <wsdl:part name=\"parameters\" 
element=\"tns:getTestData\"/>\n" +
+                "    <wsdl:message name=\"multiplyMessage\">\n" +
+                "        <wsdl:part name=\"part1\" element=\"ns0:multiply\" 
/>\n" +
                 "    </wsdl:message>\n" +
-                "    <wsdl:message name=\"getTestDataResponse\">\n" +
-                "        <wsdl:part name=\"parameters\" 
element=\"tns:getTestDataResponse\"/>\n" +
+                "    <wsdl:message name=\"multiplyResponse\">\n" +
+                "        <wsdl:part name=\"part1\" 
element=\"ns0:multiplyResponse\" />\n" +
                 "    </wsdl:message>\n" +
-                "    <wsdl:portType name=\"Test\">\n" +
-                "        <wsdl:operation name=\"getTestData\">\n" +
-                "            <wsdl:input message=\"tns:getTestDataRequest\" 
name=\"getTestData\"/>\n" +
-                "            <wsdl:output message=\"tns:getTestDataResponse\" 
name=\"getTestDataResponse\"/>\n" +
+                "    <wsdl:portType name=\"esbservicePortType\">\n" +
+                "        <wsdl:operation name=\"multiply\">\n" +
+                "            <wsdl:input 
xmlns:wsaw=\"http://www.w3.org/2006/05/addressing/wsdl\"; 
message=\"axis2:multiplyMessage\" wsaw:Action=\"urn:multiply\" />\n" +
+                "            <wsdl:output message=\"axis2:multiplyResponse\" 
/>\n" +
                 "        </wsdl:operation>\n" +
                 "    </wsdl:portType>\n" +
-                "</wsdl:definitions>" +
-                "</localEntry>";
+                "    <wsdl:binding name=\"esbserviceSOAP11Binding\" 
type=\"axis2:esbservicePortType\">\n" +
+                "        <soap:binding 
transport=\"http://schemas.xmlsoap.org/soap/http\"; style=\"document\" />\n" +
+                "        <wsdl:operation name=\"multiply\">\n" +
+                "            <soap:operation soapAction=\"urn:multiply\" 
style=\"document\" />\n" +
+                "            <wsdl:input>\n" +
+                "                <soap:body use=\"literal\" />\n" +
+                "            </wsdl:input>\n" +
+                "            <wsdl:output>\n" +
+                "                <soap:body use=\"literal\" />\n" +
+                "            </wsdl:output>\n" +
+                "        </wsdl:operation>\n" +
+                "    </wsdl:binding>\n" +
+                "    <wsdl:binding name=\"esbserviceSOAP12Binding\" 
type=\"axis2:esbservicePortType\">\n" +
+                "        <soap12:binding 
transport=\"http://schemas.xmlsoap.org/soap/http\"; style=\"document\" />\n" +
+                "        <wsdl:operation name=\"multiply\">\n" +
+                "            <soap12:operation soapAction=\"urn:multiply\" 
style=\"document\" />\n" +
+                "            <wsdl:input>\n" +
+                "                <soap12:body use=\"literal\" />\n" +
+                "            </wsdl:input>\n" +
+                "            <wsdl:output>\n" +
+                "                <soap12:body use=\"literal\" />\n" +
+                "            </wsdl:output>\n" +
+                "        </wsdl:operation>\n" +
+                "    </wsdl:binding>\n" +
+                "    <wsdl:binding name=\"esbserviceHttpBinding\" 
type=\"axis2:esbservicePortType\">\n" +
+                "        <http:binding verb=\"POST\" />\n" +
+                "        <wsdl:operation name=\"multiply\">\n" +
+                "            <http:operation location=\"multiply\" />\n" +
+                "            <wsdl:input>\n" +
+                "                <mime:content type=\"text/xml\" />\n" +
+                "            </wsdl:input>\n" +
+                "            <wsdl:output>\n" +
+                "                <mime:content type=\"text/xml\" />\n" +
+                "            </wsdl:output>\n" +
+                "        </wsdl:operation>\n" +
+                "    </wsdl:binding>\n" +
+                "    <wsdl:service name=\"esbservice\">\n" +
+                "        <wsdl:port name=\"esbserviceSOAP11port_http\" 
binding=\"axis2:esbserviceSOAP11Binding\">\n" +
+                "            <soap:address 
location=\"http://localhost:9001/services/Service1\"; />\n" +
+                "        </wsdl:port>\n" +
+                "        <wsdl:port name=\"esbserviceSOAP12port_http\" 
binding=\"axis2:esbserviceSOAP12Binding\">\n" +
+                "            <soap12:address 
location=\"http://localhost:9001/services/Service1\"; />\n" +
+                "        </wsdl:port>\n" +
+                "        <wsdl:port name=\"esbserviceHttpport1\" 
binding=\"axis2:esbserviceHttpBinding\">\n" +
+                "            <http:address 
location=\"http://localhost:9001/services/Service1\"; />\n" +
+                "        </wsdl:port>\n" +
+                "    </wsdl:service>\n" +
+                "</wsdl:definitions>";
+        
+        String entrySrc = "<localEntry 
xmlns=\"http://synapse.apache.org/ns/2010/04/configuration\"; " +
+                "key=\"" + key + "\">" + xml + "</localEntry>";
 
         try {
-            OMElement source = parseEntrySource(entrySrc);
-            OMElement original = source.cloneOMElement();
-            Entry entry = EntryFactory.createEntry(source);
-            assertTrue(compare(original.getFirstElement(), (OMElement) 
entry.getValue()));
+            OMElement elem = AXIOMUtil.stringToOM(entrySrc);
+            OMElement expectedSerialization = elem.cloneOMElement();
+            Entry entry = EntryFactory.createEntry(elem);
+            assertEquals(key, entry.getKey());
+            assertEquals(Entry.INLINE_XML, entry.getType());
+
+            OMElement valueElem = AXIOMUtil.stringToOM(xml);
+            assertTrue(compare(valueElem, (OMElement) entry.getValue()));
 
             OMElement serialization = EntrySerializer.serializeEntry(entry, 
null);
-            assertTrue(compare(original, serialization));
+            assertTrue(compare(expectedSerialization, serialization));
         } catch (XMLStreamException e) {
-            fail("Large XML Entry test failed: " + e.getMessage());
+            fail("Error while parsing entry definition: " + e.getMessage());
         }
     }
 
-    private OMElement parseEntrySource(String src) throws XMLStreamException {
+    private OMElement parseWithCDATA(String src) throws XMLStreamException {
         StringReader strReader = new StringReader(src);
         XMLInputFactory xmlInFac = XMLInputFactory.newInstance();
         //Non-Coalescing parsing


Reply via email to