You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ws.apache.org by ve...@apache.org on 2011/07/30 11:33:22 UTC

svn commit: r1152438 - in /webservices/commons/trunk/modules/axiom/modules: axiom-api/src/test/java/org/apache/axiom/attachments/ axiom-tests/src/test/java/org/apache/axiom/attachments/

Author: veithen
Date: Sat Jul 30 09:33:21 2011
New Revision: 1152438

URL: http://svn.apache.org/viewvc?rev=1152438&view=rev
Log:
AXIOM-311: Moved some attachments related unit tests from axiom-tests to axiom-api so that we can do a unit test coverage analysis in preparation of AXIOM-326.

Added:
    webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/attachments/PartOnFileTest.java
      - copied unchanged from r1149334, webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/attachments/PartOnFileTest.java
    webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/attachments/PdfAttachmentStreamingTest.java
      - copied unchanged from r1149334, webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/attachments/PdfAttachmentStreamingTest.java
Removed:
    webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/attachments/PartOnFileTest.java
    webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/attachments/PdfAttachmentStreamingTest.java
Modified:
    webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/attachments/AttachmentsTest.java
    webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/attachments/AttachmentsTest.java

Modified: 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=1152438&r1=1152437&r2=1152438&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/attachments/AttachmentsTest.java (original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/attachments/AttachmentsTest.java Sat Jul 30 09:33:21 2011
@@ -18,6 +18,7 @@
  */
 package org.apache.axiom.attachments;
 
+import java.io.File;
 import java.io.InputStream;
 import java.util.Collection;
 import java.util.List;
@@ -32,6 +33,7 @@ import org.apache.axiom.om.TestConstants
 import org.apache.axiom.testutils.io.IOTestUtils;
 
 public class AttachmentsTest extends AbstractTestCase {
+    String img1FileName = "mtom/img/test.jpg";
     String img2FileName = "mtom/img/test2.jpg";
     
     public void testGetDataHandler() throws Exception {
@@ -170,6 +172,108 @@ public class AttachmentsTest extends Abs
         assertEquals("test-value", dataIs.getHeader("new-header"));
     }
     
+    public void testGetIncomingAttachmentStreams2() throws Exception {
+
+        IncomingAttachmentInputStream dataIs;
+        InputStream expectedDataIs;
+
+        InputStream inStream = getTestResource(TestConstants.MTOM_MESSAGE);
+        Attachments attachments = new Attachments(inStream, TestConstants.MTOM_MESSAGE_CONTENT_TYPE);
+
+        // Since SOAP part operated independently of other streams, access it
+        // directly, and then get to the streams. If this sequence throws an
+        // error, something is wrong with the stream handling code.
+        InputStream is = attachments.getSOAPPartInputStream();
+        while (is.read() != -1) ;
+
+        // Get the inputstream container
+        IncomingAttachmentStreams ias = attachments.getIncomingAttachmentStreams();
+
+        dataIs = ias.getNextStream();
+        expectedDataIs = getTestResource(img1FileName);
+        IOTestUtils.compareStreams(dataIs, expectedDataIs);
+
+        dataIs = ias.getNextStream();
+        expectedDataIs = getTestResource(img2FileName);
+        IOTestUtils.compareStreams(dataIs, expectedDataIs);
+
+        // Confirm that no more streams are left
+        assertEquals(null, ias.getNextStream());
+        
+        // After all is done, we should *still* be able to access and
+        // re-consume the SOAP part stream, as it should be cached.. can we?
+        is = attachments.getSOAPPartInputStream();
+        while (is.read() != -1) ;  
+    }
+    
+    public void testSimultaneousStreamAccess() throws Exception {
+        InputStream inStream;
+        Attachments attachments;
+    
+        inStream = getTestResource(TestConstants.MTOM_MESSAGE);
+        attachments = new Attachments(inStream, TestConstants.MTOM_MESSAGE_CONTENT_TYPE);
+    
+        attachments.getDataHandler("2.urn:uuid:A3ADBAEE51A1A87B2A11443668160994@apache.org");
+    
+        // This should throw an error
+        try {
+            attachments.getIncomingAttachmentStreams();
+            fail("No exception caught when attempting to access datahandler and stream at the same time");
+        } catch (IllegalStateException ise) {
+            // Nothing
+        }
+    
+        inStream.close();
+    
+        // Try the other way around.
+        inStream = getTestResource(TestConstants.MTOM_MESSAGE);
+        attachments = new Attachments(inStream, TestConstants.MTOM_MESSAGE_CONTENT_TYPE);
+    
+        attachments.getIncomingAttachmentStreams();
+    
+        // These should NOT throw error even though they are using part based access
+        try {
+            String contentType = attachments.getSOAPPartContentType();
+            assertTrue(contentType.indexOf("application/xop+xml;") >=0);
+            assertTrue(contentType.indexOf("charset=UTF-8;") >=0);
+            assertTrue(contentType.indexOf("type=\"application/soap+xml\";") >=0);
+        } catch (IllegalStateException ise) {
+            fail("No exception expected when requesting SOAP part data");
+            ise.printStackTrace();
+        }
+    
+        try {
+            attachments.getSOAPPartInputStream();
+        } catch (IllegalStateException ise) {
+            fail("No exception expected when requesting SOAP part data");
+        }
+    
+        // These should throw an error
+        try {
+            attachments.getDataHandler("2.urn:uuid:A3ADBAEE51A1A87B2A11443668160994@apache.org");
+            fail("No exception caught when attempting to access stream and datahandler at the same time");
+        } catch (IllegalStateException ise) {
+            // Nothing
+        }
+    
+        // Additionally, we also need to ensure mutual exclusion if someone
+        // tries to access part data directly
+    
+        try {
+            attachments.getAllContentIDs();
+            fail("No exception caught when attempting to access stream and contentids list at the same time");
+        } catch (IllegalStateException ise) {
+            // Nothing
+        }
+    
+        try {
+            attachments.getDataHandler("2.urn:uuid:A3ADBAEE51A1A87B2A11443668160994@apache.org");
+            fail("No exception caught when attempting to access stream and part at the same time");
+        } catch (IllegalStateException ise) {
+            // Nothing
+        }
+    }
+
     public void testRemoveDataHandlerWithStream() throws Exception {
         InputStream inStream = getTestResource(TestConstants.MTOM_MESSAGE);
         Attachments attachments = new Attachments(inStream, TestConstants.MTOM_MESSAGE_CONTENT_TYPE);
@@ -189,4 +293,76 @@ public class AttachmentsTest extends Abs
         assertFalse(list2.contains("1.urn:uuid:A3ADBAEE51A1A87B2A11443668160943@apache.org"));
         assertTrue(list2.contains("2.urn:uuid:A3ADBAEE51A1A87B2A11443668160994@apache.org"));
     }
+
+    public void testCachedFilesExpired() throws Exception {
+        
+        // Set file expiration to 10 seconds
+        long INTERVAL = 3 * 1000; // 3 seconds for Thread to sleep
+        Thread t = Thread.currentThread();
+
+       
+        // Get the AttachmentCacheMonitor and force it to remove files after
+        // 10 seconds.
+        AttachmentCacheMonitor acm = AttachmentCacheMonitor.getAttachmentCacheMonitor();
+        int previousTime = acm.getTimeout();
+        
+        try {
+            acm.setTimeout(10); 
+
+
+            File aFile = new File("A");
+            aFile.createNewFile();
+            String aFileName = aFile.getCanonicalPath();
+            acm.register(aFileName);
+
+            t.sleep(INTERVAL);
+
+            File bFile = new File("B");
+            bFile.createNewFile();
+            String bFileName = bFile.getCanonicalPath();
+            acm.register(bFileName);
+
+            t.sleep(INTERVAL);
+
+            acm.access(aFileName);
+
+            // time since file A registration <= cached file expiration
+            assertTrue("File A should still exist", aFile.exists());
+
+            t.sleep(INTERVAL);
+
+            acm.access(bFileName);
+
+            // time since file B registration <= cached file expiration
+            assertTrue("File B should still exist", bFile.exists());
+
+            t.sleep(INTERVAL);
+
+            File cFile = new File("C");
+            cFile.createNewFile();
+            String cFileName = cFile.getCanonicalPath();
+            acm.register(cFileName);
+            acm.access(bFileName);
+
+            t.sleep(INTERVAL);
+
+            acm.checkForAgedFiles();
+
+            // time since file C registration <= cached file expiration
+            assertTrue("File C should still exist", cFile.exists());
+
+            t.sleep(10* INTERVAL);  // Give task loop time to delete aged files
+
+
+            // All files should be gone by now
+            assertFalse("File A should no longer exist", aFile.exists());
+            assertFalse("File B should no longer exist", bFile.exists());
+            assertFalse("File C should no longer exist", cFile.exists());
+        } finally {
+       
+            // Reset the timeout to the previous value so that no 
+            // other tests are affected
+            acm.setTimeout(previousTime);
+        }
+    }
 }

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=1152438&r1=1152437&r2=1152438&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 Sat Jul 30 09:33:21 2011
@@ -19,7 +19,6 @@
 
 package org.apache.axiom.attachments;
 
-import org.apache.axiom.attachments.AttachmentCacheMonitor;
 import org.apache.axiom.om.AbstractTestCase;
 import org.apache.axiom.om.OMElement;
 import org.apache.axiom.om.OMOutputFormat;
@@ -29,14 +28,12 @@ import org.apache.axiom.om.impl.MTOMXMLS
 import org.apache.axiom.om.impl.builder.XOPAwareStAXOMBuilder;
 import org.apache.axiom.om.util.StAXUtils;
 import org.apache.axiom.soap.impl.builder.MTOMStAXSOAPModelBuilder;
-import org.apache.axiom.testutils.io.IOTestUtils;
 
 import javax.xml.stream.XMLStreamReader;
 
 import java.io.BufferedReader;
 import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
-import java.io.File;
 import java.io.InputStream;
 import java.io.InputStreamReader;
 import java.io.StringWriter;
@@ -54,108 +51,6 @@ public class AttachmentsTest extends Abs
     String contentTypeString =
         "multipart/related; boundary=\"MIMEBoundaryurn:uuid:A3ADBAEE51A1A87B2A11443668160701\"; type=\"application/xop+xml\"; start=\"<0....@apache.org>\"; start-info=\"application/soap+xml\"; charset=UTF-8;action=\"mtomSample\"";
 
-    public void testSimultaneousStreamAccess() throws Exception {
-        InputStream inStream;
-        Attachments attachments;
-
-        inStream = getTestResource(TestConstants.MTOM_MESSAGE);
-        attachments = new Attachments(inStream, TestConstants.MTOM_MESSAGE_CONTENT_TYPE);
-
-        attachments.getDataHandler("2.urn:uuid:A3ADBAEE51A1A87B2A11443668160994@apache.org");
-
-        // This should throw an error
-        try {
-            attachments.getIncomingAttachmentStreams();
-            fail("No exception caught when attempting to access datahandler and stream at the same time");
-        } catch (IllegalStateException ise) {
-            // Nothing
-        }
-
-        inStream.close();
-
-        // Try the other way around.
-        inStream = getTestResource(TestConstants.MTOM_MESSAGE);
-        attachments = new Attachments(inStream, TestConstants.MTOM_MESSAGE_CONTENT_TYPE);
-
-        attachments.getIncomingAttachmentStreams();
-
-        // These should NOT throw error even though they are using part based access
-        try {
-            String contentType = attachments.getSOAPPartContentType();
-            assertTrue(contentType.indexOf("application/xop+xml;") >=0);
-            assertTrue(contentType.indexOf("charset=UTF-8;") >=0);
-            assertTrue(contentType.indexOf("type=\"application/soap+xml\";") >=0);
-        } catch (IllegalStateException ise) {
-            fail("No exception expected when requesting SOAP part data");
-            ise.printStackTrace();
-        }
-
-        try {
-            attachments.getSOAPPartInputStream();
-        } catch (IllegalStateException ise) {
-            fail("No exception expected when requesting SOAP part data");
-        }
-
-        // These should throw an error
-        try {
-            attachments.getDataHandler("2.urn:uuid:A3ADBAEE51A1A87B2A11443668160994@apache.org");
-            fail("No exception caught when attempting to access stream and datahandler at the same time");
-        } catch (IllegalStateException ise) {
-            // Nothing
-        }
-
-        // Additionally, we also need to ensure mutual exclusion if someone
-        // tries to access part data directly
-
-        try {
-            attachments.getAllContentIDs();
-            fail("No exception caught when attempting to access stream and contentids list at the same time");
-        } catch (IllegalStateException ise) {
-            // Nothing
-        }
-
-        try {
-            attachments.getDataHandler("2.urn:uuid:A3ADBAEE51A1A87B2A11443668160994@apache.org");
-            fail("No exception caught when attempting to access stream and part at the same time");
-        } catch (IllegalStateException ise) {
-            // Nothing
-        }
-    }
-
-    public void testGetInputAttachhmentStreams() throws Exception {
-
-        IncomingAttachmentInputStream dataIs;
-        InputStream expectedDataIs;
-
-        InputStream inStream = getTestResource(TestConstants.MTOM_MESSAGE);
-        Attachments attachments = new Attachments(inStream, TestConstants.MTOM_MESSAGE_CONTENT_TYPE);
-
-        // Since SOAP part operated independently of other streams, access it
-        // directly, and then get to the streams. If this sequence throws an
-        // error, something is wrong with the stream handling code.
-        InputStream is = attachments.getSOAPPartInputStream();
-        while (is.read() != -1) ;
-
-        // Get the inputstream container
-        IncomingAttachmentStreams ias = attachments.getIncomingAttachmentStreams();
-
-        dataIs = ias.getNextStream();
-        expectedDataIs = getTestResource(img1FileName);
-        IOTestUtils.compareStreams(dataIs, expectedDataIs);
-
-        dataIs = ias.getNextStream();
-        expectedDataIs = getTestResource(img2FileName);
-        IOTestUtils.compareStreams(dataIs, expectedDataIs);
-
-        // Confirm that no more streams are left
-        assertEquals(null, ias.getNextStream());
-        
-        // After all is done, we should *still* be able to access and
-        // re-consume the SOAP part stream, as it should be cached.. can we?
-        is = attachments.getSOAPPartInputStream();
-        while (is.read() != -1) ;  
-    }
-    
     public void testWritingBinaryAttachments() throws Exception {
 
         // Read in message: SOAPPart and 2 image attachments
@@ -313,76 +208,4 @@ public class AttachmentsTest extends Abs
         assertTrue(text.indexOf("BAttachment") < text.indexOf("AAttachment"));
         
     }
-
-    public void testCachedFilesExpired() throws Exception {
-    	
-    	// Set file expiration to 10 seconds
-    	long INTERVAL = 3 * 1000; // 3 seconds for Thread to sleep
-        Thread t = Thread.currentThread();
-
-       
-        // Get the AttachmentCacheMonitor and force it to remove files after
-        // 10 seconds.
-        AttachmentCacheMonitor acm = AttachmentCacheMonitor.getAttachmentCacheMonitor();
-        int previousTime = acm.getTimeout();
-        
-        try {
-            acm.setTimeout(10); 
-
-
-            File aFile = new File("A");
-            aFile.createNewFile();
-            String aFileName = aFile.getCanonicalPath();
-            acm.register(aFileName);
-
-            t.sleep(INTERVAL);
-
-            File bFile = new File("B");
-            bFile.createNewFile();
-            String bFileName = bFile.getCanonicalPath();
-            acm.register(bFileName);
-
-            t.sleep(INTERVAL);
-
-            acm.access(aFileName);
-
-            // time since file A registration <= cached file expiration
-            assertTrue("File A should still exist", aFile.exists());
-
-            t.sleep(INTERVAL);
-
-            acm.access(bFileName);
-
-            // time since file B registration <= cached file expiration
-            assertTrue("File B should still exist", bFile.exists());
-
-            t.sleep(INTERVAL);
-
-            File cFile = new File("C");
-            cFile.createNewFile();
-            String cFileName = cFile.getCanonicalPath();
-            acm.register(cFileName);
-            acm.access(bFileName);
-
-            t.sleep(INTERVAL);
-
-            acm.checkForAgedFiles();
-
-            // time since file C registration <= cached file expiration
-            assertTrue("File C should still exist", cFile.exists());
-
-            t.sleep(10* INTERVAL);  // Give task loop time to delete aged files
-
-
-            // All files should be gone by now
-            assertFalse("File A should no longer exist", aFile.exists());
-            assertFalse("File B should no longer exist", bFile.exists());
-            assertFalse("File C should no longer exist", cFile.exists());
-        } finally {
-       
-            // Reset the timeout to the previous value so that no 
-            // other tests are affected
-            acm.setTimeout(previousTime);
-        }
-    }
 }