diff --git a/org.springframework.testsuite/src/test/java/org/springframework/web/util/TagUtilsTests.java b/org.springframework.testsuite/src/test/java/org/springframework/web/util/TagUtilsTests.java deleted file mode 100644 index 086cf64fad8..00000000000 --- a/org.springframework.testsuite/src/test/java/org/springframework/web/util/TagUtilsTests.java +++ /dev/null @@ -1,162 +0,0 @@ -/* - * Copyright 2002-2006 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.web.util; - -import junit.framework.TestCase; -import org.springframework.test.AssertThrows; - -import javax.servlet.jsp.PageContext; -import javax.servlet.jsp.tagext.Tag; -import javax.servlet.jsp.tagext.TagSupport; - -/** - * Unit tests for the {@link TagUtils} class. - * - * @author Alef Arendsen - * @author Rick Evans - */ -public final class TagUtilsTests extends TestCase { - - public void testGetScopeSunnyDay() { - assertEquals(TagUtils.SCOPE_PAGE, "page"); - assertEquals(TagUtils.SCOPE_APPLICATION, "application"); - assertEquals(TagUtils.SCOPE_SESSION, "session"); - assertEquals(TagUtils.SCOPE_REQUEST, "request"); - - assertEquals(TagUtils.getScope("page"), PageContext.PAGE_SCOPE); - assertEquals(TagUtils.getScope("request"), PageContext.REQUEST_SCOPE); - assertEquals(TagUtils.getScope("session"), PageContext.SESSION_SCOPE); - assertEquals(TagUtils.getScope("application"), PageContext.APPLICATION_SCOPE); - - // non-existent scope - assertEquals("TagUtils.getScope(..) with a non-existent scope argument must " + - "just return the default scope (PageContext.PAGE_SCOPE).", - TagUtils.getScope("bla"), PageContext.PAGE_SCOPE); - } - - public void testGetScopeWithNullScopeArgument() { - new AssertThrows(IllegalArgumentException.class) { - public void test() throws Exception { - TagUtils.getScope(null); - } - }.runTest(); - } - - public void testHasAncestorOfTypeWhereAncestorTagIsNotATagType() throws Exception { - new AssertThrows(IllegalArgumentException.class) { - public void test() throws Exception { - assertFalse(TagUtils.hasAncestorOfType( - new TagSupport(), String.class)); - } - }.runTest(); - } - - public void testHasAncestorOfTypeWithNullTagArgument() throws Exception { - new AssertThrows(IllegalArgumentException.class) { - public void test() throws Exception { - assertFalse(TagUtils.hasAncestorOfType(null, TagSupport.class)); - } - }.runTest(); - } - - public void testHasAncestorOfTypeWithNullAncestorTagClassArgument() throws Exception { - new AssertThrows(IllegalArgumentException.class) { - public void test() throws Exception { - assertFalse(TagUtils.hasAncestorOfType(new TagSupport(), null)); - } - }.runTest(); - } - - public void testHasAncestorOfTypeTrueScenario() throws Exception { - Tag a = new TagA(); - Tag b = new TagB(); - Tag c = new TagC(); - - a.setParent(b); - b.setParent(c); - - assertTrue(TagUtils.hasAncestorOfType(a, TagC.class)); - } - - public void testHasAncestorOfTypeFalseScenario() throws Exception { - Tag a = new TagA(); - Tag b = new TagB(); - Tag anotherB = new TagB(); - - a.setParent(b); - b.setParent(anotherB); - - assertFalse(TagUtils.hasAncestorOfType(a, TagC.class)); - } - - public void testHasAncestorOfTypeWhenTagHasNoParent() throws Exception { - assertFalse(TagUtils.hasAncestorOfType(new TagA(), TagC.class)); - } - - public void testAssertHasAncestorOfTypeWithNullTagName() throws Exception { - new AssertThrows(IllegalArgumentException.class) { - public void test() throws Exception { - TagUtils.assertHasAncestorOfType(new TagA(), TagC.class, null, "c"); - } - }.runTest(); - } - - public void testAssertHasAncestorOfTypeWithNullAncestorTagName() throws Exception { - new AssertThrows(IllegalArgumentException.class) { - public void test() throws Exception { - TagUtils.assertHasAncestorOfType(new TagA(), TagC.class, "a", null); - } - }.runTest(); - } - - public void testAssertHasAncestorOfTypeThrowsExceptionOnFail() throws Exception { - new AssertThrows(IllegalStateException.class) { - public void test() throws Exception { - Tag a = new TagA(); - Tag b = new TagB(); - Tag anotherB = new TagB(); - - a.setParent(b); - b.setParent(anotherB); - - TagUtils.assertHasAncestorOfType(a, TagC.class, "a", "c"); - } - }.runTest(); - } - - public void testAssertHasAncestorOfTypeDoesNotThrowExceptionOnPass() throws Exception { - Tag a = new TagA(); - Tag b = new TagB(); - Tag c = new TagC(); - - a.setParent(b); - b.setParent(c); - - TagUtils.assertHasAncestorOfType(a, TagC.class, "a", "c"); - } - - - private static final class TagA extends TagSupport { - } - - private static final class TagB extends TagSupport { - } - - private static final class TagC extends TagSupport { - } - -} diff --git a/org.springframework.testsuite/src/test/java/org/springframework/web/util/HtmlCharacterEntityReferencesTests.java b/org.springframework.web/src/test/java/org/springframework/web/util/HtmlCharacterEntityReferencesTests.java similarity index 100% rename from org.springframework.testsuite/src/test/java/org/springframework/web/util/HtmlCharacterEntityReferencesTests.java rename to org.springframework.web/src/test/java/org/springframework/web/util/HtmlCharacterEntityReferencesTests.java diff --git a/org.springframework.testsuite/src/test/java/org/springframework/web/util/HtmlUtilsTests.java b/org.springframework.web/src/test/java/org/springframework/web/util/HtmlUtilsTests.java similarity index 100% rename from org.springframework.testsuite/src/test/java/org/springframework/web/util/HtmlUtilsTests.java rename to org.springframework.web/src/test/java/org/springframework/web/util/HtmlUtilsTests.java diff --git a/org.springframework.web/src/test/java/org/springframework/web/util/TagUtilsTests.java b/org.springframework.web/src/test/java/org/springframework/web/util/TagUtilsTests.java new file mode 100644 index 00000000000..9484a2c514b --- /dev/null +++ b/org.springframework.web/src/test/java/org/springframework/web/util/TagUtilsTests.java @@ -0,0 +1,148 @@ +/* + * Copyright 2002-2006 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.web.util; + +import javax.servlet.jsp.PageContext; +import javax.servlet.jsp.tagext.Tag; +import javax.servlet.jsp.tagext.TagSupport; + +import static org.junit.Assert.*; +import org.junit.Test; + + +/** + * Unit tests for the {@link TagUtils} class. + * + * @author Alef Arendsen + * @author Rick Evans + */ +public final class TagUtilsTests { + + @Test + public void getScopeSunnyDay() { + assertEquals(TagUtils.SCOPE_PAGE, "page"); + assertEquals(TagUtils.SCOPE_APPLICATION, "application"); + assertEquals(TagUtils.SCOPE_SESSION, "session"); + assertEquals(TagUtils.SCOPE_REQUEST, "request"); + + assertEquals(PageContext.PAGE_SCOPE, TagUtils.getScope("page")); + assertEquals(PageContext.REQUEST_SCOPE, TagUtils.getScope("request")); + assertEquals(PageContext.SESSION_SCOPE, TagUtils.getScope("session")); + assertEquals(PageContext.APPLICATION_SCOPE, TagUtils.getScope("application")); + + // non-existent scope + assertEquals("TagUtils.getScope(..) with a non-existent scope argument must " + + "just return the default scope (PageContext.PAGE_SCOPE).", PageContext.PAGE_SCOPE, + TagUtils.getScope("bla")); + } + + @Test(expected = IllegalArgumentException.class) + public void getScopeWithNullScopeArgument() { + TagUtils.getScope(null); + } + + @Test(expected = IllegalArgumentException.class) + public void hasAncestorOfTypeWhereAncestorTagIsNotATagType() throws Exception { + assertFalse(TagUtils.hasAncestorOfType(new TagSupport(), String.class)); + } + + @Test(expected = IllegalArgumentException.class) + public void hasAncestorOfTypeWithNullTagArgument() throws Exception { + assertFalse(TagUtils.hasAncestorOfType(null, TagSupport.class)); + } + + @Test(expected = IllegalArgumentException.class) + public void hasAncestorOfTypeWithNullAncestorTagClassArgument() throws Exception { + assertFalse(TagUtils.hasAncestorOfType(new TagSupport(), null)); + } + + @Test + public void hasAncestorOfTypeTrueScenario() throws Exception { + Tag a = new TagA(); + Tag b = new TagB(); + Tag c = new TagC(); + + a.setParent(b); + b.setParent(c); + + assertTrue(TagUtils.hasAncestorOfType(a, TagC.class)); + } + + @Test + public void hasAncestorOfTypeFalseScenario() throws Exception { + Tag a = new TagA(); + Tag b = new TagB(); + Tag anotherB = new TagB(); + + a.setParent(b); + b.setParent(anotherB); + + assertFalse(TagUtils.hasAncestorOfType(a, TagC.class)); + } + + @Test + public void hasAncestorOfTypeWhenTagHasNoParent() throws Exception { + assertFalse(TagUtils.hasAncestorOfType(new TagA(), TagC.class)); + } + + @Test(expected = IllegalArgumentException.class) + public void assertHasAncestorOfTypeWithNullTagName() throws Exception { + TagUtils.assertHasAncestorOfType(new TagA(), TagC.class, null, "c"); + } + + @Test(expected = IllegalArgumentException.class) + public void assertHasAncestorOfTypeWithNullAncestorTagName() throws Exception { + TagUtils.assertHasAncestorOfType(new TagA(), TagC.class, "a", null); + } + + @Test(expected = IllegalStateException.class) + public void assertHasAncestorOfTypeThrowsExceptionOnFail() throws Exception { + Tag a = new TagA(); + Tag b = new TagB(); + Tag anotherB = new TagB(); + + a.setParent(b); + b.setParent(anotherB); + + TagUtils.assertHasAncestorOfType(a, TagC.class, "a", "c"); + } + + @Test + public void testAssertHasAncestorOfTypeDoesNotThrowExceptionOnPass() throws Exception { + Tag a = new TagA(); + Tag b = new TagB(); + Tag c = new TagC(); + + a.setParent(b); + b.setParent(c); + + TagUtils.assertHasAncestorOfType(a, TagC.class, "a", "c"); + } + + private static final class TagA extends TagSupport { + + } + + private static final class TagB extends TagSupport { + + } + + private static final class TagC extends TagSupport { + + } + +} diff --git a/org.springframework.testsuite/src/test/java/org/springframework/web/util/WebUtilsTests.java b/org.springframework.web/src/test/java/org/springframework/web/util/WebUtilsTests.java similarity index 96% rename from org.springframework.testsuite/src/test/java/org/springframework/web/util/WebUtilsTests.java rename to org.springframework.web/src/test/java/org/springframework/web/util/WebUtilsTests.java index d98d1ae2ac2..a3e8cea4b1b 100644 --- a/org.springframework.testsuite/src/test/java/org/springframework/web/util/WebUtilsTests.java +++ b/org.springframework.web/src/test/java/org/springframework/web/util/WebUtilsTests.java @@ -27,7 +27,7 @@ import junit.framework.TestCase; public class WebUtilsTests extends TestCase { public void testFindParameterValue() { - Map params = new HashMap(); + Map params = new HashMap(); params.put("myKey1", "myValue1"); params.put("myKey2_myValue2", "xxx"); params.put("myKey3_myValue3.x", "xxx"); diff --git a/org.springframework.web/src/test/resources/org/springframework/web/util/HtmlCharacterEntityReferences.dtd b/org.springframework.web/src/test/resources/org/springframework/web/util/HtmlCharacterEntityReferences.dtd new file mode 100644 index 00000000000..31aa2524bff --- /dev/null +++ b/org.springframework.web/src/test/resources/org/springframework/web/util/HtmlCharacterEntityReferences.dtd @@ -0,0 +1,523 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file