View Javadoc

1   /*
2    * $Id: DuplicateRegistrationTestCase.java 19191 2010-08-25 21:05:23Z tcarlson $
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.registry;
12  
13  import org.mule.api.registry.RegistrationException;
14  import org.mule.tck.AbstractMuleTestCase;
15  import org.mule.util.StringUtils;
16  
17  import java.util.Collection;
18  
19  public class DuplicateRegistrationTestCase extends AbstractMuleTestCase
20  {
21      public void testComponentAlreadyDefinedThrowsException() throws Exception
22      {
23          Collection components = muleContext.getRegistry().lookupServices();
24          assertEquals(0, components.size());
25          
26          final String componentName = "TEST_COMPONENT_1";
27          getTestService(componentName, Object.class);
28  
29          components = muleContext.getRegistry().lookupServices();
30          assertEquals(1, components.size());
31          
32          // register it again with the same name
33          try
34          {
35              getTestService(componentName, Object.class);
36              fail("Trying to register a service with the same name must have thrown an exception.");
37          }
38          catch (RegistrationException e)
39          {
40              // expected
41              assertTrue("Exception message should contain service name", 
42                         StringUtils.contains(e.getMessage(), componentName));
43          }
44  
45          components = muleContext.getRegistry().lookupServices();
46          assertEquals(1, components.size());
47      }
48  }