Author: davsclaus
Date: Mon Sep 28 10:11:28 2009
New Revision: 819489

URL: http://svn.apache.org/viewvc?rev=819489&view=rev
Log:
MR-187: Added more unit tests.

Added:
    
camel/trunk/camel-core/src/test/java/org/apache/camel/util/CamelContextHelperTest.java
   (with props)
    
camel/trunk/camel-core/src/test/java/org/apache/camel/util/IOHelperTest.java   
(with props)
    
camel/trunk/camel-core/src/test/resources/org/apache/camel/model/routeWithCastorDataFormat.xml
      - copied, changed from r819470, 
camel/trunk/camel-core/src/test/resources/org/apache/camel/model/routeWithArtixDSDataFormat.xml
Modified:
    camel/trunk/camel-core/src/main/java/org/apache/camel/util/ObjectHelper.java
    
camel/trunk/camel-core/src/test/java/org/apache/camel/language/TokenizerTest.java
    
camel/trunk/camel-core/src/test/java/org/apache/camel/model/XmlParseTest.java
    
camel/trunk/camel-core/src/test/java/org/apache/camel/util/ObjectHelperTest.java
    
camel/trunk/camel-core/src/test/resources/org/apache/camel/model/routeWithCvsDataFormat.xml
    
camel/trunk/camel-core/src/test/resources/org/apache/camel/model/routeWithTidyMarkupDataFormat.xml
    
camel/trunk/camel-core/src/test/resources/org/apache/camel/model/routeWithXMLSecurityDataFormat.xml

Modified: 
camel/trunk/camel-core/src/main/java/org/apache/camel/util/ObjectHelper.java
URL: 
http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/util/ObjectHelper.java?rev=819489&r1=819488&r2=819489&view=diff
==============================================================================
--- 
camel/trunk/camel-core/src/main/java/org/apache/camel/util/ObjectHelper.java 
(original)
+++ 
camel/trunk/camel-core/src/main/java/org/apache/camel/util/ObjectHelper.java 
Mon Sep 28 10:11:28 2009
@@ -861,10 +861,8 @@
                 rc = Short.class;
             } else if (type == byte.class) {
                 rc = Byte.class;
-                // TODO: Why is boolean disabled
-                /*
-                 * } else if (type == boolean.class) { rc = Boolean.class;
-                 */
+            } else if (type == boolean.class) {
+                rc = Boolean.class;
             }
         }
         return rc;

Modified: 
camel/trunk/camel-core/src/test/java/org/apache/camel/language/TokenizerTest.java
URL: 
http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/language/TokenizerTest.java?rev=819489&r1=819488&r2=819489&view=diff
==============================================================================
--- 
camel/trunk/camel-core/src/test/java/org/apache/camel/language/TokenizerTest.java
 (original)
+++ 
camel/trunk/camel-core/src/test/java/org/apache/camel/language/TokenizerTest.java
 Mon Sep 28 10:11:28 2009
@@ -79,4 +79,24 @@
         assertEquals("rocks", names.get(1));
     }
 
+    public void testTokenizeManualConfiguration() throws Exception {
+        TokenizeLanguage lan = new TokenizeLanguage();
+        lan.setHeaderName("names");
+        lan.setRegex(false);
+        lan.setToken(",");
+        Expression exp = lan.createExpression();
+
+        List names = exp.evaluate(exchange, List.class);
+        assertEquals(3, names.size());
+
+        assertEquals("Claus", names.get(0));
+        assertEquals("James", names.get(1));
+        assertEquals("Willem", names.get(2));
+
+        assertEquals("names", lan.getHeaderName());
+        assertEquals(",", lan.getToken());
+        assertEquals(false, lan.isRegex());
+        assertEquals(false, lan.isSingleton());
+    }
+
 }
\ No newline at end of file

Modified: 
camel/trunk/camel-core/src/test/java/org/apache/camel/model/XmlParseTest.java
URL: 
http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/model/XmlParseTest.java?rev=819489&r1=819488&r2=819489&view=diff
==============================================================================
--- 
camel/trunk/camel-core/src/test/java/org/apache/camel/model/XmlParseTest.java 
(original)
+++ 
camel/trunk/camel-core/src/test/java/org/apache/camel/model/XmlParseTest.java 
Mon Sep 28 10:11:28 2009
@@ -272,7 +272,7 @@
     }
 
     public void testParseJaxbDataFormat() throws Exception {
-        RouteDefinition route = assertOneRoute("routeWithJSonDataFormat.xml");
+        RouteDefinition route = assertOneRoute("routeWithJaxbDataFormat.xml");
         assertFrom(route, "seda:a");
     }
 
