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.agenda.AgendaDefinition;
21  import org.kuali.rice.krms.api.repository.context.ContextDefinition;
22  import org.kuali.rice.krms.api.repository.type.KrmsTypeDefinition;
23  import org.kuali.rice.krms.impl.repository.ActionBoService;
24  import org.kuali.rice.krms.impl.repository.ActionBoServiceImpl;
25  import org.kuali.rice.krms.impl.repository.AgendaBo;
26  import org.kuali.rice.krms.impl.repository.AgendaBoService;
27  import org.kuali.rice.krms.impl.repository.AgendaBoServiceImpl;
28  import org.kuali.rice.krms.impl.repository.ContextBoServiceImpl;
29  import org.kuali.rice.krms.impl.repository.KrmsRepositoryServiceLocator;
30  import org.kuali.rice.krms.impl.repository.PropositionBoService;
31  import org.kuali.rice.krms.impl.repository.PropositionBoServiceImpl;
32  import org.kuali.rice.krms.impl.repository.RuleBoService;
33  import org.kuali.rice.krms.impl.repository.RuleBoServiceImpl;
34  import org.kuali.rice.krms.impl.repository.TermBoService;
35  import org.kuali.rice.krms.impl.repository.TermBoServiceImpl;
36  import org.kuali.rice.krms.test.AbstractBoTest;
37  import org.kuali.rice.test.BaselineTestCase.BaselineMode;
38  import org.kuali.rice.test.BaselineTestCase.Mode;
39  
40  import java.util.Collections;
41  import java.util.HashMap;
42  import java.util.Map;
43  
44  /**
45   * Validation Integration Test
46   * @author Kuali Rice Team (rice.collab@kuali.org)
47   */
48  @BaselineMode(Mode.CLEAR_DB)
49  public class AgendaEditorMaintainableIntegrationTest extends AbstractBoTest {
50  
51      static final String NAMESPACE1 = "AEMIT_KRMS_TEST_1";
52      static final String CONTEXT1 = "AEMIT_Context1";
53  
54      static final String CONTEXT1_QUALIFIER = "Context1Qualifier";
55      static final String CONTEXT1_QUALIFIER_VALUE = "BLAH1";
56      static final String AGENDA1 = "TestAgenda1";
57  
58      private PropositionBoService propositionBoService;
59      private TermBoService termBoService;
60      private AgendaBoService agendaBoService;
61      private RuleBoService ruleBoService;
62      private ActionBoService actionBoService;
63  
64      @Before
65      public void setup() {
66  
67          krmsAttributeDefinitionService = KrmsRepositoryServiceLocator.getKrmsAttributeDefinitionService();
68          krmsTypeRepository = KrmsRepositoryServiceLocator.getKrmsTypeRepositoryService();
69  
70          // like RepositoryCreateAndExecuteIntegrationTest
71          propositionBoService = new PropositionBoServiceImpl();
72          ((PropositionBoServiceImpl)propositionBoService).setBusinessObjectService(getBoService());
73          termBoService = new TermBoServiceImpl();
74          ((TermBoServiceImpl)termBoService).setBusinessObjectService(getBoService());
75          contextRepository = new ContextBoServiceImpl();
76          ((ContextBoServiceImpl)contextRepository).setBusinessObjectService(getBoService());
77          agendaBoService = new AgendaBoServiceImpl();
78          ((AgendaBoServiceImpl)agendaBoService).setBusinessObjectService(getBoService());
79          ((AgendaBoServiceImpl)agendaBoService).setAttributeDefinitionService(krmsAttributeDefinitionService);
80          ruleBoService = new RuleBoServiceImpl();
81          ((RuleBoServiceImpl)ruleBoService).setBusinessObjectService(getBoService());
82          actionBoService = new ActionBoServiceImpl();
83          ((ActionBoServiceImpl)actionBoService).setBusinessObjectService(getBoService());
84      }
85  
86      @Test
87      public void testEmptyAgendaDelete() {
88          ContextDefinition contextDefintion1 = createContextDefinition(NAMESPACE1, CONTEXT1, Collections.singletonMap(
89                  CONTEXT1_QUALIFIER, CONTEXT1_QUALIFIER_VALUE));
90          createAgendaDefinition(AGENDA1, "AgendaLabel", contextDefintion1);
91          AgendaDefinition agendaDefinition = agendaBoService.getAgendaByNameAndContextId(AGENDA1, contextDefintion1.getId());
92  
93          lookupAndSaveDataObject(agendaDefinition);
94      }
95  
96  /*
97     This test requires:
98     1. changing the BaselineMode to (Mode.NONE).
99     2. Setting a breakpoint on the first line.
100    3. Debug the test.
101    4. When you reach the breakpoint, re-impex (and then apply the db test script) your database.
102    5. Continue.  No exceptions should be thrown.
103     @Test
104     public void testDbAgendaItems() {
105         AgendaDefinition agendaDefinition = agendaBoService.getAgendaByNameAndContextId("My Fabulous Agenda", "CONTEXT1"); // values from populated test db
106         lookupAndSaveDataObject(agendaDefinition);
107         agendaDefinition = agendaBoService.getAgendaByNameAndContextId("SimpleAgendaCompoundProp", "CONTEXT1"); // values from populated test db
108         lookupAndSaveDataObject(agendaDefinition);
109         agendaDefinition = agendaBoService.getAgendaByNameAndContextId("One Big Rule", "CONTEXT1"); // values from populated test db
110         lookupAndSaveDataObject(agendaDefinition);
111     }
112 */
113 
114     private void lookupAndSaveDataObject(AgendaDefinition agendaDefinition) {
115         AgendaBo blah = findAgendaByPrimaryKey(agendaDefinition);
116 
117         AgendaEditorMaintainable aem = new AgendaEditorMaintainable();
118         AgendaEditor ae = new AgendaEditor();
119         ae.setAgenda(blah);
120         aem.setDataObject(ae);
121         aem.saveDataObject();
122     }
123 
124     private AgendaBo findAgendaByPrimaryKey(AgendaDefinition agendaDefinition) {Map<String,String>
125             primaryKeys = new HashMap<String, String>();
126         primaryKeys.put("id", agendaDefinition.getId());
127         return getBoService().findByPrimaryKey(AgendaBo.class, primaryKeys);
128     }
129 
130     private void createAgendaDefinition(String agendaName, String agendaLabel, ContextDefinition contextDefinition) {
131         KrmsTypeDefinition krmsGenericTypeDefinition = createKrmsGenericTypeDefinition(contextDefinition.getNamespace(), "testAgendaTypeService", agendaName, agendaLabel);
132 
133         AgendaDefinition agendaDefinition =
134                 AgendaDefinition.Builder.create(null, agendaName, krmsGenericTypeDefinition.getId(), contextDefinition.getId()).build();
135         agendaDefinition = agendaBoService.createAgenda(agendaDefinition);
136         agendaBoService.updateAgenda(agendaDefinition);
137 
138         AgendaBo blah = findAgendaByPrimaryKey(agendaDefinition);
139 
140         AgendaDefinition.Builder agendaDefBuilder1 = AgendaDefinition.Builder.create(agendaBoService.to(blah));
141         agendaDefinition = agendaDefBuilder1.build();
142 
143         agendaBoService.updateAgenda(agendaDefinition);
144     }
145 }