You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@synapse.apache.org by sa...@apache.org on 2012/07/21 11:42:39 UTC
svn commit: r1364056 - in /synapse/trunk/java/modules/core/src:
main/java/org/apache/synapse/config/xml/
test/java/org/apache/synapse/config/xml/
test/java/org/apache/synapse/mediators/bean/
Author: sadeep
Date: Sat Jul 21 09:42:38 2012
New Revision: 1364056
URL: http://svn.apache.org/viewvc?rev=1364056&view=rev
Log:
SYNAPSE-838: Adding unit tests.
Added:
synapse/trunk/java/modules/core/src/test/java/org/apache/synapse/config/xml/BeanMediatorSerializationTest.java
synapse/trunk/java/modules/core/src/test/java/org/apache/synapse/config/xml/EJBMediatorSerializationTest.java
synapse/trunk/java/modules/core/src/test/java/org/apache/synapse/mediators/bean/
synapse/trunk/java/modules/core/src/test/java/org/apache/synapse/mediators/bean/BeanMediatorTest.java
synapse/trunk/java/modules/core/src/test/java/org/apache/synapse/mediators/bean/Quote.java
Modified:
synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/BeanMediatorSerializer.java
Modified: synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/BeanMediatorSerializer.java
URL: http://svn.apache.org/viewvc/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/BeanMediatorSerializer.java?rev=1364056&r1=1364055&r2=1364056&view=diff
==============================================================================
--- synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/BeanMediatorSerializer.java (original)
+++ synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/BeanMediatorSerializer.java Sat Jul 21 09:42:38 2012
@@ -63,6 +63,8 @@ public class BeanMediatorSerializer exte
case CREATE:
serializeCreateBeanCase(mediatorElem, mediator);
break;
+ case REMOVE:
+ break;
case SET_PROPERTY:
serializeSetPropertyCase(mediatorElem, mediator);
break;
Added: synapse/trunk/java/modules/core/src/test/java/org/apache/synapse/config/xml/BeanMediatorSerializationTest.java
URL: http://svn.apache.org/viewvc/synapse/trunk/java/modules/core/src/test/java/org/apache/synapse/config/xml/BeanMediatorSerializationTest.java?rev=1364056&view=auto
==============================================================================
--- synapse/trunk/java/modules/core/src/test/java/org/apache/synapse/config/xml/BeanMediatorSerializationTest.java (added)
+++ synapse/trunk/java/modules/core/src/test/java/org/apache/synapse/config/xml/BeanMediatorSerializationTest.java Sat Jul 21 09:42:38 2012
@@ -0,0 +1,96 @@
+/*
+ * 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;
+
+/**
+ * Tests Bean mediator serialization scenarios.
+ */
+public class BeanMediatorSerializationTest extends AbstractTestCase {
+
+ private BeanMediatorFactory beanMediatorFactory = new BeanMediatorFactory();
+ private BeanMediatorSerializer beanMediatorSerializer = new BeanMediatorSerializer();
+
+ public BeanMediatorSerializationTest() {
+ super(AbstractTestCase.class.getName());
+ }
+
+ public void testBeanMediatorCreateActionSerialization() throws Exception {
+
+ String inputXml = "<bean action='CREATE' class='org.apache.synapse.mediators.bean.Quote' var='test_quote' " +
+ " xmlns='http://ws.apache.org/ns/synapse'/>";
+
+ assertTrue(serialization(inputXml, beanMediatorFactory, beanMediatorSerializer));
+ assertTrue(serialization(inputXml, beanMediatorSerializer));
+ }
+
+ public void testBeanMediatorCreateNoReplaceActionSerialization() throws Exception {
+
+ String inputXml = "<bean action='CREATE' class='org.apache.synapse.mediators.bean.Quote' var='test_quote' " +
+ "replace='false' xmlns='http://ws.apache.org/ns/synapse'/>";
+
+ assertTrue(serialization(inputXml, beanMediatorFactory, beanMediatorSerializer));
+ assertTrue(serialization(inputXml, beanMediatorSerializer));
+ }
+
+ public void testBeanMediatorRemoveActionSerialization() throws Exception {
+
+ String inputXml = "<bean action='REMOVE' var='test_quote' xmlns='http://ws.apache.org/ns/synapse'/>";
+
+ assertTrue(serialization(inputXml, beanMediatorFactory, beanMediatorSerializer));
+ assertTrue(serialization(inputXml, beanMediatorSerializer));
+ }
+
+ public void testSetPropertyFromStaticValueActionSerialization() throws Exception {
+
+ String inputXml = "<bean action='SET_PROPERTY' var='test_quote' property='symbol' value='IBM' " +
+ "xmlns='http://ws.apache.org/ns/synapse'/>";
+
+ assertTrue(serialization(inputXml, beanMediatorFactory, beanMediatorSerializer));
+ assertTrue(serialization(inputXml, beanMediatorSerializer));
+ }
+
+ public void testSetPropertyFromXPathActionSerialization() throws Exception {
+
+ String inputXml = "<bean action='SET_PROPERTY' var='test_quote' property='price' value='{//m:price}' " +
+ "xmlns:m='http://services.samples' xmlns='http://ws.apache.org/ns/synapse'/>";
+
+ assertTrue(serialization(inputXml, beanMediatorFactory, beanMediatorSerializer));
+ assertTrue(serialization(inputXml, beanMediatorSerializer));
+ }
+
+ public void testGetPropertyToMCPropertyActionSerialization() throws Exception {
+
+ String inputXml = "<bean action='GET_PROPERTY' var='test_quote' property='price' target='quote_price' " +
+ "xmlns='http://ws.apache.org/ns/synapse'/>";
+
+ assertTrue(serialization(inputXml, beanMediatorFactory, beanMediatorSerializer));
+ assertTrue(serialization(inputXml, beanMediatorSerializer));
+ }
+
+ public void testGetPropertyToXPathActionSerialization() throws Exception {
+
+ String inputXml = "<bean action='GET_PROPERTY' var='test_quote' property='symbol' " +
+ "target='{//m:QuoteResponse/m:symbol}' " +
+ "xmlns:m='http://services.samples' xmlns='http://ws.apache.org/ns/synapse'/>";
+
+ assertTrue(serialization(inputXml, beanMediatorFactory, beanMediatorSerializer));
+ assertTrue(serialization(inputXml, beanMediatorSerializer));
+ }
+}
Added: synapse/trunk/java/modules/core/src/test/java/org/apache/synapse/config/xml/EJBMediatorSerializationTest.java
URL: http://svn.apache.org/viewvc/synapse/trunk/java/modules/core/src/test/java/org/apache/synapse/config/xml/EJBMediatorSerializationTest.java?rev=1364056&view=auto
==============================================================================
--- synapse/trunk/java/modules/core/src/test/java/org/apache/synapse/config/xml/EJBMediatorSerializationTest.java (added)
+++ synapse/trunk/java/modules/core/src/test/java/org/apache/synapse/config/xml/EJBMediatorSerializationTest.java Sat Jul 21 09:42:38 2012
@@ -0,0 +1,85 @@
+/*
+ * 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;
+
+/**
+ * Tests EJB mediator serialization scenarios.
+ */
+public class EJBMediatorSerializationTest extends AbstractTestCase {
+
+ private EJBMediatorFactory ejbMediatorFactory = new EJBMediatorFactory();
+ private EJBMediatorSerializer ejbMediatorSerializer = new EJBMediatorSerializer();
+
+ public EJBMediatorSerializationTest() {
+ super(AbstractTestCase.class.getName());
+ }
+
+ public void testEJBMediatorStatelessScenario1Serialization() throws Exception {
+
+ String inputXml = "<ejb class='org.apache.synapse.mediators.bean.Quote' beanstalk='demo' method='setPrice' " +
+ "jndiName='jndi' xmlns='http://ws.apache.org/ns/synapse'>" +
+ "<args><arg value=\"{get-property('price')}\"/></args></ejb>";
+
+ assertTrue(serialization(inputXml, ejbMediatorFactory, ejbMediatorSerializer));
+ assertTrue(serialization(inputXml, ejbMediatorSerializer));
+ }
+
+ public void testEJBMediatorStatelessScenario2Serialization() throws Exception {
+
+ String inputXml = "<ejb class='org.apache.synapse.mediators.bean.Quote' beanstalk='demo' method='getPrice' " +
+ "target='{//m:Price}' xmlns:m='http://services.samples' xmlns='http://ws.apache.org/ns/synapse'/>";
+
+ assertTrue(serialization(inputXml, ejbMediatorFactory, ejbMediatorSerializer));
+ assertTrue(serialization(inputXml, ejbMediatorSerializer));
+ }
+
+ public void testEJBMediatorStatelessScenario3Serialization() throws Exception {
+
+ String inputXml = "<ejb class='org.apache.synapse.mediators.bean.Quote' beanstalk='demo' method='testMethod' " +
+ "target='bar' jndiName='jndi' xmlns='http://ws.apache.org/ns/synapse'>" +
+ "<args><arg value='100'/><arg value=\"{get-property('batz')}\"/></args></ejb>";
+
+ assertTrue(serialization(inputXml, ejbMediatorFactory, ejbMediatorSerializer));
+ assertTrue(serialization(inputXml, ejbMediatorSerializer));
+ }
+
+
+ public void testEJBMediatorStatefulScenario1Serialization() throws Exception {
+
+ String inputXml = "<ejb class='org.apache.synapse.mediators.bean.Quote' beanstalk='demo' method='testMethod' " +
+ "target='bar' sessionId=\"{get-property('SESSION_ID')}\" jndiName='jndi' " +
+ "xmlns='http://ws.apache.org/ns/synapse'>" +
+ "<args><arg value='{//m:item//m:quantity}' xmlns:m='http://org.test.ejb'/>" +
+ "<arg value='{//m:item//m:id}' xmlns:m='http://org.test.ejb'/></args></ejb>";
+
+ assertTrue(serialization(inputXml, ejbMediatorFactory, ejbMediatorSerializer));
+ assertTrue(serialization(inputXml, ejbMediatorSerializer));
+ }
+
+ public void testEJBMediatorStatefulScenario2Serialization() throws Exception {
+
+ String inputXml = "<ejb class='org.apache.synapse.mediators.bean.Quote' beanstalk='demo' method='testMethod' " +
+ "target='bar' sessionId='1234' remove='true' xmlns='http://ws.apache.org/ns/synapse'>" +
+ "<args><arg value='100'/><arg value=\"{get-property('batz')}\"/></args></ejb>";
+
+ assertTrue(serialization(inputXml, ejbMediatorFactory, ejbMediatorSerializer));
+ assertTrue(serialization(inputXml, ejbMediatorSerializer));
+ }
+}
Added: synapse/trunk/java/modules/core/src/test/java/org/apache/synapse/mediators/bean/BeanMediatorTest.java
URL: http://svn.apache.org/viewvc/synapse/trunk/java/modules/core/src/test/java/org/apache/synapse/mediators/bean/BeanMediatorTest.java?rev=1364056&view=auto
==============================================================================
--- synapse/trunk/java/modules/core/src/test/java/org/apache/synapse/mediators/bean/BeanMediatorTest.java (added)
+++ synapse/trunk/java/modules/core/src/test/java/org/apache/synapse/mediators/bean/BeanMediatorTest.java Sat Jul 21 09:42:38 2012
@@ -0,0 +1,185 @@
+/*
+ * 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.bean;
+
+import org.apache.synapse.Mediator;
+import org.apache.synapse.MessageContext;
+import org.apache.synapse.TestMessageContext;
+import org.apache.synapse.config.xml.MediatorFactoryFinder;
+import org.apache.synapse.mediators.AbstractMediatorTestCase;
+import org.apache.synapse.mediators.TestUtils;
+import org.apache.synapse.util.xpath.SynapseXPath;
+
+import java.util.Properties;
+
+/**
+ * Tests Bean mediator's runtime behavior.
+ */
+public class BeanMediatorTest extends AbstractMediatorTestCase {
+
+ private static final String MESSAGE_BODY =
+ "<m:QuoteResponse xmlns:m='http://services.samples'>" +
+ "<m:symbol>SUN</m:symbol>" +
+ "<m:price>20.5</m:price>" +
+ "</m:QuoteResponse>";
+
+ private static final String VAR_NAME = "test_quote";
+
+ public void testCreateAction() throws Exception {
+
+ Mediator beanMediator = MediatorFactoryFinder.getInstance().getMediator(
+ createOMElement(
+ "<bean action='CREATE' class='org.apache.synapse.mediators.bean.Quote' var='test_quote' " +
+ "xmlns='http://ws.apache.org/ns/synapse'/>"),
+ new Properties());
+
+ MessageContext synCtx = new TestMessageContext();
+
+ assertTrue(beanMediator.mediate(synCtx));
+
+ assertNotNull(synCtx.getProperty(VAR_NAME));
+ assertTrue(synCtx.getProperty(VAR_NAME) instanceof Quote);
+ }
+
+ public void testCreateNoReplaceAction() throws Exception {
+
+ Mediator beanMediator = MediatorFactoryFinder.getInstance().getMediator(
+ createOMElement(
+ "<bean action='CREATE' class='org.apache.synapse.mediators.bean.Quote' var='test_quote' " +
+ "replace='false' xmlns='http://ws.apache.org/ns/synapse'/>"),
+ new Properties());
+
+ MessageContext synCtx = new TestMessageContext();
+ Quote existingQuote = new Quote();
+ synCtx.setProperty(VAR_NAME, existingQuote);
+
+ assertTrue(beanMediator.mediate(synCtx));
+
+ assertEquals(existingQuote, synCtx.getProperty(VAR_NAME));
+ }
+
+ public void testRemoveAction() throws Exception {
+
+ Mediator beanMediator = MediatorFactoryFinder.getInstance().getMediator(
+ createOMElement(
+ "<bean action='REMOVE' var='test_quote' xmlns='http://ws.apache.org/ns/synapse'/>"),
+ new Properties());
+
+ MessageContext synCtx = new TestMessageContext();
+ synCtx.setProperty(VAR_NAME, new Quote());
+
+ assertTrue(beanMediator.mediate(synCtx));
+
+ assertNull(synCtx.getProperty(VAR_NAME));
+ }
+
+ public void testSetPropertyFromStaticValueAction() throws Exception {
+
+ Mediator beanMediator = MediatorFactoryFinder.getInstance().getMediator(
+ createOMElement(
+ "<bean action='SET_PROPERTY' var='test_quote' property='symbol' value='IBM' " +
+ "xmlns='http://ws.apache.org/ns/synapse'/>"),
+ new Properties());
+
+ MessageContext synCtx = TestUtils.getTestContext(MESSAGE_BODY);
+ synCtx.setProperty(VAR_NAME, new Quote());
+
+ assertTrue(beanMediator.mediate(synCtx));
+
+ assertEquals("IBM", ((Quote) synCtx.getProperty(VAR_NAME)).getSymbol());
+ }
+
+ public void testSetPropertyFromMCPropertyAction() throws Exception {
+
+ Mediator beanMediator = MediatorFactoryFinder.getInstance().getMediator(
+ createOMElement(
+ "<bean action='SET_PROPERTY' var='test_quote' property='price' " +
+ "value=\"{get-property('mc_property')}\" " +
+ "xmlns:m='http://services.samples' xmlns='http://ws.apache.org/ns/synapse'/>"),
+ new Properties());
+
+ MessageContext synCtx = TestUtils.getTestContext(MESSAGE_BODY);
+ synCtx.setProperty(VAR_NAME, new Quote());
+ float price = 30.0f;
+ synCtx.setProperty("mc_property", price);
+
+ assertTrue(beanMediator.mediate(synCtx));
+
+ assertEquals(price, ((Quote) synCtx.getProperty(VAR_NAME)).getPrice());
+ }
+
+ public void testSetPropertyFromMessageBodyAction() throws Exception {
+
+ Mediator beanMediator = MediatorFactoryFinder.getInstance().getMediator(
+ createOMElement(
+ "<bean action='SET_PROPERTY' var='test_quote' property='price' value='{//m:price}' " +
+ "xmlns:m='http://services.samples' xmlns='http://ws.apache.org/ns/synapse'/>"),
+ new Properties());
+
+ MessageContext synCtx = TestUtils.getTestContext(MESSAGE_BODY);
+ synCtx.setProperty(VAR_NAME, new Quote());
+
+ assertTrue(beanMediator.mediate(synCtx));
+
+ assertEquals(new Float("20.5"), ((Quote) synCtx.getProperty(VAR_NAME)).getPrice());
+ }
+
+ public void testGetPropertyToMCPropertyAction() throws Exception {
+
+ Mediator beanMediator = MediatorFactoryFinder.getInstance().getMediator(
+ createOMElement(
+ "<bean action='GET_PROPERTY' var='test_quote' property='price' target='mc_property' " +
+ "xmlns='http://ws.apache.org/ns/synapse'/>"),
+ new Properties());
+
+ MessageContext synCtx = TestUtils.getTestContext(MESSAGE_BODY);
+ Quote quote = new Quote();
+ Float price = 10.5f;
+ quote.setPrice(price);
+ synCtx.setProperty(VAR_NAME, quote);
+
+ assertTrue(beanMediator.mediate(synCtx));
+
+ assertEquals(price, synCtx.getProperty("mc_property"));
+ }
+
+ public void testGetPropertyToMessageBodyAction() throws Exception {
+
+ Mediator beanMediator = MediatorFactoryFinder.getInstance().getMediator(
+ createOMElement(
+ "<bean action='GET_PROPERTY' var='test_quote' property='symbol' " +
+ "target='{//m:QuoteResponse/m:symbol/text()}' " +
+ "xmlns:m='http://services.samples' xmlns='http://ws.apache.org/ns/synapse'/>"),
+ new Properties());
+
+ MessageContext synCtx = TestUtils.getTestContext(MESSAGE_BODY);
+ Quote quote = new Quote();
+ String symbol = "IBM";
+ quote.setSymbol(symbol);
+ synCtx.setProperty(VAR_NAME, quote);
+
+ assertTrue(beanMediator.mediate(synCtx));
+
+ SynapseXPath xpath = new SynapseXPath("//m:QuoteResponse/m:symbol");
+ xpath.addNamespace("m", "http://services.samples");
+
+ assertEquals(symbol, xpath.stringValueOf(synCtx));
+ }
+}
Added: synapse/trunk/java/modules/core/src/test/java/org/apache/synapse/mediators/bean/Quote.java
URL: http://svn.apache.org/viewvc/synapse/trunk/java/modules/core/src/test/java/org/apache/synapse/mediators/bean/Quote.java?rev=1364056&view=auto
==============================================================================
--- synapse/trunk/java/modules/core/src/test/java/org/apache/synapse/mediators/bean/Quote.java (added)
+++ synapse/trunk/java/modules/core/src/test/java/org/apache/synapse/mediators/bean/Quote.java Sat Jul 21 09:42:38 2012
@@ -0,0 +1,50 @@
+/*
+ * 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.bean;
+
+/**
+ * Simple bean class for testing the Bean/EJB mediators.
+ */
+public class Quote {
+
+ private String symbol;
+
+ private float price;
+
+ public String getSymbol() {
+ return symbol;
+ }
+
+ public void setSymbol(String symbol) {
+ this.symbol = symbol;
+ }
+
+ public float getPrice() {
+ return price;
+ }
+
+ public void setPrice(float price) {
+ this.price = price;
+ }
+
+ public float testMethod(int i, String str) {
+ return i + str.length();
+ }
+}