1
2
3
4
5
6
7
8
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
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
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 }