001 /**
002 * Copyright 2005-2013 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.kew.service.impl;
017
018 import org.junit.Before;
019 import org.junit.Test;
020 import org.kuali.rice.core.api.resourceloader.GlobalResourceLoader;
021 import org.kuali.rice.kew.doctype.bo.DocumentTypeEBO;
022 import org.kuali.rice.kew.test.KEWTestCase;
023 import org.kuali.rice.krad.service.KualiModuleService;
024 import org.kuali.rice.krad.service.ModuleService;
025 import org.springframework.util.CollectionUtils;
026
027 import java.util.Collection;
028 import java.util.Collections;
029 import java.util.List;
030
031 import static org.junit.Assert.*;
032
033 /**
034 * Integration test for the {@link KEWModuleService}
035 */
036 public class KEWModuleServiceIntTest extends KEWTestCase {
037
038 private static final String KUALI_NAMESPACE_CODE = "KUALI";
039
040 private ModuleService kewModuleService;
041
042 @Before
043 public void setupServiceUnderTest() {
044 KualiModuleService kualiModuleService = GlobalResourceLoader.getService("kualiModuleService");
045
046 kewModuleService = kualiModuleService.getResponsibleModuleService(DocumentTypeEBO.class);
047 }
048
049 /**
050 * Test that we can load the DocumentType EBO which this ModuleService is responsible for
051 */
052 @Test public void testGetDocumentTypeEbo() {
053 assertNotNull("kewModuleService wasn't successfully configured", kewModuleService);
054
055 DocumentTypeEBO riceDocument = kewModuleService.getExternalizableBusinessObject(DocumentTypeEBO.class,
056 Collections.<String,Object>singletonMap("name", "RiceDocument"));
057
058 assertNotNull("riceDocument wasn't successfully loaded", riceDocument);
059 assertEquals("riceDocument doesn't have the requested name", riceDocument.getName(),
060 "RiceDocument");
061
062 assertNull("non-null result for bogus query", kewModuleService.getExternalizableBusinessObject(
063 DocumentTypeEBO.class, Collections.<String, Object>singletonMap("name", "Kwisatz Haderach")));
064
065 List<DocumentTypeEBO> documentTypes = kewModuleService.getExternalizableBusinessObjectsList(DocumentTypeEBO.class,
066 Collections.<String,Object>emptyMap());
067
068 assertFalse("documentTypes weren't successfully retrieved", CollectionUtils.isEmpty(documentTypes));
069 assertTrue(documentTypes.size() > 1);
070 assertTrue(contains(documentTypes, riceDocument));
071
072 documentTypes = kewModuleService.getExternalizableBusinessObjectsList(DocumentTypeEBO.class,
073 Collections.<String,Object>singletonMap("name", "RiceDocument"));
074
075 assertFalse("documentTypes weren't successfully retrieved", CollectionUtils.isEmpty(documentTypes));
076 assertTrue(documentTypes.size() == 1);
077 assertTrue(contains(documentTypes, riceDocument));
078
079 documentTypes = kewModuleService.getExternalizableBusinessObjectsList(DocumentTypeEBO.class,
080 Collections.<String,Object>singletonMap("name", "Kwisatz Haderach"));
081
082 assertTrue("no documentTypes should have been returned", CollectionUtils.isEmpty(documentTypes));
083 }
084
085 private static boolean contains(Collection<DocumentTypeEBO> collection, DocumentTypeEBO documentType) {
086 if (collection != null) for (DocumentTypeEBO element : collection) {
087 if (documentType.getName().equals(element.getName()) &&
088 documentType.getDocumentTypeId().equals(element.getDocumentTypeId())) {
089 return true;
090 }
091 }
092 return false;
093 }
094
095 }