View Javadoc

1   /*
2    * $Id: StdioNamespaceHandlerTestCase.java 22468 2011-07-20 09:24:03Z justin.calleja $
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  package org.mule.transport.stdio;
11  
12  import static org.junit.Assert.assertEquals;
13  import static org.junit.Assert.assertNotNull;
14  import static org.junit.Assert.assertTrue;
15  
16  import java.util.Arrays;
17  import java.util.Collection;
18  
19  import org.junit.Test;
20  import org.junit.runners.Parameterized.Parameters;
21  import org.mule.api.endpoint.ImmutableEndpoint;
22  import org.mule.tck.AbstractServiceAndFlowTestCase;
23  
24  public class StdioNamespaceHandlerTestCase extends AbstractServiceAndFlowTestCase
25  {
26  
27      public StdioNamespaceHandlerTestCase(ConfigVariant variant, String configResources)
28      {
29          super(variant, configResources);
30      }
31      
32      @Parameters
33      public static Collection<Object[]> parameters()
34      {
35          return Arrays.asList(new Object[][]{
36              {ConfigVariant.SERVICE, "stdio-namespace-config-service.xml"},
37              {ConfigVariant.FLOW, "stdio-namespace-config-flow.xml"}
38          });
39      }
40      
41      @Test
42      public void testConfig() throws Exception
43      {
44          PromptStdioConnector c =
45                  (PromptStdioConnector) muleContext.getRegistry().lookupConnector("stdioConnector");
46          assertNotNull(c);
47  
48          assertEquals(1234, c.getMessageDelayTime());
49          assertEquals("abc", c.getOutputMessage());
50          assertEquals("edc", c.getPromptMessage());
51          assertEquals("456", c.getPromptMessageCode());
52          assertEquals("dummy-messages", c.getResourceBundle());
53  
54          assertTrue(c.isConnected());
55          assertTrue(c.isStarted());
56      }
57  
58      @Test
59      public void testNoBundle() throws Exception
60      {
61          PromptStdioConnector c =
62                  (PromptStdioConnector)muleContext.getRegistry().lookupConnector("noBundleConnector");
63          assertNotNull(c);
64  
65          assertEquals(1234, c.getMessageDelayTime());
66          assertEquals("abc", c.getOutputMessage());
67          assertEquals("bcd", c.getPromptMessage());
68  
69          assertTrue(c.isConnected());
70          assertTrue(c.isStarted());
71      }
72  
73      @Test
74      public void testSystemAttributeMap()
75      {
76          testEndpointAttribute("in", "system.in");
77          testEndpointAttribute("out", "system.out");
78          testEndpointAttribute("err", "system.err");
79      }
80  
81      protected void testEndpointAttribute(String name, String address)
82      {
83          ImmutableEndpoint endpoint = (ImmutableEndpoint) muleContext.getRegistry().lookupObject(name);
84          assertNotNull("Null " + name, endpoint);
85          assertEquals(address, endpoint.getEndpointURI().getAddress());
86      }
87  
88  }