Repository: camel
Updated Branches:
  refs/heads/master 55552780e -> f64757d2d


CAMEL-7395 Simplify the way CxfRsProducer JAXRSClientFactoryBean can be test 
with thanks to Sergey


Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/f64757d2
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/f64757d2
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/f64757d2

Branch: refs/heads/master
Commit: f64757d2d34c087536b9f9939953d8b6b8189f0e
Parents: 5555278
Author: Willem Jiang <[email protected]>
Authored: Fri Apr 25 20:52:13 2014 +0800
Committer: Willem Jiang <[email protected]>
Committed: Fri Apr 25 20:53:54 2014 +0800

----------------------------------------------------------------------
 .../component/cxf/jaxrs/CxfRsProducer.java      |  6 +-
 .../CxfRsProducerClientFactoryBeanTest.java     | 75 ++++++++++++++++++++
 .../CxfRsProducerClientFactoryBeanTest.xml      | 46 ++++++++++++
 3 files changed, 126 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/f64757d2/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/jaxrs/CxfRsProducer.java
----------------------------------------------------------------------
diff --git 
a/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/jaxrs/CxfRsProducer.java
 
b/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/jaxrs/CxfRsProducer.java
index d6f0ee5..729417b 100644
--- 
a/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/jaxrs/CxfRsProducer.java
+++ 
b/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/jaxrs/CxfRsProducer.java
@@ -244,6 +244,10 @@ public class CxfRsProducer extends DefaultProducer {
         }
     }
     
+    protected ClientFactoryBeanCache getClientFactoryBeanCache() { 
+        return clientFactoryBeanCache;
+    }
+    
     private Map<String, String> getQueryParametersFromQueryString(String 
queryString, String charset) throws UnsupportedEncodingException {
         Map<String, String> answer  = new LinkedHashMap<String, String>();
         for (String param : queryString.split("&")) {
@@ -343,7 +347,7 @@ public class CxfRsProducer extends DefaultProducer {
     /**
      * Cache contains {@link 
org.apache.cxf.jaxrs.client.JAXRSClientFactoryBean}
      */
-    private class ClientFactoryBeanCache {
+    class ClientFactoryBeanCache {
         private LRUSoftCache<String, JAXRSClientFactoryBean> cache;    
         
         public ClientFactoryBeanCache(final int maxCacheSize) {

http://git-wip-us.apache.org/repos/asf/camel/blob/f64757d2/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/jaxrs/CxfRsProducerClientFactoryBeanTest.java
----------------------------------------------------------------------
diff --git 
a/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/jaxrs/CxfRsProducerClientFactoryBeanTest.java
 
b/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/jaxrs/CxfRsProducerClientFactoryBeanTest.java
new file mode 100644
index 0000000..6a1a5f0
--- /dev/null
+++ 
b/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/jaxrs/CxfRsProducerClientFactoryBeanTest.java
@@ -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.
+ */
+package org.apache.camel.component.cxf.jaxrs;
+
+import java.util.List;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.spring.SpringCamelContext;
+import org.apache.cxf.interceptor.Interceptor;
+import org.apache.cxf.interceptor.LoggingInInterceptor;
+import org.apache.cxf.interceptor.LoggingOutInterceptor;
+import org.apache.cxf.jaxrs.client.JAXRSClientFactoryBean;
+import org.junit.After;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+import org.springframework.context.support.AbstractApplicationContext;
+import org.springframework.context.support.ClassPathXmlApplicationContext;
+
+/**
+ *
+ */
+public class CxfRsProducerClientFactoryBeanTest extends Assert {
+
+    private CamelContext context;
+    private AbstractApplicationContext applicationContext;
+
+    @Before
+    public void setUp() throws Exception {
+        applicationContext = new ClassPathXmlApplicationContext(
+            
"org/apache/camel/component/cxf/jaxrs/CxfRsProducerClientFactoryBeanTest.xml");
+        context = SpringCamelContext.springCamelContext(applicationContext, 
false);
+        context.start();
+    }
+
+    @Test
+    public void testProducerInOutInterceptors() throws Exception {
+        CxfRsEndpoint e = context.getEndpoint(
+            "cxfrs://bean://rsClientHttpInterceptors", CxfRsEndpoint.class);
+        CxfRsProducer p = new CxfRsProducer(e);
+        CxfRsProducer.ClientFactoryBeanCache cache = 
p.getClientFactoryBeanCache();
+        JAXRSClientFactoryBean bean = 
cache.get("http://localhost:8080/CxfRsProducerClientFactoryBeanInterceptors/";);
+        List<Interceptor<?>> ins = bean.getInInterceptors();
+        assertEquals(1, ins.size());
+        assertTrue(ins.get(0) instanceof LoggingInInterceptor);
+        List<Interceptor<?>> outs = bean.getOutInterceptors();
+        assertEquals(1, outs.size());
+        assertTrue(outs.get(0) instanceof LoggingOutInterceptor);
+    }
+
+    @After
+    public void tearDown() throws Exception {
+        if (context != null) {
+            context.stop();
+        }
+        // need to shutdown the application context to shutdown the bus
+        if (applicationContext != null) {
+            applicationContext.close();
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/f64757d2/components/camel-cxf/src/test/resources/org/apache/camel/component/cxf/jaxrs/CxfRsProducerClientFactoryBeanTest.xml
----------------------------------------------------------------------
diff --git 
a/components/camel-cxf/src/test/resources/org/apache/camel/component/cxf/jaxrs/CxfRsProducerClientFactoryBeanTest.xml
 
b/components/camel-cxf/src/test/resources/org/apache/camel/component/cxf/jaxrs/CxfRsProducerClientFactoryBeanTest.xml
new file mode 100644
index 0000000..c444f0b
--- /dev/null
+++ 
b/components/camel-cxf/src/test/resources/org/apache/camel/component/cxf/jaxrs/CxfRsProducerClientFactoryBeanTest.xml
@@ -0,0 +1,46 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+    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.
+-->
+<beans xmlns="http://www.springframework.org/schema/beans";
+       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
+       xmlns:cxf="http://camel.apache.org/schema/cxf";
+       xmlns:jaxrs="http://cxf.apache.org/jaxrs";
+       xsi:schemaLocation="
+       http://www.springframework.org/schema/beans 
http://www.springframework.org/schema/beans/spring-beans.xsd
+       http://camel.apache.org/schema/cxf 
http://camel.apache.org/schema/cxf/camel-cxf.xsd
+       http://cxf.apache.org/jaxrs http://cxf.apache.org/schemas/jaxrs.xsd
+       http://camel.apache.org/schema/spring 
http://camel.apache.org/schema/spring/camel-spring.xsd
+    ">
+     
+  <cxf:rsClient id="rsClientHttpInterceptors" 
+      
address="http://localhost:8080/CxfRsProducerClientFactoryBeanInterceptors/";>
+      <cxf:inInterceptors>
+         <bean class="org.apache.cxf.interceptor.LoggingInInterceptor"/>
+      </cxf:inInterceptors>
+      <cxf:outInterceptors>
+         <bean class="org.apache.cxf.interceptor.LoggingOutInterceptor"/>
+      </cxf:outInterceptors>
+  </cxf:rsClient>
+
+  <camelContext id="camel" xmlns="http://camel.apache.org/schema/spring";>
+    <route>
+       <from uri="direct://http"/>
+       <to uri="cxfrs://bean://rsClientHttpInterceptors"/>
+    </route>
+  </camelContext>
+  
+</beans>

Reply via email to