Search in sources :

Example 11 with SynapseSubscription

use of org.apache.synapse.eventing.SynapseSubscription in project wso2-synapse by wso2.

the class MessageBuilderTest method testSubscriptionMessageBuilderScenarioTwo.

public void testSubscriptionMessageBuilderScenarioTwo() {
    String addressUrl = "http://synapse.test.com/eventing/subscriptions";
    String message = "<wse:Unsubscribe xmlns:wse=\"http://schemas.xmlsoap.org/ws/2004/08/eventing\"/>";
    try {
        MessageContext msgCtx = TestUtils.getAxis2MessageContext(message, null).getAxis2MessageContext();
        msgCtx.setTo(new EndpointReference(addressUrl));
        String id = addIdentifierHeader(msgCtx);
        SubscriptionMessageBuilder.resetErrorInfo();
        SynapseSubscription sub = SubscriptionMessageBuilder.createUnSubscribeMessage(msgCtx);
        assertEquals(id, sub.getId());
        assertEquals(addressUrl, sub.getAddressUrl());
        assertNull(SubscriptionMessageBuilder.getErrorCode());
        assertNull(SubscriptionMessageBuilder.getErrorReason());
        assertNull(SubscriptionMessageBuilder.getErrorSubCode());
    } catch (Exception e) {
        e.printStackTrace();
        fail("Error while constructing the sample subscription request: " + e.getMessage());
    }
}
Also used : SynapseSubscription(org.apache.synapse.eventing.SynapseSubscription) MessageContext(org.apache.axis2.context.MessageContext) EndpointReference(org.apache.axis2.addressing.EndpointReference)

Example 12 with SynapseSubscription

use of org.apache.synapse.eventing.SynapseSubscription in project wso2-synapse by wso2.

the class MessageBuilderTest method testSubscriptionMessageBuilderScenarioFive.

public void testSubscriptionMessageBuilderScenarioFive() {
    String addressUrl = "http://synapse.test.com/eventing/subscriptions";
    String message = "<wse:Renew xmlns:wse=\"http://schemas.xmlsoap.org/ws/2004/08/eventing\">\n" + "   <wse:Expires>2004-06-26T21:07:00.000-08:00</wse:Expires>\n" + "</wse:Renew>";
    try {
        MessageContext msgCtx = TestUtils.getAxis2MessageContext(message, null).getAxis2MessageContext();
        msgCtx.setTo(new EndpointReference(addressUrl));
        String id = addIdentifierHeader(msgCtx);
        SubscriptionMessageBuilder.resetErrorInfo();
        SynapseSubscription sub = SubscriptionMessageBuilder.createRenewSubscribeMessage(msgCtx);
        assertNull(id, sub.getId());
        assertEquals(addressUrl, sub.getAddressUrl());
        assertNotNull(SubscriptionMessageBuilder.getErrorCode());
        assertNotNull(SubscriptionMessageBuilder.getErrorReason());
        assertNotNull(SubscriptionMessageBuilder.getErrorSubCode());
    } catch (Exception e) {
        e.printStackTrace();
        fail("Error while constructing the sample subscription request: " + e.getMessage());
    }
}
Also used : SynapseSubscription(org.apache.synapse.eventing.SynapseSubscription) MessageContext(org.apache.axis2.context.MessageContext) EndpointReference(org.apache.axis2.addressing.EndpointReference)

Example 13 with SynapseSubscription

use of org.apache.synapse.eventing.SynapseSubscription in project wso2-synapse by wso2.

the class MessageBuilderTest method testSubscriptionMessageBuilderScenarioOne.

public void testSubscriptionMessageBuilderScenarioOne() {
    String subManUrl = "http://synapse.test.com/eventing/subscriptions";
    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 = TestUtils.getAxis2MessageContext(message, null).getAxis2MessageContext();
        msgCtx.setTo(new EndpointReference(subManUrl));
        SubscriptionMessageBuilder.resetErrorInfo();
        SynapseSubscription sub = SubscriptionMessageBuilder.createSubscription(msgCtx);
        assertEquals(subManUrl, sub.getSubManUrl());
        assertEquals(addressUrl, sub.getAddressUrl());
        assertEquals(addressUrl, sub.getEndpointUrl());
        assertEquals(filterDialect, sub.getFilterDialect());
        assertEquals(filter, sub.getFilterValue());
        assertEquals(date, sub.getExpires().getTime());
        assertNull(SubscriptionMessageBuilder.getErrorCode());
        assertNull(SubscriptionMessageBuilder.getErrorReason());
        assertNull(SubscriptionMessageBuilder.getErrorSubCode());
    } catch (Exception e) {
        fail("Error while constructing the sample subscription request: " + e.getMessage());
    }
}
Also used : SynapseSubscription(org.apache.synapse.eventing.SynapseSubscription) Calendar(java.util.Calendar) MessageContext(org.apache.axis2.context.MessageContext) Date(java.util.Date) EndpointReference(org.apache.axis2.addressing.EndpointReference)

