001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
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: package org.apache.commons.beanutils.locale;
018:
019: import junit.framework.TestCase;
020: import junit.framework.Test;
021: import junit.framework.TestSuite;
022:
023: import org.apache.commons.beanutils.TestBean;
024: import org.apache.commons.logging.Log;
025: import org.apache.commons.logging.LogFactory;
026:
027: /**
028: * Test Case for {@link LocaleBeanUtils}.
029: *
030: * @version $Revision: 555476 $ $Date: 2007-07-12 04:08:37 +0100 (Thu, 12 Jul 2007) $
031: */
032: public class LocaleBeanUtilsTestCase extends TestCase {
033:
034: private static Log log = LogFactory
035: .getLog(LocaleBeanUtilsTestCase.class);
036:
037: /**
038: * Construct a new instance of this test case.
039: *
040: * @param name Name of the test case
041: */
042: public LocaleBeanUtilsTestCase(String name) {
043: super (name);
044: }
045:
046: // -------------------------------------------------- Overall Test Methods
047:
048: /**
049: * Set up instance variables required by this test case.
050: */
051: public void setUp() {
052: }
053:
054: /**
055: * Return the tests included in this test suite.
056: * @return Test Suite
057: */
058: public static Test suite() {
059: return (new TestSuite(LocaleBeanUtilsTestCase.class));
060: }
061:
062: /**
063: * Tear down instance variables required by this test case.
064: */
065: public void tearDown() {
066: }
067:
068: // ------------------------------------------------ Individual Test Methods
069:
070: /**
071: * Test setting a nested simple property
072: */
073: public void testSetNestedPropertySimple() {
074: TestBean bean = new TestBean();
075: bean.getNested().setIntProperty(5);
076: assertEquals("Initial value 5", 5, bean.getNested()
077: .getIntProperty());
078: try {
079: LocaleBeanUtils.setProperty(bean, "nested.intProperty",
080: "123", null);
081: } catch (Throwable t) {
082: log.error(t);
083: fail("Threw " + t);
084: }
085: assertEquals("Check Set Value", 123, bean.getNested()
086: .getIntProperty());
087: }
088:
089: /**
090: * Test setting a nested indexed property
091: */
092: public void testSetNestedPropertyIndexed() {
093: TestBean bean = new TestBean();
094: bean.getNested().setIntIndexed(1, 51);
095: assertEquals("Initial value[1] 51", 51, bean.getNested()
096: .getIntIndexed(1));
097: try {
098: LocaleBeanUtils.setProperty(bean, "nested.intIndexed[1]",
099: "123", null);
100: } catch (Throwable t) {
101: log.error(t);
102: fail("Threw " + t);
103: }
104: assertEquals("Check Set Value", 123, bean.getNested()
105: .getIntIndexed(1));
106: }
107: }
|