@@ -296,6 +296,12 @@
         assertFrom(route, "seda:a");
     }
 
+    public void testParseCastorDataFormat() throws Exception {
+        RouteDefinition route = 
assertOneRoute("routeWithCastorDataFormat.xml");
+        assertFrom(route, "seda:a");
+    }
+
+
     public void testParseBatchResequencerXml() throws Exception {
         RouteDefinition route = assertOneRoute("resequencerBatch.xml");
         ResequenceDefinition resequencer = 
assertOneProcessorInstanceOf(ResequenceDefinition.class, route);

Added: 
camel/trunk/camel-core/src/test/java/org/apache/camel/util/CamelContextHelperTest.java
URL: 
http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/util/CamelContextHelperTest.java?rev=819489&view=auto
==============================================================================
--- 
camel/trunk/camel-core/src/test/java/org/apache/camel/util/CamelContextHelperTest.java
 (added)
+++ 
camel/trunk/camel-core/src/test/java/org/apache/camel/util/CamelContextHelperTest.java
 Mon Sep 28 10:11:28 2009
@@ -0,0 +1,69 @@
+/**
+ * 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 org.apache.camel.CamelContext;
+import org.apache.camel.ContextTestSupport;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.impl.JndiRegistry;
+
+/**
+ * @version $Revision$
+ */
+public class CamelContextHelperTest extends ContextTestSupport {
+
+    @Override
+    protected JndiRegistry createRegistry() throws Exception {
+        JndiRegistry jndi = super.createRegistry();
+        jndi.bind("foo", new MyFooBean());
+        return jndi;
+    }
+
+    public void testGetMandatoryEndpoint() {
+        MockEndpoint mock = CamelContextHelper.getMandatoryEndpoint(context, 
"mock:foo", MockEndpoint.class);
+        assertNotNull(mock);
+    }
+
+    public void testMandatoryConvertTo() {
+        Integer num = CamelContextHelper.mandatoryConvertTo(context, 
Integer.class, "5");
+        assertEquals(5, num.intValue());
+    }
+
+    public void testMandatoryConvertToNotPossible() {
+        try {
+            CamelContextHelper.mandatoryConvertTo(context, CamelContext.class, 
"5");
+            fail("Should have thrown an exception");
+        } catch (IllegalArgumentException e) {
+            // expected
+        }
+    }
+
+    public void testLookupBean() {
+        Object foo = CamelContextHelper.lookup(context, "foo");
+        assertNotNull(foo);
+        assertIsInstanceOf(MyFooBean.class, foo);
+    }
+
+    public void testLookupBeanAndType() {
+        MyFooBean foo = CamelContextHelper.lookup(context, "foo", 
MyFooBean.class);
+        assertNotNull(foo);
+    }
+
+    public static class MyFooBean {
+
+    }
+}

Propchange: 
camel/trunk/camel-core/src/test/java/org/apache/camel/util/CamelContextHelperTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
camel/trunk/camel-core/src/test/java/org/apache/camel/util/CamelContextHelperTest.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: 
camel/trunk/camel-core/src/test/java/org/apache/camel/util/IOHelperTest.java
URL: 
http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/util/IOHelperTest.java?rev=819489&view=auto
==============================================================================
--- 
camel/trunk/camel-core/src/test/java/org/apache/camel/util/IOHelperTest.java 
(added)
+++ 
camel/trunk/camel-core/src/test/java/org/apache/camel/util/IOHelperTest.java 
Mon Sep 28 10:11:28 2009
@@ -0,0 +1,59 @@
+/**
+ * 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.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+
+import junit.framework.TestCase;
+
+/**
+ * @version $Revision$
+ */
+public class IOHelperTest extends TestCase {
+
+    public void testIOException() {
+        IOException io = IOHelper.createIOException(new 
IllegalArgumentException("Damn"));
+        assertEquals("Damn", io.getMessage());
+        assertTrue(io.getCause() instanceof IllegalArgumentException);
+    }
+
+    public void testIOExceptionWithMessage() {
+        IOException io = IOHelper.createIOException("Not again", new 
IllegalArgumentException("Damn"));
+        assertEquals("Not again", io.getMessage());
+        assertTrue(io.getCause() instanceof IllegalArgumentException);
+    }
+
+    public void testNewStringFromBytes() {
+        String s = IOHelper.newStringFromBytes("Hello".getBytes());
+        assertEquals("Hello", s);
+    }
+
+    public void testNewStringFromBytesWithStart() {
+        String s = IOHelper.newStringFromBytes("Hello".getBytes(), 2, 3);
+        assertEquals("llo", s);
+    }
+
+    public void testCopyAndCloseInput() throws Exception {
+        InputStream is = new ByteArrayInputStream("Hello".getBytes());
+        OutputStream os = new ByteArrayOutputStream();
+        IOHelper.copyAndCloseInput(is, os, 256);
+    }
+}

Propchange: 
camel/trunk/camel-core/src/test/java/org/apache/camel/util/IOHelperTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
camel/trunk/camel-core/src/test/java/org/apache/camel/util/IOHelperTest.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Modified: 
camel/trunk/camel-core/src/test/java/org/apache/camel/util/ObjectHelperTest.java
URL: 
http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/util/ObjectHelperTest.java?rev=819489&r1=819488&r2=819489&view=diff
==============================================================================
--- 
camel/trunk/camel-core/src/test/java/org/apache/camel/util/ObjectHelperTest.java
 (original)
+++ 
camel/trunk/camel-core/src/test/java/org/apache/camel/util/ObjectHelperTest.java
 Mon Sep 28 10:11:28 2009
@@ -22,6 +22,7 @@
 import java.util.Collection;
 import java.util.Iterator;
 import java.util.List;
+import java.util.Date;
 
 import junit.framework.TestCase;
 
@@ -168,4 +169,75 @@
         assertEquals(null, ObjectHelper.between("Hello ${foo bar} how are 
you", "'", "'"));
     }
 
+    public void testIsJavaIdentifier() {
+        assertEquals(true, ObjectHelper.isJavaIdentifier("foo"));
+        assertEquals(false, ObjectHelper.isJavaIdentifier("foo.bar"));
+        assertEquals(false, ObjectHelper.isJavaIdentifier(""));
+        assertEquals(false, ObjectHelper.isJavaIdentifier(null));
+    }
+
+    public void testGetDefaultCharSet() {
+        assertNotNull(ObjectHelper.getDefaultCharacterSet());
+    }
+
+    public void testConvertPrimitiveTypeToWrapper() {
+        assertEquals("java.lang.Integer", 
ObjectHelper.convertPrimitiveTypeToWrapperType(int.class).getName());
+        assertEquals("java.lang.Long", 
ObjectHelper.convertPrimitiveTypeToWrapperType(long.class).getName());
+        assertEquals("java.lang.Double", 
ObjectHelper.convertPrimitiveTypeToWrapperType(double.class).getName());
+        assertEquals("java.lang.Float", 
ObjectHelper.convertPrimitiveTypeToWrapperType(float.class).getName());
+        assertEquals("java.lang.Short", 
ObjectHelper.convertPrimitiveTypeToWrapperType(short.class).getName());
+        assertEquals("java.lang.Byte", 
ObjectHelper.convertPrimitiveTypeToWrapperType(byte.class).getName());
+        assertEquals("java.lang.Boolean", 
ObjectHelper.convertPrimitiveTypeToWrapperType(boolean.class).getName());
+        // non primitive just fall through
+        assertEquals("java.lang.Object", 
ObjectHelper.convertPrimitiveTypeToWrapperType(Object.class).getName());
+    }
+
+    public void testAsString() {
+        String[] args = new String[] { "foo", "bar"};
+        String out = ObjectHelper.asString(args);
+        assertNotNull(out);
+        assertEquals("{foo, bar}", out);
+    }
+
+    public void testName() {
+        assertEquals("java.lang.Integer", ObjectHelper.name(Integer.class));
+        assertEquals(null, ObjectHelper.name(null));
+    }
+
+    public void testClassName() {
+        assertEquals("java.lang.Integer", 
ObjectHelper.className(Integer.valueOf("5")));
+        assertEquals(null, ObjectHelper.className(null));
+    }
+
+    public void testGetSystemPropertyDefault() {
+        assertEquals("foo", 
ObjectHelper.getSystemProperty("CamelFooDoesNotExist", "foo"));
+    }
+
+    public void testGetSystemPropertyBooleanDefault() {
+        assertEquals(true, 
ObjectHelper.getSystemProperty("CamelFooDoesNotExist", Boolean.TRUE));
+    }
+
+    public void testMatches() {
+        List data = new ArrayList();
+        data.add("foo");
+        data.add("bar");
+        assertEquals(true, ObjectHelper.matches(data));
+
+        data.clear();
+        data.add(Boolean.FALSE);
+        data.add("bar");
+        assertEquals(false, ObjectHelper.matches(data));
+
+        data.clear();
+        assertEquals(false, ObjectHelper.matches(data));
+    }
+
+    public void testToBoolean() {
+        assertEquals(Boolean.TRUE, ObjectHelper.toBoolean(Boolean.TRUE));
+        assertEquals(Boolean.TRUE, ObjectHelper.toBoolean("true"));
+        assertEquals(Boolean.TRUE, 
ObjectHelper.toBoolean(Integer.valueOf("1")));
+        assertEquals(Boolean.FALSE, 
ObjectHelper.toBoolean(Integer.valueOf("0")));
+        assertEquals(null, ObjectHelper.toBoolean(new Date()));
+    }
+
 }

Copied: 
camel/trunk/camel-core/src/test/resources/org/apache/camel/model/routeWithCastorDataFormat.xml
 (from r819470, 
camel/trunk/camel-core/src/test/resources/org/apache/camel/model/routeWithArtixDSDataFormat.xml)
URL: 
http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/resources/org/apache/camel/model/routeWithCastorDataFormat.xml?p2=camel/trunk/camel-core/src/test/resources/org/apache/camel/model/routeWithCastorDataFormat.xml&p1=camel/trunk/camel-core/src/test/resources/org/apache/camel/model/routeWithArtixDSDataFormat.xml&r1=819470&r2=819489&rev=819489&view=diff
==============================================================================
--- 
camel/trunk/camel-core/src/test/resources/org/apache/camel/model/routeWithArtixDSDataFormat.xml
 (original)
+++ 
camel/trunk/camel-core/src/test/resources/org/apache/camel/model/routeWithCastorDataFormat.xml
 Mon Sep 28 10:11:28 2009
@@ -20,7 +20,7 @@
         <from uri="seda:a"/>
         <pipeline>
             <marshal>
-                <artixDS/>
+                <castor/>
             </marshal>
             <to uri="seda:b"/>
         </pipeline>

Modified: 
camel/trunk/camel-core/src/test/resources/org/apache/camel/model/routeWithCvsDataFormat.xml
URL: 
http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/resources/org/apache/camel/model/routeWithCvsDataFormat.xml?rev=819489&r1=819488&r2=819489&view=diff
==============================================================================
--- 
camel/trunk/camel-core/src/test/resources/org/apache/camel/model/routeWithCvsDataFormat.xml
 (original)
+++ 
camel/trunk/camel-core/src/test/resources/org/apache/camel/model/routeWithCvsDataFormat.xml
 Mon Sep 28 10:11:28 2009
@@ -20,7 +20,7 @@
         <from uri="seda:a"/>
         <pipeline>
             <marshal>
-                <cvs/>
+                <csv/>
             </marshal>
             <to uri="seda:b"/>
         </pipeline>

Modified: 
camel/trunk/camel-core/src/test/resources/org/apache/camel/model/routeWithTidyMarkupDataFormat.xml
URL: 
http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/resources/org/apache/camel/model/routeWithTidyMarkupDataFormat.xml?rev=819489&r1=819488&r2=819489&view=diff
==============================================================================
--- 
camel/trunk/camel-core/src/test/resources/org/apache/camel/model/routeWithTidyMarkupDataFormat.xml
 (original)
+++ 
camel/trunk/camel-core/src/test/resources/org/apache/camel/model/routeWithTidyMarkupDataFormat.xml
 Mon Sep 28 10:11:28 2009
@@ -19,9 +19,9 @@
     <route>
         <from uri="seda:a"/>
         <pipeline>
-            <marshal>
+            <unmarshal>
                 <tidyMarkup/>
-            </marshal>
+            </unmarshal>
             <to uri="seda:b"/>
         </pipeline>
     </route>

Modified: 
camel/trunk/camel-core/src/test/resources/org/apache/camel/model/routeWithXMLSecurityDataFormat.xml
URL: 
http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/resources/org/apache/camel/model/routeWithXMLSecurityDataFormat.xml?rev=819489&r1=819488&r2=819489&view=diff
==============================================================================
--- 
camel/trunk/camel-core/src/test/resources/org/apache/camel/model/routeWithXMLSecurityDataFormat.xml
 (original)
+++ 
camel/trunk/camel-core/src/test/resources/org/apache/camel/model/routeWithXMLSecurityDataFormat.xml
 Mon Sep 28 10:11:28 2009
@@ -20,7 +20,7 @@
         <from uri="seda:a"/>
         <pipeline>
             <marshal>
-                <xmlSecurity/>
+                <secureXML/>
             </marshal>
             <to uri="seda:b"/>
         </pipeline>


Reply via email to