View Javadoc
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 $Id$
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(final 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      @Override
53      public void setUp() {
54      }
55  
56  
57      /**
58       * Return the tests included in this test suite.
59       * @return Test Suite
60       */
61      public static Test suite() {
62          return (new TestSuite(LocaleBeanUtilsTestCase.class));
63      }
64  
65  
66      /**
67       * Tear down instance variables required by this test case.
68       */
69      @Override
70      public void tearDown() {
71      }
72  
73  
74      // ------------------------------------------------ Individual Test Methods
75  
76      /**
77       * Test setting a nested simple property
78       */
79      public void testSetNestedPropertySimple() {
80          final TestBean bean = new TestBean();
81          bean.getNested().setIntProperty(5);
82          assertEquals("Initial value 5", 5, bean.getNested().getIntProperty());
83          try {
84              LocaleBeanUtils.setProperty(bean, "nested.intProperty", "123", null);
85          } catch (final Throwable t) {
86              log.error(t);
87              fail("Threw " + t);
88          }
89          assertEquals("Check Set Value", 123, bean.getNested().getIntProperty());
90      }
91  
92      /**
93       * Test setting a nested indexed property
94       */
95      public void testSetNestedPropertyIndexed() {
96          final TestBean bean = new TestBean();
97          bean.getNested().setIntIndexed(1, 51);
98          assertEquals("Initial value[1] 51", 51, bean.getNested().getIntIndexed(1));
99          try {
100             LocaleBeanUtils.setProperty(bean, "nested.intIndexed[1]", "123", null);
101         } catch (final Throwable t) {
102             log.error(t);
103             fail("Threw " + t);
104         }
105         assertEquals("Check Set Value", 123, bean.getNested().getIntIndexed(1));
106     }
107 }
108