Author: hiranya
Date: Sun Aug  4 01:48:45 2013
New Revision: 1510087

URL: http://svn.apache.org/r1510087
Log:
Adding serialization tests for message store mediator and call-template mediator

Added:
    
synapse/trunk/java/modules/core/src/test/java/org/apache/synapse/config/xml/InvokeMediatorSerializationTest.java
    
synapse/trunk/java/modules/core/src/test/java/org/apache/synapse/config/xml/MessageStoreMediatorSerializationTest.java
Modified:
    
synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/InvokeMediatorFactory.java
    
synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/MessageStoreMediatorFactory.java
    
synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/ValueFactory.java
    
synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/template/InvokeMediator.java

Modified: 
synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/InvokeMediatorFactory.java
URL: 
http://svn.apache.org/viewvc/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/InvokeMediatorFactory.java?rev=1510087&r1=1510086&r2=1510087&view=diff
==============================================================================
--- 
synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/InvokeMediatorFactory.java
 (original)
+++ 
synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/InvokeMediatorFactory.java
 Sun Aug  4 01:48:45 2013
@@ -71,9 +71,9 @@ public class InvokeMediatorFactory exten
             OMElement child = (OMElement) subElements.next();
             if (child.getQName().equals(WITH_PARAM_Q)) {
                 OMAttribute paramNameAttr = child.getAttribute(ATT_NAME);
-                Value paramValue = new ValueFactory().createValue("value", 
child);
                 if (paramNameAttr != null) {
                     //set parameter value
+                    Value paramValue = new ValueFactory().createValue("value", 
child);
                     
invoker.addExpressionForParamName(paramNameAttr.getAttributeValue(), 
paramValue);
                 }
             }

Modified: 
synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/MessageStoreMediatorFactory.java
URL: 
http://svn.apache.org/viewvc/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/MessageStoreMediatorFactory.java?rev=1510087&r1=1510086&r2=1510087&view=diff
==============================================================================
--- 
synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/MessageStoreMediatorFactory.java
 (original)
+++ 
synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/MessageStoreMediatorFactory.java
 Sun Aug  4 01:48:45 2013
