View Javadoc

1   /*
2    * $Id: FtpEncodingFunctionalTestCase.java 22491 2011-07-21 10:04:30Z claude.mamo $
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 static org.junit.Assert.assertEquals;
14  import static org.junit.Assert.assertNotNull;
15  
16  import org.mule.api.MuleMessage;
17  import org.mule.module.client.MuleClient;
18  import org.mule.util.FileUtils;
19  
20  import java.io.File;
21  import java.util.Arrays;
22  import java.util.Collection;
23  
24  import org.junit.Test;
25  import org.junit.runners.Parameterized.Parameters;
26  
27  public class FtpEncodingFunctionalTestCase extends AbstractFtpServerTestCase
28  {
29  
30      private static final String TEST_MESSAGE_EUC_JP_ENCODED = "\u3053";
31      private static final int FIVE_SECONDS_TIMEOUT = 5000;
32      private static final String ENCODING = "EUC-JP";
33  
34      private File testDataFile;
35  
36      public FtpEncodingFunctionalTestCase(ConfigVariant variant, String configResources)
37      {
38          super(variant, configResources);
39      }
40  
41      @Parameters
42      public static Collection<Object[]> parameters()
43      {
44          return Arrays.asList(new Object[][]{
45              {ConfigVariant.SERVICE, "ftp-encoding-functional-config-service.xml"},
46              {ConfigVariant.FLOW, "ftp-encoding-functional-config-flow.xml"}
47          });
48      }      
49      
50      @Test
51      public void testReadingFileWithEucJpEncodingGetsTheRightText() throws Exception
52      {
53          File tmpDir = new File(FTP_SERVER_BASE_DIR);
54          testDataFile = createDataFile(tmpDir, ENCODING, TEST_MESSAGE_EUC_JP_ENCODED);
55  
56          MuleClient client = new MuleClient(muleContext);
57          MuleMessage message = client.request("vm://receive", FIVE_SECONDS_TIMEOUT);
58  
59          assertNotNull(message);
60          assertEquals(ENCODING, message.getEncoding());
61          assertEquals(TEST_MESSAGE_EUC_JP_ENCODED, message.getPayloadAsString());
62      }
63  
64      private File createDataFile(File folder, String encoding, final String testMessage) throws Exception
65      {
66          File target = File.createTempFile("mule-file-test-", ".txt", folder);
67          target.deleteOnExit();
68          FileUtils.writeStringToFile(target, testMessage, encoding);
69  
70          return target;
71      }
72  
73      @Override
74      protected void doTearDown() throws Exception
75      {
76          super.doTearDown();
77          FileUtils.deleteTree(testDataFile);
78      }
79  }