1   /*
2    * $Id: FileToStringTestCase.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.providers.file.transformers;
12  
13  import org.mule.tck.AbstractTransformerTestCase;
14  import org.mule.umo.transformer.TransformerException;
15  import org.mule.umo.transformer.UMOTransformer;
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      /*
32       * (non-Javadoc)
33       * 
34       * @see org.mule.tck.AbstractTransformerTestCase#doSetUp()
35       */
36      protected void doSetUp() throws Exception
37      {
38          super.doSetUp();
39          _testData = FileUtils.newFile(SystemUtils.JAVA_IO_TMPDIR, "FileToStringTestData");
40          FileWriter fw = new FileWriter(_testData);
41          fw.write(_resultData);
42          fw.close();
43      }
44  
45      /*
46       * (non-Javadoc)
47       * 
48       * @see org.mule.tck.AbstractTransformerTestCase#doTearDown()
49       */
50      protected void doTearDown() throws Exception
51      {
52          assertTrue(_testData.delete());
53          super.doTearDown();
54      }
55  
56      /*
57       * (non-Javadoc)
58       * 
59       * @see org.mule.tck.AbstractTransformerTestCase#getResultData()
60       */
61      public Object getResultData()
62      {
63          return _resultData;
64      }
65  
66      /*
67       * (non-Javadoc)
68       * 
69       * @see org.mule.tck.AbstractTransformerTestCase#getRoundTripTransformer()
70       */
71      public UMOTransformer getRoundTripTransformer() throws Exception
72      {
73          return null;
74      }
75  
76      /*
77       * (non-Javadoc)
78       * 
79       * @see org.mule.tck.AbstractTransformerTestCase#getTestData()
80       */
81      public Object getTestData()
82      {
83          return _testData;
84      }
85  
86      /*
87       * (non-Javadoc)
88       * 
89       * @see org.mule.tck.AbstractTransformerTestCase#getTransformer()
90       */
91      public UMOTransformer getTransformer() throws Exception
92      {
93          return new FileToString();
94      }
95  
96      /**
97       * Transform with a wrong encoding should result in an Exception to be thrown
98       */
99      public void testTransformExcEnc() throws Exception
100     {
101         try
102         {
103             FileToString fts = (FileToString)getTransformer();
104             fts.doTransform(getTestData(), "NO-SUCH_ENCODING");
105             fail("Should fail when the specified encoding is not supported");
106         }
107         catch (TransformerException tfe)
108         {
109             // Expected
110         }
111     }
112 
113 }