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 2010/09/20 08:24:50 UTC

svn commit: r998794 - in /camel/trunk/tests/camel-itest-osgi: ./ src/test/java/org/apache/camel/itest/osgi/jasypt/ src/test/resources/org/apache/camel/itest/osgi/jasypt/

Author: davsclaus
Date: Mon Sep 20 06:24:50 2010
New Revision: 998794

URL: http://svn.apache.org/viewvc?rev=998794&view=rev
Log:
CAMEL-3126: Added jasypt osgi test.

Added:
    camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/jasypt/
    camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/jasypt/JasyptTest.java
      - copied, changed from r998780, camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/freemarker/FreemarkerTest.java
    camel/trunk/tests/camel-itest-osgi/src/test/resources/org/apache/camel/itest/osgi/jasypt/
    camel/trunk/tests/camel-itest-osgi/src/test/resources/org/apache/camel/itest/osgi/jasypt/myproperties.properties
Modified:
    camel/trunk/tests/camel-itest-osgi/pom.xml

Modified: camel/trunk/tests/camel-itest-osgi/pom.xml
URL: http://svn.apache.org/viewvc/camel/trunk/tests/camel-itest-osgi/pom.xml?rev=998794&r1=998793&r2=998794&view=diff
==============================================================================
--- camel/trunk/tests/camel-itest-osgi/pom.xml (original)
+++ camel/trunk/tests/camel-itest-osgi/pom.xml Mon Sep 20 06:24:50 2010
@@ -91,6 +91,11 @@
     </dependency>
     <dependency>
       <groupId>org.apache.camel</groupId>
+      <artifactId>camel-jasypt</artifactId>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.camel</groupId>
       <artifactId>camel-jpa</artifactId>
       <scope>test</scope>
     </dependency>
@@ -117,7 +122,7 @@
 	<dependency>
 	  <groupId>org.apache.camel.tests</groupId>
 	  <artifactId>org.apache.camel.tests.mock-javamail_1.7</artifactId>
-          <version>2.4.0</version>
+      <version>2.4.0</version>
 	  <scope>test</scope>
     </dependency>
 	<dependency>
@@ -254,7 +259,7 @@
                             <include>**/*Test.*</include>
                         </includes>
                         <excludes>
-			    <!-- TODO: temporary disable unit test to let TC not hang -->
+			            <!-- TODO: temporary disable unit test to let TC not hang -->
 	                    <exclude>**/*Test.*</exclude>
                             <!--There are some conflicts of the JAXB OSGi bundle and Hudson System jar
                                 so I comment out these JAXB related tests -->

Copied: camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/jasypt/JasyptTest.java (from r998780, camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/freemarker/FreemarkerTest.java)
URL: http://svn.apache.org/viewvc/camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/jasypt/JasyptTest.java?p2=camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/jasypt/JasyptTest.java&p1=camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/freemarker/FreemarkerTest.java&r1=998780&r2=998794&rev=998794&view=diff
==============================================================================
--- camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/freemarker/FreemarkerTest.java (original)
+++ camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/jasypt/JasyptTest.java Mon Sep 20 06:24:50 2010
@@ -14,13 +14,11 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package org.apache.camel.itest.osgi.freemarker;
+package org.apache.camel.itest.osgi.jasypt;
 
-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.jasypt.JasyptPropertiesParser;
+import org.apache.camel.component.properties.PropertiesComponent;
 import org.apache.camel.itest.osgi.OSGiIntegrationTestSupport;
 import org.junit.Test;
 import org.junit.runner.RunWith;
@@ -36,29 +34,35 @@ import static org.ops4j.pax.exam.contain
 import static org.ops4j.pax.exam.container.def.PaxRunnerOptions.workingDirectory;
 
 @RunWith(JUnit4TestRunner.class)
-public class FreemarkerTest extends OSGiIntegrationTestSupport {
+public class JasyptTest extends OSGiIntegrationTestSupport {
     
     @Test
-    public void testReceivesResponse() throws Exception {        
-        assertRespondsWith("foo", "<hello>foo</hello>");
-        assertRespondsWith("bar", "<hello>bar</hello>");
-    }
+    public void testJasyptProperties() throws Exception {
+        getMockEndpoint("mock:tiger").expectedBodiesReceived("Hello World");
 
-    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);
+        template.sendBody("direct:start", "Hello World");
+
+        assertMockEndpointsSatisfied();
     }
 
     protected RouteBuilder createRouteBuilder() {
+        // create the jasypt properties parser
+        JasyptPropertiesParser jasypt = new JasyptPropertiesParser();
+        // and set the master password
+        jasypt.setPassword("secret");
+
+        // create the properties component
+        PropertiesComponent pc = new PropertiesComponent();
+        pc.setLocation("classpath:org/apache/camel/itest/osgi/jasypt/myproperties.properties");
+        // and use the jasypt properties parser so we can decrypt values
+        pc.setPropertiesParser(jasypt);
+
+        // add properties component to camel context
+        context.addComponent("properties", pc);
+
         return new RouteBuilder() {
             public void configure() {
-                from("direct:a").to("freemarker:org/apache/camel/itest/osgi/freemarker/example.ftl");
+                from("direct:start").to("{{cool.result}}");
             }
         };
     }
@@ -73,7 +77,7 @@ public class FreemarkerTest extends OSGi
             
             // using the features to install the camel components             
             scanFeatures(getCamelKarafFeatureUrl(),                         
-                          "camel-core", "camel-spring", "camel-test", "camel-freemarker"),
+                          "camel-core", "camel-test", "camel-jasypt"),
             
             workingDirectory("target/paxrunner/"),
 

Added: camel/trunk/tests/camel-itest-osgi/src/test/resources/org/apache/camel/itest/osgi/jasypt/myproperties.properties
URL: http://svn.apache.org/viewvc/camel/trunk/tests/camel-itest-osgi/src/test/resources/org/apache/camel/itest/osgi/jasypt/myproperties.properties?rev=998794&view=auto
==============================================================================
--- camel/trunk/tests/camel-itest-osgi/src/test/resources/org/apache/camel/itest/osgi/jasypt/myproperties.properties (added)
+++ camel/trunk/tests/camel-itest-osgi/src/test/resources/org/apache/camel/itest/osgi/jasypt/myproperties.properties Mon Sep 20 06:24:50 2010
@@ -0,0 +1,22 @@
+## ---------------------------------------------------------------------------
+## 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.
+## ---------------------------------------------------------------------------
+
+# refer to a mock endpoint name by that encrypted password
+cool.result=mock:{{cool.password}}
+
+# here is a password which is encrypted
+cool.password=ENC(bsW9uV37gQ0QHFu7KO03Ww==)