camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ningji...@apache.org
Subject svn commit: r802307 - in /camel/trunk/examples/camel-example-loan-broker: ./ src/main/java/org/apache/camel/loanbroker/queue/version/ src/test/ src/test/java/ src/test/java/org/ src/test/java/org/apache/ src/test/java/org/apache/camel/ src/test/java/or...
Date Sat, 08 Aug 2009 07:01:19 GMT
Author: ningjiang
Date: Sat Aug  8 07:01:19 2009
New Revision: 802307

URL: http://svn.apache.org/viewvc?rev=802307&view=rev
Log:
CAMEL-1890 Added unit test for camel-example-loan-broker

Added:
    camel/trunk/examples/camel-example-loan-broker/src/test/
    camel/trunk/examples/camel-example-loan-broker/src/test/java/
    camel/trunk/examples/camel-example-loan-broker/src/test/java/org/
    camel/trunk/examples/camel-example-loan-broker/src/test/java/org/apache/
    camel/trunk/examples/camel-example-loan-broker/src/test/java/org/apache/camel/
    camel/trunk/examples/camel-example-loan-broker/src/test/java/org/apache/camel/loanbroker/
    camel/trunk/examples/camel-example-loan-broker/src/test/java/org/apache/camel/loanbroker/queue/
    camel/trunk/examples/camel-example-loan-broker/src/test/java/org/apache/camel/loanbroker/queue/version/
    camel/trunk/examples/camel-example-loan-broker/src/test/java/org/apache/camel/loanbroker/queue/version/LoanBrokerTest.java
  (with props)
    camel/trunk/examples/camel-example-loan-broker/src/test/java/org/apache/camel/loanbroker/webservice/
    camel/trunk/examples/camel-example-loan-broker/src/test/java/org/apache/camel/loanbroker/webservice/version/
    camel/trunk/examples/camel-example-loan-broker/src/test/java/org/apache/camel/loanbroker/webservice/version/LoadBrokerTest.java
  (with props)
    camel/trunk/examples/camel-example-loan-broker/src/test/resources/
    camel/trunk/examples/camel-example-loan-broker/src/test/resources/log4j.properties   (with
props)
    camel/trunk/examples/camel-example-loan-broker/src/test/resources/logging.properties 
 (with props)
Modified:
    camel/trunk/examples/camel-example-loan-broker/pom.xml
    camel/trunk/examples/camel-example-loan-broker/src/main/java/org/apache/camel/loanbroker/queue/version/Bank.java
    camel/trunk/examples/camel-example-loan-broker/src/main/java/org/apache/camel/loanbroker/queue/version/CreditAgency.java

Modified: camel/trunk/examples/camel-example-loan-broker/pom.xml
URL: http://svn.apache.org/viewvc/camel/trunk/examples/camel-example-loan-broker/pom.xml?rev=802307&r1=802306&r2=802307&view=diff
==============================================================================
--- camel/trunk/examples/camel-example-loan-broker/pom.xml (original)
+++ camel/trunk/examples/camel-example-loan-broker/pom.xml Sat Aug  8 07:01:19 2009
@@ -55,6 +55,18 @@
       <groupId>log4j</groupId>
       <artifactId>log4j</artifactId>
     </dependency>
+    <!-- testing -->
+    <dependency>
+      <groupId>junit</groupId>
+      <artifactId>junit</artifactId>
+      <scope>test</scope>
+    </dependency>
+    
+    <dependency>
+      <groupId>org.apache.camel</groupId>
+      <artifactId>camel-test</artifactId>
+      <scope>test</scope>
+    </dependency>
   </dependencies>
 
   <build>
@@ -67,6 +79,23 @@
           <target>1.5</target>
         </configuration>
       </plugin>
