View Javadoc

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