Search in sources :

Example 1 with SplunkEvent

use of org.apache.camel.component.splunk.event.SplunkEvent in project camel by apache.

the class ConsumerStreamingTest method testSearch.

@Test
public void testSearch() throws Exception {
    MockEndpoint searchMock = getMockEndpoint("mock:search-result");
    searchMock.expectedMessageCount(3);
    JobCollection jobCollection = mock(JobCollection.class);
    Job jobMock = mock(Job.class);
    when(service.getJobs()).thenReturn(jobCollection);
    when(jobCollection.create(anyString(), any(JobArgs.class))).thenReturn(jobMock);
    when(jobMock.isDone()).thenReturn(Boolean.TRUE);
    InputStream stream = ConsumerTest.class.getResourceAsStream("/resultsreader_test_data.json");
    when(jobMock.getResults(any(JobResultsArgs.class))).thenReturn(stream);
    assertMockEndpointsSatisfied();
    SplunkEvent recieved = searchMock.getReceivedExchanges().get(0).getIn().getBody(SplunkEvent.class);
    assertNotNull(recieved);
    Map<String, String> data = recieved.getEventData();
    assertEquals("indexertpool", data.get("name"));
    stream.close();
}
Also used : JobResultsArgs(com.splunk.JobResultsArgs) SplunkEvent(org.apache.camel.component.splunk.event.SplunkEvent) JobCollection(com.splunk.JobCollection) JobArgs(com.splunk.JobArgs) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) InputStream(java.io.InputStream) Matchers.anyString(org.mockito.Matchers.anyString) Job(com.splunk.Job) Test(org.junit.Test)

Example 2 with SplunkEvent

use of org.apache.camel.component.splunk.event.SplunkEvent in project camel by apache.

the class ConsumerTest method testSearch.

@Test
public void testSearch() throws Exception {
    MockEndpoint searchMock = getMockEndpoint("mock:search-result");
    searchMock.expectedMessageCount(3);
    searchMock.expectedPropertyReceived(Exchange.BATCH_SIZE, 3);
    JobCollection jobCollection = mock(JobCollection.class);
    Job jobMock = mock(Job.class);
    when(service.getJobs()).thenReturn(jobCollection);
    when(jobCollection.create(anyString(), any(JobArgs.class))).thenReturn(jobMock);
    when(jobMock.isDone()).thenReturn(Boolean.TRUE);
    InputStream stream = ConsumerTest.class.getResourceAsStream("/resultsreader_test_data.json");
    when(jobMock.getResults(any(JobResultsArgs.class))).thenReturn(stream);
    assertMockEndpointsSatisfied();
    SplunkEvent recieved = searchMock.getReceivedExchanges().get(0).getIn().getBody(SplunkEvent.class);
    assertNotNull(recieved);
    Map<String, String> data = recieved.getEventData();
    assertEquals("indexertpool", data.get("name"));
    assertEquals(true, searchMock.getReceivedExchanges().get(2).getProperty(Exchange.BATCH_COMPLETE, Boolean.class));
    stream.close();
}
Also used : JobResultsArgs(com.splunk.JobResultsArgs) SplunkEvent(org.apache.camel.component.splunk.event.SplunkEvent) JobCollection(com.splunk.JobCollection) JobArgs(com.splunk.JobArgs) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) InputStream(java.io.InputStream) Matchers.anyString(org.mockito.Matchers.anyString) Job(com.splunk.Job) Test(org.junit.Test)

Example 3 with SplunkEvent

use of org.apache.camel.component.splunk.event.SplunkEvent in project camel by apache.

the class ProducerTest method testTcpWriter.

@Test
public void testTcpWriter() throws Exception {
    MockEndpoint mock = getMockEndpoint("mock:tcpresult");
    mock.setExpectedMessageCount(1);
    SplunkEvent splunkEvent = new SplunkEvent();
    splunkEvent.addPair("key1", "value1");
    splunkEvent.addPair("key2", "value2");
    splunkEvent.addPair("key3", "value3");
    template.sendBody("direct:tcp", splunkEvent);
    assertMockEndpointsSatisfied();
    Producer tcpProducer = tcpEndpoint.createProducer();
    assertIsInstanceOf(TcpDataWriter.class, ((SplunkProducer) tcpProducer).getDataWriter());
}
Also used : SplunkEvent(org.apache.camel.component.splunk.event.SplunkEvent) Producer(org.apache.camel.Producer) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) Test(org.junit.Test)

Example 4 with SplunkEvent

use of org.apache.camel.component.splunk.event.SplunkEvent in project camel by apache.

the class ProducerTest method testStreamWriter.

@Test
public void testStreamWriter() throws Exception {
    MockEndpoint mock = getMockEndpoint("mock:stream-result");
    mock.setExpectedMessageCount(1);
    SplunkEvent splunkEvent = new SplunkEvent();
    splunkEvent.addPair("key11", "value1");
    splunkEvent.addPair("key22", "value2");
    splunkEvent.addPair("key33", "value3");
    template.sendBody("direct:stream", splunkEvent);
    assertMockEndpointsSatisfied();
    Producer streamProducer = streamEndpoint.createProducer();
    assertIsInstanceOf(StreamDataWriter.class, ((SplunkProducer) streamProducer).getDataWriter());
}
Also used : SplunkEvent(org.apache.camel.component.splunk.event.SplunkEvent) Producer(org.apache.camel.Producer) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) Test(org.junit.Test)

Example 5 with SplunkEvent

use of org.apache.camel.component.splunk.event.SplunkEvent in project camel by apache.

the class SplunkEventTest method testEventDataWithQuotedValues.

@Test
public void testEventDataWithQuotedValues() {
    Date now = new Date();
    SplunkEvent event = new SplunkEvent("testevent", "123", false, true);
    event.addPair("key1", "value1");
    event.addPair("key2", "value2 with whitespace");
    event.addPair(SplunkEvent.COMMON_DVC_TIME, now);
    assertEquals("Values should be quoted", "name=\"testevent\" event_id=\"123\" key1=\"value1\" key2=\"value2 with whitespace\" dvc_time=\"" + now.toString() + "\"\n", event.toString());
    assertEquals(5, event.getEventData().size());
    assertTrue(event.getEventData().get("key2").equals("value2 with whitespace"));
}
Also used : SplunkEvent(org.apache.camel.component.splunk.event.SplunkEvent) Date(java.util.Date) Test(org.junit.Test)

Aggregations

SplunkEvent (org.apache.camel.component.splunk.event.SplunkEvent)21 Test (org.junit.Test)13 MockEndpoint (org.apache.camel.component.mock.MockEndpoint)11 JobArgs (com.splunk.JobArgs)4 Job (com.splunk.Job)3 JobResultsArgs (com.splunk.JobResultsArgs)3 InputStream (java.io.InputStream)3 Calendar (java.util.Calendar)3 Producer (org.apache.camel.Producer)3 JobCollection (com.splunk.JobCollection)2 Exchange (org.apache.camel.Exchange)2 Message (org.apache.camel.Message)2 Matchers.anyString (org.mockito.Matchers.anyString)2 ResultsReader (com.splunk.ResultsReader)1 ResultsReaderJson (com.splunk.ResultsReaderJson)1 SavedSearch (com.splunk.SavedSearch)1 SavedSearchCollection (com.splunk.SavedSearchCollection)1 SavedSearchDispatchArgs (com.splunk.SavedSearchDispatchArgs)1 Service (com.splunk.Service)1 ServiceArgs (com.splunk.ServiceArgs)1