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.MessageExchangePattern;
10  import org.mule.api.endpoint.InboundEndpoint;
11  import org.mule.endpoint.DefaultInboundEndpoint;
12  import org.mule.tck.junit4.AbstractMuleContextTestCase;
13  
14  import java.util.HashMap;
15  import java.util.Map;
16  
17  import org.junit.Test;
18  
19  import static org.junit.Assert.assertEquals;
20  
21  public class FileMessageRequesterTestCase extends AbstractMuleContextTestCase
22  {
23      
24      private static final String CONNECTOR_MOVE_DIR = "connector/moveto";
25      private static final String ENDPOINT_MOVE_DIR = "endpoint/moveto";
26      private static final String CONNECTOR_MOVE_TO_PATTERN = "#connector";
27      private static final String ENDPOINT_MOVE_TO_PATTERN = "#endpoint";
28  
29      private FileConnector connector;
30      
31      @Override
32      protected void doSetUp() throws Exception
33      {
34          super.doSetUp();
35          
36          connector = new FileConnector(muleContext);
37          connector.setMoveToDirectory(CONNECTOR_MOVE_DIR);        
38          connector.setMoveToPattern(CONNECTOR_MOVE_TO_PATTERN);
39      }
40  
41      @Test
42      public void testMoveDirectoryFromConnector() throws Exception
43      {
44          FileMessageRequester requester = new FileMessageRequester(createEndpoint());        
45          assertEquals(CONNECTOR_MOVE_DIR, requester.getMoveDirectory());
46      }
47      
48      @Test
49      public void testMoveDirectoryFromEndpoint() throws Exception
50      {
51          InboundEndpoint endpoint = createEndpoint(FileConnector.PROPERTY_MOVE_TO_DIRECTORY, 
52              ENDPOINT_MOVE_DIR);
53          FileMessageRequester requester = new FileMessageRequester(endpoint);
54          assertEquals(ENDPOINT_MOVE_DIR, requester.getMoveDirectory());
55      }
56      
57      @Test
58      public void testMoveToPatternFromConnector() throws Exception
59      {
60          FileMessageRequester requester = new FileMessageRequester(createEndpoint());
61          assertEquals(CONNECTOR_MOVE_TO_PATTERN, requester.getMoveToPattern());
62      }
63      
64      @Test
65      public void testMoveToPatternFromEndpoint() throws Exception
66      {
67          InboundEndpoint endpoint = createEndpoint(FileConnector.PROPERTY_MOVE_TO_PATTERN,
68              ENDPOINT_MOVE_TO_PATTERN);
69          FileMessageRequester requester = new FileMessageRequester(endpoint);
70          assertEquals(ENDPOINT_MOVE_TO_PATTERN, requester.getMoveToPattern());
71      }
72      
73      private InboundEndpoint createEndpoint()
74      {
75          return createEndpoint(null, null);
76      }
77  
78      private InboundEndpoint createEndpoint(Object key, Object value)
79      {
80          Map<Object, Object> properties = new HashMap<Object, Object>();
81          if (key != null)
82          {
83              properties.put(key, value);
84          }
85          
86          return new DefaultInboundEndpoint(connector, null, null, properties, null, 
87              false, MessageExchangePattern.ONE_WAY, 42, null, null, null, 
88              muleContext, null, null, null, null, false, null);
89      }
90  }