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