001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. The ASF licenses this file to You
004: * under the Apache License, Version 2.0 (the "License"); you may not
005: * use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.apache.org/licenses/LICENSE-2.0
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. For additional information regarding
015: * copyright in this work, please see the NOTICE file in the top level
016: * directory of this distribution.
017: */
018: /*
019: * PropertiesTest.java
020: *
021: * Created on April 9, 2006, 2:51 PM
022: */
023:
024: package org.apache.roller.business;
025:
026: import java.util.Map;
027: import junit.framework.Test;
028: import junit.framework.TestCase;
029: import junit.framework.TestSuite;
030: import org.apache.commons.logging.Log;
031: import org.apache.commons.logging.LogFactory;
032: import org.apache.roller.TestUtils;
033: import org.apache.roller.business.PropertiesManager;
034: import org.apache.roller.business.RollerFactory;
035: import org.apache.roller.pojos.RollerPropertyData;
036:
037: /**
038: * Test Properties related business operations.
039: *
040: * That includes:
041: *
042: */
043: public class PropertiesTest extends TestCase {
044:
045: public static Log log = LogFactory.getLog(PropertiesTest.class);
046:
047: public PropertiesTest(String name) {
048: super (name);
049: }
050:
051: public static Test suite() {
052: return new TestSuite(PropertiesTest.class);
053: }
054:
055: public void setUp() throws Exception {
056:
057: }
058:
059: public void tearDown() throws Exception {
060:
061: }
062:
063: public void testProperiesCRUD() throws Exception {
064:
065: // remember, the properties table is initialized during Roller startup
066: PropertiesManager mgr = RollerFactory.getRoller()
067: .getPropertiesManager();
068: TestUtils.endSession(true);
069:
070: RollerPropertyData prop = null;
071:
072: // get a property by name
073: prop = mgr.getProperty("site.name");
074: assertNotNull(prop);
075:
076: // update a property
077: prop.setValue("testtest");
078: mgr.saveProperty(prop);
079: TestUtils.endSession(true);
080:
081: // make sure property was updated
082: prop = null;
083: prop = mgr.getProperty("site.name");
084: assertNotNull(prop);
085: assertEquals("testtest", prop.getValue());
086:
087: // get all properties
088: Map props = mgr.getProperties();
089: assertNotNull(props);
090: assertTrue(props.containsKey("site.name"));
091:
092: // update multiple properties
093: prop = (RollerPropertyData) props.get("site.name");
094: prop.setValue("foofoo");
095: prop = (RollerPropertyData) props.get("site.description");
096: prop.setValue("blahblah");
097: mgr.saveProperties(props);
098: TestUtils.endSession(true);
099:
100: // make sure all properties were updated
101: props = mgr.getProperties();
102: assertNotNull(props);
103: assertEquals("foofoo", ((RollerPropertyData) props
104: .get("site.name")).getValue());
105: assertEquals("blahblah", ((RollerPropertyData) props
106: .get("site.description")).getValue());
107: }
108:
109: }
|