synapse-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From asan...@apache.org
Subject svn commit: r609122 - in /webservices/synapse/trunk/java/modules: core/ core/src/test/java/org/apache/synapse/mediators/ core/src/test/java/org/apache/synapse/mediators/builtin/ core/src/test/java/org/apache/synapse/mediators/transform/ extensions/ ext...
Date Sat, 05 Jan 2008 10:40:53 GMT
Author: asankha
Date: Sat Jan  5 02:40:39 2008
New Revision: 609122

URL: http://svn.apache.org/viewvc?rev=609122&view=rev
Log:
fix SYNAPSE-214 and also move Validate mediator tests appropriately

Added:
    webservices/synapse/trunk/java/modules/core/src/test/java/org/apache/synapse/mediators/AbstractTestCase.java
    webservices/synapse/trunk/java/modules/core/src/test/java/org/apache/synapse/mediators/builtin/ValidateMediatorSerializationTest.java
  (contents, props changed)
      - copied, changed from r608815, webservices/synapse/trunk/java/modules/extensions/src/test/java/org/apache/synapse/mediators/validate/ValidateMediatorSerializationTest.java
    webservices/synapse/trunk/java/modules/core/src/test/java/org/apache/synapse/mediators/builtin/ValidateMediatorTest.java
  (contents, props changed)
      - copied, changed from r608815, webservices/synapse/trunk/java/modules/extensions/src/test/java/org/apache/synapse/mediators/validate/ValidateMediatorTest.java
    webservices/synapse/trunk/java/modules/core/src/test/java/org/apache/synapse/mediators/transform/XSLTMediatorTest.java
  (contents, props changed)
      - copied, changed from r608815, webservices/synapse/trunk/java/modules/extensions/src/test/java/org/apache/synapse/mediators/transform/XSLTMediatorTest.java
Removed:
    webservices/synapse/trunk/java/modules/extensions/src/test/java/org/apache/synapse/mediators/transform/XSLTMediatorTest.java
    webservices/synapse/trunk/java/modules/extensions/src/test/java/org/apache/synapse/mediators/validate/ValidateMediatorSerializationTest.java
    webservices/synapse/trunk/java/modules/extensions/src/test/java/org/apache/synapse/mediators/validate/ValidateMediatorTest.java
Modified:
    webservices/synapse/trunk/java/modules/core/pom.xml
    webservices/synapse/trunk/java/modules/core/src/test/java/org/apache/synapse/mediators/TestUtils.java
    webservices/synapse/trunk/java/modules/extensions/pom.xml
    webservices/synapse/trunk/java/modules/extensions/src/test/java/org/apache/synapse/mediators/TestUtils.java

Modified: webservices/synapse/trunk/java/modules/core/pom.xml
URL: http://svn.apache.org/viewvc/webservices/synapse/trunk/java/modules/core/pom.xml?rev=609122&r1=609121&r2=609122&view=diff
==============================================================================
--- webservices/synapse/trunk/java/modules/core/pom.xml (original)
+++ webservices/synapse/trunk/java/modules/core/pom.xml Sat Jan  5 02:40:39 2008
@@ -124,6 +124,16 @@
                 <artifactId>maven-surefire-plugin</artifactId>
                 <version>2.3</version>
                 <configuration>
+                    <systemProperties>
+                        <property>
+                            <name>org.xml.sax.driver</name>
+                            <value>org.apache.xerces.parsers.SAXParser</value>
+                        </property>
+                        <property>
+                            <name>javax.xml.validation.SchemaFactory:http://www.w3.org/2001/XMLSchema</name>
+                            <value>org.apache.xerces.jaxp.validation.XMLSchemaFactory</value>
+                        </property>
+                    </systemProperties>
                     <forkMode>pertest</forkMode>
                     <!--<redirectTestOutputToFile>true</redirectTestOutputToFile>-->
                     <!--<workingDirectory>../..</workingDirectory>-->

