Search in sources :

Example 1 with CriteriaAdapter

use of org.talend.esb.sam.server.persistence.criterias.CriteriaAdapter in project tesb-rt-se by Talend.

the class CriteriaAdapterTest method testSQLValuesProvider.

public void testSQLValuesProvider() throws Exception {
    Map<String, String[]> params = new HashMap<String, String[]>();
    params.put("ignore", new String[] { "ha ha" });
    params.put("port", new String[] { "port*" });
    params.put("operation", new String[] { "blah" });
    CriteriaAdapter adapter = new CriteriaAdapter(0, 100, params);
    assertTrue(adapter.hasValue("limit") && adapter.hasValue("offset"));
    assertTrue(adapter.hasValue("port") && adapter.hasValue("operation"));
}
Also used : CriteriaAdapter(org.talend.esb.sam.server.persistence.criterias.CriteriaAdapter) HashMap(java.util.HashMap)

Example 2 with CriteriaAdapter

use of org.talend.esb.sam.server.persistence.criterias.CriteriaAdapter 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)

Example 3 with CriteriaAdapter

use of org.talend.esb.sam.server.persistence.criterias.CriteriaAdapter in project tesb-rt-se by Talend.

the class SAMRestServiceImpl method getFlows.

@Override
public Response getFlows(Integer offset, Integer limit) {
    Map<String, String[]> params = new HashMap<String, String[]>();
    MultivaluedMap<String, String> queryParams = uriInfo.getQueryParameters();
    for (Entry<String, List<String>> entry : queryParams.entrySet()) {
        params.put(entry.getKey(), entry.getValue().toArray(new String[] {}));
    }
    CriteriaAdapter adapter = new CriteriaAdapter(offset, limit, params);
    FlowCollection flowCollection = provider.getFlows(adapter);
    return Response.ok(aggregateRawData(flowCollection)).build();
}
Also used : CriteriaAdapter(org.talend.esb.sam.server.persistence.criterias.CriteriaAdapter) HashMap(java.util.HashMap) AggregatedFlowCollection(org.talend.esb.sam.server.persistence.AggregatedFlowCollection) FlowCollection(org.talend.esb.sam.server.persistence.FlowCollection) ArrayList(java.util.ArrayList) List(java.util.List)

Aggregations

HashMap (java.util.HashMap)3 CriteriaAdapter (org.talend.esb.sam.server.persistence.criterias.CriteriaAdapter)3 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Test (org.junit.Test)1 Event (org.talend.esb.sam.common.event.Event)1 MessageInfo (org.talend.esb.sam.common.event.MessageInfo)1 Originator (org.talend.esb.sam.common.event.Originator)1 AggregatedFlowCollection (org.talend.esb.sam.server.persistence.AggregatedFlowCollection)1 FlowCollection (org.talend.esb.sam.server.persistence.FlowCollection)1