You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@synapse.apache.org by as...@apache.org on 2006/12/20 07:50:15 UTC

svn commit: r488932 - in /incubator/synapse/trunk/java/modules: core/src/test/java/org/apache/synapse/config/xml/ extensions/src/test/java/org/apache/synapse/

Author: asankha
Date: Tue Dec 19 22:50:14 2006
New Revision: 488932

URL: http://svn.apache.org/viewvc?view=rev&rev=488932
Log:
committing for Chathura for http://issues.apache.org/jira/browse/SYNAPSE-40

Added:
    incubator/synapse/trunk/java/modules/core/src/test/java/org/apache/synapse/config/xml/RegistrySerializationTest.java
    incubator/synapse/trunk/java/modules/core/src/test/java/org/apache/synapse/config/xml/SendMediatorSerializationTest.java
    incubator/synapse/trunk/java/modules/core/src/test/java/org/apache/synapse/config/xml/SwitchMediatorSerializationTest.java
    incubator/synapse/trunk/java/modules/core/src/test/java/org/apache/synapse/config/xml/TryMediatorSerializationTest.java
    incubator/synapse/trunk/java/modules/extensions/src/test/java/org/apache/synapse/ValidateMediatorSerializationTest.java
Modified:
    incubator/synapse/trunk/java/modules/core/src/test/java/org/apache/synapse/config/xml/AbstractTestCase.java

Modified: incubator/synapse/trunk/java/modules/core/src/test/java/org/apache/synapse/config/xml/AbstractTestCase.java
URL: http://svn.apache.org/viewvc/incubator/synapse/trunk/java/modules/core/src/test/java/org/apache/synapse/config/xml/AbstractTestCase.java?view=diff&rev=488932&r1=488931&r2=488932
==============================================================================
--- incubator/synapse/trunk/java/modules/core/src/test/java/org/apache/synapse/config/xml/AbstractTestCase.java (original)
+++ incubator/synapse/trunk/java/modules/core/src/test/java/org/apache/synapse/config/xml/AbstractTestCase.java Tue Dec 19 22:50:14 2006
@@ -82,4 +82,8 @@
         String parentXML = "<synapse xmlns=\"http://ws.apache.org/ns/synapse\"><definitions></definitions></synapse>";
         return createOMElement(parentXML);
     }
+
+    protected boolean compare(OMElement inputElement, OMElement serializedElement) throws XMLComparisonException {
+        return  comparator.compare(inputElement, serializedElement);
+    }
 }