Added: webservices/synapse/trunk/java/modules/core/src/test/java/org/apache/synapse/mediators/AbstractTestCase.java
URL: http://svn.apache.org/viewvc/webservices/synapse/trunk/java/modules/core/src/test/java/org/apache/synapse/mediators/AbstractTestCase.java?rev=609122&view=auto
==============================================================================
--- webservices/synapse/trunk/java/modules/core/src/test/java/org/apache/synapse/mediators/AbstractTestCase.java
(added)
+++ webservices/synapse/trunk/java/modules/core/src/test/java/org/apache/synapse/mediators/AbstractTestCase.java
Sat Jan  5 02:40:39 2008
@@ -0,0 +1,121 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you 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.synapse.mediators;
+
+import org.custommonkey.xmlunit.XMLTestCase;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.axiom.om.OMElement;
+import org.apache.axiom.om.impl.builder.StAXOMBuilder;
+import org.apache.synapse.config.xml.MediatorFactory;
+import org.apache.synapse.config.xml.MediatorSerializer;
+import org.apache.synapse.config.xml.MediatorFactoryFinder;
+import org.apache.synapse.Mediator;
+import org.xml.sax.SAXException;
+
+import javax.xml.stream.XMLStreamReader;
+import javax.xml.stream.XMLInputFactory;
+import javax.xml.stream.XMLStreamException;
+import java.io.StringReader;
+import java.io.IOException;
+
+/**
+ *
+ *
+ */
+
+public abstract class AbstractTestCase extends XMLTestCase {
+
+
+    private static final Log log = LogFactory.getLog(AbstractTestCase.class);
+
+    public AbstractTestCase(String name) {
+        super(name);
+    }
+
+    public AbstractTestCase() {
+    }
+
+    protected void setUp() throws Exception {
+        super.setUp();
+    }
+
+    protected OMElement createOMElement(String xml) {
+        try {
+
+            XMLStreamReader reader = XMLInputFactory.newInstance().createXMLStreamReader(new
StringReader(xml));
+            StAXOMBuilder builder = new StAXOMBuilder(reader);
+            OMElement omElement = builder.getDocumentElement();
+            return omElement;
+
+        }
+        catch (XMLStreamException e) {
+            throw new RuntimeException(e);
+        }
+    }
+
+    protected boolean serialization(String inputXml, MediatorFactory mediatorFactory, MediatorSerializer
mediatorSerializer) {
+
+        OMElement inputOM = createOMElement(inputXml);
+        Mediator mediator = mediatorFactory.createMediator(inputOM);
+        OMElement resultOM = mediatorSerializer.serializeMediator(null, mediator);
+        try {
+            assertXMLEqual(resultOM.toString(), inputXml);
+            return true;
+        } catch (SAXException e) {
+            log.error(e);
+        } catch (IOException e) {
+            log.error(e);
+        }
+        return false;
+    }
+
+    protected boolean serialization(String inputXml, MediatorSerializer mediatorSerializer)
{
+        OMElement inputOM = createOMElement(inputXml);
+        Mediator mediator = MediatorFactoryFinder.getInstance().getMediator(inputOM);
+        OMElement resultOM = mediatorSerializer.serializeMediator(null, mediator);
+        try {
+            assertXMLEqual(resultOM.toString(), inputXml);
+            return true;
+        } catch (SAXException e) {
+            log.error(e);
+        } catch (IOException e) {
+            log.error(e);
+        }
+        return false;
+    }
+
+    protected OMElement getParent() {
+        String parentXML = "<synapse xmlns=\"http://ws.apache.org/ns/synapse\"><definitions></definitions></synapse>";
+        return createOMElement(parentXML);
+    }
+
+    protected boolean compare(OMElement inputElement, OMElement serializedElement) {
+        try {
+            assertXMLEqual(inputElement.toString(), serializedElement.toString());
+            return true;
+        } catch (SAXException e) {
+            log.error(e);
+        } catch (IOException e) {
+            log.error(e);
+        }
+        return false;
+    }
+}

Modified: webservices/synapse/trunk/java/modules/core/src/test/java/org/apache/synapse/mediators/TestUtils.java
URL: http://svn.apache.org/viewvc/webservices/synapse/trunk/java/modules/core/src/test/java/org/apache/synapse/mediators/TestUtils.java?rev=609122&r1=609121&r2=609122&view=diff
==============================================================================
--- webservices/synapse/trunk/java/modules/core/src/test/java/org/apache/synapse/mediators/TestUtils.java
(original)
+++ webservices/synapse/trunk/java/modules/core/src/test/java/org/apache/synapse/mediators/TestUtils.java
Sat Jan  5 02:40:39 2008
@@ -30,6 +30,7 @@
 import org.apache.axiom.om.OMAbstractFactory;
 import org.apache.axiom.om.OMDocument;
 import org.apache.axiom.om.OMElement;
+import org.apache.axiom.om.OMFactory;
 import org.apache.axiom.om.impl.builder.StAXOMBuilder;
 import org.apache.axiom.soap.SOAPEnvelope;
 import org.apache.synapse.MessageContext;
@@ -56,7 +57,7 @@
             Iterator iter = props.keySet().iterator();
             while (iter.hasNext()) {
                 String key = (String) iter.next();
-                testConfig.addEntry(key, (Entry)props.get(key));
+                testConfig.addEntry(key, (Entry) props.get(key));
             }
         }
         synCtx.setConfiguration(testConfig);
