View Javadoc

1   /*
2    * $Id: FtpEncodingFunctionalTestCase.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.ftp;
12  
13  import org.mule.api.MuleMessage;
14  import org.mule.module.client.MuleClient;
15  import org.mule.util.FileUtils;
16  
17  import java.io.File;
18  
19  public class FtpEncodingFunctionalTestCase extends AbstractFtpServerTestCase
20  {
21  
22      private static final String TEST_MESSAGE_EUC_JP_ENCODED = "\u3053";
23      private static final int FIVE_SECONDS_TIMEOUT = 5000;
24      private static final String ENCODING = "EUC-JP";
25      private static final int FTP_SERVER_PORT = 60200;
26  
27      private File testDataFile;
28  
29      public FtpEncodingFunctionalTestCase()
30      {
31          super(FTP_SERVER_PORT);
32      }
33  
34      @Override
35      protected String getConfigResources()
36      {
37          return "ftp-encoding-functional-config.xml";
38      }
39  
40      public void testReadingFileWithEucJpEncodingGetsTheRightText() throws Exception
41      {
42          File tmpDir = new File(FTP_SERVER_BASE_DIR);
43          testDataFile = createDataFile(tmpDir, ENCODING, TEST_MESSAGE_EUC_JP_ENCODED);
44  
45          MuleClient client = new MuleClient(muleContext);
46          MuleMessage message = client.request("vm://receive", FIVE_SECONDS_TIMEOUT);
47  
48          assertNotNull(message);
49          assertEquals(ENCODING, message.getEncoding());
50          assertEquals(TEST_MESSAGE_EUC_JP_ENCODED, message.getPayloadAsString());
51      }
52  
53      private File createDataFile(File folder, String encoding, final String testMessage) throws Exception
54      {
55          File target = File.createTempFile("mule-file-test-", ".txt", folder);
56          target.deleteOnExit();
57          FileUtils.writeStringToFile(target, testMessage, encoding);
58  
59          return target;
60      }
61  
62      @Override
63      protected void doTearDown() throws Exception
64      {
65          super.doTearDown();
66          FileUtils.deleteTree(testDataFile);
67      }
68  }