1 17 package org.apache.geronimo.activation.handlers; 18 19 import java.io.ByteArrayInputStream ; 20 import java.io.InputStream ; 21 import java.io.OutputStream ; 22 import java.io.ByteArrayOutputStream ; 23 import javax.activation.DataContentHandler ; 24 import javax.activation.DataSource ; 25 26 import org.apache.geronimo.testsupport.TestSupport; 27 28 31 public abstract class AbstractHandler extends TestSupport { 32 protected DataContentHandler dch; 33 protected String mimeType; 34 35 public void testGetContent() throws Exception { 36 final byte[] bytes = "Hello World".getBytes(); 37 DataSource ds = new DataSource () { 38 public InputStream getInputStream() { 39 return new ByteArrayInputStream (bytes); 40 } 41 42 public OutputStream getOutputStream() { 43 throw new UnsupportedOperationException (); 44 } 45 46 public String getContentType() { 47 throw new UnsupportedOperationException (); 48 } 49 50 public String getName() { 51 throw new UnsupportedOperationException (); 52 } 53 }; 54 Object o = dch.getContent(ds); 55 assertEquals("Hello World", o); 56 } 57 58 public void testWriteTo() throws Exception { 59 ByteArrayOutputStream baos = new ByteArrayOutputStream (); 60 dch.writeTo("Hello World", mimeType, baos); 61 assertEquals("Hello World", baos.toString()); 62 } 63 } 64 | Popular Tags |