From 6cec73d6c3a33696d1a9a960cae86b67785351b9 Mon Sep 17 00:00:00 2001 From: Geoffrey De Smet Date: Wed, 20 Jul 2011 15:21:55 +0200 Subject: [PATCH] SEAMCONFIG-49 Support fields of the class Properties: replacing and modifying (regression from seam 2) --- .../seam/config/xml/fieldset/MapFieldSet.java | 5 +++ .../test/fieldset/PropertiesFieldValue.java | 26 ++++++++++++ .../SetPropertiesFieldValueBeanTest.java | 42 +++++++++++++++++++ .../properties-set-field-value-beans.xml | 29 +++++++++++++ 4 files changed, 102 insertions(+) create mode 100644 providers/xml/src/test/java/org/jboss/seam/config/xml/test/fieldset/PropertiesFieldValue.java create mode 100644 providers/xml/src/test/java/org/jboss/seam/config/xml/test/fieldset/SetPropertiesFieldValueBeanTest.java create mode 100644 providers/xml/src/test/resources/org/jboss/seam/config/xml/test/fieldset/properties-set-field-value-beans.xml diff --git a/providers/xml/src/main/java/org/jboss/seam/config/xml/fieldset/MapFieldSet.java b/providers/xml/src/main/java/org/jboss/seam/config/xml/fieldset/MapFieldSet.java index 935b042..168ede0 100644 --- a/providers/xml/src/main/java/org/jboss/seam/config/xml/fieldset/MapFieldSet.java +++ b/providers/xml/src/main/java/org/jboss/seam/config/xml/fieldset/MapFieldSet.java @@ -24,6 +24,7 @@ import java.util.List; import java.util.Map; import java.util.Map.Entry; +import java.util.Properties; import java.util.SortedMap; import java.util.TreeMap; @@ -70,6 +71,10 @@ public MapFieldSet(Property field, List items) { keyType = TypeReader.readClassFromType(parameterizedType.getActualTypeArguments()[0]); valueType = TypeReader.readClassFromType(parameterizedType.getActualTypeArguments()[1]); + } else if (type == Properties.class) { + collectionType = Properties.class; + keyType = TypeReader.readClassFromType(String.class); + valueType = TypeReader.readClassFromType(String.class); } else { throw new RuntimeException("Could not determine element type for map " + field.getDeclaringClass().getName() + "." + field.getName()); } diff --git a/providers/xml/src/test/java/org/jboss/seam/config/xml/test/fieldset/PropertiesFieldValue.java b/providers/xml/src/test/java/org/jboss/seam/config/xml/test/fieldset/PropertiesFieldValue.java new file mode 100644 index 0000000..02c09cb --- /dev/null +++ b/providers/xml/src/test/java/org/jboss/seam/config/xml/test/fieldset/PropertiesFieldValue.java @@ -0,0 +1,26 @@ +/* + * JBoss, Home of Professional Open Source + * Copyright 2011, Red Hat, Inc. and/or its affiliates, and individual + * contributors by the @authors tag. See the copyright.txt in the + * distribution for a full listing of individual contributors. + * + * Licensed 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.jboss.seam.config.xml.test.fieldset; + +import java.util.Properties; + +public class PropertiesFieldValue { + + public Properties properties1; + + public Properties properties2; +} diff --git a/providers/xml/src/test/java/org/jboss/seam/config/xml/test/fieldset/SetPropertiesFieldValueBeanTest.java b/providers/xml/src/test/java/org/jboss/seam/config/xml/test/fieldset/SetPropertiesFieldValueBeanTest.java new file mode 100644 index 0000000..007a4fc --- /dev/null +++ b/providers/xml/src/test/java/org/jboss/seam/config/xml/test/fieldset/SetPropertiesFieldValueBeanTest.java @@ -0,0 +1,42 @@ +/* + * JBoss, Home of Professional Open Source + * Copyright 2011, Red Hat, Inc. and/or its affiliates, and individual + * contributors by the @authors tag. See the copyright.txt in the + * distribution for a full listing of individual contributors. + * + * Licensed 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.jboss.seam.config.xml.test.fieldset; + +import junit.framework.Assert; +import org.jboss.seam.config.xml.test.AbstractXMLTest; +import org.junit.Test; + +public class SetPropertiesFieldValueBeanTest extends AbstractXMLTest { + + @Override + protected String getXmlFileName() { + return "properties-set-field-value-beans.xml"; + } + + @Test + public void propertiesSetFieldValue() { + PropertiesFieldValue x = getReference(PropertiesFieldValue.class); + Assert.assertTrue(x.properties1.size() == 2); + Assert.assertTrue(x.properties2.size() == 2); + + Assert.assertTrue(x.properties1.get("1").equals("hello")); + Assert.assertTrue(x.properties1.get("2").equals("world")); + Assert.assertTrue(x.properties2.get("key1").equals("Value 1")); + Assert.assertTrue(x.properties2.get("key2").equals("Value 2")); + + } +} diff --git a/providers/xml/src/test/resources/org/jboss/seam/config/xml/test/fieldset/properties-set-field-value-beans.xml b/providers/xml/src/test/resources/org/jboss/seam/config/xml/test/fieldset/properties-set-field-value-beans.xml new file mode 100644 index 0000000..d44e214 --- /dev/null +++ b/providers/xml/src/test/resources/org/jboss/seam/config/xml/test/fieldset/properties-set-field-value-beans.xml @@ -0,0 +1,29 @@ + + + + + + + 1 + hello + + + 2 + world + + + + + key1 + Value 1 + + + key2 + Value 2 + + + + + +