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);
}
}
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());
}
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"));
}
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"));
}
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;
}
Aggregations