Search in sources :

Example 26 with Event

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

the class AbstractEventProducerTest method checkNonNullFields.

protected void checkNonNullFields(List<Event> eventList) {
    for (Event event : eventList) {
        String operationName = event.getMessageInfo().getOperationName();
        Assert.assertNotNull("operationName should not be null in " + event.getEventType(), operationName);
    }
}
Also used : Event(org.talend.esb.sam.common.event.Event)

Example 27 with Event

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

the class AbstractEventProducerTest method checkEventsNum.

protected void checkEventsNum(List<Event> eventList, int expectedNum) {
    List<EventTypeEnum> eventTypeList = new ArrayList<EventTypeEnum>();
    for (Event event : eventList) {
        eventTypeList.add(event.getEventType());
    }
    Assert.assertEquals("The expected events num should be " + expectedNum + ". Actually events num is " + eventList.size() + " which are " + eventTypeList, expectedNum, eventList.size());
}
Also used : EventTypeEnum(org.talend.esb.sam.common.event.EventTypeEnum) ArrayList(java.util.ArrayList) Event(org.talend.esb.sam.common.event.Event)

Example 28 with Event

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

the class MessageToEventMapperTest method testMapEvent.

@Test
public void testMapEvent() throws IOException, EndpointException {
    Message message = getTestMessage();
    Event event = new MessageToEventMapper().mapToEvent(message);
    Assert.assertEquals(EventTypeEnum.REQ_IN, event.getEventType());
    Assert.assertEquals("{interfaceNs}interfaceName", event.getMessageInfo().getPortType());
    Assert.assertEquals("{namespace}opName", event.getMessageInfo().getOperationName());
    Assert.assertEquals(TransportType, event.getMessageInfo().getTransportType());
    Assert.assertEquals(FlowID, event.getMessageInfo().getFlowId());
    Assert.assertNull(event.getMessageInfo().getMessageId());
    // By default the content should not be cut
    Assert.assertEquals(TESTCONTENT, event.getContent());
    Assert.assertFalse(event.isContentCut());
    // Principal
    Assert.assertEquals(PrincipalString, event.getOriginator().getPrincipal());
    Map<String, String> customInfo = event.getCustomInfo();
    // Assert.assertEquals(2, customInfo.keySet().size());
    // Assert.assertEquals(Address, customInfo.get("address"));
    Assert.assertEquals("value1", customInfo.get("key1"));
}
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 29 with Event

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

the class SamRestServiceImplTest method test.

