This is an automated email from the ASF dual-hosted git repository. juanpablo pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/jspwiki.git
commit 3857b0e7ede29d5d66e58847b204183ab6cb058f Author: juanpablo <[email protected]> AuthorDate: Sat Mar 7 14:05:04 2020 +0100 Move PropertyReader tests from main module to util + delete Util test class, use Collection#contains(..) method instead --- .../java/org/apache/wiki/PropertyReaderTest.java | 103 --------------------- .../src/test/java/org/apache/wiki/Util.java | 45 --------- .../wiki/references/ReferenceManagerTest.java | 3 +- .../org/apache/wiki/util/PropertyReaderTest.java | 88 ++++++++++++++++-- 4 files changed, 79 insertions(+), 160 deletions(-) diff --git a/jspwiki-main/src/test/java/org/apache/wiki/PropertyReaderTest.java b/jspwiki-main/src/test/java/org/apache/wiki/PropertyReaderTest.java deleted file mode 100644 index b665127..0000000 --- a/jspwiki-main/src/test/java/org/apache/wiki/PropertyReaderTest.java +++ /dev/null @@ -1,103 +0,0 @@ -/* - 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.wiki; - -import java.util.Properties; - -import org.apache.wiki.util.PropertyReader; -import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.Test; - -public class PropertyReaderTest -{ - @Test - public void testVariableExpansion() - { - Properties p = new Properties(); - - p.put("var.basedir", "/p/mywiki"); - - p.put("jspwiki.fileSystemProvider.pageDir", "$basedir/www/"); - p.put("jspwiki.basicAttachmentProvider.storageDir", "$basedir/www/"); - p.put("jspwiki.workDir", "$basedir/wrk/"); - p.put("jspwiki.xyz", "test basedir"); //don't touch this - - PropertyReader.expandVars(p); - - Assertions.assertTrue( p.getProperty("jspwiki.fileSystemProvider.pageDir").equals("/p/mywiki/www/") ); - Assertions.assertTrue( p.getProperty("jspwiki.basicAttachmentProvider.storageDir").equals("/p/mywiki/www/") ); - Assertions.assertTrue( p.getProperty("jspwiki.fileSystemProvider.pageDir").equals("/p/mywiki/www/") ); - Assertions.assertTrue( p.getProperty("jspwiki.workDir").endsWith("/p/mywiki/wrk/") ); - Assertions.assertTrue( p.getProperty("jspwiki.xyz").endsWith("test basedir") ); //don't touch this - - Assertions.assertFalse( p.getProperty("jspwiki.workDir").endsWith("$basedir/wrk/") ); - } - - @Test - public void testVariableExpansion2() - { - Properties p = new Properties(); - - //this time, declare the var at the end... (should overwrite this one); - p.put("var.basedir", "xxx"); - - p.put("jspwiki.fileSystemProvider.pageDir", "$basedir/www/"); - p.put("jspwiki.basicAttachmentProvider.storageDir", "$basedir/www/"); - p.put("jspwiki.workDir", "$basedir/wrk/"); - p.put("jspwiki.xyz", "test basedir"); //don't touch this - p.put("jspwiki.abc", "test $x2"); //don't touch this - - p.put("var.basedir", " /p/mywiki"); //note that this var has a space at the beginning... - p.put("var.x2", " wiki "); //note that this var has a space at the beginning... - - PropertyReader.expandVars(p); - - Assertions.assertTrue( p.getProperty("jspwiki.fileSystemProvider.pageDir").equals("/p/mywiki/www/") ); - Assertions.assertTrue( p.getProperty("jspwiki.basicAttachmentProvider.storageDir").equals("/p/mywiki/www/") ); - Assertions.assertTrue( p.getProperty("jspwiki.fileSystemProvider.pageDir").equals("/p/mywiki/www/") ); - Assertions.assertTrue( p.getProperty("jspwiki.workDir").endsWith("/p/mywiki/wrk/") ); - Assertions.assertTrue( p.getProperty("jspwiki.xyz").endsWith("test basedir") ); //don't touch this - - Assertions.assertFalse( p.getProperty("jspwiki.workDir").endsWith("$basedir/wrk/") ); - Assertions.assertTrue( p.getProperty("jspwiki.abc").endsWith("test wiki") ); - } - - - - @Test - public void testMultipleVariableExpansion() - { - Properties p = new Properties(); - - //this time, declare the var at the end... (should overwrite this one); - p.put("var.x1", "a"); - p.put("var.x2", "b"); - - p.put("jspwiki.x1", "$x1"); - p.put("jspwiki.x2", "$x2"); - p.put("jspwiki.x3", "$x1/$x2"); - - PropertyReader.expandVars(p); - - Assertions.assertTrue( p.getProperty("jspwiki.x1").equals("a") ); - Assertions.assertTrue( p.getProperty("jspwiki.x2").equals("b") ); - Assertions.assertTrue( p.getProperty("jspwiki.x3").equals("a/b") ); - } - -} \ No newline at end of file diff --git a/jspwiki-main/src/test/java/org/apache/wiki/Util.java b/jspwiki-main/src/test/java/org/apache/wiki/Util.java deleted file mode 100644 index 77c2ff1..0000000 --- a/jspwiki-main/src/test/java/org/apache/wiki/Util.java +++ /dev/null @@ -1,45 +0,0 @@ -/* - 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.wiki; - -import java.util.Collection; -import java.util.Iterator; - - -/** - * Utilities for tests. - */ -public class Util -{ - /** - * Check that a collection contains the required string. - */ - public static boolean collectionContains( Collection< ? > container, String captive ) - { - Iterator< ? > i = container.iterator(); - while( i.hasNext() ) - { - Object cap = i.next(); - if( cap instanceof String && captive.equals( cap ) ) - return true; - } - - return false; - } -} diff --git a/jspwiki-main/src/test/java/org/apache/wiki/references/ReferenceManagerTest.java b/jspwiki-main/src/test/java/org/apache/wiki/references/ReferenceManagerTest.java index e9ccc48..f520822 100644 --- a/jspwiki-main/src/test/java/org/apache/wiki/references/ReferenceManagerTest.java +++ b/jspwiki-main/src/test/java/org/apache/wiki/references/ReferenceManagerTest.java @@ -15,7 +15,6 @@ package org.apache.wiki.references; import net.sf.ehcache.CacheManager; import org.apache.wiki.TestEngine; -import org.apache.wiki.Util; import org.apache.wiki.WikiPage; import org.apache.wiki.api.exceptions.WikiException; import org.apache.wiki.pages.PageManager; @@ -98,7 +97,7 @@ public class ReferenceManagerTest { @Test public void testUnreferenced() { final Collection< String > c = mgr.findUnreferenced(); - Assertions.assertTrue( Util.collectionContains( c, "TestPage" ), "Unreferenced page not found by ReferenceManager" ); + Assertions.assertTrue( c.contains( "TestPage" ), "Unreferenced page not found by ReferenceManager" ); } diff --git a/jspwiki-util/src/test/java/org/apache/wiki/util/PropertyReaderTest.java b/jspwiki-util/src/test/java/org/apache/wiki/util/PropertyReaderTest.java index 0658af5..bb60cea 100644 --- a/jspwiki-util/src/test/java/org/apache/wiki/util/PropertyReaderTest.java +++ b/jspwiki-util/src/test/java/org/apache/wiki/util/PropertyReaderTest.java @@ -20,9 +20,11 @@ */ package org.apache.wiki.util; +import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.Assertions; +import java.util.Properties; + /** * Unit test for PropertyReader. @@ -30,14 +32,80 @@ import org.junit.jupiter.api.Assertions; public class PropertyReaderTest { @Test - public void testLocateClassPathResource() throws Exception { - Assertions.assertEquals("/ini/jspwiki.properties", PropertyReader.createResourceLocation("ini", "jspwiki.properties")); - Assertions.assertEquals("/ini/jspwiki.properties", PropertyReader.createResourceLocation(null, "ini/jspwiki.properties")); - Assertions.assertEquals("/ini/jspwiki.properties", PropertyReader.createResourceLocation(null, "/ini/jspwiki.properties")); - Assertions.assertEquals("/jspwiki-custom.properties", PropertyReader.createResourceLocation(null, "/jspwiki-custom.properties")); - Assertions.assertEquals("/jspwiki.custom.cascade.1.ini", PropertyReader.createResourceLocation(null, "jspwiki.custom.cascade.1.ini")); - Assertions.assertEquals("/WEB-INF/classes/jspwiki-custom.properties", PropertyReader.createResourceLocation("WEB-INF/classes", PropertyReader.CUSTOM_JSPWIKI_CONFIG)); - Assertions.assertEquals("/WEB-INF/classes/jspwiki-custom.properties", PropertyReader.createResourceLocation("/WEB-INF/classes", PropertyReader.CUSTOM_JSPWIKI_CONFIG)); - Assertions.assertEquals("/WEB-INF/classes/jspwiki-custom.properties", PropertyReader.createResourceLocation("/WEB-INF/classes/", PropertyReader.CUSTOM_JSPWIKI_CONFIG)); + public void testLocateClassPathResource() { + Assertions.assertEquals( "/ini/jspwiki.properties", PropertyReader.createResourceLocation( "ini", "jspwiki.properties" ) ); + Assertions.assertEquals( "/ini/jspwiki.properties", PropertyReader.createResourceLocation( null, "ini/jspwiki.properties" ) ); + Assertions.assertEquals( "/ini/jspwiki.properties", PropertyReader.createResourceLocation( null, "/ini/jspwiki.properties" ) ); + Assertions.assertEquals( "/jspwiki-custom.properties", PropertyReader.createResourceLocation( null, "/jspwiki-custom.properties" ) ); + Assertions.assertEquals( "/jspwiki.custom.cascade.1.ini", PropertyReader.createResourceLocation( null, "jspwiki.custom.cascade.1.ini" ) ); + Assertions.assertEquals( "/WEB-INF/classes/jspwiki-custom.properties", PropertyReader.createResourceLocation( "WEB-INF/classes", PropertyReader.CUSTOM_JSPWIKI_CONFIG ) ); + Assertions.assertEquals( "/WEB-INF/classes/jspwiki-custom.properties", PropertyReader.createResourceLocation( "/WEB-INF/classes", PropertyReader.CUSTOM_JSPWIKI_CONFIG ) ); + Assertions.assertEquals( "/WEB-INF/classes/jspwiki-custom.properties", PropertyReader.createResourceLocation( "/WEB-INF/classes/", PropertyReader.CUSTOM_JSPWIKI_CONFIG ) ); + } + + @Test + public void testVariableExpansion() { + final Properties p = new Properties(); + p.put( "var.basedir", "/p/mywiki" ); + p.put( "jspwiki.fileSystemProvider.pageDir", "$basedir/www/" ); + p.put( "jspwiki.basicAttachmentProvider.storageDir", "$basedir/www/" ); + p.put( "jspwiki.workDir", "$basedir/wrk/" ); + p.put( "jspwiki.xyz", "test basedir" ); //don't touch this + + PropertyReader.expandVars( p ); + + Assertions.assertEquals( "/p/mywiki/www/", p.getProperty( "jspwiki.fileSystemProvider.pageDir" ) ); + Assertions.assertEquals( "/p/mywiki/www/", p.getProperty( "jspwiki.basicAttachmentProvider.storageDir" ) ); + Assertions.assertEquals( "/p/mywiki/www/", p.getProperty( "jspwiki.fileSystemProvider.pageDir" ) ); + Assertions.assertTrue( p.getProperty( "jspwiki.workDir" ).endsWith( "/p/mywiki/wrk/" ) ); + Assertions.assertTrue( p.getProperty( "jspwiki.xyz" ).endsWith( "test basedir" ) ); //don't touch this + Assertions.assertFalse( p.getProperty( "jspwiki.workDir" ).endsWith( "$basedir/wrk/" ) ); + } + + @Test + public void testVariableExpansion2() { + final Properties p = new Properties(); + + //this time, declare the var at the end... (should overwrite this one); + p.put( "var.basedir", "xxx" ); + + p.put( "jspwiki.fileSystemProvider.pageDir", "$basedir/www/" ); + p.put( "jspwiki.basicAttachmentProvider.storageDir", "$basedir/www/" ); + p.put( "jspwiki.workDir", "$basedir/wrk/" ); + p.put( "jspwiki.xyz", "test basedir" ); //don't touch this + p.put( "jspwiki.abc", "test $x2" ); //don't touch this + + p.put( "var.basedir", " /p/mywiki" ); //note that this var has a space at the beginning... + p.put( "var.x2", " wiki " ); //note that this var has a space at the beginning... + + PropertyReader.expandVars( p ); + + Assertions.assertEquals( "/p/mywiki/www/", p.getProperty( "jspwiki.fileSystemProvider.pageDir" ) ); + Assertions.assertEquals( "/p/mywiki/www/", p.getProperty( "jspwiki.basicAttachmentProvider.storageDir" ) ); + Assertions.assertEquals( "/p/mywiki/www/", p.getProperty( "jspwiki.fileSystemProvider.pageDir" ) ); + Assertions.assertTrue( p.getProperty( "jspwiki.workDir" ).endsWith( "/p/mywiki/wrk/" ) ); + Assertions.assertTrue( p.getProperty( "jspwiki.xyz" ).endsWith( "test basedir" ) ); //don't touch this + Assertions.assertFalse( p.getProperty( "jspwiki.workDir" ).endsWith( "$basedir/wrk/" ) ); + Assertions.assertTrue( p.getProperty( "jspwiki.abc" ).endsWith( "test wiki" ) ); + } + + @Test + public void testMultipleVariableExpansion() { + final Properties p = new Properties(); + + //this time, declare the var at the end... (should overwrite this one); + p.put( "var.x1", "a" ); + p.put( "var.x2", "b" ); + + p.put( "jspwiki.x1", "$x1" ); + p.put( "jspwiki.x2", "$x2" ); + p.put( "jspwiki.x3", "$x1/$x2" ); + + PropertyReader.expandVars( p ); + + Assertions.assertEquals( "a", p.getProperty( "jspwiki.x1" ) ); + Assertions.assertEquals( "b", p.getProperty( "jspwiki.x2" ) ); + Assertions.assertEquals( "a/b", p.getProperty( "jspwiki.x3" ) ); } + }
