1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.core.impl.component;
17
18 import org.junit.Before;
19 import org.junit.Test;
20 import org.kuali.rice.core.test.CORETestCase;
21 import org.kuali.rice.coreservice.api.CoreServiceApiServiceLocator;
22 import org.kuali.rice.coreservice.api.component.Component;
23 import org.kuali.rice.coreservice.api.component.ComponentService;
24 import org.kuali.rice.test.BaselineTestCase;
25
26 import java.util.ArrayList;
27 import java.util.Collections;
28 import java.util.List;
29
30 import static org.junit.Assert.*;
31
32
33
34
35
36
37
38
39
40 @BaselineTestCase.BaselineMode(BaselineTestCase.Mode.CLEAR_DB)
41 public class DerivedComponentTest extends CORETestCase {
42
43 private ComponentService componentService;
44
45 @Before
46 public void establishComponentService() {
47 componentService = CoreServiceApiServiceLocator.getComponentService();
48 assertNotNull("Failed to locate ComponentService", componentService);
49 }
50
51 @Test
52
53
54
55 public void testPublishComponents_and_getPublishedComponentSet() {
56
57 String testComponentSetId = "testComponentSet";
58 String workflowNamespace = "KR-WKFLW";
59 String testNamespace1 = "TestNamespace1";
60 String testNamespace2 = "TestNamespace2";
61
62 List<Component> testComponentSet = componentService.getDerivedComponentSet(testComponentSetId);
63 assertTrue("Initial testComponentSet should be empty", testComponentSet.isEmpty());
64 List<Component> workflowComponents = componentService.getAllComponentsByNamespaceCode(workflowNamespace);
65
66 assertTrue(componentService.getAllComponentsByNamespaceCode(testNamespace1).isEmpty());
67 assertTrue(componentService.getAllComponentsByNamespaceCode(testNamespace2).isEmpty());
68
69 String customTestWorkflowComponent = "CustomTestWorkflowComponent";
70 Component component1 = Component.Builder.create(workflowNamespace, customTestWorkflowComponent, customTestWorkflowComponent).build();
71 String testNamespace1Component = "TestNamespace1Component";
72 Component component2 = Component.Builder.create(testNamespace1, testNamespace1Component, testNamespace1Component).build();
73 String testNamespace2Component1 = "TestNamespace2Component1";
74 Component component3 = Component.Builder.create(testNamespace2, testNamespace2Component1, testNamespace2Component1).build();
75 String testNamespace2Component2 = "TestNamespace2Component2";
76 Component component4 = Component.Builder.create(testNamespace2, testNamespace2Component2, testNamespace2Component2).build();
77
78 List<Component> setToPublish = new ArrayList<Component>();
79 setToPublish.add(component1);
80 setToPublish.add(component2);
81 setToPublish.add(component3);
82 setToPublish.add(component4);
83
84 componentService.publishDerivedComponents(testComponentSetId, setToPublish);
85
86
87 testComponentSet = componentService.getDerivedComponentSet(testComponentSetId);
88 assertEquals(4, testComponentSet.size());
89 for (Component component : testComponentSet) {
90
91 assertEquals(testComponentSetId, component.getComponentSetId());
92 }
93
94 List<Component> shuffledComponentSet = new ArrayList<Component>(testComponentSet);
95
96 Collections.shuffle(shuffledComponentSet);
97 componentService.publishDerivedComponents(testComponentSetId, shuffledComponentSet);
98
99
100 testComponentSet = componentService.getDerivedComponentSet(testComponentSetId);
101 assertEquals(4, testComponentSet.size());
102
103
104 List<Component> workflowComponentsNew = componentService.getAllComponentsByNamespaceCode(workflowNamespace);
105 assertEquals(workflowComponents.size() + 1, workflowComponentsNew.size());
106
107
108 setToPublish = new ArrayList<Component>();
109 setToPublish.add(component2);
110 setToPublish.add(component3);
111 setToPublish.add(component4);
112 componentService.publishDerivedComponents(testComponentSetId, setToPublish);
113
114
115 testComponentSet = componentService.getDerivedComponentSet(testComponentSetId);
116 assertEquals(3, testComponentSet.size());
117
118
119 workflowComponentsNew = componentService.getAllComponentsByNamespaceCode(workflowNamespace);
120 assertEquals(workflowComponents.size(), workflowComponentsNew.size());
121 }
122
123
124 }