@Test
public void test() {
    Event e = writeEventtoDb("flow123", EventTypeEnum.REQ_IN);
    List<FlowEvent> flowEvents = samProvider.getFlowDetails("flow123");
    Assert.assertNotNull(flowEvents);
    Assert.assertTrue(!flowEvents.isEmpty());
    Response response = restService.getFlow("flow123");
    String responseString = response.readEntity(String.class);
    System.out.println(responseString);
    JSONParser parser = new JSONParser();
    JSONObject obj = null;
    try {
        obj = (JSONObject) parser.parse(responseString);
    } catch (Exception ex) {
        ex.printStackTrace();
        Assert.fail(ex.getMessage());
    }
    Assert.assertNotNull(obj);
    JSONObject events = (JSONObject) obj.get("events");
    Assert.assertNotNull(events);
    Assert.assertFalse((Boolean) (events.get("contentCut")));
    Assert.assertEquals("custom_id1", events.get("customId"));
    Assert.assertTrue(((String) events.get("details")).startsWith("local://sam-rest/event/"));
    Assert.assertEquals("flow123", events.get("flowID"));
    Assert.assertEquals("localhost", events.get("host"));
    Assert.assertEquals(new Long(2), events.get("id"));
    Assert.assertEquals("127.0.0.1", events.get("ip"));
    Assert.assertEquals("mid1", events.get("messageID"));
    Assert.assertEquals("seekBook", events.get("operation"));
    Assert.assertEquals("portType_1", events.get("port"));
    Assert.assertEquals("principal1", events.get("principal"));
    Assert.assertEquals("pid1", events.get("process"));
    Assert.assertEquals("HTTP", events.get("transport"));
    Assert.assertEquals("REQ_IN", events.get("type"));
    // Test not existing flow
    response = restService.getFlow("notExistingFlow");
    Assert.assertEquals(404, response.getStatus());
    // Test getEvent
    response = restService.getEvent("notANumber");
    Assert.assertEquals(400, response.getStatus());
    response = restService.getEvent("-1");
    Assert.assertEquals(404, response.getStatus());
    response = restService.getEvent(Long.toString(e.getPersistedId()));
    Assert.assertEquals(200, response.getStatus());
    try {
        obj = (JSONObject) parser.parse(response.readEntity(String.class));
    } catch (Exception ex) {
        ex.printStackTrace();
        Assert.fail(ex.getMessage());
    }
    Assert.assertEquals("<seekBook>Survival in the Arctic</seekBook>", obj.get("content"));
    Assert.assertFalse((Boolean) obj.get("contentCut"));
    Assert.assertEquals("custom_id1", obj.get("customId"));
    Assert.assertEquals("flow123", obj.get("flowID"));
    Assert.assertEquals("localhost", obj.get("host"));
    Assert.assertEquals(new Long(2), obj.get("id"));
    Assert.assertEquals("127.0.0.1", obj.get("ip"));
    Assert.assertEquals("mid1", obj.get("messageID"));
    Assert.assertEquals("seekBook", obj.get("operation"));
    Assert.assertEquals("portType_1", obj.get("port"));
    Assert.assertEquals("principal1", obj.get("principal"));
    Assert.assertEquals("pid1", obj.get("process"));
    Assert.assertEquals("HTTP", obj.get("transport"));
    Assert.assertEquals("REQ_IN", obj.get("type"));
    // ---------------------------------------------------
    Event e2 = writeEventtoDb("flow123", EventTypeEnum.REQ_OUT);
    response = restService.getFlows(0, 10);
    try {
        obj = (JSONObject) parser.parse(response.readEntity(String.class));
    } catch (Exception ex) {
        ex.printStackTrace();
        Assert.fail(ex.getMessage());
    }
    Assert.assertEquals(new Long(1), obj.get("count"));
    obj = (JSONObject) obj.get("aggregated");
    Assert.assertNotNull(obj);
    Assert.assertEquals("localhost", obj.get("consumerHost"));
    Assert.assertEquals("127.0.0.1", obj.get("consumerIP"));
    Assert.assertEquals("local://sam-rest/flow/flow123", obj.get("details"));
    Assert.assertEquals("flow123", obj.get("flowID"));
    Assert.assertEquals("seekBook", obj.get("operation"));
    Assert.assertEquals("portType_1", obj.get("port"));
    Assert.assertEquals("localhost", obj.get("providerHost"));
    Assert.assertEquals("127.0.0.1", obj.get("providerIP"));
    Assert.assertEquals("HTTP", obj.get("transport"));
}
Also used : Response(javax.ws.rs.core.Response) FlowEvent(org.talend.esb.sam.server.persistence.FlowEvent) JSONObject(org.json.simple.JSONObject) Event(org.talend.esb.sam.common.event.Event) FlowEvent(org.talend.esb.sam.server.persistence.FlowEvent) JSONParser(org.json.simple.parser.JSONParser) Test(org.junit.Test)

Example 30 with Event

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

the class EventTypeMapper method map.

/**
 * Map the EventType.
 *
 * @param eventType the event type
 * @return the event
 */
public static Event map(EventType eventType) {
    Event event = new Event();
    event.setEventType(mapEventTypeEnum(eventType.getEventType()));
    Date date = (eventType.getTimestamp() == null) ? new Date() : eventType.getTimestamp().toGregorianCalendar().getTime();
    event.setTimestamp(date);
    event.setOriginator(mapOriginatorType(eventType.getOriginator()));
    MessageInfo messageInfo = mapMessageInfo(eventType.getMessageInfo());
    event.setMessageInfo(messageInfo);
    String content = mapContent(eventType.getContent());
    event.setContent(content);
    event.getCustomInfo().clear();
    event.getCustomInfo().putAll(mapCustomInfo(eventType.getCustomInfo()));
    return event;
}
Also used : Event(org.talend.esb.sam.common.event.Event) Date(java.util.Date) MessageInfo(org.talend.esb.sam.common.event.MessageInfo)

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