Example 14 with SynapseSubscription

use of org.apache.synapse.eventing.SynapseSubscription in project wso2-synapse by wso2.

the class ResponseMessageBuilderTest method testGetStatusResponse.

public void testGetStatusResponse() {
    String id = UIDGenerator.generateURNString();
    String addressUrl = "http://synapse.test.com/eventing/sunscriptions";
    Date date = new Date(System.currentTimeMillis() + 3600000);
    Calendar cal = Calendar.getInstance();
    cal.setTime(date);
    SynapseSubscription sub = new SynapseSubscription();
    sub.setId(id);
    sub.setSubManUrl(addressUrl);
    sub.setExpires(cal);
    String expected = "<wse:GetStatusResponse xmlns:wse=\"http://schemas.xmlsoap.org/ws/2004/08/eventing\">" + "<wse:Expires>" + ConverterUtil.convertToString(cal) + "</wse:Expires>" + "</wse:GetStatusResponse>";
    try {
        MessageContext msgCtx = TestUtils.getAxis2MessageContext("<empty/>", null).getAxis2MessageContext();
        ResponseMessageBuilder builder = new ResponseMessageBuilder(msgCtx);
        SOAPEnvelope env = builder.genGetStatusResponse(sub);
        OMElement resultOm = env.getBody().getFirstElement();
        OMElement expectedOm = AXIOMUtil.stringToOM(expected);
        assertTrue(compare(expectedOm, resultOm));
    } catch (Exception e) {
        fail("Error while constructing the test message context: " + e.getMessage());
    }
}
Also used : SynapseSubscription(org.apache.synapse.eventing.SynapseSubscription) Calendar(java.util.Calendar) OMElement(org.apache.axiom.om.OMElement) MessageContext(org.apache.axis2.context.MessageContext) SOAPEnvelope(org.apache.axiom.soap.SOAPEnvelope) Date(java.util.Date)

Example 15 with SynapseSubscription

use of org.apache.synapse.eventing.SynapseSubscription in project wso2-synapse by wso2.

the class ResponseMessageBuilderTest method testRenewResponse.

public void testRenewResponse() {
    String id = UIDGenerator.generateURNString();
    String addressUrl = "http://synapse.test.com/eventing/sunscriptions";
    Date date = new Date(System.currentTimeMillis() + 3600000);
    Calendar cal = Calendar.getInstance();
    cal.setTime(date);
    SynapseSubscription sub = new SynapseSubscription();
    sub.setId(id);
    sub.setSubManUrl(addressUrl);
    sub.setExpires(cal);
    String expected = "<wse:RenewResponse xmlns:wse=\"http://schemas.xmlsoap.org/ws/2004/08/eventing\">" + "<wse:Expires>" + ConverterUtil.convertToString(cal) + "</wse:Expires>" + "</wse:RenewResponse>";
    try {
        MessageContext msgCtx = TestUtils.getAxis2MessageContext("<empty/>", null).getAxis2MessageContext();
        ResponseMessageBuilder builder = new ResponseMessageBuilder(msgCtx);
        SOAPEnvelope env = builder.genRenewSubscriptionResponse(sub);
        OMElement resultOm = env.getBody().getFirstElement();
        OMElement expectedOm = AXIOMUtil.stringToOM(expected);
        assertTrue(compare(expectedOm, resultOm));
    } catch (Exception e) {
        fail("Error while constructing the test message context: " + e.getMessage());
    }
}
Also used : SynapseSubscription(org.apache.synapse.eventing.SynapseSubscription) Calendar(java.util.Calendar) OMElement(org.apache.axiom.om.OMElement) MessageContext(org.apache.axis2.context.MessageContext) SOAPEnvelope(org.apache.axiom.soap.SOAPEnvelope) Date(java.util.Date)

Aggregations

SynapseSubscription (org.apache.synapse.eventing.SynapseSubscription)15 OMElement (org.apache.axiom.om.OMElement)10 MessageContext (org.apache.axis2.context.MessageContext)9 Calendar (java.util.Calendar)7 Date (java.util.Date)5 EndpointReference (org.apache.axis2.addressing.EndpointReference)5 SOAPEnvelope (org.apache.axiom.soap.SOAPEnvelope)4 SynapseException (org.apache.synapse.SynapseException)3 OMAttribute (org.apache.axiom.om.OMAttribute)2 Iterator (java.util.Iterator)1 SynapseEventSource (org.apache.synapse.eventing.SynapseEventSource)1 DefaultInMemorySubscriptionManager (org.apache.synapse.eventing.managers.DefaultInMemorySubscriptionManager)1 Test (org.junit.Test)1 SubscriptionManager (org.wso2.eventing.SubscriptionManager)1 EventException (org.wso2.eventing.exceptions.EventException)1