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.issues;
8   
9   import org.mule.api.MuleMessage;
10  import org.mule.api.endpoint.InboundEndpoint;
11  import org.mule.api.service.Service;
12  import org.mule.api.source.CompositeMessageSource;
13  import org.mule.module.client.MuleClient;
14  import org.mule.transport.file.AbstractFileFunctionalTestCase;
15  
16  import java.io.File;
17  
18  import org.junit.Test;
19  
20  import static org.junit.Assert.assertNotNull;
21  
22  /**
23   * This used to be part of FileFunctionalTest; moved here to allow isolation of individual case.
24   */
25  public class IndirectReceiveMule1842TestCase extends AbstractFileFunctionalTestCase
26  {
27  
28      @Test
29      public void testIndirectRequest() throws Exception
30      {
31          File target = initForRequest();
32  
33          // add a receiver endpoint that will poll the readFromDirectory
34          Service relay = muleContext.getRegistry().lookupService("relay");
35          assertNotNull(relay);
36          String url = fileToUrl(target) + "?connector=receiveConnector";
37          logger.debug(url);
38          
39          InboundEndpoint endpoint = 
40              muleContext.getEndpointFactory().getInboundEndpoint(url);
41          ((CompositeMessageSource) relay.getMessageSource()).addSource(endpoint);
42          relay.stop();
43          relay.start();
44  
45          // then read from the queue that the polling receiver will write to
46          MuleClient client = new MuleClient(muleContext);
47          MuleMessage message = client.request("receive", 3000);
48          checkReceivedMessage(message);
49      }
50  
51  }