View Javadoc

1   /*
2    * $Id: FileMuleMessageFactoryTestCase.java 22387 2011-07-12 03:53:36Z dirk.olmes $
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;
12  
13  import org.mule.api.MuleMessage;
14  import org.mule.api.transport.MuleMessageFactory;
15  
16  import org.junit.Test;
17  
18  import static org.junit.Assert.assertEquals;
19  import static org.junit.Assert.assertNotNull;
20  
21  public class FileMuleMessageFactoryTestCase extends AbstractFileMuleMessageFactoryTestCase
22  {
23      @Override
24      protected MuleMessageFactory doCreateMuleMessageFactory()
25      {
26          return new FileMuleMessageFactory(muleContext);
27      }
28  
29      @Override
30      protected Object getValidTransportMessage()
31      {
32          return tempFile;
33      }
34  
35      @Test
36      public void testMessageProperties() throws Exception
37      {
38          MuleMessageFactory factory = createMuleMessageFactory();
39  
40          MuleMessage message = factory.create(getValidTransportMessage(), encoding);
41          assertNotNull(message);
42          assertMessageProperties(message);
43      }
44  
45      @Test
46      public void testCreateMessageFromStream() throws Exception
47      {
48          MuleMessageFactory factory = createMuleMessageFactory();
49  
50          ReceiverFileInputStream stream = new ReceiverFileInputStream(tempFile, false, null);
51          MuleMessage message = factory.create(stream, encoding);
52          assertNotNull(message);
53          assertMessageProperties(message);
54      }
55  
56      private void assertMessageProperties(MuleMessage message)
57      {
58          assertEquals(tempFile.getName(),
59              message.getOutboundProperty(FileConnector.PROPERTY_ORIGINAL_FILENAME));
60          assertEquals(tempFile.getParent(), message.getOutboundProperty(FileConnector.PROPERTY_DIRECTORY));
61          assertEquals(0l, message.getOutboundProperty(FileConnector.PROPERTY_FILE_SIZE));
62      }
63  }
64  
65