View Javadoc

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