View Javadoc
1   /**
2    * Copyright 2005-2014 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.kew.service.impl;
17  
18  import org.junit.Before;
19  import org.junit.Test;
20  import org.kuali.rice.core.api.resourceloader.GlobalResourceLoader;
21  import org.kuali.rice.kew.doctype.bo.DocumentTypeEBO;
22  import org.kuali.rice.kew.test.KEWTestCase;
23  import org.kuali.rice.krad.service.KualiModuleService;
24  import org.kuali.rice.krad.service.ModuleService;
25  import org.springframework.util.CollectionUtils;
26  
27  import java.util.Collection;
28  import java.util.Collections;
29  import java.util.List;
30  
31  import static org.junit.Assert.*;
32  
33  /**
34   * Integration test for the {@link KEWModuleService}
35   */
36  public class KEWModuleServiceIntTest extends KEWTestCase {
37  
38      private static final String KUALI_NAMESPACE_CODE = "KUALI";
39  
40      private ModuleService kewModuleService;
41  
42      @Before
43      public void setupServiceUnderTest() {
44          KualiModuleService kualiModuleService = GlobalResourceLoader.getService("kualiModuleService");
45  
46          kewModuleService = kualiModuleService.getResponsibleModuleService(DocumentTypeEBO.class);
47      }
48  
49      /**
50       * Test that we can load the DocumentType EBO which this ModuleService is responsible for
51       */
52      @Test public void testGetDocumentTypeEbo() {
53          assertNotNull("kewModuleService wasn't successfully configured", kewModuleService);
54  
55          DocumentTypeEBO riceDocument = kewModuleService.getExternalizableBusinessObject(DocumentTypeEBO.class,
56                  Collections.<String,Object>singletonMap("name", "RiceDocument"));
57  
58          assertNotNull("riceDocument wasn't successfully loaded", riceDocument);
59          assertEquals("riceDocument doesn't have the requested name", riceDocument.getName(),
60                  "RiceDocument");
61  
62          assertNull("non-null result for bogus query", kewModuleService.getExternalizableBusinessObject(
63                  DocumentTypeEBO.class, Collections.<String, Object>singletonMap("name", "Kwisatz Haderach")));
64  
65          List<DocumentTypeEBO> documentTypes = kewModuleService.getExternalizableBusinessObjectsList(DocumentTypeEBO.class,
66                  Collections.<String,Object>emptyMap());
67  
68          assertFalse("documentTypes weren't successfully retrieved", CollectionUtils.isEmpty(documentTypes));
69          assertTrue(documentTypes.size() > 1);
70          assertTrue(contains(documentTypes, riceDocument));
71  
72          documentTypes = kewModuleService.getExternalizableBusinessObjectsList(DocumentTypeEBO.class,
73                  Collections.<String,Object>singletonMap("name", "RiceDocument"));
74  
75          assertFalse("documentTypes weren't successfully retrieved", CollectionUtils.isEmpty(documentTypes));
76          assertTrue(documentTypes.size() == 1);
77          assertTrue(contains(documentTypes, riceDocument));
78  
79          documentTypes = kewModuleService.getExternalizableBusinessObjectsList(DocumentTypeEBO.class,
80                  Collections.<String,Object>singletonMap("name", "Kwisatz Haderach"));
81  
82          assertTrue("no documentTypes should have been returned", CollectionUtils.isEmpty(documentTypes));
83      }
84  
85      private static boolean contains(Collection<DocumentTypeEBO> collection, DocumentTypeEBO documentType) {
86          if (collection != null) for (DocumentTypeEBO element : collection) {
87              if (documentType.getName().equals(element.getName()) &&
88                      documentType.getDocumentTypeId().equals(element.getDocumentTypeId())) {
89                  return true;
90              }
91          }
92          return false;
93      }
94  
95  }