You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by bv...@apache.org on 2012/11/19 16:07:32 UTC

svn commit: r1411232 - in /camel/branches/camel-2.10.x: ./ components/camel-cxf/src/test/java/org/apache/camel/component/cxf/cxfbean/ components/camel-cxf/src/test/java/org/apache/camel/component/cxf/jaxrs/ components/camel-cxf/src/test/java/org/apache...

Author: bvahdat
Date: Mon Nov 19 15:07:31 2012
New Revision: 1411232

URL: http://svn.apache.org/viewvc?rev=1411232&view=rev
Log:
Merged revisions 1411217 via svnmerge from 
https://svn.apache.org/repos/asf/camel/trunk

........
  r1411217 | bvahdat | 2012-11-19 15:51:16 +0100 (Mo, 19 Nov 2012) | 1 line
  
  Fixed the broken CxfBeanTest on the JDK7-CI-Profile which made assumption about the *order* of the test methods being executed. Also fixed CxfRsProducerTest making assumption about the order of the entries inside the *concrete* Map implementation being used by the CustomerService (java.util.Map.values()), which on it's turn, now is thread-safe.
........

Modified:
    camel/branches/camel-2.10.x/   (props changed)
    camel/branches/camel-2.10.x/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/cxfbean/CxfBeanTest.java
    camel/branches/camel-2.10.x/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/jaxrs/CxfRsProducerTest.java
    camel/branches/camel-2.10.x/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/jaxrs/testbean/Customer.java
    camel/branches/camel-2.10.x/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/jaxrs/testbean/CustomerService.java

Propchange: camel/branches/camel-2.10.x/
------------------------------------------------------------------------------
  Merged /camel/trunk:r1411217

Propchange: camel/branches/camel-2.10.x/
------------------------------------------------------------------------------
Binary property 'svnmerge-integrated' - no diff available.

Modified: camel/branches/camel-2.10.x/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/cxfbean/CxfBeanTest.java
URL: http://svn.apache.org/viewvc/camel/branches/camel-2.10.x/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/cxfbean/CxfBeanTest.java?rev=1411232&r1=1411231&r2=1411232&view=diff
==============================================================================
--- camel/branches/camel-2.10.x/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/cxfbean/CxfBeanTest.java (original)
+++ camel/branches/camel-2.10.x/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/cxfbean/CxfBeanTest.java Mon Nov 19 15:07:31 2012
@@ -27,6 +27,7 @@ import org.apache.camel.CamelContext;
 import org.apache.camel.Endpoint;
 import org.apache.camel.component.cxf.CXFTestSupport;
 import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.util.ObjectHelper;
 import org.apache.camel.wsdl_first.Person;
 import org.apache.camel.wsdl_first.PersonService;
 import org.apache.http.HttpResponse;
