=== modified file 'dhis-2/dhis-api/pom.xml' --- dhis-2/dhis-api/pom.xml 2015-09-04 09:00:49 +0000 +++ dhis-2/dhis-api/pom.xml 2015-09-25 12:29:08 +0000 @@ -16,10 +16,6 @@ - junit - junit - - org.apache.commons commons-lang3 @@ -91,6 +87,14 @@ org.javassist javassist + + + + + junit + junit + test + === modified file 'dhis-2/dhis-support/dhis-support-commons/pom.xml' --- dhis-2/dhis-support/dhis-support-commons/pom.xml 2015-09-16 18:32:40 +0000 +++ dhis-2/dhis-support/dhis-support-commons/pom.xml 2015-09-25 12:29:08 +0000 @@ -35,6 +35,15 @@ org.apache.commons commons-jexl + + + + + junit + junit + test + + === added directory 'dhis-2/dhis-support/dhis-support-commons/src/test' === added directory 'dhis-2/dhis-support/dhis-support-commons/src/test/java' === added directory 'dhis-2/dhis-support/dhis-support-commons/src/test/java/org' === added directory 'dhis-2/dhis-support/dhis-support-commons/src/test/java/org/hisp' === added directory 'dhis-2/dhis-support/dhis-support-commons/src/test/java/org/hisp/dhis' === added file 'dhis-2/dhis-support/dhis-support-commons/src/test/java/org/hisp/dhis/IntegrationTest.java' --- dhis-2/dhis-support/dhis-support-commons/src/test/java/org/hisp/dhis/IntegrationTest.java 1970-01-01 00:00:00 +0000 +++ dhis-2/dhis-support/dhis-support-commons/src/test/java/org/hisp/dhis/IntegrationTest.java 2015-09-25 12:29:08 +0000 @@ -0,0 +1,36 @@ +package org.hisp.dhis; + +/* + * Copyright (c) 2004-2015, University of Oslo + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * Neither the name of the HISP project nor the names of its contributors may + * be used to endorse or promote products derived from this software without + * specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/** + * @author Morten Olav Hansen + */ +public interface IntegrationTest +{ +} === added directory 'dhis-2/dhis-support/dhis-support-commons/src/test/java/org/hisp/dhis/commons' === added directory 'dhis-2/dhis-support/dhis-support-commons/src/test/java/org/hisp/dhis/commons/util' === added file 'dhis-2/dhis-support/dhis-support-commons/src/test/java/org/hisp/dhis/commons/util/DebugUtilsTest.java' --- dhis-2/dhis-support/dhis-support-commons/src/test/java/org/hisp/dhis/commons/util/DebugUtilsTest.java 1970-01-01 00:00:00 +0000 +++ dhis-2/dhis-support/dhis-support-commons/src/test/java/org/hisp/dhis/commons/util/DebugUtilsTest.java 2015-09-25 12:29:08 +0000 @@ -0,0 +1,70 @@ +package org.hisp.dhis.commons.util; + +/* + * Copyright (c) 2004-2015, University of Oslo + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * Neither the name of the HISP project nor the names of its contributors may + * be used to endorse or promote products derived from this software without + * specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +import static org.hisp.dhis.commons.util.DebugUtils.SEPARATOR; +import static org.hisp.dhis.commons.util.DebugUtils.logDuplicates; +import static org.hisp.dhis.commons.util.DebugUtils.resetDuplicates; +import junit.framework.TestCase; + +/** + * @author Lars Helge Overland + * @version $Id$ + */ +public class DebugUtilsTest + extends TestCase +{ + public void testLogDuplicate() + { + String keyA = "name"; + String keyB = "code"; + String keyC = "identifier"; + + assertNull( logDuplicates( keyA, "john" ) ); + assertNull( logDuplicates( keyA, "tom" ) ); + assertNull( logDuplicates( keyA, "george" ) ); + assertEquals( "tom", logDuplicates( keyA, "tom" ) ); + assertNull( logDuplicates( keyA, "will" ) ); + assertEquals( "john", logDuplicates( keyA, "john" ) ); + + assertNull( logDuplicates( keyB, "john" ) ); + assertNull( logDuplicates( keyB, "A2", "A3" ) ); + assertNull( logDuplicates( keyB, "B1" ) ); + assertEquals( "A2" + SEPARATOR + "A3", logDuplicates( keyB, "A2", "A3" ) ); + assertEquals( "A2" + SEPARATOR + "A3", logDuplicates( keyB, "A2", "A3" ) ); + assertNull( logDuplicates( keyB, "C1" ) ); + + assertNull( logDuplicates( keyC, 1, 2, 3 ) ); + assertNull( logDuplicates( keyC, 1, 2, 4 ) ); + assertEquals( 1 + SEPARATOR + 2 + SEPARATOR + 3, logDuplicates( keyC, 1, 2, 3 ) ); + + assertTrue( resetDuplicates( keyA ) ); + assertNull( logDuplicates( keyA, "tom" ) ); + } +} === added file 'dhis-2/dhis-support/dhis-support-commons/src/test/java/org/hisp/dhis/commons/util/ExpressionUtilsTest.java' --- dhis-2/dhis-support/dhis-support-commons/src/test/java/org/hisp/dhis/commons/util/ExpressionUtilsTest.java 1970-01-01 00:00:00 +0000 +++ dhis-2/dhis-support/dhis-support-commons/src/test/java/org/hisp/dhis/commons/util/ExpressionUtilsTest.java 2015-09-25 12:29:08 +0000 @@ -0,0 +1,196 @@ +package org.hisp.dhis.commons.util; + +/* + * Copyright (c) 2004-2015, University of Oslo + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * Neither the name of the HISP project nor the names of its contributors may + * be used to endorse or promote products derived from this software without + * specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +import java.util.HashMap; +import java.util.Map; + +import org.hisp.dhis.commons.util.ExpressionUtils; +import org.junit.Test; + +/** + * @author Lars Helge Overland + */ +public class ExpressionUtilsTest +{ + private static final double DELTA = 0.01; + + @Test + public void testEvaluateToDouble() + { + assertEquals( 3d, ExpressionUtils.evaluateToDouble( "3", null ), DELTA ); + assertEquals( 3.45, ExpressionUtils.evaluateToDouble( "3.45", null ), DELTA ); + assertEquals( 5d, ExpressionUtils.evaluateToDouble( "2 + 3", null ), DELTA ); + assertEquals( 15.6, ExpressionUtils.evaluateToDouble( "12.4 + 3.2", null ), DELTA ); + assertEquals( 2.0, ExpressionUtils.evaluateToDouble( "2 > 1 ? 2.0 : 1.0", null ), DELTA ); + assertEquals( 1.0, ExpressionUtils.evaluateToDouble( "2 > 4 ? 2.0 : 1.0", null ), DELTA ); + assertEquals( 3d, ExpressionUtils.evaluateToDouble( "d2:zing(3)", null ), DELTA ); + assertEquals( 2d, ExpressionUtils.evaluateToDouble( "d2:zing(-3) + 2.0", null ), DELTA ); + assertEquals( 4d, ExpressionUtils.evaluateToDouble( "d2:zing(-1) + 4 + d2:zing(-2)", null ), DELTA ); + assertEquals( 0d, ExpressionUtils.evaluateToDouble( "d2:oizp(-4)", null ), DELTA ); + assertEquals( 1d, ExpressionUtils.evaluateToDouble( "d2:oizp(0)", null ), DELTA ); + assertEquals( 2d, ExpressionUtils.evaluateToDouble( "d2:oizp(-4) + d2:oizp(0) + d2:oizp(3.0)", null ), DELTA ); + assertEquals( 3d, ExpressionUtils.evaluateToDouble( "d2:daysBetween('2015-03-01','2015-03-04')", null ), DELTA ); + assertEquals( 1d, ExpressionUtils.evaluateToDouble( "d2:oizp(d2:zing(3))", null ), DELTA ); + assertEquals( 1d, ExpressionUtils.evaluateToDouble( "d2:zing(d2:oizp(3))", null ), DELTA ); + assertEquals( 2d, ExpressionUtils.evaluateToDouble( "d2:zpvc(1,3)", null ), DELTA ); + assertEquals( 3d, ExpressionUtils.evaluateToDouble( "d2:zpvc(1,-1,2,-3,0)", null ), DELTA ); + } + + @Test + public void testEvaluateToDoubleWithVars() + { + Map vars = new HashMap<>(); + + vars.put( "v1", 4d ); + vars.put( "v2", -5d ); + + assertEquals( 7d, ExpressionUtils.evaluateToDouble( "v1 + 3", vars ), DELTA ); + assertEquals( 4d, ExpressionUtils.evaluateToDouble( "d2:zing(v1)", vars ), DELTA ); + assertEquals( 0d, ExpressionUtils.evaluateToDouble( "d2:zing(v2)", vars ), DELTA ); + assertEquals( 4d, ExpressionUtils.evaluateToDouble( "d2:zing(v1) + d2:zing(v2)", vars ), DELTA ); + } + + //@Test + public void testEvaluateToDoubleZeroPositiveValueCount() + { + String expression = "d2:zing(3"; + } + + @Test + public void testEvaluate() + { + assertEquals( 4, ExpressionUtils.evaluate( "d2:condition('3 > 2',4,3)", null ) ); + assertEquals( 3, ExpressionUtils.evaluate( "d2:condition('5 > 7',4,3)", null ) ); + assertEquals( "yes", ExpressionUtils.evaluate( "d2:condition(\"'goat' == 'goat'\",'yes','no')", null ) ); + assertEquals( "no", ExpressionUtils.evaluate( "d2:condition(\"'goat' != 'goat'\",'yes','no')", null ) ); + assertEquals( "indoor", ExpressionUtils.evaluate( "d2:condition(\"'weather' == 'nice'\",'beach','indoor')", null ) ); + } + + @Test + public void testIsTrue() + { + assertTrue( ExpressionUtils.isTrue( "2 > 1", null ) ); + assertTrue( ExpressionUtils.isTrue( "(2 * 3) == 6", null ) ); + assertTrue( ExpressionUtils.isTrue( "\"a\" == \"a\"", null ) ); + assertTrue( ExpressionUtils.isTrue( "'b' == 'b'", null ) ); + assertTrue( ExpressionUtils.isTrue( "('b' == 'b') && ('c' == 'c')", null ) ); + assertTrue( ExpressionUtils.isTrue( "'goat' == 'goat'", null ) ); + + assertFalse( ExpressionUtils.isTrue( "2 < 1", null ) ); + assertFalse( ExpressionUtils.isTrue( "(2 * 3) == 8", null ) ); + assertFalse( ExpressionUtils.isTrue( "\"a\" == \"b\"", null ) ); + assertFalse( ExpressionUtils.isTrue( "'b' == 'c'", null ) ); + assertFalse( ExpressionUtils.isTrue( "'goat' == 'cow'", null ) ); + } + + @Test + public void testIsTrueWithVars() + { + Map vars = new HashMap<>(); + + vars.put( "v1", "4" ); + vars.put( "v2", "12" ); + vars.put( "v3", "goat" ); + vars.put( "v4", "horse" ); + + assertTrue( ExpressionUtils.isTrue( "v1 > 1", vars ) ); + assertTrue( ExpressionUtils.isTrue( "v2 < 18", vars ) ); + assertTrue( ExpressionUtils.isTrue( "v2 < '23'", vars ) ); + assertTrue( ExpressionUtils.isTrue( "v3 == 'goat'", vars ) ); + assertTrue( ExpressionUtils.isTrue( "v4 == 'horse'", vars ) ); + assertTrue( ExpressionUtils.isTrue( "v4 == \"horse\"", vars ) ); + + assertFalse( ExpressionUtils.isTrue( "v1 < 1", vars ) ); + assertFalse( ExpressionUtils.isTrue( "v2 > 18", vars ) ); + assertFalse( ExpressionUtils.isTrue( "v2 > '23'", vars ) ); + assertFalse( ExpressionUtils.isTrue( "v3 == 'cow'", vars ) ); + assertFalse( ExpressionUtils.isTrue( "v4 == 'goat'", vars ) ); + assertFalse( ExpressionUtils.isTrue( "v4 == \"goat\"", vars ) ); + } + + @Test + public void testIsBoolean() + { + Map vars = new HashMap<>(); + + vars.put( "uA2hsh8j26j", "FEMALE" ); + vars.put( "v2", "12" ); + + assertTrue( ExpressionUtils.isBoolean( "2 > 1", null ) ); + assertTrue( ExpressionUtils.isBoolean( "(2 * 3) == 6", null ) ); + assertTrue( ExpressionUtils.isBoolean( "\"a\" == \"a\"", null ) ); + assertTrue( ExpressionUtils.isBoolean( "'b' == 'b'", null ) ); + assertTrue( ExpressionUtils.isBoolean( "('b' == 'b') && ('c' == 'c')", null ) ); + assertTrue( ExpressionUtils.isBoolean( "'goat' == 'goat'", null ) ); + + assertFalse( ExpressionUtils.isBoolean( "4", null ) ); + assertFalse( ExpressionUtils.isBoolean( "3 + 2", null ) ); + assertFalse( ExpressionUtils.isBoolean( "someinvalid expr", null ) ); + } + + @Test + public void testAsSql() + { + assertEquals( "2 > 1 and 3 < 4", ExpressionUtils.asSql( "2 > 1 && 3 < 4" ) ); + assertEquals( "2 > 1 or 3 < 4", ExpressionUtils.asSql( "2 > 1 || 3 < 4" ) ); + assertEquals( "'a' = 1", ExpressionUtils.asSql( "'a' == 1" ) ); + assertEquals( "\"oZg33kd9taw\" = 'Female'", ExpressionUtils.asSql( "\"oZg33kd9taw\" == 'Female'" ) ); + } + + @Test + public void testIsValid() + { + Map vars = new HashMap<>(); + + vars.put( "v1", "12" ); + + assertTrue( ExpressionUtils.isValid( "2 + 8", null ) ); + assertTrue( ExpressionUtils.isValid( "3 - v1", vars ) ); + assertTrue( ExpressionUtils.isValid( "d2:zing(1)", null ) ); + assertTrue( ExpressionUtils.isValid( "d2:oizp(1)", null ) ); + assertTrue( ExpressionUtils.isValid( "d2:oizp(d2:zing(1))", null ) ); + assertTrue( ExpressionUtils.isValid( "d2:daysBetween('2015-02-01','2015-04-02')", null ) ); + assertTrue( ExpressionUtils.isValid( "(d2:zing(1)+d2:zing(1))*50/1", null ) ); + assertTrue( ExpressionUtils.isValid( "d2:condition('1 > 100',5,100)", null ) ); + assertTrue( ExpressionUtils.isValid( "1/(1/100)", null ) ); + assertTrue( ExpressionUtils.isValid( "SUM(1)", null ) ); + assertTrue( ExpressionUtils.isValid( "average(2+1)", null ) ); + + assertFalse( ExpressionUtils.isValid( "2 a 3", null ) ); + assertFalse( ExpressionUtils.isValid( "v2 + 3", vars ) ); + assertFalse( ExpressionUtils.isValid( "4 + abc", vars ) ); + assertFalse( ExpressionUtils.isValid( "'goat' == goat", null ) ); + assertFalse( ExpressionUtils.isValid( "aver(2+1)", null ) ); + } +} === added file 'dhis-2/dhis-support/dhis-support-commons/src/test/java/org/hisp/dhis/commons/util/ListUtilsTest.java' --- dhis-2/dhis-support/dhis-support-commons/src/test/java/org/hisp/dhis/commons/util/ListUtilsTest.java 1970-01-01 00:00:00 +0000 +++ dhis-2/dhis-support/dhis-support-commons/src/test/java/org/hisp/dhis/commons/util/ListUtilsTest.java 2015-09-25 12:29:08 +0000 @@ -0,0 +1,76 @@ +package org.hisp.dhis.commons.util; + +/* + * Copyright (c) 2004-2015, University of Oslo + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * Neither the name of the HISP project nor the names of its contributors may + * be used to endorse or promote products derived from this software without + * specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashSet; +import java.util.List; +import java.util.Set; + +import org.hisp.dhis.commons.collection.ListUtils; +import org.junit.Test; + +/** + * @author Lars Helge Overland + */ +public class ListUtilsTest +{ + @Test + public void testRemoveAll() + { + List list = new ArrayList<>( Arrays.asList( "a", "b", "c", "d", "e", "f", "g", "h" ) ); + + Integer[] indexes = { 0, 2, 5, 7, -1, 78 }; + + assertEquals( 8, list.size() ); + + ListUtils.removeAll( list, indexes ); + + assertEquals( 4, list.size() ); + assertTrue( list.contains( "b" ) ); + assertTrue( list.contains( "d" ) ); + assertTrue( list.contains( "e" ) ); + assertTrue( list.contains( "g" ) ); + } + + @Test + public void testGetDuplicates() + { + List list = new ArrayList<>( Arrays.asList( "a", "b", "c", "c", "d", "e", "e", "e", "f" ) ); + Set expected = new HashSet<>( Arrays.asList( "c", "e" ) ); + assertEquals( expected, ListUtils.getDuplicates( list ) ); + + list = new ArrayList<>( Arrays.asList( "a", "b", "c", "d", "e", "f", "g", "h" ) ); + assertEquals( 0, ListUtils.getDuplicates( list ).size() ); + } +} === added file 'dhis-2/dhis-support/dhis-support-commons/src/test/java/org/hisp/dhis/commons/util/PageRangeTest.java' --- dhis-2/dhis-support/dhis-support-commons/src/test/java/org/hisp/dhis/commons/util/PageRangeTest.java 1970-01-01 00:00:00 +0000 +++ dhis-2/dhis-support/dhis-support-commons/src/test/java/org/hisp/dhis/commons/util/PageRangeTest.java 2015-09-25 12:29:08 +0000 @@ -0,0 +1,98 @@ +package org.hisp.dhis.commons.util; + +/* + * Copyright (c) 2004-2015, University of Oslo + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * Neither the name of the HISP project nor the names of its contributors may + * be used to endorse or promote products derived from this software without + * specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +import java.util.List; + +import org.hisp.dhis.commons.util.PageRange; +import org.junit.Test; + +import static org.junit.Assert.*; + +/** + * @author Lars Helge Overland + */ +public class PageRangeTest +{ + @Test + public void testPageSize() + { + PageRange range = new PageRange( 12 ).setPageSize( 5 ); + + assertTrue( range.nextPage() ); + assertEquals( 0, range.getFromIndex() ); + assertEquals( 5, range.getToIndex() ); + + assertTrue( range.nextPage() ); + assertEquals( 5, range.getFromIndex() ); + assertEquals( 10, range.getToIndex() ); + + assertTrue( range.nextPage() ); + assertEquals( 10, range.getFromIndex() ); + assertEquals( 12, range.getToIndex() ); + + assertFalse( range.nextPage() ); + } + + @Test + public void testPages() + { + PageRange range = new PageRange( 11 ).setPages( 3 ); + + assertTrue( range.nextPage() ); + assertEquals( 0, range.getFromIndex() ); + assertEquals( 4, range.getToIndex() ); + + assertTrue( range.nextPage() ); + assertEquals( 4, range.getFromIndex() ); + assertEquals( 8, range.getToIndex() ); + + assertTrue( range.nextPage() ); + assertEquals( 8, range.getFromIndex() ); + assertEquals( 11, range.getToIndex() ); + + assertFalse( range.nextPage() ); + } + + @Test + public void testGetPages() + { + PageRange range = new PageRange( 12 ).setPageSize( 5 ); + + List pages = range.getPages(); + + assertEquals( 3, pages.size() ); + assertEquals( 0, pages.get( 0 )[0] ); + assertEquals( 5, pages.get( 0 )[1] ); + assertEquals( 5, pages.get( 1 )[0] ); + assertEquals( 10, pages.get( 1 )[1] ); + assertEquals( 10, pages.get( 2 )[0] ); + assertEquals( 12, pages.get( 2 )[1] ); + } +} === added file 'dhis-2/dhis-support/dhis-support-commons/src/test/java/org/hisp/dhis/commons/util/PaginatedListTest.java' --- dhis-2/dhis-support/dhis-support-commons/src/test/java/org/hisp/dhis/commons/util/PaginatedListTest.java 1970-01-01 00:00:00 +0000 +++ dhis-2/dhis-support/dhis-support-commons/src/test/java/org/hisp/dhis/commons/util/PaginatedListTest.java 2015-09-25 12:29:08 +0000 @@ -0,0 +1,160 @@ +package org.hisp.dhis.commons.util; + +/* + * Copyright (c) 2004-2015, University of Oslo + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * Neither the name of the HISP project nor the names of its contributors may + * be used to endorse or promote products derived from this software without + * specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +import org.hisp.dhis.commons.collection.PaginatedList; +import org.junit.Test; + +/** + * @author Lars Helge Overland + */ +public class PaginatedListTest +{ + @Test + public void testNextPage() + { + PaginatedList list = new PaginatedList<>( Arrays.asList( "A", "B", "C" ) ).setPageSize( 2 ); + + List page = list.nextPage(); + + assertNotNull( page ); + assertEquals( 2, page.size() ); + assertTrue( page.contains( "A" ) ); + assertTrue( page.contains( "B" ) ); + + page = list.nextPage(); + + assertNotNull( page ); + assertEquals( 1, page.size() ); + assertTrue( page.contains( "C" ) ); + + page = list.nextPage(); + + assertNull( page ); + } + + @Test + public void testGetPageEmpty() + { + PaginatedList list = new PaginatedList<>( new ArrayList() ).setPageSize( 2 ); + + List page = list.nextPage(); + + assertNull( page ); + } + + @Test + public void testPageCount() + { + PaginatedList list = new PaginatedList<>( Arrays.asList( "A", "B", "C" ) ).setPageSize( 2 ); + + assertEquals( 2, list.pageCount() ); + + list = new PaginatedList<>( Arrays.asList( "A", "B", "C", "D" ) ).setPageSize( 2 ); + + assertEquals( 2, list.pageCount() ); + + list = new PaginatedList<>( Arrays.asList( "A", "B", "C", "D", "E" ) ).setPageSize( 2 ); + + assertEquals( 3, list.pageCount() ); + } + + @Test + public void testReset() + { + PaginatedList list = new PaginatedList<>( Arrays.asList( "A", "B", "C" ) ).setPageSize( 2 ); + + assertTrue( list.nextPage().contains( "A" ) ); + + list.reset(); + + assertTrue( list.nextPage().contains( "A" ) ); + } + + @Test + public void testSetNumberOfPages() + { + PaginatedList list = new PaginatedList<>( Arrays.asList( "A", "B", "C", "D", "E" ) ).setNumberOfPages( 3 ); + + assertEquals( 3, list.pageCount() ); + + assertEquals( 2, list.nextPage().size() ); + } + + @Test + public void testNextPageNumberOfPages() + { + PaginatedList list = new PaginatedList<>( Arrays.asList( "A", "B", "C", "D", "E" ) ).setNumberOfPages( 2 ); + + List page = list.nextPage(); + + assertNotNull( page ); + assertEquals( 3, page.size() ); + assertTrue( page.contains( "A" ) ); + assertTrue( page.contains( "B" ) ); + assertTrue( page.contains( "C" ) ); + + page = list.nextPage(); + + assertNotNull( page ); + assertEquals( 2, page.size() ); + assertTrue( page.contains( "D" ) ); + assertTrue( page.contains( "E" ) ); + + page = list.nextPage(); + + assertNull( page ); + } + + @Test + public void testGetPages() + { + PaginatedList list = new PaginatedList<>( Arrays.asList( "A", "B", "C", "D", "E" ) ).setPageSize( 2 ); + + List> pages = list.getPages(); + + assertNotNull( pages ); + assertEquals( 3, pages.size() ); + + List page = pages.get( 0 ); + assertNotNull( page ); + assertEquals( 2, page.size() ); + assertTrue( page.contains( "A" ) ); + assertTrue( page.contains( "B" ) ); + } +} === added file 'dhis-2/dhis-support/dhis-support-commons/src/test/java/org/hisp/dhis/commons/util/TextUtilsTest.java' --- dhis-2/dhis-support/dhis-support-commons/src/test/java/org/hisp/dhis/commons/util/TextUtilsTest.java 1970-01-01 00:00:00 +0000 +++ dhis-2/dhis-support/dhis-support-commons/src/test/java/org/hisp/dhis/commons/util/TextUtilsTest.java 2015-09-25 12:29:08 +0000 @@ -0,0 +1,134 @@ +package org.hisp.dhis.commons.util; + +/* + * Copyright (c) 2004-2015, University of Oslo + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * Neither the name of the HISP project nor the names of its contributors may + * be used to endorse or promote products derived from this software without + * specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; +import static org.hisp.dhis.commons.util.TextUtils.*; + +import java.util.ArrayList; +import java.util.Arrays; + +import org.hisp.dhis.commons.util.TextUtils; +import org.junit.Test; + +/** + * @author Lars Helge Overland + */ +public class TextUtilsTest +{ + private static final String STRING = "abcdefghij"; + + @Test + public void testHtmlLinks() + { + assertEquals( "http://dhis2.org", htmlLinks( "http://dhis2.org" ) ); + assertEquals( "https://dhis2.org", htmlLinks( "https://dhis2.org" ) ); + assertEquals( "www.dhis2.org", htmlLinks( "www.dhis2.org" ) ); + assertEquals( "Navigate to http://dhis2.org or www.dhis2.com to read more.", + htmlLinks( "Navigate to http://dhis2.org or www.dhis2.com to read more." ) ); + } + + @Test + public void testSubString() + { + assertEquals( "abcdefghij", subString( STRING, 0, 10 ) ); + assertEquals( "cdef", subString( STRING, 2, 4 ) ); + assertEquals( "ghij", subString( STRING, 6, 4 ) ); + assertEquals( "ghij", subString( STRING, 6, 6 ) ); + assertEquals( "", subString( STRING, 11, 3 ) ); + assertEquals( "j", subString( STRING, 9, 1 ) ); + assertEquals( "", subString( STRING, 4, 0 ) ); + } + + @Test + public void testTrim() + { + assertEquals( "abcdefgh", trimEnd( "abcdefghijkl", 4 ) ); + } + + @Test + public void testGetTokens() + { + assertEquals( new ArrayList<>( Arrays.asList( "John", "Doe", "Main", "Road", "25" ) ), TextUtils.getTokens( "John Doe Main Road 25" ) ); + assertEquals( new ArrayList<>( Arrays.asList( "Ted,Johnson", "Upper-Road", "45" ) ), TextUtils.getTokens( "Ted,Johnson Upper-Road 45" ) ); + } + + @Test + public void testRemoveLastOr() + { + assertEquals( null, TextUtils.removeLastOr( null ) ); + assertEquals( "", TextUtils.removeLastOr( "" ) ); + assertEquals( "or name='tom' or name='john' ", TextUtils.removeLastOr( "or name='tom' or name='john' or" ) ); + assertEquals( "or name='tom' or name='john' ", TextUtils.removeLastOr( "or name='tom' or name='john' or " ) ); + assertEquals( "or name='tom' or name='john' ", TextUtils.removeLastOr( "or name='tom' or name='john' or " ) ); + } + + @Test + public void testRemoveLastAnd() + { + assertEquals( null, TextUtils.removeLastAnd( null ) ); + assertEquals( "", TextUtils.removeLastAnd( "" ) ); + assertEquals( "and name='tom' and name='john' ", TextUtils.removeLastAnd( "and name='tom' and name='john' and" ) ); + assertEquals( "and name='tom' and name='john' ", TextUtils.removeLastAnd( "and name='tom' and name='john' and " ) ); + assertEquals( "and name='tom' and name='john' ", TextUtils.removeLastAnd( "and name='tom' and name='john' and " ) ); + } + + @Test + public void testRemoveLastComma() + { + assertEquals( null, TextUtils.removeLastComma( null ) ); + assertEquals( "", TextUtils.removeLastComma( "" ) ); + assertEquals( "tom,john", TextUtils.removeLastComma( "tom,john," ) ); + assertEquals( "tom, john", TextUtils.removeLastComma( "tom, john, " ) ); + assertEquals( "tom, john", TextUtils.removeLastComma( "tom, john, " ) ); + } + + @Test + public void testJoinReplaceNull() + { + assertEquals( "green-red-blue", TextUtils.join( Arrays.asList( "green", "red", "blue" ), "-", "[n/a]" ) ); + assertEquals( "green-[n/a]-blue", TextUtils.join( Arrays.asList( "green", null, "blue" ), "-", "[n/a]" ) ); + assertEquals( "green-red-[n/a]", TextUtils.join( Arrays.asList( "green", "red", null ), "-", "[n/a]" ) ); + assertEquals( "greenred[n/a]", TextUtils.join( Arrays.asList( "green", "red", null ), null, "[n/a]" ) ); + assertEquals( "greenred", TextUtils.join( Arrays.asList( "green", "red", null ), null, null ) ); + } + + @Test + public void testSplitSafe() + { + assertEquals( "green", TextUtils.splitSafe( "red-green-blue", "-", 1 ) ); + assertEquals( "green", TextUtils.splitSafe( "red.green.blue", "\\.", 1 ) ); + assertEquals( "red", TextUtils.splitSafe( "red-green-blue", "-", 0 ) ); + assertEquals( "blue", TextUtils.splitSafe( "red-green-blue", "-", 2 ) ); + assertNull( TextUtils.splitSafe( "red-green-blue", "-", 3 ) ); + assertNull( TextUtils.splitSafe( "red-green-blue", "-", -2 ) ); + assertNull( TextUtils.splitSafe( "red-green-blue-", "-", 3 ) ); + } +} === modified file 'dhis-2/dhis-support/dhis-support-hibernate/pom.xml' --- dhis-2/dhis-support/dhis-support-hibernate/pom.xml 2015-07-20 02:01:37 +0000 +++ dhis-2/dhis-support/dhis-support-hibernate/pom.xml 2015-09-25 12:29:08 +0000 @@ -94,6 +94,14 @@ commons-logging + + + + junit + junit + test + + ../../ === modified file 'dhis-2/dhis-support/dhis-support-jdbc/pom.xml' --- dhis-2/dhis-support/dhis-support-jdbc/pom.xml 2015-07-20 02:01:37 +0000 +++ dhis-2/dhis-support/dhis-support-jdbc/pom.xml 2015-09-25 12:29:08 +0000 @@ -48,7 +48,15 @@ org.hisp.dhis dhis-support-hibernate - + + + + + junit + junit + test + + ../../ === modified file 'dhis-2/dhis-support/dhis-support-system/pom.xml' --- dhis-2/dhis-support/dhis-support-system/pom.xml 2015-07-20 02:01:37 +0000 +++ dhis-2/dhis-support/dhis-support-system/pom.xml 2015-09-25 12:29:08 +0000 @@ -194,13 +194,18 @@ guava + net.sourceforge.javacsv + javacsv + + + + + junit junit - - - net.sourceforge.javacsv - javacsv - + test + + ../../ === modified file 'dhis-2/dhis-support/dhis-support-system/src/test/java/org/hisp/dhis/system/filter/AggregatableDataElementFilterTest.java' --- dhis-2/dhis-support/dhis-support-system/src/test/java/org/hisp/dhis/system/filter/AggregatableDataElementFilterTest.java 2015-09-04 09:29:23 +0000 +++ dhis-2/dhis-support/dhis-support-system/src/test/java/org/hisp/dhis/system/filter/AggregatableDataElementFilterTest.java 2015-09-25 12:29:08 +0000 @@ -29,10 +29,12 @@ */ import com.google.common.collect.Sets; + import org.hisp.dhis.DhisConvenienceTest; import org.hisp.dhis.common.ValueType; import org.hisp.dhis.commons.filter.FilterUtils; import org.hisp.dhis.dataelement.DataElement; +import org.hisp.dhis.system.filter.AggregatableDataElementFilter; import org.junit.Test; import java.util.Set; === removed file 'dhis-2/dhis-support/dhis-support-system/src/test/java/org/hisp/dhis/system/util/DebugUtilsTest.java' --- dhis-2/dhis-support/dhis-support-system/src/test/java/org/hisp/dhis/system/util/DebugUtilsTest.java 2015-06-15 13:44:20 +0000 +++ dhis-2/dhis-support/dhis-support-system/src/test/java/org/hisp/dhis/system/util/DebugUtilsTest.java 1970-01-01 00:00:00 +0000 @@ -1,70 +0,0 @@ -package org.hisp.dhis.system.util; - -/* - * Copyright (c) 2004-2015, University of Oslo - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * - * Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * Neither the name of the HISP project nor the names of its contributors may - * be used to endorse or promote products derived from this software without - * specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR - * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON - * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -import static org.hisp.dhis.commons.util.DebugUtils.SEPARATOR; -import static org.hisp.dhis.commons.util.DebugUtils.logDuplicates; -import static org.hisp.dhis.commons.util.DebugUtils.resetDuplicates; -import junit.framework.TestCase; - -/** - * @author Lars Helge Overland - * @version $Id$ - */ -public class DebugUtilsTest - extends TestCase -{ - public void testLogDuplicate() - { - String keyA = "name"; - String keyB = "code"; - String keyC = "identifier"; - - assertNull( logDuplicates( keyA, "john" ) ); - assertNull( logDuplicates( keyA, "tom" ) ); - assertNull( logDuplicates( keyA, "george" ) ); - assertEquals( "tom", logDuplicates( keyA, "tom" ) ); - assertNull( logDuplicates( keyA, "will" ) ); - assertEquals( "john", logDuplicates( keyA, "john" ) ); - - assertNull( logDuplicates( keyB, "john" ) ); - assertNull( logDuplicates( keyB, "A2", "A3" ) ); - assertNull( logDuplicates( keyB, "B1" ) ); - assertEquals( "A2" + SEPARATOR + "A3", logDuplicates( keyB, "A2", "A3" ) ); - assertEquals( "A2" + SEPARATOR + "A3", logDuplicates( keyB, "A2", "A3" ) ); - assertNull( logDuplicates( keyB, "C1" ) ); - - assertNull( logDuplicates( keyC, 1, 2, 3 ) ); - assertNull( logDuplicates( keyC, 1, 2, 4 ) ); - assertEquals( 1 + SEPARATOR + 2 + SEPARATOR + 3, logDuplicates( keyC, 1, 2, 3 ) ); - - assertTrue( resetDuplicates( keyA ) ); - assertNull( logDuplicates( keyA, "tom" ) ); - } -} === removed file 'dhis-2/dhis-support/dhis-support-system/src/test/java/org/hisp/dhis/system/util/ExpressionUtilsTest.java' --- dhis-2/dhis-support/dhis-support-system/src/test/java/org/hisp/dhis/system/util/ExpressionUtilsTest.java 2015-09-24 19:18:20 +0000 +++ dhis-2/dhis-support/dhis-support-system/src/test/java/org/hisp/dhis/system/util/ExpressionUtilsTest.java 1970-01-01 00:00:00 +0000 @@ -1,190 +0,0 @@ -package org.hisp.dhis.system.util; - -/* - * Copyright (c) 2004-2015, University of Oslo - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * - * Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * Neither the name of the HISP project nor the names of its contributors may - * be used to endorse or promote products derived from this software without - * specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR - * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON - * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; - -import java.util.HashMap; -import java.util.Map; - -import org.hisp.dhis.commons.util.ExpressionUtils; -import org.junit.Test; - -/** - * @author Lars Helge Overland - */ -public class ExpressionUtilsTest -{ - private static final double DELTA = 0.01; - - @Test - public void testEvaluateToDouble() - { - assertEquals( 3d, ExpressionUtils.evaluateToDouble( "3", null ), DELTA ); - assertEquals( 3.45, ExpressionUtils.evaluateToDouble( "3.45", null ), DELTA ); - assertEquals( 5d, ExpressionUtils.evaluateToDouble( "2 + 3", null ), DELTA ); - assertEquals( 15.6, ExpressionUtils.evaluateToDouble( "12.4 + 3.2", null ), DELTA ); - assertEquals( 2.0, ExpressionUtils.evaluateToDouble( "2 > 1 ? 2.0 : 1.0", null ), DELTA ); - assertEquals( 1.0, ExpressionUtils.evaluateToDouble( "2 > 4 ? 2.0 : 1.0", null ), DELTA ); - assertEquals( 3d, ExpressionUtils.evaluateToDouble( "d2:zing(3)", null ), DELTA ); - assertEquals( 2d, ExpressionUtils.evaluateToDouble( "d2:zing(-3) + 2.0", null ), DELTA ); - assertEquals( 4d, ExpressionUtils.evaluateToDouble( "d2:zing(-1) + 4 + d2:zing(-2)", null ), DELTA ); - assertEquals( 0d, ExpressionUtils.evaluateToDouble( "d2:oizp(-4)", null ), DELTA ); - assertEquals( 1d, ExpressionUtils.evaluateToDouble( "d2:oizp(0)", null ), DELTA ); - assertEquals( 2d, ExpressionUtils.evaluateToDouble( "d2:oizp(-4) + d2:oizp(0) + d2:oizp(3.0)", null ), DELTA ); - assertEquals( 3d, ExpressionUtils.evaluateToDouble( "d2:daysBetween('2015-03-01','2015-03-04')", null ), DELTA ); - assertEquals( 1d, ExpressionUtils.evaluateToDouble( "d2:oizp(d2:zing(3))", null ), DELTA ); - assertEquals( 1d, ExpressionUtils.evaluateToDouble( "d2:zing(d2:oizp(3))", null ), DELTA ); - assertEquals( 2d, ExpressionUtils.evaluateToDouble( "d2:zpvc(1,3)", null ), DELTA ); - assertEquals( 3d, ExpressionUtils.evaluateToDouble( "d2:zpvc(1,-1,2,-3,0)", null ), DELTA ); - } - - @Test - public void testEvaluateToDoubleWithVars() - { - Map vars = new HashMap<>(); - - vars.put( "v1", 4d ); - vars.put( "v2", -5d ); - - assertEquals( 7d, ExpressionUtils.evaluateToDouble( "v1 + 3", vars ), DELTA ); - assertEquals( 4d, ExpressionUtils.evaluateToDouble( "d2:zing(v1)", vars ), DELTA ); - assertEquals( 0d, ExpressionUtils.evaluateToDouble( "d2:zing(v2)", vars ), DELTA ); - assertEquals( 4d, ExpressionUtils.evaluateToDouble( "d2:zing(v1) + d2:zing(v2)", vars ), DELTA ); - } - - @Test - public void testEvaluate() - { - assertEquals( 4, ExpressionUtils.evaluate( "d2:condition('3 > 2',4,3)", null ) ); - assertEquals( 3, ExpressionUtils.evaluate( "d2:condition('5 > 7',4,3)", null ) ); - assertEquals( "yes", ExpressionUtils.evaluate( "d2:condition(\"'goat' == 'goat'\",'yes','no')", null ) ); - assertEquals( "no", ExpressionUtils.evaluate( "d2:condition(\"'goat' != 'goat'\",'yes','no')", null ) ); - assertEquals( "indoor", ExpressionUtils.evaluate( "d2:condition(\"'weather' == 'nice'\",'beach','indoor')", null ) ); - } - - @Test - public void testIsTrue() - { - assertTrue( ExpressionUtils.isTrue( "2 > 1", null ) ); - assertTrue( ExpressionUtils.isTrue( "(2 * 3) == 6", null ) ); - assertTrue( ExpressionUtils.isTrue( "\"a\" == \"a\"", null ) ); - assertTrue( ExpressionUtils.isTrue( "'b' == 'b'", null ) ); - assertTrue( ExpressionUtils.isTrue( "('b' == 'b') && ('c' == 'c')", null ) ); - assertTrue( ExpressionUtils.isTrue( "'goat' == 'goat'", null ) ); - - assertFalse( ExpressionUtils.isTrue( "2 < 1", null ) ); - assertFalse( ExpressionUtils.isTrue( "(2 * 3) == 8", null ) ); - assertFalse( ExpressionUtils.isTrue( "\"a\" == \"b\"", null ) ); - assertFalse( ExpressionUtils.isTrue( "'b' == 'c'", null ) ); - assertFalse( ExpressionUtils.isTrue( "'goat' == 'cow'", null ) ); - } - - @Test - public void testIsTrueWithVars() - { - Map vars = new HashMap<>(); - - vars.put( "v1", "4" ); - vars.put( "v2", "12" ); - vars.put( "v3", "goat" ); - vars.put( "v4", "horse" ); - - assertTrue( ExpressionUtils.isTrue( "v1 > 1", vars ) ); - assertTrue( ExpressionUtils.isTrue( "v2 < 18", vars ) ); - assertTrue( ExpressionUtils.isTrue( "v2 < '23'", vars ) ); - assertTrue( ExpressionUtils.isTrue( "v3 == 'goat'", vars ) ); - assertTrue( ExpressionUtils.isTrue( "v4 == 'horse'", vars ) ); - assertTrue( ExpressionUtils.isTrue( "v4 == \"horse\"", vars ) ); - - assertFalse( ExpressionUtils.isTrue( "v1 < 1", vars ) ); - assertFalse( ExpressionUtils.isTrue( "v2 > 18", vars ) ); - assertFalse( ExpressionUtils.isTrue( "v2 > '23'", vars ) ); - assertFalse( ExpressionUtils.isTrue( "v3 == 'cow'", vars ) ); - assertFalse( ExpressionUtils.isTrue( "v4 == 'goat'", vars ) ); - assertFalse( ExpressionUtils.isTrue( "v4 == \"goat\"", vars ) ); - } - - @Test - public void testIsBoolean() - { - Map vars = new HashMap<>(); - - vars.put( "uA2hsh8j26j", "FEMALE" ); - vars.put( "v2", "12" ); - - assertTrue( ExpressionUtils.isBoolean( "2 > 1", null ) ); - assertTrue( ExpressionUtils.isBoolean( "(2 * 3) == 6", null ) ); - assertTrue( ExpressionUtils.isBoolean( "\"a\" == \"a\"", null ) ); - assertTrue( ExpressionUtils.isBoolean( "'b' == 'b'", null ) ); - assertTrue( ExpressionUtils.isBoolean( "('b' == 'b') && ('c' == 'c')", null ) ); - assertTrue( ExpressionUtils.isBoolean( "'goat' == 'goat'", null ) ); - - assertFalse( ExpressionUtils.isBoolean( "4", null ) ); - assertFalse( ExpressionUtils.isBoolean( "3 + 2", null ) ); - assertFalse( ExpressionUtils.isBoolean( "someinvalid expr", null ) ); - } - - @Test - public void testAsSql() - { - assertEquals( "2 > 1 and 3 < 4", ExpressionUtils.asSql( "2 > 1 && 3 < 4" ) ); - assertEquals( "2 > 1 or 3 < 4", ExpressionUtils.asSql( "2 > 1 || 3 < 4" ) ); - assertEquals( "'a' = 1", ExpressionUtils.asSql( "'a' == 1" ) ); - assertEquals( "\"oZg33kd9taw\" = 'Female'", ExpressionUtils.asSql( "\"oZg33kd9taw\" == 'Female'" ) ); - } - - @Test - public void testIsValid() - { - Map vars = new HashMap<>(); - - vars.put( "v1", "12" ); - - assertTrue( ExpressionUtils.isValid( "2 + 8", null ) ); - assertTrue( ExpressionUtils.isValid( "3 - v1", vars ) ); - assertTrue( ExpressionUtils.isValid( "d2:zing(1)", null ) ); - assertTrue( ExpressionUtils.isValid( "d2:oizp(1)", null ) ); - assertTrue( ExpressionUtils.isValid( "d2:oizp(d2:zing(1))", null ) ); - assertTrue( ExpressionUtils.isValid( "d2:daysBetween('2015-02-01','2015-04-02')", null ) ); - assertTrue( ExpressionUtils.isValid( "(d2:zing(1)+d2:zing(1))*50/1", null ) ); - assertTrue( ExpressionUtils.isValid( "d2:condition('1 > 100',5,100)", null ) ); - assertTrue( ExpressionUtils.isValid( "1/(1/100)", null ) ); - assertTrue( ExpressionUtils.isValid( "SUM(1)", null ) ); - assertTrue( ExpressionUtils.isValid( "average(2+1)", null ) ); - - assertFalse( ExpressionUtils.isValid( "2 a 3", null ) ); - assertFalse( ExpressionUtils.isValid( "v2 + 3", vars ) ); - assertFalse( ExpressionUtils.isValid( "4 + abc", vars ) ); - assertFalse( ExpressionUtils.isValid( "'goat' == goat", null ) ); - assertFalse( ExpressionUtils.isValid( "aver(2+1)", null ) ); - } -} === removed file 'dhis-2/dhis-support/dhis-support-system/src/test/java/org/hisp/dhis/system/util/ListUtilsTest.java' --- dhis-2/dhis-support/dhis-support-system/src/test/java/org/hisp/dhis/system/util/ListUtilsTest.java 2015-06-15 13:44:20 +0000 +++ dhis-2/dhis-support/dhis-support-system/src/test/java/org/hisp/dhis/system/util/ListUtilsTest.java 1970-01-01 00:00:00 +0000 @@ -1,78 +0,0 @@ -package org.hisp.dhis.system.util; - -/* - * Copyright (c) 2004-2015, University of Oslo - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * - * Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * Neither the name of the HISP project nor the names of its contributors may - * be used to endorse or promote products derived from this software without - * specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR - * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON - * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; -import java.util.Set; - -import org.hisp.dhis.commons.collection.ListUtils; -import org.junit.Test; - -import com.google.common.collect.Lists; -import com.google.common.collect.Sets; - -/** - * @author Lars Helge Overland - */ -public class ListUtilsTest -{ - @Test - public void testRemoveAll() - { - List list = Lists.newArrayList( "a", "b", "c", "d", "e", "f", "g", "h" ); - - Integer[] indexes = { 0, 2, 5, 7, -1, 78 }; - - assertEquals( 8, list.size() ); - - ListUtils.removeAll( list, indexes ); - - assertEquals( 4, list.size() ); - assertTrue( list.contains( "b" ) ); - assertTrue( list.contains( "d" ) ); - assertTrue( list.contains( "e" ) ); - assertTrue( list.contains( "g" ) ); - } - - @Test - public void testGetDuplicates() - { - List list = Lists.newArrayList( "a", "b", "c", "c", "d", "e", "e", "e", "f" ); - Set expected = Sets.newHashSet( "c", "e" ); - assertEquals( expected, ListUtils.getDuplicates( list ) ); - - list = new ArrayList<>( Arrays.asList( "a", "b", "c", "d", "e", "f", "g", "h" ) ); - assertEquals( 0, ListUtils.getDuplicates( list ).size() ); - } -} === removed file 'dhis-2/dhis-support/dhis-support-system/src/test/java/org/hisp/dhis/system/util/PageRangeTest.java' --- dhis-2/dhis-support/dhis-support-system/src/test/java/org/hisp/dhis/system/util/PageRangeTest.java 2015-06-15 13:44:20 +0000 +++ dhis-2/dhis-support/dhis-support-system/src/test/java/org/hisp/dhis/system/util/PageRangeTest.java 1970-01-01 00:00:00 +0000 @@ -1,98 +0,0 @@ -package org.hisp.dhis.system.util; - -/* - * Copyright (c) 2004-2015, University of Oslo - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * - * Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * Neither the name of the HISP project nor the names of its contributors may - * be used to endorse or promote products derived from this software without - * specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR - * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON - * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -import java.util.List; - -import org.hisp.dhis.commons.util.PageRange; -import org.junit.Test; - -import static org.junit.Assert.*; - -/** - * @author Lars Helge Overland - */ -public class PageRangeTest -{ - @Test - public void testPageSize() - { - PageRange range = new PageRange( 12 ).setPageSize( 5 ); - - assertTrue( range.nextPage() ); - assertEquals( 0, range.getFromIndex() ); - assertEquals( 5, range.getToIndex() ); - - assertTrue( range.nextPage() ); - assertEquals( 5, range.getFromIndex() ); - assertEquals( 10, range.getToIndex() ); - - assertTrue( range.nextPage() ); - assertEquals( 10, range.getFromIndex() ); - assertEquals( 12, range.getToIndex() ); - - assertFalse( range.nextPage() ); - } - - @Test - public void testPages() - { - PageRange range = new PageRange( 11 ).setPages( 3 ); - - assertTrue( range.nextPage() ); - assertEquals( 0, range.getFromIndex() ); - assertEquals( 4, range.getToIndex() ); - - assertTrue( range.nextPage() ); - assertEquals( 4, range.getFromIndex() ); - assertEquals( 8, range.getToIndex() ); - - assertTrue( range.nextPage() ); - assertEquals( 8, range.getFromIndex() ); - assertEquals( 11, range.getToIndex() ); - - assertFalse( range.nextPage() ); - } - - @Test - public void testGetPages() - { - PageRange range = new PageRange( 12 ).setPageSize( 5 ); - - List pages = range.getPages(); - - assertEquals( 3, pages.size() ); - assertEquals( 0, pages.get( 0 )[0] ); - assertEquals( 5, pages.get( 0 )[1] ); - assertEquals( 5, pages.get( 1 )[0] ); - assertEquals( 10, pages.get( 1 )[1] ); - assertEquals( 10, pages.get( 2 )[0] ); - assertEquals( 12, pages.get( 2 )[1] ); - } -} === removed file 'dhis-2/dhis-support/dhis-support-system/src/test/java/org/hisp/dhis/system/util/PaginatedListTest.java' --- dhis-2/dhis-support/dhis-support-system/src/test/java/org/hisp/dhis/system/util/PaginatedListTest.java 2015-06-15 13:44:20 +0000 +++ dhis-2/dhis-support/dhis-support-system/src/test/java/org/hisp/dhis/system/util/PaginatedListTest.java 1970-01-01 00:00:00 +0000 @@ -1,160 +0,0 @@ -package org.hisp.dhis.system.util; - -/* - * Copyright (c) 2004-2015, University of Oslo - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * - * Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * Neither the name of the HISP project nor the names of its contributors may - * be used to endorse or promote products derived from this software without - * specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR - * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON - * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertTrue; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; - -import org.hisp.dhis.commons.collection.PaginatedList; -import org.junit.Test; - -/** - * @author Lars Helge Overland - */ -public class PaginatedListTest -{ - @Test - public void testNextPage() - { - PaginatedList list = new PaginatedList<>( Arrays.asList( "A", "B", "C" ) ).setPageSize( 2 ); - - List page = list.nextPage(); - - assertNotNull( page ); - assertEquals( 2, page.size() ); - assertTrue( page.contains( "A" ) ); - assertTrue( page.contains( "B" ) ); - - page = list.nextPage(); - - assertNotNull( page ); - assertEquals( 1, page.size() ); - assertTrue( page.contains( "C" ) ); - - page = list.nextPage(); - - assertNull( page ); - } - - @Test - public void testGetPageEmpty() - { - PaginatedList list = new PaginatedList<>( new ArrayList() ).setPageSize( 2 ); - - List page = list.nextPage(); - - assertNull( page ); - } - - @Test - public void testPageCount() - { - PaginatedList list = new PaginatedList<>( Arrays.asList( "A", "B", "C" ) ).setPageSize( 2 ); - - assertEquals( 2, list.pageCount() ); - - list = new PaginatedList<>( Arrays.asList( "A", "B", "C", "D" ) ).setPageSize( 2 ); - - assertEquals( 2, list.pageCount() ); - - list = new PaginatedList<>( Arrays.asList( "A", "B", "C", "D", "E" ) ).setPageSize( 2 ); - - assertEquals( 3, list.pageCount() ); - } - - @Test - public void testReset() - { - PaginatedList list = new PaginatedList<>( Arrays.asList( "A", "B", "C" ) ).setPageSize( 2 ); - - assertTrue( list.nextPage().contains( "A" ) ); - - list.reset(); - - assertTrue( list.nextPage().contains( "A" ) ); - } - - @Test - public void testSetNumberOfPages() - { - PaginatedList list = new PaginatedList<>( Arrays.asList( "A", "B", "C", "D", "E" ) ).setNumberOfPages( 3 ); - - assertEquals( 3, list.pageCount() ); - - assertEquals( 2, list.nextPage().size() ); - } - - @Test - public void testNextPageNumberOfPages() - { - PaginatedList list = new PaginatedList<>( Arrays.asList( "A", "B", "C", "D", "E" ) ).setNumberOfPages( 2 ); - - List page = list.nextPage(); - - assertNotNull( page ); - assertEquals( 3, page.size() ); - assertTrue( page.contains( "A" ) ); - assertTrue( page.contains( "B" ) ); - assertTrue( page.contains( "C" ) ); - - page = list.nextPage(); - - assertNotNull( page ); - assertEquals( 2, page.size() ); - assertTrue( page.contains( "D" ) ); - assertTrue( page.contains( "E" ) ); - - page = list.nextPage(); - - assertNull( page ); - } - - @Test - public void testGetPages() - { - PaginatedList list = new PaginatedList<>( Arrays.asList( "A", "B", "C", "D", "E" ) ).setPageSize( 2 ); - - List> pages = list.getPages(); - - assertNotNull( pages ); - assertEquals( 3, pages.size() ); - - List page = pages.get( 0 ); - assertNotNull( page ); - assertEquals( 2, page.size() ); - assertTrue( page.contains( "A" ) ); - assertTrue( page.contains( "B" ) ); - } -} === removed file 'dhis-2/dhis-support/dhis-support-system/src/test/java/org/hisp/dhis/system/util/TextUtilsTest.java' --- dhis-2/dhis-support/dhis-support-system/src/test/java/org/hisp/dhis/system/util/TextUtilsTest.java 2015-07-03 11:42:28 +0000 +++ dhis-2/dhis-support/dhis-support-system/src/test/java/org/hisp/dhis/system/util/TextUtilsTest.java 1970-01-01 00:00:00 +0000 @@ -1,134 +0,0 @@ -package org.hisp.dhis.system.util; - -/* - * Copyright (c) 2004-2015, University of Oslo - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * - * Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * Neither the name of the HISP project nor the names of its contributors may - * be used to endorse or promote products derived from this software without - * specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR - * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON - * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNull; -import static org.hisp.dhis.commons.util.TextUtils.*; - -import java.util.ArrayList; -import java.util.Arrays; - -import org.hisp.dhis.commons.util.TextUtils; -import org.junit.Test; - -/** - * @author Lars Helge Overland - */ -public class TextUtilsTest -{ - private static final String STRING = "abcdefghij"; - - @Test - public void testHtmlLinks() - { - assertEquals( "http://dhis2.org", htmlLinks( "http://dhis2.org" ) ); - assertEquals( "https://dhis2.org", htmlLinks( "https://dhis2.org" ) ); - assertEquals( "www.dhis2.org", htmlLinks( "www.dhis2.org" ) ); - assertEquals( "Navigate to http://dhis2.org or www.dhis2.com to read more.", - htmlLinks( "Navigate to http://dhis2.org or www.dhis2.com to read more." ) ); - } - - @Test - public void testSubString() - { - assertEquals( "abcdefghij", subString( STRING, 0, 10 ) ); - assertEquals( "cdef", subString( STRING, 2, 4 ) ); - assertEquals( "ghij", subString( STRING, 6, 4 ) ); - assertEquals( "ghij", subString( STRING, 6, 6 ) ); - assertEquals( "", subString( STRING, 11, 3 ) ); - assertEquals( "j", subString( STRING, 9, 1 ) ); - assertEquals( "", subString( STRING, 4, 0 ) ); - } - - @Test - public void testTrim() - { - assertEquals( "abcdefgh", trimEnd( "abcdefghijkl", 4 ) ); - } - - @Test - public void testGetTokens() - { - assertEquals( new ArrayList<>( Arrays.asList( "John", "Doe", "Main", "Road", "25" ) ), TextUtils.getTokens( "John Doe Main Road 25" ) ); - assertEquals( new ArrayList<>( Arrays.asList( "Ted,Johnson", "Upper-Road", "45" ) ), TextUtils.getTokens( "Ted,Johnson Upper-Road 45" ) ); - } - - @Test - public void testRemoveLastOr() - { - assertEquals( null, TextUtils.removeLastOr( null ) ); - assertEquals( "", TextUtils.removeLastOr( "" ) ); - assertEquals( "or name='tom' or name='john' ", TextUtils.removeLastOr( "or name='tom' or name='john' or" ) ); - assertEquals( "or name='tom' or name='john' ", TextUtils.removeLastOr( "or name='tom' or name='john' or " ) ); - assertEquals( "or name='tom' or name='john' ", TextUtils.removeLastOr( "or name='tom' or name='john' or " ) ); - } - - @Test - public void testRemoveLastAnd() - { - assertEquals( null, TextUtils.removeLastAnd( null ) ); - assertEquals( "", TextUtils.removeLastAnd( "" ) ); - assertEquals( "and name='tom' and name='john' ", TextUtils.removeLastAnd( "and name='tom' and name='john' and" ) ); - assertEquals( "and name='tom' and name='john' ", TextUtils.removeLastAnd( "and name='tom' and name='john' and " ) ); - assertEquals( "and name='tom' and name='john' ", TextUtils.removeLastAnd( "and name='tom' and name='john' and " ) ); - } - - @Test - public void testRemoveLastComma() - { - assertEquals( null, TextUtils.removeLastComma( null ) ); - assertEquals( "", TextUtils.removeLastComma( "" ) ); - assertEquals( "tom,john", TextUtils.removeLastComma( "tom,john," ) ); - assertEquals( "tom, john", TextUtils.removeLastComma( "tom, john, " ) ); - assertEquals( "tom, john", TextUtils.removeLastComma( "tom, john, " ) ); - } - - @Test - public void testJoinReplaceNull() - { - assertEquals( "green-red-blue", TextUtils.join( Arrays.asList( "green", "red", "blue" ), "-", "[n/a]" ) ); - assertEquals( "green-[n/a]-blue", TextUtils.join( Arrays.asList( "green", null, "blue" ), "-", "[n/a]" ) ); - assertEquals( "green-red-[n/a]", TextUtils.join( Arrays.asList( "green", "red", null ), "-", "[n/a]" ) ); - assertEquals( "greenred[n/a]", TextUtils.join( Arrays.asList( "green", "red", null ), null, "[n/a]" ) ); - assertEquals( "greenred", TextUtils.join( Arrays.asList( "green", "red", null ), null, null ) ); - } - - @Test - public void testSplitSafe() - { - assertEquals( "green", TextUtils.splitSafe( "red-green-blue", "-", 1 ) ); - assertEquals( "green", TextUtils.splitSafe( "red.green.blue", "\\.", 1 ) ); - assertEquals( "red", TextUtils.splitSafe( "red-green-blue", "-", 0 ) ); - assertEquals( "blue", TextUtils.splitSafe( "red-green-blue", "-", 2 ) ); - assertNull( TextUtils.splitSafe( "red-green-blue", "-", 3 ) ); - assertNull( TextUtils.splitSafe( "red-green-blue", "-", -2 ) ); - assertNull( TextUtils.splitSafe( "red-green-blue-", "-", 3 ) ); - } -} === modified file 'dhis-2/dhis-web/dhis-web-api-mobile/pom.xml' --- dhis-2/dhis-web/dhis-web-api-mobile/pom.xml 2015-07-20 02:01:37 +0000 +++ dhis-2/dhis-web/dhis-web-api-mobile/pom.xml 2015-09-25 12:29:08 +0000 @@ -37,6 +37,15 @@ com.jcraft jzlib + + + + + junit + junit + test + +