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 2009/09/25 09:11:07 UTC
svn commit: r818745 - in /camel/trunk/camel-core/src:
main/java/org/apache/camel/processor/ main/java/org/apache/camel/util/
test/java/org/apache/camel/impl/ test/java/org/apache/camel/util/
Author: davsclaus
Date: Fri Sep 25 07:11:06 2009
New Revision: 818745
URL: http://svn.apache.org/viewvc?rev=818745&view=rev
Log:
MR-187: Added more unit test. Removed stuff not used.
Added:
camel/trunk/camel-core/src/test/java/org/apache/camel/util/EndpointHelperTest.java (with props)
Modified:
camel/trunk/camel-core/src/main/java/org/apache/camel/processor/FilterProcessor.java
camel/trunk/camel-core/src/main/java/org/apache/camel/util/CollectionHelper.java
camel/trunk/camel-core/src/main/java/org/apache/camel/util/EndpointHelper.java
camel/trunk/camel-core/src/main/java/org/apache/camel/util/ExchangeHelper.java
camel/trunk/camel-core/src/main/java/org/apache/camel/util/IntrospectionSupport.java
camel/trunk/camel-core/src/main/java/org/apache/camel/util/ServiceHelper.java
camel/trunk/camel-core/src/test/java/org/apache/camel/impl/DefaultProducerTemplateAsyncTest.java
camel/trunk/camel-core/src/test/java/org/apache/camel/util/CollectionHelperTest.java
camel/trunk/camel-core/src/test/java/org/apache/camel/util/ExchangeHelperTest.java
camel/trunk/camel-core/src/test/java/org/apache/camel/util/IntrospectionSupportTest.java
camel/trunk/camel-core/src/test/java/org/apache/camel/util/KeyValueHolderTest.java
camel/trunk/camel-core/src/test/java/org/apache/camel/util/MessageHelperTest.java
camel/trunk/camel-core/src/test/java/org/apache/camel/util/UuidGeneratorTest.java
Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/processor/FilterProcessor.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/processor/FilterProcessor.java?rev=818745&r1=818744&r2=818745&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/processor/FilterProcessor.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/processor/FilterProcessor.java Fri Sep 25 07:11:06 2009
@@ -19,6 +19,7 @@
import org.apache.camel.Exchange;
import org.apache.camel.Predicate;
import org.apache.camel.Processor;
+import org.apache.camel.util.ServiceHelper;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@@ -61,4 +62,16 @@
public Predicate getPredicate() {
return predicate;
}
+
+ @Override
+ protected void doStart() throws Exception {
+ super.doStart();
+ ServiceHelper.startService(predicate);
+ }
+
+ @Override
+ protected void doStop() throws Exception {
+ ServiceHelper.stopService(predicate);
+ super.doStop();
+ }
}
Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/util/CollectionHelper.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/util/CollectionHelper.java?rev=818745&r1=818744&r2=818745&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/util/CollectionHelper.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/util/CollectionHelper.java Fri Sep 25 07:11:06 2009
@@ -87,6 +87,9 @@
} else {
list = new ArrayList();
list.add(oldValue);
+ // replace old entry with list
+ map.remove(key);
+ map.put(key, list);
}
list.add(value);
} else {
@@ -94,26 +97,6 @@
}
}
- /**
- * Filters the given list to skip instanceof filter objects.
- *
- * @param list the list
- * @param filters objects to skip
- * @return a new list without the filtered objects
- */
- @SuppressWarnings("unchecked")
- public static List filterList(List list, Object... filters) {
- List answer = new ArrayList();
- for (Object o : list) {
- for (Object filter : filters) {
- if (!o.getClass().isInstance(filter)) {
- answer.add(o);
- }
- }
- }
- return answer;
- }
-
public static <T> Set<T> createSetContaining(T... contents) {
Set<T> contentsAsSet = new HashSet<T>();
contentsAsSet.addAll(Arrays.asList(contents));
Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/util/EndpointHelper.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/util/EndpointHelper.java?rev=818745&r1=818744&r2=818745&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/util/EndpointHelper.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/util/EndpointHelper.java Fri Sep 25 07:11:06 2009
@@ -40,6 +40,7 @@
private EndpointHelper() {
//Utility Class
}
+
/**
* Creates a {@link PollingConsumer} and polls all pending messages on the endpoint
* and invokes the given {@link Processor} to process each {@link Exchange} and then closes
Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/util/ExchangeHelper.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/util/ExchangeHelper.java?rev=818745&r1=818744&r2=818745&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/util/ExchangeHelper.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/util/ExchangeHelper.java Fri Sep 25 07:11:06 2009
@@ -52,25 +52,6 @@
}
/**
- * Extracts the exchange property of the given name and type; if it is not present then the
- * default value will be used
- *
- * @param exchange the message exchange
- * @param propertyName the name of the property on the exchange
- * @param type the expected type of the property
- * @param defaultValue the default value to be used if the property name does not exist or could not be
- * converted to the given type
- * @return the property value as the given type or the defaultValue if it could not be found or converted
- */
- public static <T> T getExchangeProperty(Exchange exchange, String propertyName, Class<T> type, T defaultValue) {
- T answer = exchange.getProperty(propertyName, type);
- if (answer == null) {
- return defaultValue;
- }
- return answer;
- }
-
- /**
* Extracts the Exchange.BINDING of the given type or null if not present
*
* @param exchange the message exchange
@@ -92,8 +73,7 @@
* @return the endpoint
* @throws NoSuchEndpointException if the endpoint cannot be resolved
*/
- public static Endpoint resolveEndpoint(Exchange exchange, Object value)
- throws NoSuchEndpointException {
+ public static Endpoint resolveEndpoint(Exchange exchange, Object value) throws NoSuchEndpointException {
Endpoint endpoint;
if (value instanceof Endpoint) {
endpoint = (Endpoint)value;
@@ -282,8 +262,7 @@
* Returns the message where to write results in an
* exchange-pattern-sensitive way.
*
- * @param exchange
- * message exchange.
+ * @param exchange message exchange.
* @return result message.
*/
public static Message getResultMessage(Exchange exchange) {
@@ -295,19 +274,7 @@
}
/**
- * Returns true if the given exchange pattern (if defined) can support IN messagea
- *
- * @param exchange the exchange to interrogate
- * @return true if the exchange is defined as an {@link ExchangePattern} which supports
- * IN messages
- */
- public static boolean isInCapable(Exchange exchange) {
- ExchangePattern pattern = exchange.getPattern();
- return pattern != null && pattern.isInCapable();
- }
-
- /**
- * Returns true if the given exchange pattern (if defined) can support OUT messagea
+ * Returns true if the given exchange pattern (if defined) can support OUT messages
*
* @param exchange the exchange to interrogate
* @return true if the exchange is defined as an {@link ExchangePattern} which supports
@@ -329,7 +296,7 @@
* Creates a Map of the variables which are made available to a script or template
*
* @param exchange the exchange to make available
- * @return a Map populated with the require dvariables
+ * @return a Map populated with the require variables
*/
public static Map createVariableMap(Exchange exchange) {
Map answer = new HashMap();
Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/util/IntrospectionSupport.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/util/IntrospectionSupport.java?rev=818745&r1=818744&r2=818745&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/util/IntrospectionSupport.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/util/IntrospectionSupport.java Fri Sep 25 07:11:06 2009
@@ -339,73 +339,4 @@
return false;
}
- public static String toString(Object target) {
- return toString(target, Object.class);
- }
-
- public static String toString(Object target, Class stopClass) {
- LinkedHashMap map = new LinkedHashMap();
- addFields(target, target.getClass(), stopClass, map);
- StringBuffer buffer = new StringBuffer(simpleName(target.getClass()));
- buffer.append(" {");
- Set entrySet = map.entrySet();
- boolean first = true;
- for (Iterator iter = entrySet.iterator(); iter.hasNext();) {
- Map.Entry entry = (Map.Entry)iter.next();
- if (first) {
- first = false;
- } else {
- buffer.append(", ");
- }
- buffer.append(entry.getKey());
- buffer.append(" = ");
- appendToString(buffer, entry.getValue());
- }
- buffer.append("}");
- return buffer.toString();
- }
-
- protected static void appendToString(StringBuffer buffer, Object value) {
- buffer.append(value);
- }
-
- public static String simpleName(Class clazz) {
- String name = clazz.getName();
- int p = name.lastIndexOf('.');
- if (p >= 0) {
- name = name.substring(p + 1);
- }
- return name;
- }
-
- @SuppressWarnings("unchecked")
- private static void addFields(Object target, Class startClass, Class stopClass, LinkedHashMap map) {
- if (startClass != stopClass) {
- addFields(target, startClass.getSuperclass(), stopClass, map);
- }
-
- Field[] fields = startClass.getDeclaredFields();
- for (Field field : fields) {
- if (Modifier.isStatic(field.getModifiers()) || Modifier.isTransient(field.getModifiers())
- || Modifier.isPrivate(field.getModifiers())) {
- continue;
- }
-
- try {
- field.setAccessible(true);
- Object o = field.get(target);
- if (o != null && o.getClass().isArray()) {
- try {
- o = Arrays.asList((Object[])o);
- } catch (Throwable e) {
- // ignore
- }
- }
- map.put(field.getName(), o);
- } catch (Throwable e) {
- throw ObjectHelper.wrapRuntimeCamelException(e);
- }
- }
- }
-
}
Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/util/ServiceHelper.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/util/ServiceHelper.java?rev=818745&r1=818744&r2=818745&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/util/ServiceHelper.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/util/ServiceHelper.java Fri Sep 25 07:11:06 2009
@@ -17,6 +17,8 @@
package org.apache.camel.util;
import java.util.Collection;
+import java.util.List;
+import java.util.Arrays;
import org.apache.camel.Service;
import org.apache.commons.logging.Log;
@@ -76,26 +78,8 @@
* Stops all of the given services, throwing the first exception caught
*/
public static void stopServices(Object... services) throws Exception {
- Exception firstException = null;
- for (Object value : services) {
- if (value instanceof Service) {
- Service service = (Service)value;
- try {
- if (LOG.isTraceEnabled()) {
- LOG.trace("Stopping service: " + service);
- }
- service.stop();
- } catch (Exception e) {
- LOG.debug("Caught exception shutting down: " + e, e);
- if (firstException == null) {
- firstException = e;
- }
- }
- }
- }
- if (firstException != null) {
- throw firstException;
- }
+ List list = Arrays.asList(services);
+ stopServices(list);
}
public static void stopService(Object value) throws Exception {
Modified: camel/trunk/camel-core/src/test/java/org/apache/camel/impl/DefaultProducerTemplateAsyncTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/impl/DefaultProducerTemplateAsyncTest.java?rev=818745&r1=818744&r2=818745&view=diff
==============================================================================
--- camel/trunk/camel-core/src/test/java/org/apache/camel/impl/DefaultProducerTemplateAsyncTest.java (original)
+++ camel/trunk/camel-core/src/test/java/org/apache/camel/impl/DefaultProducerTemplateAsyncTest.java Fri Sep 25 07:11:06 2009
@@ -277,6 +277,33 @@
assertTrue("Should take longer than: " + delta, delta > 250);
}
+ public void testAsyncProcessWithClassicAPIAndTimeout() throws Exception {
+ Endpoint endpoint = context.getEndpoint("direct:start");
+ Exchange exchange = endpoint.createExchange();
+ exchange.getIn().setBody("Hello");
+
+ long start = System.currentTimeMillis();
+
+ // produce it async so we use a helper
+ Producer producer = endpoint.createProducer();
+ // normally you will use a shared exectutor service with pools
+ ExecutorService executor = Executors.newSingleThreadExecutor();
+ // send it async with the help of this helper
+ Future<Exchange> future = AsyncProcessorHelper.asyncProcess(executor, producer, exchange);
+
+ // you can do other stuff
+ String echo = template.requestBody("direct:echo", "Hi", String.class);
+ assertEquals("HiHi", echo);
+
+ String result = template.extractFutureBody(future, 5, TimeUnit.SECONDS, String.class);
+
+ assertMockEndpointsSatisfied();
+
+ long delta = System.currentTimeMillis() - start;
+ assertEquals("Hello World", result);
+ assertTrue("Should take longer than: " + delta, delta > 250);
+ }
+
public void testAsyncCallbackExchangeInOnly() throws Exception {
order = "";
Modified: camel/trunk/camel-core/src/test/java/org/apache/camel/util/CollectionHelperTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/util/CollectionHelperTest.java?rev=818745&r1=818744&r2=818745&view=diff
==============================================================================
--- camel/trunk/camel-core/src/test/java/org/apache/camel/util/CollectionHelperTest.java (original)
+++ camel/trunk/camel-core/src/test/java/org/apache/camel/util/CollectionHelperTest.java Fri Sep 25 07:11:06 2009
@@ -16,9 +16,13 @@
*/
package org.apache.camel.util;
+import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
+import java.util.Date;
+import java.util.HashMap;
import java.util.List;
+import java.util.Map;
import junit.framework.TestCase;
@@ -40,4 +44,35 @@
assertEquals("Claus", CollectionHelper.collectionAsCommaDelimitedString(new String[]{"Claus"}));
}
-}
\ No newline at end of file
+ public void testSize() {
+ Map map = new HashMap();
+ map.put("foo", 123);
+ map.put("bar", 456);
+
+ assertEquals(2, CollectionHelper.size(map).intValue());
+
+ String[] array = new String[]{"Claus", "Willem"};
+ assertEquals(2, CollectionHelper.size(array).intValue());
+ }
+
+ public void testAppendValue() {
+ Map map = new HashMap();
+ CollectionHelper.appendValue(map, "foo", 123);
+ assertEquals(1, map.size());
+
+ CollectionHelper.appendValue(map, "foo", 456);
+ assertEquals(1, map.size());
+
+ CollectionHelper.appendValue(map, "bar", 789);
+ assertEquals(2, map.size());
+
+ List values = (List) map.get("foo");
+ assertEquals(2, values.size());
+ assertEquals(123, values.get(0));
+ assertEquals(456, values.get(1));
+
+ Integer value = (Integer) map.get("bar");
+ assertEquals(789, value.intValue());
+ }
+
+}
Added: camel/trunk/camel-core/src/test/java/org/apache/camel/util/EndpointHelperTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/util/EndpointHelperTest.java?rev=818745&view=auto
==============================================================================
--- camel/trunk/camel-core/src/test/java/org/apache/camel/util/EndpointHelperTest.java (added)
+++ camel/trunk/camel-core/src/test/java/org/apache/camel/util/EndpointHelperTest.java Fri Sep 25 07:11:06 2009
@@ -0,0 +1,63 @@
+/**
+ * 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.util;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.camel.ContextTestSupport;
+import org.apache.camel.Exchange;
+import org.apache.camel.Processor;
+
+/**
+ * @version $Revision$
+ */
+public class EndpointHelperTest extends ContextTestSupport {
+
+ public void testPollEndpoint() throws Exception {
+ template.sendBody("seda:foo", "Hello World");
+ template.sendBody("seda:foo", "Bye World");
+
+ final List<String> bodies = new ArrayList<String>();
+ EndpointHelper.pollEndpoint(context.getEndpoint("seda:foo"), new Processor() {
+ public void process(Exchange exchange) throws Exception {
+ bodies.add(exchange.getIn().getBody(String.class));
+ }
+ });
+
+ assertEquals(2, bodies.size());
+ assertEquals("Hello World", bodies.get(0));
+ assertEquals("Bye World", bodies.get(1));
+ }
+
+ public void testPollEndpointTimeout() throws Exception {
+ template.sendBody("seda:foo", "Hello World");
+ template.sendBody("seda:foo", "Bye World");
+
+ final List<String> bodies = new ArrayList<String>();
+ EndpointHelper.pollEndpoint(context.getEndpoint("seda:foo"), new Processor() {
+ public void process(Exchange exchange) throws Exception {
+ bodies.add(exchange.getIn().getBody(String.class));
+ }
+ }, 2000);
+
+ assertEquals(2, bodies.size());
+ assertEquals("Hello World", bodies.get(0));
+ assertEquals("Bye World", bodies.get(1));
+ }
+
+}
Propchange: camel/trunk/camel-core/src/test/java/org/apache/camel/util/EndpointHelperTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: camel/trunk/camel-core/src/test/java/org/apache/camel/util/EndpointHelperTest.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Modified: camel/trunk/camel-core/src/test/java/org/apache/camel/util/ExchangeHelperTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/util/ExchangeHelperTest.java?rev=818745&r1=818744&r2=818745&view=diff
==============================================================================
--- camel/trunk/camel-core/src/test/java/org/apache/camel/util/ExchangeHelperTest.java (original)
+++ camel/trunk/camel-core/src/test/java/org/apache/camel/util/ExchangeHelperTest.java Fri Sep 25 07:11:06 2009
@@ -16,10 +16,14 @@
*/
package org.apache.camel.util;
+import java.util.ArrayList;
+import java.util.HashMap;
import java.util.List;
+import java.util.Map;
import org.apache.camel.ContextTestSupport;
import org.apache.camel.Exchange;
+import org.apache.camel.ExchangePattern;
import org.apache.camel.NoSuchBeanException;
import org.apache.camel.NoSuchHeaderException;
import org.apache.camel.NoSuchPropertyException;
@@ -85,6 +89,75 @@
}
}
+ public void testNoSuchBeanType() throws Exception {
+ try {
+ ExchangeHelper.lookupMandatoryBean(exchange, "foo", String.class);
+ fail("Should have thrown an exception");
+ } catch (NoSuchBeanException e) {
+ assertEquals("No bean could be found in the registry for: foo", e.getMessage());
+ assertEquals("foo", e.getName());
+ }
+ }
+
+ public void testGetExchangeById() throws Exception {
+ List<Exchange> list = new ArrayList<Exchange>();
+ Exchange e1 = context.getEndpoint("mock:foo").createExchange();
+ Exchange e2 = context.getEndpoint("mock:foo").createExchange();
+ list.add(e1);
+ list.add(e2);
+
+ assertNull(ExchangeHelper.getExchangeById(list, "unknown"));
+ assertEquals(e1, ExchangeHelper.getExchangeById(list, e1.getExchangeId()));
+ assertEquals(e2, ExchangeHelper.getExchangeById(list, e2.getExchangeId()));
+ }
+
+ public void testPopulateVariableMap() throws Exception {
+ exchange.setPattern(ExchangePattern.InOut);
+ exchange.getOut().setBody("bar");
+ exchange.getOut().setHeader("quote", "Camel rocks");
+
+ Map map = new HashMap();
+ ExchangeHelper.populateVariableMap(exchange, map);
+
+ assertEquals(8, map.size());
+ assertSame(exchange, map.get("exchange"));
+ assertSame(exchange.getIn(), map.get("in"));
+ assertSame(exchange.getIn(), map.get("request"));
+ assertSame(exchange.getOut(), map.get("out"));
+ assertSame(exchange.getOut(), map.get("response"));
+ assertSame(exchange.getIn().getHeaders(), map.get("headers"));
+ assertSame(exchange.getIn().getBody(), map.get("body"));
+ assertSame(exchange.getContext(), map.get("camelContext"));
+ }
+
+ public void testCreateVariableMap() throws Exception {
+ exchange.setPattern(ExchangePattern.InOut);
+ exchange.getOut().setBody("bar");
+ exchange.getOut().setHeader("quote", "Camel rocks");
+
+ Map map = ExchangeHelper.createVariableMap(exchange);
+
+ assertEquals(8, map.size());
+ assertSame(exchange, map.get("exchange"));
+ assertSame(exchange.getIn(), map.get("in"));
+ assertSame(exchange.getIn(), map.get("request"));
+ assertSame(exchange.getOut(), map.get("out"));
+ assertSame(exchange.getOut(), map.get("response"));
+ assertSame(exchange.getIn().getHeaders(), map.get("headers"));
+ assertSame(exchange.getIn().getBody(), map.get("body"));
+ assertSame(exchange.getContext(), map.get("camelContext"));
+ }
+
+ public void testGetContentType() throws Exception {
+ exchange.getIn().setHeader(Exchange.CONTENT_TYPE, "text/xml");
+ assertEquals("text/xml", ExchangeHelper.getContentType(exchange));
+ }
+
+ public void testGetContentEncpding() throws Exception {
+ exchange.getIn().setHeader(Exchange.CONTENT_ENCODING, "iso-8859-1");
+ assertEquals("iso-8859-1", ExchangeHelper.getContentEncoding(exchange));
+ }
+
@Override
protected void setUp() throws Exception {
super.setUp();
Modified: camel/trunk/camel-core/src/test/java/org/apache/camel/util/IntrospectionSupportTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/util/IntrospectionSupportTest.java?rev=818745&r1=818744&r2=818745&view=diff
==============================================================================
--- camel/trunk/camel-core/src/test/java/org/apache/camel/util/IntrospectionSupportTest.java (original)
+++ camel/trunk/camel-core/src/test/java/org/apache/camel/util/IntrospectionSupportTest.java Fri Sep 25 07:11:06 2009
@@ -19,6 +19,7 @@
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
+import java.lang.reflect.Method;
import org.apache.camel.ContextTestSupport;
import org.apache.camel.util.jndi.ExampleBean;
@@ -88,5 +89,51 @@
assertTrue(IntrospectionSupport.hasProperties(param, "foo."));
}
+ public void testGetProperties() throws Exception {
+ ExampleBean bean = new ExampleBean();
+ bean.setName("Claus");
+ bean.setPrice(10.0);
+
+ Map map = new HashMap();
+ IntrospectionSupport.getProperties(bean, map, null);
+ assertEquals(2, map.size());
+
+ assertEquals("Claus", map.get("name"));
+ String price = map.get("price").toString();
+ assertTrue(price.startsWith("10"));
+ }
+
+ public void testGetPropertiesOptionPrefix() throws Exception {
+ ExampleBean bean = new ExampleBean();
+ bean.setName("Claus");
+ bean.setPrice(10.0);
+
+ Map map = new HashMap();
+ IntrospectionSupport.getProperties(bean, map, "bean.");
+ assertEquals(2, map.size());
+
+ assertEquals("Claus", map.get("bean.name"));
+ String price = map.get("bean.price").toString();
+ assertTrue(price.startsWith("10"));
+ }
+
+ public void testGetProperty() throws Exception {
+ ExampleBean bean = new ExampleBean();
+ bean.setName("Claus");
+ bean.setPrice(10.0);
+
+ Object name = IntrospectionSupport.getProperty(bean, "name");
+ assertEquals("Claus", name);
+ }
+
+ public void testGetPropertyGetter() throws Exception {
+ ExampleBean bean = new ExampleBean();
+ bean.setName("Claus");
+ bean.setPrice(10.0);
+
+ Method name = IntrospectionSupport.getPropertyGetter(ExampleBean.class, "name");
+ assertEquals("getName", name.getName());
+ }
+
}
Modified: camel/trunk/camel-core/src/test/java/org/apache/camel/util/KeyValueHolderTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/util/KeyValueHolderTest.java?rev=818745&r1=818744&r2=818745&view=diff
==============================================================================
--- camel/trunk/camel-core/src/test/java/org/apache/camel/util/KeyValueHolderTest.java (original)
+++ camel/trunk/camel-core/src/test/java/org/apache/camel/util/KeyValueHolderTest.java Fri Sep 25 07:11:06 2009
@@ -34,6 +34,8 @@
assertFalse("Should not be equals", foo.equals(bar));
+ assertNotSame(foo.hashCode(), bar.hashCode());
+
KeyValueHolder bar2 = new KeyValueHolder("bar", 456);
assertTrue("Should be equals", bar.equals(bar2));
Modified: camel/trunk/camel-core/src/test/java/org/apache/camel/util/MessageHelperTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/util/MessageHelperTest.java?rev=818745&r1=818744&r2=818745&view=diff
==============================================================================
--- camel/trunk/camel-core/src/test/java/org/apache/camel/util/MessageHelperTest.java (original)
+++ camel/trunk/camel-core/src/test/java/org/apache/camel/util/MessageHelperTest.java Fri Sep 25 07:11:06 2009
@@ -22,6 +22,7 @@
import junit.framework.TestCase;
import org.apache.camel.Message;
import org.apache.camel.StreamCache;
+import org.apache.camel.Exchange;
import org.apache.camel.impl.DefaultMessage;
/**
@@ -58,4 +59,15 @@
MessageHelper.resetStreamCache(message);
assertTrue("Should have reset the stream cache", reset.get());
}
+
+ public void testGetContentType() throws Exception {
+ message.setHeader(Exchange.CONTENT_TYPE, "text/xml");
+ assertEquals("text/xml", MessageHelper.getContentType(message));
+ }
+
+ public void testGetContentEncpding() throws Exception {
+ message.setHeader(Exchange.CONTENT_ENCODING, "iso-8859-1");
+ assertEquals("iso-8859-1", MessageHelper.getContentEncoding(message));
+ }
+
}
Modified: camel/trunk/camel-core/src/test/java/org/apache/camel/util/UuidGeneratorTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/util/UuidGeneratorTest.java?rev=818745&r1=818744&r2=818745&view=diff
==============================================================================
--- camel/trunk/camel-core/src/test/java/org/apache/camel/util/UuidGeneratorTest.java (original)
+++ camel/trunk/camel-core/src/test/java/org/apache/camel/util/UuidGeneratorTest.java Fri Sep 25 07:11:06 2009
@@ -33,6 +33,10 @@
assertNotSame("Should generate unique ids", generator.generateId(), generator.generateId());
}
+ public void testHostName() {
+ assertNotNull(UuidGenerator.getHostName());
+ }
+
public void testSimpleSanitizedId() {
String out = UuidGenerator.generateSanitizedId("hello");
assertTrue("Should not contain : ", out.indexOf(':') == -1);
@@ -45,4 +49,10 @@
assertTrue("Should not contain . ", out.indexOf('.') == -1);
}
+ public void testSanitizedId() {
+ String out = generator.generateSanitizedId();
+ assertTrue("Should not contain : ", out.indexOf(':') == -1);
+ assertTrue("Should not contain . ", out.indexOf('.') == -1);
+ }
+
}