Author: davsclaus
Date: Sun Jul 13 01:52:56 2008
New Revision: 676282

URL: http://svn.apache.org/viewvc?rev=676282&view=rev
Log:
Added unit test with a domain object

Added:
    
activemq/camel/trunk/components/camel-velocity/src/test/java/org/apache/camel/component/velocity/VelocityBodyAsDomainObjectTest.java
   (contents, props changed)
      - copied, changed from r676219, 
activemq/camel/trunk/components/camel-velocity/src/test/java/org/apache/camel/component/velocity/VelocityTest.java
    
activemq/camel/trunk/components/camel-velocity/src/test/resources/org/apache/camel/component/velocity/BodyAsDomainObject.vm
   (contents, props changed)
      - copied, changed from r676219, 
activemq/camel/trunk/components/camel-velocity/src/test/resources/org/apache/camel/component/velocity/example.vm
Modified:
    
activemq/camel/trunk/components/camel-velocity/src/test/resources/log4j.properties

Copied: 
activemq/camel/trunk/components/camel-velocity/src/test/java/org/apache/camel/component/velocity/VelocityBodyAsDomainObjectTest.java
 (from r676219, 
activemq/camel/trunk/components/camel-velocity/src/test/java/org/apache/camel/component/velocity/VelocityTest.java)
URL: 
http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-velocity/src/test/java/org/apache/camel/component/velocity/VelocityBodyAsDomainObjectTest.java?p2=activemq/camel/trunk/components/camel-velocity/src/test/java/org/apache/camel/component/velocity/VelocityBodyAsDomainObjectTest.java&p1=activemq/camel/trunk/components/camel-velocity/src/test/java/org/apache/camel/component/velocity/VelocityTest.java&r1=676219&r2=676282&rev=676282&view=diff
==============================================================================
--- 
activemq/camel/trunk/components/camel-velocity/src/test/java/org/apache/camel/component/velocity/VelocityTest.java
 (original)
+++ 
activemq/camel/trunk/components/camel-velocity/src/test/java/org/apache/camel/component/velocity/VelocityBodyAsDomainObjectTest.java
 Sun Jul 13 01:52:56 2008
@@ -17,43 +17,67 @@
 package org.apache.camel.component.velocity;
 
 import org.apache.camel.ContextTestSupport;
-import org.apache.camel.Exchange;
-import org.apache.camel.InvalidPayloadException;
-import org.apache.camel.Message;
-import org.apache.camel.Processor;
 import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
 
 /**
+ * Unit test with the body as a Domain object.
+ *
  * @version $Revision$
  */
