001: /*
002: * Copyright 2005-2007 The Kuali Foundation.
003: *
004: *
005: * Licensed under the Educational Community License, Version 1.0 (the "License");
006: * you may not use this file except in compliance with the License.
007: * You may obtain a copy of the License at
008: *
009: * http://www.opensource.org/licenses/ecl1.php
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017: // Created on Dec 14, 2005
018: package edu.iu.uis.eden.applicationconstants;
019:
020: import junit.framework.AssertionFailedError;
021:
022: import org.junit.Test;
023: import org.kuali.workflow.test.WorkflowTestCase;
024:
025: import edu.iu.uis.eden.KEWServiceLocator;
026: import edu.iu.uis.eden.WorkflowServiceErrorException;
027:
028: /**
029: * Tests adding/modifying an application constant
030: * @author Aaron Hamid
031: * @author rkirkend
032: */
033: public class ApplicationConstantsTest extends WorkflowTestCase {
034: private static final String CONSTANT_NAME = "BogusConstant";
035: private static final String CONSTANT_VALUE = "test value";
036:
037: @Test
038: public void testApplicationConstantsDeleteCacheInteraction() {
039: ApplicationConstantsService appConstSrv = KEWServiceLocator
040: .getApplicationConstantsService();
041: String name = "testName";
042: String value = "testValue";
043: ApplicationConstant constant = new ApplicationConstant(name,
044: value);
045: appConstSrv.save(constant);
046:
047: //verify that the constant is there.
048: constant = appConstSrv.findByName(name);
049: assertNotNull("Constant should have been fetched.", constant);
050:
051: //that fetch should have put the constant in the cache. verify using the cache service
052: constant = (ApplicationConstant) KEWServiceLocator
053: .getCacheAdministrator().getFromCache(name);
054: assertNotNull("Constant should have been in cache", constant);
055:
056: //delete the constant and verify that it's not in the cache
057: appConstSrv.delete(constant);
058: constant = (ApplicationConstant) KEWServiceLocator
059: .getCacheAdministrator().getFromCache(name);
060: assertNull("Constant should no longer be in the cache",
061: constant);
062:
063: //verify that the service isn't giving any deleted constants
064: constant = appConstSrv.findByName(name);
065: assertNull("Constant should be deleted and not fetched.",
066: constant);
067: }
068:
069: @Test
070: public void testApplicationConstantsUpdateCacheInteraction() {
071: ApplicationConstantsService appConstSrv = KEWServiceLocator
072: .getApplicationConstantsService();
073: String name = "testName";
074: String value = "testValue";
075: ApplicationConstant constant = new ApplicationConstant(name,
076: value);
077: appConstSrv.save(constant);
078:
079: //verify that the constant is there.
080: constant = appConstSrv.findByName(name);
081: assertNotNull("Constant should have been fetched.", constant);
082:
083: //that fetch should have put the constant in the cache. verify using the cache service
084: constant = (ApplicationConstant) KEWServiceLocator
085: .getCacheAdministrator().getFromCache(name);
086: assertNotNull("Constant should have been in cache", constant);
087:
088: String newValue = "new Value";
089:
090: constant.setApplicationConstantValue(newValue);
091: appConstSrv.save(constant);
092:
093: constant = appConstSrv.findByName(name);
094: assertEquals("Constants value should have been updated",
095: newValue, constant.getApplicationConstantValue());
096:
097: //check that it's in the cache correctly
098: constant = (ApplicationConstant) KEWServiceLocator
099: .getCacheAdministrator().getFromCache(name);
100: assertEquals(
101: "Constants value should have been updated in the cache",
102: newValue, constant.getApplicationConstantValue());
103: }
104:
105: @Test
106: public void testConstants() {
107: ApplicationConstantsService acs = KEWServiceLocator
108: .getApplicationConstantsService();
109: ApplicationConstant ac = acs.findByName(CONSTANT_NAME);
110: assertNull(ac);
111: ac = new ApplicationConstant();
112: ac.setApplicationConstantName(CONSTANT_NAME);
113:
114: try {
115: acs.save(ac);
116: throw new AssertionFailedError("Empty constant was saved");
117: } catch (WorkflowServiceErrorException wsee) {
118: // should be thrown due to empty constant value
119: // log.info("WorkflowServiceErrorException due to empty constant value should follow.");
120: // wsee.printStackTrace();
121: }
122:
123: assertNull(acs.findByName(CONSTANT_NAME));
124:
125: ac.setApplicationConstantValue(CONSTANT_VALUE);
126: acs.save(ac);
127: ac = acs.findByName(CONSTANT_NAME);
128: assertNotNull(ac);
129: assertEquals(CONSTANT_NAME, ac.getApplicationConstantName());
130: assertEquals(CONSTANT_VALUE, ac.getApplicationConstantValue());
131:
132: ac = new ApplicationConstant();
133: ac.setApplicationConstantName(CONSTANT_NAME);
134: ac.setApplicationConstantValue(CONSTANT_VALUE);
135: // try {
136: acs.save(ac);
137: // fail("Exception should have been thrown from lack of version number");
138: // } catch (OjbOperationException ooe) {
139: // should throw an exception because lockvernbr is not set
140: // }
141:
142: ac = acs.findByName(CONSTANT_NAME);
143: assertNotNull(ac);
144: assertEquals(CONSTANT_NAME, ac.getApplicationConstantName());
145: assertEquals(CONSTANT_VALUE, ac.getApplicationConstantValue());
146: ac.setApplicationConstantValue(CONSTANT_VALUE + "2");
147:
148: acs.save(ac);
149:
150: ac = acs.findByName(CONSTANT_NAME);
151: assertNotNull(ac);
152: assertEquals(CONSTANT_NAME, ac.getApplicationConstantName());
153: assertEquals(CONSTANT_VALUE + "2", ac
154: .getApplicationConstantValue());
155: }
156: }
|