@@ -47,21 +47,21 @@ public class MessageStoreMediatorFactory
     protected Mediator createSpecificMediator(OMElement elem, Properties 
properties) {
         MessageStoreMediator messageStoreMediator = new MessageStoreMediator();
         OMAttribute nameAtt = elem.getAttribute(ATT_NAME);
-        if(nameAtt != null) {
+        if (nameAtt != null) {
             messageStoreMediator.setName(nameAtt.getAttributeValue());
         }
 
         OMAttribute messageStoreNameAtt = elem.getAttribute(ATT_MESSAGE_STORE);
 
-        if(messageStoreNameAtt != null) {
+        if (messageStoreNameAtt != null) {
             
messageStoreMediator.setMessageStoreName(messageStoreNameAtt.getAttributeValue());
         } else {
-            throw new SynapseException("Message Store mediator must have a 
Message store defined");
+            throw new SynapseException("Message Store mediator must have a 
message store defined");
         }
 
         OMAttribute sequenceAtt = elem.getAttribute(ATT_SEQUENCE);
 
-        if(sequenceAtt != null) {
+        if (sequenceAtt != null) {
             
messageStoreMediator.setOnStoreSequence(sequenceAtt.getAttributeValue());
         }
 

Modified: 
synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/ValueFactory.java
URL: 
http://svn.apache.org/viewvc/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/ValueFactory.java?rev=1510087&r1=1510086&r2=1510087&view=diff
==============================================================================
--- 
synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/ValueFactory.java
 (original)
+++ 
synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/ValueFactory.java
 Sun Aug  4 01:48:45 2013
@@ -69,7 +69,8 @@ public class ValueFactory {
                 key = new Value(attributeValue);
             }
         } else {
-            handleException("The 'key' attribute is required for the XSLT 
mediator");
+            handleException("The '" + name + "' attribute is required on the " 
+
+                    elem.getLocalName() + " element");
         }
         return key;
     }

Modified: 
synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/template/InvokeMediator.java
URL: 
http://svn.apache.org/viewvc/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/template/InvokeMediator.java?rev=1510087&r1=1510086&r2=1510087&view=diff
==============================================================================
--- 
synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/template/InvokeMediator.java
 (original)
+++ 
synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/template/InvokeMediator.java
 Sun Aug  4 01:48:45 2013
@@ -16,6 +16,7 @@
  *  specific language governing permissions and limitations
  *  under the License.
  */
+
 package org.apache.synapse.mediators.template;
 
 import org.apache.synapse.Mediator;
@@ -25,8 +26,8 @@ import org.apache.synapse.mediators.Abst
 import org.apache.synapse.mediators.Value;
 import org.apache.synapse.mediators.eip.EIPUtils;
 
-import java.util.HashMap;
 import java.util.Iterator;
+import java.util.LinkedHashMap;
 import java.util.Map;
 
 /**
@@ -50,7 +51,8 @@ public class InvokeMediator extends Abst
     private Map<String, Value> pName2ExpressionMap;
 
     public InvokeMediator() {
-        pName2ExpressionMap = new HashMap<String, Value>();
+        // use a LinkedHashMap to maintain the order in which params are 
defined by the user
+        pName2ExpressionMap = new LinkedHashMap<String, Value>();
     }
 
     public boolean mediate(MessageContext synCtx) {

Added: 
synapse/trunk/java/modules/core/src/test/java/org/apache/synapse/config/xml/InvokeMediatorSerializationTest.java
URL: 
http://svn.apache.org/viewvc/synapse/trunk/java/modules/core/src/test/java/org/apache/synapse/config/xml/InvokeMediatorSerializationTest.java?rev=1510087&view=auto
==============================================================================
--- 
synapse/trunk/java/modules/core/src/test/java/org/apache/synapse/config/xml/InvokeMediatorSerializationTest.java
 (added)
+++ 
synapse/trunk/java/modules/core/src/test/java/org/apache/synapse/config/xml/InvokeMediatorSerializationTest.java
 Sun Aug  4 01:48:45 2013
@@ -0,0 +1,57 @@
+/*
+ *  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 InvokeMediatorSerializationTest extends AbstractTestCase {
+
+    private InvokeMediatorFactory factory;
+    private InvokeMediatorSerializer serializer;
+
+    public InvokeMediatorSerializationTest() {
+        super(InvokeMediatorSerializationTest.class.getName());
+        factory = new InvokeMediatorFactory();
+        serializer = new InvokeMediatorSerializer();
+    }
+
+    public void testInvokeMediatorSerializationScenarioOne() throws Exception {
+        String inputXml = "<call-template 
xmlns=\"http://ws.apache.org/ns/synapse\"; " +
+                "target=\"foo\"/>";
+        assertTrue(serialization(inputXml, factory, serializer));
+        assertTrue(serialization(inputXml, serializer));
+    }
+
+    public void testInvokeMediatorSerializationScenarioTwo() throws Exception {
+        String inputXml = "<call-template 
xmlns=\"http://ws.apache.org/ns/synapse\"; " +
+                "target=\"foo\"><with-param name=\"bar\" 
value=\"bar_value\"/></call-template>";
+        assertTrue(serialization(inputXml, factory, serializer));
+        assertTrue(serialization(inputXml, serializer));
+    }
+
+    public void testInvokeMediatorSerializationScenarioThree() throws 
Exception {
+        String inputXml = "<call-template 
xmlns=\"http://ws.apache.org/ns/synapse\"; " +
+                "target=\"foo\"><with-param name=\"bar\" 
value=\"bar_value\"/>" +
+                "<with-param name=\"bar2\" value=\"bar2_value\"/>" +
+                "<with-param name=\"bar3\" 
value=\"bar3_value\"/></call-template>";
+        System.out.println(inputXml);
+        
System.out.println(serializer.serializeSpecificMediator(factory.createSpecificMediator(createOMElement(inputXml),
 null)));
+        assertTrue(serialization(inputXml, factory, serializer));
+        assertTrue(serialization(inputXml, serializer));
+    }
+}

Added: 
synapse/trunk/java/modules/core/src/test/java/org/apache/synapse/config/xml/MessageStoreMediatorSerializationTest.java
URL: 
http://svn.apache.org/viewvc/synapse/trunk/java/modules/core/src/test/java/org/apache/synapse/config/xml/MessageStoreMediatorSerializationTest.java?rev=1510087&view=auto
==============================================================================
--- 
synapse/trunk/java/modules/core/src/test/java/org/apache/synapse/config/xml/MessageStoreMediatorSerializationTest.java
 (added)
+++ 
synapse/trunk/java/modules/core/src/test/java/org/apache/synapse/config/xml/MessageStoreMediatorSerializationTest.java
 Sun Aug  4 01:48:45 2013
@@ -0,0 +1,46 @@
+/*
+ *  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 MessageStoreMediatorSerializationTest extends AbstractTestCase {
+
+    private MessageStoreMediatorFactory factory;
+    private MessageStoreMediatorSerializer serializer;
+
+    public MessageStoreMediatorSerializationTest() {
+        super(MessageStoreMediatorSerializationTest.class.getName());
+        factory = new MessageStoreMediatorFactory();
+        serializer = new MessageStoreMediatorSerializer();
+    }
+
+    public void testStoreMediatorSerializationScenarioOne() throws Exception {
+        String inputXml = "<store xmlns=\"http://ws.apache.org/ns/synapse\"; " +
+                "messageStore=\"foo\"/>";
+        assertTrue(serialization(inputXml, factory, serializer));
+        assertTrue(serialization(inputXml, serializer));
+    }
+
+    public void testStoreMediatorSerializationScenarioTwo() throws Exception {
+        String inputXml = "<store xmlns=\"http://ws.apache.org/ns/synapse\"; " +
+                "messageStore=\"foo\" sequence=\"bar\"/>";
+        assertTrue(serialization(inputXml, factory, serializer));
+        assertTrue(serialization(inputXml, serializer));
+    }
+}


Reply via email to