CAMEL-7632 Added an unit test of streaming option and fix an CS error

Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/cfd8ad0b
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/cfd8ad0b
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/cfd8ad0b

Branch: refs/heads/master
Commit: cfd8ad0baf931dae67a8aaecf05efd11b892da46
Parents: c040863
Author: Willem Jiang <willem.ji...@gmail.com>
Authored: Fri Jul 25 11:08:50 2014 +0800
Committer: Willem Jiang <willem.ji...@gmail.com>
Committed: Fri Jul 25 11:10:12 2014 +0800

----------------------------------------------------------------------
 .../splunk/support/SplunkResultProcessor.java   |  2 +-
 .../component/splunk/ConsumerStreamingTest.java | 68 ++++++++++++++++++++
 2 files changed, 69 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/cfd8ad0b/components/camel-splunk/src/main/java/org/apache/camel/component/splunk/support/SplunkResultProcessor.java
----------------------------------------------------------------------
diff --git 
a/components/camel-splunk/src/main/java/org/apache/camel/component/splunk/support/SplunkResultProcessor.java
 
b/components/camel-splunk/src/main/java/org/apache/camel/component/splunk/support/SplunkResultProcessor.java
index 46ea42c..72b4f3d 100644
--- 
a/components/camel-splunk/src/main/java/org/apache/camel/component/splunk/support/SplunkResultProcessor.java
+++ 
b/components/camel-splunk/src/main/java/org/apache/camel/component/splunk/support/SplunkResultProcessor.java
@@ -22,5 +22,5 @@ import org.apache.camel.component.splunk.event.SplunkEvent;
  * Processes splunk results
  */
 public interface SplunkResultProcessor {
-    public void process(SplunkEvent splunkData);
+    void process(SplunkEvent splunkData);
 }

http://git-wip-us.apache.org/repos/asf/camel/blob/cfd8ad0b/components/camel-splunk/src/test/java/org/apache/camel/component/splunk/ConsumerStreamingTest.java
----------------------------------------------------------------------
diff --git 
a/components/camel-splunk/src/test/java/org/apache/camel/component/splunk/ConsumerStreamingTest.java
 
b/components/camel-splunk/src/test/java/org/apache/camel/component/splunk/ConsumerStreamingTest.java
new file mode 100644
index 0000000..bfa27ea
--- /dev/null
+++ 
b/components/camel-splunk/src/test/java/org/apache/camel/component/splunk/ConsumerStreamingTest.java
@@ -0,0 +1,68 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.splunk;
+
+import java.io.InputStream;
+import java.util.Map;
+
+import com.splunk.Job;
+import com.splunk.JobArgs;
+import com.splunk.JobCollection;
+import com.splunk.JobResultsArgs;
+
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.component.splunk.event.SplunkEvent;
+import org.junit.Test;
+
+import static org.mockito.Matchers.any;
+import static org.mockito.Matchers.anyString;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+public class ConsumerStreamingTest extends SplunkMockTestSupport {
+    @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();
+    }
+
+    @Override
+    protected RouteBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            public void configure() {
+                
from("splunk://normal?delay=5s&username=foo&password=bar&initEarliestTime=-10s&latestTime=now&search=search
 index=myindex&sourceType=testSource&streaming=true")
+                        .to("mock:search-result");
+            }
+        };
+    }
+}
+

Reply via email to