You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@synapse.apache.org by sa...@apache.org on 2006/05/09 07:00:14 UTC
svn commit: r405304 - in /incubator/synapse/trunk/java/modules/core:
src/org/apache/synapse/api/ src/org/apache/synapse/core/axis2/
src/org/apache/synapse/mediators/ src/org/apache/synapse/mediators/filters/
test-resources/misc/ test/org/apache/axis2/ ...
Author: saminda
Date: Mon May 8 22:00:10 2006
New Revision: 405304
URL: http://svn.apache.org/viewcvs?rev=405304&view=rev
Log:
applying patch sent by asankha
Added:
incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/core/axis2/Axis2SynapseEnvironment.java
incubator/synapse/trunk/java/modules/core/test-resources/misc/transform.xslt
incubator/synapse/trunk/java/modules/core/test/org/apache/synapse/mediators/TestUtils.java
incubator/synapse/trunk/java/modules/core/test/org/apache/synapse/mediators/filters/
incubator/synapse/trunk/java/modules/core/test/org/apache/synapse/mediators/filters/FilterMediatorTest.java
incubator/synapse/trunk/java/modules/core/test/org/apache/synapse/mediators/filters/SwitchMediatorTest.java
incubator/synapse/trunk/java/modules/core/test/org/apache/synapse/mediators/transform/
incubator/synapse/trunk/java/modules/core/test/org/apache/synapse/mediators/transform/TransformMediatorTest.java
Removed:
incubator/synapse/trunk/java/modules/core/test/org/apache/axis2/
Modified:
incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/api/ListMediator.java
incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/mediators/AbstractListMediator.java
incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/mediators/filters/SwitchCaseMediator.java
incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/mediators/filters/SwitchMediator.java
incubator/synapse/trunk/java/modules/core/test/org/apache/synapse/TestSynapseMessage.java
incubator/synapse/trunk/java/modules/core/test/org/apache/synapse/mediators/builtin/ValidateMediatorTest.java
Modified: incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/api/ListMediator.java
URL: http://svn.apache.org/viewcvs/incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/api/ListMediator.java?rev=405304&r1=405303&r2=405304&view=diff
==============================================================================
--- incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/api/ListMediator.java (original)
+++ incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/api/ListMediator.java Mon May 8 22:00:10 2006
@@ -30,6 +30,14 @@
public boolean addChild(Mediator m);
/**
+ * Appends all of the mediators in the specified collection to the end of this mediator's (children)
+ * list, in the order that they are returned by the specified collection's iterator
+ * @param c the list of mediators to be added
+ * @return true if this list changed as a result of the call
+ */
+ public boolean addAll(List c);
+
+ /**
* Returns the mediator at the specified position
* @param pos index of mediator to return
* @return the mediator at the specified position in this list
Added: incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/core/axis2/Axis2SynapseEnvironment.java
URL: http://svn.apache.org/viewcvs/incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/core/axis2/Axis2SynapseEnvironment.java?rev=405304&view=auto
==============================================================================
--- incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/core/axis2/Axis2SynapseEnvironment.java (added)
+++ incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/core/axis2/Axis2SynapseEnvironment.java Mon May 8 22:00:10 2006
@@ -0,0 +1,57 @@
+/*
+ * Copyright 2004,2005 The Apache Software Foundation.
+ *
+ * Licensed 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.core.axis2;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.synapse.SynapseContext;
+import org.apache.synapse.core.SynapseEnvironment;
+
+/**
+ * <p> This is the Axis2 implementation of the SynapseContext
+ */
+public class Axis2SynapseEnvironment implements SynapseEnvironment {
+
+ private ClassLoader cl = null;
+ private static final Log log = LogFactory.getLog(Axis2SynapseEnvironment.class);
+
+ public Axis2SynapseEnvironment(ClassLoader cl) {
+ super();
+ this.cl = cl;
+ }
+
+ public void injectMessage(SynapseContext synCtx) {
+ synCtx.setSynapseEnvironment(this);
+ synCtx.getConfiguration().getMainMediator().mediate(synCtx);
+ }
+
+ public void send(SynapseContext synCtx) {
+ if (synCtx.getSynapseMessage().isResponse())
+ Axis2Sender.sendBack(synCtx);
+ else
+ Axis2Sender.sendOn(synCtx);
+ }
+
+ public ClassLoader getClassLoader() {
+ return cl;
+ }
+
+ public void setClassLoader(ClassLoader cl) {
+ this.cl = cl;
+ }
+
+}
Modified: incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/mediators/AbstractListMediator.java
URL: http://svn.apache.org/viewcvs/incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/mediators/AbstractListMediator.java?rev=405304&r1=405303&r2=405304&view=diff
==============================================================================
--- incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/mediators/AbstractListMediator.java (original)
+++ incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/mediators/AbstractListMediator.java Mon May 8 22:00:10 2006
@@ -58,6 +58,10 @@
return mediators.add(m);
}
+ public boolean addAll(List c) {
+ return mediators.addAll(c);
+ }
+
public Mediator getChild(int pos) {
return (Mediator) mediators.get(pos);
}
Modified: incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/mediators/filters/SwitchCaseMediator.java
URL: http://svn.apache.org/viewcvs/incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/mediators/filters/SwitchCaseMediator.java?rev=405304&r1=405303&r2=405304&view=diff
==============================================================================
--- incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/mediators/filters/SwitchCaseMediator.java (original)
+++ incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/mediators/filters/SwitchCaseMediator.java Mon May 8 22:00:10 2006
@@ -18,6 +18,7 @@
import org.apache.synapse.mediators.AbstractListMediator;
import java.util.regex.Pattern;
+import java.util.List;
/**
* A SwitchCaseMediator is a list mediator which has a regex that is matched by
@@ -28,6 +29,14 @@
private Pattern regex = null;
private boolean defaultCase = false;
+ public SwitchCaseMediator() {}
+
+ public SwitchCaseMediator(Pattern regex, boolean defaultCase, List children) {
+ this.regex = regex;
+ this.defaultCase = defaultCase;
+ this.addAll(children);
+ }
+
public Pattern getRegex() {
return regex;
}
@@ -45,6 +54,8 @@
}
public boolean matches(String value) {
+ if (isDefaultCase())
+ return true;
return regex.matcher(value).matches();
}
}
Modified: incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/mediators/filters/SwitchMediator.java
URL: http://svn.apache.org/viewcvs/incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/mediators/filters/SwitchMediator.java?rev=405304&r1=405303&r2=405304&view=diff
==============================================================================
--- incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/mediators/filters/SwitchMediator.java (original)
+++ incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/mediators/filters/SwitchMediator.java Mon May 8 22:00:10 2006
@@ -75,4 +75,20 @@
public void addCase(SwitchCaseMediator m) {
cases.add(m);
}
+
+ /**
+ * Return the source XPath expression set
+ * @return thje source XPath expression
+ */
+ public AXIOMXPath getSource() {
+ return source;
+ }
+
+ /**
+ * Sets the source XPath expression
+ * @param source the XPath expression to be used as the source
+ */
+ public void setSource(AXIOMXPath source) {
+ this.source = source;
+ }
}
Added: incubator/synapse/trunk/java/modules/core/test-resources/misc/transform.xslt
URL: http://svn.apache.org/viewcvs/incubator/synapse/trunk/java/modules/core/test-resources/misc/transform.xslt?rev=405304&view=auto
==============================================================================
--- incubator/synapse/trunk/java/modules/core/test-resources/misc/transform.xslt (added)
+++ incubator/synapse/trunk/java/modules/core/test-resources/misc/transform.xslt Mon May 8 22:00:10 2006
@@ -0,0 +1,20 @@
+<?xml version="1.0" encoding="ISO-8859-1"?>
+<xsl:stylesheet version="2.0"
+ xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
+ xmlns:fn="http://www.w3.org/2005/02/xpath-functions"
+ xmlns:m0="http://www.apache-synapse.org/test"
+ exclude-result-prefixes="m0 fn">
+<xsl:output method="xml" omit-xml-declaration="yes" indent="yes"/>
+
+<xsl:template match="/">
+ <xsl:apply-templates select="//m0:CheckPriceRequest" />
+</xsl:template>
+
+<xsl:template match="m0:CheckPriceRequest">
+
+<m:GetQuote xmlns:m="http://www.webserviceX.NET/">
+ <m:symbol><xsl:value-of select="m0:Code"/></m:symbol>
+</m:GetQuote>
+
+</xsl:template>
+</xsl:stylesheet>
\ No newline at end of file
Modified: incubator/synapse/trunk/java/modules/core/test/org/apache/synapse/TestSynapseMessage.java
URL: http://svn.apache.org/viewcvs/incubator/synapse/trunk/java/modules/core/test/org/apache/synapse/TestSynapseMessage.java?rev=405304&r1=405303&r2=405304&view=diff
==============================================================================
--- incubator/synapse/trunk/java/modules/core/test/org/apache/synapse/TestSynapseMessage.java (original)
+++ incubator/synapse/trunk/java/modules/core/test/org/apache/synapse/TestSynapseMessage.java Mon May 8 22:00:10 2006
@@ -17,6 +17,7 @@
import org.apache.axiom.soap.SOAPEnvelope;
import org.apache.axiom.soap.SOAPFactory;
+import org.apache.axiom.soap.SOAP11Constants;
import org.apache.axiom.om.OMAbstractFactory;
import org.apache.axis2.AxisFault;
import org.apache.axis2.addressing.EndpointReference;
@@ -115,7 +116,7 @@
}
public boolean isSOAP11() {
- return false;
+ return envelope.getNamespace().getName().equals(SOAP11Constants.SOAP_ENVELOPE_NAMESPACE_URI);
}
public void setResponse(boolean b) {
Added: incubator/synapse/trunk/java/modules/core/test/org/apache/synapse/mediators/TestUtils.java
URL: http://svn.apache.org/viewcvs/incubator/synapse/trunk/java/modules/core/test/org/apache/synapse/mediators/TestUtils.java?rev=405304&view=auto
==============================================================================
--- incubator/synapse/trunk/java/modules/core/test/org/apache/synapse/mediators/TestUtils.java (added)
+++ incubator/synapse/trunk/java/modules/core/test/org/apache/synapse/mediators/TestUtils.java Mon May 8 22:00:10 2006
@@ -0,0 +1,52 @@
+/*
+* Copyright 2004,2005 The Apache Software Foundation.
+*
+* Licensed 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.apache.synapse.TestSynapseMessageContext;
+import org.apache.synapse.TestSynapseMessage;
+import org.apache.axiom.soap.SOAPEnvelope;
+import org.apache.axiom.om.OMAbstractFactory;
+import org.apache.axiom.om.OMDocument;
+import org.apache.axiom.om.impl.builder.StAXOMBuilder;
+
+import javax.xml.stream.XMLStreamReader;
+import javax.xml.stream.XMLInputFactory;
+import java.io.StringReader;
+
+public class TestUtils {
+
+ public static TestSynapseMessageContext getTestContext(String bodyText) throws Exception {
+
+ // create a test synapse context
+ TestSynapseMessageContext synCtx = new TestSynapseMessageContext();
+ TestSynapseMessage synMsg = new TestSynapseMessage();
+
+ 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());
+
+ synMsg.setEnvelope(envelope);
+ synCtx.setSynapseMessage(synMsg);
+ return synCtx;
+ }
+}
Modified: incubator/synapse/trunk/java/modules/core/test/org/apache/synapse/mediators/builtin/ValidateMediatorTest.java
URL: http://svn.apache.org/viewcvs/incubator/synapse/trunk/java/modules/core/test/org/apache/synapse/mediators/builtin/ValidateMediatorTest.java?rev=405304&r1=405303&r2=405304&view=diff
==============================================================================
--- incubator/synapse/trunk/java/modules/core/test/org/apache/synapse/mediators/builtin/ValidateMediatorTest.java (original)
+++ incubator/synapse/trunk/java/modules/core/test/org/apache/synapse/mediators/builtin/ValidateMediatorTest.java Mon May 8 22:00:10 2006
@@ -25,13 +25,14 @@
import org.apache.synapse.TestSynapseMessageContext;
import org.apache.synapse.mediators.TestMediateHandler;
import org.apache.synapse.mediators.TestMediator;
+import org.apache.synapse.mediators.TestUtils;
import javax.xml.stream.XMLInputFactory;
import javax.xml.stream.XMLStreamReader;
import java.io.StringReader;
import java.io.File;
-public class ValidateMediatorTest extends TestCase implements TestMediateHandler {
+public class ValidateMediatorTest extends TestCase {
private static final String VALID_ENVELOPE =
"<m0:CheckPriceRequest xmlns:m0=\"http://www.apache-synapse.org/test\">\n" +
@@ -43,16 +44,27 @@
"\t<m0:Codes>String</m0:Codes>\n" +
"</m0:CheckPriceRequest>\n";
+ private static final String VALID_ENVELOPE_NO_NS =
+ "<CheckPriceRequest xmlns=\"http://www.apache-synapse.org/test\">\n" +
+ "\t<Code>String</Code>\n" +
+ "</CheckPriceRequest>\n";
+
+ private static final String IN_VALID_ENVELOPE_NO_NS =
+ "<CheckPriceRequest xmlns=\"http://www.apache-synapse.org/test\">\n" +
+ "\t<Code>String</Code>\n" +
+ "</CheckPriceRequest>\n";
+
private boolean onFailInvoked = false;
private TestMediator testMediator = null;
public void setUp() {
testMediator = new TestMediator();
- testMediator.setHandler(this);
- }
-
- public void handle(SynapseContext synCtx) {
- onFailInvoked = true;
+ testMediator.setHandler(
+ new TestMediateHandler() {
+ public void handle(SynapseContext synCtx) {
+ setOnFailInvoked(true);
+ }
+ });
}
public void setOnFailInvoked(boolean onFailInvoked) {
@@ -66,7 +78,6 @@
ValidateMediator validate = new ValidateMediator();
// set the schema url, source xpath and any name spaces
- System.out.println("Current Dir : " + new File(".").getAbsolutePath());
validate.setSchemaUrl("test-resources/misc/validate.xsd");
AXIOMXPath source = new AXIOMXPath("//m0:CheckPriceRequest");
source.addNamespace("m0", "http://www.apache-synapse.org/test");
@@ -76,7 +87,7 @@
validate.addChild(testMediator);
// test validate mediator, with static enveope
- validate.mediate(getTestContext(VALID_ENVELOPE));
+ validate.mediate(TestUtils.getTestContext(VALID_ENVELOPE));
assertTrue(!onFailInvoked);
}
@@ -97,31 +108,50 @@
validate.addChild(testMediator);
// test validate mediator, with static enveope
- validate.mediate(getTestContext(IN_VALID_ENVELOPE));
+ validate.mediate(TestUtils.getTestContext(IN_VALID_ENVELOPE));
assertTrue(onFailInvoked);
}
- private TestSynapseMessageContext getTestContext(String bodyText) throws Exception {
+ public void testValidateMedaitorValidCaseNoNS() throws Exception {
+ setOnFailInvoked(false);
+
+ // create a validate mediator
+ ValidateMediator validate = new ValidateMediator();
- // create a test synapse context
- TestSynapseMessageContext synCtx = new TestSynapseMessageContext();
- TestSynapseMessage synMsg = new TestSynapseMessage();
-
- 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());
-
- synMsg.setEnvelope(envelope);
- synCtx.setSynapseMessage(synMsg);
- return synCtx;
+ // set the schema url, source xpath and any name spaces
+ validate.setSchemaUrl("test-resources/misc/validate.xsd");
+ AXIOMXPath source = new AXIOMXPath("//m0:CheckPriceRequest");
+ source.addNamespace("m0", "http://www.apache-synapse.org/test");
+ validate.setSource(source);
+
+ // set dummy mediator to be called on fail
+ validate.addChild(testMediator);
+
+ // test validate mediator, with static enveope
+ validate.mediate(TestUtils.getTestContext(VALID_ENVELOPE_NO_NS));
+
+ assertTrue(!onFailInvoked);
}
+ public void testValidateMedaitorInvalidCaseNoNS() throws Exception {
+ setOnFailInvoked(false);
+
+ // create a validate mediator
+ ValidateMediator validate = new ValidateMediator();
+
+ // set the schema url, source xpath and any name spaces
+ validate.setSchemaUrl("modules/core/test-resources/misc/validate.xsd");
+ AXIOMXPath source = new AXIOMXPath("//m0:CheckPriceRequest");
+ source.addNamespace("m0", "http://www.apache-synapse.org/test");
+ validate.setSource(source);
+
+ // set dummy mediator to be called on fail
+ validate.addChild(testMediator);
+
+ // test validate mediator, with static enveope
+ validate.mediate(TestUtils.getTestContext(IN_VALID_ENVELOPE_NO_NS));
+
+ assertTrue(onFailInvoked);
+ }
}
Added: incubator/synapse/trunk/java/modules/core/test/org/apache/synapse/mediators/filters/FilterMediatorTest.java
URL: http://svn.apache.org/viewcvs/incubator/synapse/trunk/java/modules/core/test/org/apache/synapse/mediators/filters/FilterMediatorTest.java?rev=405304&view=auto
==============================================================================
--- incubator/synapse/trunk/java/modules/core/test/org/apache/synapse/mediators/filters/FilterMediatorTest.java (added)
+++ incubator/synapse/trunk/java/modules/core/test/org/apache/synapse/mediators/filters/FilterMediatorTest.java Mon May 8 22:00:10 2006
@@ -0,0 +1,142 @@
+/*
+* Copyright 2004,2005 The Apache Software Foundation.
+*
+* Licensed 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.filters;
+
+import junit.framework.TestCase;
+import org.apache.synapse.mediators.TestMediateHandler;
+import org.apache.synapse.mediators.TestMediator;
+import org.apache.synapse.mediators.TestUtils;
+import org.apache.synapse.SynapseContext;
+import org.apache.axiom.om.xpath.AXIOMXPath;
+
+import java.util.regex.Pattern;
+
+public class FilterMediatorTest extends TestCase {
+
+ private static final String REQ =
+ "<m:GetQuote xmlns:m=\"http://www.webserviceX.NET/\">\n" +
+ "\t<m:symbol>IBM</m:symbol>\n" +
+ "</m:GetQuote>";
+
+ private boolean filterConditionPassed = false;
+ TestMediator testMediator = new TestMediator();
+
+ public void setUp() {
+ testMediator = new TestMediator();
+ testMediator.setHandler(
+ new TestMediateHandler() {
+ public void handle(SynapseContext synCtx) {
+ setFilterConditionPassed(true);
+ }
+ });
+ }
+
+ public void testFilterConditionTrueXPath() throws Exception {
+ setFilterConditionPassed(false);
+
+ // create a new filter mediator
+ FilterMediator filter = new FilterMediator();
+
+ // set xpath condition to IBM
+ AXIOMXPath xpath = new AXIOMXPath("//*[wsx:symbol='IBM']");
+ xpath.addNamespace("wsx", "http://www.webserviceX.NET/");
+ filter.setXpath(xpath);
+
+ // set dummy mediator to be called on success
+ filter.addChild(testMediator);
+
+ // test validate mediator, with static enveope
+ filter.mediate(TestUtils.getTestContext(REQ));
+
+ assertTrue(filterConditionPassed);
+ }
+
+ public void testFilterConditionFalseXPath() throws Exception {
+ setFilterConditionPassed(false);
+
+ // create a new filter mediator
+ FilterMediator filter = new FilterMediator();
+
+ // set xpath condition to MSFT
+ AXIOMXPath xpath = new AXIOMXPath("//*[wsx:symbol='MSFT']");
+ xpath.addNamespace("wsx", "http://www.webserviceX.NET/");
+ filter.setXpath(xpath);
+
+ // set dummy mediator to be called on success
+ filter.addChild(testMediator);
+
+ // test validate mediator, with static enveope
+ filter.mediate(TestUtils.getTestContext(REQ));
+
+ assertTrue(!filterConditionPassed);
+ }
+
+ public void testFilterConditionTrueRegex() throws Exception {
+ setFilterConditionPassed(false);
+
+ // create a new filter mediator
+ FilterMediator filter = new FilterMediator();
+
+ // set source xpath condition to //symbol
+ AXIOMXPath source = new AXIOMXPath("//wsx:symbol");
+ source.addNamespace("wsx", "http://www.webserviceX.NET/");
+ filter.setSource(source);
+
+ // set regex to IBM
+ Pattern regex = Pattern.compile("IBM");
+ filter.setRegex(regex);
+
+ // set dummy mediator to be called on success
+ filter.addChild(testMediator);
+
+ // test validate mediator, with static enveope
+ filter.mediate(TestUtils.getTestContext(REQ));
+
+ assertTrue(filterConditionPassed);
+ }
+
+ public void testFilterConditionFalseRegex() throws Exception {
+ setFilterConditionPassed(false);
+
+ // create a new filter mediator
+ FilterMediator filter = new FilterMediator();
+
+ // set source xpath condition to //symbol
+ AXIOMXPath source = new AXIOMXPath("//wsx:symbol");
+ source.addNamespace("wsx", "http://www.webserviceX.NET/");
+ filter.setSource(source);
+
+ // set regex to MSFT
+ Pattern regex = Pattern.compile("MSFT");
+ filter.setRegex(regex);
+
+ // set dummy mediator to be called on success
+ filter.addChild(testMediator);
+
+ // test validate mediator, with static enveope
+ filter.mediate(TestUtils.getTestContext(REQ));
+
+ assertTrue(!filterConditionPassed);
+ }
+
+ public boolean isFilterConditionPassed() {
+ return filterConditionPassed;
+ }
+
+ public void setFilterConditionPassed(boolean filterConditionPassed) {
+ this.filterConditionPassed = filterConditionPassed;
+ }
+}
Added: incubator/synapse/trunk/java/modules/core/test/org/apache/synapse/mediators/filters/SwitchMediatorTest.java
URL: http://svn.apache.org/viewcvs/incubator/synapse/trunk/java/modules/core/test/org/apache/synapse/mediators/filters/SwitchMediatorTest.java?rev=405304&view=auto
==============================================================================
--- incubator/synapse/trunk/java/modules/core/test/org/apache/synapse/mediators/filters/SwitchMediatorTest.java (added)
+++ incubator/synapse/trunk/java/modules/core/test/org/apache/synapse/mediators/filters/SwitchMediatorTest.java Mon May 8 22:00:10 2006
@@ -0,0 +1,131 @@
+/*
+* Copyright 2004,2005 The Apache Software Foundation.
+*
+* Licensed 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.filters;
+
+import junit.framework.TestCase;
+import org.apache.synapse.mediators.TestMediateHandler;
+import org.apache.synapse.mediators.TestMediator;
+import org.apache.synapse.mediators.TestUtils;
+import org.apache.synapse.SynapseContext;
+import org.apache.synapse.api.Mediator;
+import org.apache.axiom.om.xpath.AXIOMXPath;
+
+import java.util.regex.Pattern;
+import java.util.ArrayList;
+import java.util.Arrays;
+
+public class SwitchMediatorTest extends TestCase {
+
+ private static final String IBM_REQ =
+ "<m:GetQuote xmlns:m=\"http://www.webserviceX.NET/\">\n" +
+ "\t<m:symbol>IBM</m:symbol>\n" +
+ "</m:GetQuote>";
+
+ private static final String MSFT_REQ =
+ "<m:GetQuote xmlns:m=\"http://www.webserviceX.NET/\">\n" +
+ "\t<m:symbol>MSFT</m:symbol>\n" +
+ "</m:GetQuote>";
+
+ private static final String DEFAULT_REQ =
+ "<m:GetQuote xmlns:m=\"http://www.webserviceX.NET/\">\n" +
+ "\t<m:symbol>SUN</m:symbol>\n" +
+ "</m:GetQuote>";
+
+ private String executedCase = null;
+ TestMediator ibmMediator, msftMediator, defaultMediator;
+ SwitchMediator switchMediator = null;
+
+ public void setUp() throws Exception {
+
+ ibmMediator = new TestMediator();
+ ibmMediator.setHandler(
+ new TestMediateHandler() {
+ public void handle(SynapseContext synCtx) {
+ setExecutedCase("IBM");
+ }
+ });
+
+ msftMediator = new TestMediator();
+ msftMediator.setHandler(
+ new TestMediateHandler() {
+ public void handle(SynapseContext synCtx) {
+ setExecutedCase("MSFT");
+ }
+ });
+
+ defaultMediator = new TestMediator();
+ defaultMediator.setHandler(
+ new TestMediateHandler() {
+ public void handle(SynapseContext synCtx) {
+ setExecutedCase("DEFAULT");
+ }
+ });
+
+ // create a new switch mediator
+ switchMediator = new SwitchMediator();
+
+ // set xpath condition to select symbol
+ AXIOMXPath xpath = new AXIOMXPath("//wsx:symbol");
+ xpath.addNamespace("wsx", "http://www.webserviceX.NET/");
+ switchMediator.setSource(xpath);
+
+ // set ibm mediator to be called for IBM, msft for MSFT and default for others..
+ switchMediator.addCase(new SwitchCaseMediator(Pattern.compile("IBM"), false,
+ Arrays.asList(new Mediator[] {ibmMediator})));
+ switchMediator.addCase(new SwitchCaseMediator(Pattern.compile("MSFT"), false,
+ Arrays.asList(new Mediator[] {msftMediator})));
+ switchMediator.addCase(new SwitchCaseMediator(null, true,
+ Arrays.asList(new Mediator[] {defaultMediator})));
+ }
+
+ public void testSwitchConditionCaseOne() throws Exception {
+ setExecutedCase(null);
+
+ // test switch mediator, with static enveope
+ switchMediator.mediate(TestUtils.getTestContext(IBM_REQ));
+
+ assertTrue("IBM".equals(getExecutedCase()));
+ }
+
+ public void testSwitchConditionCaseTwo() throws Exception {
+ setExecutedCase(null);
+
+ // test switch mediator, with static enveope
+ switchMediator.mediate(TestUtils.getTestContext(MSFT_REQ));
+
+ assertTrue("MSFT".equals(getExecutedCase()));
+ }
+
+ public void testSwitchConditionCaseDefault() throws Exception {
+ setExecutedCase(null);
+
+ // test switch mediator, with static enveope
+ switchMediator.mediate(TestUtils.getTestContext(DEFAULT_REQ));
+
+ assertTrue("DEFAULT".equals(getExecutedCase()));
+ }
+
+ public String getExecutedCase() {
+ return executedCase;
+ }
+
+ public void setExecutedCase(String executedCase) {
+ if (this.executedCase != null) {
+ throw new RuntimeException("Case already executed");
+ }
+ this.executedCase = executedCase;
+ }
+}
Added: incubator/synapse/trunk/java/modules/core/test/org/apache/synapse/mediators/transform/TransformMediatorTest.java
URL: http://svn.apache.org/viewcvs/incubator/synapse/trunk/java/modules/core/test/org/apache/synapse/mediators/transform/TransformMediatorTest.java?rev=405304&view=auto
==============================================================================
--- incubator/synapse/trunk/java/modules/core/test/org/apache/synapse/mediators/transform/TransformMediatorTest.java (added)
+++ incubator/synapse/trunk/java/modules/core/test/org/apache/synapse/mediators/transform/TransformMediatorTest.java Mon May 8 22:00:10 2006
@@ -0,0 +1,155 @@
+/*
+* Copyright 2004,2005 The Apache Software Foundation.
+*
+* Licensed 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.transform;
+
+import junit.framework.TestCase;
+import org.apache.axiom.om.xpath.AXIOMXPath;
+import org.apache.axiom.om.OMContainer;
+import org.apache.axiom.om.OMElement;
+import org.apache.synapse.mediators.TestUtils;
+import org.apache.synapse.SynapseContext;
+
+import java.net.URL;
+import java.io.File;
+
+public class TransformMediatorTest extends TestCase {
+
+ private static final String SOURCE =
+ "<m0:CheckPriceRequest xmlns:m0=\"http://www.apache-synapse.org/test\">\n" +
+ "<m0:Code>String</m0:Code>\n" +
+ "</m0:CheckPriceRequest>";
+
+ private static final String ENCLOSING_SOURCE =
+ "<m:someOtherElement xmlns:m=\"http://someother\">" +
+ "<m0:CheckPriceRequest xmlns:m0=\"http://www.apache-synapse.org/test\">\n" +
+ "<m0:Code>String</m0:Code>\n" +
+ "</m0:CheckPriceRequest>" +
+ "</m:someOtherElement>";
+
+ TransformMediator transformMediator = null;
+
+ public void testTransformXSLTCustomSource() throws Exception {
+
+ // create a new switch mediator
+ transformMediator = new TransformMediator();
+
+ // set xpath condition to select source
+ AXIOMXPath xpath = new AXIOMXPath("//m0:CheckPriceRequest");
+ xpath.addNamespace("m0", "http://www.apache-synapse.org/test");
+ transformMediator.setSource(xpath);
+
+ // set XSLT transformation URL
+ transformMediator.setXsltUrl(
+ new URL("file:///" + new File(".").getAbsolutePath() + "/test-resources/misc/transform.xslt"));
+
+ // invoke transformation, with static enveope
+ SynapseContext synCtx = TestUtils.getTestContext(SOURCE);
+ transformMediator.mediate(synCtx);
+
+ // validate result
+ OMContainer body = synCtx.getSynapseMessage().getEnvelope().getBody();
+ if (body.getFirstOMChild() instanceof OMElement) {
+
+ OMElement getQuoteElem = (OMElement) body.getFirstOMChild();
+ assertTrue("GetQuote".equals(getQuoteElem.getLocalName()));
+ assertTrue("http://www.webserviceX.NET/".equals(getQuoteElem.getNamespace().getName()));
+
+ OMElement symbolElem = getQuoteElem.getFirstElement();
+ assertTrue("symbol".equals(symbolElem.getLocalName()));
+ assertTrue("http://www.webserviceX.NET/".equals(symbolElem.getNamespace().getName()));
+
+ assertTrue("String".equals(symbolElem.getText()));
+ } else {
+ fail("Unexpected element found in SOAP body");
+ }
+ }
+
+ /**
+ * If a source element for transformation is not found, default to soap body
+ * @throws Exception
+ */
+ public void testTransformXSLTDefaultSource() throws Exception {
+
+ // create a new switch mediator
+ transformMediator = new TransformMediator();
+
+ // set XSLT transformation URL
+ transformMediator.setXsltUrl(
+ new URL("file:///" + new File(".").getAbsolutePath() + "/test-resources/misc/transform.xslt"));
+
+ // invoke transformation, with static enveope
+ SynapseContext synCtx = TestUtils.getTestContext(SOURCE);
+ transformMediator.mediate(synCtx);
+
+ // validate result
+ OMContainer body = synCtx.getSynapseMessage().getEnvelope().getBody();
+ if (body.getFirstOMChild() instanceof OMElement) {
+
+ OMElement getQuoteElem = (OMElement) body.getFirstOMChild();
+ assertTrue("GetQuote".equals(getQuoteElem.getLocalName()));
+ assertTrue("http://www.webserviceX.NET/".equals(getQuoteElem.getNamespace().getName()));
+
+ OMElement symbolElem = getQuoteElem.getFirstElement();
+ assertTrue("symbol".equals(symbolElem.getLocalName()));
+ assertTrue("http://www.webserviceX.NET/".equals(symbolElem.getNamespace().getName()));
+
+ assertTrue("String".equals(symbolElem.getText()));
+ } else {
+ fail("Unexpected element found in SOAP body");
+ }
+ }
+
+ public void testTransformXSLTCustomSourceNonMainElement() throws Exception {
+
+ // create a new switch mediator
+ transformMediator = new TransformMediator();
+
+ // set xpath condition to select source
+ AXIOMXPath xpath = new AXIOMXPath("//m0:CheckPriceRequest");
+ xpath.addNamespace("m0", "http://www.apache-synapse.org/test");
+ transformMediator.setSource(xpath);
+
+ // set XSLT transformation URL
+ transformMediator.setXsltUrl(
+ new URL("file:///" + new File(".").getAbsolutePath() + "/test-resources/misc/transform.xslt"));
+
+ // invoke transformation, with static enveope
+ SynapseContext synCtx = TestUtils.getTestContext(ENCLOSING_SOURCE);
+ transformMediator.mediate(synCtx);
+
+ // validate result
+ OMContainer body = synCtx.getSynapseMessage().getEnvelope().getBody();
+ if (body.getFirstOMChild() instanceof OMElement) {
+
+ OMElement someOtherElem = (OMElement) body.getFirstOMChild();
+ assertTrue("someOtherElement".equals(someOtherElem.getLocalName()));
+ assertTrue("http://someother".equals(someOtherElem.getNamespace().getName()));
+
+ OMElement getQuoteElem = (OMElement) someOtherElem.getFirstOMChild();
+ assertTrue("GetQuote".equals(getQuoteElem.getLocalName()));
+ assertTrue("http://www.webserviceX.NET/".equals(getQuoteElem.getNamespace().getName()));
+
+ OMElement symbolElem = getQuoteElem.getFirstElement();
+ assertTrue("symbol".equals(symbolElem.getLocalName()));
+ assertTrue("http://www.webserviceX.NET/".equals(symbolElem.getNamespace().getName()));
+
+ assertTrue("String".equals(symbolElem.getText()));
+ } else {
+ fail("Unexpected element found in SOAP body");
+ }
+ }
+
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: synapse-dev-unsubscribe@ws.apache.org
For additional commands, e-mail: synapse-dev-help@ws.apache.org