Author: mthl
Date: Sat May 25 14:12:37 2019 New Revision: 1859975 URL: http://svn.apache.org/viewvc?rev=1859975&view=rev Log: Improved: Turn ‘UtilPropertiesTests’ into a unit test class (OFBIZ-11067) Added: ofbiz/ofbiz-framework/trunk/framework/base/src/test/java/org/apache/ofbiz/base/util/UtilPropertiesTests.java (with props) Removed: ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/test/UtilPropertiesTests.java Modified: ofbiz/ofbiz-framework/trunk/framework/base/testdef/basetests.xml Added: ofbiz/ofbiz-framework/trunk/framework/base/src/test/java/org/apache/ofbiz/base/util/UtilPropertiesTests.java URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/framework/base/src/test/java/org/apache/ofbiz/base/util/UtilPropertiesTests.java?rev=1859975&view=auto ============================================================================== --- ofbiz/ofbiz-framework/trunk/framework/base/src/test/java/org/apache/ofbiz/base/util/UtilPropertiesTests.java (added) +++ ofbiz/ofbiz-framework/trunk/framework/base/src/test/java/org/apache/ofbiz/base/util/UtilPropertiesTests.java Sat May 25 14:12:37 2019 @@ -0,0 +1,84 @@ +/* + * 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.ofbiz.base.util; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; + +import java.io.ByteArrayInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.nio.charset.Charset; +import java.util.Locale; +import java.util.Properties; + +import org.apache.ofbiz.base.util.UtilProperties; +import org.junit.Test; + +public class UtilPropertiesTests { + + private static final String country = "AU"; + private static final String language = "en"; + private final Locale locale = new Locale(language, country); + + /** + * Old style xml:lang attribute value was of form en_AU. Test this + * format still works. + * @throws Exception + */ + @Test + public void testReadXmlLangOldStyle() throws Exception { + Properties result = xmlToProperties("_"); + assertNotNull(result); + assertTrue(!result.isEmpty()); + assertEquals(1, result.size()); + assertEquals("Key Value", result.getProperty("PropertyKey")); + } + + /** + * New (and correct) style xml:lang value is en-AU. + * Test it works. + * @throws Exception + */ + @Test + public void testReadXmlLangNewStyle() throws Exception { + Properties result = xmlToProperties("-"); + assertNotNull(result); + assertTrue(!result.isEmpty()); + assertEquals(1, result.size()); + assertEquals("Key Value", result.getProperty("PropertyKey")); + } + + private Properties xmlToProperties(String separator) throws IOException { + String xmlData = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + + "<resource xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n" + + " xsi:noNamespaceSchemaLocation=\"http://ofbiz.apache.org/dtds/ofbiz-properties.xsd\">\n" + + " <property key=\"PropertyKey\">\n" + + " <value xml:lang=\"" + + language + separator + country + + "\">Key Value</value>\n" + + " </property>\n" + + "</resource>"; + try (InputStream in = new ByteArrayInputStream( + new String(xmlData.getBytes(), Charset.forName("UTF-8")).getBytes())) { + return UtilProperties.xmlToProperties(in, locale, null); + } + } +} Propchange: ofbiz/ofbiz-framework/trunk/framework/base/src/test/java/org/apache/ofbiz/base/util/UtilPropertiesTests.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: ofbiz/ofbiz-framework/trunk/framework/base/src/test/java/org/apache/ofbiz/base/util/UtilPropertiesTests.java ------------------------------------------------------------------------------ svn:keywords = Date Rev Author URL Id Propchange: ofbiz/ofbiz-framework/trunk/framework/base/src/test/java/org/apache/ofbiz/base/util/UtilPropertiesTests.java ------------------------------------------------------------------------------ svn:mime-type = text/plain Modified: ofbiz/ofbiz-framework/trunk/framework/base/testdef/basetests.xml URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/framework/base/testdef/basetests.xml?rev=1859975&r1=1859974&r2=1859975&view=diff ============================================================================== --- ofbiz/ofbiz-framework/trunk/framework/base/testdef/basetests.xml (original) +++ ofbiz/ofbiz-framework/trunk/framework/base/testdef/basetests.xml Sat May 25 14:12:37 2019 @@ -41,7 +41,6 @@ <junit-test-suite class-name="org.apache.ofbiz.base.conversion.test.TestJSONConverters"/> <!--junit-test-suite class-name="org.apache.ofbiz.base.util.test.UtilIOTests"/--> <junit-test-suite class-name="org.apache.ofbiz.base.test.BaseUnitTests"/> - <junit-test-suite class-name="org.apache.ofbiz.base.util.test.UtilPropertiesTests"/> <groovy-test-suite name="simple" location="component://base/groovyScripts/test/SimpleTests.groovy"/> </test-group> </test-suite> |
Free forum by Nabble | Edit this page |