camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jstrac...@apache.org
Subject svn commit: r633440 - in /activemq/camel/trunk/camel-core/src: main/java/org/apache/camel/ main/java/org/apache/camel/component/dataset/ main/java/org/apache/camel/component/mock/ main/java/org/apache/camel/util/ main/resources/META-INF/services/org/ap...
Date Tue, 04 Mar 2008 12:11:39 GMT
Author: jstrachan
Date: Tue Mar  4 04:11:22 2008
New Revision: 633440

URL: http://svn.apache.org/viewvc?rev=633440&view=rev
Log:
First cut of a DataSet component for easier load & soak testing for https://issues.apache.org/activemq/browse/CAMEL-354

Added:
    activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/NoSuchHeaderException.java
      - copied, changed from r633075, activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/NoSuchPropertyException.java
    activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/dataset/
    activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/dataset/DataSet.java
  (with props)
    activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/dataset/DataSetComponent.java
      - copied, changed from r633075, activemq/camel/trunk/components/camel-spring/src/main/java/org/apache/camel/component/test/TestComponent.java
    activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/dataset/DataSetConsumer.java
  (with props)
    activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/dataset/DataSetEndpoint.java
  (with props)
    activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/dataset/SimpleDataSet.java
  (with props)
    activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/dataset/package.html
  (with props)
    activemq/camel/trunk/camel-core/src/main/resources/META-INF/services/org/apache/camel/component/dataset
      - copied, changed from r633075, activemq/camel/trunk/camel-core/src/main/resources/META-INF/services/org/apache/camel/component/bean
    activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/component/dataset/
    activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/component/dataset/DataSetConsumeTest.java
  (with props)
    activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/component/dataset/DataSetTest.java
  (with props)
Modified:
    activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/NoSuchPropertyException.java
    activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/mock/MockEndpoint.java
    activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/util/ExchangeHelper.java

Copied: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/NoSuchHeaderException.java
(from r633075, activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/NoSuchPropertyException.java)
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/NoSuchHeaderException.java?p2=activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/NoSuchHeaderException.java&p1=activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/NoSuchPropertyException.java&r1=633075&r2=633440&rev=633440&view=diff
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/NoSuchPropertyException.java
(original)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/NoSuchHeaderException.java
Tue Mar  4 04:11:22 2008
@@ -16,29 +16,30 @@
  */
 package org.apache.camel;
 
+import org.apache.camel.util.ExchangeHelper;
 
 /**
- * An exception caused when a mandatory property is not available on a message
+ * An exception caused when a mandatory header is not available on a message
  * {@link Exchange}
- * 
- * @see ExchangeHelper#getMandatoryProperty(Exchange, String, Class)
- * 
+ *
+ * @see ExchangeHelper#getMandatoryHeader(Exchange, String, Class)
+ *
  * @version $Revision$
  */
