cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject svn commit: r833911 [2/2] - in /cxf/branches/2.2.x-fixes: ./ rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/ rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/multipart/ rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/ rt/fro...
Date Sun, 08 Nov 2009 18:46:08 GMT
Modified: cxf/branches/2.2.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSMultipartTest.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.2.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSMultipartTest.java?rev=833911&r1=833910&r2=833911&view=diff
==============================================================================
--- cxf/branches/2.2.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSMultipartTest.java
(original)
+++ cxf/branches/2.2.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSMultipartTest.java
Sun Nov  8 18:46:07 2009
@@ -89,6 +89,30 @@
     }
     
     @Test
+    public void testBookJSONForm() throws Exception {
+        String address = "http://localhost:9085/bookstore/books/jsonform";
+        doAddFormBook(address, "attachmentFormJson", 200);               
+    }
+    
+    @Test
+    public void testBookJaxbForm() throws Exception {
+        String address = "http://localhost:9085/bookstore/books/jaxbform";
+        doAddFormBook(address, "attachmentFormJaxb", 200);               
+    }
+    
+    @Test
+    public void testBookJSONJAXBForm() throws Exception {
+        String address = "http://localhost:9085/bookstore/books/jsonjaxbform";
+        doAddFormBook(address, "attachmentFormJsonJaxb", 200);               
+    }
+    
+    @Test
+    public void testBookJSONFormFiles() throws Exception {
+        String address = "http://localhost:9085/bookstore/books/filesform";
+        doAddFormBook(address, "attachmentFormJsonFiles", 200);               
+    }
+    
+    @Test
     public void testBookAsMessageContextAttachment() throws Exception {
         String address = "http://localhost:9085/bookstore/books/attachment";
         doAddBook(address, "attachmentData", 200);               
@@ -400,6 +424,30 @@
         }
     }
     
+    private void doAddFormBook(String address, String resourceName, int status) throws Exception
{
+        PostMethod post = new PostMethod(address);
+        
+        String ct = "multipart/form-data; boundary=bqJky99mlBWa-ZuqjC53mG6EzbmlxB";
+        post.setRequestHeader("Content-Type", ct);
+        InputStream is = 
+            getClass().getResourceAsStream("/org/apache/cxf/systest/jaxrs/resources/" + resourceName);
+        RequestEntity entity = new InputStreamRequestEntity(is);
+        post.setRequestEntity(entity);
+        HttpClient httpclient = new HttpClient();
+        
+        try {
+            int result = httpclient.executeMethod(post);
+            assertEquals(status, result);
+            if (status == 200) {
+                InputStream expected = getClass().getResourceAsStream("resources/expected_add_book.txt");
+                assertEquals(getStringFromInputStream(expected), post.getResponseBodyAsString());
+            }
+        } finally {
+            // Release current connection to the connection pool once you are done
+            post.releaseConnection();
+        }
+    }
+    
     private String getStringFromInputStream(InputStream in) throws Exception {        
         CachedOutputStream bos = new CachedOutputStream();
         IOUtils.copy(in, bos);

Modified: cxf/branches/2.2.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/MultipartStore.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.2.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/MultipartStore.java?rev=833911&r1=833910&r2=833911&view=diff
==============================================================================
--- cxf/branches/2.2.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/MultipartStore.java
(original)
+++ cxf/branches/2.2.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/MultipartStore.java
Sun Nov  8 18:46:07 2009
@@ -223,6 +223,64 @@
     }
     
     @POST
+    @Path("/books/jsonform")
+    @Produces("text/xml")
+    @Consumes("multipart/form-data")
+    public Response addBookJsonFromForm(Book b1) 
+        throws Exception {
+        b1.setId(124);
+        return Response.ok(b1).build();
+    }
+    
+    @POST
+    @Path("/books/filesform")
+    @Produces("text/xml")
+    @Consumes("multipart/form-data")
+    public Response addBookFilesForm(@Multipart("owner") String name, 
+                                     @Multipart("files") List<Book> books) 
+        throws Exception {
+        if (books.size() != 2) {
+            throw new WebApplicationException();
+        }
+        Book b1 = books.get(0);
+        Book b2 = books.get(1);
+        if (!"CXF in Action - 1".equals(b1.getName())
+            || !"CXF in Action - 2".equals(b2.getName())
+            || !"Larry".equals(name)) {
+            throw new WebApplicationException();
+        }
+        b1.setId(124);
+        b1.setName("CXF in Action - 2");
+        return Response.ok(b1).build();
+    }
+    
+    @POST
+    @Path("/books/jaxbform")
+    @Produces("text/xml")
+    @Consumes("multipart/form-data")
+    public Response addBookJaxbFromForm(Book b1) 
+        throws Exception {
+        b1.setId(124);
+        return Response.ok(b1).build();
+    }
+    
+    @POST
+    @Path("/books/jsonjaxbform")
+    @Produces("text/xml")
+    @Consumes("multipart/form-data")
+    public Response addBookJaxbJsonForm(@Multipart("jsonPart") Book b1, 
+                                        @Multipart("bookXML") Book b2) 
+        throws Exception {
+        if (!"CXF in Action - 1".equals(b1.getName())
+            || !"CXF in Action - 2".equals(b2.getName())) {
+            throw new WebApplicationException();
+        }
+        b2.setId(124);
+        return Response.ok(b2).build();
+    }
+    
+    
+    @POST
     @Path("/books/dsource2")
     @Produces("text/xml")
     public Response addBookFromDataSource2(@Multipart("rootPart") DataSource ds1,

Modified: cxf/branches/2.2.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/resources/expected_get_chapter1.txt
URL: http://svn.apache.org/viewvc/cxf/branches/2.2.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/resources/expected_get_chapter1.txt?rev=833911&r1=833910&r2=833911&view=diff
==============================================================================
--- cxf/branches/2.2.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/resources/expected_get_chapter1.txt
(original)
+++ cxf/branches/2.2.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/resources/expected_get_chapter1.txt
Sun Nov  8 18:46:07 2009
@@ -1 +1 @@
-<?xml version="1.0" encoding="iso-8859-1" standalone="yes"?><Chapter><id>1</id><title>chapter
1</title></Chapter>
\ No newline at end of file
+<?xml version="1.0" encoding="ISO-8859-1" standalone="yes"?><Chapter><id>1</id><title>chapter
1</title></Chapter>
\ No newline at end of file



Mime
View raw message