Search in sources :

Example 16 with Event

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

the class EventRepositoryTest method testWriteEvent.

@Test
public void testWriteEvent() {
    GregorianCalendar cal = new GregorianCalendar(2000, Calendar.JANUARY, 1, 01, 01, 10);
    Event event = EventCreator.createEvent("content", cal.getTime(), EventTypeEnum.REQ_IN, "orig_id", "localhost", "10.0.0.1", "1", "2", "3", "operation", "service", "http");
    event.getCustomInfo().put("mykey1", "myValue1");
    event.getCustomInfo().put("mykey2", "myValue2");
    Assert.assertNull(event.getPersistedId());
    eventRepository.writeEvent(event);
    Assert.assertNotNull(event.getPersistedId());
    // read Event from database
    Event readEvent = eventRepository.readEvent(event.getPersistedId().longValue());
    Assert.assertTrue(EqualsBuilder.reflectionEquals(event, readEvent));
}
Also used : GregorianCalendar(java.util.GregorianCalendar) Event(org.talend.esb.sam.common.event.Event) Test(org.junit.Test)

Example 17 with Event

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

the class MonitoringServiceFullTest method testSendEvents.

// @Before
// public void setUp() throws Exception {
// executeSqlScript("create.sql", true);
// }
@Test
public void testSendEvents() throws PutEventsFault, MalformedURLException, URISyntaxException {
    Client client = ClientProxy.getClient(monitoringService);
    HTTPConduit conduit = (HTTPConduit) client.getConduit();
    HTTPClientPolicy clientConfig = new HTTPClientPolicy();
    clientConfig.setReceiveTimeout(100000);
    conduit.setClient(clientConfig);
    jdbcTemplate.update("delete from EVENTS");
    List<EventType> events = new ArrayList<EventType>();
    EventType eventType = new EventType();
    eventType.setEventType(EventEnumType.REQ_OUT);
    URL messageContentFile = this.getClass().getResource("/testmessage.xml").toURI().toURL();
    eventType.setContent(new DataHandler(messageContentFile));
    CustomInfoType ciType = new CustomInfoType();
    CustomInfoType.Item prop1 = new CustomInfoType.Item();
    prop1.setKey("mykey1");
    prop1.setValue("myValue1");
    ciType.getItem().add(prop1);
    CustomInfoType.Item prop2 = new CustomInfoType.Item();
    prop2.setKey("mykey2");
    prop2.setValue("myValue2");
    ciType.getItem().add(prop2);
    eventType.setCustomInfo(ciType);
    MessageInfoType mit = new MessageInfoType();
    mit.setFlowId("uuid");
    eventType.setMessageInfo(mit);
    events.add(eventType);
    String result = monitoringService.putEvents(events);
    Assert.assertEquals("success", result);
    long id = jdbcTemplate.queryForObject("select id from EVENTS", Long.class);
    Event readEvent = eventRepository.readEvent(id);
    Assert.assertEquals(EventTypeEnum.REQ_OUT, readEvent.getEventType());
    Map<String, String> customInfo = readEvent.getCustomInfo();
    Assert.assertEquals("myValue1", customInfo.get("mykey1"));
    Assert.assertEquals("myValue2", customInfo.get("mykey2"));
}
Also used : EventType(org.talend.esb.sam._2011._03.common.EventType) ArrayList(java.util.ArrayList) DataHandler(javax.activation.DataHandler) URL(java.net.URL) HTTPConduit(org.apache.cxf.transport.http.HTTPConduit) CustomInfoType(org.talend.esb.sam._2011._03.common.CustomInfoType) HTTPClientPolicy(org.apache.cxf.transports.http.configuration.HTTPClientPolicy) Event(org.talend.esb.sam.common.event.Event) Client(org.apache.cxf.endpoint.Client) MessageInfoType(org.talend.esb.sam._2011._03.common.MessageInfoType) Test(org.junit.Test)

Example 18 with Event

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

the class MonitoringServiceImplTest method testWritingSeveralEvents.

// @Before
// public void setUp() throws Exception {
// executeSqlScript("create.sql", true);
// }
@Test
public void testWritingSeveralEvents() {
    List<Event> events = new ArrayList<Event>();
    events.add(generateEvent());
    events.add(generateEvent());
    events.add(generateEvent());
    monitoringSerivce.putEvents(events);
    for (Event event : events) {
        EventRowMapper rowMapper = new EventRowMapper();
        Event loaded = jdbcTemplate.queryForObject("select * from EVENTS where ID=?", rowMapper, event.getPersistedId());
        Assert.assertNotNull(loaded);
        Assert.assertEquals(event.getPersistedId(), loaded.getPersistedId());
    }
}
Also used : EventRowMapper(org.talend.esb.sam.server.persistence.EventRowMapper) ArrayList(java.util.ArrayList) Event(org.talend.esb.sam.common.event.Event) Test(org.junit.Test)

Example 19 with Event

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

the class SamRestServiceImplTest method writeEventtoDb.

private Event writeEventtoDb(String flowId, EventTypeEnum eventType) {
    Event e = new Event();
    Date ts = new Date();
    e.setTimestamp(ts);
    e.setEventType(eventType);
    Originator orig = new Originator("pid1", "127.0.0.1", "localhost", "custom_id1", "principal1");
    e.setOriginator(orig);
    MessageInfo mi = new MessageInfo("mid1", flowId, "portType_1", "seekBook", "HTTP");
    e.setMessageInfo(mi);
    e.setContentCut(false);
    e.setContent("<seekBook>Survival in the Arctic</seekBook>");
    e.getCustomInfo().put("key1", "value1");
    e.getCustomInfo().put("key2", "value2");
    eventRepository.writeEvent(e);
    return e;
}
Also used : Originator(org.talend.esb.sam.common.event.Originator) Event(org.talend.esb.sam.common.event.Event) FlowEvent(org.talend.esb.sam.server.persistence.FlowEvent) Date(java.util.Date) MessageInfo(org.talend.esb.sam.common.event.MessageInfo)

Example 20 with Event

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

the class MonitoringServiceImpl method putEvents.

/**
 * Executes all event manipulating handler and writes the event with persist
 * handler.
 *
 * @param events the events
 */
public void putEvents(List<Event> events) {
    List<Event> filteredEvents = filterEvents(events);
    executeHandlers(filteredEvents);
    for (Event event : filteredEvents) {
        persistenceHandler.writeEvent(event);
    }
}
Also used : Event(org.talend.esb.sam.common.event.Event)

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