View Javadoc

1   /*
2    * $Id: GZipTransformerStreamTestCase.java 19191 2010-08-25 21:05:23Z tcarlson $
3    * --------------------------------------------------------------------------------------
4    * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.com
5    *
6    * The software in this package is published under the terms of the CPAL v1.0
7    * license, a copy of which has been included with this distribution in the
8    * LICENSE.txt file.
9    */
10  
11  package org.mule.transformer.compression;
12  
13  import org.mule.api.transformer.TransformerException;
14  
15  import java.io.ByteArrayInputStream;
16  import java.io.InputStream;
17  import java.util.Arrays;
18  
19  import org.apache.commons.lang.SerializationUtils;
20  
21  public class GZipTransformerStreamTestCase extends GZipTransformerTestCase
22  {
23      
24      public void testStreamingCompression() throws TransformerException
25      {
26          GZipCompressTransformer transformer = new GZipCompressTransformer();
27          
28          InputStream input = new ByteArrayInputStream(SerializationUtils.serialize(TEST_DATA));
29  
30          byte[] expected = (byte[]) this.getResultData();
31          byte[] result = (byte[]) transformer.transform(input);
32          
33          assertTrue(Arrays.equals(expected, result));
34      }
35  
36      public void testStreamingDecompression() throws TransformerException
37      {
38          GZipUncompressTransformer transformer = new GZipUncompressTransformer();
39          
40          InputStream input = new ByteArrayInputStream((byte[]) this.getResultData());
41          byte[] resultBytes = (byte[]) transformer.transform(input);
42          assertEquals(TEST_DATA, SerializationUtils.deserialize(resultBytes));
43      }
44  
45  }
46  
47