View Javadoc

1   /**
2    * Copyright 2005-2011 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl2.php
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
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   * Tests the {@link org.kuali.rice.kim.impl.services.KimImplServiceLocator} class.
33   * 
34   * @author Kuali Rice Team (rice.collab@kuali.org)
35   *
36   */
37  public class KIMServiceLocatorInternalTest extends KIMTestCase {
38  
39  	@Test
40  	public void testGetKimTypeService_KimType() {
41  		
42  		// test by passing null
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  		// test by passing a KimType with a null service name
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  		// test by passing a KimType with an empty service name
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  		// test by passing a KimType that refers to the Permission TypeService
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  		// test by passing null
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  		// test by passing an invalid QName
87  		
88  		KimTypeService typeService1 = KimFrameworkServiceLocator.getKimTypeService(new QName("badNamespace", "badServiceName"));
89  		assertNull("A null KimTypeService should have been returned.", typeService1);
90  		
91  		// test by passing a QName for a valid service, but not one which is a KimTypeService, null should be returned
92  		
93  		// fetch the group service instead
94  		KimTypeService typeService2 = KimFrameworkServiceLocator.getKimTypeService(new QName(KimApiServiceLocator.KIM_GROUP_SERVICE));
95  		assertNull("A null KimTypeService should have been returned.", typeService2);
96  
97  		// test by passing the QName for the Permission TypeService
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 }