Author: veithen
Date: Sun May 22 10:55:06 2011
New Revision: 1125908

URL: http://svn.apache.org/viewvc?rev=1125908&view=rev
Log:
Consolidated the unit tests for org.apache.axiom.attachments.Attachments:
* Moved unit tests that don't need an OM implementation from axiom-tests to 
axiom-api.
* Merged DeleteAttachmentTest and IncomingAttachmentTest into AttachmentsTest.

Added:
    
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/attachments/AttachmentsTest.java
   (with props)
Removed:
    
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/attachments/DeleteAttachmentTest.java
    
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/attachments/IncomingAttachmentTest.java
Modified:
    
webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/attachments/AttachmentsTest.java

Added: 
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/attachments/AttachmentsTest.java
URL: 
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/attachments/AttachmentsTest.java?rev=1125908&view=auto
==============================================================================
--- 
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/attachments/AttachmentsTest.java
 (added)
+++ 
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/attachments/AttachmentsTest.java
 Sun May 22 10:55:06 2011
@@ -0,0 +1,173 @@
+/*
+ * 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.axiom.attachments;
+
+import java.io.InputStream;
+import java.util.Collection;
+import java.util.List;
+import java.util.Set;
+
+import javax.activation.DataHandler;
+
+import org.apache.axiom.attachments.utils.IOUtils;
+import org.apache.axiom.om.AbstractTestCase;
+import org.apache.axiom.om.TestConstants;
+import org.apache.axiom.testutils.io.IOTestUtils;
+
+public class AttachmentsTest extends AbstractTestCase {
+    String img2FileName = "mtom/img/test2.jpg";
+    
+    public void testGetDataHandler() throws Exception {
+        InputStream inStream = getTestResource(TestConstants.MTOM_MESSAGE);
+        Attachments attachments = new Attachments(inStream, 
TestConstants.MTOM_MESSAGE_CONTENT_TYPE);
+
+        DataHandler dh = attachments
+                
.getDataHandler("2.urn:uuid:[email protected]");
+        InputStream dataIs = dh.getDataSource().getInputStream();
+
+        InputStream expectedDataIs = getTestResource(img2FileName);
+
+        // Compare data across streams
+        IOTestUtils.compareStreams(dataIs, expectedDataIs);
+    }
+
+    public void testGetDataHandlerNonExistingMIMEPart() throws Exception {
+        InputStream inStream = getTestResource(TestConstants.MTOM_MESSAGE);
+        Attachments attachments = new Attachments(inStream, 
TestConstants.MTOM_MESSAGE_CONTENT_TYPE);
+
+        DataHandler dh = attachments.getDataHandler("ThisShouldReturnNull");
+        assertNull(dh);
+    }
+
+    public void testGetAllContentIDs() throws Exception {
+        InputStream inStream = getTestResource(TestConstants.MTOM_MESSAGE);
+        Attachments attachments = new Attachments(inStream, 
TestConstants.MTOM_MESSAGE_CONTENT_TYPE);
+
+        String[] contentIDs = attachments.getAllContentIDs();
+        assertEquals(contentIDs.length, 3);
+        assertEquals(contentIDs[0], 
"0.urn:uuid:[email protected]");
+        assertEquals(contentIDs[1], 
"1.urn:uuid:[email protected]");
+        assertEquals(contentIDs[2], 
"2.urn:uuid:[email protected]");
+
+        Set idSet = attachments.getContentIDSet();
+        
assertTrue(idSet.contains("0.urn:uuid:[email protected]"));
+        
assertTrue(idSet.contains("2.urn:uuid:[email protected]"));
+        
assertTrue(idSet.contains("1.urn:uuid:[email protected]"));
+        
+        // Make sure the length is correct
+        long length = attachments.getContentLength();
+        long fileSize = 
IOUtils.getStreamAsByteArray(getTestResource(TestConstants.MTOM_MESSAGE)).length;
+        assertTrue("Expected MessageContent Length of " + fileSize + " but 
received " + length,
+                   length == fileSize);
+    }
+
+    private void testGetSOAPPartContentID(String contentTypeStartParam, String 
contentId)
+            throws Exception {
+        // It doesn't actually matter what the stream *is* it just needs to 
exist
+        String contentType = "multipart/related; boundary=\"" + 
TestConstants.MTOM_MESSAGE_BOUNDARY +
+                "\"; type=\"text/xml\"; start=\"" + contentTypeStartParam + 
"\"";
+        InputStream inStream = getTestResource(TestConstants.MTOM_MESSAGE);
+        Attachments attachments = new Attachments(inStream, contentType);
+        assertEquals("Did not obtain correct content ID", contentId,
+                attachments.getSOAPPartContentID());
+    }
+    
+    public void testGetSOAPPartContentIDWithoutBrackets() throws Exception {
+        testGetSOAPPartContentID("my-content-id@localhost", 
"my-content-id@localhost");
+    }
+    
+    public void testGetSOAPPartContentIDWithBrackets() throws Exception {
+        testGetSOAPPartContentID("<my-content-id@localhost>", 
"my-content-id@localhost");
+    }
+    
+    // Not sure when exactly somebody uses the "cid:" prefix in the start 
parameter, but
+    // this is how the code currently works.
+    public void testGetSOAPPartContentIDWithCidPrefix() throws Exception {
+        testGetSOAPPartContentID("cid:my-content-id@localhost", 
"my-content-id@localhost");
+    }
+    
+    // Regression test for WSCOMMONS-329
+    public void testGetSOAPPartContentIDWithCidPrefix2() throws Exception {
+        testGetSOAPPartContentID("<[email protected]>", 
"[email protected]");
+    }
+    
+    public void testGetSOAPPartContentIDShort() throws Exception {
+        testGetSOAPPartContentID("bbb", "bbb");
+    }
+    
+    public void testGetSOAPPartContentIDShortWithBrackets() throws Exception {
+        testGetSOAPPartContentID("<b>", "b");
+    }
+    
+    public void testGetSOAPPartContentIDBorderline() throws Exception {
+        testGetSOAPPartContentID("cid:", "cid:");
+    }
+    
+    public void testGetIncomingAttachmentStreams() throws Exception {
+        InputStream inStream = getTestResource(TestConstants.MTOM_MESSAGE);
+        Attachments attachments = new Attachments(inStream, 
TestConstants.MTOM_MESSAGE_CONTENT_TYPE);
+
+        // Get the inputstream container
+        IncomingAttachmentStreams ias = 
attachments.getIncomingAttachmentStreams();
+
+        IncomingAttachmentInputStream dataIs;
+
+        // Img1 stream
+        dataIs = ias.getNextStream();
+
+        // Make sure it was the first attachment
+        
assertEquals("<1.urn:uuid:[email protected]>",
+                     dataIs.getContentId());
+
+        // Consume the stream
+        while (dataIs.read() != -1) ;
+
+        // Img2 stream
+        dataIs = ias.getNextStream();
+        
assertEquals("<2.urn:uuid:[email protected]>",
+                     dataIs.getContentId());
+
+        // Test if getContentType() works..
+        assertEquals("image/jpeg", dataIs.getContentType());
+
+        // Test if a adding/getting a header works
+        dataIs.addHeader("new-header", "test-value");
+        assertEquals("test-value", dataIs.getHeader("new-header"));
+    }
+    
+    public void testRemoveDataHandlerWithStream() throws Exception {
+        InputStream inStream = getTestResource(TestConstants.MTOM_MESSAGE);
+        Attachments attachments = new Attachments(inStream, 
TestConstants.MTOM_MESSAGE_CONTENT_TYPE);
+
+        Collection list = attachments.getContentIDSet();
+        assertEquals(3, list.size());
+        
+        
assertTrue(list.contains("1.urn:uuid:[email protected]"));
+        
assertTrue(list.contains("2.urn:uuid:[email protected]"));
+        
+        
attachments.removeDataHandler("1.urn:uuid:[email protected]");
+
+        List list2 = attachments.getContentIDList();
+        assertEquals(2, list2.size());
+        assertEquals(2, attachments.getMap().size());
+
+        
assertFalse(list2.contains("1.urn:uuid:[email protected]"));
+        
assertTrue(list2.contains("2.urn:uuid:[email protected]"));
+    }
+}

Propchange: 
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/attachments/AttachmentsTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: 
webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/attachments/AttachmentsTest.java
URL: 
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/attachments/AttachmentsTest.java?rev=1125908&r1=1125907&r2=1125908&view=diff
==============================================================================
--- 
webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/attachments/AttachmentsTest.java
 (original)
+++ 
webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/attachments/AttachmentsTest.java
 Sun May 22 10:55:06 2011
@@ -20,7 +20,6 @@
 package org.apache.axiom.attachments;
 
 import org.apache.axiom.attachments.AttachmentCacheMonitor;
-import org.apache.axiom.attachments.utils.IOUtils;
 import org.apache.axiom.om.AbstractTestCase;
 import org.apache.axiom.om.OMElement;
 import org.apache.axiom.om.OMOutputFormat;
@@ -32,7 +31,6 @@ import org.apache.axiom.om.util.StAXUtil
 import org.apache.axiom.soap.impl.builder.MTOMStAXSOAPModelBuilder;
 import org.apache.axiom.testutils.io.IOTestUtils;
 
-import javax.activation.DataHandler;
 import javax.xml.stream.XMLStreamReader;
 
 import java.io.BufferedReader;
@@ -42,7 +40,6 @@ import java.io.File;
 import java.io.InputStream;
 import java.io.InputStreamReader;
 import java.io.StringWriter;
-import java.util.Set;
 
 public class AttachmentsTest extends AbstractTestCase {
 
@@ -57,12 +54,6 @@ public class AttachmentsTest extends Abs
     String contentTypeString =
         "multipart/related; 
boundary=\"MIMEBoundaryurn:uuid:A3ADBAEE51A1A87B2A11443668160701\"; 
type=\"application/xop+xml\"; 
start=\"<0.urn:uuid:[email protected]>\"; 
start-info=\"application/soap+xml\"; charset=UTF-8;action=\"mtomSample\"";
 
-    public void testMIMEHelper() {
-    }
-
-    public void testGetAttachmentSpecType() {
-    }
-
     public void testSimultaneousStreamAccess() throws Exception {
         InputStream inStream;
         Attachments attachments;
@@ -323,53 +314,6 @@ public class AttachmentsTest extends Abs
         
     }
 
-    public void testGetDataHandler() throws Exception {
-
-        InputStream inStream = getTestResource(TestConstants.MTOM_MESSAGE);
-        Attachments attachments = new Attachments(inStream, 
TestConstants.MTOM_MESSAGE_CONTENT_TYPE);
-
-        DataHandler dh = attachments
-                
.getDataHandler("2.urn:uuid:[email protected]");
-        InputStream dataIs = dh.getDataSource().getInputStream();
-
-        InputStream expectedDataIs = getTestResource(img2FileName);
-
-        // Compare data across streams
-        IOTestUtils.compareStreams(dataIs, expectedDataIs);
-    }
-
-    public void testNonExistingMIMEPart() throws Exception {
-
-        InputStream inStream = getTestResource(TestConstants.MTOM_MESSAGE);
-        Attachments attachments = new Attachments(inStream, 
TestConstants.MTOM_MESSAGE_CONTENT_TYPE);
-
-        DataHandler dh = attachments.getDataHandler("ThisShouldReturnNull");
-        assertNull(dh);
-    }
-
-    public void testGetAllContentIDs() throws Exception {
-
-        InputStream inStream = getTestResource(TestConstants.MTOM_MESSAGE);
-        Attachments attachments = new Attachments(inStream, 
TestConstants.MTOM_MESSAGE_CONTENT_TYPE);
-
-        String[] contentIDs = attachments.getAllContentIDs();
-        assertEquals(contentIDs.length, 3);
-        assertEquals(contentIDs[0], 
"0.urn:uuid:[email protected]");
-        assertEquals(contentIDs[1], 
"1.urn:uuid:[email protected]");
-        assertEquals(contentIDs[2], 
"2.urn:uuid:[email protected]");
-
-        Set idSet = attachments.getContentIDSet();
-        
assertTrue(idSet.contains("0.urn:uuid:[email protected]"));
-        
assertTrue(idSet.contains("2.urn:uuid:[email protected]"));
-        
assertTrue(idSet.contains("1.urn:uuid:[email protected]"));
-        
-        // Make sure the length is correct
-        long length = attachments.getContentLength();
-        long fileSize = 
IOUtils.getStreamAsByteArray(getTestResource(TestConstants.MTOM_MESSAGE)).length;
-        assertTrue("Expected MessageContent Length of " + fileSize + " but 
received " + length,
-                   length == fileSize);
-    }
-    
     public void testCachedFilesExpired() throws Exception {
        
        // Set file expiration to 10 seconds
@@ -441,46 +385,4 @@ public class AttachmentsTest extends Abs
             acm.setTimeout(previousTime);
         }
     }
-
-    private void testGetSOAPPartContentID(String contentTypeStartParam, String 
contentId)
-            throws Exception {
-        // It doesn't actually matter what the stream *is* it just needs to 
exist
-        String contentType = "multipart/related; boundary=\"" + 
TestConstants.MTOM_MESSAGE_BOUNDARY +
-                "\"; type=\"text/xml\"; start=\"" + contentTypeStartParam + 
"\"";
-        InputStream inStream = getTestResource(TestConstants.MTOM_MESSAGE);
-        Attachments attachments = new Attachments(inStream, contentType);
-        assertEquals("Did not obtain correct content ID", contentId,
-                attachments.getSOAPPartContentID());
-    }
-    
-    public void testGetSOAPPartContentIDWithoutBrackets() throws Exception {
-        testGetSOAPPartContentID("my-content-id@localhost", 
"my-content-id@localhost");
-    }
-    
-    public void testGetSOAPPartContentIDWithBrackets() throws Exception {
-        testGetSOAPPartContentID("<my-content-id@localhost>", 
"my-content-id@localhost");
-    }
-    
-    // Not sure when exactly somebody uses the "cid:" prefix in the start 
parameter, but
-    // this is how the code currently works.
-    public void testGetSOAPPartContentIDWithCidPrefix() throws Exception {
-        testGetSOAPPartContentID("cid:my-content-id@localhost", 
"my-content-id@localhost");
-    }
-    
-    // Regression test for WSCOMMONS-329
-    public void testGetSOAPPartContentIDWithCidPrefix2() throws Exception {
-        testGetSOAPPartContentID("<[email protected]>", 
"[email protected]");
-    }
-    
-    public void testGetSOAPPartContentIDShort() throws Exception {
-        testGetSOAPPartContentID("bbb", "bbb");
-    }
-    
-    public void testGetSOAPPartContentIDShortWithBrackets() throws Exception {
-        testGetSOAPPartContentID("<b>", "b");
-    }
-    
-    public void testGetSOAPPartContentIDBorderline() throws Exception {
-        testGetSOAPPartContentID("cid:", "cid:");
-    }
 }


Reply via email to