Search in sources :

Example 6 with Event

use of org.talend.esb.sam.common.event.Event in project tesb-rt-se by Talend.

the class ClientSAMEnabledTest method testServiceCallOneway.

@Test
public void testServiceCallOneway() {
    queue.clear();
    Customer cust = new Customer();
    cust.setName("test");
    customerService.updateCustomer(cust);
    try {
        Thread.sleep(500);
    } catch (InterruptedException e) {
        e.printStackTrace();
    }
    List<Event> eventsList = new ArrayList<Event>();
    while (!queue.isEmpty()) {
        eventsList.add(queue.remove());
    }
    checkEventsNum(eventsList, 1);
    checkFlowIdPresentAndSame(eventsList);
    checkReq_Out(eventsList.get(0));
    checkNonNullFields(eventsList);
}
Also used : Customer(com.example.customerservice.Customer) ArrayList(java.util.ArrayList) Event(org.talend.esb.sam.common.event.Event) Test(org.junit.Test)

Example 7 with Event

use of org.talend.esb.sam.common.event.Event in project tesb-rt-se by Talend.

the class EventProducerTest method testServiceCallOneway.

@Test
public void testServiceCallOneway() {
    queue.clear();
    Customer cust = new Customer();
    cust.setName("test");
    customerService.updateCustomer(cust);
    try {
        Thread.sleep(500);
    } catch (InterruptedException e) {
        e.printStackTrace();
    }
    List<Event> eventsList = new ArrayList<Event>();
    while (!queue.isEmpty()) {
        eventsList.add(queue.remove());
    }
    checkEventsNum(eventsList, 2);
    checkFlowIdPresentAndSame(eventsList);
    checkMessageIdPresentAndSame(eventsList, true);
    checkReq_Out(eventsList.get(0));
    checkReq_In(eventsList.get(1));
    checkNonNullFields(eventsList);
}
Also used : Customer(com.example.customerservice.Customer) ArrayList(java.util.ArrayList) Event(org.talend.esb.sam.common.event.Event) Test(org.junit.Test)

Example 8 with Event

use of org.talend.esb.sam.common.event.Event in project tesb-rt-se by Talend.

the class MessageToEventMapperTest method testMapEventRest.

@Test
public void testMapEventRest() throws IOException, EndpointException {
    QName portType = new QName("PORT_TYPE");
    EndpointInfo info = EasyMock.createMock(EndpointInfo.class);
    EasyMock.expect(info.getName()).andReturn(portType).anyTimes();
    EasyMock.expect(info.getAddress()).andReturn(null).anyTimes();
    EasyMock.replay(info);
    Endpoint endpoint = EasyMock.createMock(Endpoint.class);
    EasyMock.expect(endpoint.getEndpointInfo()).andReturn(info).anyTimes();
    Map<String, String> samProperties = new HashMap<String, String>();
    EasyMock.expect(endpoint.get(EventFeature.SAM_PROPERTIES)).andReturn(samProperties).anyTimes();
    EasyMock.replay(endpoint);
    Message outMessage = EasyMock.createMock(Message.class);
    EasyMock.expect(outMessage.containsKey(Message.HTTP_REQUEST_METHOD)).andReturn(true).anyTimes();
    EasyMock.expect(outMessage.get(Message.HTTP_REQUEST_METHOD)).andReturn("POST").anyTimes();
    EasyMock.expect(outMessage.containsKey(Message.REQUEST_URI)).andReturn(true).anyTimes();
    EasyMock.expect(outMessage.get(Message.REQUEST_URI)).andReturn("REQUEST_URI").anyTimes();
    EasyMock.expect(outMessage.containsKey(Message.BASE_PATH)).andReturn(true).anyTimes();
    EasyMock.expect(outMessage.get(Message.BASE_PATH)).andReturn("REQUEST_URI").anyTimes();
    EasyMock.replay(outMessage);
    Exchange e = EasyMock.createMock(Exchange.class);
    EasyMock.expect(e.getOutMessage()).andReturn(outMessage).anyTimes();
    EasyMock.expect(e.getOutFaultMessage()).andReturn(null).anyTimes();
    EasyMock.expect(e.getInFaultMessage()).andReturn(null).anyTimes();
    EasyMock.expect(e.getBinding()).andReturn(null).anyTimes();
    EasyMock.expect(e.getEndpoint()).andReturn(endpoint).anyTimes();
    EasyMock.expect(e.get("org.apache.cxf.resource.operation.name")).andReturn("operationName").anyTimes();
    EasyMock.replay(e);
    AuthorizationPolicy authPolicy = EasyMock.createMock(AuthorizationPolicy.class);
    EasyMock.expect(authPolicy.getUserName()).andReturn("USERNAME").anyTimes();
    EasyMock.replay(authPolicy);
    CachedOutputStream cos = new CachedOutputStream();
    cos.write(1);
    cos.write(2);
    cos.write(3);
    Message message = EasyMock.createNiceMock(Message.class);
    EasyMock.expect(message.entrySet()).andReturn(null).anyTimes();
    EasyMock.expect(message.get(Message.REQUESTOR_ROLE)).andReturn(true).anyTimes();
    EasyMock.expect(message.getExchange()).andReturn(e).anyTimes();
    EasyMock.expect(message.get(Message.ENCODING)).andReturn("UTF-8").anyTimes();
    EasyMock.expect(message.getContent(CachedOutputStream.class)).andReturn(cos).anyTimes();
    EasyMock.expect(message.get("FlowId")).andReturn(FlowID).anyTimes();
    EasyMock.expect(message.get(CorrelationIdHelper.CORRELATION_ID_KEY)).andReturn("CORRELATION_ID_KEY").anyTimes();
    EasyMock.expect(message.get(Message.ACCEPT_CONTENT_TYPE)).andReturn("XML").anyTimes();
    EasyMock.expect(message.get(Message.CONTENT_TYPE)).andReturn("XML").anyTimes();
    EasyMock.expect(message.get(Message.RESPONSE_CODE)).andReturn(0).anyTimes();
    EasyMock.expect(message.get(SecurityContext.class)).andReturn(null).anyTimes();
    EasyMock.expect(message.get(AuthorizationPolicy.class)).andReturn(authPolicy).anyTimes();
    EasyMock.expect(message.get(CustomInfo.class)).andReturn(EasyMock.createMock(CustomInfo.class)).anyTimes();
    EasyMock.replay(message);
    MessageToEventMapper mapper = new MessageToEventMapper();
    mapper.setMaxContentLength(2);
    Event event = mapper.mapToEvent(message);
    Assert.assertEquals(EventTypeEnum.RESP_IN, event.getEventType());
    Assert.assertEquals("PORT_TYPE", event.getMessageInfo().getPortType());
    Assert.assertEquals("POST[/]", event.getMessageInfo().getOperationName());
    Assert.assertEquals("http://cxf.apache.org/transports/http", event.getMessageInfo().getTransportType());
    Assert.assertEquals(FlowID, event.getMessageInfo().getFlowId());
    Assert.assertNull(event.getMessageInfo().getMessageId());
}
Also used : Message(org.apache.cxf.message.Message) HashMap(java.util.HashMap) QName(javax.xml.namespace.QName) MessageToEventMapper(org.talend.esb.sam.agent.eventproducer.MessageToEventMapper) CachedOutputStream(org.apache.cxf.io.CachedOutputStream) Exchange(org.apache.cxf.message.Exchange) EndpointInfo(org.apache.cxf.service.model.EndpointInfo) AuthorizationPolicy(org.apache.cxf.configuration.security.AuthorizationPolicy) Endpoint(org.apache.cxf.endpoint.Endpoint) DefaultSecurityContext(org.apache.cxf.interceptor.security.DefaultSecurityContext) SecurityContext(org.apache.cxf.security.SecurityContext) CustomInfo(org.talend.esb.sam.agent.message.CustomInfo) Event(org.talend.esb.sam.common.event.Event) Test(org.junit.Test)