@@ -68,7 +69,7 @@
         omDoc.addChild(envelope);
 
         XMLStreamReader parser = XMLInputFactory.newInstance().
-            createXMLStreamReader(new StringReader(bodyText));
+                createXMLStreamReader(new StringReader(bodyText));
         StAXOMBuilder builder = new StAXOMBuilder(parser);
 
         // set a dummy static message
@@ -78,6 +79,108 @@
         return synCtx;
     }
 
+    public static Axis2MessageContext getAxis2MessageContext(String bodyText,
+                                                             Map props) throws Exception
{
+        // create a test synapse context
+        SynapseConfiguration testConfig = new SynapseConfiguration();
+        org.apache.axis2.context.MessageContext inContext =
+                new org.apache.axis2.context.MessageContext();
+
+        Axis2MessageContext synCtx = new Axis2MessageContext(inContext, testConfig, null);
+        testConfig.setRegistry(new SimpleURLRegistry());
+
+        if (props != null) {
+            Iterator iter = props.keySet().iterator();
+            while (iter.hasNext()) {
+                String key = (String) iter.next();
+                testConfig.addEntry(key, (Entry) props.get(key));
+            }
+        }
+        synCtx.setConfiguration(testConfig);
+
+        SOAPEnvelope envelope = OMAbstractFactory.getSOAP11Factory().getDefaultEnvelope();
+        OMDocument omDoc = OMAbstractFactory.getSOAP11Factory().createOMDocument();
+        omDoc.addChild(envelope);
+
+        XMLStreamReader parser = XMLInputFactory.newInstance().
+                createXMLStreamReader(new StringReader(bodyText));
+        StAXOMBuilder builder = new StAXOMBuilder(parser);
+
+        // set a dummy static message
+        envelope.getBody().addChild(builder.getDocumentElement());
+
+        synCtx.setEnvelope(envelope);
+        return synCtx;
+    }
+
+    public static TestMessageContext getTestContextForXSLTMediator(String bodyText, Map props)
throws Exception {
+
+        // create a test synapse context
+        TestMessageContext synCtx = new TestMessageContext();
+        SynapseConfiguration testConfig = new SynapseConfiguration();
+        testConfig.setRegistry(new SimpleURLRegistry());
+
+        if (props != null) {
+            Iterator iter = props.keySet().iterator();
+            while (iter.hasNext()) {
+                String key = (String) iter.next();
+                testConfig.addEntry(key, (Entry) props.get(key));
+            }
+        }
+        synCtx.setConfiguration(testConfig);
+
+        SOAPEnvelope envelope = OMAbstractFactory.getSOAP11Factory().getDefaultEnvelope();
+        OMDocument omDoc = OMAbstractFactory.getSOAP11Factory().createOMDocument();
+        omDoc.addChild(envelope);
+
+        XMLStreamReader parser = XMLInputFactory.newInstance().
+                createXMLStreamReader(new StringReader(bodyText));
+        StAXOMBuilder builder = new StAXOMBuilder(parser);
+
+        // set a dummy static message
+        OMFactory fac = OMAbstractFactory.getOMFactory();
+        envelope.getBody().addChild(fac.createOMText("first text child "));
+        envelope.getBody().addChild(builder.getDocumentElement());
+        envelope.getBody().addChild(fac.createOMText("second text child "));
+
+        synCtx.setEnvelope(envelope);
+        return synCtx;
+    }
+
+    public static TestMessageContext getTestContextForXSLTMediatorUsingFile(String path,
Map props) throws Exception {
+
+        // create a test synapse context
+        TestMessageContext synCtx = new TestMessageContext();
+        SynapseConfiguration testConfig = new SynapseConfiguration();
+        testConfig.setRegistry(new SimpleURLRegistry());
+
+        if (props != null) {
+            Iterator iter = props.keySet().iterator();
+            while (iter.hasNext()) {
+                String key = (String) iter.next();
+                testConfig.addEntry(key, (Entry) props.get(key));
+            }
+        }
+        synCtx.setConfiguration(testConfig);
+
+        SOAPEnvelope envelope = OMAbstractFactory.getSOAP11Factory().getDefaultEnvelope();
+        OMDocument omDoc = OMAbstractFactory.getSOAP11Factory().createOMDocument();
+        omDoc.addChild(envelope);
+
+        //XMLStreamReader parser = XMLInputFactory.newInstance().
+        //        createXMLStreamReader(new FileReader(path));
+        StAXOMBuilder builder = new StAXOMBuilder(path);
+
+        // set a dummy static message
+        OMFactory fac = OMAbstractFactory.getOMFactory();
+        envelope.getBody().addChild(fac.createOMText("first text child "));
+        envelope.getBody().addChild(builder.getDocumentElement());
+        envelope.getBody().addChild(fac.createOMText("second text child "));
+
+        synCtx.setEnvelope(envelope);
+        return synCtx;
+    }
+
     public static TestMessageContext getTestContext(String bodyText) throws Exception {
         return getTestContext(bodyText, null);
     }