@@ -47,10 +48,12 @@ import static org.junit.Assert.assertEqu
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.fail;
+
 @ContextConfiguration
 public class CxfBeanTest extends AbstractJUnit4SpringContextTests {
     private static final String PUT_REQUEST = "<Customer><name>Mary</name><id>113</id></Customer>";
     private static final String POST_REQUEST = "<Customer><name>Jack</name></Customer>";
+    private static final String POST2_REQUEST = "<Customer><name>James</name></Customer>";
     private static final int PORT1 = CXFTestSupport.getPort("CxfBeanTest.1");
     private static final int PORT2 = CXFTestSupport.getPort("CxfBeanTest.2");
     
@@ -176,7 +179,8 @@ public class CxfBeanTest extends Abstrac
         try {
             HttpResponse response = httpclient.execute(post);
             assertEquals(200, response.getStatusLine().getStatusCode());
-            assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><Customer><id>124</id><name>Jack</name></Customer>",
+            String id = getCustomerId("Jack");
+            assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><Customer><id>" + id + "</id><name>Jack</name></Customer>",
                          EntityUtils.toString(response.getEntity()));
         } finally {
             httpclient.getConnectionManager().shutdown();
@@ -187,7 +191,7 @@ public class CxfBeanTest extends Abstrac
     public void testPostConsumerUniqueResponseCode() throws Exception {
         HttpPost post = new HttpPost("http://localhost:" + PORT1 + "/customerservice/customersUniqueResponseCode");
         post.addHeader("Accept" , "text/xml");
-        StringEntity entity = new StringEntity(POST_REQUEST, "ISO-8859-1");
+        StringEntity entity = new StringEntity(POST2_REQUEST, "ISO-8859-1");
         entity.setContentType("text/xml; charset=ISO-8859-1");
         post.setEntity(entity);
         HttpClient httpclient = new DefaultHttpClient();
@@ -195,13 +199,31 @@ public class CxfBeanTest extends Abstrac
         try {
             HttpResponse response = httpclient.execute(post);
             assertEquals(201, response.getStatusLine().getStatusCode());
-            assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><Customer><id>125</id><name>Jack</name></Customer>",
+            String id = getCustomerId("James");
+            assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><Customer><id>" + id + "</id><name>James</name></Customer>",
                          EntityUtils.toString(response.getEntity()));
         } finally {
             httpclient.getConnectionManager().shutdown();
         }
     }
 
+    private String getCustomerId(String name) throws Exception {
+        HttpGet get = new HttpGet("http://localhost:" + PORT1 + "/customerservice/customers/");
+        get.addHeader("Accept", "application/xml");
+        HttpClient httpclient = new DefaultHttpClient();
+
+        try {
+            HttpResponse response = httpclient.execute(get);
+            assertEquals(200, response.getStatusLine().getStatusCode());
+            String customers = EntityUtils.toString(response.getEntity());
+            String before = ObjectHelper.before(customers, "</id><name>" + name + "</name></Customer>");
+            String answer = before.substring(before.lastIndexOf(">") + 1, before.length());
+            return answer;
+        } finally {
+            httpclient.getConnectionManager().shutdown();
+        }
+    }
+
     @Test
     public void testJaxWsBean() throws Exception {        
         HttpPost post = new HttpPost("http://localhost:" + PORT2 + "/customerservice/customers");

Modified: camel/branches/camel-2.10.x/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/jaxrs/CxfRsProducerTest.java
URL: http://svn.apache.org/viewvc/camel/branches/camel-2.10.x/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/jaxrs/CxfRsProducerTest.java?rev=1411232&r1=1411231&r2=1411232&view=diff
==============================================================================
--- camel/branches/camel-2.10.x/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/jaxrs/CxfRsProducerTest.java (original)
+++ camel/branches/camel-2.10.x/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/jaxrs/CxfRsProducerTest.java Mon Nov 19 15:07:31 2012
@@ -121,8 +121,8 @@ public class CxfRsProducerTest extends C
         List<Customer> response = CastUtils.cast((List<?>) exchange.getOut().getBody());
         
         assertNotNull("The response should not be null ", response);
-        assertEquals("Get a wrong customer id ", String.valueOf(response.get(0).getId()), "113");
-        assertEquals("Get a wrong customer name", response.get(0).getName(), "Dan");
+        assertTrue("Dan is missing!", response.contains(new Customer(113, "Dan")));
+        assertTrue("John is missing!", response.contains(new Customer(123, "John")));
         assertEquals("Get a wrong response code", 200, exchange.getOut().getHeader(Exchange.HTTP_RESPONSE_CODE));
     }
     

Modified: camel/branches/camel-2.10.x/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/jaxrs/testbean/Customer.java
URL: http://svn.apache.org/viewvc/camel/branches/camel-2.10.x/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/jaxrs/testbean/Customer.java?rev=1411232&r1=1411231&r2=1411232&view=diff
==============================================================================
--- camel/branches/camel-2.10.x/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/jaxrs/testbean/Customer.java (original)
+++ camel/branches/camel-2.10.x/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/jaxrs/testbean/Customer.java Mon Nov 19 15:07:31 2012
@@ -18,6 +18,8 @@ package org.apache.camel.component.cxf.j
 
 import javax.xml.bind.annotation.XmlRootElement;
 
