cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject cxf git commit: [CXF-6849] Adding a test
Date Thu, 31 Mar 2016 17:58:55 GMT
Repository: cxf
Updated Branches:
  refs/heads/3.1.x-fixes 239cb5d1a -> 0c05b1fe6


[CXF-6849] Adding a test


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

Branch: refs/heads/3.1.x-fixes
Commit: 0c05b1fe6acf3069e1dae2d95caa21d71613b6b1
Parents: 239cb5d
Author: Sergey Beryozkin <sberyozkin@gmail.com>
Authored: Thu Mar 31 18:57:55 2016 +0100
Committer: Sergey Beryozkin <sberyozkin@gmail.com>
Committed: Thu Mar 31 18:58:40 2016 +0100

----------------------------------------------------------------------
 .../org/apache/cxf/jaxrs/utils/FormUtils.java   | 21 ++++++--
 .../org/apache/cxf/systest/jaxrs/BookStore.java |  8 +++
 .../jaxrs/JAXRSClientServerBookTest.java        | 56 +++++++-------------
 3 files changed, 43 insertions(+), 42 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cxf/blob/0c05b1fe/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/FormUtils.java
----------------------------------------------------------------------
diff --git a/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/FormUtils.java b/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/FormUtils.java
index ec5d0e0..ac01098 100644
--- a/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/FormUtils.java
+++ b/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/FormUtils.java
@@ -193,16 +193,27 @@ public final class FormUtils {
                                               boolean encoded) throws IOException {
         for (Iterator<Map.Entry<String, List<String>>> it = map.entrySet().iterator();
it.hasNext();) {
             Map.Entry<String, List<String>> entry = it.next();
+            
+            String key = entry.getKey();
+            if (!encoded) {
+                key = HttpUtils.urlEncode(key, enc);
+            }
             for (Iterator<String> entryIterator = entry.getValue().iterator(); entryIterator.hasNext();)
{
-                String value = entryIterator.next();
-                os.write(entry.getKey().getBytes(enc));
+                os.write(key.getBytes(enc));
                 os.write('=');
-                String data = encoded ? value : HttpUtils.urlEncode(value, enc);
-                os.write(data.getBytes(enc));
-                if (entryIterator.hasNext() || it.hasNext()) {
+                
+                String value = entryIterator.next();
+                if (!encoded) {
+                    value = HttpUtils.urlEncode(value, enc);
+                }
+                os.write(value.getBytes(enc));
+                if (entryIterator.hasNext()) {
                     os.write('&');
                 }
             }
+            if (it.hasNext()) {
+                os.write('&');
+            }
 
         }
     }

http://git-wip-us.apache.org/repos/asf/cxf/blob/0c05b1fe/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookStore.java
----------------------------------------------------------------------
diff --git a/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookStore.java b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookStore.java
index 665c950..e6ae99e 100644
--- a/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookStore.java
+++ b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookStore.java
@@ -324,6 +324,14 @@ public class BookStore {
         return "empty form";
     }
     
+    @POST
+    @Path("/form")
+    @Produces(MediaType.APPLICATION_FORM_URLENCODED)
+    @Consumes(MediaType.APPLICATION_FORM_URLENCODED)
+    public Form echoForm(Form form) {
+        return form;
+    }
+    
     @GET
     @Path("/booknames/123")
     @Produces("application/bar")

http://git-wip-us.apache.org/repos/asf/cxf/blob/0c05b1fe/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java
----------------------------------------------------------------------
diff --git a/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java
b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java
index 94c2897..61fdeec 100644
--- a/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java
+++ b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java
@@ -60,6 +60,7 @@ import org.apache.commons.httpclient.methods.GetMethod;
 import org.apache.commons.httpclient.methods.PostMethod;
 import org.apache.commons.httpclient.methods.PutMethod;
 import org.apache.commons.httpclient.methods.RequestEntity;
+import org.apache.cxf.feature.LoggingFeature;
 import org.apache.cxf.helpers.IOUtils;
 import org.apache.cxf.interceptor.LoggingInInterceptor;
 import org.apache.cxf.io.CachedOutputStream;
@@ -76,7 +77,6 @@ import org.apache.cxf.systest.jaxrs.BookStore.BookNotReturnedException;
 import org.apache.cxf.testutil.common.AbstractBusClientServerTestBase;
 
 import org.junit.BeforeClass;
-import org.junit.Ignore;
 import org.junit.Test;
 
 public class JAXRSClientServerBookTest extends AbstractBusClientServerTestBase {
@@ -284,6 +284,18 @@ public class JAXRSClientServerBookTest extends AbstractBusClientServerTestBase
{
         Response r = wc.form(new Form());
         assertEquals("empty form", r.readEntity(String.class));
     }
+    @Test
+    public void testEchoForm() throws Exception {
+        String address = "http://localhost:" + PORT + "/bookstore/form";
+        WebClient wc = WebClient.create(address, Collections.singletonList(new LoggingFeature()));
+        Form formOut = new Form().param("a", "aValue").param("b", "b value")
+            .param("c%", "cValue");
+        Form formIn = wc.post(formOut, Form.class);
+        assertEquals(3, formIn.asMap().size());
+        assertEquals("aValue", formIn.asMap().getFirst("a"));
+        assertEquals("b value", formIn.asMap().getFirst("b"));
+        assertEquals("cValue", formIn.asMap().getFirst("c%"));
+    }
     
     @Test
     public void testPostEmptyFormAsInStream() throws Exception {
@@ -1212,21 +1224,6 @@ public class JAXRSClientServerBookTest extends AbstractBusClientServerTestBase
{
     }
     
     @Test
-    @Ignore
-    // uncomment once I can figure out how to set for this test only
-    // com.sun.xml.bind.v2.bytecode.ClassTailor.noOptimize - JAXB is a pain
-    public void testProxyUnwrapBookWithXslt() throws Exception {
-        XSLTJaxbProvider<?> provider = new XSLTJaxbProvider<Object>();
-        provider.setInTemplate("classpath:/org/apache/cxf/systest/jaxrs/resources/unwrapbook2.xsl");
-        BookStore bs = JAXRSClientFactory.create("http://localhost:" + PORT, BookStore.class,
-                             Collections.singletonList(provider));
-        Book book = bs.getWrappedBook2(123L);
-        assertNotNull(book);
-        assertEquals(123L, book.getId());
-        
-    }
-    
-    @Test
     public void testOptions() throws Exception {
         WebClient wc = 
             WebClient.create("http://localhost:" 
@@ -1538,9 +1535,12 @@ public class JAXRSClientServerBookTest extends AbstractBusClientServerTestBase
{
         String msg1 = 
             "No message body writer has been found for class java.util.GregorianCalendar,
ContentType: */*";
         String msg2 = "No message body writer has been found for class java.util.Calendar,
ContentType: */*";
-        
-        getAndCompareStrings("http://localhost:" + PORT + "/bookstore/timetable", 
-                             new String[]{msg1, msg2}, "*/*", 500);
+        WebClient wc = WebClient.create("http://localhost:" + PORT + "/bookstore/timetable");
+        wc.accept("*/*");
+        Response r = wc.get();
+        assertEquals(500, r.getStatus());
+        String s = r.readEntity(String.class);
+        assertTrue(s.equals(msg1) || s.equals(msg2));
     }
     
     @SuppressWarnings("deprecation")
@@ -2747,24 +2747,6 @@ public class JAXRSClientServerBookTest extends AbstractBusClientServerTestBase
{
         return str;
     }
     
-    private void getAndCompareStrings(String address, 
-                               String[] expectedValue,
-                               String acceptType,
-                               int expectedStatus) throws Exception {
-        assertEquals(2, expectedValue.length);
-        GetMethod get = new GetMethod(address);
-        get.setRequestHeader("Accept", acceptType);
-        HttpClient httpClient = new HttpClient();
-        try {
-            int result = httpClient.executeMethod(get);
-            assertEquals(expectedStatus, result);
-            String jsonContent = getStringFromInputStream(get.getResponseBodyAsStream());
-            assertTrue("Expected value is wrong", 
-                       expectedValue[0].equals(jsonContent) || expectedValue[1].equals(jsonContent));
-        } finally {
-            get.releaseConnection();
-        }
-    }
     
     
     private String getStringFromInputStream(InputStream in) throws Exception {        


Mime
View raw message