1   /*
2    * $Id: HexStringByteArrayTransformersTestCase.java 7963 2007-08-21 08:53:15Z dirk.olmes $
3    * --------------------------------------------------------------------------------------
4    * Copyright (c) MuleSource, Inc.  All rights reserved.  http://www.mulesource.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.transformers.simple;
12  
13  import org.mule.tck.AbstractTransformerTestCase;
14  import org.mule.umo.transformer.TransformerException;
15  import org.mule.umo.transformer.UMOTransformer;
16  
17  import java.util.Arrays;
18  
19  public class HexStringByteArrayTransformersTestCase extends AbstractTransformerTestCase
20  {
21  
22      public UMOTransformer getTransformer()
23      {
24          return new HexStringToByteArray();
25      }
26  
27      public UMOTransformer getRoundTripTransformer()
28      {
29          return new ByteArrayToHexString();
30      }
31  
32      public Object getTestData()
33      {
34          return "01020aff";
35      }
36  
37      public Object getResultData()
38      {
39          return new byte[]{1, 2, 10, (byte)0xff};
40      }
41  
42      // @Override
43      public boolean compareResults(Object src, Object result)
44      {
45          if (src == null && result == null)
46          {
47              return true;
48          }
49          if (src == null || result == null)
50          {
51              return false;
52          }
53          return Arrays.equals((byte[])src, (byte[])result);
54      }
55  
56      // @Override
57      public boolean compareRoundtripResults(Object src, Object result)
58      {
59          if (src == null && result == null)
60          {
61              return true;
62          }
63          if (src == null || result == null)
64          {
65              return false;
66          }
67          return src.equals(result);
68      }
69  
70      // extra test for uppercase output
71      public void testUppercase() throws TransformerException
72      {
73          ByteArrayToHexString t = new ByteArrayToHexString();
74          t.setUpperCase(true);
75  
76          assertEquals(((String)getTestData()).toUpperCase(), t.transform(getResultData()));
77      }
78  
79  }