cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject git commit: Adding a JAX-RS multipart test with a minor update to Attachment
Date Mon, 10 Mar 2014 17:52:40 GMT
Repository: cxf
Updated Branches:
  refs/heads/2.7.x-fixes 5e83949b3 -> c729193dd


Adding a JAX-RS multipart test with a minor update to Attachment


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

Branch: refs/heads/2.7.x-fixes
Commit: c729193dd87698c7e499281ab7e33654f9f8c8f4
Parents: 5e83949
Author: Sergey Beryozkin <sberyozkin@talend.com>
Authored: Mon Mar 10 17:50:20 2014 +0000
Committer: Sergey Beryozkin <sberyozkin@talend.com>
Committed: Mon Mar 10 17:52:19 2014 +0000

----------------------------------------------------------------------
 .../cxf/jaxrs/ext/multipart/Attachment.java     |  5 ++
 .../cxf/systest/jaxrs/JAXRSMultipartTest.java   | 51 ++++++++++++++++++++
 2 files changed, 56 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cxf/blob/c729193d/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/multipart/Attachment.java
----------------------------------------------------------------------
diff --git a/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/multipart/Attachment.java
b/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/multipart/Attachment.java
index 18ab5b6..aaeacd0 100644
--- a/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/multipart/Attachment.java
+++ b/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/multipart/Attachment.java
@@ -78,6 +78,11 @@ public class Attachment implements Transferable {
         this(id, new DataHandler(ds), headers);
     }
     
+    public Attachment(MultivaluedMap<String, String> headers, Object object) {
+        this.headers = headers;
+        this.object = object;
+    }
+    
     public Attachment(InputStream is, MultivaluedMap<String, String> headers) {
         this(headers.getFirst("Content-ID"), 
              new DataHandler(new InputStreamDataSource(is, headers.getFirst("Content-Type"))),


http://git-wip-us.apache.org/repos/asf/cxf/blob/c729193d/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSMultipartTest.java
----------------------------------------------------------------------
diff --git a/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSMultipartTest.java
b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSMultipartTest.java
index 8ce64f2..152396e 100644
--- a/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSMultipartTest.java
+++ b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSMultipartTest.java
@@ -494,6 +494,57 @@ public class JAXRSMultipartTest extends AbstractBusClientServerTestBase
{
         assertNotNull(params.get("start"));
     }
     
+    @Test
+    public void testAddBookJaxbJsonImageWebClientRelated2() throws Exception {
+        String address = "http://localhost:" + PORT + "/bookstore/books/jaxbimagejson";
+        WebClient client = WebClient.create(address);
+        WebClient.getConfig(client).getOutInterceptors().add(new LoggingOutInterceptor());
+        WebClient.getConfig(client).getInInterceptors().add(new LoggingInInterceptor());
+        client.type("multipart/mixed").accept("multipart/mixed");
+       
+        Book jaxb = new Book("jaxb", 1L);
+        Book json = new Book("json", 2L);
+        InputStream is1 = 
+            getClass().getResourceAsStream("/org/apache/cxf/systest/jaxrs/resources/java.jpg");
+        Map<String, Object> objects = new LinkedHashMap<String, Object>();
+
+        MultivaluedMap<String, String> headers = new MetadataMap<String, String>();
+        headers.putSingle("Content-Type", "application/xml");
+        headers.putSingle("Content-ID", "theroot");
+        headers.putSingle("Content-Transfer-Encoding", "customxml");
+        Attachment attJaxb = new Attachment(headers, jaxb);
+        
+        headers = new MetadataMap<String, String>();
+        headers.putSingle("Content-Type", "application/json");
+        headers.putSingle("Content-ID", "thejson");
+        headers.putSingle("Content-Transfer-Encoding", "customjson");
+        Attachment attJson = new Attachment(headers, json);
+        
+        headers = new MetadataMap<String, String>();
+        headers.putSingle("Content-Type", "application/octet-stream");
+        headers.putSingle("Content-ID", "theimage");
+        headers.putSingle("Content-Transfer-Encoding", "customstream");
+        Attachment attIs = new Attachment(headers, is1);
+        
+        objects.put(MediaType.APPLICATION_XML, attJaxb);
+        objects.put(MediaType.APPLICATION_JSON, attJson);
+        objects.put(MediaType.APPLICATION_OCTET_STREAM, attIs);
+        
+        Collection<? extends Attachment> coll = client.postAndGetCollection(objects,
Attachment.class);
+        List<Attachment> result = new ArrayList<Attachment>(coll);
+        Book jaxb2 = readBookFromInputStream(result.get(0).getDataHandler().getInputStream());
+        assertEquals("jaxb", jaxb2.getName());
+        assertEquals(1L, jaxb2.getId());
+        Book json2 = readJSONBookFromInputStream(result.get(1).getDataHandler().getInputStream());
+        assertEquals("json", json2.getName());
+        assertEquals(2L, json2.getId());
+        InputStream is2 = result.get(2).getDataHandler().getInputStream();
+        byte[] image1 = IOUtils.readBytesFromStream(
+            getClass().getResourceAsStream("/org/apache/cxf/systest/jaxrs/resources/java.jpg"));
+        byte[] image2 = IOUtils.readBytesFromStream(is2);
+        assertTrue(Arrays.equals(image1, image2));
+    }
+    
     private Map<String, String> doTestAddBookJaxbJsonImageWebClient(String multipartType)
throws Exception {
         String address = "http://localhost:" + PORT + "/bookstore/books/jaxbjsonimage";
         WebClient client = WebClient.create(address);


Mime
View raw message