View Javadoc
1   /**
2    * Copyright 2005-2014 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.Ignore;
21  import org.junit.Test;
22  
23  import static org.junit.Assert.assertFalse;
24  
25  public class PojoPropertyUtilsBeanTest {
26  
27      @Before
28      /**
29       * This method sets up BeanUtils so PropertyUtils will delegate to the
30       * PojoPropertyUtilsBean like it does with Struts
31       */
32      public void setup() {
33          PojoPlugin.initBeanUtils();
34      }
35  
36      @Ignore
37      /**
38       * This test was added for KULRICE-12283 and is correct, but the fix IU contributed caused an IT to fail
39       * so the change was reverted and this test is being ignored until that contribution is finished.
40       */
41      @Test
42      /**
43       * This test checks to ensure that the PropertyUtils method which delegates
44       * to the PojoPropertyUtilsBean in the KNS properly handles checking if a
45       * nested property is writeable.
46       */
47      public void testNestedPropertyIsWriteable() {
48          ReadonlyBean testBean = new ReadonlyBean();
49          ReadonlyWrappingBean readonlyBean = new ReadonlyWrappingBean(testBean);
50          WriteableWrappingBean writeableBean = new WriteableWrappingBean(testBean);
51  
52          assertFalse(PropertyUtils.isWriteable(readonlyBean, "bean.value"));
53          assertFalse(PropertyUtils.isWriteable(writeableBean, "bean.value"));
54      }
55  
56      private static class ReadonlyBean {
57  
58          private Boolean value;
59  
60          public Boolean getValue() {
61              return value;
62          }
63      }
64  
65      private static class ReadonlyWrappingBean {
66  
67          private ReadonlyBean bean;
68  
69          public ReadonlyWrappingBean(ReadonlyBean bean) {
70              this.bean = bean;
71          }
72  
73          public ReadonlyBean getBean() {
74              return bean;
75          }
76      }
77  
78      private static class WriteableWrappingBean {
79  
80          private ReadonlyBean bean;
81  
82          public WriteableWrappingBean(ReadonlyBean bean) {
83              this.bean = bean;
84          }
85  
86          public ReadonlyBean getBean() {
87              return bean;
88          }
89  
90          public void setBean(ReadonlyBean bean) {
91              this.bean = bean;
92          }
93      }
94  }