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.kim.api.KimConstants;
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.kns.kim.type.DataDictionaryTypeServiceBase;
26
27 import javax.xml.namespace.QName;
28
29 import static org.junit.Assert.*;
30
31
32
33
34
35
36
37 public class KIMServiceLocatorInternalTest extends KIMTestCase {
38
39 @Test
40 public void testGetKimTypeService_KimType() {
41
42
43 try {
44 KimTypeService typeService1 = KimFrameworkServiceLocator.getKimTypeService((KimType) null);
45 assertTrue("should have thrown exception and never got here", false);
46 } catch (IllegalArgumentException e) {
47 }
48
49
50
51 KimType.Builder nullKimType = KimType.Builder.create();
52 nullKimType.setServiceName(null);
53 KimTypeService typeService2 = KimFrameworkServiceLocator.getKimTypeService(nullKimType.build());
54 assertNotNull("type service shoudl have been found", typeService2);
55 assertEquals("should be the default kim type", DataDictionaryTypeServiceBase.class, typeService2.getClass());
56
57
58
59 KimType.Builder emptyKimType = KimType.Builder.create();
60 nullKimType.setServiceName("");
61 KimTypeService typeService3 = KimFrameworkServiceLocator.getKimTypeService(emptyKimType.build());
62 assertNotNull("type service should have been found", typeService3);
63 assertEquals("should be the default kim type", DataDictionaryTypeServiceBase.class, typeService3.getClass());
64
65
66
67 KimType permissionKimType = KimApiServiceLocator.getKimTypeInfoService().findKimTypeByNameAndNamespace(
68 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 }