View Javadoc

1   /*
2    * $Id: IndirectReceiveMule1842TestCase.java 22491 2011-07-21 10:04:30Z claude.mamo $
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.issues;
12  
13  import static org.junit.Assert.assertNotNull;
14  
15  import org.mule.api.MuleMessage;
16  import org.mule.api.endpoint.InboundEndpoint;
17  import org.mule.api.lifecycle.Startable;
18  import org.mule.api.lifecycle.Stoppable;
19  import org.mule.api.service.Service;
20  import org.mule.api.source.CompositeMessageSource;
21  import org.mule.construct.Flow;
22  import org.mule.module.client.MuleClient;
23  import org.mule.transport.file.AbstractFileFunctionalTestCase;
24  
25  import java.io.File;
26  
27  import org.junit.Test;
28  
29  /**
30   * This used to be part of FileFunctionalTest; moved here to allow isolation of
31   * individual case.
32   */
33  public class IndirectReceiveMule1842TestCase extends AbstractFileFunctionalTestCase
34  {
35  
36      public IndirectReceiveMule1842TestCase(ConfigVariant variant, String configResources)
37      {
38          super(variant, configResources);
39      }
40  
41      @Test
42      public void testIndirectRequest() throws Exception
43      {
44          File target = initForRequest();
45  
46          // add a receiver endpoint that will poll the readFromDirectory
47          Object relay = muleContext.getRegistry().lookupObject("relay");
48          assertNotNull(relay);
49          String url = fileToUrl(target) + "?connector=receiveConnector";
50          logger.debug(url);
51  
52          InboundEndpoint endpoint = muleContext.getEndpointFactory().getInboundEndpoint(url);
53  
54          if (variant.equals(ConfigVariant.FLOW))
55          {
56              ((CompositeMessageSource) ((Flow) relay).getMessageSource()).addSource(endpoint);
57          }
58          else
59          {
60              ((CompositeMessageSource) ((Service) relay).getMessageSource()).addSource(endpoint);
61          }
62  
63          ((Stoppable) relay).stop();
64          ((Startable) relay).start();
65  
66          // then read from the queue that the polling receiver will write to
67          MuleClient client = new MuleClient(muleContext);
68          MuleMessage message = client.request("receive", 3000);
69          checkReceivedMessage(message);
70      }
71  
72  }