-public class NoSuchPropertyException extends CamelExchangeException {
+public class NoSuchHeaderException extends CamelExchangeException {
     private static final long serialVersionUID = -8721487431101572630L;
-    private final String propertyName;
+    private final String headerName;
     private final Class<?> type;
 
-    public NoSuchPropertyException(Exchange exchange, String propertyName, Class<?>
type) {
-        super("No '" + propertyName + "' property available of type: " + type.getName()
-              + reason(exchange, propertyName), exchange);
-        this.propertyName = propertyName;
+    public NoSuchHeaderException(Exchange exchange, String headerName, Class<?> type)
{
+        super("No '" + headerName + "' header available of type: " + type.getName()
+              + reason(exchange, headerName), exchange);
+        this.headerName = headerName;
         this.type = type;
     }
 
-    public String getPropertyName() {
-        return propertyName;
+    public String getHeaderName() {
+        return headerName;
     }
 
     public Class<?> getType() {
@@ -56,4 +57,4 @@
         }
         return " but has value: " + value + " of type: " + value.getClass().getName();
     }
-}
+}
\ No newline at end of file

Modified: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/NoSuchPropertyException.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/NoSuchPropertyException.java?rev=633440&r1=633439&r2=633440&view=diff
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/NoSuchPropertyException.java
(original)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/NoSuchPropertyException.java
Tue Mar  4 04:11:22 2008
@@ -16,6 +16,7 @@
  */
 package org.apache.camel;
 
+import org.apache.camel.util.ExchangeHelper;
 
 /**
  * An exception caused when a mandatory property is not available on a message

Added: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/dataset/DataSet.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/dataset/DataSet.java?rev=633440&view=auto
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/dataset/DataSet.java
(added)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/dataset/DataSet.java
Tue Mar  4 04:11:22 2008
@@ -0,0 +1,41 @@
+/**
+ *
+ * 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 org.apache.camel.Exchange;
+
+/**
+ * Represents a strategy for testing endpoints with canned data.
+ * 
+ * @version $Revision: 1.1 $
+ */
+public interface DataSet {
+    String INDEX_HEADER = "camelDataSetIndex";
+
+    /**
+     * Populates a message exchange when using the DataSet as a source of messages
+     * 
+     * @param exchange
+     */
+    public void populateMessage(Exchange exchange, long messageIndex) throws Exception;
+
+    /**
+     * Returns the size of the dataset
+     */
+    public long getSize();
+}

Propchange: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/dataset/DataSet.java
------------------------------------------------------------------------------
    svn:eol-style = native

Copied: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/dataset/DataSetComponent.java
(from r633075, activemq/camel/trunk/components/camel-spring/src/main/java/org/apache/camel/component/test/TestComponent.java)
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/dataset/DataSetComponent.java?p2=activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/dataset/DataSetComponent.java&p1=activemq/camel/trunk/components/camel-spring/src/main/java/org/apache/camel/component/test/TestComponent.java&r1=633075&r2=633440&rev=633440&view=diff
==============================================================================
--- activemq/camel/trunk/components/camel-spring/src/main/java/org/apache/camel/component/test/TestComponent.java
(original)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/dataset/DataSetComponent.java
Tue Mar  4 04:11:22 2008
@@ -15,7 +15,7 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package org.apache.camel.component.test;
+package org.apache.camel.component.dataset;
 
 import java.net.URI;
 import java.util.HashMap;
@@ -31,20 +31,11 @@
 /**
  * @version $Revision$
  */
-public class TestComponent extends DefaultComponent<Exchange> {
-    public Endpoint<Exchange> createEndpoint(String uri) throws Exception {
-        // lets not use the normal parameter handling so that all parameters are sent to
the nested endpoint
-
-        ObjectHelper.notNull(getCamelContext(), "camelContext");
-        URI u = new URI(UnsafeUriCharactersEncoder.encode(uri));
-        String path = u.getSchemeSpecificPart();
-
-        return createEndpoint(uri, path, new HashMap());
-    }
+public class DataSetComponent extends DefaultComponent<Exchange> {
 
     @Override
     protected Endpoint<Exchange> createEndpoint(String uri, String remaining, Map parameters)
throws Exception {
-        Endpoint endpoint = CamelContextHelper.getMandatoryEndpoint(getCamelContext(), remaining);
-        return new TestEndpoint(uri, this, endpoint);
+        DataSet dataSet = CamelContextHelper.mandatoryLookup(getCamelContext(), remaining,
DataSet.class);
+        return new DataSetEndpoint(uri, this, dataSet);
     }
 }

Added: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/dataset/DataSetConsumer.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/dataset/DataSetConsumer.java?rev=633440&view=auto
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/dataset/DataSetConsumer.java
(added)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/dataset/DataSetConsumer.java
Tue Mar  4 04:11:22 2008
@@ -0,0 +1,46 @@
+/**
+ *
+ * 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 org.apache.camel.Exchange;
+import org.apache.camel.Consumer;
+import org.apache.camel.Processor;
+import org.apache.camel.impl.DefaultConsumer;
+
+/**
+ * @version $Revision: 1.1 $
+ */
+public class DataSetConsumer extends DefaultConsumer<Exchange> {
+    private DataSetEndpoint endpoint;
+
+    public DataSetConsumer(DataSetEndpoint endpoint, Processor processor) {
+        super(endpoint, processor);
+        this.endpoint = endpoint;
+    }
+
+    @Override
+    protected void doStart() throws Exception {
+        super.doStart();
+
+        DataSet dataSet = endpoint.getDataSet();
+        for (long i = 0; i < dataSet.getSize(); i++) {
+            Exchange exchange = endpoint.createExchange(i);
+            getProcessor().process(exchange);
+        }
+    }
+}

Propchange: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/dataset/DataSetConsumer.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/dataset/DataSetEndpoint.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/dataset/DataSetEndpoint.java?rev=633440&view=auto
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/dataset/DataSetEndpoint.java
(added)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/dataset/DataSetEndpoint.java
Tue Mar  4 04:11:22 2008
@@ -0,0 +1,127 @@
+/**
+ *
+ * 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.concurrent.atomic.AtomicLong;
+import java.util.concurrent.atomic.AtomicInteger;
+
+import org.apache.camel.Component;
+import org.apache.camel.Exchange;
+import org.apache.camel.InvalidPayloadException;
+import org.apache.camel.NoSuchHeaderException;
+import org.apache.camel.Service;
+import org.apache.camel.Consumer;
+import org.apache.camel.Processor;
+import org.apache.camel.PollingConsumer;
+import org.apache.camel.impl.EventDrivenPollingConsumer;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.util.ExchangeHelper;
+import org.apache.camel.util.ObjectHelper;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+/**
+ * @version $Revision: 1.1 $
+ */
+public class DataSetEndpoint extends MockEndpoint implements Service {
+    private static final transient Log LOG = LogFactory.getLog(DataSetEndpoint.class);
+    private DataSet dataSet;
+    private AtomicInteger receivedCounter = new AtomicInteger();
+
+    public DataSetEndpoint(String endpointUri, Component component, DataSet dataSet) {
+        super(endpointUri, component);
+        this.dataSet = dataSet;
+    }
+
+    @Override
+    public PollingConsumer<Exchange> createPollingConsumer() throws Exception {
+        return new EventDrivenPollingConsumer<Exchange>(this);
+    }
+
+    @Override
+    public Consumer<Exchange> createConsumer(Processor processor) throws Exception
{
+        return new DataSetConsumer(this, processor);
+    }
+
+    @Override
+    public void reset() {
+        super.reset();
+        receivedCounter.set(0);
+    }
+
+    @Override
+        public int getReceivedCounter() {
+        return receivedCounter.get();
+    }
+
+    /**
+     * Creates a message exchange for the given index in the {@link DataSet}
+     */
+    public Exchange createExchange(long counter) throws Exception {
+        Exchange expected = createExchange();
+        getDataSet().populateMessage(expected, counter);
+        return expected;
+    }
+
+
+    public DataSet getDataSet() {
+        return dataSet;
+    }
+
+    public void setDataSet(DataSet dataSet) {
+        this.dataSet = dataSet;
+    }
+
+    @Override
+    protected void performAssertions(Exchange actual) throws Exception {
+        int receivedCount = receivedCounter.incrementAndGet();
+        long counter = receivedCount - 1;
+        Exchange expected = createExchange(counter);
+
+        // now lets assert that they are the same
+        LOG.debug("Received message: " + counter + " = " + actual);
+        assertMessageExpected(counter, expected, actual);
+    }
+
+    protected void assertMessageExpected(long counter, Exchange expected, Exchange actual)
throws InvalidPayloadException, NoSuchHeaderException {
+        long actualCounter = ExchangeHelper.getMandatoryHeader(actual, DataSet.INDEX_HEADER,
Long.class);
+        assertEquals(DataSet.INDEX_HEADER, counter, actualCounter, actual);
+
+        Object expectedBody = expected.getIn().getBody();
+        Object actualBody = actual.getIn().getBody();
+        if (expectedBody != null) {
+            // lets coerce to the correct type
+            actualBody = ExchangeHelper.getMandatoryInBody(actual, expectedBody.getClass());
+        }
+        assertEquals("message body", expectedBody, actualBody, actual);
+    }
+
+    protected void assertEquals(String description, Object expected, Object actual, Exchange
exchange) {
+        if (!ObjectHelper.equal(expected, actual)) {
+            throw new AssertionError(description + " does not match. Expected: " + expected
+ " but was: " + actual + " on  " + exchange);
+        }
+    }
+
+    public void start() throws Exception {
+        long size = getDataSet().getSize();
+        expectedMessageCount((int) size);
+    }
+
+    public void stop() throws Exception {
+    }
+}

Propchange: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/dataset/DataSetEndpoint.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/dataset/SimpleDataSet.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/dataset/SimpleDataSet.java?rev=633440&view=auto
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/dataset/SimpleDataSet.java
(added)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/dataset/SimpleDataSet.java
Tue Mar  4 04:11:22 2008
@@ -0,0 +1,114 @@
+/**
+ *
+ * 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.Map;
+import java.util.HashMap;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.Message;
+import org.apache.camel.Processor;
+
+/**
+ * A simple DataSet that allows a static payload to be used to create each message exchange
+ * along with using a pluggable transformer to randomize the message.
+ *
+ * @version $Revision: 1.1 $
+ */
+public class SimpleDataSet implements DataSet {
+    private Object defaultBody = "<hello>world!</hello>";
+    private Map<String,Object> defaultHeaders;
+    private Processor outputTransformer;
+    private Processor inputTransformer;
+    private long size = 10;
+
+    public SimpleDataSet() {
+    }
+
+    public SimpleDataSet(int size) {
+        setSize(size);
+    }
+
+    public void populateMessage(Exchange exchange, long messageIndex) throws Exception {
+        Message in = exchange.getIn();
+        in.setBody(getDefaultBody());
+        in.setHeaders(getDefaultHeaders());
+        applyHeaders(exchange, messageIndex);
+
+        if (outputTransformer != null) {
+            outputTransformer.process(exchange);
+        }
+    }
+
+    // Properties
+    //-------------------------------------------------------------------------
+
+    public long getSize() {
+        return size;
+    }
+
+    public void setSize(long size) {
+        this.size = size;
+    }
+
+    public Object getDefaultBody() {
+        return defaultBody;
+    }
+
+    public void setDefaultBody(Object defaultBody) {
+        this.defaultBody = defaultBody;
+    }
+
+    public Map<String, Object> getDefaultHeaders() {
+        if (defaultHeaders == null) {
+            defaultHeaders = new HashMap<String, Object>();
+            populateDefaultHeaders(defaultHeaders);
+        }
+        return defaultHeaders;
+    }
+
+    public void setDefaultHeaders(Map<String, Object> defaultHeaders) {
+        this.defaultHeaders = defaultHeaders;
+    }
+
+    public Processor getInputTransformer() {
+        return inputTransformer;
+    }
+
+    public void setInputTransformer(Processor inputTransformer) {
+        this.inputTransformer = inputTransformer;
+    }
+
+    public Processor getOutputTransformer() {
+        return outputTransformer;
+    }
+
+    public void setOutputTransformer(Processor outputTransformer) {
+        this.outputTransformer = outputTransformer;
+    }
+
+    // Implementation methods
+    //-------------------------------------------------------------------------
+    protected void applyHeaders(Exchange exchange, long messageIndex) {
+        Message in = exchange.getIn();
+        in.setHeader(DataSet.INDEX_HEADER, messageIndex);
+    }
+
+    protected void populateDefaultHeaders(Map<String, Object> map) {
+    }
+}

Propchange: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/dataset/SimpleDataSet.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/dataset/package.html
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/dataset/package.html?rev=633440&view=auto
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/dataset/package.html
(added)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/dataset/package.html
Tue Mar  4 04:11:22 2008
@@ -0,0 +1,25 @@
+<!--
+    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.
+-->
+<html>
+<head>
+</head>
+<body>
+
+A <a href="http://activemq.apache.org/camel/dataset.html">DataSet Endpoint</a>
for testing of endpoints using defined DataSets
+
+</body>
+</html>

Propchange: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/dataset/package.html
------------------------------------------------------------------------------
    svn:mime-type = text/html

Modified: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/mock/MockEndpoint.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/mock/MockEndpoint.java?rev=633440&r1=633439&r2=633440&view=diff
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/mock/MockEndpoint.java
(original)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/mock/MockEndpoint.java
Tue Mar  4 04:11:22 2008
@@ -69,7 +69,7 @@
 
     public MockEndpoint(String endpointUri, Component component) {
         super(endpointUri, component);
-        reset();
+        init();
     }
 
     public static void assertWait(long timeout, TimeUnit unit, MockEndpoint... endpoints)
throws InterruptedException {
@@ -503,7 +503,11 @@
     }
 
     public void reset() {
-    	expectedCount = -1;
+        init();
+    }
+
+    private void init() {
+        expectedCount = -1;
         counter = 0;
         processors = new HashMap<Integer, Processor>();
         receivedExchanges = new CopyOnWriteArrayList<Exchange>();
@@ -516,41 +520,45 @@
         expectedBodyValues = null;
         actualBodyValues = new ArrayList();
     }
-    
+
     // Implementation methods
     // -------------------------------------------------------------------------
     protected synchronized void onExchange(Exchange exchange) {
         try {
-            Message in = exchange.getIn();
-            Object actualBody = in.getBody();
+            performAssertions(exchange);
 
-            if (expectedBodyValues != null) {
-                int index = actualBodyValues.size();
-                if (expectedBodyValues.size() > index) {
-                    Object expectedBody = expectedBodyValues.get(index);
-                    if (expectedBody != null) {
-                        actualBody = in.getBody(expectedBody.getClass());
-                    }
-                    actualBodyValues.add(actualBody);
+        } catch (Throwable e) {
+            failures.add(e);
+        }
+        if (latch != null) {
+            latch.countDown();
+        }
+    }
+
+    protected void performAssertions(Exchange exchange) throws Exception {
+        Message in = exchange.getIn();
+        Object actualBody = in.getBody();
+
+        if (expectedBodyValues != null) {
+            int index = actualBodyValues.size();
+            if (expectedBodyValues.size() > index) {
+                Object expectedBody = expectedBodyValues.get(index);
+                if (expectedBody != null) {
+                    actualBody = in.getBody(expectedBody.getClass());
                 }
+                actualBodyValues.add(actualBody);
             }
+        }
 
-            LOG.debug(getEndpointUri() + " >>>> " + (++counter) + " : " + exchange
+ " with body: " + actualBody);
+        LOG.debug(getEndpointUri() + " >>>> " + (++counter) + " : " + exchange
+ " with body: " + actualBody);
 
-            receivedExchanges.add(exchange);
+        receivedExchanges.add(exchange);
 
-            Processor processor = processors.get(getReceivedCounter()) != null ?
-                    processors.get(getReceivedCounter()) : defaultProcessor;
-                    
-            if (processor != null) {
-                processor.process(exchange);
-            }
+        Processor processor = processors.get(getReceivedCounter()) != null ?
+                processors.get(getReceivedCounter()) : defaultProcessor;
 
-            if (latch != null) {
-                latch.countDown();
-            }
-        } catch (Exception e) {
-            failures.add(e);
+        if (processor != null) {
+            processor.process(exchange);
         }
     }
 

Modified: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/util/ExchangeHelper.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/util/ExchangeHelper.java?rev=633440&r1=633439&r2=633440&view=diff
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/util/ExchangeHelper.java
(original)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/util/ExchangeHelper.java
Tue Mar  4 04:11:22 2008
@@ -19,15 +19,7 @@
 import java.util.HashMap;
 import java.util.Map;
 
-import org.apache.camel.Endpoint;
-import org.apache.camel.Exchange;
-import org.apache.camel.ExchangePattern;
-import org.apache.camel.InvalidPayloadException;
-import org.apache.camel.InvalidTypeException;
-import org.apache.camel.Message;
-import org.apache.camel.NoSuchBeanException;
-import org.apache.camel.NoSuchEndpointException;
-import org.apache.camel.NoSuchPropertyException;
+import org.apache.camel.*;
 
 /**
  * Some helper methods for working with {@link Exchange} objects
@@ -91,6 +83,15 @@
         T answer = exchange.getProperty(propertyName, type);
         if (answer == null) {
             throw new NoSuchPropertyException(exchange, propertyName, type);
+        }
+        return answer;
+    }
+
+    public static <T> T getMandatoryHeader(Exchange exchange, String propertyName,
Class<T> type)
+            throws NoSuchHeaderException {
+        T answer = exchange.getIn().getHeader(propertyName, type);
+        if (answer == null) {
+            throw new NoSuchHeaderException(exchange, propertyName, type);
         }
         return answer;
     }

Copied: activemq/camel/trunk/camel-core/src/main/resources/META-INF/services/org/apache/camel/component/dataset
(from r633075, activemq/camel/trunk/camel-core/src/main/resources/META-INF/services/org/apache/camel/component/bean)
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/resources/META-INF/services/org/apache/camel/component/dataset?p2=activemq/camel/trunk/camel-core/src/main/resources/META-INF/services/org/apache/camel/component/dataset&p1=activemq/camel/trunk/camel-core/src/main/resources/META-INF/services/org/apache/camel/component/bean&r1=633075&r2=633440&rev=633440&view=diff
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/resources/META-INF/services/org/apache/camel/component/bean
(original)
+++ activemq/camel/trunk/camel-core/src/main/resources/META-INF/services/org/apache/camel/component/dataset
Tue Mar  4 04:11:22 2008
@@ -15,4 +15,4 @@
 # limitations under the License.
 #
 
-class=org.apache.camel.component.bean.BeanComponent
\ No newline at end of file
+class=org.apache.camel.component.dataset.DataSetComponent
\ No newline at end of file

Added: activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/component/dataset/DataSetConsumeTest.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/component/dataset/DataSetConsumeTest.java?rev=633440&view=auto
==============================================================================
--- activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/component/dataset/DataSetConsumeTest.java
(added)
+++ activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/component/dataset/DataSetConsumeTest.java
Tue Mar  4 04:11:22 2008
@@ -0,0 +1,46 @@
+/**
+ *
+ * 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;
+
+/**
+ * @version $Revision: 1.1 $
+ */
+public class DataSetConsumeTest extends ContextTestSupport {
+    protected SimpleDataSet dataSet = new SimpleDataSet(20);
+
+    public void testSendingMessagesExplicitlyToDataSetEndpoint() throws Exception {
+        long size = dataSet.getSize();
+        for (long i = 0; i < size; i++) {
+            template.sendBodyAndHeader("dataset:foo", "<hello>world!</hello>",
DataSet.INDEX_HEADER, i);
+        }
+
+        assertMockEndpointsSatisifed();
+    }
+
+    @Override
+    protected Context createJndiContext() throws Exception {
+        Context context = super.createJndiContext();
+        context.bind("foo", dataSet);
+        return context;
+    }
+}
\ No newline at end of file

Propchange: activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/component/dataset/DataSetConsumeTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/component/dataset/DataSetTest.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/component/dataset/DataSetTest.java?rev=633440&view=auto
==============================================================================
--- activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/component/dataset/DataSetTest.java
(added)
+++ activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/component/dataset/DataSetTest.java
Tue Mar  4 04:11:22 2008
@@ -0,0 +1,58 @@
+/**
+ *
+ * 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.component.mock.MockEndpoint;
+import org.apache.camel.builder.RouteBuilder;
+
+/**
+ * @version $Revision: 1.1 $
+ */
+public class DataSetTest extends ContextTestSupport {
+    protected SimpleDataSet dataSet = new SimpleDataSet(20);
+
+    public void test() throws Exception {
+        MockEndpoint endpoint = getMockEndpoint("mock:results");
+        endpoint.expectedMessageCount((int) dataSet.getSize());
+
+        assertMockEndpointsSatisifed();
+    }
+
+    @Override
+    protected Context createJndiContext() throws Exception {
+        Context context = super.createJndiContext();
+        context.bind("foo", dataSet);
+        return context;
+    }
+
+    @Override
+    protected RouteBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            public void configure() throws Exception {
+                from("dataset:foo").multicast().
+                        to("mock:results").
+                        to("seda:foo");
+
+                from("seda:foo").to("dataset:foo");
+            }
+        };
+    }
+}

Propchange: activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/component/dataset/DataSetTest.java
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message