+      <plugin>
+        <artifactId>maven-surefire-plugin</artifactId>
+        <configuration>
+          <forkMode>pertest</forkMode>
+          <childDelegation>false</childDelegation>
+          <useFile>true</useFile>
+          <includes>
+            <include>**/*Test.*</include>
+          </includes>
+          <systemProperties>
+               <property>
+                    <name>java.util.logging.config.file</name>
+                    <value>${basedir}/target/test-classes/logging.properties</value>
+               </property>
+          </systemProperties>
+        </configuration>
+      </plugin>
       <!-- Allows the example to be run via 'mvn compile exec:java' -->
       <plugin>
         <groupId>org.codehaus.mojo</groupId>

Modified: camel/trunk/examples/camel-example-loan-broker/src/main/java/org/apache/camel/loanbroker/queue/version/Bank.java
URL: http://svn.apache.org/viewvc/camel/trunk/examples/camel-example-loan-broker/src/main/java/org/apache/camel/loanbroker/queue/version/Bank.java?rev=802307&r1=802306&r2=802307&view=diff
==============================================================================
--- camel/trunk/examples/camel-example-loan-broker/src/main/java/org/apache/camel/loanbroker/queue/version/Bank.java
(original)
+++ camel/trunk/examples/camel-example-loan-broker/src/main/java/org/apache/camel/loanbroker/queue/version/Bank.java
Sat Aug  8 07:01:19 2009
@@ -41,6 +41,7 @@
         exchange.getOut().setHeader(Constants.PROPERTY_RATE, new Double(rate));
         exchange.getOut().setHeader(Constants.PROPERTY_BANK, bankName);
         exchange.getOut().setHeader(Constants.PROPERTY_SSN, ssn);
+        exchange.getOut().setBody("Bank processed the request.");
         // Sleep some time
         try {
             Thread.sleep((int) (Math.random() * 10) * 100);

Modified: camel/trunk/examples/camel-example-loan-broker/src/main/java/org/apache/camel/loanbroker/queue/version/CreditAgency.java
URL: http://svn.apache.org/viewvc/camel/trunk/examples/camel-example-loan-broker/src/main/java/org/apache/camel/loanbroker/queue/version/CreditAgency.java?rev=802307&r1=802306&r2=802307&view=diff
==============================================================================
--- camel/trunk/examples/camel-example-loan-broker/src/main/java/org/apache/camel/loanbroker/queue/version/CreditAgency.java
(original)
+++ camel/trunk/examples/camel-example-loan-broker/src/main/java/org/apache/camel/loanbroker/queue/version/CreditAgency.java
Sat Aug  8 07:01:19 2009
@@ -33,6 +33,7 @@
         exchange.getOut().setHeader(Constants.PROPERTY_SCORE, new Integer(score));
         exchange.getOut().setHeader(Constants.PROPERTY_HISTORYLENGTH, new Integer(hlength));
         exchange.getOut().setHeader(Constants.PROPERTY_SSN, ssn);
+        exchange.getOut().setBody("CreditAgency processed the request.");
     }
 
 }

Added: camel/trunk/examples/camel-example-loan-broker/src/test/java/org/apache/camel/loanbroker/queue/version/LoanBrokerTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/examples/camel-example-loan-broker/src/test/java/org/apache/camel/loanbroker/queue/version/LoanBrokerTest.java?rev=802307&view=auto
==============================================================================
--- camel/trunk/examples/camel-example-loan-broker/src/test/java/org/apache/camel/loanbroker/queue/version/LoanBrokerTest.java
(added)
+++ camel/trunk/examples/camel-example-loan-broker/src/test/java/org/apache/camel/loanbroker/queue/version/LoanBrokerTest.java
Sat Aug  8 07:01:19 2009
@@ -0,0 +1,125 @@
+/**
+ * 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.loanbroker.queue.version;
+
+import java.util.List;
+
+import javax.jms.ConnectionFactory;
+
+import org.apache.activemq.ActiveMQConnectionFactory;
+import org.apache.camel.CamelContext;
+import org.apache.camel.Exchange;
+import org.apache.camel.ExchangePattern;
+import org.apache.camel.Processor;
+import org.apache.camel.ProducerTemplate;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.jms.JmsComponent;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.impl.DefaultCamelContext;
+
+import org.junit.After;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
+public class LoanBrokerTest extends Assert {
+    CamelContext camelContext;
+    JmsBroker broker;
+    ProducerTemplate template;
+ 
+    @Before
+    public void startServices() throws Exception {
+        camelContext = new DefaultCamelContext();
+        broker = new JmsBroker("vm://localhost");
+        broker.start();
+        // Set up the ActiveMQ JMS Components
+        ConnectionFactory connectionFactory = new ActiveMQConnectionFactory("vm://localhost");
+
+        // Note we can explicitly name the component
+        camelContext.addComponent("jms", JmsComponent.jmsComponentAutoAcknowledge(connectionFactory));
+
+        camelContext.addRoutes(new LoanBroker());
+        
+        camelContext.addRoutes(new RouteBuilder() {
+            // using the mock endpoint to check the result
+            public void configure() throws Exception {
+                from("jms:queue:loanReplyQueue").to("mock:endpoint");
+            }
+        });
+       
+        template = camelContext.createProducerTemplate();
+        camelContext.start();
+    }
+    
+    @After
+    public void stopServices() throws Exception {
+        
+        if (camelContext != null) {
+            camelContext.stop();
+        }
+        
+        Thread.sleep(1000);
+        if (broker != null) {
+            broker.stop();
+        }
+        
+    }
+    
+    @Test
+    public void testClientInvocation() throws Exception {
+        MockEndpoint endpoint = (MockEndpoint) camelContext.getEndpoint("mock:endpoint");
+        endpoint.expectedMessageCount(2);
+        // send out the request message
+        for (int i = 0; i < 2; i++) {
+            template.sendBodyAndHeader("jms:queue:loanRequestQueue",
+                                       "Quote for the lowerst rate of loaning bank",
+                                       Constants.PROPERTY_SSN, "Client-A" + i);
+            Thread.sleep(100);
+        }
+        endpoint.assertIsSatisfied();
+        // check the response from the mock endpoint
+        List<Exchange> exchanges = endpoint.getExchanges();
+        int index = 0;
+        for (Exchange exchange : exchanges) {
+            String ssn = "Client-A" + index;
+            String result = exchange.getIn().getBody(String.class);
+            assertNotNull("The result should not be null", result);
+            assertTrue("The result is wrong", result.startsWith("Loan quotion for Client
" + ssn));
+            index++;
+        }
+        
+        // send the request and get the response from the same queue       
+        Exchange exchange = template.send("jms:queue2:parallelLoanRequestQueue", new Processor()
{
+            public void process(Exchange exchange) throws Exception {
+                exchange.setPattern(ExchangePattern.InOut);
+                exchange.getIn().setBody("Quote for the lowerst rate of loaning bank");
+                exchange.getIn().setHeader(Constants.PROPERTY_SSN, "Client-B");
+            }
+        });
+        
+        String bank = (String)exchange.getOut().getHeader(Constants.PROPERTY_BANK);
+        Double rate = (Double)exchange.getOut().getHeader(Constants.PROPERTY_RATE);
+        String ssn = (String)exchange.getOut().getHeader(Constants.PROPERTY_SSN);
+        
+        assertNotNull("The ssn should not be null.", ssn);
+        assertEquals("Get a wrong ssn", "Client-B",  ssn);
+        assertNotNull("The bank should not be null", bank);
+        assertNotNull("The rate should not be null", rate);
+        
+    }
+
+}

Propchange: camel/trunk/examples/camel-example-loan-broker/src/test/java/org/apache/camel/loanbroker/queue/version/LoanBrokerTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: camel/trunk/examples/camel-example-loan-broker/src/test/java/org/apache/camel/loanbroker/queue/version/LoanBrokerTest.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: camel/trunk/examples/camel-example-loan-broker/src/test/java/org/apache/camel/loanbroker/webservice/version/LoadBrokerTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/examples/camel-example-loan-broker/src/test/java/org/apache/camel/loanbroker/webservice/version/LoadBrokerTest.java?rev=802307&view=auto
==============================================================================
--- camel/trunk/examples/camel-example-loan-broker/src/test/java/org/apache/camel/loanbroker/webservice/version/LoadBrokerTest.java
(added)
+++ camel/trunk/examples/camel-example-loan-broker/src/test/java/org/apache/camel/loanbroker/webservice/version/LoadBrokerTest.java
Sat Aug  8 07:01:19 2009
@@ -0,0 +1,83 @@
+/**
+ * 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.loanbroker.webservice.version;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.impl.DefaultCamelContext;
+import org.apache.camel.loanbroker.webservice.version.bank.BankServer;
+import org.apache.camel.loanbroker.webservice.version.credit.CreditAgencyServer;
+import org.junit.After;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
+public class LoadBrokerTest extends Assert {
+    CamelContext camelContext;
+    CreditAgencyServer creditAgencyServer;
+    BankServer bankServer;
+    
+    @Before
+    public void startServices() throws Exception {
+        camelContext = new DefaultCamelContext();
+        creditAgencyServer = new CreditAgencyServer();
+        // Start the credit server
+        creditAgencyServer.start();
+
+        // Start the bank server
+        bankServer = new BankServer();
+        bankServer.start();
+
+        // Start the camel context
+        camelContext.addRoutes(new LoanBroker());
+        camelContext.start();
+    }
+    
+    @After
+    public void stopServices() throws Exception {
+        if (camelContext != null) {
+            camelContext.stop();
+        }
+        if (bankServer != null) {
+            bankServer.stop();
+        }
+        if (creditAgencyServer != null) {
+            creditAgencyServer.stop();
+        }
+    }
+    
+    @Test
+    public void testInvocation() {
+        Client client = new Client();
+        String result = null;
+        LoanBrokerWS loanBroker = client.getProxy(Constants.LOANBROKER_ADDRESS);
+        long startTime = System.currentTimeMillis();
+        result = loanBroker.getLoanQuote("Sequential SSN", 1000.54, 10);
+        long endTime = System.currentTimeMillis();
+        long delta1 = endTime - startTime;
+        assertTrue(result.startsWith("The best rate is [ ssn:Sequential SSN bank:bank"));
+
+        LoanBrokerWS paralleLoanBroker = client.getProxy(Constants.PARALLEL_LOANBROKER_ADDRESS);
+        startTime = System.currentTimeMillis();
+        result = paralleLoanBroker.getLoanQuote("Parallel SSN", 1000.54, 10);
+        endTime = System.currentTimeMillis();
+        long delta2 = endTime - startTime;
+        assertTrue(result.startsWith("The best rate is [ ssn:Parallel SSN bank:bank"));
+        
+        assertTrue(delta2 < delta1);
+    }
+ 
+}

Propchange: camel/trunk/examples/camel-example-loan-broker/src/test/java/org/apache/camel/loanbroker/webservice/version/LoadBrokerTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: camel/trunk/examples/camel-example-loan-broker/src/test/java/org/apache/camel/loanbroker/webservice/version/LoadBrokerTest.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: camel/trunk/examples/camel-example-loan-broker/src/test/resources/log4j.properties
URL: http://svn.apache.org/viewvc/camel/trunk/examples/camel-example-loan-broker/src/test/resources/log4j.properties?rev=802307&view=auto
==============================================================================
--- camel/trunk/examples/camel-example-loan-broker/src/test/resources/log4j.properties (added)
+++ camel/trunk/examples/camel-example-loan-broker/src/test/resources/log4j.properties Sat
Aug  8 07:01:19 2009
@@ -0,0 +1,38 @@
+## ---------------------------------------------------------------------------
+## 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.
+## ---------------------------------------------------------------------------
+
+#
+# The logging properties used during tests..
+#
+log4j.rootLogger=INFO, file
+
+log4j.logger.org.apache.activemq.spring=WARN
+#log4j.logger.org.apache.camel.component=TRACE
+log4j.logger.org.apache.camel.impl.converter=WARN
+log4j.logger.org.apache.camel.component.cxf=INFO
+
+# CONSOLE appender not used by default
+log4j.appender.out=org.apache.log4j.ConsoleAppender
+log4j.appender.out.layout=org.apache.log4j.PatternLayout
+log4j.appender.out.layout.ConversionPattern=%d [%-15.15t] %-5p %-30.30c{1} - %m%n
+
+# File appender
+log4j.appender.file=org.apache.log4j.FileAppender
+log4j.appender.file.layout=org.apache.log4j.PatternLayout
+log4j.appender.file.layout.ConversionPattern=%d [%-15.15t] %-5p %-30.30c{1} - %m%n
+log4j.appender.file.file=target/camel-cxf-test.log
+log4j.appender.file.append=true

Propchange: camel/trunk/examples/camel-example-loan-broker/src/test/resources/log4j.properties
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: camel/trunk/examples/camel-example-loan-broker/src/test/resources/log4j.properties
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Propchange: camel/trunk/examples/camel-example-loan-broker/src/test/resources/log4j.properties
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: camel/trunk/examples/camel-example-loan-broker/src/test/resources/logging.properties
URL: http://svn.apache.org/viewvc/camel/trunk/examples/camel-example-loan-broker/src/test/resources/logging.properties?rev=802307&view=auto
==============================================================================
--- camel/trunk/examples/camel-example-loan-broker/src/test/resources/logging.properties (added)
+++ camel/trunk/examples/camel-example-loan-broker/src/test/resources/logging.properties Sat
Aug  8 07:01:19 2009
@@ -0,0 +1,75 @@
+#
+#
+#    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.
+#
+#
+############################################################
+#  	Default Logging Configuration File
+#
+# You can use a different file by specifying a filename
+# with the java.util.logging.config.file system property.
+# For example java -Djava.util.logging.config.file=myfile
+############################################################
+
+############################################################
+#  	Global properties
+############################################################
+
+# "handlers" specifies a comma separated list of log Handler
+# classes.  These handlers will be installed during VM startup.
+# Note that these classes must be on the system classpath.
+# By default we only configure a ConsoleHandler, which will only
+# show messages at the INFO and above levels.
+#handlers= java.util.logging.ConsoleHandler
+
+# To also add the FileHandler, use the following line instead.
+#handlers= java.util.logging.FileHandler, java.util.logging.ConsoleHandler
+
+# Default global logging level.
+# This specifies which kinds of events are logged across
+# all loggers.  For any given facility this global level
+# can be overriden by a facility specific level
+# Note that the ConsoleHandler also has a separate level
+# setting to limit messages printed to the console.
+.level= INFO
+
+############################################################
+# Handler specific properties.
+# Describes specific configuration info for Handlers.
+############################################################
+
+# default file output is in user's home directory.
+java.util.logging.FileHandler.pattern = %h/java%u.log
+java.util.logging.FileHandler.limit = 5000000
+java.util.logging.FileHandler.count = 1
+java.util.logging.FileHandler.formatter = java.util.logging.SimpleFormatter
+
+# Limit the message that are printed on the console to INFO and above.
+java.util.logging.ConsoleHandler.level = FINEST
+java.util.logging.ConsoleHandler.formatter = java.util.logging.SimpleFormatter
+
+
+############################################################
+# Facility specific properties.
+# Provides extra control for each logger.
+############################################################
+
+# For example, set the com.xyz.foo logger to only log SEVERE
+# messages:
+#com.xyz.foo.level = SEVERE
+org.apache.cxf.level = FINEST

Propchange: camel/trunk/examples/camel-example-loan-broker/src/test/resources/logging.properties
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: camel/trunk/examples/camel-example-loan-broker/src/test/resources/logging.properties
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Propchange: camel/trunk/examples/camel-example-loan-broker/src/test/resources/logging.properties
------------------------------------------------------------------------------
    svn:mime-type = text/plain



Mime
View raw message