You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@synapse.apache.org by hi...@apache.org on 2010/05/06 11:11:53 UTC
svn commit: r941619 -
/synapse/trunk/java/modules/core/src/test/java/org/apache/synapse/eventing/SynapseEventSourceTest.java
Author: hiranya
Date: Thu May 6 09:11:52 2010
New Revision: 941619
URL: http://svn.apache.org/viewvc?rev=941619&view=rev
Log:
Event source tests
Added:
synapse/trunk/java/modules/core/src/test/java/org/apache/synapse/eventing/SynapseEventSourceTest.java
Added: synapse/trunk/java/modules/core/src/test/java/org/apache/synapse/eventing/SynapseEventSourceTest.java
URL: http://svn.apache.org/viewvc/synapse/trunk/java/modules/core/src/test/java/org/apache/synapse/eventing/SynapseEventSourceTest.java?rev=941619&view=auto
==============================================================================
--- synapse/trunk/java/modules/core/src/test/java/org/apache/synapse/eventing/SynapseEventSourceTest.java (added)
+++ synapse/trunk/java/modules/core/src/test/java/org/apache/synapse/eventing/SynapseEventSourceTest.java Thu May 6 09:11:52 2010
@@ -0,0 +1,131 @@
+/*
+ * 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.eventing;
+
+import org.apache.axis2.context.MessageContext;
+import org.apache.axis2.context.ConfigurationContext;
+import org.apache.axis2.engine.AxisConfiguration;
+import org.apache.axis2.databinding.utils.ConverterUtil;
+import org.apache.axis2.addressing.EndpointReference;
+import org.apache.synapse.config.SynapseConfiguration;
+import org.apache.synapse.SynapseConstants;
+import org.apache.synapse.eventing.managers.DefaultInMemorySubscriptionManager;
+import org.apache.synapse.mediators.TestUtils;
+import org.apache.synapse.core.SynapseEnvironment;
+import org.apache.synapse.core.axis2.Axis2SynapseEnvironment;
+import org.wso2.eventing.SubscriptionManager;
+import org.wso2.eventing.EventingConstants;
+import org.wso2.eventing.exceptions.EventException;
+import junit.framework.TestCase;
+
+import java.util.Date;
+import java.util.Calendar;
+
+public class SynapseEventSourceTest extends TestCase {
+
+ private SubscriptionManager subMan;
+ private SynapseEventSource source;
+
+ private static final String SUB_MAN_URL = "http://synapse.test.com/eventing/subscriptions";
+
+ protected void setUp() throws Exception {
+ source = new SynapseEventSource("foo");
+ subMan = new DefaultInMemorySubscriptionManager();
+ source.setSubscriptionManager(subMan);
+ }
+
+ public void testSubscriptionHandling() {
+ subscribeTest();
+ }
+
+ private void subscribeTest() {
+ String addressUrl = "http://www.other.example.com/OnStormWarning";
+ String filterDialect = "http://www.example.org/topicFilter";
+ String filter = "weather.storms";
+ Date date = new Date(System.currentTimeMillis() + 3600000);
+ Calendar cal = Calendar.getInstance();
+ cal.setTime(date);
+
+ String message =
+ "<wse:Subscribe xmlns:wse=\"http://schemas.xmlsoap.org/ws/2004/08/eventing\" " +
+ " xmlns:wsa=\"http://schemas.xmlsoap.org/ws/2004/08/addressing\" " +
+ " xmlns:ew=\"http://www.example.com/warnings\">\n" +
+ " <wse:EndTo>\n" +
+ " <wsa:Address>http://www.example.com/MyEventSink</wsa:Address>\n" +
+ " <wsa:ReferenceProperties>\n" +
+ " <ew:MySubscription>2597</ew:MySubscription>\n" +
+ " </wsa:ReferenceProperties>\n" +
+ " </wse:EndTo>\n" +
+ " <wse:Delivery>\n" +
+ " <wse:NotifyTo>\n" +
+ " <wsa:Address>" + addressUrl + "</wsa:Address>\n" +
+ " <wsa:ReferenceProperties>\n" +
+ " <ew:MySubscription>2597</ew:MySubscription>\n" +
+ " </wsa:ReferenceProperties>\n" +
+ " </wse:NotifyTo>\n" +
+ " </wse:Delivery>\n" +
+ " <wse:Expires>" + ConverterUtil.convertToString(cal) + "</wse:Expires>\n" +
+ " <wse:Filter xmlns:ow=\"http://www.example.org/oceanwatch\"\n" +
+ " Dialect=\"" + filterDialect + "\" >" + filter +"</wse:Filter>\n" +
+ "</wse:Subscribe>";
+
+ try {
+ MessageContext msgCtx = createMessageContext(message, EventingConstants.WSE_SUBSCRIBE);
+ source.receive(msgCtx);
+
+ } catch (Exception ignored) {
+
+ }
+
+ try {
+ assertEquals(1, subMan.getSubscriptions().size());
+ SynapseSubscription s = (SynapseSubscription) subMan.getSubscriptions().get(0);
+ assertEquals(SUB_MAN_URL, s.getSubManUrl());
+ assertEquals(addressUrl, s.getAddressUrl());
+ assertEquals(filterDialect, s.getFilterDialect());
+ assertEquals(filter, s.getFilterValue());
+ assertEquals(date, s.getExpires().getTime());
+ } catch (EventException e) {
+ fail("Eventing exception occured while accessing the subscription manager");
+ }
+ }
+
+ private MessageContext createMessageContext(String payload, String action) {
+ try {
+ SynapseConfiguration synapseConfig = new SynapseConfiguration();
+ AxisConfiguration axisConfig = new AxisConfiguration();
+ synapseConfig.setAxisConfiguration(axisConfig);
+ ConfigurationContext cfgCtx = new ConfigurationContext(axisConfig);
+ SynapseEnvironment env = new Axis2SynapseEnvironment(cfgCtx, synapseConfig);
+ axisConfig.addParameter(SynapseConstants.SYNAPSE_CONFIG, synapseConfig);
+ axisConfig.addParameter(SynapseConstants.SYNAPSE_ENV, env);
+
+ MessageContext msgCtx = TestUtils.getAxis2MessageContext(payload, null).
+ getAxis2MessageContext();
+ msgCtx.setConfigurationContext(cfgCtx);
+ msgCtx.setTo(new EndpointReference(SUB_MAN_URL));
+ msgCtx.setWSAAction(action);
+ return msgCtx;
+ } catch (Exception e) {
+ fail();
+ }
+ return null;
+ }
+}