@@ -88,7 +191,7 @@
                 new org.apache.axis2.context.MessageContext();
         SynapseConfiguration config = new SynapseConfiguration();
         SynapseEnvironment env = new Axis2SynapseEnvironment(config);
-        MessageContext synMc = new Axis2MessageContext(mc,config,env);
+        MessageContext synMc = new Axis2MessageContext(mc, config, env);
         SOAPEnvelope envelope =
                 OMAbstractFactory.getSOAP11Factory().getDefaultEnvelope();
         OMDocument omDoc =

Copied: webservices/synapse/trunk/java/modules/core/src/test/java/org/apache/synapse/mediators/builtin/ValidateMediatorSerializationTest.java
(from r608815, webservices/synapse/trunk/java/modules/extensions/src/test/java/org/apache/synapse/mediators/validate/ValidateMediatorSerializationTest.java)
URL: http://svn.apache.org/viewvc/webservices/synapse/trunk/java/modules/core/src/test/java/org/apache/synapse/mediators/builtin/ValidateMediatorSerializationTest.java?p2=webservices/synapse/trunk/java/modules/core/src/test/java/org/apache/synapse/mediators/builtin/ValidateMediatorSerializationTest.java&p1=webservices/synapse/trunk/java/modules/extensions/src/test/java/org/apache/synapse/mediators/validate/ValidateMediatorSerializationTest.java&r1=608815&r2=609122&rev=609122&view=diff
==============================================================================
--- webservices/synapse/trunk/java/modules/extensions/src/test/java/org/apache/synapse/mediators/validate/ValidateMediatorSerializationTest.java
(original)
+++ webservices/synapse/trunk/java/modules/core/src/test/java/org/apache/synapse/mediators/builtin/ValidateMediatorSerializationTest.java
Sat Jan  5 02:40:39 2008
@@ -17,7 +17,7 @@
  *  under the License.
  */
 
-package org.apache.synapse.mediators.validate;
+package org.apache.synapse.mediators.builtin;
 
 import org.apache.synapse.mediators.AbstractTestCase;
 import org.apache.synapse.config.xml.ValidateMediatorFactory;

Propchange: webservices/synapse/trunk/java/modules/core/src/test/java/org/apache/synapse/mediators/builtin/ValidateMediatorSerializationTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Copied: webservices/synapse/trunk/java/modules/core/src/test/java/org/apache/synapse/mediators/builtin/ValidateMediatorTest.java
(from r608815, webservices/synapse/trunk/java/modules/extensions/src/test/java/org/apache/synapse/mediators/validate/ValidateMediatorTest.java)
URL: http://svn.apache.org/viewvc/webservices/synapse/trunk/java/modules/core/src/test/java/org/apache/synapse/mediators/builtin/ValidateMediatorTest.java?p2=webservices/synapse/trunk/java/modules/core/src/test/java/org/apache/synapse/mediators/builtin/ValidateMediatorTest.java&p1=webservices/synapse/trunk/java/modules/extensions/src/test/java/org/apache/synapse/mediators/validate/ValidateMediatorTest.java&r1=608815&r2=609122&rev=609122&view=diff
==============================================================================
--- webservices/synapse/trunk/java/modules/extensions/src/test/java/org/apache/synapse/mediators/validate/ValidateMediatorTest.java
(original)
+++ webservices/synapse/trunk/java/modules/core/src/test/java/org/apache/synapse/mediators/builtin/ValidateMediatorTest.java
Sat Jan  5 02:40:39 2008
@@ -17,18 +17,18 @@
  *  under the License.
  */
 
-package org.apache.synapse.mediators.validate;
+package org.apache.synapse.mediators.builtin;
 
 import junit.framework.TestCase;
 import org.apache.axiom.om.OMElement;
 import org.apache.axiom.om.impl.builder.StAXOMBuilder;
 import org.apache.axiom.om.xpath.AXIOMXPath;
 import org.apache.synapse.mediators.TestUtils;
