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.junit4.AbstractMuleContextTestCase;
15 import org.mule.util.StringUtils;
16
17 import java.util.Collection;
18
19 import org.junit.Test;
20
21 import static org.junit.Assert.assertEquals;
22 import static org.junit.Assert.assertTrue;
23 import static org.junit.Assert.fail;
24
25 public class DuplicateRegistrationTestCase extends AbstractMuleContextTestCase
26 {
27 @Test
28 public void testComponentAlreadyDefinedThrowsException() throws Exception
29 {
30 Collection components = muleContext.getRegistry().lookupServices();
31 assertEquals(0, components.size());
32
33 final String componentName = "TEST_COMPONENT_1";
34 getTestService(componentName, Object.class);
35
36 components = muleContext.getRegistry().lookupServices();
37 assertEquals(1, components.size());
38
39
40 try
41 {
42 getTestService(componentName, Object.class);
43 fail("Trying to register a service with the same name must have thrown an exception.");
44 }
45 catch (RegistrationException e)
46 {
47
48 assertTrue("Exception message should contain service name",
49 StringUtils.contains(e.getMessage(), componentName));
50 }
51
52 components = muleContext.getRegistry().lookupServices();
53 assertEquals(1, components.size());
54 }
55 }