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