+import org.apache.camel.util.ObjectHelper;
+
 /**
  *
  * @version 
@@ -27,6 +29,14 @@ public class Customer {
     private long id;
     private String name;
 
+    public Customer() {
+    }
+
+    public Customer(long id, String name) {
+        setId(id);
+        setName(name);
+    }
+
     public long getId() {
         return id;
     }
@@ -42,4 +52,28 @@ public class Customer {
     public void setName(String name) {
         this.name = name;
     }
+
+    @Override
+    public int hashCode() {
+        final int prime = 31;
+        int result = 1;
+        result = prime * result + (int) (id ^ (id >>> 32));
+        result = prime * result + ((name == null) ? 0 : name.hashCode());
+        return result;
+    }
+
+    @Override
+    public boolean equals(Object obj) {
+        if (!(obj instanceof Customer)) {
+            return false;
+        }
+
+        if (this == obj) {
+            return true;
+        }
+
+        Customer other = (Customer) obj;
+        return id == other.id && ObjectHelper.equal(name, other.name);
+    }
+
 }

Modified: camel/branches/camel-2.10.x/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/jaxrs/testbean/CustomerService.java
URL: http://svn.apache.org/viewvc/camel/branches/camel-2.10.x/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/jaxrs/testbean/CustomerService.java?rev=1411232&r1=1411231&r2=1411232&view=diff
==============================================================================
--- camel/branches/camel-2.10.x/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/jaxrs/testbean/CustomerService.java (original)
+++ camel/branches/camel-2.10.x/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/jaxrs/testbean/CustomerService.java Mon Nov 19 15:07:31 2012
@@ -17,9 +17,10 @@
 package org.apache.camel.component.cxf.jaxrs.testbean;
 
 import java.util.ArrayList;
-import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.atomic.AtomicLong;
 
 import javax.ws.rs.DELETE;
 import javax.ws.rs.GET;
@@ -39,9 +40,9 @@ import javax.ws.rs.core.Response;
  */
 @Path("/customerservice/")
 public class CustomerService {
-    long currentId = 123;
-    Map<Long, Customer> customers = new HashMap<Long, Customer>();
-    Map<Long, Order> orders = new HashMap<Long, Order>();
+    private final AtomicLong currentId = new AtomicLong(123L);
+    private final Map<Long, Customer> customers = new ConcurrentHashMap<Long, Customer>();
+    private final Map<Long, Order> orders = new ConcurrentHashMap<Long, Order>();
 
     public CustomerService() {
         init();
@@ -67,8 +68,8 @@ public class CustomerService {
     @Path("/customers/")
     @Produces("application/xml")
     public List<Customer> getCustomers() {
-        List<Customer> l = new ArrayList<Customer>(customers.values());
-        return l;
+        List<Customer> list = new ArrayList<Customer>(customers.values());
+        return list;
     }
     
 
@@ -90,7 +91,7 @@ public class CustomerService {
     @POST
     @Path("/customers/")
     public Response addCustomer(Customer customer) {
-        customer.setId(++currentId);
+        customer.setId(currentId.incrementAndGet());
 
         customers.put(customer.getId(), customer);
         
@@ -100,7 +101,7 @@ public class CustomerService {
     @POST
     @Path("/customersUniqueResponseCode/")
     public Response addCustomerUniqueResponseCode(Customer customer) {
-        customer.setId(++currentId);
+        customer.setId(currentId.incrementAndGet());
 
         customers.put(customer.getId(), customer);
         
@@ -120,8 +121,8 @@ public class CustomerService {
         } else {
             r = Response.notModified().build();
         }
-        if (idNumber == currentId) {
-            --currentId;
+        if (idNumber == currentId.get()) {
+            currentId.decrementAndGet();
         }
         return r;
     }