Example 9 with Event

use of org.talend.esb.sam.common.event.Event in project tesb-rt-se by Talend.

the class MessageToEventMapperTest method testMaxContentLength.

@Test
public void testMaxContentLength() throws IOException, EndpointException {
    Message message = getTestMessage();
    MessageToEventMapper mapper = new MessageToEventMapper();
    mapper.setMaxContentLength(MAXCONTENTLENGTH);
    Event event = mapper.mapToEvent(message);
    // System.out.println(event.getContent());
    Assert.assertEquals(MAXCONTENTLENGTH, event.getContent().length());
    Assert.assertEquals("<cut><![CDATA[" + TESTCONTENT.substring(0, MAXCONTENTLENGTH - 23) + "]]></cut>", event.getContent());
    Assert.assertTrue(event.isContentCut());
}
Also used : Message(org.apache.cxf.message.Message) Event(org.talend.esb.sam.common.event.Event) MessageToEventMapper(org.talend.esb.sam.agent.eventproducer.MessageToEventMapper) Test(org.junit.Test)

Example 10 with Event

use of org.talend.esb.sam.common.event.Event in project tesb-rt-se by Talend.

the class ServerSAMEnabledTest method testServiceCallOneway.

@Test
public void testServiceCallOneway() {
    queue.clear();
    Customer cust = new Customer();
    cust.setName("test");
    customerService.updateCustomer(cust);
    try {
        Thread.sleep(500);
    } catch (InterruptedException e) {
        e.printStackTrace();
    }
    List<Event> eventsList = new ArrayList<Event>();
    for (int i = 1; i <= 3; i++) {
        while (!queue.isEmpty()) {
            eventsList.add(queue.remove());
        }
        if (i < 3 && eventsList.isEmpty()) {
            try {
                Thread.sleep(500 * i);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        } else {
            break;
        }
    }
    checkEventsNum(eventsList, 1);
    checkFlowIdPresentAndSame(eventsList);
    checkReq_In(eventsList.get(0));
    checkNonNullFields(eventsList);
}
Also used : Customer(com.example.customerservice.Customer) ArrayList(java.util.ArrayList) Event(org.talend.esb.sam.common.event.Event) Test(org.junit.Test)

Aggregations

Event (org.talend.esb.sam.common.event.Event)37 Test (org.junit.Test)16 MessageInfo (org.talend.esb.sam.common.event.MessageInfo)11 ArrayList (java.util.ArrayList)10 Originator (org.talend.esb.sam.common.event.Originator)9 Date (java.util.Date)6 EventType (org.talend.esb.sam._2011._03.common.EventType)4 Customer (com.example.customerservice.Customer)3 DataHandler (javax.activation.DataHandler)3 Message (org.apache.cxf.message.Message)3 MessageToEventMapper (org.talend.esb.sam.agent.eventproducer.MessageToEventMapper)3 InetAddress (java.net.InetAddress)2 UnknownHostException (java.net.UnknownHostException)2 HashMap (java.util.HashMap)2 SoapBinding (org.apache.cxf.binding.soap.SoapBinding)2 SoapBindingInfo (org.apache.cxf.binding.soap.model.SoapBindingInfo)2 AuthorizationPolicy (org.apache.cxf.configuration.security.AuthorizationPolicy)2 SecurityContext (org.apache.cxf.security.SecurityContext)2 CustomInfo (org.talend.esb.sam.agent.message.CustomInfo)2 EventTypeEnum (org.talend.esb.sam.common.event.EventTypeEnum)2