KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > geronimo > activation > handlers > AbstractHandler


1 /**
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements. See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License. You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */

17 package org.apache.geronimo.activation.handlers;
18
19 import java.io.ByteArrayInputStream JavaDoc;
20 import java.io.InputStream JavaDoc;
21 import java.io.OutputStream JavaDoc;
22 import java.io.ByteArrayOutputStream JavaDoc;
23 import javax.activation.DataContentHandler JavaDoc;
24 import javax.activation.DataSource JavaDoc;
25
26 import org.apache.geronimo.testsupport.TestSupport;
27
28 /**
29  * @version $Rev: 476457 $ $Date: 2006-11-18 01:49:20 -0500 (Sat, 18 Nov 2006) $
30  */

31 public abstract class AbstractHandler extends TestSupport {
32     protected DataContentHandler JavaDoc dch;
33     protected String JavaDoc mimeType;
34
35     public void testGetContent() throws Exception JavaDoc {
36         final byte[] bytes = "Hello World".getBytes();
37         DataSource JavaDoc ds = new DataSource JavaDoc() {
38             public InputStream JavaDoc getInputStream() {
39                 return new ByteArrayInputStream JavaDoc(bytes);
40             }
41
42             public OutputStream JavaDoc getOutputStream() {
43                 throw new UnsupportedOperationException JavaDoc();
44             }
45
46             public String JavaDoc getContentType() {
47                 throw new UnsupportedOperationException JavaDoc();
48             }
49
50             public String JavaDoc getName() {
51                 throw new UnsupportedOperationException JavaDoc();
52             }
53         };
54         Object JavaDoc o = dch.getContent(ds);
55         assertEquals("Hello World", o);
56     }
57
58     public void testWriteTo() throws Exception JavaDoc {
59         ByteArrayOutputStream JavaDoc baos = new ByteArrayOutputStream JavaDoc();
60         dch.writeTo("Hello World", mimeType, baos);
61         assertEquals("Hello World", baos.toString());
62     }
63 }
64
Popular Tags