View Javadoc
1   /**
2    * Copyright 2005-2014 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  package org.kuali.rice.krms.test;
17  
18  import com.google.common.collect.Sets;
19  import org.apache.commons.lang.StringUtils;
20  import org.junit.Ignore;
21  import org.junit.Test;
22  import org.kuali.rice.core.api.exception.RiceIllegalArgumentException;
23  import org.kuali.rice.core.api.exception.RiceRuntimeException;
24  import org.kuali.rice.krms.api.repository.LogicalOperator;
25  import org.kuali.rice.krms.api.repository.action.ActionDefinition;
26  import org.kuali.rice.krms.api.repository.agenda.AgendaDefinition;
27  import org.kuali.rice.krms.api.repository.agenda.AgendaItemDefinition;
28  import org.kuali.rice.krms.api.repository.agenda.AgendaItemDefinitionContract;
29  import org.kuali.rice.krms.api.repository.context.ContextDefinition;
30  import org.kuali.rice.krms.api.repository.proposition.PropositionDefinition;
31  import org.kuali.rice.krms.api.repository.proposition.PropositionParameter;
32  import org.kuali.rice.krms.api.repository.proposition.PropositionParameterType;
33  import org.kuali.rice.krms.api.repository.proposition.PropositionType;
34  import org.kuali.rice.krms.api.repository.rule.RuleDefinition;
35  import org.kuali.rice.krms.api.repository.type.KrmsAttributeDefinition;
36  import org.kuali.rice.krms.api.repository.type.KrmsTypeDefinition;
37  import org.kuali.rice.krms.impl.repository.ActionAttributeBo;
38  import org.kuali.rice.krms.impl.repository.ActionBo;
39  import org.kuali.rice.krms.impl.repository.ActionBoService;
40  import org.kuali.rice.krms.impl.repository.AgendaBo;
41  import org.kuali.rice.krms.impl.repository.AgendaItemBo;
42  import org.kuali.rice.krms.impl.repository.KrmsAttributeDefinitionBo;
43  import org.kuali.rice.krms.impl.repository.RuleBo;
44  import org.kuali.rice.test.BaselineTestCase;
45  import org.springframework.util.CollectionUtils;
46  
47  import java.util.ArrayList;
48  import java.util.Arrays;
49  import java.util.Collections;
50  import java.util.HashMap;
51  import java.util.HashSet;
52  import java.util.List;
53  import java.util.Map;
54  import java.util.Set;
55  
56  import static org.junit.Assert.*;
57  
58  /**
59   * Integration test for the AgendaBoService.  Note that we inherit the test data created by AbstractAgendaBoTest, and
60   * test the service against that data.
61   */
62  @BaselineTestCase.BaselineMode(BaselineTestCase.Mode.CLEAR_DB)
63  public class AgendaBoServiceTest extends AbstractAgendaBoTest {
64  
65      private static final String NULL = new String("null"); // null String.  Hah. Using it as a "null object".
66  
67      private static <A> A nullConvertingGet(List<A> list, int index) {
68          // being lazy, no input checks here
69          A result = list.get(index);
70          if (result == NULL) result = null;
71          return result;
72      }
73  
74      @Test public void testGetByContextId() {
75  
76          assertTrue(CollectionUtils.isEmpty(getAgendaBoService().getAgendasByContextId("#$^$ BogusContextId !@#$")));
77          assertTrue(CollectionUtils.isEmpty(getAgendaBoService().getAgendaItemsByContext("#$^$ BogusContextId !@#$")));
78  
79          for (String contextName : Arrays.asList(CONTEXT1, CONTEXT2, CONTEXT3)) {
80              String namespace = getNamespaceByContextName(contextName);
81              if (StringUtils.isBlank(namespace)) {
82                  throw new RiceRuntimeException("namespace is " + namespace + " for context with name " + contextName);
83              }
84  
85              String contextId = getContextRepository().getContextByNameAndNamespace(contextName, namespace).getId();
86  
87              List<AgendaDefinition> agendas = getAgendaBoService().getAgendasByContextId(contextId);
88              List<AgendaItemDefinition> agendaItems = getAgendaBoService().getAgendaItemsByContext(contextId);
89  
90              assertEquals("agenda count doesn't match our tally for context " + contextName, agendas.size(),
91                      getBoService().countMatching(AgendaBo.class, Collections.singletonMap("contextId", contextId)));
92  
93              int totalAgendaItems = 0; // count agenda items in the context for verification purposes
94  
95              Set<String> agendaIds = new HashSet<String>(); // build set of agenda ids, also for verification purposes
96  
97              for (AgendaDefinition agenda : agendas) {
98                  assertEquals("agenda w/ ID "+ agenda.getId() +" has a context ID that doesn't match",
99                          agenda.getContextId(), contextId);
100 
101                 totalAgendaItems += getBoService().countMatching(
102                         AgendaItemBo.class, Collections.singletonMap("agendaId", agenda.getId())
103                 );
104 
105                 agendaIds.add(agenda.getId());
106             }
107 
108             for (AgendaItemDefinition agendaItem : agendaItems) {
109                 assertTrue("agenda item is not part of any agendas in " + contextName,
110                         agendaIds.contains(agendaItem.getAgendaId()));
111             }
112 
113             assertEquals("number of agenda items doesn't match our tally", agendaItems.size(), totalAgendaItems);
114         }
115 
116     }
117 
118     @Test public void testGetAgendasByContextId_nullOrBlank() {
119 
120         for (String contextId : Arrays.asList(null, "", " ")) {
121             try {
122                 getAgendaBoService().getAgendasByContextId(contextId);
123                 fail("getAgendasByContextId should have thrown "+ RiceIllegalArgumentException.class.getSimpleName() +
124                         " for invalid contextId=" + contextId +".");
125             } catch (RiceIllegalArgumentException e) {
126                 // good, that's what it should do
127             }
128         }
129     }
130 
131     @Test public void testGetAgendaItemsByContextId_nullOrBlank() {
132 
133         for (String contextId : Arrays.asList(null, "", " ")) {
134             try {
135                 getAgendaBoService().getAgendaItemsByContext(contextId);
136                 fail("getAgendaItemsByContext should have thrown "+ RiceIllegalArgumentException.class.getSimpleName() +
137                         " for invalid contextId=" + contextId +".");
138             } catch (RiceIllegalArgumentException e) {
139                 // good, that's what it should do
140             }
141         }
142     }
143 
144     @Test
145     public void testGetByType() {
146 
147         assertTrue(CollectionUtils.isEmpty(getAgendaBoService().getAgendasByType("#$^$ BogusTypeId !@#$")));
148         assertTrue(CollectionUtils.isEmpty(getAgendaBoService().getAgendaItemsByType("#$^$ BogusTypeId !@#$")));
149 
150         List<KrmsTypeDefinition> agendaTypes =  getAgendaTypesForContexts(Arrays.asList(CONTEXT1, CONTEXT2, CONTEXT3));
151 
152         assertTrue("We must have some types to test with or we prove nothing", agendaTypes.size() > 0);
153 
154         for (KrmsTypeDefinition agendaType : agendaTypes) {
155             String typeName = agendaType.getName();
156             String typeNamespace = agendaType.getNamespace();
157 
158             KrmsTypeDefinition type = getKrmsTypeRepository().getTypeByName(typeNamespace, typeName);
159 
160             List<AgendaDefinition> agendas = getAgendaBoService().getAgendasByType(type.getId());
161             List<AgendaItemDefinition> agendaItems = getAgendaBoService().getAgendaItemsByType(type.getId());
162 
163 
164             assertEquals("agenda count doesn't match our tally for type " + typeNamespace+":"+typeName,
165                     agendas.size(), getBoService().countMatching(
166                     AgendaBo.class, Collections.singletonMap("typeId", type.getId()))
167             );
168 
169             int totalAgendaItems = 0; // count agenda items in the type for verification purposes
170 
171             Set<String> agendaIds = new HashSet<String>(); // build set of agenda ids, also for verification purposes
172 
173             for (AgendaDefinition agenda : agendas) {
174                 assertEquals("agenda w/ ID "+ agenda.getTypeId() +" has a type ID that doesn't match",
175                         agenda.getTypeId(), type.getId());
176 
177                 totalAgendaItems += getBoService().countMatching(
178                         AgendaItemBo.class, Collections.singletonMap("agendaId", agenda.getId())
179                 );
180 
181                 agendaIds.add(agenda.getId());
182             }
183 
184             for (AgendaItemDefinition agendaItem : agendaItems) {
185                 assertTrue("agenda item is not part of any agendas in type " + typeNamespace+":"+typeName,
186                         agendaIds.contains(agendaItem.getAgendaId()));
187             }
188 
189             assertEquals("number of agenda items doesn't match our tally", agendaItems.size(), totalAgendaItems);
190 
191         }
192     }
193 
194     private List<KrmsTypeDefinition> getAgendaTypesForContexts(List<String> contextNames) {
195         List<KrmsTypeDefinition> results = new ArrayList<KrmsTypeDefinition>();
196 
197         // collect all the types used for the agendas in our contexts
198         for (String contextName : contextNames) {
199             String namespace = getNamespaceByContextName(contextName);
200             if (StringUtils.isBlank(namespace)) {
201                 throw new RiceRuntimeException("namespace is " + namespace + " for context with name " + contextName);
202             }
203 
204             String contextId = getContextRepository().getContextByNameAndNamespace(contextName, namespace).getId();
205 
206             // depending on good behavior of getAgendasByContextId which is tested elsewhere
207             List<AgendaDefinition> agendas = getAgendaBoService().getAgendasByContextId(contextId);
208 
209             // stacked filters here
210             if (!CollectionUtils.isEmpty(agendas)) {
211                 for (AgendaDefinition agenda : agendas) {
212                     if (agenda.getTypeId() != null) {
213                         KrmsTypeDefinition type = getKrmsTypeRepository().getTypeById(agenda.getTypeId());
214 
215                         // we depend on working hashcode & equals for KrmsTypeDefinition here
216                         if (!results.contains(type)) {
217                             results.add(type);
218                         }
219                     }
220                 }
221             }
222         }
223         return results;
224     }
225 
226     @Test public void testGetAgendasByType_nullOrBlank() {
227 
228         for (String contextId : Arrays.asList(null, "", " ")) {
229             try {
230                 getAgendaBoService().getAgendasByType(contextId);
231                 fail("getAgendasByType should have thrown "+ RiceIllegalArgumentException.class.getSimpleName() +
232                         " for invalid contextId=" + contextId +".");
233             } catch (RiceIllegalArgumentException e) {
234                 // good, that's what it should do
235             }
236         }
237     }
238 
239     @Test public void testGetAgendaItemsByType_nullOrBlank() {
240 
241         for (String contextId : Arrays.asList(null, "", " ")) {
242             try {
243                 getAgendaBoService().getAgendaItemsByType(contextId);
244                 fail("getAgendaItemsByType should have thrown "+ RiceIllegalArgumentException.class.getSimpleName() +
245                         " for invalid contextId=" + contextId +".");
246             } catch (RiceIllegalArgumentException e) {
247                 // good, that's what it should do
248             }
249         }
250     }
251 
252     @Test public void testGetByTypeAndContext() {
253 
254         boolean testedSomeTypes = false;
255 
256         for (String contextName : Arrays.asList(CONTEXT1, CONTEXT2, CONTEXT3)) {
257 
258             List<KrmsTypeDefinition> agendaTypes =  getAgendaTypesForContexts(Collections.singletonList(contextName));
259 
260             String namespace = getNamespaceByContextName(contextName);
261             if (StringUtils.isBlank(namespace)) {
262                 throw new RiceRuntimeException("namespace is " + namespace + " for context with name " + contextName);
263             }
264 
265             ContextDefinition context = getContextRepository().getContextByNameAndNamespace(contextName, namespace);
266 
267             for (KrmsTypeDefinition agendaType : agendaTypes) {
268 
269                 testedSomeTypes = true; // prove we got to the inner loop
270 
271                 assertTrue(CollectionUtils.isEmpty(getAgendaBoService().getAgendasByTypeAndContext("#$^$ BogusTypeId !@#$", context.getId())));
272                 assertTrue(CollectionUtils.isEmpty(getAgendaBoService().getAgendaItemsByTypeAndContext("#$^$ BogusTypeId !@#$", context.getId())));
273                 assertTrue(CollectionUtils.isEmpty(getAgendaBoService().getAgendasByTypeAndContext(agendaType.getId(), "#$^$ BogusContextId !@#$")));
274                 assertTrue(CollectionUtils.isEmpty(getAgendaBoService().getAgendaItemsByTypeAndContext(
275                         agendaType.getId(), "#$^$ BogusContextId !@#$")));
276 
277                 List<AgendaDefinition> agendas = getAgendaBoService().getAgendasByTypeAndContext(agendaType.getId(), context.getId());
278                 List<AgendaItemDefinition> agendaItems = getAgendaBoService().getAgendaItemsByTypeAndContext(agendaType.getId(), context.getId());
279 
280                 Map<String, String> agendaCountCrit = new HashMap<String, String>();
281                 agendaCountCrit.put("typeId", agendaType.getId());
282                 agendaCountCrit.put("contextId", context.getId());
283                 assertEquals(
284                         "agenda count doesn't match our tally for type " + agendaType.getNamespace() + ":" + agendaType
285                                 .getName(), agendas.size(), getBoService().countMatching(AgendaBo.class,
286                         agendaCountCrit));
287 
288                 int totalAgendaItems = 0; // count agenda items in the type for verification purposes
289 
290                 Set<String> agendaIds = new HashSet<String>(); // build set of agenda ids, also for verification purposes
291 
292                 for (AgendaDefinition agenda : agendas) {
293                     assertEquals("agenda w/ ID "+ agenda.getTypeId() +" has a type ID that doesn't match",
294                             agenda.getTypeId(), agendaType.getId());
295 
296                     totalAgendaItems += getBoService().countMatching(
297                             AgendaItemBo.class, Collections.singletonMap("agendaId", agenda.getId())
298                     );
299 
300                     agendaIds.add(agenda.getId());
301                 }
302 
303                 for (AgendaItemDefinition agendaItem : agendaItems) {
304                     String assertionString = "agenda item is not part of any agendas in type " +
305                             agendaType.getNamespace()+":"+agendaType.getName() +
306                             " and context " + context.getNamespace()+":"+context.getName();
307 
308                     assertTrue(assertionString, agendaIds.contains(agendaItem.getAgendaId())
309                     );
310                 }
311 
312                 assertEquals("number of agenda items doesn't match our tally", agendaItems.size(), totalAgendaItems);
313             }
314 
315             assertTrue("We have to test some types or we prove nothing", testedSomeTypes);
316 
317         }
318     }
319 
320     @Test public void testGetAgendaItemsByTypeAndContext_nullOrBlank() {
321 
322 
323         Set<String> emptyValues = new HashSet<String>();
324         emptyValues.addAll(Arrays.asList(NULL, "", " "));
325 
326         Set<String> oneNonBlank = Sets.union(emptyValues, Collections.singleton("fakeId"));
327         Set<List<String>> testIds = Sets.union(Sets.cartesianProduct(emptyValues, oneNonBlank),
328                 Sets.cartesianProduct(oneNonBlank, emptyValues));
329 
330         for (List<String> ids : testIds) {
331             try {
332                 getAgendaBoService().getAgendaItemsByTypeAndContext(nullConvertingGet(ids, 0), nullConvertingGet(ids, 1));
333                 fail("getAgendaItemsByType should have thrown "+ RiceIllegalArgumentException.class.getSimpleName() +
334                         " for invalid combo of contextId=" + ids +".");
335             } catch (RiceIllegalArgumentException e) {
336                 // good, that's what it should do
337             }
338         }
339     }
340 
341     @Test
342     public void testUpdateAgendaItem() {
343         ContextDefinition context = getContextRepository().getContextByNameAndNamespace(CONTEXT1, NAMESPACE1);
344         assertNotNull("context " + CONTEXT1 + " not found", context);
345         AgendaDefinition agenda = getAgendaBoService().getAgendaByNameAndContextId(AGENDA1, context.getId());
346         assertNotNull("agenda " + AGENDA1 + " not found", agenda);
347         AgendaItemDefinition agendaItem = getAgendaBoService().getAgendaItemById(agenda.getFirstItemId());
348         assertNotNull("agenda item " + agenda.getFirstItemId() + " not found", agendaItem);
349 
350         KrmsAttributeDefinition attributeDefinition = getKrmsAttributeDefinitionService().createAttributeDefinition(
351                 KrmsAttributeDefinition.Builder.create(null, ATTRIBUTE1, NAMESPACE1).build());
352         KrmsAttributeDefinitionBo attributeDefinitionBo = KrmsAttributeDefinitionBo.from(attributeDefinition);
353 
354         // verify the agenda item
355         AgendaItemBo agendaItemBo = AgendaItemBo.from(agendaItem);
356         assertNotNull("agenda item null", agendaItemBo);
357         List<ActionBo> agendaItemActionBos = agendaItemBo.getRule().getActions();
358         assertEquals("incorrect number of agenda item rule actions found", 1, agendaItemActionBos.size());
359         ActionBo agendaItemActionBo = agendaItemActionBos.get(0);
360         assertTrue("agenda item rule action attributes found", agendaItemActionBo.getAttributes().isEmpty());
361         assertTrue("agenda item rule action attributes found", agendaItemActionBo.getAttributeBos().isEmpty());
362 
363         // verify the child agenda item
364         AgendaItemBo alwaysBo = agendaItemBo.getAlways();
365         assertNotNull("always agenda item null", alwaysBo);
366         List<ActionBo> alwaysActionBos = alwaysBo.getRule().getActions();
367         assertEquals("incorrect number of always agenda item rule actions found", 1, alwaysActionBos.size());
368         ActionBo alwaysActionBo = alwaysActionBos.get(0);
369         assertTrue("always agenda item rule action attributes found", alwaysActionBo.getAttributes().isEmpty());
370         assertTrue("always agenda item rule action attributes found", alwaysActionBo.getAttributeBos().isEmpty());
371 
372         // add agenda item attribute
373         ActionAttributeBo agendaItemActionAttributeBo = new ActionAttributeBo();
374         agendaItemActionAttributeBo.setAction(agendaItemActionBo);
375         agendaItemActionAttributeBo.setAttributeDefinition(attributeDefinitionBo);
376         agendaItemActionAttributeBo.setValue("testAgendaItem");
377         agendaItemActionBo.setAttributeBos(Arrays.asList(agendaItemActionAttributeBo));
378 
379         // add child agenda item attribute
380         ActionAttributeBo whenAlwaysActionAttributeBo = new ActionAttributeBo();
381         whenAlwaysActionAttributeBo.setAction(alwaysActionBo);
382         whenAlwaysActionAttributeBo.setAttributeDefinition(attributeDefinitionBo);
383         whenAlwaysActionAttributeBo.setValue("testAlwaysAgendaItem");
384         alwaysActionBo.setAttributeBos(Arrays.asList(whenAlwaysActionAttributeBo));
385 
386         // update the agenda item
387         AgendaItemDefinition updatedAgendaItem
388                 = getAgendaBoService().updateAgendaItem(AgendaItemDefinition.Builder.create(agendaItemBo).build());
389 
390         // verify the updated agenda item
391         AgendaItemBo updatedAgendaItemBo = AgendaItemBo.from(updatedAgendaItem);
392         assertNotNull("updated agenda item null", updatedAgendaItemBo);
393         List<ActionBo> updatedAgendaItemActionBos = updatedAgendaItemBo.getRule().getActions();
394         assertEquals("incorrect number of updated agenda item rule actions found", 1, updatedAgendaItemActionBos.size());
395         ActionBo updatedAgendaItemActionBo = updatedAgendaItemActionBos.get(0);
396         assertEquals("incorrect number of updated agenda item rule action attributes found", 1, updatedAgendaItemActionBo.getAttributes().size());
397         assertEquals("incorrect number of updated agenda item rule action attributes found", 1, updatedAgendaItemActionBo.getAttributeBos().size());
398 
399         // verify the updated child agenda item
400         AgendaItemBo updatedAlwaysBo = updatedAgendaItemBo.getAlways();
401         assertNotNull("updated always agenda item null", updatedAlwaysBo);
402         List<ActionBo> updatedAlwaysActionBos = updatedAlwaysBo.getRule().getActions();
403         assertEquals("incorrect number of updated always agenda item rule actions found", 1, updatedAlwaysActionBos.size());
404         ActionBo updatedAlwaysActionBo = updatedAlwaysActionBos.get(0);
405         assertEquals("incorrect number of updated always agenda item rule action attributes found", 1, updatedAlwaysActionBo.getAttributes().size());
406         assertEquals("incorrect number of updated always agenda item rule action attributes found", 1, updatedAlwaysActionBo.getAttributeBos().size());
407 
408         // Check to make sure there are no orphaned records
409         KrmsAttributeDefinition orgAttribute = getKrmsAttributeDefinitionService().getAttributeDefinitionById( attributeDefinition.getId() );
410         assertEquals("incorrect number of updated attributes found for the agenda", 1, getAgendaBoService().getAgendaByAgendaId(updatedAgendaItem.getAgendaId()).getAttributes().size());
411         assertNotNull("Attribute definition orphaned on AgendaItem update", orgAttribute);
412 
413     }
414 
415 
416     private class AgendaDefinitionDataWrapper {
417         private ContextDefinition context;
418         private AgendaDefinition agenda;
419         private AgendaItemDefinition firstItem;
420         private AgendaItemDefinition secondItem;
421         private AgendaItemDefinition thirdItem;
422         private AgendaItemDefinition fourthItem;
423 
424         private RuleDefinition firstItemRule;
425 
426         AgendaDefinitionDataWrapper() {
427             context = getContextRepository().getContextByNameAndNamespace(CONTEXT1, NAMESPACE1);
428             assertNotNull("context " + CONTEXT1 + " not found", context);
429             agenda = getAgendaBoService().getAgendaByNameAndContextId(AGENDA1, context.getId());
430             assertNotNull("agenda " + AGENDA1 + " not found", agenda);
431 
432             firstItem = getAgendaBoService().getAgendaItemById( agenda.getFirstItemId() );
433             assertNotNull("agenda item " + agenda.getFirstItemId() + " not found", firstItem);
434 
435             secondItem = firstItem.getAlways();
436             thirdItem = secondItem.getAlways();
437             fourthItem = thirdItem.getAlways();
438 
439             firstItemRule = firstItem.getRule();
440         }
441     }
442 
443 
444     @Test
445     public void testOrphanActions(){
446         AgendaDefinitionDataWrapper agendaWrapper = new AgendaDefinitionDataWrapper();
447 
448         // update the Action in the Rule
449         List<ActionDefinition> actionDefinitionList = agendaWrapper.firstItemRule.getActions();
450         ActionDefinition orgAction = actionDefinitionList.get(0);
451 
452         // create rule actions
453         RuleDefinition.Builder rule1Builder = RuleDefinition.Builder.create( agendaWrapper.firstItemRule );
454         List<ActionDefinition.Builder> newActionList = new ArrayList<ActionDefinition.Builder>();
455 
456         ActionDefinition.Builder actionDefBuilder1 = ActionDefinition.Builder.create(null,
457                 agendaWrapper.firstItemRule.getName() + "::UpdatedAction", NAMESPACE1, createKrmsActionTypeDefinition(NAMESPACE1)
458                 .getId(), agendaWrapper.firstItemRule.getId(), 1);
459         newActionList.add(actionDefBuilder1);
460         rule1Builder.setActions(newActionList);
461         RuleDefinition updatedFirstRule = rule1Builder.build();
462         ruleBoService.updateRule(updatedFirstRule);
463 
464         ActionDefinition shouldBeDeletedAction = actionBoService.getActionByActionId(orgAction.getId());
465         assertNull("Original Action should have been removed", shouldBeDeletedAction);
466     }
467 
468     @Test
469     public void testOrphanPropositions(){
470         AgendaDefinitionDataWrapper agendaWrapper = new AgendaDefinitionDataWrapper();
471 
472         // update the Action in the Rule
473         List<ActionDefinition> actionDefinitionList = agendaWrapper.firstItemRule.getActions();
474         ActionDefinition orgAction = actionDefinitionList.get(0);
475 
476         RuleDefinition.Builder rule1Builder = RuleDefinition.Builder.create(agendaWrapper.firstItemRule);
477         // update rule proposition
478         PropositionDefinition.Builder parentProposition =
479                 PropositionDefinition.Builder.create(null, PropositionType.COMPOUND.getCode(),
480                         agendaWrapper.firstItemRule.getId(), null, null);
481         parentProposition.setCompoundComponents(new ArrayList<PropositionDefinition.Builder>());
482 
483         agendaWrapper.firstItemRule = ruleBoService.getRuleByRuleId( agendaWrapper.firstItemRule.getId() );
484         RuleDefinition.Builder rule2Builder = RuleDefinition.Builder.create(agendaWrapper.firstItemRule);
485 
486 
487         PropositionParametersBuilder params1 = new PropositionParametersBuilder();
488         params1.add(createTermDefinition(CAMPUS_CODE_TERM_NAME, String.class, agendaWrapper.context).getId(), PropositionParameterType.TERM);
489         params1.add("DC", PropositionParameterType.CONSTANT);
490         params1.add("=", PropositionParameterType.OPERATOR);
491 
492         PropositionParametersBuilder params2 = new PropositionParametersBuilder();
493         params2.add(createTermDefinition(CAMPUS_CODE_TERM_NAME, String.class, agendaWrapper.context).getId(),
494                 PropositionParameterType.TERM);
495         params2.add("DD", PropositionParameterType.CONSTANT);
496         params2.add("=", PropositionParameterType.OPERATOR);
497 
498         StringBuilder propositionNameBuilder = new StringBuilder(agendaWrapper.firstItemRule.getName());
499 
500         PropositionDefinition.Builder propositionBuilder =
501                 createPropositionDefinition(propositionNameBuilder.toString(), params1, agendaWrapper.firstItemRule);
502         parentProposition.getCompoundComponents().add(propositionBuilder);
503 
504 
505         PropositionDefinition.Builder proposition2Builder =
506                 createPropositionDefinition(propositionNameBuilder.toString(), params2, agendaWrapper.firstItemRule);
507         parentProposition.getCompoundComponents().add(proposition2Builder);
508 
509         rule2Builder.setProposition(parentProposition);
510         RuleDefinition updatedFirstRule = rule2Builder.build();
511         RuleDefinition updatedRuleDef = ruleBoService.updateRule(updatedFirstRule);
512 
513         PropositionDefinition deletedParentProp = propositionBoService.getPropositionById(
514                 agendaWrapper.firstItemRule.getProposition().getId());
515         PropositionDefinition deletedProp1 = propositionBoService.getPropositionById(
516                 agendaWrapper.firstItemRule.getProposition().getCompoundComponents().get(0).getId());
517         PropositionDefinition deletedProp2 = propositionBoService.getPropositionById(
518                 agendaWrapper.firstItemRule.getProposition().getCompoundComponents().get(1).getId());
519 
520         assertNull("Old parent proposition should be removed", deletedParentProp);
521         assertNull("Old compound proposition should be removed", deletedProp1);
522         assertNull("Old compound proposition should be removed", deletedProp2);
523     }
524 
525     @Test
526     public void testDeleteAgenda() {
527         ContextDefinition context = getContextRepository().getContextByNameAndNamespace(CONTEXT2, NAMESPACE2);
528         assertNotNull("context " + CONTEXT2 + " not found", context);
529         AgendaDefinition agenda = getAgendaBoService().getAgendaByNameAndContextId(AGENDA2, context.getId());
530         assertNotNull("agenda " + AGENDA2 + " not found", agenda);
531         AgendaItemDefinition agendaItem = getAgendaBoService().getAgendaItemById(agenda.getFirstItemId());
532         assertNotNull("agenda item " + agenda.getFirstItemId() + " not found", agendaItem);
533 
534         AgendaItemDefinition firstItem = getAgendaBoService().getAgendaItemById(agenda.getFirstItemId());
535         RuleDefinition firstItemRule = firstItem.getRule();
536         List<ActionDefinition> firstActionDefinitions = firstItemRule.getActions();
537 
538         AgendaItemDefinition secondItem = firstItem.getAlways();
539         RuleDefinition secondItemRule =   secondItem.getRule();
540         List<ActionDefinition> secondActionDefinitions = secondItemRule.getActions();
541 
542         AgendaItemDefinition thirdItem = secondItem.getAlways();
543         RuleDefinition thirdItemRule = thirdItem.getRule();
544         List<ActionDefinition> thirdActionDefinitions = thirdItemRule.getActions();
545 
546         getAgendaBoService().deleteAgenda(agenda.getId());
547 
548         AgendaDefinition deletedAgenda = getAgendaBoService().getAgendaByAgendaId( agenda.getId() );
549         assertNull("Agenda should have been deleted", deletedAgenda);
550 
551         AgendaItemDefinition deletedAgendaItem =  getAgendaBoService().getAgendaItemById( firstItem.getId() );
552         assertNull("First Agenda item should have been deleted as part of agenda delete", deletedAgendaItem);
553 
554         AgendaItemDefinition deletedSecondAgendaItem =  getAgendaBoService().getAgendaItemById( secondItem.getId() );
555         assertNull("Second Agenda item should have been deleted as part of agenda delete", deletedSecondAgendaItem);
556 
557         AgendaItemDefinition deletedThirdAgendaItem =  getAgendaBoService().getAgendaItemById( thirdItem.getId() );
558         assertNull("Third Agenda item should have been deleted as part of agenda delete", deletedThirdAgendaItem);
559 
560         RuleDefinition deletedFirstRule = getRuleBoService().getRuleByRuleId(firstItemRule.getId());
561         assertNull("First rule should have been deleted as part of agenda delete", deletedFirstRule);
562 
563         RuleDefinition deletedSecondRule = getRuleBoService().getRuleByRuleId(secondItemRule.getId());
564         assertNull("Second rule should have been deleted as part of agenda delete", deletedSecondRule);
565 
566         RuleDefinition deletedThirdRule = getRuleBoService().getRuleByRuleId(thirdItemRule.getId());
567         assertNull("Third rule should have been deleted as part of agenda delete", deletedThirdRule);
568 
569         List<ActionDefinition> actionDefinitionList = new ArrayList<ActionDefinition>();
570 
571         for (ActionDefinition actionDefinition: firstActionDefinitions) {
572             actionDefinitionList.add(actionDefinition);
573         }
574 
575         for (ActionDefinition actionDefinition: secondActionDefinitions) {
576             actionDefinitionList.add(actionDefinition);
577         }
578 
579         for (ActionDefinition actionDefinition: thirdActionDefinitions) {
580             actionDefinitionList.add(actionDefinition);
581         }
582 
583         for(ActionDefinition actionDef : actionDefinitionList) {
584             ActionDefinition deletedActionDef = getActionBoService().getActionByActionId( actionDef.getId() );
585             assertNull("All action definitions not deleted as part of agenda delete", deletedActionDef);
586         }
587     }
588 
589     @Test
590     public void testDeleteAgenda_WithNoAgendaItems() {
591         AgendaDefinition emptyAgendaDefinition = createEmptyAgenda(CONTEXT1, "testAgenda-deleteEmptyAgenda");
592 
593         // get it as a business object
594         final AgendaBo bo = getDataObjectService().find(AgendaBo.class, emptyAgendaDefinition.getId());
595 
596         getAgendaBoService().deleteAgenda(bo.getId());
597 
598         AgendaDefinition deletedAgenda = getAgendaBoService().getAgendaByAgendaId( bo.getId() );
599         assertNull("Agenda should have been deleted", deletedAgenda);
600     }
601 
602     private AgendaDefinition createEmptyAgenda(String contextName, String agendaName) {
603         String namespace = getNamespaceByContextName(contextName);
604         if (StringUtils.isBlank(namespace)) {
605             throw new RiceRuntimeException("namespace is " + namespace + " for context with name " + CONTEXT1);
606         }
607 
608         ContextDefinition context = getContextRepository().getContextByNameAndNamespace(CONTEXT1, namespace);
609 
610         // Get an agenda to use as a template for agenda creation
611         List<AgendaDefinition> agendas = getAgendaBoService().getAgendasByContextId(context.getId());
612         AgendaDefinition templateAgenda = agendas.get(0);
613 
614         AgendaDefinition.Builder agendaBuilder = AgendaDefinition.Builder.create(templateAgenda);
615 
616         agendaBuilder.setFirstItemId(null);
617         agendaBuilder.setId(null);
618         agendaBuilder.setVersionNumber(null);
619         agendaBuilder.setName("testAgendaCrud-agenda");
620 
621         // create agenda
622         AgendaDefinition newAgenda = getAgendaBoService().createAgenda(agendaBuilder.build());
623 
624         return newAgenda;
625     }
626 
627     @Test
628     public void testAgendaCrud() {
629 
630         // create agenda
631         AgendaDefinition newAgenda = createEmptyAgenda(CONTEXT1, "testAgendaCrud-agenda");
632 
633         // verify the agenda is there and
634         assertNotNull(newAgenda);
635         // we depend on working equals for AgendaDefinition here
636         assertEquals(newAgenda, getAgendaBoService().getAgendaByAgendaId(newAgenda.getId()));
637 
638 //        List<AgendaItemDefinition> templateAgendaItems = getAgendaBoService().getAgendaItemsByAgendaId(templateAgenda.getId());
639 //        List<AgendaItemDefinition.Builder> agendaItemBuilders = new ArrayList<AgendaItemDefinition.Builder>();
640 //
641 //        for (AgendaItemDefinition templateAgendaItem : templateAgendaItems) {
642 //            AgendaItemDefinition.Builder agendaItemBuilder = AgendaItemDefinition.Builder.create(templateAgendaItem);
643 //            agendaItemBuilder.setAlwaysId(null);
644 //            agendaItemBuilder.setWhenFalseId(null);
645 //            agendaItemBuilder.setWhenTrueId(null);
646 //            agendaItemBuilder.setAgendaId(newAgenda.getId());
647 //            agendaItemBuilder.set
648 //        }
649 
650     }
651 
652     /**
653      * This uses an Agenda which has 4 Agenda Items, 3 of which are nested.  The Agenda is updated with all
654      * new Agenda Items, also nested 3 deep.  The Rules, Proposition and Actions in the original are checked
655      * to be sure they are not orphaned after the update.  The new Agenda is tested to see if the new Agenda Items
656      * and Rules exist.
657      */
658     @Test
659     public void testUpdateAgendaMega() {
660         AgendaDefinitionDataWrapper agendaWrapper = new AgendaDefinitionDataWrapper();
661         ContextDefinition contextDef = agendaWrapper.context;
662         AgendaDefinition agendaDef = agendaWrapper.agenda;
663 
664         AgendaItemDefinition agendaItemDefOriginal1 = agendaWrapper.firstItem;
665         AgendaItemDefinition agendaItemDefOriginal2 = agendaWrapper.secondItem;
666         AgendaItemDefinition agendaItemDefOriginal3 = agendaWrapper.thirdItem;
667         AgendaItemDefinition agendaItemDefOriginal4 = agendaWrapper.fourthItem;
668 
669         // Existing Rules
670         RuleDefinition ruleDef1 = agendaItemDefOriginal1.getRule();
671         RuleDefinition ruleDef2 = agendaItemDefOriginal2.getRule();
672         RuleDefinition ruleDef3 = agendaItemDefOriginal3.getRule();
673         RuleDefinition ruleDef4 = agendaItemDefOriginal4.getRule();
674 
675         // Existing Propositions
676         PropositionDefinition propDef1 = ruleDef1.getProposition();
677         PropositionDefinition propDef2 = ruleDef2.getProposition();
678         PropositionDefinition propDef3 = ruleDef3.getProposition();
679         PropositionDefinition propDef4 = ruleDef4.getProposition();
680 
681         // Existing Actions
682         List<ActionDefinition> actionDefs1 = ruleDef1.getActions();
683         List<ActionDefinition> actionDefs2 = ruleDef2.getActions();
684         List<ActionDefinition> actionDefs3 = ruleDef3.getActions();
685         List<ActionDefinition> actionDefs4 = ruleDef4.getActions();
686 
687         // "Build" new Agenda Item Defs and Rules
688         AgendaItemDefinition.Builder agendaItemDefBuilder1 = AgendaItemDefinition.Builder.create(null, agendaDef.getId());
689         agendaItemDefBuilder1.setRuleId(createRuleDefinition1(contextDef, "New Agenda", NAMESPACE1).getId());
690         agendaItemDefBuilder1.setRule(RuleDefinition.Builder.create(ruleBoService.getRuleByRuleId(
691                 agendaItemDefBuilder1.getRuleId())));
692 
693         AgendaItemDefinition.Builder agendaItemDefBuilder2 = AgendaItemDefinition.Builder.create(null, agendaDef.getId());
694         agendaItemDefBuilder1.setAlways(agendaItemDefBuilder2);
695         agendaItemDefBuilder2.setRuleId(createRuleDefinition2(contextDef, "New Agenda", NAMESPACE1).getId());
696         agendaItemDefBuilder2.setRule(RuleDefinition.Builder.create(ruleBoService.getRuleByRuleId(
697                 agendaItemDefBuilder2.getRuleId())));
698 
699         AgendaItemDefinition.Builder agendaItemDefBuilder3 = AgendaItemDefinition.Builder.create(null, agendaDef.getId());
700         agendaItemDefBuilder2.setAlways(agendaItemDefBuilder3);
701         agendaItemDefBuilder3.setRuleId(createRuleDefinition3(contextDef, "New Agenda", NAMESPACE1).getId());
702         agendaItemDefBuilder3.setRule(RuleDefinition.Builder.create(ruleBoService.getRuleByRuleId(
703                 agendaItemDefBuilder3.getRuleId())));
704 
705         AgendaItemDefinition.Builder agendaItemDefBuilder4 = AgendaItemDefinition.Builder.create(null, agendaDef.getId());
706         agendaItemDefBuilder3.setAlways(agendaItemDefBuilder4);
707         agendaItemDefBuilder4.setRuleId(createRuleDefinition4(contextDef, "New Agenda", NAMESPACE1).getId());
708         agendaItemDefBuilder4.setRule(RuleDefinition.Builder.create(ruleBoService.getRuleByRuleId(
709                 agendaItemDefBuilder4.getRuleId())));
710 
711         // Create 4 the new Agenda Item Defs, nesting them
712         AgendaItemDefinition agendaItemDefNew4 = agendaBoService.createAgendaItem(agendaItemDefBuilder4.build());
713 
714         agendaItemDefBuilder3.setAlwaysId(agendaItemDefNew4.getId());
715         agendaItemDefBuilder3.setAlways(AgendaItemDefinition.Builder.create(agendaItemDefNew4));
716         AgendaItemDefinition agendaItemDefNew3 = agendaBoService.createAgendaItem(agendaItemDefBuilder3.build());
717 
718         agendaItemDefBuilder2.setAlwaysId(agendaItemDefNew3.getId());
719         agendaItemDefBuilder2.setAlways(AgendaItemDefinition.Builder.create(agendaItemDefNew3));
720         AgendaItemDefinition agendaItemDefNew2 = agendaBoService.createAgendaItem(agendaItemDefBuilder2.build());
721 
722         agendaItemDefBuilder1.setAlwaysId(agendaItemDefNew2.getId());
723         agendaItemDefBuilder1.setAlways(AgendaItemDefinition.Builder.create(agendaItemDefNew2));
724         AgendaItemDefinition agendaItemDefNew1 = agendaBoService.createAgendaItem(agendaItemDefBuilder1.build());
725 
726         AgendaDefinition.Builder agendaDefBuilder = AgendaDefinition.Builder.create(agendaDef);
727         agendaDefBuilder.setFirstItemId(agendaItemDefNew1.getId());
728 
729         agendaDef = agendaDefBuilder.build();
730 
731         // Update Agenda Definition
732         AgendaDefinition agendaDefUpdated = agendaBoService.updateAgenda(agendaDef);
733 
734         // Original Agenda Item Defs deleted?
735         assertNull("First agenda item should be deleted", agendaBoService.getAgendaItemById(agendaItemDefOriginal1.getId()));
736         assertNull("Second agenda item should be deleted", agendaBoService.getAgendaItemById(agendaItemDefOriginal2.getId()));
737         assertNull("Third agenda item should be deleted", agendaBoService.getAgendaItemById(agendaItemDefOriginal3.getId()));
738         assertNull("Fourth agenda item should be deleted", agendaBoService.getAgendaItemById(agendaItemDefOriginal4.getId()));
739 
740         // Original Rules deleted?
741         assertNull("First agenda item rule should be deleted", ruleBoService.getRuleByRuleId(ruleDef1.getId()));
742         assertNull("Second agenda item rule should be deleted", ruleBoService.getRuleByRuleId(ruleDef2.getId()));
743         assertNull("Third agenda item rule should be deleted", ruleBoService.getRuleByRuleId(ruleDef3.getId()));
744         assertNull("Fourth agenda item rule should be deleted", ruleBoService.getRuleByRuleId(ruleDef4.getId()));
745 
746         // Original Proposition and Compound Components deleted?
747         assertNull("First rule proposition should be deleted", propositionBoService.getPropositionById(propDef1.getId()));
748         assertNull("First rule compound component 0 should be deleted",
749                 propositionBoService.getPropositionById(propDef1.getCompoundComponents().get(0).getId()));
750         assertNull("First rule compound component 1 should be deleted",
751                 propositionBoService.getPropositionById(propDef1.getCompoundComponents().get(1).getId()));
752 
753         assertNull("Second rule proposition should be deleted", propositionBoService.getPropositionById(propDef2.getId()));
754         assertNull("Second rule compound component 0 should be deleted",
755                 propositionBoService.getPropositionById(propDef2.getCompoundComponents().get(0).getId()));
756         assertNull("Second rule compound component 1 should be deleted",
757                 propositionBoService.getPropositionById(propDef2.getCompoundComponents().get(1).getId()));
758 
759         // This one does not have any Compound Components (not sure why)
760         assertNull("Second rule proposition should be deleted", propositionBoService.getPropositionById(propDef3.getId()));
761 
762         assertNull("Fourth rule proposition should be deleted", propositionBoService.getPropositionById(propDef4.getId()));
763         assertNull("Fourth rule compound component 0 should be deleted",
764                 propositionBoService.getPropositionById(propDef4.getCompoundComponents().get(0).getId()));
765         assertNull("Fourth rule compound component 1 should be deleted",
766                 propositionBoService.getPropositionById(propDef4.getCompoundComponents().get(1).getId()));
767 
768         // Actions deleted?
769         assertNull("First rule action should be deleted", actionBoService.getActionByActionId(actionDefs1.get(0).getId()));
770         assertNull("Second rule action should be deleted", actionBoService.getActionByActionId(actionDefs2.get(0).getId()));
771         assertNull("Third rule action should be deleted", actionBoService.getActionByActionId(actionDefs3.get(0).getId()));
772         assertNull("Fourth rule action should be deleted", actionBoService.getActionByActionId(actionDefs4.get(0).getId()));
773 
774         // New Agenda Items there?
775         AgendaItemDefinition agendaItemDefVerify1 = getAgendaBoService().getAgendaItemById(agendaDefUpdated.getFirstItemId());
776         AgendaItemDefinition agendaItemDefVerify2 = agendaItemDefVerify1.getAlways();
777         AgendaItemDefinition agendaItemDefVerify3 = agendaItemDefVerify2.getAlways();
778         AgendaItemDefinition agendaItemDefVerify4 = agendaItemDefVerify3.getAlways();
779 
780         assertNotNull("First updated agenda item should not be null", agendaItemDefVerify1);
781         assertNotNull("Second updated agenda item should not be null", agendaItemDefVerify2);
782         assertNotNull("Third updated agenda item should not be null", agendaItemDefVerify3);
783         assertNotNull("Fourth updated agenda item should not be null", agendaItemDefVerify4);
784 
785         // New Rules there?
786         assertNotNull("First agenda item rule should not be null", ruleBoService.getRuleByRuleId(agendaItemDefVerify1.getRuleId()));
787         assertNotNull("Second agenda item rule should not be null", ruleBoService.getRuleByRuleId(agendaItemDefVerify2.getRuleId()));
788         assertNotNull("Third agenda item rule should not be null", ruleBoService.getRuleByRuleId(agendaItemDefVerify3.getRuleId()));
789         assertNotNull("Fourth agenda item rule should not be null", ruleBoService.getRuleByRuleId(agendaItemDefVerify4.getRuleId()));
790     }
791 
792     @Test
793     public void testUpdateAgendaPullLowerTwo () {
794         ContextDefinition context = getContextRepository().getContextByNameAndNamespace(CONTEXT2, NAMESPACE2);
795         assertNotNull("context " + CONTEXT2 + " not found", context);
796         AgendaDefinition agendaDef = getAgendaBoService().getAgendaByNameAndContextId(AGENDA3, context.getId());
797         assertNotNull("agenda " + AGENDA3 + " not found", agendaDef);
798 
799         AgendaItemDefinition agendaItemDefOriginal1 = getAgendaBoService().getAgendaItemById(agendaDef.getFirstItemId());
800         assertNotNull("agenda item " + agendaDef.getFirstItemId() + " not found", agendaItemDefOriginal1);
801         AgendaItemDefinition agendaItemDefOriginal2 = agendaItemDefOriginal1.getAlways();
802         AgendaItemDefinition agendaItemDefOriginal3 = agendaItemDefOriginal2.getAlways();
803         AgendaItemDefinition agendaItemDefOriginal4 = agendaItemDefOriginal3.getAlways();
804 
805         // Existing Rules
806         RuleDefinition ruleDef1 = agendaItemDefOriginal1.getRule();
807         RuleDefinition ruleDef2 = agendaItemDefOriginal2.getRule();
808         RuleDefinition ruleDef3 = agendaItemDefOriginal3.getRule();
809         RuleDefinition ruleDef4 = agendaItemDefOriginal4.getRule();
810 
811         // Existing Propositions
812         PropositionDefinition propDef1 = ruleDef1.getProposition();
813         PropositionDefinition propDef2 = ruleDef2.getProposition();
814         PropositionDefinition propDef3 = ruleDef3.getProposition();
815         PropositionDefinition propDef4 = ruleDef4.getProposition();
816 
817         // Existing Actions
818         List<ActionDefinition> actionDefs1 = ruleDef1.getActions();
819         List<ActionDefinition> actionDefs2 = ruleDef2.getActions();
820         List<ActionDefinition> actionDefs3 = ruleDef3.getActions();
821         List<ActionDefinition> actionDefs4 = ruleDef4.getActions();
822 
823         // Rebuild based on AgendaItemDefs 1 and 2.
824         AgendaItemDefinition.Builder agendaItemDefBuilder1 = AgendaItemDefinition.Builder.create(agendaItemDefOriginal1);
825         AgendaItemDefinition.Builder agendaItemDefBuilder2 = AgendaItemDefinition.Builder.create(agendaItemDefOriginal2);
826 
827         // Force force the always list to end at AgendaItemDef 2
828         agendaItemDefBuilder2.setAlwaysId(null);
829         agendaItemDefBuilder2.setAlways(null);
830 
831         // Build
832         AgendaItemDefinition agendaItemDefNew2 = agendaItemDefBuilder2.build();
833         AgendaItemDefinition agendaItemDefNew1 = agendaItemDefBuilder1.build();
834 
835         // update AgendaItemDef 2.
836         agendaBoService.updateAgendaItem(agendaItemDefNew2);
837 
838         // Build new AgendaDef based on existing one
839         AgendaDefinition.Builder agendaDefBuilder = AgendaDefinition.Builder.create(agendaDef);
840         agendaDefBuilder.setFirstItemId(agendaItemDefNew1.getId());
841         agendaDef = agendaDefBuilder.build();
842 
843         // Update Agenda Definition
844         AgendaDefinition agendaDefUpdated = agendaBoService.updateAgenda(agendaDef);
845 
846         // Original Agenda Item Defs deleted?
847         assertNull("Third agenda item should be deleted", agendaBoService.getAgendaItemById(agendaItemDefOriginal3.getId()));
848         assertNull("Fourth agenda item should be deleted", agendaBoService.getAgendaItemById(agendaItemDefOriginal4.getId()));
849 
850         // Original Rules deleted?
851         RuleDefinition ruleDefCheck = ruleBoService.getRuleByRuleId(ruleDef3.getId());
852         assertNull("Third agenda item rule should be deleted", ruleBoService.getRuleByRuleId(ruleDef3.getId()));
853         assertNull("Fourth agenda item rule should be deleted", ruleBoService.getRuleByRuleId(ruleDef4.getId()));
854 
855         // Original Proposition and Compound Components deleted?
856         // This rule does not have any Compound Components (not sure why)
857         assertNull("Third rule proposition should be deleted", propositionBoService.getPropositionById(propDef3.getId()));
858 
859         assertNull("Fourth rule proposition should be deleted", propositionBoService.getPropositionById(propDef4.getId()));
860         assertNull("Fourth rule compound component 0 should be deleted",
861                 propositionBoService.getPropositionById(propDef4.getCompoundComponents().get(0).getId()));
862         assertNull("Fourth rule compound component 1 should be deleted",
863                 propositionBoService.getPropositionById(propDef4.getCompoundComponents().get(1).getId()));
864 
865         // Actions deleted?
866         assertNull("Third rule action should be deleted", actionBoService.getActionByActionId(actionDefs3.get(0).getId()));
867         assertNull("Fourth rule action should be deleted", actionBoService.getActionByActionId(actionDefs4.get(0).getId()));
868 
869         // New Agenda Items there?
870         AgendaItemDefinition agendaItemDefVerify1 = getAgendaBoService().getAgendaItemById(agendaDefUpdated.getFirstItemId());
871         AgendaItemDefinition agendaItemDefVerify2 = agendaItemDefVerify1.getAlways();
872 
873         assertNotNull("First updated agenda item should not be null", agendaItemDefVerify1);
874         assertNotNull("Second updated agenda item should not be null", agendaItemDefVerify2);
875 
876         // New Rules there?
877         assertNotNull("First agenda item rule should not be null", ruleBoService.getRuleByRuleId(agendaItemDefVerify1.getRuleId()));
878         assertNotNull("Second agenda item rule should not be null", ruleBoService.getRuleByRuleId(agendaItemDefVerify2.getRuleId()));
879     }
880 
881 }