use of org.talend.esb.sam.common.event.Originator in project tesb-rt-se by Talend.
the class SAMProviderImplTest method test.
@Test
public void test() {
SAMProviderImpl provider = new SAMProviderImpl();
provider.setDialect("derbyDialect");
provider.setDataSource(ds);
provider.init();
Event e = writeEventtoDb("SAMProviderImplTest-1");
Event e2 = writeEventtoDb("SAMProviderImplTest-2");
Assert.assertEquals("derbyDialect", provider.getDialect());
List<FlowEvent> flowEvents = provider.getFlowDetails("SAMProviderImplTest-1");
Assert.assertNotNull(flowEvents);
for (FlowEvent fe : flowEvents) {
if (fe.getFlowID().equals(e.getMessageInfo().getFlowId())) {
Assert.assertEquals(e.getTimestamp().getTime(), fe.getTimestamp());
Assert.assertEquals(e.getEventType(), fe.getType());
Originator o = e.getOriginator();
Assert.assertEquals(o.getProcessId(), fe.getProcess());
Assert.assertEquals(o.getIp(), fe.getIp());
Assert.assertEquals(o.getHostname(), fe.getHost());
Assert.assertEquals(o.getCustomId(), fe.getCustomId());
Assert.assertEquals(o.getPrincipal(), fe.getPrincipal());
MessageInfo mi = e.getMessageInfo();
Assert.assertEquals(mi.getMessageId(), fe.getMessageID());
Assert.assertEquals(mi.getFlowId(), fe.getFlowID());
Assert.assertEquals(mi.getPortType(), fe.getPort());
Assert.assertEquals(mi.getOperationName(), fe.getOperation());
Assert.assertEquals(mi.getTransportType(), fe.getTransport());
Assert.assertEquals(e.isContentCut(), fe.isContentCut());
// Assert.assertEquals(e.getContent(), fe.getContent());
} else {
Assert.fail("record with invalid flowId " + fe.getFlowID() + " was written into database");
}
}
FlowEvent fe = provider.getEventDetails(-33);
Assert.assertNull(fe);
int id = Integer.parseInt(e.getPersistedId().toString());
fe = provider.getEventDetails(id);
Assert.assertNotNull(fe);
Assert.assertEquals(e.getTimestamp().getTime(), fe.getTimestamp());
Assert.assertEquals(e.getEventType(), fe.getType());
Originator o = e.getOriginator();
Assert.assertEquals(o.getProcessId(), fe.getProcess());
Assert.assertEquals(o.getIp(), fe.getIp());
Assert.assertEquals(o.getHostname(), fe.getHost());
Assert.assertEquals(o.getCustomId(), fe.getCustomId());
Assert.assertEquals(o.getPrincipal(), fe.getPrincipal());
MessageInfo mi = e.getMessageInfo();
Assert.assertEquals(mi.getMessageId(), fe.getMessageID());
Assert.assertEquals(mi.getFlowId(), fe.getFlowID());
Assert.assertEquals(mi.getPortType(), fe.getPort());
Assert.assertEquals(mi.getOperationName(), fe.getOperation());
Assert.assertEquals(mi.getTransportType(), fe.getTransport());
Assert.assertEquals(e.isContentCut(), fe.isContentCut());
Assert.assertEquals(e.getContent(), fe.getContent());
Map<String, String[]> criterias = new HashMap<String, String[]>();
String[] arr = { "SAMProviderImplTest-1" };
criterias.put("flowID", arr);
CriteriaAdapter ca = new CriteriaAdapter(0, 100, criterias);
FlowCollection fc = provider.getFlows(ca);
Assert.assertNotNull(fc);
Assert.assertNotNull(fc.getFlows());
List<Flow> flows = fc.getFlows();
Assert.assertFalse(flows.isEmpty());
Assert.assertEquals(1, flows.size());
Flow flow = flows.get(0);
Assert.assertEquals(flow.getEventType(), e.getEventType());
Assert.assertEquals(flow.getflowID(), e.getMessageInfo().getFlowId());
Assert.assertEquals(flow.getHost(), e.getOriginator().getHostname());
Assert.assertEquals(flow.getIp(), e.getOriginator().getIp());
Assert.assertEquals(flow.getOperation(), e.getMessageInfo().getOperationName());
Assert.assertEquals(flow.getPort(), e.getMessageInfo().getPortType());
Assert.assertEquals(flow.getTransport(), e.getMessageInfo().getTransportType());
}
Aggregations