View Javadoc

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