1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.krms.impl.ui;
17
18 import org.junit.Before;
19 import org.junit.Test;
20 import org.kuali.rice.krms.api.repository.LogicalOperator;
21 import org.kuali.rice.krms.api.repository.agenda.AgendaDefinition;
22 import org.kuali.rice.krms.api.repository.agenda.AgendaItemDefinition;
23 import org.kuali.rice.krms.api.repository.context.ContextDefinition;
24 import org.kuali.rice.krms.api.repository.proposition.PropositionDefinition;
25 import org.kuali.rice.krms.api.repository.proposition.PropositionType;
26 import org.kuali.rice.krms.api.repository.rule.RuleDefinition;
27 import org.kuali.rice.krms.api.repository.type.KrmsTypeDefinition;
28 import org.kuali.rice.krms.impl.repository.ActionBoService;
29 import org.kuali.rice.krms.impl.repository.ActionBoServiceImpl;
30 import org.kuali.rice.krms.impl.repository.AgendaBo;
31 import org.kuali.rice.krms.impl.repository.AgendaBoService;
32 import org.kuali.rice.krms.impl.repository.AgendaBoServiceImpl;
33 import org.kuali.rice.krms.impl.repository.ContextBoServiceImpl;
34 import org.kuali.rice.krms.impl.repository.KrmsRepositoryServiceLocator;
35 import org.kuali.rice.krms.impl.repository.PropositionBoService;
36 import org.kuali.rice.krms.impl.repository.PropositionBoServiceImpl;
37 import org.kuali.rice.krms.impl.repository.RuleBoService;
38 import org.kuali.rice.krms.impl.repository.RuleBoServiceImpl;
39 import org.kuali.rice.krms.impl.repository.TermBoService;
40 import org.kuali.rice.krms.impl.repository.TermBoServiceImpl;
41 import org.kuali.rice.test.BaselineTestCase.BaselineMode;
42 import org.kuali.rice.test.BaselineTestCase.Mode;
43 import org.kuali.rice.krms.test.AbstractBoTest;
44
45 import java.util.ArrayList;
46 import java.util.Collections;
47 import java.util.Comparator;
48 import java.util.HashMap;
49 import java.util.Iterator;
50 import java.util.LinkedList;
51 import java.util.List;
52 import java.util.Map;
53 import java.util.Set;
54 import java.util.StringTokenizer;
55 import java.util.TreeMap;
56
57 import static org.junit.Assert.assertEquals;
58 import static org.junit.Assert.assertFalse;
59 import static org.junit.Assert.assertTrue;
60
61
62
63
64
65 @BaselineMode(Mode.CLEAR_DB)
66 public class AgendaEditorMaintainableIntegrationTest extends AbstractBoTest {
67
68 static final String NAMESPACE1 = "KRMS_TEST_1";
69 static final String CONTEXT1 = "Context1";
70 static final String CONTEXT1_QUALIFIER = "Context1Qualifier";
71 static final String CONTEXT1_QUALIFIER_VALUE = "BLAH1";
72 static final String AGENDA1 = "TestAgenda1";
73
74 private PropositionBoService propositionBoService;
75 private TermBoService termBoService;
76 private AgendaBoService agendaBoService;
77 private RuleBoService ruleBoService;
78 private ActionBoService actionBoService;
79
80 @Before
81 public void setup() {
82
83 krmsAttributeDefinitionService = KrmsRepositoryServiceLocator.getKrmsAttributeDefinitionService();
84 krmsTypeRepository = KrmsRepositoryServiceLocator.getKrmsTypeRepositoryService();
85
86
87 propositionBoService = new PropositionBoServiceImpl();
88 ((PropositionBoServiceImpl)propositionBoService).setBusinessObjectService(getBoService());
89 termBoService = new TermBoServiceImpl();
90 ((TermBoServiceImpl)termBoService).setBusinessObjectService(getBoService());
91 contextRepository = new ContextBoServiceImpl();
92 ((ContextBoServiceImpl)contextRepository).setBusinessObjectService(getBoService());
93 agendaBoService = new AgendaBoServiceImpl();
94 ((AgendaBoServiceImpl)agendaBoService).setBusinessObjectService(getBoService());
95 ((AgendaBoServiceImpl)agendaBoService).setAttributeDefinitionService(krmsAttributeDefinitionService);
96 ruleBoService = new RuleBoServiceImpl();
97 ((RuleBoServiceImpl)ruleBoService).setBusinessObjectService(getBoService());
98 actionBoService = new ActionBoServiceImpl();
99 ((ActionBoServiceImpl)actionBoService).setBusinessObjectService(getBoService());
100 }
101
102 @Test
103 public void testEmptyAgendaDelete() {
104 ContextDefinition contextDefintion1 = createContextDefinition(NAMESPACE1, CONTEXT1, Collections.singletonMap(
105 CONTEXT1_QUALIFIER, CONTEXT1_QUALIFIER_VALUE));
106 createAgendaDefinition(AGENDA1, "AgendaLabel", contextDefintion1);
107 AgendaDefinition agendaDefinition = agendaBoService.getAgendaByNameAndContextId(AGENDA1, contextDefintion1.getId());
108
109 lookupAndSaveDataObject(agendaDefinition);
110 }
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130 private void lookupAndSaveDataObject(AgendaDefinition agendaDefinition) {
131 AgendaBo blah = findAgendaByPrimaryKey(agendaDefinition);
132
133 AgendaEditorMaintainable aem = new AgendaEditorMaintainable();
134 AgendaEditor ae = new AgendaEditor();
135 ae.setAgenda(blah);
136 aem.setDataObject(ae);
137 aem.saveDataObject();
138 }
139
140 private AgendaBo findAgendaByPrimaryKey(AgendaDefinition agendaDefinition) {Map<String,String>
141 primaryKeys = new HashMap<String, String>();
142 primaryKeys.put("id", agendaDefinition.getId());
143 return getBoService().findByPrimaryKey(AgendaBo.class, primaryKeys);
144 }
145
146 private void createAgendaDefinition(String agendaName, String agendaLabel, ContextDefinition contextDefinition) {
147 KrmsTypeDefinition krmsGenericTypeDefinition = createKrmsGenericTypeDefinition(contextDefinition.getNamespace(), "testAgendaTypeService", agendaName, agendaLabel);
148
149 AgendaDefinition agendaDefinition =
150 AgendaDefinition.Builder.create(null, agendaName, krmsGenericTypeDefinition.getId(), contextDefinition.getId()).build();
151 agendaDefinition = agendaBoService.createAgenda(agendaDefinition);
152 agendaBoService.updateAgenda(agendaDefinition);
153
154 AgendaBo blah = findAgendaByPrimaryKey(agendaDefinition);
155
156 AgendaDefinition.Builder agendaDefBuilder1 = AgendaDefinition.Builder.create(agendaBoService.to(blah));
157 agendaDefinition = agendaDefBuilder1.build();
158
159 agendaBoService.updateAgenda(agendaDefinition);
160 }
161 }