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 static org.junit.Assert.fail;
10  
11  import org.mule.api.lifecycle.InitialisationException;
12  import org.mule.api.transformer.Transformer;
13  
14  import java.io.UnsupportedEncodingException;
15  
16  /**
17   * Tests {@link GZipCompressTransformer} and its counterpart, the {@link GZipUncompressTransformer} with raw bytes as input.
18   */
19  public class GZipTransformerRawBytesTestCase extends GZipTransformerTestCase
20  {
21  
22      @Override
23      public Object getResultData()
24      {
25          try
26          {
27              return strat.compressByteArray((byte[]) this.getTestData());
28          }
29          catch (Exception e)
30          {
31              fail(e.getMessage());
32              return null;
33          }
34      }
35  
36      @Override
37      public Object getTestData()
38      {
39          try
40          {
41              return ((String) super.getTestData()).getBytes("UTF8");
42          }
43          catch (UnsupportedEncodingException uex)
44          {
45              fail(uex.getMessage());
46              return null;
47          }
48      }
49  
50      @Override
51      public Transformer getRoundTripTransformer()
52      {
53          GZipUncompressTransformer transformer = new GZipUncompressTransformer();
54          transformer.setMuleContext(muleContext);
55  
56          try
57          {
58              transformer.initialise();
59          }
60          catch (InitialisationException e)
61          {
62              fail(e.getMessage());
63          }
64  
65          return transformer;
66      }
67  
68      @Override
69      public void doTestBadReturnType(Transformer tran, Object src) throws Exception
70      {
71          /*
72           * Disabled, otherwise the test for invalid return types would fail. The
73           * "invalid" class that is configured as returnType by the test harness would
74           * actually be a valid return type for our roundTripTransformer.
75           */
76      }
77  
78  }