1   /*
2    * $Id: ConnectorCreationTestCase.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.test.config;
12  
13  import org.mule.components.simple.EchoComponent;
14  import org.mule.config.builders.QuickConfigurationBuilder;
15  import org.mule.tck.AbstractMuleTestCase;
16  import org.mule.umo.UMOComponent;
17  import org.mule.umo.UMOException;
18  
19  public class ConnectorCreationTestCase extends AbstractMuleTestCase
20  {
21  
22      public void testAlwaysCreateUsingParamString() throws Exception
23      {
24          QuickConfigurationBuilder builder = new QuickConfigurationBuilder(true);
25          builder.registerEndpoint("test://inbound?createConnector=ALWAYS", "in", true);
26          builder.registerEndpoint("test://outbound?createConnector=ALWAYS", "out", false);
27          UMOComponent c = builder.registerComponent(EchoComponent.class.getName(), "echo", "in", "out", null);
28          assertTrue(!c.getDescriptor().getInboundEndpoint().getConnector().equals(
29              c.getDescriptor().getOutboundEndpoint().getConnector()));
30      }
31  
32      public void testCreateOnce() throws Exception
33      {
34          QuickConfigurationBuilder builder = new QuickConfigurationBuilder(true);
35          builder.registerEndpoint("test://inbound", "in", true);
36          builder.registerEndpoint("test://outbound", "out", false);
37          UMOComponent c = builder.registerComponent(EchoComponent.class.getName(), "echo", "in", "out", null);
38          assertEquals(c.getDescriptor().getInboundEndpoint().getConnector(), c.getDescriptor()
39              .getOutboundEndpoint()
40              .getConnector());
41      }
42  
43      public void testCreateNeverUsingParamString() throws Exception
44      {
45          QuickConfigurationBuilder builder = new QuickConfigurationBuilder(true);
46          try
47          {
48              builder.registerEndpoint("test://inbound?createConnector=NEVER", "in", true);
49              fail("Should fail as there is no existing test connector");
50          }
51          catch (UMOException e)
52          {
53              // expected
54          }
55      }
56  
57  }