View Javadoc

1   /*
2    * $Id: GZipTransformerTestCase.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.lifecycle.InitialisationException;
14  import org.mule.api.transformer.Transformer;
15  import org.mule.transformer.AbstractTransformerTestCase;
16  import org.mule.transformer.types.DataTypeFactory;
17  import org.mule.util.SerializationUtils;
18  import org.mule.util.compression.GZipCompression;
19  
20  import static org.junit.Assert.fail;
21  
22  public class GZipTransformerTestCase extends AbstractTransformerTestCase
23  {
24      protected static final String TEST_DATA = "the quick brown fox jumped over the lazy dog the quick brown fox jumped over the lazy dog the quick brown fox jumped over the lazy dog";
25      protected GZipCompression strat;
26  
27      @Override
28      protected void doSetUp() throws Exception
29      {
30          strat = new GZipCompression();
31      }
32  
33      @Override
34      public Object getResultData()
35      {
36          try
37          {
38              return strat.compressByteArray(SerializationUtils.serialize(TEST_DATA));
39          }
40          catch (Exception e)
41          {
42              fail(e.getMessage());
43              return null;
44          }
45      }
46  
47      @Override
48      public Object getTestData()
49      {
50          return TEST_DATA;
51      }
52  
53      @Override
54      public Transformer getTransformer()
55      {
56          return new GZipCompressTransformer();
57      }
58  
59      @Override
60      public Transformer getRoundTripTransformer()
61      {
62          GZipUncompressTransformer transformer = new GZipUncompressTransformer();
63          transformer.setMuleContext(muleContext);
64          transformer.setReturnDataType(DataTypeFactory.STRING);
65  
66          try
67          {
68              transformer.initialise();
69          }
70          catch (InitialisationException e)
71          {
72              fail(e.getMessage());
73          }
74  
75          return transformer;
76      }
77  }