001 /**
002 * Copyright 2005-2011 The Kuali Foundation
003 *
004 * Licensed under the Educational Community License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 * http://www.opensource.org/licenses/ecl2.php
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016 package org.kuali.rice.kim.service;
017
018 import org.junit.Test;
019 import org.kuali.rice.kim.api.KimConstants;
020 import org.kuali.rice.kim.api.services.KimApiServiceLocator;
021 import org.kuali.rice.kim.api.type.KimType;
022 import org.kuali.rice.kim.framework.services.KimFrameworkServiceLocator;
023 import org.kuali.rice.kim.framework.type.KimTypeService;
024 import org.kuali.rice.kim.test.KIMTestCase;
025 import org.kuali.rice.kns.kim.type.DataDictionaryTypeServiceBase;
026
027 import javax.xml.namespace.QName;
028
029 import static org.junit.Assert.*;
030
031 /**
032 * Tests the {@link org.kuali.rice.kim.impl.services.KimImplServiceLocator} class.
033 *
034 * @author Kuali Rice Team (rice.collab@kuali.org)
035 *
036 */
037 public class KIMServiceLocatorInternalTest extends KIMTestCase {
038
039 @Test
040 public void testGetKimTypeService_KimType() {
041
042 // test by passing null
043 try {
044 KimTypeService typeService1 = KimFrameworkServiceLocator.getKimTypeService((KimType) null);
045 assertTrue("should have thrown exception and never got here", false);
046 } catch (IllegalArgumentException e) {
047 }
048
049 // test by passing a KimType with a null service name
050
051 KimType.Builder nullKimType = KimType.Builder.create();
052 nullKimType.setServiceName(null);
053 KimTypeService typeService2 = KimFrameworkServiceLocator.getKimTypeService(nullKimType.build());
054 assertNotNull("type service shoudl have been found", typeService2);
055 assertEquals("should be the default kim type", DataDictionaryTypeServiceBase.class, typeService2.getClass());
056
057 // test by passing a KimType with an empty service name
058
059 KimType.Builder emptyKimType = KimType.Builder.create();
060 nullKimType.setServiceName("");
061 KimTypeService typeService3 = KimFrameworkServiceLocator.getKimTypeService(emptyKimType.build());
062 assertNotNull("type service should have been found", typeService3);
063 assertEquals("should be the default kim type", DataDictionaryTypeServiceBase.class, typeService3.getClass());
064
065 // test by passing a KimType that refers to the Permission TypeService
066
067 KimType permissionKimType = KimApiServiceLocator.getKimTypeInfoService().findKimTypeByNameAndNamespace(
068 KimConstants.NAMESPACE_CODE, "Permission");
069 assertNotNull("The KR-IDM:Permission KimType should exist.", permissionKimType);
070
071 KimTypeService typeService4 = KimFrameworkServiceLocator.getKimTypeService(permissionKimType);
072 assertNotNull("type service should have been found", typeService4);
073
074 }
075
076 @Test
077 public void testGetKimTypeService_QName() {
078
079 // test by passing null
080
081 try {
082 KimFrameworkServiceLocator.getKimTypeService((QName) null);
083 fail("getKimTypeService with a null QName should have thrown an IllegalArgumentException");
084 } catch (IllegalArgumentException e) {}
085
086 // test by passing an invalid QName
087
088 KimTypeService typeService1 = KimFrameworkServiceLocator.getKimTypeService(new QName("badNamespace", "badServiceName"));
089 assertNull("A null KimTypeService should have been returned.", typeService1);
090
091 // test by passing a QName for a valid service, but not one which is a KimTypeService, null should be returned
092
093 // fetch the group service instead
094 KimTypeService typeService2 = KimFrameworkServiceLocator.getKimTypeService(new QName(KimApiServiceLocator.KIM_GROUP_SERVICE));
095 assertNull("A null KimTypeService should have been returned.", typeService2);
096
097 // test by passing the QName for the Permission TypeService
098
099 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 }