View Javadoc
1   /**
2    * Copyright 2005-2016 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl2.php
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.
15   */
16  package org.kuali.rice.kns.web.struts.form.pojo;
17  
18  import org.apache.commons.beanutils.PropertyUtils;
19  import org.junit.Before;
20  import org.junit.Test;
21  
22  import static org.junit.Assert.assertFalse;
23  
24  public class PojoPropertyUtilsBeanTest {
25  
26      @Before
27      /**
28       * This method sets up BeanUtils so PropertyUtils will delegate to the
29       * PojoPropertyUtilsBean like it does with Struts
30       */
31      public void setup() {
32          PojoPlugin.initBeanUtils();
33      }
34  
35      /**
36       * This test was added for KULRICE-12283 and is correct, but the fix IU contributed caused an IT to fail
37       * so the change was reverted and this test is being ignored until that contribution is finished.
38       */
39      @Test
40      /**
41       * This test checks to ensure that the PropertyUtils method which delegates
42       * to the PojoPropertyUtilsBean in the KNS properly handles checking if a
43       * nested property is writeable.
44       */
45      public void testNestedPropertyIsWriteable() {
46          ReadonlyBean testBean = new ReadonlyBean();
47          ReadonlyWrappingBean readonlyBean = new ReadonlyWrappingBean(testBean);
48          WriteableWrappingBean writeableBean = new WriteableWrappingBean(testBean);
49  
50          assertFalse(PropertyUtils.isWriteable(readonlyBean, "bean.value"));
51          assertFalse(PropertyUtils.isWriteable(writeableBean, "bean.value"));
52      }
53  
54      private static class ReadonlyBean {
55  
56          private Boolean value;
57  
58          public Boolean getValue() {
59              return value;
60          }
61      }
62  
63      private static class ReadonlyWrappingBean {
64  
65          private ReadonlyBean bean;
66  
67          public ReadonlyWrappingBean(ReadonlyBean bean) {
68              this.bean = bean;
69          }
70  
71          public ReadonlyBean getBean() {
72              return bean;
73          }
74      }
75  
76      private static class WriteableWrappingBean {
77  
78          private ReadonlyBean bean;
79  
80          public WriteableWrappingBean(ReadonlyBean bean) {
81              this.bean = bean;
82          }
83  
84          public ReadonlyBean getBean() {
85              return bean;
86          }
87  
88          public void setBean(ReadonlyBean bean) {
89              this.bean = bean;
90          }
91      }
92  }