Added: incubator/synapse/trunk/java/modules/core/src/test/java/org/apache/synapse/config/xml/RegistrySerializationTest.java
URL: http://svn.apache.org/viewvc/incubator/synapse/trunk/java/modules/core/src/test/java/org/apache/synapse/config/xml/RegistrySerializationTest.java?view=auto&rev=488932
==============================================================================
--- incubator/synapse/trunk/java/modules/core/src/test/java/org/apache/synapse/config/xml/RegistrySerializationTest.java (added)
+++ incubator/synapse/trunk/java/modules/core/src/test/java/org/apache/synapse/config/xml/RegistrySerializationTest.java Tue Dec 19 22:50:14 2006
@@ -0,0 +1,53 @@
+/*
+ *  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.config.xml;
+
+import org.apache.axiom.om.OMElement;
+import org.apache.axiom.om.impl.exception.XMLComparisonException;
+import org.apache.synapse.registry.Registry;
+
+public class RegistrySerializationTest extends AbstractTestCase {
+
+    private RegistryFactory registryFactory = null;
+    private RegistrySerializer registrySerializer = null;
+
+    public RegistrySerializationTest() {
+        registryFactory = new RegistryFactory();
+        registrySerializer = new RegistrySerializer();
+    }
+
+    public void testRegistrySerialization() {
+
+        String regitryConfiguration = "<syn:registry xmlns:syn=\"http://ws.apache.org/ns/synapse\" provider=\"org.apache.synapse.registry.url.SimpleURLRegistry\" name=\"myregistry\">" +
+                "<syn:property name=\"root\" value=\"file:./../../repository/\"/>" +
+                "<syn:property name=\"cachableDuration\" value=\"15000\"/>" +
+                "</syn:registry>";
+
+        OMElement registryElement = createOMElement(regitryConfiguration);
+        Registry registry = RegistryFactory.createRegistry(registryElement);
+        OMElement serializedElement = RegistrySerializer.serializeRegistry(null, registry);
+
+        try {
+            assertTrue(compare(registryElement, serializedElement));
+        } catch (XMLComparisonException e) {
+            fail("Exception in test.");
+        }
+    }
+}

Added: incubator/synapse/trunk/java/modules/core/src/test/java/org/apache/synapse/config/xml/SendMediatorSerializationTest.java
URL: http://svn.apache.org/viewvc/incubator/synapse/trunk/java/modules/core/src/test/java/org/apache/synapse/config/xml/SendMediatorSerializationTest.java?view=auto&rev=488932
==============================================================================
--- incubator/synapse/trunk/java/modules/core/src/test/java/org/apache/synapse/config/xml/SendMediatorSerializationTest.java (added)
+++ incubator/synapse/trunk/java/modules/core/src/test/java/org/apache/synapse/config/xml/SendMediatorSerializationTest.java Tue Dec 19 22:50:14 2006
@@ -0,0 +1,99 @@
+/*
+ *  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.config.xml;
+
+import org.apache.axiom.om.impl.exception.XMLComparisonException;
+
+public class SendMediatorSerializationTest extends AbstractTestCase {
+
+    private SendMediatorFactory sendMediatorFactory = null;
+    private SendMediatorSerializer sendMediatorSerializer = null;
+
+    public SendMediatorSerializationTest() {
+        sendMediatorFactory = new SendMediatorFactory();
+        sendMediatorSerializer = new SendMediatorSerializer();
+    }
+
+    public void testSendMediatorWithNoEndpoints() {
+
+        String sendConfiguration = "<syn:send xmlns:syn=\"http://ws.apache.org/ns/synapse\"/>";
+
+        try {
+            assertTrue(serialization(sendConfiguration, sendMediatorFactory, sendMediatorSerializer));
+        } catch (XMLComparisonException e) {
+            fail("Exception in test.");
+        }
+    }
+
+    public void testSendMediatorWithSingleEndpoint() {
+
+        String sendConfiguration = "<syn:send xmlns:syn=\"http://ws.apache.org/ns/synapse\">" +
+                "<syn:endpoint name=\"myendpoint\" address=\"http://ws.apache.org/axis2/services/Service1\" />" +
+                "</syn:send>";
+
+        try {
+            assertTrue(serialization(sendConfiguration, sendMediatorFactory, sendMediatorSerializer));
+        } catch (XMLComparisonException e) {
+            fail("Exception in test.");
+        }
+    }
+
+    public void testSendMediatorWithMultipleEndpoints() {
+
+        String sendConfiguration = "<syn:send xmlns:syn=\"http://ws.apache.org/ns/synapse\">" +
+                "<syn:endpoint name=\"myendpoint1\" address=\"http://ws.apache.org/axis2/services/Service1\" />" +
+                "<syn:endpoint name=\"myendpoint2\" address=\"http://ws.apache.org/axis2/services/Service2\" />" +
+                "</syn:send>";
+
+        try {
+            assertTrue(serialization(sendConfiguration, sendMediatorFactory, sendMediatorSerializer));
+        } catch (XMLComparisonException e) {
+            fail("Exception in test.");
+        }
+    }
+
+    public void testSendMediatorWithSingleEndpointReference() {
+
+        String sendConfiguration = "<syn:send xmlns:syn=\"http://ws.apache.org/ns/synapse\">" +
+                "<syn:endpoint ref=\"ep1\"/>" +
+                "</syn:send>";
+
+        try {
+            assertTrue(serialization(sendConfiguration, sendMediatorFactory, sendMediatorSerializer));
+        } catch (XMLComparisonException e) {
+            fail("Exception in test.");
+        }
+    }
+
+    public void testSendMediatorWithMultipleEndpointReferences() {
+
+        String sendConfiguration = "<syn:send xmlns:syn=\"http://ws.apache.org/ns/synapse\">" +
+                "<syn:endpoint ref=\"ep1\"/>" +
+                "<syn:endpoint ref=\"ep2\"/>" +
+                "</syn:send>";
+
+        try {
+            assertTrue(serialization(sendConfiguration, sendMediatorFactory, sendMediatorSerializer));
+        } catch (XMLComparisonException e) {
+            fail("Exception in test.");
+        }
+    }
+
+}

Added: incubator/synapse/trunk/java/modules/core/src/test/java/org/apache/synapse/config/xml/SwitchMediatorSerializationTest.java
URL: http://svn.apache.org/viewvc/incubator/synapse/trunk/java/modules/core/src/test/java/org/apache/synapse/config/xml/SwitchMediatorSerializationTest.java?view=auto&rev=488932
==============================================================================
--- incubator/synapse/trunk/java/modules/core/src/test/java/org/apache/synapse/config/xml/SwitchMediatorSerializationTest.java (added)
+++ incubator/synapse/trunk/java/modules/core/src/test/java/org/apache/synapse/config/xml/SwitchMediatorSerializationTest.java Tue Dec 19 22:50:14 2006
@@ -0,0 +1,62 @@
+/*
+ *  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.config.xml;
+
+import org.apache.axiom.om.impl.exception.XMLComparisonException;
+
+public class SwitchMediatorSerializationTest extends AbstractTestCase {
+
+    private SwitchMediatorFactory switchMediatorFactory = null;
+    private SwitchMediatorSerializer switchMediatorSerializer = null;
+
+    public SwitchMediatorSerializationTest() {
+        switchMediatorFactory = new SwitchMediatorFactory();
+        switchMediatorSerializer = new SwitchMediatorSerializer();
+    }
+
+    public void testSwitchMediatorSerializationScenarioOne() {
+
+        String switchConfiguration = "<syn:switch xmlns:syn=\"http://ws.apache.org/ns/synapse\" source=\"synapse:get-property('to')\">" +
+                "<syn:case regex=\"MyService1\"><syn:drop/></syn:case>" +
+                "<syn:case regex=\"MyService2\"><syn:drop/></syn:case>" +
+                "<syn:default><syn:drop/></syn:default>" +
+                "</syn:switch>";
+
+        try {
+            assertTrue(serialization(switchConfiguration, switchMediatorFactory, switchMediatorSerializer));
+        } catch (XMLComparisonException e) {
+            fail("Exception in test");
+        }
+    }
+
+    public void testSwitchMediatorSerializationScenarioTwo() {
+
+        String switchConfiguration = "<syn:switch xmlns:syn=\"http://ws.apache.org/ns/synapse\" source=\"synapse:get-property('to')\">" +
+                "<syn:case regex=\"MyService1\"><syn:drop/></syn:case>" +
+                "<syn:case regex=\"MyService2\"><syn:drop/></syn:case>" +
+                "</syn:switch>";
+
+        try {
+            assertTrue(serialization(switchConfiguration, switchMediatorFactory, switchMediatorSerializer));
+        } catch (XMLComparisonException e) {
+            fail("Exception in test");
+        }
+    }
+}

Added: incubator/synapse/trunk/java/modules/core/src/test/java/org/apache/synapse/config/xml/TryMediatorSerializationTest.java
URL: http://svn.apache.org/viewvc/incubator/synapse/trunk/java/modules/core/src/test/java/org/apache/synapse/config/xml/TryMediatorSerializationTest.java?view=auto&rev=488932
==============================================================================
--- incubator/synapse/trunk/java/modules/core/src/test/java/org/apache/synapse/config/xml/TryMediatorSerializationTest.java (added)
+++ incubator/synapse/trunk/java/modules/core/src/test/java/org/apache/synapse/config/xml/TryMediatorSerializationTest.java Tue Dec 19 22:50:14 2006
@@ -0,0 +1,61 @@
+/*
+ *  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.config.xml;
+
+public class TryMediatorSerializationTest extends AbstractTestCase {
+
+    private TryMediatorFactory tryMediatorFactory = null;
+    private TryMediatorSerializer tryMediatorSerializer = null;
+
+    public TryMediatorSerializationTest() {
+        tryMediatorFactory = new TryMediatorFactory();
+        tryMediatorSerializer = new TryMediatorSerializer();
+    }
+
+    public void testTryMediatorSerializationScenarioOne() {
+
+        String tryConfiguration = "<syn:try xmlns:syn=\"http://ws.apache.org/ns/synapse\">" +
+                "<syn:sequence><syn:send/></syn:sequence>" +
+                "<syn:onError><syn:drop/></syn:onError>" +
+                "<syn:finally><syn:send/></syn:finally>" +
+                "</syn:try>";
+
+        try {
+            assertTrue(serialization(tryConfiguration, tryMediatorFactory, tryMediatorSerializer));
+        } catch (Exception e) {
+            fail("Exception in test");
+        }
+    }
+
+    public void testTryMediatorSerializationScenarioTwo() {
+
+        String tryConfiguration = "<syn:try xmlns:syn=\"http://ws.apache.org/ns/synapse\">" +
+                "<syn:sequence><syn:sequence ref=\"MySequence1\" /></syn:sequence>" +
+                "<syn:onError><syn:sequence ref=\"MySequence2\" /></syn:onError>" +
+                "<syn:finally><syn:sequence ref=\"MySequence3\" /></syn:finally>" +
+                "</syn:try>";
+
+        try {
+            assertTrue(serialization(tryConfiguration, tryMediatorFactory, tryMediatorSerializer));
+        } catch (Exception e) {
+            fail("Exception in test");
+        }
+    }
+}

Added: incubator/synapse/trunk/java/modules/extensions/src/test/java/org/apache/synapse/ValidateMediatorSerializationTest.java
URL: http://svn.apache.org/viewvc/incubator/synapse/trunk/java/modules/extensions/src/test/java/org/apache/synapse/ValidateMediatorSerializationTest.java?view=auto&rev=488932
==============================================================================
--- incubator/synapse/trunk/java/modules/extensions/src/test/java/org/apache/synapse/ValidateMediatorSerializationTest.java (added)
+++ incubator/synapse/trunk/java/modules/extensions/src/test/java/org/apache/synapse/ValidateMediatorSerializationTest.java Tue Dec 19 22:50:14 2006
@@ -0,0 +1,170 @@
+/*
+ *  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;
+
+import org.apache.axiom.om.impl.exception.XMLComparisonException;
+import org.apache.axiom.om.impl.builder.StAXOMBuilder;
+import org.apache.axiom.om.impl.llom.util.XMLComparator;
+import org.apache.axiom.om.OMElement;
+import org.apache.synapse.mediators.validate.ValidateMediatorSerializer;
+import org.apache.synapse.mediators.validate.ValidateMediatorFactory;
+import org.apache.synapse.config.xml.MediatorFactory;
+import org.apache.synapse.config.xml.MediatorSerializer;
+import org.apache.xmlbeans.xml.stream.XMLStreamException;
+import junit.framework.TestCase;
+
+import javax.xml.stream.XMLStreamReader;
+import javax.xml.stream.XMLInputFactory;
+import java.io.StringReader;
+
+public class ValidateMediatorSerializationTest extends TestCase {
+
+    private ValidateMediatorFactory validateMediatorFactory = null;
+    private ValidateMediatorSerializer validateMediatorSerializer = null;
+
+    public ValidateMediatorSerializationTest() {
+        validateMediatorFactory = new ValidateMediatorFactory();
+        validateMediatorSerializer = new ValidateMediatorSerializer();
+    }
+
+    public void testValidateMediatorSerialization() {
+
+        String validateConfiguration = "<syn:validate xmlns:syn=\"http://ws.apache.org/ns/synapse\" source=\"//regRequest\">" +
+                "<syn:schema key=\"file:synapse_repository/conf/sample/validate.xsd\"/>" +
+                "<syn:on-fail>" +
+                "<syn:drop/>" +
+                "</syn:on-fail>" +
+                "</syn:validate>";
+
+        try {
+            assertTrue(serialization(validateConfiguration, validateMediatorFactory, validateMediatorSerializer));
+        } catch (Exception e) {
+            fail("Exception in test.");
+        }
+    }
+
+    private boolean serialization(String inputXml, MediatorFactory mediatorFactory, MediatorSerializer mediatorSerializer) throws XMLComparisonException {
+
+        XMLComparator comparator = new XMLComparator();
+
+        OMElement inputOM = createOMElement(inputXml);
+        Mediator mediator = mediatorFactory.createMediator(inputOM);
+        OMElement resultOM = mediatorSerializer.serializeMediator(null, mediator);
+        return comparator.compare(resultOM, inputOM);
+    }
+
+    private 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 (javax.xml.stream.XMLStreamException e) {
+            throw new RuntimeException(e);
+        }
+    }
+}
+/*
+ *  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;
+
+import org.apache.axiom.om.impl.exception.XMLComparisonException;
+import org.apache.axiom.om.impl.builder.StAXOMBuilder;
+import org.apache.axiom.om.impl.llom.util.XMLComparator;
+import org.apache.axiom.om.OMElement;
+import org.apache.synapse.mediators.validate.ValidateMediatorSerializer;
+import org.apache.synapse.mediators.validate.ValidateMediatorFactory;
+import org.apache.synapse.config.xml.MediatorFactory;
+import org.apache.synapse.config.xml.MediatorSerializer;
+import org.apache.xmlbeans.xml.stream.XMLStreamException;
+import junit.framework.TestCase;
+
+import javax.xml.stream.XMLStreamReader;
+import javax.xml.stream.XMLInputFactory;
+import java.io.StringReader;
+
+public class ValidateMediatorSerializationTest extends TestCase {
+
+    private ValidateMediatorFactory validateMediatorFactory = null;
+    private ValidateMediatorSerializer validateMediatorSerializer = null;
+
+    public ValidateMediatorSerializationTest() {
+        validateMediatorFactory = new ValidateMediatorFactory();
+        validateMediatorSerializer = new ValidateMediatorSerializer();
+    }
+
+    public void testValidateMediatorSerialization() {
+
+        String validateConfiguration = "<syn:validate xmlns:syn=\"http://ws.apache.org/ns/synapse\" source=\"//regRequest\">" +
+                "<syn:schema key=\"file:synapse_repository/conf/sample/validate.xsd\"/>" +
+                "<syn:on-fail>" +
+                "<syn:drop/>" +
+                "</syn:on-fail>" +
+                "</syn:validate>";
+
+        try {
+            assertTrue(serialization(validateConfiguration, validateMediatorFactory, validateMediatorSerializer));
+        } catch (Exception e) {
+            fail("Exception in test.");
+        }
+    }
+
+    private boolean serialization(String inputXml, MediatorFactory mediatorFactory, MediatorSerializer mediatorSerializer) throws XMLComparisonException {
+
+        XMLComparator comparator = new XMLComparator();
+
+        OMElement inputOM = createOMElement(inputXml);
+        Mediator mediator = mediatorFactory.createMediator(inputOM);
+        OMElement resultOM = mediatorSerializer.serializeMediator(null, mediator);
+        return comparator.compare(resultOM, inputOM);
+    }
+
+    private 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 (javax.xml.stream.XMLStreamException e) {
+            throw new RuntimeException(e);
+        }
+    }
+}



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