1
2
3
4
5
6
7
8
9
10
11
12
13
14
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
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
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 }