+import org.apache.synapse.mediators.TestMediator;
+import org.apache.synapse.mediators.TestMediateHandler;
 import org.apache.synapse.mediators.builtin.ValidateMediator;
 import org.apache.synapse.config.xml.ValidateMediatorFactory;
 import org.apache.synapse.config.Entry;
-import org.apache.synapse.TestMediator;
-import org.apache.synapse.TestMediateHandler;
 import org.apache.synapse.MessageContext;
 
 import javax.xml.stream.XMLStreamException;

Propchange: webservices/synapse/trunk/java/modules/core/src/test/java/org/apache/synapse/mediators/builtin/ValidateMediatorTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Copied: webservices/synapse/trunk/java/modules/core/src/test/java/org/apache/synapse/mediators/transform/XSLTMediatorTest.java
(from r608815, webservices/synapse/trunk/java/modules/extensions/src/test/java/org/apache/synapse/mediators/transform/XSLTMediatorTest.java)
URL: http://svn.apache.org/viewvc/webservices/synapse/trunk/java/modules/core/src/test/java/org/apache/synapse/mediators/transform/XSLTMediatorTest.java?p2=webservices/synapse/trunk/java/modules/core/src/test/java/org/apache/synapse/mediators/transform/XSLTMediatorTest.java&p1=webservices/synapse/trunk/java/modules/extensions/src/test/java/org/apache/synapse/mediators/transform/XSLTMediatorTest.java&r1=608815&r2=609122&rev=609122&view=diff
==============================================================================
    (empty)

Propchange: webservices/synapse/trunk/java/modules/core/src/test/java/org/apache/synapse/mediators/transform/XSLTMediatorTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: webservices/synapse/trunk/java/modules/extensions/pom.xml
URL: http://svn.apache.org/viewvc/webservices/synapse/trunk/java/modules/extensions/pom.xml?rev=609122&r1=609121&r2=609122&view=diff
==============================================================================
--- webservices/synapse/trunk/java/modules/extensions/pom.xml (original)
+++ webservices/synapse/trunk/java/modules/extensions/pom.xml Sat Jan  5 02:40:39 2008
@@ -43,18 +43,6 @@
                 <groupId>org.apache.maven.plugins</groupId>
                 <artifactId>maven-surefire-plugin</artifactId>
                 <version>2.2</version>
-                <configuration>
-                    <systemProperties>
-                        <property>
-                            <name>org.xml.sax.driver</name>
-                            <value>org.apache.xerces.parsers.SAXParser</value>
-                        </property>
-                        <property>
-                            <name>javax.xml.validation.SchemaFactory:http://www.w3.org/2001/XMLSchema</name>
-                            <value>org.apache.xerces.jaxp.validation.XMLSchemaFactory</value>
-                        </property>
-                    </systemProperties>
-                </configuration>
             </plugin>
 
         </plugins>

Modified: webservices/synapse/trunk/java/modules/extensions/src/test/java/org/apache/synapse/mediators/TestUtils.java
URL: http://svn.apache.org/viewvc/webservices/synapse/trunk/java/modules/extensions/src/test/java/org/apache/synapse/mediators/TestUtils.java?rev=609122&r1=609121&r2=609122&view=diff
==============================================================================
--- webservices/synapse/trunk/java/modules/extensions/src/test/java/org/apache/synapse/mediators/TestUtils.java
(original)
+++ webservices/synapse/trunk/java/modules/extensions/src/test/java/org/apache/synapse/mediators/TestUtils.java
Sat Jan  5 02:40:39 2008
@@ -33,6 +33,8 @@
 import org.apache.synapse.core.axis2.Axis2MessageContext;
 import org.apache.synapse.core.axis2.Axis2SynapseEnvironment;
 import org.apache.synapse.registry.url.SimpleURLRegistry;
+import org.apache.axis2.context.ConfigurationContext;
+import org.apache.axis2.engine.AxisConfiguration;
 
 import javax.xml.stream.XMLInputFactory;
 import javax.xml.stream.XMLStreamException;
@@ -58,6 +60,8 @@
             }
         }
         synCtx.setConfiguration(testConfig);
+        synCtx.setEnvironment(new Axis2SynapseEnvironment(
+            new ConfigurationContext(new AxisConfiguration()), testConfig));
 
         SOAPEnvelope envelope = OMAbstractFactory.getSOAP11Factory().getDefaultEnvelope();
         OMDocument omDoc = OMAbstractFactory.getSOAP11Factory().createOMDocument();



---------------------------------------------------------------------
To unsubscribe, e-mail: synapse-dev-unsubscribe@ws.apache.org
For additional commands, e-mail: synapse-dev-help@ws.apache.org


Mime
View raw message