1   /*
2    * $Id: StreamMessageReceiverTestCase.java 7976 2007-08-21 14:26:13Z dirk.olmes $
3    * --------------------------------------------------------------------------------------
4    * Copyright (c) MuleSource, Inc.  All rights reserved.  http://www.mulesource.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.providers.stream;
12  
13  import org.mule.impl.DefaultExceptionStrategy;
14  import org.mule.impl.MuleDescriptor;
15  import org.mule.impl.endpoint.MuleEndpoint;
16  import org.mule.tck.providers.AbstractMessageReceiverTestCase;
17  import org.mule.tck.testmodels.fruit.Orange;
18  import org.mule.umo.UMOComponent;
19  import org.mule.umo.endpoint.UMOEndpoint;
20  import org.mule.umo.lifecycle.InitialisationException;
21  import org.mule.umo.provider.UMOConnector;
22  import org.mule.umo.provider.UMOMessageReceiver;
23  
24  import com.mockobjects.dynamic.Mock;
25  
26  public class StreamMessageReceiverTestCase extends AbstractMessageReceiverTestCase
27  {
28  
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      public void testOtherProperties() throws Exception
37      {
38          StreamMessageReceiver receiver = (StreamMessageReceiver)getMessageReceiver();
39  
40          MuleDescriptor descriptor = getTestDescriptor("orange", Orange.class.getName());
41          assertNotNull(descriptor);
42  
43          UMOComponent component = getTestComponent(descriptor);
44          assertNotNull(component);
45  
46          endpoint.getConnector().startConnector();
47          Mock connector = new Mock(UMOConnector.class);
48          connector.expectAndReturn("getExceptionListener", new DefaultExceptionStrategy());
49  
50          receiver.setFrequency(1001);
51          receiver.setInputStream(System.in);
52  
53          assertTrue(receiver.getFrequency() == 1001);
54          receiver.setFrequency(0);
55          assertTrue(receiver.getFrequency() == StreamMessageReceiver.DEFAULT_POLL_FREQUENCY);
56      }
57  
58      /*
59       * (non-Javadoc)
60       * 
61       * @see org.mule.tck.providers.AbstractMessageReceiverTestCase#getMessageReceiver()
62       */
63      public UMOMessageReceiver getMessageReceiver() throws InitialisationException
64      {
65          return new StreamMessageReceiver(endpoint.getConnector(), component, endpoint, 1000);
66      }
67  
68      public UMOEndpoint getEndpoint() throws Exception
69      {
70          endpoint = new MuleEndpoint("stream://System", true);
71          return endpoint;
72      }
73  }