1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.kim.service;
17
18 import org.junit.Test;
19 import org.kuali.rice.core.api.exception.RiceIllegalArgumentException;
20 import org.kuali.rice.kim.api.services.KimApiServiceLocator;
21 import org.kuali.rice.kim.api.type.KimType;
22 import org.kuali.rice.kim.framework.services.KimFrameworkServiceLocator;
23 import org.kuali.rice.kim.framework.type.KimTypeService;
24 import org.kuali.rice.kim.test.KIMTestCase;
25 import org.kuali.rice.kim.util.KimConstants;
26 import org.kuali.rice.kns.kim.type.DataDictionaryTypeServiceBase;
27
28 import javax.xml.namespace.QName;
29
30 import static org.junit.Assert.*;
31
32
33
34
35
36
37
38 public class KIMServiceLocatorInternalTest extends KIMTestCase {
39
40 @Test
41 public void testGetKimTypeService_KimType() {
42
43
44 try {
45 KimTypeService typeService1 = KimFrameworkServiceLocator.getKimTypeService((KimType) null);
46 assertTrue("should have thrown exception and never got here", false);
47 } catch (IllegalArgumentException e) {
48 }
49
50
51
52 KimType.Builder nullKimType = KimType.Builder.create();
53 nullKimType.setServiceName(null);
54 KimTypeService typeService2 = KimFrameworkServiceLocator.getKimTypeService(nullKimType.build());
55 assertNotNull("type service shoudl have been found", typeService2);
56 assertEquals("should be the default kim type", DataDictionaryTypeServiceBase.class, typeService2.getClass());
57
58
59
60 KimType.Builder emptyKimType = KimType.Builder.create();
61 nullKimType.setServiceName("");
62 KimTypeService typeService3 = KimFrameworkServiceLocator.getKimTypeService(emptyKimType.build());
63 assertNotNull("type service should have been found", typeService3);
64 assertEquals("should be the default kim type", DataDictionaryTypeServiceBase.class, typeService3.getClass());
65
66
67
68 KimType permissionKimType = KimApiServiceLocator.getKimTypeInfoService().findKimTypeByNameAndNamespace(KimConstants.NAMESPACE_CODE, "Permission");
69 assertNotNull("The KR-IDM:Permission KimType should exist.", permissionKimType);
70
71 KimTypeService typeService4 = KimFrameworkServiceLocator.getKimTypeService(permissionKimType);
72 assertNotNull("type service should have been found", typeService4);
73
74 }
75
76 @Test
77 public void testGetKimTypeService_QName() {
78
79
80
81 try {
82 KimFrameworkServiceLocator.getKimTypeService((QName) null);
83 fail("getKimTypeService with a null QName should have thrown an IllegalArgumentException");
84 } catch (IllegalArgumentException e) {}
85
86
87
88 KimTypeService typeService1 = KimFrameworkServiceLocator.getKimTypeService(new QName("badNamespace", "badServiceName"));
89 assertNull("A null KimTypeService should have been returned.", typeService1);
90
91
92
93
94 KimTypeService typeService2 = KimFrameworkServiceLocator.getKimTypeService(new QName(KimApiServiceLocator.KIM_GROUP_SERVICE));
95 assertNull("A null KimTypeService should have been returned.", typeService2);
96
97
98
99 QName permissionServiceName = new QName("permissionPermissionTypeService");
100 KimTypeService typeService3 = KimFrameworkServiceLocator.getKimTypeService(permissionServiceName);
101 assertNotNull("permission type service should have been found", typeService3);
102
103 }
104
105 }