You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@openwebbeans.apache.org by ge...@apache.org on 2010/08/17 17:30:40 UTC
svn commit: r986359 - in /openwebbeans/trunk/webbeans-impl/src/test:
java/org/apache/webbeans/newtests/config/
resources/org/apache/webbeans/newtests/config/
Author: gerdogdu
Date: Tue Aug 17 15:30:39 2010
New Revision: 986359
URL: http://svn.apache.org/viewvc?rev=986359&view=rev
Log:
more test method for PropertyLoaderTest
Added:
openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/config/MockPropertyLoader.java (with props)
openwebbeans/trunk/webbeans-impl/src/test/resources/org/apache/webbeans/newtests/config/propertyloadertest2.properties (with props)
openwebbeans/trunk/webbeans-impl/src/test/resources/org/apache/webbeans/newtests/config/propertyloadertest3.properties (with props)
Modified:
openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/config/PropertyLoaderTest.java
openwebbeans/trunk/webbeans-impl/src/test/resources/org/apache/webbeans/newtests/config/propertyloadertest.properties
Added: openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/config/MockPropertyLoader.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/config/MockPropertyLoader.java?rev=986359&view=auto
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/config/MockPropertyLoader.java (added)
+++ openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/config/MockPropertyLoader.java Tue Aug 17 15:30:39 2010
@@ -0,0 +1,115 @@
+/*
+ * 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.webbeans.newtests.config;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+import java.util.Properties;
+
+import org.apache.webbeans.config.PropertyLoader;
+
+/**
+ *
+ * For tesing pruposes. Methods are taken
+ * from {@link PropertyLoader} class.
+ *
+ */
+class MockPropertyLoader
+{
+ /**
+ * Implement a quick and dirty sorting mechanism for the given Properties.
+ * @param allProperties
+ * @return the Properties list sorted by it's 'configuration.ordinal' in ascending order.
+ */
+ static List<Properties> sortProperties(List<Properties> allProperties)
+ {
+ List<Properties> sortedProperties = new ArrayList<Properties>();
+ for (Properties p : allProperties)
+ {
+ int configOrder = getConfigurationOrdinal(p);
+
+ int i;
+ for (i = 0; i < sortedProperties.size(); i++)
+ {
+ int listConfigOrder = getConfigurationOrdinal(sortedProperties.get(i));
+ if (listConfigOrder > configOrder)
+ {
+ // only go as far as we found a higher priority Properties file
+ break;
+ }
+ }
+ sortedProperties.add(i, p);
+ }
+ return sortedProperties;
+ }
+
+ /**
+ * Determine the 'configuration.ordinal' of the given properties.
+ * {@link #CONFIGURATION_ORDINAL_DEFAULT_VALUE} if
+ * {@link #CONFIGURATION_ORDINAL_PROPERTY_NAME} is not set in the
+ * Properties file.
+ *
+ * @param p the Properties from the file.
+ * @return the ordinal number of the given Properties file.
+ */
+ static int getConfigurationOrdinal(Properties p)
+ {
+ int configOrder = PropertyLoader.CONFIGURATION_ORDINAL_DEFAULT_VALUE;
+
+ String configOrderString = p.getProperty(PropertyLoader.CONFIGURATION_ORDINAL_PROPERTY_NAME);
+ if (configOrderString != null && configOrderString.length() > 0)
+ {
+ try
+ {
+ configOrder = Integer.parseInt(configOrderString);
+ }
+ catch(NumberFormatException nfe)
+ {
+ throw nfe;
+ }
+ }
+
+ return configOrder;
+ }
+
+ /**
+ * Merge the given Properties in order of appearance.
+ * @param sortedProperties
+ * @return the merged Properties
+ */
+ static Properties mergeProperties(List<Properties> sortedProperties)
+ {
+ Properties mergedProperties = new Properties();
+ for (Properties p : sortedProperties)
+ {
+ for (Map.Entry<?,?> entry : p.entrySet())
+ {
+ String key = (String) entry.getKey();
+ String value = (String) entry.getValue();
+
+ // simply overwrite the old properties with the new ones.
+ mergedProperties.setProperty(key, value);
+ }
+ }
+
+ return mergedProperties;
+ }
+
+}
Propchange: openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/config/MockPropertyLoader.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/config/PropertyLoaderTest.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/config/PropertyLoaderTest.java?rev=986359&r1=986358&r2=986359&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/config/PropertyLoaderTest.java (original)
+++ openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/config/PropertyLoaderTest.java Tue Aug 17 15:30:39 2010
@@ -22,11 +22,15 @@ import org.apache.webbeans.config.Proper
import org.junit.Assert;
import org.junit.Test;
+import java.util.ArrayList;
+import java.util.List;
import java.util.Properties;
public class PropertyLoaderTest
{
private static final String PROPERTY_FILE = "org/apache/webbeans/newtests/config/propertyloadertest.properties";
+ private static final String PROPERTY_FILE2 = "org/apache/webbeans/newtests/config/propertyloadertest2.properties";
+ private static final String PROPERTY_FILE3 = "org/apache/webbeans/newtests/config/propertyloadertest3.properties";
@Test
public void testPropertyLoader() throws Exception
@@ -45,4 +49,29 @@ public class PropertyLoaderTest
Properties p = PropertyLoader.getProperties("notexisting.properties");
Assert.assertNull(p);
}
+
+ @Test
+ public void testOrdinal()
+ {
+ Properties p15 = PropertyLoader.getProperties(PROPERTY_FILE);
+ Properties p16 = PropertyLoader.getProperties(PROPERTY_FILE2);
+ Properties p20 = PropertyLoader.getProperties(PROPERTY_FILE3);
+
+ List<Properties> properties = new ArrayList<Properties>();
+ properties.add(p15);
+ properties.add(p16);
+ properties.add(p20);
+
+ Properties prop = MockPropertyLoader.mergeProperties(MockPropertyLoader.sortProperties(properties));
+ Assert.assertEquals("testValue16", prop.get("testConfig"));
+ Assert.assertEquals("16", prop.get("test16"));
+ Assert.assertEquals("15", prop.get("test15"));
+ Assert.assertEquals("20", prop.get("configuration.ordinal"));
+ Assert.assertEquals("z", prop.get("override_y"));
+ Assert.assertEquals("20", prop.get("override_all"));
+ Assert.assertEquals("15", prop.get("unique_1"));
+ Assert.assertEquals("16", prop.get("unique_2"));
+ Assert.assertEquals("20", prop.get("unique_3"));
+
+ }
}
Modified: openwebbeans/trunk/webbeans-impl/src/test/resources/org/apache/webbeans/newtests/config/propertyloadertest.properties
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/test/resources/org/apache/webbeans/newtests/config/propertyloadertest.properties?rev=986359&r1=986358&r2=986359&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/test/resources/org/apache/webbeans/newtests/config/propertyloadertest.properties (original)
+++ openwebbeans/trunk/webbeans-impl/src/test/resources/org/apache/webbeans/newtests/config/propertyloadertest.properties Tue Aug 17 15:30:39 2010
@@ -23,3 +23,7 @@
configuration.ordinal=15
testConfig=testValue
+test15=15
+override_y=y
+override_all=15
+unique_1=15
Added: openwebbeans/trunk/webbeans-impl/src/test/resources/org/apache/webbeans/newtests/config/propertyloadertest2.properties
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/test/resources/org/apache/webbeans/newtests/config/propertyloadertest2.properties?rev=986359&view=auto
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/test/resources/org/apache/webbeans/newtests/config/propertyloadertest2.properties (added)
+++ openwebbeans/trunk/webbeans-impl/src/test/resources/org/apache/webbeans/newtests/config/propertyloadertest2.properties Tue Aug 17 15:30:39 2010
@@ -0,0 +1,29 @@
+# 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.
+#---------------------------------------------------------------
+#
+# test properties for the PropertyLoaderTest
+#
+#---------------------------------------------------------------
+
+configuration.ordinal=16
+
+testConfig=testValue16
+test16=16
+override_y=z
+override_all=16
+unique_2=16
Propchange: openwebbeans/trunk/webbeans-impl/src/test/resources/org/apache/webbeans/newtests/config/propertyloadertest2.properties
------------------------------------------------------------------------------
svn:eol-style = native
Added: openwebbeans/trunk/webbeans-impl/src/test/resources/org/apache/webbeans/newtests/config/propertyloadertest3.properties
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/test/resources/org/apache/webbeans/newtests/config/propertyloadertest3.properties?rev=986359&view=auto
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/test/resources/org/apache/webbeans/newtests/config/propertyloadertest3.properties (added)
+++ openwebbeans/trunk/webbeans-impl/src/test/resources/org/apache/webbeans/newtests/config/propertyloadertest3.properties Tue Aug 17 15:30:39 2010
@@ -0,0 +1,26 @@
+# 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.
+#---------------------------------------------------------------
+#
+# test properties for the PropertyLoaderTest
+#
+#---------------------------------------------------------------
+
+configuration.ordinal=20
+
+override_all=20
+unique_3=20
\ No newline at end of file
Propchange: openwebbeans/trunk/webbeans-impl/src/test/resources/org/apache/webbeans/newtests/config/propertyloadertest3.properties
------------------------------------------------------------------------------
svn:eol-style = native