View Javadoc

1   /*
2    * $Id: GZipTransformerTestCase.java 20321 2010-11-24 15:21:24Z dfeist $
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.compression.GZipCompression;
18  
19  import org.apache.commons.lang.SerializationUtils;
20  
21  public class GZipTransformerTestCase extends AbstractTransformerTestCase
22  {
23      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";
24      protected GZipCompression strat;
25  
26      @Override
27      protected void doSetUp() throws Exception
28      {
29          strat = new GZipCompression();
30      }
31  
32      @Override
33      public Object getResultData()
34      {
35          try
36          {
37              return strat.compressByteArray(SerializationUtils.serialize(TEST_DATA));
38          }
39          catch (Exception e)
40          {
41              fail(e.getMessage());
42              return null;
43          }
44      }
45  
46      @Override
47      public Object getTestData()
48      {
49          return TEST_DATA;
50      }
51  
52      @Override
53      public Transformer getTransformer()
54      {
55          return new GZipCompressTransformer();
56      }
57  
58      @Override
59      public Transformer getRoundTripTransformer()
60      {
61          GZipUncompressTransformer transformer = new GZipUncompressTransformer();
62          transformer.setReturnDataType(DataTypeFactory.STRING);
63  
64          try
65          {
66              transformer.initialise();
67          }
68          catch (InitialisationException e)
69          {
70              fail(e.getMessage());
71          }
72  
73          return transformer;
74      }
75  }