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