Home » HttpComponents-Core-4.0.1 » org.apache.http.io » [javadoc | source]

    1   /*
    2    * $HeadURL: https://svn.apache.org/repos/asf/jakarta/httpcomponents/httpcore/tags/4.0-alpha2/src/test/org/apache/http/io/TestHttpDataOutputStream.java $
    3    * $Revision: 376458 $
    4    * $Date: 2006-02-09 23:22:06 +0100 (Thu, 09 Feb 2006) $
    5    * ====================================================================
    6    *
    7    *  Copyright 1999-2006 The Apache Software Foundation
    8    *
    9    *  Licensed under the Apache License, Version 2.0 (the "License");
   10    *  you may not use this file except in compliance with the License.
   11    *  You may obtain a copy of the License at
   12    *
   13    *      http://www.apache.org/licenses/LICENSE-2.0
   14    *
   15    *  Unless required by applicable law or agreed to in writing, software
   16    *  distributed under the License is distributed on an "AS IS" BASIS,
   17    *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   18    *  See the License for the specific language governing permissions and
   19    *  limitations under the License.
   20    * ====================================================================
   21    *
   22    * This software consists of voluntary contributions made by many
   23    * individuals on behalf of the Apache Software Foundation.  For more
   24    * information on the Apache Software Foundation, please see
   25    * <http://www.apache.org/>.
   26    *
   27    */
   28   
   29   package org.apache.http.io;
   30   
   31   import org.apache.http.mockup.HttpDataTransmitterMockup;
   32   
   33   import junit.framework.Test;
   34   import junit.framework.TestCase;
   35   import junit.framework.TestSuite;
   36   
   37   /**
   38    * Simple tests for {@link HttpDataOutputStream}.
   39    *
   40    * @author <a href="mailto:oleg at ural.ru">Oleg Kalnichevski</a>
   41    */
   42   public class TestHttpDataOutputStream extends TestCase {
   43   
   44       // ------------------------------------------------------------ Constructor
   45       public TestHttpDataOutputStream(String testName) {
   46           super(testName);
   47       }
   48   
   49       // ------------------------------------------------------------------- Main
   50       public static void main(String args[]) {
   51           String[] testCaseName = { TestHttpDataOutputStream.class.getName() };
   52           junit.textui.TestRunner.main(testCaseName);
   53       }
   54   
   55       // ------------------------------------------------------- TestCase Methods
   56   
   57       public static Test suite() {
   58           return new TestSuite(TestHttpDataOutputStream.class);
   59       }
   60   
   61       public void testConstructor() throws Exception {
   62           HttpDataTransmitterMockup transmitter = new HttpDataTransmitterMockup();
   63           new HttpDataOutputStream(transmitter);
   64           try {
   65               new HttpDataOutputStream(null);
   66               fail("IllegalArgumentException should have been thrown");
   67           } catch (IllegalArgumentException ex) {
   68               //expected
   69           }
   70       }
   71       
   72       public void testBasicWrite() throws Exception {
   73       	HttpDataTransmitterMockup transmitter = new HttpDataTransmitterMockup();
   74           HttpDataOutputStream outstream = new HttpDataOutputStream(transmitter);
   75           outstream.write(new byte[] {'a', 'b'}, 0, 2);
   76           outstream.write('c');
   77           outstream.flush();
   78           
   79           byte[] input = transmitter.getData();
   80           
   81           assertNotNull(input);
   82           byte[] expected = new byte[] {'a', 'b', 'c'};
   83           assertEquals(expected.length, input.length);
   84           for (int i = 0; i < expected.length; i++) {
   85               assertEquals(expected[i], input[i]);
   86           }
   87       }
   88       
   89       public void testClosedCondition() throws Exception {
   90       	HttpDataTransmitterMockup transmitter = new HttpDataTransmitterMockup();
   91           HttpDataOutputStream outstream = new HttpDataOutputStream(transmitter);
   92           outstream.close();
   93           outstream.close();
   94           
   95           try {
   96               byte[] tmp = new byte[2];
   97               outstream.write(tmp, 0, tmp.length);
   98               fail("IllegalStateException should have been thrown");
   99           } catch (IllegalStateException e) {
  100               //expected
  101           }
  102           try {
  103               outstream.write('a');
  104               fail("IllegalStateException should have been thrown");
  105           } catch (IllegalStateException e) {
  106               //expected
  107           }
  108           try {
  109               outstream.flush();
  110               fail("IllegalStateException should have been thrown");
  111           } catch (IllegalStateException e) {
  112               //expected
  113           }
  114       }
  115   
  116   }

Home » HttpComponents-Core-4.0.1 » org.apache.http.io » [javadoc | source]