KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > roller > business > PropertiesTest


1 /*
2 * Licensed to the Apache Software Foundation (ASF) under one or more
3 * contributor license agreements. The ASF licenses this file to You
4 * under the Apache License, Version 2.0 (the "License"); you may not
5 * use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
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. For additional information regarding
15 * copyright in this work, please see the NOTICE file in the top level
16 * directory of this distribution.
17 */

18 /*
19  * PropertiesTest.java
20  *
21  * Created on April 9, 2006, 2:51 PM
22  */

23
24 package org.apache.roller.business;
25
26 import java.util.Map JavaDoc;
27 import junit.framework.Test;
28 import junit.framework.TestCase;
29 import junit.framework.TestSuite;
30 import org.apache.commons.logging.Log;
31 import org.apache.commons.logging.LogFactory;
32 import org.apache.roller.TestUtils;
33 import org.apache.roller.model.PropertiesManager;
34 import org.apache.roller.model.RollerFactory;
35 import org.apache.roller.pojos.RollerPropertyData;
36
37 /**
38  * Test Properties related business operations.
39  *
40  * That includes:
41  *
42  */

43 public class PropertiesTest extends TestCase {
44     
45     public static Log log = LogFactory.getLog(PropertiesTest.class);
46     
47     
48     public PropertiesTest(String JavaDoc name) {
49         super(name);
50     }
51     
52     
53     public static Test suite() {
54         return new TestSuite(PropertiesTest.class);
55     }
56     
57     
58     public void setUp() throws Exception JavaDoc {
59         
60     }
61     
62     public void tearDown() throws Exception JavaDoc {
63         
64     }
65     
66     
67     public void testProperiesCRUD() throws Exception JavaDoc {
68         
69         // remember, the properties table is initialized during Roller startup
70
PropertiesManager mgr = RollerFactory.getRoller().getPropertiesManager();
71         TestUtils.endSession(true);
72         
73         RollerPropertyData prop = null;
74         
75         // get a property by name
76
prop = mgr.getProperty("site.name");
77         assertNotNull(prop);
78         
79         // update a property
80
prop.setValue("testtest");
81         mgr.saveProperty(prop);
82         TestUtils.endSession(true);
83         
84         // make sure property was updated
85
prop = null;
86         prop = mgr.getProperty("site.name");
87         assertNotNull(prop);
88         assertEquals("testtest", prop.getValue());
89         
90         // get all properties
91
Map JavaDoc props = mgr.getProperties();
92         assertNotNull(props);
93         assertTrue(props.containsKey("site.name"));
94         
95         // update multiple properties
96
prop = (RollerPropertyData) props.get("site.name");
97         prop.setValue("foofoo");
98         prop = (RollerPropertyData) props.get("site.description");
99         prop.setValue("blahblah");
100         mgr.saveProperties(props);
101         TestUtils.endSession(true);
102         
103         // make sure all properties were updated
104
props = mgr.getProperties();
105         assertNotNull(props);
106         assertEquals("foofoo", ((RollerPropertyData)props.get("site.name")).getValue());
107         assertEquals("blahblah", ((RollerPropertyData)props.get("site.description")).getValue());
108     }
109     
110 }
111
Popular Tags