001: /*
002: * BEGIN_HEADER - DO NOT EDIT
003: *
004: * The contents of this file are subject to the terms
005: * of the Common Development and Distribution License
006: * (the "License"). You may not use this file except
007: * in compliance with the License.
008: *
009: * You can obtain a copy of the license at
010: * https://open-esb.dev.java.net/public/CDDLv1.0.html.
011: * See the License for the specific language governing
012: * permissions and limitations under the License.
013: *
014: * When distributing Covered Code, include this CDDL
015: * HEADER in each file and include the License file at
016: * https://open-esb.dev.java.net/public/CDDLv1.0.html.
017: * If applicable add the following below this CDDL HEADER,
018: * with the fields enclosed by brackets "[]" replaced with
019: * your own identifying information: Portions Copyright
020: * [year] [name of copyright owner]
021: */
022:
023: /*
024: * @(#)TestStreamDataSource.java
025: * Copyright 2004-2007 Sun Microsystems, Inc. All Rights Reserved.
026: *
027: * END_HEADER - DO NOT EDIT
028: */
029: package com.sun.jbi.binding.proxy.util;
030:
031: import java.io.InputStream;
032: import java.io.OutputStream;
033:
034: /**
035: * Tests for the ExchangeIdImpl class
036: *
037: * @author Sun Microsystems, Inc.
038: */
039: public class TestStreamDataSource extends junit.framework.TestCase {
040:
041: final static String CONTENT_TYPE = "text/plain";
042: final static String CONTENT_NAME = "Name";
043:
044: /**
045: * The constructor for this testcase, forwards the test name to
046: * the jUnit TestCase base class.
047: * @param aTestName String with the name of this test.
048: */
049: public TestStreamDataSource(String aTestName) {
050: super (aTestName);
051: }
052:
053: /**
054: * Setup for the test. This creates the ComponentRegistry instance
055: * and other objects needed for the tests.
056: * @throws Exception when set up fails for any reason.
057: */
058: public void setUp() throws Exception {
059: super .setUp();
060: }
061:
062: /**
063: * Cleanup for the test.
064: * @throws Exception when tearDown fails for any reason.
065: */
066: public void tearDown() throws Exception {
067: super .tearDown();
068: }
069:
070: // ============================= test methods ================================
071:
072: /**
073: * testNextId
074: * @throws Exception if an unexpected error occurs
075: */
076: public void testBasic() throws Exception {
077: StreamDataSource sds;
078: OutputStream os;
079: InputStream is;
080:
081: sds = new StreamDataSource("Name", "text/plain");
082: assertEquals(CONTENT_TYPE, sds.getContentType());
083: assertEquals(CONTENT_NAME, sds.getName());
084:
085: //
086: // Shouldn't be able to read yet since there is no output.
087: //
088: try {
089: sds.getInputStream();
090: fail("Expected IOException");
091: } catch (java.io.IOException ioEx) {
092: }
093:
094: //
095: // Fill up the Stream.
096: //
097: os = sds.getOutputStream();
098: os.write(1);
099: os.write(2);
100: os.write(3);
101: os.close();
102:
103: //
104: // Now we should be able to get the InputStream.
105: //
106: is = sds.getInputStream();
107: assertEquals(is.read(), 1);
108: assertEquals(is.read(), 2);
109: assertEquals(is.read(), 3);
110: assertEquals(is.read(), -1);
111:
112: //
113: // Shouldn't be able to read yet since the output has been consumed.
114: //
115: try {
116: sds.getInputStream();
117: fail("Expected IOException");
118: } catch (java.io.IOException ioEx) {
119: }
120: }
121:
122: }
|