You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by ni...@apache.org on 2009/09/13 09:51:53 UTC
svn commit: r814277 - in /camel/trunk/components/camel-cache: ./
src/main/java/org/apache/camel/processor/cache/
src/test/java/org/apache/camel/component/cache/
src/test/java/org/apache/camel/processor/cache/
Author: ningjiang
Date: Sun Sep 13 07:51:52 2009
New Revision: 814277
URL: http://svn.apache.org/viewvc?rev=814277&view=rev
Log:
CAMEL-1868 fixed the CS errors and update the svn property
Modified:
camel/trunk/components/camel-cache/ (props changed)
camel/trunk/components/camel-cache/src/main/java/org/apache/camel/processor/cache/CacheBasedMessageBodyReplacer.java
camel/trunk/components/camel-cache/src/main/java/org/apache/camel/processor/cache/CacheBasedTokenReplacer.java
camel/trunk/components/camel-cache/src/main/java/org/apache/camel/processor/cache/CacheBasedXPathReplacer.java
camel/trunk/components/camel-cache/src/main/java/org/apache/camel/processor/cache/CacheValidate.java
camel/trunk/components/camel-cache/src/test/java/org/apache/camel/component/cache/CacheConsumerTest.java
camel/trunk/components/camel-cache/src/test/java/org/apache/camel/component/cache/CacheProducerTest.java
camel/trunk/components/camel-cache/src/test/java/org/apache/camel/processor/cache/CacheBasedBodyReplacerTest.java
camel/trunk/components/camel-cache/src/test/java/org/apache/camel/processor/cache/CacheBasedTokenReplacerTest.java
camel/trunk/components/camel-cache/src/test/java/org/apache/camel/processor/cache/CacheBasedXPathElementReplacerTest.java
Propchange: camel/trunk/components/camel-cache/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Sun Sep 13 07:51:52 2009
@@ -0,0 +1,7 @@
+.project
+.checkstyle
+.pmd
+.classpath
+target
+.settings
+eclipse-classes
Modified: camel/trunk/components/camel-cache/src/main/java/org/apache/camel/processor/cache/CacheBasedMessageBodyReplacer.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-cache/src/main/java/org/apache/camel/processor/cache/CacheBasedMessageBodyReplacer.java?rev=814277&r1=814276&r2=814277&view=diff
==============================================================================
--- camel/trunk/components/camel-cache/src/main/java/org/apache/camel/processor/cache/CacheBasedMessageBodyReplacer.java (original)
+++ camel/trunk/components/camel-cache/src/main/java/org/apache/camel/processor/cache/CacheBasedMessageBodyReplacer.java Sun Sep 13 07:51:52 2009
@@ -1,3 +1,19 @@
+/**
+ * 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.processor.cache;
import net.sf.ehcache.CacheManager;
@@ -11,54 +27,49 @@
public class CacheBasedMessageBodyReplacer extends CacheValidate implements Processor {
private static final transient Log LOG = LogFactory.getLog(CacheBasedMessageBodyReplacer.class);
- private String cacheName;
- private String key;
CacheManager cacheManager;
Ehcache cache;
+ private String cacheName;
+ private String key;
+
+
+ public CacheBasedMessageBodyReplacer(String cacheName, String key) {
+ super();
+ if (cacheName.contains("cache://")) {
+ this.setCacheName(cacheName.replace("cache://", ""));
+ } else {
+ this.setCacheName(cacheName);
+ }
+ this.setKey(key);
+ }
- public CacheBasedMessageBodyReplacer(String cacheName, String key) {
- super();
- if (cacheName.contains("cache://")) {
- this.setCacheName(cacheName.replace("cache://", ""));
- } else {
- this.setCacheName(cacheName);
- }
- this.setKey(key);
- }
-
-
- public void process(Exchange exchange) throws Exception {
- // Cache the buffer to the specified Cache against the specified key
+ public void process(Exchange exchange) throws Exception {
+ // Cache the buffer to the specified Cache against the specified key
cacheManager = new CacheManagerFactory().instantiateCacheManager();
if (isValid(cacheManager, cacheName, key)) {
cache = cacheManager.getCache(cacheName);
LOG.info("Replacing Message Body from CacheName " + cacheName + " for key " + key);
exchange.getIn().setHeader("CACHE_KEY", key);
- exchange.getIn().setBody(cache.get(key).getObjectValue());
+ exchange.getIn().setBody(cache.get(key).getObjectValue());
}
-
- }
-
-
- public String getCacheName() {
- return cacheName;
- }
-
-
- public void setCacheName(String cacheName) {
- this.cacheName = cacheName;
- }
-
-
- public String getKey() {
- return key;
- }
+ }
- public void setKey(String key) {
- this.key = key;
- }
+ public String getCacheName() {
+ return cacheName;
+ }
+
+ public void setCacheName(String cacheName) {
+ this.cacheName = cacheName;
+ }
+
+ public String getKey() {
+ return key;
+ }
+
+ public void setKey(String key) {
+ this.key = key;
+ }
-
}
Modified: camel/trunk/components/camel-cache/src/main/java/org/apache/camel/processor/cache/CacheBasedTokenReplacer.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-cache/src/main/java/org/apache/camel/processor/cache/CacheBasedTokenReplacer.java?rev=814277&r1=814276&r2=814277&view=diff
==============================================================================
--- camel/trunk/components/camel-cache/src/main/java/org/apache/camel/processor/cache/CacheBasedTokenReplacer.java (original)
+++ camel/trunk/components/camel-cache/src/main/java/org/apache/camel/processor/cache/CacheBasedTokenReplacer.java Sun Sep 13 07:51:52 2009
@@ -1,3 +1,19 @@
+/**
+ * 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.processor.cache;
import java.io.InputStream;
@@ -12,77 +28,73 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-public class CacheBasedTokenReplacer extends CacheValidate implements Processor {
+public class CacheBasedTokenReplacer extends CacheValidate implements Processor {
private static final transient Log LOG = LogFactory.getLog(CacheBasedTokenReplacer.class);
- private String cacheName;
- private String key;
- private String replacementToken;
+ private String cacheName;
+ private String key;
+ private String replacementToken;
private CacheManager cacheManager;
private Ehcache cache;
-
-
- public CacheBasedTokenReplacer(String cacheName, String key, String replacementToken) {
- super();
- if (cacheName.contains("cache://")) {
- this.setCacheName(cacheName.replace("cache://", ""));
- } else {
- this.setCacheName(cacheName);
- }
- this.setKey(key);
- this.setReplacementToken(replacementToken);
- }
+ public CacheBasedTokenReplacer(String cacheName, String key, String replacementToken) {
+ super();
+ if (cacheName.contains("cache://")) {
+ this.setCacheName(cacheName.replace("cache://", ""));
+ } else {
+ this.setCacheName(cacheName);
+ }
+ this.setKey(key);
+ this.setReplacementToken(replacementToken);
+ }
- public void process(Exchange exchange) throws Exception {
- // Cache the buffer to the specified Cache against the specified key
+ public void process(Exchange exchange) throws Exception {
+ // Cache the buffer to the specified Cache against the specified key
cacheManager = new CacheManagerFactory().instantiateCacheManager();
-
+
if (isValid(cacheManager, cacheName, key)) {
cache = cacheManager.getCache(cacheName);
- LOG.info("Replacing Token " + replacementToken + "in Message with value stored against key " + key + " in CacheName " + cacheName);
+ LOG.info("Replacing Token " + replacementToken + "in Message with value stored against key "
+ + key + " in CacheName " + cacheName);
exchange.getIn().setHeader("CACHE_KEY", key);
- Object body = exchange.getIn().getBody();
+ Object body = exchange.getIn().getBody();
InputStream is = exchange.getContext().getTypeConverter().convertTo(InputStream.class, body);
-
+
byte[] buffer = IOConverter.toBytes(is);
is.close();
- //Note: The value in the cache must be a String
- String cacheValue = exchange.getContext().getTypeConverter().convertTo(String.class, cache.get(key).getObjectValue());
+ // Note: The value in the cache must be a String
+ String cacheValue = exchange.getContext().getTypeConverter().convertTo(
+ String.class,
+ cache.get(key)
+ .getObjectValue());
String replacedTokenString = new String(buffer).replaceAll(replacementToken, cacheValue);
LOG.debug("replacedTokenString = " + replacedTokenString);
exchange.getIn().setBody(replacedTokenString.getBytes());
}
- }
-
-
- public String getCacheName() {
- return cacheName;
- }
-
-
- public void setCacheName(String cacheName) {
- this.cacheName = cacheName;
- }
-
-
- public String getKey() {
- return key;
- }
-
-
- public void setKey(String key) {
- this.key = key;
- }
-
-
- public String getReplacementToken() {
- return replacementToken;
- }
+ }
+ public String getCacheName() {
+ return cacheName;
+ }
+
+ public void setCacheName(String cacheName) {
+ this.cacheName = cacheName;
+ }
+
+ public String getKey() {
+ return key;
+ }
+
+ public void setKey(String key) {
+ this.key = key;
+ }
+
+ public String getReplacementToken() {
+ return replacementToken;
+ }
+
+ public void setReplacementToken(String replacementToken) {
+ this.replacementToken = replacementToken;
+ }
- public void setReplacementToken(String replacementToken) {
- this.replacementToken = replacementToken;
- }
-
}
Modified: camel/trunk/components/camel-cache/src/main/java/org/apache/camel/processor/cache/CacheBasedXPathReplacer.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-cache/src/main/java/org/apache/camel/processor/cache/CacheBasedXPathReplacer.java?rev=814277&r1=814276&r2=814277&view=diff
==============================================================================
--- camel/trunk/components/camel-cache/src/main/java/org/apache/camel/processor/cache/CacheBasedXPathReplacer.java (original)
+++ camel/trunk/components/camel-cache/src/main/java/org/apache/camel/processor/cache/CacheBasedXPathReplacer.java Sun Sep 13 07:51:52 2009
@@ -1,3 +1,19 @@
+/**
+ * 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.processor.cache;
import java.io.File;
@@ -10,9 +26,10 @@
import javax.xml.transform.dom.DOMResult;
import javax.xml.transform.dom.DOMSource;
+import org.w3c.dom.Document;
+
import net.sf.ehcache.CacheManager;
import net.sf.ehcache.Ehcache;
-
import org.apache.camel.Exchange;
import org.apache.camel.Processor;
import org.apache.camel.component.cache.factory.CacheManagerFactory;
@@ -20,13 +37,13 @@
import org.apache.camel.converter.jaxp.XmlConverter;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-import org.w3c.dom.Document;
-public class CacheBasedXPathReplacer extends CacheValidate implements Processor {
+
+public class CacheBasedXPathReplacer extends CacheValidate implements Processor {
private static final transient Log LOG = LogFactory.getLog(CacheBasedXPathReplacer.class);
- private String cacheName;
- private String key;
- private String xpath;
+ private String cacheName;
+ private String key;
+ private String xpath;
private CacheManager cacheManager;
private Ehcache cache;
private Document document;
@@ -41,17 +58,17 @@
this.setCacheName(cacheName);
}
this.key = key;
- this.xpath = xpath;
+ this.xpath = xpath;
}
-
public void process(Exchange exchange) throws Exception {
- // Cache the buffer to the specified Cache against the specified key
+ // Cache the buffer to the specified Cache against the specified key
cacheManager = new CacheManagerFactory().instantiateCacheManager();
-
+
if (isValid(cacheManager, cacheName, key)) {
cache = cacheManager.getCache(cacheName);
- LOG.info("Replacing XPath value " + xpath + "in Message with value stored against key " + key + " in CacheName " + cacheName);
+ LOG.info("Replacing XPath value " + xpath + "in Message with value stored against key " + key
+ + " in CacheName " + cacheName);
exchange.getIn().setHeader("CACHE_KEY", key);
Object body = exchange.getIn().getBody();
InputStream is = exchange.getContext().getTypeConverter().convertTo(InputStream.class, body);
@@ -61,11 +78,15 @@
is.close();
}
- InputStream cis = exchange.getContext().getTypeConverter().convertTo(InputStream.class, cache.get(key).getObjectValue());
+ InputStream cis = exchange.getContext().getTypeConverter().convertTo(
+ InputStream.class,
+ cache.get(key)
+ .getObjectValue());
try {
- Document cacheValueDocument = exchange.getContext().getTypeConverter().convertTo(Document.class, exchange, cis);
-
- //Create/setup the Transformer
+ Document cacheValueDocument = exchange.getContext().getTypeConverter()
+ .convertTo(Document.class, exchange, cis);
+
+ // Create/setup the Transformer
XmlConverter xmlConverter = new XmlConverter();
String xslString = IOConverter.toString(new File("./src/main/resources/xpathreplacer.xsl"));
xslString = xslString.replace("##match_token##", xpath);
@@ -79,15 +100,17 @@
transformer.transform(source, result);
} finally {
cis.close();
- }
+ }
}
-
- exchange.getIn().setBody(IOConverter.toBytes(IOConverter.toInputStrean(new DOMSource(result.getNode()))));
+
+ exchange.getIn().setBody(
+ IOConverter.toBytes(IOConverter
+ .toInputStrean(new DOMSource(result.getNode()))));
}
public String getCacheName() {
- return cacheName;
- }
+ return cacheName;
+ }
public void setCacheName(String cacheName) {
this.cacheName = cacheName;
@@ -106,7 +129,7 @@
}
public void setXpath(String xpath) {
- this.xpath = xpath;
- }
+ this.xpath = xpath;
+ }
}
Modified: camel/trunk/components/camel-cache/src/main/java/org/apache/camel/processor/cache/CacheValidate.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-cache/src/main/java/org/apache/camel/processor/cache/CacheValidate.java?rev=814277&r1=814276&r2=814277&view=diff
==============================================================================
--- camel/trunk/components/camel-cache/src/main/java/org/apache/camel/processor/cache/CacheValidate.java (original)
+++ camel/trunk/components/camel-cache/src/main/java/org/apache/camel/processor/cache/CacheValidate.java Sun Sep 13 07:51:52 2009
@@ -1,3 +1,19 @@
+/**
+ * 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.processor.cache;
import net.sf.ehcache.CacheManager;
@@ -12,21 +28,30 @@
public boolean isValid(CacheManager cacheManager, String cacheName, String key) {
LOG.info("Cache Name: " + cacheName);
if (!cacheManager.cacheExists(cacheName)) {
- LOG.info("No existing Cache found with name: " + cacheName + ". Please ensure a cache is first instantiated using a Cache Consumer or Cache Producer");
- LOG.info("Replacement will not be performed since the cache " + cacheName + "does not presently exist");
+ LOG
+ .info("No existing Cache found with name: "
+ + cacheName
+ + ". Please ensure a cache is first instantiated using a Cache Consumer or Cache Producer");
+ LOG.info("Replacement will not be performed since the cache " + cacheName
+ + "does not presently exist");
return false;
}
-
+
LOG.info("Found an existing cache: " + cacheName);
- LOG.info("Cache " + cacheName + " currently contains " + cacheManager.getCache(cacheName).getSize() + " elements");
+ LOG.info("Cache " + cacheName + " currently contains " + cacheManager.getCache(cacheName).getSize()
+ + " elements");
Ehcache cache = cacheManager.getCache(cacheName);
if (!cache.isKeyInCache(key)) {
- LOG.info("No Key with name: " + key + "presently exists in the cache. It is also possible that the key may have expired in the cache");
- LOG.info("Replacement will not be performed until an appropriate key/value pair is added to (or) found in the cache.");
- return false;
-
+ LOG
+ .info("No Key with name: "
+ + key
+ + "presently exists in the cache. It is also possible that the key may have expired in the cache");
+ LOG
+ .info("Replacement will not be performed until an appropriate key/value pair is added to (or) found in the cache.");
+ return false;
+
}
-
- return true;
+
+ return true;
}
}
Modified: camel/trunk/components/camel-cache/src/test/java/org/apache/camel/component/cache/CacheConsumerTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-cache/src/test/java/org/apache/camel/component/cache/CacheConsumerTest.java?rev=814277&r1=814276&r2=814277&view=diff
==============================================================================
--- camel/trunk/components/camel-cache/src/test/java/org/apache/camel/component/cache/CacheConsumerTest.java (original)
+++ camel/trunk/components/camel-cache/src/test/java/org/apache/camel/component/cache/CacheConsumerTest.java Sun Sep 13 07:51:52 2009
@@ -17,15 +17,9 @@
package org.apache.camel.component.cache;
-import java.io.BufferedInputStream;
-import java.io.FileInputStream;
-import java.io.InputStream;
import java.util.ArrayList;
-import java.util.Iterator;
import java.util.List;
-import org.apache.camel.test.junit4.CamelTestSupport;
-import org.junit.Test;
import org.apache.camel.EndpointInject;
import org.apache.camel.Exchange;
import org.apache.camel.Message;
@@ -34,9 +28,10 @@
import org.apache.camel.ProducerTemplate;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.component.mock.MockEndpoint;
-import org.apache.camel.impl.DefaultExchange;
+import org.apache.camel.test.junit4.CamelTestSupport;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+import org.junit.Test;
public class CacheConsumerTest extends CamelTestSupport {
private static final transient Log LOG = LogFactory.getLog(CacheConsumerTest.class);
@@ -46,13 +41,12 @@
@Produce(uri = "direct:start")
protected ProducerTemplate producerTemplate;
-
@Test
public void testReceivingFileFromCache() throws Exception {
- LOG.info("Beginning Test ---> testReceivingFileFromCache()");
-
+ LOG.info("Beginning Test ---> testReceivingFileFromCache()");
+
resultEndpoint.expectedMessageCount(3);
-
+
List<String> operations = new ArrayList<String>();
operations.add("ADD");
operations.add("UPDATE");
@@ -70,21 +64,20 @@
}
resultEndpoint.assertIsSatisfied();
- LOG.info("Completed Test ---> testReceivingFileFromCache()");
+ LOG.info("Completed Test ---> testReceivingFileFromCache()");
}
-
+
@Override
protected RouteBuilder createRouteBuilder() throws Exception {
return new RouteBuilder() {
public void configure() {
- from("cache://TestCache1").
- process(new Processor() {
+ from("cache://TestCache1").process(new Processor() {
public void process(Exchange exchange) throws Exception {
- String operation = (String) exchange.getIn().getHeader("CACHE_OPERATION");
- String key = (String) exchange.getIn().getHeader("CACHE_KEY");
+ String operation = (String)exchange.getIn().getHeader("CACHE_OPERATION");
+ String key = (String)exchange.getIn().getHeader("CACHE_KEY");
Object body = exchange.getIn().getBody();
String data = exchange.getContext().getTypeConverter().convertTo(String.class, body);
-
+
LOG.info("------- Cache Event Notification ---------");
LOG.info("Received notification for the following activity in cache TestCache1:");
LOG.info("Operation = " + operation);
@@ -92,14 +85,12 @@
LOG.info("value = " + data);
LOG.info("------ End Cache Event Notification ------");
}
-
- }).
- to("mock:result");
-
- from("direct:start").
- to("cache://TestCache1");
+
+ }).to("mock:result");
+
+ from("direct:start").to("cache://TestCache1");
}
};
- }
-
+ }
+
}
Modified: camel/trunk/components/camel-cache/src/test/java/org/apache/camel/component/cache/CacheProducerTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-cache/src/test/java/org/apache/camel/component/cache/CacheProducerTest.java?rev=814277&r1=814276&r2=814277&view=diff
==============================================================================
--- camel/trunk/components/camel-cache/src/test/java/org/apache/camel/component/cache/CacheProducerTest.java (original)
+++ camel/trunk/components/camel-cache/src/test/java/org/apache/camel/component/cache/CacheProducerTest.java Sun Sep 13 07:51:52 2009
@@ -21,15 +21,15 @@
import java.io.FileInputStream;
import java.io.InputStream;
-import org.apache.camel.test.junit4.CamelTestSupport;
-import org.junit.Test;
import org.apache.camel.Exchange;
import org.apache.camel.Message;
import org.apache.camel.Processor;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.converter.IOConverter;
+import org.apache.camel.test.junit4.CamelTestSupport;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+import org.junit.Test;
public class CacheProducerTest extends CamelTestSupport {
private static final transient Log LOG = LogFactory.getLog(CacheProducerTest.class);
Modified: camel/trunk/components/camel-cache/src/test/java/org/apache/camel/processor/cache/CacheBasedBodyReplacerTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-cache/src/test/java/org/apache/camel/processor/cache/CacheBasedBodyReplacerTest.java?rev=814277&r1=814276&r2=814277&view=diff
==============================================================================
--- camel/trunk/components/camel-cache/src/test/java/org/apache/camel/processor/cache/CacheBasedBodyReplacerTest.java (original)
+++ camel/trunk/components/camel-cache/src/test/java/org/apache/camel/processor/cache/CacheBasedBodyReplacerTest.java Sun Sep 13 07:51:52 2009
@@ -43,13 +43,12 @@
@Produce(uri = "direct:start")
protected ProducerTemplate producerTemplate;
-
@Test
public void testCacheBasedBodyReplacer() throws Exception {
- LOG.info("Beginning Test ---> testCacheBasedBodyReplacer()");
-
- resultEndpoint.expectedMessageCount(1);
-
+ LOG.info("Beginning Test ---> testCacheBasedBodyReplacer()");
+
+ resultEndpoint.expectedMessageCount(1);
+
List<String> keys = new ArrayList<String>();
keys.add("farewell");
keys.add("greeting");
@@ -68,40 +67,36 @@
}
});
}
-
+
resultEndpoint.assertIsSatisfied();
- LOG.info("Completed Test ---> testCacheBasedBodyReplacer()");
-
+ LOG.info("Completed Test ---> testCacheBasedBodyReplacer()");
+
}
@Override
protected RouteBuilder createRouteBuilder() throws Exception {
return new RouteBuilder() {
public void configure() {
- from("cache://TestCache1").
- filter(header("CACHE_KEY").isEqualTo("greeting")).
- process (new CacheBasedMessageBodyReplacer("cache://TestCache1","farewell")).
- to("direct:next");
-
- from("direct:next").
- process (new Processor() {
- public void process(Exchange exchange) throws Exception {
- String key = (String) exchange.getIn().getHeader("CACHE_KEY");
- Object body = exchange.getIn().getBody();
- String data = exchange.getContext().getTypeConverter().convertTo(String.class, body);
-
- LOG.info("------- Payload Replacement Results ---------");
- LOG.info("The following Payload was replaced from Cache: TestCache1");
- LOG.info("key = " + key);
- LOG.info("Before value = Hello World");
- LOG.info("After value = " + data);
- LOG.info("------ End ------");
- }
- }).
- to("mock:result");
-
- from("direct:start").
- to("cache://TestCache1");
+ from("cache://TestCache1").filter(header("CACHE_KEY").isEqualTo("greeting"))
+ .process(new CacheBasedMessageBodyReplacer("cache://TestCache1", "farewell"))
+ .to("direct:next");
+
+ from("direct:next").process(new Processor() {
+ public void process(Exchange exchange) throws Exception {
+ String key = (String)exchange.getIn().getHeader("CACHE_KEY");
+ Object body = exchange.getIn().getBody();
+ String data = exchange.getContext().getTypeConverter().convertTo(String.class, body);
+
+ LOG.info("------- Payload Replacement Results ---------");
+ LOG.info("The following Payload was replaced from Cache: TestCache1");
+ LOG.info("key = " + key);
+ LOG.info("Before value = Hello World");
+ LOG.info("After value = " + data);
+ LOG.info("------ End ------");
+ }
+ }).to("mock:result");
+
+ from("direct:start").to("cache://TestCache1");
}
};
Modified: camel/trunk/components/camel-cache/src/test/java/org/apache/camel/processor/cache/CacheBasedTokenReplacerTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-cache/src/test/java/org/apache/camel/processor/cache/CacheBasedTokenReplacerTest.java?rev=814277&r1=814276&r2=814277&view=diff
==============================================================================
--- camel/trunk/components/camel-cache/src/test/java/org/apache/camel/processor/cache/CacheBasedTokenReplacerTest.java (original)
+++ camel/trunk/components/camel-cache/src/test/java/org/apache/camel/processor/cache/CacheBasedTokenReplacerTest.java Sun Sep 13 07:51:52 2009
@@ -42,19 +42,18 @@
@Produce(uri = "direct:loadcache")
protected ProducerTemplate producerTemplate;
-
- String quote = "#novel# - #author#\n" +
- "'Tis all a Chequer-board of Nights and Days\n" +
- "Where Destiny with Men for Pieces plays:\n" +
- "Hither and thither moves, and mates, and slays,\n" +
- "And #number# by #number# back in the Closet lays.";
-
+
+ String quote = "#novel# - #author#\n" + "'Tis all a Chequer-board of Nights and Days\n"
+ + "Where Destiny with Men for Pieces plays:\n"
+ + "Hither and thither moves, and mates, and slays,\n"
+ + "And #number# by #number# back in the Closet lays.";
+
@Test
public void testCacheBasedTokenReplacer() throws Exception {
- LOG.info("Beginning Test ---> testCacheBasedTokenReplacer()");
-
- resultEndpoint.expectedMessageCount(1);
-
+ LOG.info("Beginning Test ---> testCacheBasedTokenReplacer()");
+
+ resultEndpoint.expectedMessageCount(1);
+
List<String> keys = new ArrayList<String>();
keys.add("novel");
keys.add("author");
@@ -79,44 +78,38 @@
}
});
}
-
-
-
+
resultEndpoint.assertIsSatisfied();
- LOG.info("Completed Test ---> testCacheBasedTokenReplacer()");
-
+ LOG.info("Completed Test ---> testCacheBasedTokenReplacer()");
+
}
@Override
protected RouteBuilder createRouteBuilder() throws Exception {
return new RouteBuilder() {
public void configure() {
- from("cache://TestCache1").
- filter(header("CACHE_KEY").isEqualTo("quote")).
- process (new CacheBasedTokenReplacer("cache://TestCache1","novel","#novel#")).
- process (new CacheBasedTokenReplacer("cache://TestCache1","author","#author#")).
- process (new CacheBasedTokenReplacer("cache://TestCache1","number","#number#")).
- to("direct:next");
-
- from("direct:next").
- process (new Processor() {
- public void process(Exchange exchange) throws Exception {
- String key = (String) exchange.getIn().getHeader("CACHE_KEY");
- Object body = exchange.getIn().getBody();
- String data = exchange.getContext().getTypeConverter().convertTo(String.class, body);
-
- LOG.info("------- Payload Replacement Results ---------");
- LOG.info("The following Payload was replaced from Cache: TestCache1");
- LOG.info("key = " + key);
- LOG.info("Before Value = " + quote);
- LOG.info("After value = " + data);
- LOG.info("------ End ------");
- }
- }).
- to("mock:result");
-
- from("direct:loadcache").
- to("cache://TestCache1");
+ from("cache://TestCache1").filter(header("CACHE_KEY").isEqualTo("quote"))
+ .process(new CacheBasedTokenReplacer("cache://TestCache1", "novel", "#novel#"))
+ .process(new CacheBasedTokenReplacer("cache://TestCache1", "author", "#author#"))
+ .process(new CacheBasedTokenReplacer("cache://TestCache1", "number", "#number#"))
+ .to("direct:next");
+
+ from("direct:next").process(new Processor() {
+ public void process(Exchange exchange) throws Exception {
+ String key = (String)exchange.getIn().getHeader("CACHE_KEY");
+ Object body = exchange.getIn().getBody();
+ String data = exchange.getContext().getTypeConverter().convertTo(String.class, body);
+
+ LOG.info("------- Payload Replacement Results ---------");
+ LOG.info("The following Payload was replaced from Cache: TestCache1");
+ LOG.info("key = " + key);
+ LOG.info("Before Value = " + quote);
+ LOG.info("After value = " + data);
+ LOG.info("------ End ------");
+ }
+ }).to("mock:result");
+
+ from("direct:loadcache").to("cache://TestCache1");
}
};
Modified: camel/trunk/components/camel-cache/src/test/java/org/apache/camel/processor/cache/CacheBasedXPathElementReplacerTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-cache/src/test/java/org/apache/camel/processor/cache/CacheBasedXPathElementReplacerTest.java?rev=814277&r1=814276&r2=814277&view=diff
==============================================================================
--- camel/trunk/components/camel-cache/src/test/java/org/apache/camel/processor/cache/CacheBasedXPathElementReplacerTest.java (original)
+++ camel/trunk/components/camel-cache/src/test/java/org/apache/camel/processor/cache/CacheBasedXPathElementReplacerTest.java Sun Sep 13 07:51:52 2009
@@ -41,32 +41,24 @@
@Produce(uri = "direct:loadcache")
protected ProducerTemplate producerTemplate;
-
- String XML_FRAGMENT = "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>"
- + "<books>"
- + "<book1>"
- + "</book1>"
- + "<book2>"
- + "</book2>"
- + "</books>";
-
- String book1 = "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>"
- + "<book1>"
- + "<novel>My Man Jeeves</novel>"
- + "<author>P.G Wodehouse</author>"
- + "</book1>";
- String book2 = "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>"
- + "<book2>"
- + "<novel>The Jungle Book</novel>"
- + "<author>Rudyard Kipling</author>"
- + "</book2>";
-
+
+ String xmlFragment = "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>"
+ + "<books>" + "<book1>" + "</book1>"
+ + "<book2>" + "</book2>" + "</books>";
+
+ String book1 = "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>"
+ + "<book1>" + "<novel>My Man Jeeves</novel>"
+ + "<author>P.G Wodehouse</author>" + "</book1>";
+ String book2 = "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>"
+ + "<book2>" + "<novel>The Jungle Book</novel>"
+ + "<author>Rudyard Kipling</author>" + "</book2>";
+
@Test
public void testCacheBasedXPathElementReplacer() throws Exception {
- LOG.info("Beginning Test ---> testCacheBasedXPathElementReplacer()");
-
- resultEndpoint.expectedMessageCount(1);
-
+ LOG.info("Beginning Test ---> testCacheBasedXPathElementReplacer()");
+
+ resultEndpoint.expectedMessageCount(1);
+
List<String> keys = new ArrayList<String>();
keys.add("book1");
keys.add("book2");
@@ -80,49 +72,45 @@
in.setHeader("CACHE_KEY", key);
if (key.equalsIgnoreCase("book1")) {
in.setBody(book1);
- } else if(key.equalsIgnoreCase("book2")) {
+ } else if (key.equalsIgnoreCase("book2")) {
in.setBody(book2);
} else {
- in.setBody(XML_FRAGMENT);
+ in.setBody(xmlFragment);
}
}
});
- }
-
+ }
+
resultEndpoint.assertIsSatisfied();
- LOG.info("Completed Test ---> testCacheBasedXPathElementReplacer()");
-
+ LOG.info("Completed Test ---> testCacheBasedXPathElementReplacer()");
+
}
@Override
protected RouteBuilder createRouteBuilder() throws Exception {
return new RouteBuilder() {
public void configure() {
- from("cache://TestCache1").
- filter(header("CACHE_KEY").isEqualTo("XML_FRAGMENT")).
- process (new CacheBasedXPathReplacer("cache://TestCache1","book1","/books/book1")).
- process (new CacheBasedXPathReplacer("cache://TestCache1","book2","/books/book2")).
- to("direct:next");
-
- from("direct:next").
- process (new Processor() {
- public void process(Exchange exchange) throws Exception {
- String key = (String) exchange.getIn().getHeader("CACHE_KEY");
- Object body = exchange.getIn().getBody();
- String data = exchange.getContext().getTypeConverter().convertTo(String.class, body);
-
- LOG.info("------- Payload Replacement Results ---------");
- LOG.info("The following Payload was replaced from Cache: TestCache1");
- LOG.info("key = " + key);
- LOG.info("Before Value = " + XML_FRAGMENT);
- LOG.info("After value = " + data);
- LOG.info("------ End ------");
- }
- }).
- to("mock:result");
-
- from("direct:loadcache").
- to("cache://TestCache1");
+ from("cache://TestCache1").filter(header("CACHE_KEY").isEqualTo("XML_FRAGMENT"))
+ .process(new CacheBasedXPathReplacer("cache://TestCache1", "book1", "/books/book1"))
+ .process(new CacheBasedXPathReplacer("cache://TestCache1", "book2", "/books/book2"))
+ .to("direct:next");
+
+ from("direct:next").process(new Processor() {
+ public void process(Exchange exchange) throws Exception {
+ String key = (String)exchange.getIn().getHeader("CACHE_KEY");
+ Object body = exchange.getIn().getBody();
+ String data = exchange.getContext().getTypeConverter().convertTo(String.class, body);
+
+ LOG.info("------- Payload Replacement Results ---------");
+ LOG.info("The following Payload was replaced from Cache: TestCache1");
+ LOG.info("key = " + key);
+ LOG.info("Before Value = " + xmlFragment);
+ LOG.info("After value = " + data);
+ LOG.info("------ End ------");
+ }
+ }).to("mock:result");
+
+ from("direct:loadcache").to("cache://TestCache1");
}
};