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