1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one or more
3    * contributor license agreements.  See the NOTICE file distributed with
4    * this work for additional information regarding copyright ownership.
5    * The ASF licenses this file to You under the Apache License, Version 2.0
6    * (the "License"); you may not use this file except in compliance with
7    * the License.  You may obtain a copy of the License at
8    *
9    *      http://www.apache.org/licenses/LICENSE-2.0
10   *
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
16   */
17  package org.apache.commons.beanutils.locale;
18  
19  import junit.framework.TestCase;
20  import junit.framework.Test;
21  import junit.framework.TestSuite;
22  
23  import org.apache.commons.beanutils.TestBean;
24  import org.apache.commons.logging.Log;
25  import org.apache.commons.logging.LogFactory;
26  
27  /***
28   * Test Case for {@link LocaleBeanUtils}.
29   *
30   * @version $Revision: 555476 $ $Date: 2007-07-12 04:08:37 +0100 (Thu, 12 Jul 2007) $
31   */
32  public class LocaleBeanUtilsTestCase extends TestCase {
33      
34      private static Log log = LogFactory.getLog(LocaleBeanUtilsTestCase.class);
35      
36      /***
37       * Construct a new instance of this test case.
38       *
39       * @param name Name of the test case
40       */
41      public LocaleBeanUtilsTestCase(String name) {
42          super(name);
43      }
44  
45  
46      // -------------------------------------------------- Overall Test Methods
47  
48  
49      /***
50       * Set up instance variables required by this test case.
51       */
52      public void setUp() {
53      }
54  
55  
56      /***
57       * Return the tests included in this test suite.
58       * @return Test Suite
59       */
60      public static Test suite() {
61          return (new TestSuite(LocaleBeanUtilsTestCase.class));
62      }
63  
64  
65      /***
66       * Tear down instance variables required by this test case.
67       */
68      public void tearDown() {
69      }
70  
71  
72      // ------------------------------------------------ Individual Test Methods
73  
74      /***
75       * Test setting a nested simple property
76       */
77      public void testSetNestedPropertySimple() {
78          TestBean bean = new TestBean();
79          bean.getNested().setIntProperty(5);
80          assertEquals("Initial value 5", 5, bean.getNested().getIntProperty());
81          try {
82              LocaleBeanUtils.setProperty(bean, "nested.intProperty", "123", null);
83          } catch (Throwable t) {
84              log.error(t);
85              fail("Threw " + t);
86          }
87          assertEquals("Check Set Value", 123, bean.getNested().getIntProperty());
88      }
89  
90      /***
91       * Test setting a nested indexed property
92       */
93      public void testSetNestedPropertyIndexed() {
94          TestBean bean = new TestBean();
95          bean.getNested().setIntIndexed(1, 51);
96          assertEquals("Initial value[1] 51", 51, bean.getNested().getIntIndexed(1));
97          try {
98              LocaleBeanUtils.setProperty(bean, "nested.intIndexed[1]", "123", null);
99          } catch (Throwable t) {
100             log.error(t);
101             fail("Threw " + t);
102         }
103         assertEquals("Check Set Value", 123, bean.getNested().getIntIndexed(1));
104     }
105 }
106