📄 jira61testcase.java
字号:
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.commons.beanutils.bugs;
import java.util.HashMap;
import java.util.Map;
import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;
import org.apache.commons.beanutils.BeanUtils;
import org.apache.commons.beanutils.PropertyUtils;
import org.apache.commons.beanutils.WrapDynaBean;
import org.apache.commons.beanutils.bugs.other.Jira61BeanFactory;
import org.apache.commons.beanutils.bugs.other.Jira61BeanFactory.TestBean;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
/**
* Test case for Jira issue# BEANUTILS-61.
* <p />
* See https://issues.apache.org/jira/browse/BEANUTILS-61
* <p />
*
* {@link WrapDynaBean} is a secial case for the PropertyUtils's
* isReadable() and isWriteable() methods - since the bean being
* wrapped may have read-only or write-only properties (unlike
* regular DynaBeans.
*
* @version $Revision: 553357 $ $Date: 2007-07-05 02:10:25 +0100 (Thu, 05 Jul 2007) $
*/
public class Jira61TestCase extends TestCase {
private Log log = LogFactory.getLog(Jira61TestCase.class);
private Jira61BeanFactory.TestBean testBean;
private WrapDynaBean wrapDynaBean;
/**
* Create a test case with the specified name.
*
* @param name The name of the test
*/
public Jira61TestCase(String name) {
super(name);
}
/**
* Run the Test.
*
* @param args Arguments
*/
public static void main(String[] args) {
junit.textui.TestRunner.run(suite());
}
/**
* Create a test suite for this test.
*
* @return a test suite
*/
public static Test suite() {
return (new TestSuite(Jira61TestCase.class));
}
/**
* Set up.
*
* @throws java.lang.Exception
*/
protected void setUp() throws Exception {
super.setUp();
testBean = Jira61BeanFactory.createBean();
PropertyUtils.getPropertyDescriptor(testBean, "mappedReadOnly");
PropertyUtils.getPropertyDescriptor(testBean, "mappedWriteOnly");
wrapDynaBean = new WrapDynaBean(testBean);
}
/**
* Tear Down.
*
* @throws java.lang.Exception
*/
protected void tearDown() throws Exception {
super.tearDown();
}
/**
* Test {@link PropertyUtils#isReadable(Object, String)}
* for simple properties.
*/
public void testIssue_BEANUTILS_61_PropertyUtils_isReadable() {
boolean result = false;
try {
result = PropertyUtils.isReadable(wrapDynaBean, "simpleReadOnly");
} catch (Throwable t) {
log.error("ERROR " + t, t);
fail("simpleReadOnly Threw exception: " + t);
}
assertTrue("PropertyUtils.isReadable(bean, \"simpleReadOnly\") returned " + result, result);
try {
result = PropertyUtils.isReadable(wrapDynaBean, "simpleWriteOnly");
} catch (Throwable t) {
log.error("ERROR " + t, t);
fail("simpleWriteOnly Threw exception: " + t);
}
assertFalse("PropertyUtils.isReadable(bean, \"simpleWriteOnly\") returned " + result, result);
}
/**
* Test {@link PropertyUtils#isWriteable(Object, String)}
* for simple properties.
*/
public void testIssue_BEANUTILS_61_PropertyUtils_isWriteable() {
boolean result = false;
try {
result = PropertyUtils.isWriteable(wrapDynaBean, "simpleReadOnly");
} catch (Throwable t) {
log.error("ERROR " + t, t);
fail("simpleReadOnly Threw exception: " + t);
}
assertFalse("PropertyUtils.isWriteable(bean, \"simpleReadOnly\") returned " + result, result);
try {
result = PropertyUtils.isWriteable(wrapDynaBean, "simpleWriteOnly");
} catch (Throwable t) {
log.error("ERROR " + t, t);
fail("simpleWriteOnly Threw exception: " + t);
}
assertTrue("PropertyUtils.isWriteable(bean, \"simpleWriteOnly\") returned " + result, result);
}
/**
* Test {@link PropertyUtils#isReadable(Object, String)}
* for indexed properties.
*/
public void testIssue_BEANUTILS_61_PropertyUtils_isReadable_Indexed() {
boolean result = false;
try {
result = PropertyUtils.isReadable(wrapDynaBean, "indexedReadOnly");
} catch (Throwable t) {
log.error("ERROR " + t, t);
fail("indexedReadOnly Threw exception: " + t);
}
assertTrue("PropertyUtils.isReadable(bean, \"indexedReadOnly\") returned " + result, result);
try {
result = PropertyUtils.isReadable(wrapDynaBean, "indexedWriteOnly");
} catch (Throwable t) {
log.error("ERROR " + t, t);
fail("indexedWriteOnly Threw exception: " + t);
}
assertFalse("PropertyUtils.isReadable(bean, \"indexedWriteOnly\") returned " + result, result);
}
/**
* Test {@link PropertyUtils#isReadable(Object, String)}
* for mapped properties.
*/
public void testIssue_BEANUTILS_61_PropertyUtils_isReadable_Mapped() {
boolean result = false;
try {
result = PropertyUtils.isReadable(wrapDynaBean, "mappedReadOnly");
} catch (Throwable t) {
log.error("ERROR " + t, t);
fail("mappedReadOnly Threw exception: " + t);
}
assertTrue("PropertyUtils.isReadable(bean, \"mappedReadOnly\") returned " + result, result);
try {
result = PropertyUtils.isReadable(wrapDynaBean, "mappedWriteOnly");
} catch (Throwable t) {
log.error("ERROR " + t, t);
fail("mappedWriteOnly Threw exception: " + t);
}
assertFalse("PropertyUtils.isReadable(bean, \"mappedWriteOnly\") returned " + result, result);
}
/**
* Test {@link PropertyUtils#isWriteable(Object, String)}
* for indexed properties.
*/
public void testIssue_BEANUTILS_61_PropertyUtils_isWriteable_Indexed() {
boolean result = false;
try {
result = PropertyUtils.isWriteable(wrapDynaBean, "indexedReadOnly");
} catch (Throwable t) {
log.error("ERROR " + t, t);
fail("indexedReadOnly Threw exception: " + t);
}
assertFalse("PropertyUtils.isWriteable(bean, \"indexedReadOnly\") returned " + result, result);
try {
result = PropertyUtils.isWriteable(wrapDynaBean, "indexedWriteOnly");
} catch (Throwable t) {
log.error("ERROR " + t, t);
fail("indexedWriteOnly Threw exception: " + t);
}
assertTrue("PropertyUtils.isWriteable(bean, \"indexedWriteOnly\") returned " + result, result);
}
/**
* Test {@link PropertyUtils#isWriteable(Object, String)}
* for mapped properties.
*/
public void testIssue_BEANUTILS_61_PropertyUtils_isWriteable_Mapped() {
boolean result = false;
try {
result = PropertyUtils.isWriteable(wrapDynaBean, "mappedReadOnly");
} catch (Throwable t) {
log.error("ERROR " + t, t);
fail("mappedReadOnly Threw exception: " + t);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -