Search in sources :

Example 11 with Originator

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());
}
Also used : HashMap(java.util.HashMap) MessageInfo(org.talend.esb.sam.common.event.MessageInfo) CriteriaAdapter(org.talend.esb.sam.server.persistence.criterias.CriteriaAdapter) Originator(org.talend.esb.sam.common.event.Originator) Event(org.talend.esb.sam.common.event.Event) Test(org.junit.Test)

Aggregations

Originator (org.talend.esb.sam.common.event.Originator)11 MessageInfo (org.talend.esb.sam.common.event.MessageInfo)10 Event (org.talend.esb.sam.common.event.Event)9 Date (java.util.Date)5 Test (org.junit.Test)3 InetAddress (java.net.InetAddress)2 UnknownHostException (java.net.UnknownHostException)2 SoapBinding (org.apache.cxf.binding.soap.SoapBinding)2 SoapBindingInfo (org.apache.cxf.binding.soap.model.SoapBindingInfo)2 IOException (java.io.IOException)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 DataHandler (javax.activation.DataHandler)1 AuthorizationPolicy (org.apache.cxf.configuration.security.AuthorizationPolicy)1 SecurityContext (org.apache.cxf.security.SecurityContext)1 ServiceInfo (org.apache.cxf.service.model.ServiceInfo)1 EventType (org.talend.esb.sam._2011._03.common.EventType)1 CustomInfo (org.talend.esb.sam.agent.message.CustomInfo)1 EventTypeEnum (org.talend.esb.sam.common.event.EventTypeEnum)1 FlowEvent (org.talend.esb.sam.server.persistence.FlowEvent)1