-public class VelocityTest extends ContextTestSupport {
-    public void testReceivesFooResponse() throws Exception {
-        assertRespondsWith("foo", "<hello>foo</hello>");
-    }
+public class VelocityBodyAsDomainObjectTest extends ContextTestSupport {
 
-    public void testReceivesBarResponse() throws Exception {
-        assertRespondsWith("bar", "<hello>bar</hello>");
-    }
+    public void testWithObject() throws Exception {
+        MockEndpoint mock = getMockEndpoint("mock:result");
+        mock.expectedMessageCount(1);
+        mock.expectedBodiesReceived("Hi Claus how are you? Its a nice day.\n"
+            + "Give my regards to the family Ibsen.");
 
-    protected void assertRespondsWith(final String value, String expectedBody) 
throws InvalidPayloadException {
-        Exchange response = template.request("direct:a", new Processor() {
-            public void process(Exchange exchange) throws Exception {
-                Message in = exchange.getIn();
-                in.setBody("answer");
-                in.setHeader("cheese", value);
-            }
-        });
-        assertOutMessageBodyEquals(response, expectedBody);
+        MyPerson person = new MyPerson();
+        person.setFamilyName("Ibsen");
+        person.setGivenName("Claus");
+
+        template.requestBody("direct:in", person);
+
+        mock.assertIsSatisfied();
     }
 
     protected RouteBuilder createRouteBuilder() {
         return new RouteBuilder() {
             public void configure() {
-                // START SNIPPET: example
-                from("direct:a").
-                        
to("velocity:org/apache/camel/component/velocity/example.vm");
-                // END SNIPPET: example
+                from("direct:in")
+                    
.to("velocity:org/apache/camel/component/velocity/BodyAsDomainObject.vm")
+                    .to("mock:result");
             }
         };
     }
+
+    public static class MyPerson {
+        private String givenName;
+        private String familyName;
+
+        public String getGivenName() {
+            return givenName;
+        }
+
+        public void setGivenName(String givenName) {
+            this.givenName = givenName;
+        }
+
+        public String getFamilyName() {
+            return familyName;
+        }
+
+        public void setFamilyName(String familyName) {
+            this.familyName = familyName;
+        }
+
+        public String toString() {
+            return "MyPerson{" +
+                "givenName='" + givenName + '\'' +
+                ", familyName='" + familyName + '\'' +
+                '}';
+        }
+    }
+
 }
\ No newline at end of file

Propchange: 
activemq/camel/trunk/components/camel-velocity/src/test/java/org/apache/camel/component/velocity/VelocityBodyAsDomainObjectTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
activemq/camel/trunk/components/camel-velocity/src/test/java/org/apache/camel/component/velocity/VelocityBodyAsDomainObjectTest.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Modified: 
activemq/camel/trunk/components/camel-velocity/src/test/resources/log4j.properties
URL: 
http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-velocity/src/test/resources/log4j.properties?rev=676282&r1=676281&r2=676282&view=diff
==============================================================================
--- 
activemq/camel/trunk/components/camel-velocity/src/test/resources/log4j.properties
 (original)
+++ 
activemq/camel/trunk/components/camel-velocity/src/test/resources/log4j.properties
 Sun Jul 13 01:52:56 2008
@@ -32,5 +32,5 @@
 log4j.appender.out=org.apache.log4j.FileAppender
 log4j.appender.out.layout=org.apache.log4j.PatternLayout
 log4j.appender.out.layout.ConversionPattern=%d [%-15.15t] %-5p %-30.30c{1} - 
%m%n
-log4j.appender.out.file=target/camel-test.log
+log4j.appender.out.file=target/camel-velocity-test.log
 log4j.appender.out.append=true

Copied: 
activemq/camel/trunk/components/camel-velocity/src/test/resources/org/apache/camel/component/velocity/BodyAsDomainObject.vm
 (from r676219, 
activemq/camel/trunk/components/camel-velocity/src/test/resources/org/apache/camel/component/velocity/example.vm)
URL: 
http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-velocity/src/test/resources/org/apache/camel/component/velocity/BodyAsDomainObject.vm?p2=activemq/camel/trunk/components/camel-velocity/src/test/resources/org/apache/camel/component/velocity/BodyAsDomainObject.vm&p1=activemq/camel/trunk/components/camel-velocity/src/test/resources/org/apache/camel/component/velocity/example.vm&r1=676219&r2=676282&rev=676282&view=diff
==============================================================================
--- 
activemq/camel/trunk/components/camel-velocity/src/test/resources/org/apache/camel/component/velocity/example.vm
 (original)
+++ 
activemq/camel/trunk/components/camel-velocity/src/test/resources/org/apache/camel/component/velocity/BodyAsDomainObject.vm
 Sun Jul 13 01:52:56 2008
@@ -14,4 +14,5 @@
 ## See the License for the specific language governing permissions and
 ## limitations under the License.
 ## ------------------------------------------------------------------------
-<hello>${headers.cheese}</hello>
\ No newline at end of file
+Hi $body.givenName how are you? Its a nice day.
+Give my regards to the family $body.familyName.
\ No newline at end of file

Propchange: 
activemq/camel/trunk/components/camel-velocity/src/test/resources/org/apache/camel/component/velocity/BodyAsDomainObject.vm
------------------------------------------------------------------------------
    svn:eol-style = native


Reply via email to