View Javadoc

1   /*
2    * $Id: FileToStringTestCase.java 19191 2010-08-25 21:05:23Z tcarlson $
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.transport.file.transformers;
12  
13  import org.mule.api.transformer.Transformer;
14  import org.mule.api.transformer.TransformerException;
15  import org.mule.transformer.AbstractTransformerTestCase;
16  import org.mule.util.FileUtils;
17  import org.mule.util.SystemUtils;
18  
19  import java.io.File;
20  import java.io.FileWriter;
21  
22  /**
23   * Test case for FileToString transformer
24   */
25  public class FileToStringTestCase extends AbstractTransformerTestCase
26  {
27      FileToString _fts;
28      File _testData = null;
29      final String _resultData = "The dog is on the table, where's the dog?";
30  
31      @Override
32      protected void doSetUp() throws Exception
33      {
34          super.doSetUp();
35          _testData = FileUtils.newFile(SystemUtils.JAVA_IO_TMPDIR, "FileToStringTestData");
36          FileWriter fw = new FileWriter(_testData);
37          fw.write(_resultData);
38          fw.close();
39      }
40  
41      @Override
42      protected void doTearDown() throws Exception
43      {
44          assertTrue(_testData.delete());
45          super.doTearDown();
46      }
47  
48      @Override
49      public Object getResultData()
50      {
51          return _resultData;
52      }
53  
54      @Override
55      public Transformer getRoundTripTransformer() throws Exception
56      {
57          return null;
58      }
59  
60      @Override
61      public Object getTestData()
62      {
63          return _testData;
64      }
65  
66      @Override
67      public Transformer getTransformer() throws Exception
68      {
69          return new FileToString();
70      }
71  
72      /**
73       * Transform with a wrong encoding should result in an Exception to be thrown
74       */
75      public void testTransformExcEnc() throws Exception
76      {
77          try
78          {
79              FileToString fts = (FileToString)getTransformer();
80              fts.doTransform(getTestData(), "NO-SUCH_ENCODING");
81              fail("Should fail when the specified encoding is not supported");
82          }
83          catch (TransformerException tfe)
84          {
85              // Expected
86          }
87      }
88  
89  }