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.stdio;
8   
9   import org.mule.api.endpoint.InboundEndpoint;
10  import org.mule.api.lifecycle.CreateException;
11  import org.mule.api.service.Service;
12  import org.mule.api.transport.MessageReceiver;
13  import org.mule.tck.testmodels.fruit.Orange;
14  import org.mule.transport.AbstractMessageReceiverTestCase;
15  
16  import org.junit.Test;
17  
18  import static org.junit.Assert.assertNotNull;
19  import static org.junit.Assert.assertTrue;
20  
21  public class StdioMessageReceiverTestCase extends AbstractMessageReceiverTestCase
22  {
23  
24      @Test
25      public void testReceiver() throws Exception
26      {
27          // FIX A bit hard testing receive from a unit test as we need to reg
28          // listener etc
29          // file endpoint functions tests for this
30      }
31  
32      @Test
33      public void testOtherProperties() throws Exception
34      {
35          StdioMessageReceiver receiver = (StdioMessageReceiver) getMessageReceiver();
36  
37          Service service = getTestService("orange", Orange.class);
38          assertNotNull(service);
39  
40          endpoint.getConnector().start();
41  
42          receiver.setFrequency(1001);
43          receiver.setInputStream(System.in);
44  
45          assertTrue(receiver.getFrequency() == 1001);
46          receiver.setFrequency(0);
47          assertTrue(receiver.getFrequency() == StdioMessageReceiver.DEFAULT_POLL_FREQUENCY);
48      }
49  
50      public MessageReceiver getMessageReceiver() throws CreateException
51      {
52          return new StdioMessageReceiver(endpoint.getConnector(), service, endpoint, 1000);
53      }
54  
55      public InboundEndpoint getEndpoint() throws Exception
56      {
57          return muleContext.getEndpointFactory().getInboundEndpoint("stdio://System");
58      }
59  }