View Javadoc

1   /*
2    * $Id: FileMessageRequesterTestCase.java 19191 2010-08-25 21:05:23Z tcarlson $
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.AbstractMuleTestCase;
17  
18  import java.util.HashMap;
19  import java.util.Map;
20  
21  public class FileMessageRequesterTestCase extends AbstractMuleTestCase
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      public void testMoveDirectoryFromConnector() throws Exception
42      {
43          FileMessageRequester requester = new FileMessageRequester(createEndpoint());        
44          assertEquals(CONNECTOR_MOVE_DIR, requester.getMoveDirectory());
45      }
46      
47      public void testMoveDirectoryFromEndpoint() throws Exception
48      {
49          InboundEndpoint endpoint = createEndpoint(FileConnector.PROPERTY_MOVE_TO_DIRECTORY, 
50              ENDPOINT_MOVE_DIR);
51          FileMessageRequester requester = new FileMessageRequester(endpoint);
52          assertEquals(ENDPOINT_MOVE_DIR, requester.getMoveDirectory());
53      }
54      
55      public void testMoveToPatternFromConnector() throws Exception
56      {
57          FileMessageRequester requester = new FileMessageRequester(createEndpoint());
58          assertEquals(CONNECTOR_MOVE_TO_PATTERN, requester.getMoveToPattern());
59      }
60      
61      public void testMoveToPatternFromEndpoint() throws Exception
62      {
63          InboundEndpoint endpoint = createEndpoint(FileConnector.PROPERTY_MOVE_TO_PATTERN,
64              ENDPOINT_MOVE_TO_PATTERN);
65          FileMessageRequester requester = new FileMessageRequester(endpoint);
66          assertEquals(ENDPOINT_MOVE_TO_PATTERN, requester.getMoveToPattern());
67      }
68      
69      private InboundEndpoint createEndpoint()
70      {
71          return createEndpoint(null, null);
72      }
73  
74      private InboundEndpoint createEndpoint(Object key, Object value)
75      {
76          Map<Object, Object> properties = new HashMap<Object, Object>();
77          if (key != null)
78          {
79              properties.put(key, value);
80          }
81          
82          return new DefaultInboundEndpoint(connector, null, null, properties, null, 
83              false, MessageExchangePattern.ONE_WAY, 42, null, null, null, 
84              muleContext, null, null, null, null, false, null);
85      }
86  }