001 /** 002 * Copyright 2005-2013 The Kuali Foundation 003 * 004 * Licensed under the Educational Community License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.opensource.org/licenses/ecl2.php 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016 package org.kuali.rice.krms.impl.ui; 017 018 import org.junit.Before; 019 import org.junit.Test; 020 import org.kuali.rice.krms.api.repository.agenda.AgendaDefinition; 021 import org.kuali.rice.krms.api.repository.context.ContextDefinition; 022 import org.kuali.rice.krms.api.repository.type.KrmsTypeDefinition; 023 import org.kuali.rice.krms.impl.repository.ActionBoService; 024 import org.kuali.rice.krms.impl.repository.ActionBoServiceImpl; 025 import org.kuali.rice.krms.impl.repository.AgendaBo; 026 import org.kuali.rice.krms.impl.repository.AgendaBoService; 027 import org.kuali.rice.krms.impl.repository.AgendaBoServiceImpl; 028 import org.kuali.rice.krms.impl.repository.ContextBoServiceImpl; 029 import org.kuali.rice.krms.impl.repository.KrmsRepositoryServiceLocator; 030 import org.kuali.rice.krms.impl.repository.PropositionBoService; 031 import org.kuali.rice.krms.impl.repository.PropositionBoServiceImpl; 032 import org.kuali.rice.krms.impl.repository.RuleBoService; 033 import org.kuali.rice.krms.impl.repository.RuleBoServiceImpl; 034 import org.kuali.rice.krms.impl.repository.TermBoService; 035 import org.kuali.rice.krms.impl.repository.TermBoServiceImpl; 036 import org.kuali.rice.krms.test.AbstractBoTest; 037 import org.kuali.rice.test.BaselineTestCase.BaselineMode; 038 import org.kuali.rice.test.BaselineTestCase.Mode; 039 040 import java.util.Collections; 041 import java.util.HashMap; 042 import java.util.Map; 043 044 /** 045 * Validation Integration Test 046 * @author Kuali Rice Team (rice.collab@kuali.org) 047 */ 048 @BaselineMode(Mode.CLEAR_DB) 049 public class AgendaEditorMaintainableIntegrationTest extends AbstractBoTest { 050 051 static final String NAMESPACE1 = "AEMIT_KRMS_TEST_1"; 052 static final String CONTEXT1 = "AEMIT_Context1"; 053 054 static final String CONTEXT1_QUALIFIER = "Context1Qualifier"; 055 static final String CONTEXT1_QUALIFIER_VALUE = "BLAH1"; 056 static final String AGENDA1 = "TestAgenda1"; 057 058 private PropositionBoService propositionBoService; 059 private TermBoService termBoService; 060 private AgendaBoService agendaBoService; 061 private RuleBoService ruleBoService; 062 private ActionBoService actionBoService; 063 064 @Before 065 public void setup() { 066 067 krmsAttributeDefinitionService = KrmsRepositoryServiceLocator.getKrmsAttributeDefinitionService(); 068 krmsTypeRepository = KrmsRepositoryServiceLocator.getKrmsTypeRepositoryService(); 069 070 // like RepositoryCreateAndExecuteIntegrationTest 071 propositionBoService = new PropositionBoServiceImpl(); 072 ((PropositionBoServiceImpl)propositionBoService).setBusinessObjectService(getBoService()); 073 termBoService = new TermBoServiceImpl(); 074 ((TermBoServiceImpl)termBoService).setBusinessObjectService(getBoService()); 075 contextRepository = new ContextBoServiceImpl(); 076 ((ContextBoServiceImpl)contextRepository).setBusinessObjectService(getBoService()); 077 agendaBoService = new AgendaBoServiceImpl(); 078 ((AgendaBoServiceImpl)agendaBoService).setBusinessObjectService(getBoService()); 079 ((AgendaBoServiceImpl)agendaBoService).setAttributeDefinitionService(krmsAttributeDefinitionService); 080 ruleBoService = new RuleBoServiceImpl(); 081 ((RuleBoServiceImpl)ruleBoService).setBusinessObjectService(getBoService()); 082 actionBoService = new ActionBoServiceImpl(); 083 ((ActionBoServiceImpl)actionBoService).setBusinessObjectService(getBoService()); 084 } 085 086 @Test 087 public void testEmptyAgendaDelete() { 088 ContextDefinition contextDefintion1 = createContextDefinition(NAMESPACE1, CONTEXT1, Collections.singletonMap( 089 CONTEXT1_QUALIFIER, CONTEXT1_QUALIFIER_VALUE)); 090 createAgendaDefinition(AGENDA1, "AgendaLabel", contextDefintion1); 091 AgendaDefinition agendaDefinition = agendaBoService.getAgendaByNameAndContextId(AGENDA1, contextDefintion1.getId()); 092 093 lookupAndSaveDataObject(agendaDefinition); 094 } 095 096 /* 097 This test requires: 098 1. changing the BaselineMode to (Mode.NONE). 099 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 }