View Javadoc

1   /**
2    * Copyright 2005-2011 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.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   * Validation Integration Test
63   * @author Kuali Rice Team (rice.collab@kuali.org)
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          // like RepositoryCreateAndExecuteIntegrationTest
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    This test requires:
114    1. changing the BaselineMode to (Mode.NONE).
115    2. Setting a breakpoint on the first line.
116    3. Debug the test.
117    4. When you reach the breakpoint, re-impex (and then apply the db test script) your database.
118    5. Continue.  No exceptions should be thrown.
119     @Test
120     public void testDbAgendaItems() {
121         AgendaDefinition agendaDefinition = agendaBoService.getAgendaByNameAndContextId("My Fabulous Agenda", "CONTEXT1"); // values from populated test db
122         lookupAndSaveDataObject(agendaDefinition);
123         agendaDefinition = agendaBoService.getAgendaByNameAndContextId("SimpleAgendaCompoundProp", "CONTEXT1"); // values from populated test db
124         lookupAndSaveDataObject(agendaDefinition);
125         agendaDefinition = agendaBoService.getAgendaByNameAndContextId("One Big Rule", "CONTEXT1"); // values from populated test db
126         lookupAndSaveDataObject(agendaDefinition);
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 }