Return-Path: Delivered-To: apmail-commons-commits-archive@minotaur.apache.org Received: (qmail 44451 invoked from network); 5 Oct 2009 17:04:13 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 5 Oct 2009 17:04:13 -0000 Received: (qmail 16659 invoked by uid 500); 5 Oct 2009 17:04:13 -0000 Delivered-To: apmail-commons-commits-archive@commons.apache.org Received: (qmail 16585 invoked by uid 500); 5 Oct 2009 17:04:13 -0000 Mailing-List: contact commits-help@commons.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@commons.apache.org Delivered-To: mailing list commits@commons.apache.org Received: (qmail 16576 invoked by uid 99); 5 Oct 2009 17:04:13 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 05 Oct 2009 17:04:13 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 05 Oct 2009 17:04:10 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 476192388907; Mon, 5 Oct 2009 17:03:47 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r821917 - /commons/proper/beanutils/trunk/src/test/org/apache/commons/beanutils/bugs/Jira359TestCase.java Date: Mon, 05 Oct 2009 17:03:47 -0000 To: commits@commons.apache.org From: niallp@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20091005170347.476192388907@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: niallp Date: Mon Oct 5 17:03:46 2009 New Revision: 821917 URL: http://svn.apache.org/viewvc?rev=821917&view=rev Log: BEANUTILS-359 - Difference in setProperty() behaviour when invoking setter with a String value that has ':' Added: commons/proper/beanutils/trunk/src/test/org/apache/commons/beanutils/bugs/Jira359TestCase.java (with props) Added: commons/proper/beanutils/trunk/src/test/org/apache/commons/beanutils/bugs/Jira359TestCase.java URL: http://svn.apache.org/viewvc/commons/proper/beanutils/trunk/src/test/org/apache/commons/beanutils/bugs/Jira359TestCase.java?rev=821917&view=auto ============================================================================== --- commons/proper/beanutils/trunk/src/test/org/apache/commons/beanutils/bugs/Jira359TestCase.java (added) +++ commons/proper/beanutils/trunk/src/test/org/apache/commons/beanutils/bugs/Jira359TestCase.java Mon Oct 5 17:03:46 2009 @@ -0,0 +1,161 @@ +/* + * 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 junit.framework.Test; +import junit.framework.TestCase; +import junit.framework.TestSuite; + +import org.apache.commons.beanutils.BeanUtils; +import org.apache.commons.beanutils.BeanUtilsBean; +import org.apache.commons.beanutils.converters.ArrayConverter; +import org.apache.commons.beanutils.converters.StringConverter; + +/** + * See https://issues.apache.org/jira/browse/BEANUTILS-359 + *

+ * + * @version $Revision$ $Date$ + */ +public class Jira359TestCase extends TestCase { + + /** + * Create a test case with the specified name. + * + * @param name The name of the test + */ + public Jira359TestCase(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(Jira359TestCase.class)); + } + + /** + * Set up. + * + * @throws java.lang.Exception + */ + protected void setUp() throws Exception { + super.setUp(); + } + + /** + * Tear Down. + * + * @throws java.lang.Exception + */ + protected void tearDown() throws Exception { + super.tearDown(); + } + + /** + * Test {@link BeanUtils} setProperty() String to array with colon value + */ + public void testBeanUtilsSetProperty_CustomConvertStringToArray_WithColonValue() throws Exception{ + ArrayConverter converter = new ArrayConverter(String[].class, new StringConverter()); + converter.setAllowedChars(new char[] {'.', '-', ':'}); + + BeanUtilsBean utils = new BeanUtilsBean(); + utils.getConvertUtils().register(converter, String[].class); + + SimplePojoData simplePojo = new SimplePojoData(); + utils.setProperty(simplePojo, "jcrMixinTypes", "mix:rereferencible,mix:simple"); + showArray("Custom WithColonValue", simplePojo.getJcrMixinTypes()); + assertEquals("array size", 2, simplePojo.getJcrMixinTypes().length); + assertEquals("mix:rereferencible", simplePojo.getJcrMixinTypes()[0]); + assertEquals("mix:simple", simplePojo.getJcrMixinTypes()[1]); + } + + /** + * Test {@link BeanUtils} setProperty() String to array with colon value + */ + public void testBeanUtilsSetProperty_DefaultConvertStringToArray_WithColonValue() throws Exception{ + SimplePojoData simplePojo = new SimplePojoData(); + BeanUtils.setProperty(simplePojo, "jcrMixinTypes", "mix:rereferencible,mix:simple"); + showArray("Default WithColonValue", simplePojo.getJcrMixinTypes()); + assertEquals("array size", 4, simplePojo.getJcrMixinTypes().length); + assertEquals("mix", simplePojo.getJcrMixinTypes()[0]); + assertEquals("rereferencible", simplePojo.getJcrMixinTypes()[1]); + assertEquals("mix", simplePojo.getJcrMixinTypes()[2]); + assertEquals("simple", simplePojo.getJcrMixinTypes()[3]); + } + + /** + * Test {@link BeanUtils} setProperty() String to array without colon value + */ + public void testBeanUtilsSetProperty_DefaultConvertStringToArray_WithoutColonValue() throws Exception{ + SimplePojoData simplePojo = new SimplePojoData(); + BeanUtils.setProperty(simplePojo, "jcrMixinTypes", "mixrereferencible,mixsimple"); + showArray("Default WithoutColonValue", simplePojo.getJcrMixinTypes()); + assertEquals("array size", 2, simplePojo.getJcrMixinTypes().length); + assertEquals("mixrereferencible", simplePojo.getJcrMixinTypes()[0]); + assertEquals("mixsimple", simplePojo.getJcrMixinTypes()[1]); + } + + /** + * Test {@link BeanUtils} setProperty() String to array without colon value and no comma + */ + public void testBeanUtilsSetProperty_DefaultConvertStringToArray_WithoutColonValueAndNocoma() throws Exception{ + SimplePojoData simplePojo = new SimplePojoData(); + BeanUtils.setProperty(simplePojo, "jcrMixinTypes", "mixrereferencible"); + showArray("Default WithoutColonAndNocoma", simplePojo.getJcrMixinTypes()); + assertEquals("array size", 1, simplePojo.getJcrMixinTypes().length); + assertEquals("mixrereferencible", simplePojo.getJcrMixinTypes()[0]); + } + + /** + * Show array contents. + */ + private void showArray(String text, String[] array) { + if (array == null) { + System.out.println(text + " array is null"); + } else { + System.out.println(text + " array length=" + array.length); + for (int i = 0; i < array.length; i++) { + System.out.println(text + " array[" + i + "]=" + array[i]); + } + } + } + + public static class SimplePojoData { + private String[] jcrMixinTypes = new String[1]; + public SimplePojoData() { + } + public String[] getJcrMixinTypes() { + return this.jcrMixinTypes; + } + public void setJcrMixinTypes(String[] mixinTypes) { + this.jcrMixinTypes = mixinTypes; + } + } +} Propchange: commons/proper/beanutils/trunk/src/test/org/apache/commons/beanutils/bugs/Jira359TestCase.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: commons/proper/beanutils/trunk/src/test/org/apache/commons/beanutils/bugs/Jira359TestCase.java ------------------------------------------------------------------------------ svn:keywords = Date Author Id Revision HeadURL