You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2016/03/15 08:07:15 UTC
camel git commit: CAMEL-9707: Added initial versions of ListDataSet
and FileDataSet
Repository: camel
Updated Branches:
refs/heads/master 489e0286c -> 9473c8627
CAMEL-9707: Added initial versions of ListDataSet and FileDataSet
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/9473c862
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/9473c862
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/9473c862
Branch: refs/heads/master
Commit: 9473c8627be11aafbd7fdc23483b6c724d4a490b
Parents: 489e028
Author: Quinn Stevenson <qu...@pronoia-solutions.com>
Authored: Mon Mar 14 14:54:30 2016 -0600
Committer: Claus Ibsen <da...@apache.org>
Committed: Tue Mar 15 08:03:44 2016 +0100
----------------------------------------------------------------------
.../camel/component/dataset/FileDataSet.java | 96 ++++++++++++++++++++
.../camel/component/dataset/ListDataSet.java | 72 +++++++++++++++
camel-core/src/test/data/file-dataset-test.txt | 10 ++
.../dataset/FileDataSetConsumerTest.java | 75 +++++++++++++++
.../FileDataSetConsumerWithSplitTest.java | 76 ++++++++++++++++
.../dataset/FileDataSetProducerTest.java | 81 +++++++++++++++++
.../FileDataSetProducerWithSplitTest.java | 83 +++++++++++++++++
.../dataset/ListDataSetConsumerTest.java | 77 ++++++++++++++++
.../dataset/ListDataSetProducerTest.java | 80 ++++++++++++++++
9 files changed, 650 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/9473c862/camel-core/src/main/java/org/apache/camel/component/dataset/FileDataSet.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/component/dataset/FileDataSet.java b/camel-core/src/main/java/org/apache/camel/component/dataset/FileDataSet.java
new file mode 100644
index 0000000..31be077
--- /dev/null
+++ b/camel-core/src/main/java/org/apache/camel/component/dataset/FileDataSet.java
@@ -0,0 +1,96 @@
+/**
+ * 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.dataset;
+
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.FileReader;
+import java.io.IOException;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Scanner;
+
+/**
+ * A DataSet that reads payloads from a file that are used to create each message exchange
+ * along with using a pluggable transformer to customize the messages. The file contents may optionally
+ * be split using a supplied token.
+ *
+ * @version
+ */
+public class FileDataSet extends ListDataSet {
+ private File sourceFile;
+ private String delimiter = "\\z";
+
+ private List<Object> defaultBodies;
+
+ public FileDataSet(String sourceFileName) throws IOException {
+ this(new File(sourceFileName));
+ }
+
+ public FileDataSet(File sourceFile) throws IOException {
+ this(sourceFile, "\\z");
+ }
+
+ public FileDataSet(String sourceFileName, String delimiter) throws IOException {
+ this(new File(sourceFileName), delimiter);
+ }
+
+ public FileDataSet(File sourceFile, String delimiter) throws IOException {
+ setSourceFile(sourceFile, delimiter);
+ }
+
+ // Properties
+ //-------------------------------------------------------------------------
+
+ public File getSourceFile() {
+ return sourceFile;
+ }
+
+ public void setSourceFile(File sourceFile) throws IOException {
+ this.sourceFile = sourceFile;
+ readSourceFile();
+ }
+
+ public void setSourceFile(File sourceFile, String delimiter) throws IOException {
+ this.sourceFile = sourceFile;
+ this.delimiter = delimiter;
+ readSourceFile();
+ }
+
+ public String getDelimiter() {
+ return delimiter;
+ }
+
+ // Implementation methods
+ //-------------------------------------------------------------------------
+
+ private void readSourceFile() throws IOException {
+ List<Object> bodies = new LinkedList<>();
+ try (BufferedReader br = new BufferedReader(new FileReader(sourceFile))) {
+ Scanner scanner = new Scanner(br);
+ scanner.useDelimiter(delimiter);
+ while (scanner.hasNext()) {
+ String nextPayload = scanner.next();
+ if ((nextPayload != null) && (nextPayload.length() > 0)) {
+ bodies.add(nextPayload);
+ }
+ }
+ setDefaultBodies(bodies);
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/9473c862/camel-core/src/main/java/org/apache/camel/component/dataset/ListDataSet.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/component/dataset/ListDataSet.java b/camel-core/src/main/java/org/apache/camel/component/dataset/ListDataSet.java
new file mode 100644
index 0000000..437339e
--- /dev/null
+++ b/camel-core/src/main/java/org/apache/camel/component/dataset/ListDataSet.java
@@ -0,0 +1,72 @@
+/**
+ * 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.dataset;
+
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.Processor;
+
+/**
+ * A DataSet that allows a list of static payloads to be used to create each message exchange
+ * along with using a pluggable transformer to customize the messages.
+ *
+ * @version
+ */
+public class ListDataSet extends DataSetSupport {
+ private List<Object> defaultBodies;
+
+ public ListDataSet() {
+ super(0);
+ }
+
+ public ListDataSet(List<Object> defaultBodies) {
+ this.defaultBodies = defaultBodies;
+ setSize(defaultBodies.size());
+ }
+
+ // Properties
+ //-------------------------------------------------------------------------
+
+ public List<Object> getDefaultBodies() {
+ if (defaultBodies == null) {
+ defaultBodies = new LinkedList<>();
+ }
+
+ return defaultBodies;
+ }
+
+ public void setDefaultBodies(List<Object> defaultBodies) {
+ this.defaultBodies = defaultBodies;
+ setSize(defaultBodies.size());
+ }
+
+ // Implementation methods
+ //-------------------------------------------------------------------------
+
+ /**
+ * Creates the message body for a given message. If the messageIndex is greater than the size
+ * of the list, use the modulus.
+ */
+ protected Object createMessageBody(long messageIndex) {
+ int listIndex = (int) (messageIndex % getDefaultBodies().size());
+
+ return getDefaultBodies().get(listIndex);
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/9473c862/camel-core/src/test/data/file-dataset-test.txt
----------------------------------------------------------------------
diff --git a/camel-core/src/test/data/file-dataset-test.txt b/camel-core/src/test/data/file-dataset-test.txt
new file mode 100644
index 0000000..00935f1
--- /dev/null
+++ b/camel-core/src/test/data/file-dataset-test.txt
@@ -0,0 +1,10 @@
+Line 1
+Line 2
+Line 3
+Line 4
+Line 5
+Line 6
+Line 7
+Line 8
+Line 9
+Line 10
http://git-wip-us.apache.org/repos/asf/camel/blob/9473c862/camel-core/src/test/java/org/apache/camel/component/dataset/FileDataSetConsumerTest.java
----------------------------------------------------------------------
diff --git a/camel-core/src/test/java/org/apache/camel/component/dataset/FileDataSetConsumerTest.java b/camel-core/src/test/java/org/apache/camel/component/dataset/FileDataSetConsumerTest.java
new file mode 100644
index 0000000..f21543d
--- /dev/null
+++ b/camel-core/src/test/java/org/apache/camel/component/dataset/FileDataSetConsumerTest.java
@@ -0,0 +1,75 @@
+/**
+ * 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.dataset;
+
+import javax.naming.Context;
+
+import org.apache.camel.ContextTestSupport;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+
+/**
+ * @version
+ */
+public class FileDataSetConsumerTest extends ContextTestSupport {
+ protected FileDataSet dataSet;
+
+ final String testDataFileName = "src/test/data/file-dataset-test.txt";
+
+ final String resultUri = "mock://result";
+ final String dataSetName = "foo";
+ final String dataSetUri = "dataset://" + dataSetName;
+
+ public void testDefaultListDataSet() throws Exception {
+ MockEndpoint result = getMockEndpoint(resultUri);
+ result.expectedMinimumMessageCount((int) dataSet.getSize());
+
+ result.assertIsSatisfied();
+ }
+
+ public void testDefaultListDataSetWithSizeGreaterThanListSize() throws Exception {
+ MockEndpoint result = getMockEndpoint(resultUri);
+ dataSet.setSize(20);
+ result.expectedMinimumMessageCount((int) dataSet.getSize());
+
+ result.assertIsSatisfied();
+ }
+
+ @Override
+ public void setUp() throws Exception {
+ dataSet = new FileDataSet(testDataFileName);
+ assertEquals("Unexpected DataSet size", 1, dataSet.getSize());
+ super.setUp();
+ }
+
+ @Override
+ protected Context createJndiContext() throws Exception {
+ Context context = super.createJndiContext();
+ context.bind(dataSetName, dataSet);
+ return context;
+ }
+
+ @Override
+ protected RouteBuilder createRouteBuilder() throws Exception {
+ return new RouteBuilder() {
+ public void configure() throws Exception {
+ from(dataSetUri)
+ .to("mock://result");
+ }
+ };
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/9473c862/camel-core/src/test/java/org/apache/camel/component/dataset/FileDataSetConsumerWithSplitTest.java
----------------------------------------------------------------------
diff --git a/camel-core/src/test/java/org/apache/camel/component/dataset/FileDataSetConsumerWithSplitTest.java b/camel-core/src/test/java/org/apache/camel/component/dataset/FileDataSetConsumerWithSplitTest.java
new file mode 100644
index 0000000..8708282
--- /dev/null
+++ b/camel-core/src/test/java/org/apache/camel/component/dataset/FileDataSetConsumerWithSplitTest.java
@@ -0,0 +1,76 @@
+/**
+ * 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.dataset;
+
+import javax.naming.Context;
+
+import org.apache.camel.ContextTestSupport;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+
+/**
+ * @version
+ */
+public class FileDataSetConsumerWithSplitTest extends ContextTestSupport {
+ protected FileDataSet dataSet;
+
+ final String testDataFileName = "src/test/data/file-dataset-test.txt";
+ final int testDataFileRecordCount = 10;
+
+ final String resultUri = "mock://result";
+ final String dataSetName = "foo";
+ final String dataSetUri = "dataset://" + dataSetName;
+
+ public void testDefaultListDataSet() throws Exception {
+ MockEndpoint result = getMockEndpoint(resultUri);
+ result.expectedMinimumMessageCount((int) dataSet.getSize());
+
+ result.assertIsSatisfied();
+ }
+
+ public void testDefaultListDataSetWithSizeGreaterThanListSize() throws Exception {
+ MockEndpoint result = getMockEndpoint(resultUri);
+ dataSet.setSize(20);
+ result.expectedMinimumMessageCount((int) dataSet.getSize());
+
+ result.assertIsSatisfied();
+ }
+
+ @Override
+ public void setUp() throws Exception {
+ dataSet = new FileDataSet(testDataFileName, "\n");
+ assertEquals("Unexpected DataSet size", testDataFileRecordCount, dataSet.getSize());
+ super.setUp();
+ }
+
+ @Override
+ protected Context createJndiContext() throws Exception {
+ Context context = super.createJndiContext();
+ context.bind(dataSetName, dataSet);
+ return context;
+ }
+
+ @Override
+ protected RouteBuilder createRouteBuilder() throws Exception {
+ return new RouteBuilder() {
+ public void configure() throws Exception {
+ from(dataSetUri)
+ .to("mock://result");
+ }
+ };
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/9473c862/camel-core/src/test/java/org/apache/camel/component/dataset/FileDataSetProducerTest.java
----------------------------------------------------------------------
diff --git a/camel-core/src/test/java/org/apache/camel/component/dataset/FileDataSetProducerTest.java b/camel-core/src/test/java/org/apache/camel/component/dataset/FileDataSetProducerTest.java
new file mode 100644
index 0000000..33f2c9c
--- /dev/null
+++ b/camel-core/src/test/java/org/apache/camel/component/dataset/FileDataSetProducerTest.java
@@ -0,0 +1,81 @@
+/**
+ * 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.dataset;
+
+import javax.naming.Context;
+
+import org.apache.camel.ContextTestSupport;
+import org.apache.camel.Exchange;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+
+/**
+ * @version
+ */
+public class FileDataSetProducerTest extends ContextTestSupport {
+ protected FileDataSet dataSet;
+
+ final String testDataFileName = "src/test/data/file-dataset-test.txt";
+ final String testPayload = "Line 1\nLine 2\nLine 3\nLine 4\nLine 5\nLine 6\nLine 7\nLine 8\nLine 9\nLine 10\n";
+
+ final String sourceUri = "direct://source";
+ final String dataSetName = "foo";
+ final String dataSetUri = "dataset://" + dataSetName;
+
+ public void testDefaultListDataSet() throws Exception {
+ template.sendBodyAndHeader(sourceUri, testPayload, Exchange.DATASET_INDEX, 0);
+
+ assertMockEndpointsSatisfied();
+ }
+
+ public void testDefaultListDataSetWithSizeGreaterThanListSize() throws Exception {
+ int messageCount = 20;
+ dataSet.setSize(messageCount);
+
+ getMockEndpoint(dataSetUri).expectedMessageCount(messageCount);
+
+ for (int i = 0; i < messageCount; ++i) {
+ template.sendBodyAndHeader(sourceUri, testPayload, Exchange.DATASET_INDEX, i);
+ }
+
+ assertMockEndpointsSatisfied();
+ }
+
+ @Override
+ public void setUp() throws Exception {
+ dataSet = new FileDataSet(testDataFileName);
+ assertEquals("Unexpected DataSet size", 1, dataSet.getSize());
+ super.setUp();
+ }
+
+ @Override
+ protected Context createJndiContext() throws Exception {
+ Context context = super.createJndiContext();
+ context.bind(dataSetName, dataSet);
+ return context;
+ }
+
+ @Override
+ protected RouteBuilder createRouteBuilder() throws Exception {
+ return new RouteBuilder() {
+ public void configure() throws Exception {
+ from(sourceUri)
+ .to(dataSetUri);
+ }
+ };
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/9473c862/camel-core/src/test/java/org/apache/camel/component/dataset/FileDataSetProducerWithSplitTest.java
----------------------------------------------------------------------
diff --git a/camel-core/src/test/java/org/apache/camel/component/dataset/FileDataSetProducerWithSplitTest.java b/camel-core/src/test/java/org/apache/camel/component/dataset/FileDataSetProducerWithSplitTest.java
new file mode 100644
index 0000000..7eedffb
--- /dev/null
+++ b/camel-core/src/test/java/org/apache/camel/component/dataset/FileDataSetProducerWithSplitTest.java
@@ -0,0 +1,83 @@
+/**
+ * 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.dataset;
+
+import javax.naming.Context;
+
+import org.apache.camel.ContextTestSupport;
+import org.apache.camel.Exchange;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+
+/**
+ * @version
+ */
+public class FileDataSetProducerWithSplitTest extends ContextTestSupport {
+ protected FileDataSet dataSet;
+
+ final String testDataFileName = "src/test/data/file-dataset-test.txt";
+ final int testDataFileRecordCount = 10;
+
+ final String sourceUri = "direct://source";
+ final String dataSetName = "foo";
+ final String dataSetUri = "dataset://" + dataSetName;
+
+ public void testDefaultListDataSet() throws Exception {
+ for (int i = 0; i < testDataFileRecordCount; ++i) {
+ template.sendBodyAndHeader(sourceUri, "Line " + (1 + i), Exchange.DATASET_INDEX, i);
+ }
+
+ assertMockEndpointsSatisfied();
+ }
+
+ public void testDefaultListDataSetWithSizeGreaterThanListSize() throws Exception {
+ int messageCount = 20;
+ dataSet.setSize(messageCount);
+
+ getMockEndpoint(dataSetUri).expectedMessageCount(messageCount);
+
+ for (int i = 0; i < messageCount; ++i) {
+ template.sendBodyAndHeader(sourceUri, "Line " + (1 + (i % testDataFileRecordCount)), Exchange.DATASET_INDEX, i);
+ }
+
+ assertMockEndpointsSatisfied();
+ }
+
+ @Override
+ public void setUp() throws Exception {
+ dataSet = new FileDataSet(testDataFileName, "\n");
+ assertEquals("Unexpected DataSet size", testDataFileRecordCount, dataSet.getSize());
+ super.setUp();
+ }
+
+ @Override
+ protected Context createJndiContext() throws Exception {
+ Context context = super.createJndiContext();
+ context.bind(dataSetName, dataSet);
+ return context;
+ }
+
+ @Override
+ protected RouteBuilder createRouteBuilder() throws Exception {
+ return new RouteBuilder() {
+ public void configure() throws Exception {
+ from(sourceUri)
+ .to(dataSetUri);
+ }
+ };
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/9473c862/camel-core/src/test/java/org/apache/camel/component/dataset/ListDataSetConsumerTest.java
----------------------------------------------------------------------
diff --git a/camel-core/src/test/java/org/apache/camel/component/dataset/ListDataSetConsumerTest.java b/camel-core/src/test/java/org/apache/camel/component/dataset/ListDataSetConsumerTest.java
new file mode 100644
index 0000000..5779b7e
--- /dev/null
+++ b/camel-core/src/test/java/org/apache/camel/component/dataset/ListDataSetConsumerTest.java
@@ -0,0 +1,77 @@
+/**
+ * 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.dataset;
+
+import java.util.LinkedList;
+import java.util.List;
+import javax.naming.Context;
+
+import org.apache.camel.ContextTestSupport;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+
+/**
+ * @version
+ */
+public class ListDataSetConsumerTest extends ContextTestSupport {
+ protected ListDataSet dataSet;
+
+ final String resultUri = "mock://result";
+ final String dataSetName = "foo";
+ final String dataSetUri = "dataset://" + dataSetName;
+
+ public void testDefaultListDataSet() throws Exception {
+ MockEndpoint result = getMockEndpoint(resultUri);
+ result.expectedMinimumMessageCount((int) dataSet.getSize());
+
+ result.assertIsSatisfied();
+ }
+
+ public void testDefaultListDataSetWithSizeGreaterThanListSize() throws Exception {
+ MockEndpoint result = getMockEndpoint(resultUri);
+ dataSet.setSize(10);
+ result.expectedMinimumMessageCount((int) dataSet.getSize());
+
+ result.assertIsSatisfied();
+ }
+
+ @Override
+ public void setUp() throws Exception {
+ List<Object> bodies = new LinkedList<>();
+ bodies.add("<hello>world!</hello>");
+ dataSet = new ListDataSet(bodies);
+
+ super.setUp();
+ }
+
+ @Override
+ protected Context createJndiContext() throws Exception {
+ Context context = super.createJndiContext();
+ context.bind(dataSetName, dataSet);
+ return context;
+ }
+
+ @Override
+ protected RouteBuilder createRouteBuilder() throws Exception {
+ return new RouteBuilder() {
+ public void configure() throws Exception {
+ from(dataSetUri)
+ .to("mock://result");
+ }
+ };
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/9473c862/camel-core/src/test/java/org/apache/camel/component/dataset/ListDataSetProducerTest.java
----------------------------------------------------------------------
diff --git a/camel-core/src/test/java/org/apache/camel/component/dataset/ListDataSetProducerTest.java b/camel-core/src/test/java/org/apache/camel/component/dataset/ListDataSetProducerTest.java
new file mode 100644
index 0000000..bae7f92
--- /dev/null
+++ b/camel-core/src/test/java/org/apache/camel/component/dataset/ListDataSetProducerTest.java
@@ -0,0 +1,80 @@
+/**
+ * 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.dataset;
+
+import java.util.LinkedList;
+import java.util.List;
+import javax.naming.Context;
+
+import org.apache.camel.ContextTestSupport;
+import org.apache.camel.Exchange;
+import org.apache.camel.builder.RouteBuilder;
+
+/**
+ * @version
+ */
+public class ListDataSetProducerTest extends ContextTestSupport {
+ protected ListDataSet dataSet = new ListDataSet();
+
+ final String sourceUri = "direct://source";
+ final String dataSetName = "foo";
+ final String dataSetUri = "dataset://" + dataSetName;
+
+ public void testDefaultListDataSet() throws Exception {
+ template.sendBodyAndHeader(dataSetUri, "<hello>world!</hello>", Exchange.DATASET_INDEX, 0);
+
+ assertMockEndpointsSatisfied();
+ }
+
+ public void testDefaultListDataSetWithSizeGreaterThanListSize() throws Exception {
+ int messageCount = 10;
+ getMockEndpoint(dataSetUri).expectedMessageCount(messageCount);
+ dataSet.setSize(messageCount);
+ long size = dataSet.getSize();
+ for (long i = 0; i < size; i++) {
+ template.sendBodyAndHeader(sourceUri, "<hello>world!</hello>", Exchange.DATASET_INDEX, i);
+ }
+
+ assertMockEndpointsSatisfied();
+ }
+
+ @Override
+ public void setUp() throws Exception {
+ List<Object> bodies = new LinkedList<>();
+ bodies.add("<hello>world!</hello>");
+ dataSet = new ListDataSet(bodies);
+
+ super.setUp();
+ }
+
+ @Override
+ protected Context createJndiContext() throws Exception {
+ Context context = super.createJndiContext();
+ context.bind(dataSetName, dataSet);
+ return context;
+ }
+
+ @Override
+ protected RouteBuilder createRouteBuilder() throws Exception {
+ return new RouteBuilder() {
+ public void configure() throws Exception {
+ from(sourceUri)
+ .to(dataSetUri);
+ }
+ };
+ }
+}