View Javadoc
1   /*
2    * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.com
3    * The software in this package is published under the terms of the CPAL v1.0
4    * license, a copy of which has been included with this distribution in the
5    * LICENSE.txt file.
6    */
7   package org.mule.transport.file;
8   
9   import org.mule.api.MuleMessage;
10  import org.mule.api.transport.MuleMessageFactory;
11  
12  import org.junit.Test;
13  
14  import static org.junit.Assert.assertEquals;
15  import static org.junit.Assert.assertNotNull;
16  
17  public class FileMuleMessageFactoryTestCase extends AbstractFileMuleMessageFactoryTestCase
18  {
19      @Override
20      protected MuleMessageFactory doCreateMuleMessageFactory()
21      {
22          return new FileMuleMessageFactory(muleContext);
23      }
24  
25      @Override
26      protected Object getValidTransportMessage()
27      {
28          return tempFile;
29      }
30  
31      @Test
32      public void testMessageProperties() throws Exception
33      {
34          MuleMessageFactory factory = createMuleMessageFactory();
35  
36          MuleMessage message = factory.create(getValidTransportMessage(), encoding);
37          assertNotNull(message);
38          assertMessageProperties(message);
39      }
40  
41      @Test
42      public void testCreateMessageFromStream() throws Exception
43      {
44          MuleMessageFactory factory = createMuleMessageFactory();
45  
46          ReceiverFileInputStream stream = new ReceiverFileInputStream(tempFile, false, null);
47          MuleMessage message = factory.create(stream, encoding);
48          assertNotNull(message);
49          assertMessageProperties(message);
50      }
51  
52      private void assertMessageProperties(MuleMessage message)
53      {
54          assertEquals(tempFile.getName(),
55              message.getOutboundProperty(FileConnector.PROPERTY_ORIGINAL_FILENAME));
56          assertEquals(tempFile.getParent(), message.getOutboundProperty(FileConnector.PROPERTY_DIRECTORY));
57          assertEquals(0l, message.getOutboundProperty(FileConnector.PROPERTY_FILE_SIZE));
58      }
59  }
60  
61