View Javadoc

1   /*
2    * $Id: GZipTransformerStreamTestCase.java 22377 2011-07-11 12:41:42Z dirk.olmes $
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  import org.mule.util.SerializationUtils;
15  
16  import java.io.ByteArrayInputStream;
17  import java.io.InputStream;
18  import java.util.Arrays;
19  
20  import org.junit.Test;
21  
22  import static org.junit.Assert.assertEquals;
23  import static org.junit.Assert.assertTrue;
24  
25  public class GZipTransformerStreamTestCase extends GZipTransformerTestCase
26  {
27      
28      @Test
29      public void testStreamingCompression() throws TransformerException
30      {
31          GZipCompressTransformer transformer = new GZipCompressTransformer();
32          
33          InputStream input = new ByteArrayInputStream(SerializationUtils.serialize(TEST_DATA));
34  
35          byte[] expected = (byte[]) this.getResultData();
36          byte[] result = (byte[]) transformer.transform(input);
37          
38          assertTrue(Arrays.equals(expected, result));
39      }
40  
41      @Test
42      public void testStreamingDecompression() throws TransformerException
43      {
44          GZipUncompressTransformer transformer = new GZipUncompressTransformer();
45          transformer.setMuleContext(muleContext);
46          
47          InputStream input = new ByteArrayInputStream((byte[]) this.getResultData());
48          byte[] resultBytes = (byte[]) transformer.transform(input);
49          assertEquals(TEST_DATA, SerializationUtils.deserialize(resultBytes));
50      }
51  
52  }
53  
54