Author: bdelacretaz Date: Thu Apr 7 00:52:00 2005 New Revision: 160377 URL: http://svn.apache.org/viewcvs?view=rev&rev=160377 Log: patch 34294 applied: new HtmlUnit based tests, thanks to Alfred Nathaniel (forgot to svn add, here's the remaining new files)
Added: cocoon/branches/BRANCH_2_1_X/src/blocks/batik/test/htmlunit/ cocoon/branches/BRANCH_2_1_X/src/blocks/batik/test/htmlunit/org/ cocoon/branches/BRANCH_2_1_X/src/blocks/batik/test/htmlunit/org/apache/ cocoon/branches/BRANCH_2_1_X/src/blocks/batik/test/htmlunit/org/apache/cocoon/ cocoon/branches/BRANCH_2_1_X/src/blocks/batik/test/htmlunit/org/apache/cocoon/BatikSampleMimeTypesTestCase.java cocoon/branches/BRANCH_2_1_X/src/blocks/webdav/test/htmlunit/ cocoon/branches/BRANCH_2_1_X/src/blocks/webdav/test/htmlunit/org/ cocoon/branches/BRANCH_2_1_X/src/blocks/webdav/test/htmlunit/org/apache/ cocoon/branches/BRANCH_2_1_X/src/blocks/webdav/test/htmlunit/org/apache/cocoon/ cocoon/branches/BRANCH_2_1_X/src/blocks/webdav/test/htmlunit/org/apache/cocoon/WebdavDavmapTestCase.java cocoon/branches/BRANCH_2_1_X/src/blocks/webdav/test/htmlunit/org/apache/cocoon/WebdavStep3TestCase.java cocoon/branches/BRANCH_2_1_X/src/test/README.txt cocoon/branches/BRANCH_2_1_X/src/test/htmlunit/ cocoon/branches/BRANCH_2_1_X/src/test/htmlunit/org/ cocoon/branches/BRANCH_2_1_X/src/test/htmlunit/org/apache/ cocoon/branches/BRANCH_2_1_X/src/test/htmlunit/org/apache/cocoon/ cocoon/branches/BRANCH_2_1_X/src/test/htmlunit/org/apache/cocoon/Bug26186InternalRequestMemoryLeakTestCase.java cocoon/branches/BRANCH_2_1_X/src/test/htmlunit/org/apache/cocoon/Bug26571SendPageRedirectTestCase.java cocoon/branches/BRANCH_2_1_X/src/test/htmlunit/org/apache/cocoon/CalcTestCase.java cocoon/branches/BRANCH_2_1_X/src/test/htmlunit/org/apache/cocoon/FlowscriptDOMDumpTestCase.java cocoon/branches/BRANCH_2_1_X/src/test/htmlunit/org/apache/cocoon/FlowscriptRecursiveTestCase.java cocoon/branches/BRANCH_2_1_X/src/test/htmlunit/org/apache/cocoon/FlowscriptReloadTestCase.java cocoon/branches/BRANCH_2_1_X/src/test/htmlunit/org/apache/cocoon/HtmlUnitTestCase.java cocoon/branches/BRANCH_2_1_X/src/test/htmlunit/org/apache/cocoon/HttpClientResponse.java cocoon/branches/BRANCH_2_1_X/src/test/htmlunit/org/apache/cocoon/InternalRequestTestCase.java cocoon/branches/BRANCH_2_1_X/src/test/htmlunit/org/apache/cocoon/InternalSendPageTestCase.java cocoon/branches/BRANCH_2_1_X/src/test/htmlunit/org/apache/cocoon/ReaderMimeTypeTestCase.java cocoon/branches/BRANCH_2_1_X/src/test/htmlunit/org/apache/cocoon/RedirectTestCase.java cocoon/branches/BRANCH_2_1_X/src/test/htmlunit/org/apache/cocoon/SitemapReloadTestCase.java Added: cocoon/branches/BRANCH_2_1_X/src/blocks/batik/test/htmlunit/org/apache/cocoon/BatikSampleMimeTypesTestCase.java URL: http://svn.apache.org/viewcvs/cocoon/branches/BRANCH_2_1_X/src/blocks/batik/test/htmlunit/org/apache/cocoon/BatikSampleMimeTypesTestCase.java?view=auto&rev=160377 ============================================================================== --- cocoon/branches/BRANCH_2_1_X/src/blocks/batik/test/htmlunit/org/apache/cocoon/BatikSampleMimeTypesTestCase.java (added) +++ cocoon/branches/BRANCH_2_1_X/src/blocks/batik/test/htmlunit/org/apache/cocoon/BatikSampleMimeTypesTestCase.java Thu Apr 7 00:52:00 2005 @@ -0,0 +1,112 @@ +/* + * Copyright 2005 The Apache Software Foundation + * 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.apache.cocoon; + +/** + * Tests the basic functionality of the Batik samples by checking + * their content-type: if a sample gives an error instead of + * generating an image, its content-type will be text/html. + * + * @version $Id: $ + */ +public class BatikSampleMimeTypesTestCase + extends HtmlUnitTestCase +{ + public void testHelloSVG() + throws Exception + { + loadResponse("/samples/hello-world/hello.svg"); + assertEquals("Content type", "image/svg+xml", response.getContentType()); + } + + public void testHelloJPEG() + throws Exception + { + loadResponse("/samples/blocks/batik/hello.jpeg"); + assertEquals("Content type", "image/jpeg", response.getContentType()); + } + + public void testHelloPNG() + throws Exception + { + loadResponse("/samples/blocks/batik/hello.png"); + assertEquals("Content type", "image/png", response.getContentType()); + } + + public void testLogoSVG() + throws Exception + { + loadResponse("/samples/blocks/batik/batikLogo.svg"); + assertEquals("Content type", "image/svg+xml", response.getContentType()); + } + + public void testLogoJPEG() + throws Exception + { + loadResponse("/samples/blocks/batik/batikLogo.jpeg"); + assertEquals("Content type", "image/jpeg", response.getContentType()); + } + + public void testLogoPNG() + throws Exception + { + loadResponse("/samples/blocks/batik/batikLogo.png"); + assertEquals("Content type", "image/png", response.getContentType()); + } + + public void testHenrySVG() + throws Exception + { + loadResponse("/samples/blocks/batik/henryV.svg"); + assertEquals("Content type", "image/svg+xml", response.getContentType()); + } + + public void testHenryJPEG() + throws Exception + { + loadResponse("/samples/blocks/batik/henryV.jpeg"); + assertEquals("Content type", "image/jpeg", response.getContentType()); + } + + public void testHenryPNG() + throws Exception + { + loadResponse("/samples/blocks/batik/henryV.png"); + assertEquals("Content type", "image/png", response.getContentType()); + } + + public void testAnneSVG() + throws Exception + { + loadResponse("/samples/blocks/batik/anne.svg"); + assertEquals("Content type", "image/svg+xml", response.getContentType()); + } + + public void testAnneJPEG() + throws Exception + { + loadResponse("/samples/blocks/batik/anne.jpeg"); + assertEquals("Content type", "image/jpeg", response.getContentType()); + } + + public void testAnnePNG() + throws Exception + { + loadResponse("/samples/blocks/batik/anne.png"); + assertEquals("Content type", "image/png", response.getContentType()); + } +} Added: cocoon/branches/BRANCH_2_1_X/src/blocks/webdav/test/htmlunit/org/apache/cocoon/WebdavDavmapTestCase.java URL: http://svn.apache.org/viewcvs/cocoon/branches/BRANCH_2_1_X/src/blocks/webdav/test/htmlunit/org/apache/cocoon/WebdavDavmapTestCase.java?view=auto&rev=160377 ============================================================================== --- cocoon/branches/BRANCH_2_1_X/src/blocks/webdav/test/htmlunit/org/apache/cocoon/WebdavDavmapTestCase.java (added) +++ cocoon/branches/BRANCH_2_1_X/src/blocks/webdav/test/htmlunit/org/apache/cocoon/WebdavDavmapTestCase.java Thu Apr 7 00:52:00 2005 @@ -0,0 +1,58 @@ +/* + * Copyright 2005 The Apache Software Foundation + * 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.apache.cocoon; + +/** + * Check davmap samples. + * + * @version $Id: $ + */ +public class WebdavDavmapTestCase + extends HtmlUnitTestCase +{ + static final String pageurl = "/samples/blocks/webdav/davmap/"; + static final String davmapTitle = "repo"; + + static final String contentB = + "<page>\n"+ + "<title>Page 2</title>\n"+ + "<content>\n"+ + " <para>Paragraph 1</para>\n"+ + " <para>Paragraph 2</para>\n"+ + "</content>\n"+ + "</page>\n"; + + public void testDavmapTitle() + throws Exception + { + loadHtmlPage(pageurl+"repo/"); + assertXPath("/html/head/title", davmapTitle); + } + + public void testPutReadDelete() + throws Exception + { + loadPutResponse(pageurl+"repo/contentB.xml", contentB); + assertEquals("Status code", 201, response.getStatusCode()); + + loadXmlPage(pageurl+"repo/contentB.xml"); + assertXPath("/page/title", "Page 2"); + + loadDeleteResponse(pageurl+"repo/contentB.xml"); + assertEquals("Status code", 200, response.getStatusCode()); + } +} Added: cocoon/branches/BRANCH_2_1_X/src/blocks/webdav/test/htmlunit/org/apache/cocoon/WebdavStep3TestCase.java URL: http://svn.apache.org/viewcvs/cocoon/branches/BRANCH_2_1_X/src/blocks/webdav/test/htmlunit/org/apache/cocoon/WebdavStep3TestCase.java?view=auto&rev=160377 ============================================================================== --- cocoon/branches/BRANCH_2_1_X/src/blocks/webdav/test/htmlunit/org/apache/cocoon/WebdavStep3TestCase.java (added) +++ cocoon/branches/BRANCH_2_1_X/src/blocks/webdav/test/htmlunit/org/apache/cocoon/WebdavStep3TestCase.java Thu Apr 7 00:52:00 2005 @@ -0,0 +1,109 @@ +/* + * Copyright 2005 The Apache Software Foundation + * 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.apache.cocoon; + +import java.net.URLEncoder; + +/** + * Check basic TraversableGenerator functionality. + * + * @version $Id: $ + */ +public class WebdavStep3TestCase + extends HtmlUnitTestCase +{ + static final String pageurl = "/samples/blocks/webdav/"; + /** + * Testing basic TraversableGenerator functionality. + */ + public void testTraversableGenerator() + throws Exception + { + loadXmlPage(pageurl+"step1/repo/"); + addNamespace("collection", "http://apache.org/cocoon/collection/1.0"); + + // FIXME: why XPath namespaces not working? + + final String xpathName = "/collection:collection/collection:resource/@name"; + String name = evalXPath(xpathName); + if( name.length() != 0 ) { + logger.info("Good, XPath namespaces finally working"); + assertXPath(xpathName, "contentA.xml"); + } + else { + logger.info("Damnit, XPath namespaces still not working"); + assertXPath("/*[name(.)='collection:collection']/*[name(.)='collection:resource']/@name", "contentA.xml"); + } + } + + public void testContentB() + throws Exception + { + final String step3url = pageurl+"step3/repo/dir2/contentB.xml"; + + final String xpathTitle = "/html/body/form/p/[EMAIL PROTECTED]'title']/@value"; + final String xpathPara1 = "(/html/body/form/p/textarea)[1]"; + final String xpathPara2 = "(/html/body/form/p/textarea)[2]"; + final String xpathAction = "/html/body/form/@action"; + + final String xpathSuccess = "/page/sourceResult/execution"; + final String valueSuccess = "success"; + + final String oldTitle = "Content B"; + final String oldPara1 = "First Paragraph"; + final String oldPara2 = "Second Paragraph"; + + final String newTitle = "Title changed by WebdavStep3TestCase"; + final String newPara1 = "test1"; + final String newPara2 = "test2"; + + // Check contents of contentB.xml + + loadHtmlPage(step3url); + //assertXPath(xpathTitle, oldTitle); + //assertXPath(xpathPara1, oldPara1); + //assertXPath(xpathPara2, oldPara2); + String action1 = evalXPath(xpathAction); + + // Change contents of contentB.xml + + loadXmlPage(action1+"?title="+URLEncoder.encode(newTitle)+"¶="+URLEncoder.encode(newPara1)+"¶="+URLEncoder.encode(newPara2)); + assertXPath(xpathSuccess, valueSuccess); + + // Check changes + + Thread.sleep(1000); + loadHtmlPage(step3url); + assertXPath(xpathTitle, newTitle); + assertXPath(xpathPara1, newPara1); + assertXPath(xpathPara2, newPara2); + String action2 = evalXPath(xpathAction); + + // Undo changes + + loadXmlPage(action2+"?title="+URLEncoder.encode(oldTitle)+"¶="+URLEncoder.encode(oldPara1)+"¶="+URLEncoder.encode(oldPara2)); + assertXPath(xpathSuccess, valueSuccess); + + // Check success of undo + + Thread.sleep(1000); + loadHtmlPage(step3url); + assertXPath(xpathTitle, oldTitle); + assertXPath(xpathPara1, oldPara1); + assertXPath(xpathPara2, oldPara2); + } +} Added: cocoon/branches/BRANCH_2_1_X/src/test/README.txt URL: http://svn.apache.org/viewcvs/cocoon/branches/BRANCH_2_1_X/src/test/README.txt?view=auto&rev=160377 ============================================================================== --- cocoon/branches/BRANCH_2_1_X/src/test/README.txt (added) +++ cocoon/branches/BRANCH_2_1_X/src/test/README.txt Thu Apr 7 00:52:00 2005 @@ -0,0 +1,23 @@ +The anteater project has been retired. Please write new tests in the htmlunit +framework. See src/test/htmlunit/org/apache/cocoon/HtmlUnitTestCase.java +for details. + +NB this concerns only for tests on the reponse of a running Cocoon server. +Unit tests for Cocoon classes are as ever written as JUnit tests. + +To run htmlunit tests you have to download htmlunit 1.5 from +http://sourceforge.net/project/showfiles.php?group_id=47038. +Unpack it into a convenient directory and set the path in your +local.build.properties, for example: + + htmlunit.home = /my/htmlunit-1.5 + +Then build Cocoon, start the server, and run the tests: + + build.sh webapp + cocoon.sh servlet + build.sh htmlunit-tests + +With htmlunit-1.5 the test RedirectTestCase.testSendStatus fails with an NPE. +This is already fixed in CVS. For release information, see +https://sourceforge.net/tracker/?func=detail&atid=448268&aid=1166652&group_id=47038 Added: cocoon/branches/BRANCH_2_1_X/src/test/htmlunit/org/apache/cocoon/Bug26186InternalRequestMemoryLeakTestCase.java URL: http://svn.apache.org/viewcvs/cocoon/branches/BRANCH_2_1_X/src/test/htmlunit/org/apache/cocoon/Bug26186InternalRequestMemoryLeakTestCase.java?view=auto&rev=160377 ============================================================================== --- cocoon/branches/BRANCH_2_1_X/src/test/htmlunit/org/apache/cocoon/Bug26186InternalRequestMemoryLeakTestCase.java (added) +++ cocoon/branches/BRANCH_2_1_X/src/test/htmlunit/org/apache/cocoon/Bug26186InternalRequestMemoryLeakTestCase.java Thu Apr 7 00:52:00 2005 @@ -0,0 +1,46 @@ +/* + * Copyright 2005 The Apache Software Foundation + * 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.apache.cocoon; + +/** + * HtmlUnit TestCase for memory leak in internal requests (Bugzilla #26186). + * + * @version $Id: $ + */ +public class Bug26186InternalRequestMemoryLeakTestCase + extends HtmlUnitTestCase +{ + static final String pageurl = "/samples/blocks/xsp/java/resolver"; + + public void testMemoryLeak() + throws Exception + { + final int iterations = Integer.parseInt(System.getProperty("htmlunit.test.Bug26186InternalRequestMemoryLeak.iterations")); + + final String phrase = "An XSP Page using a source"; + for( int i = 0; i < iterations; i++ ) { + loadResponse(pageurl); + assertEquals("Status code", 200, response.getStatusCode()); + assertTrue("Content should contain: "+phrase, + response.getContentAsString().indexOf(phrase) != -1); + + if( (i+1)%100 == 0 ) { + logger.info("Memory leak checking "+(i+1)+" of "+iterations+" iterations"); + } + } + } +} Added: cocoon/branches/BRANCH_2_1_X/src/test/htmlunit/org/apache/cocoon/Bug26571SendPageRedirectTestCase.java URL: http://svn.apache.org/viewcvs/cocoon/branches/BRANCH_2_1_X/src/test/htmlunit/org/apache/cocoon/Bug26571SendPageRedirectTestCase.java?view=auto&rev=160377 ============================================================================== --- cocoon/branches/BRANCH_2_1_X/src/test/htmlunit/org/apache/cocoon/Bug26571SendPageRedirectTestCase.java (added) +++ cocoon/branches/BRANCH_2_1_X/src/test/htmlunit/org/apache/cocoon/Bug26571SendPageRedirectTestCase.java Thu Apr 7 00:52:00 2005 @@ -0,0 +1,42 @@ +/* + * Copyright 2005 The Apache Software Foundation + * 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.apache.cocoon; + +/** + * HtmlUnit TestCase for page redirection. + * + * @version $Id: $ + */ +public class Bug26571SendPageRedirectTestCase + extends HtmlUnitTestCase +{ + static final String pageurl = "/samples/test/sendpage-redirect/"; + + public void testSendPageRedirectGood() + throws Exception + { + loadResponse(pageurl+"test-good"); + assertEquals("Status code match", 302, response.getStatusCode()); + } + + public void testSendPageRedirectBad() + throws Exception + { + loadResponse(pageurl+"test-bad"); + assertEquals("Status code match", 302, response.getStatusCode()); + } +} Added: cocoon/branches/BRANCH_2_1_X/src/test/htmlunit/org/apache/cocoon/CalcTestCase.java URL: http://svn.apache.org/viewcvs/cocoon/branches/BRANCH_2_1_X/src/test/htmlunit/org/apache/cocoon/CalcTestCase.java?view=auto&rev=160377 ============================================================================== --- cocoon/branches/BRANCH_2_1_X/src/test/htmlunit/org/apache/cocoon/CalcTestCase.java (added) +++ cocoon/branches/BRANCH_2_1_X/src/test/htmlunit/org/apache/cocoon/CalcTestCase.java Thu Apr 7 00:52:00 2005 @@ -0,0 +1,67 @@ +/* + * Copyright 2005 The Apache Software Foundation + * 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.apache.cocoon; + +/** + * Testcase to simulate the behavior of a user that opens a browser, starts + * the calculator example, and goes back in the processing several times. + * + * @version $Id: $ + */ +public class CalcTestCase + extends HtmlUnitTestCase +{ + final String pageurl = "/samples/flow/jxcalc/"; + final String submitXPath = "html/body//form/@action"; + final String resultXPath = "html/body//form/p[contains(text(),'Result')]/strong"; + + public void testCalc() + throws Exception + { + loadHtmlPage(pageurl); + final String cont1 = evalXPath(submitXPath); + assertNotNull("cont1", cont1); + + loadHtmlPage(pageurl+cont1+"?a=1"); + final String cont2 = evalXPath(submitXPath); + assertNotNull("cont2", cont2); + + loadHtmlPage(pageurl+cont2+"?b=2"); + final String cont3 = evalXPath(submitXPath); + assertNotNull("cont3", cont3); + + loadHtmlPage(pageurl+cont3+"?operator=plus"); + final String result1 = evalXPath(resultXPath); + assertEquals("result1", "3.0", result1); + + // Simulate going back in the browser + + loadHtmlPage(pageurl+cont2+"?b=4"); + final String cont4 = evalXPath(submitXPath); + assertNotNull("cont4", cont4); + + loadHtmlPage(pageurl+cont4+"?operator=minus"); + final String result2 = evalXPath(resultXPath); + assertEquals("result2", "-3.0", result2); + + // Simulate going back again in the browser + + loadHtmlPage(pageurl+cont4+"?operator=divide"); + final String result3 = evalXPath(resultXPath); + assertEquals("result3", "0.25", result3); + } +} Added: cocoon/branches/BRANCH_2_1_X/src/test/htmlunit/org/apache/cocoon/FlowscriptDOMDumpTestCase.java URL: http://svn.apache.org/viewcvs/cocoon/branches/BRANCH_2_1_X/src/test/htmlunit/org/apache/cocoon/FlowscriptDOMDumpTestCase.java?view=auto&rev=160377 ============================================================================== --- cocoon/branches/BRANCH_2_1_X/src/test/htmlunit/org/apache/cocoon/FlowscriptDOMDumpTestCase.java (added) +++ cocoon/branches/BRANCH_2_1_X/src/test/htmlunit/org/apache/cocoon/FlowscriptDOMDumpTestCase.java Thu Apr 7 00:52:00 2005 @@ -0,0 +1,56 @@ +/* + * Copyright 2005 The Apache Software Foundation + * 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.apache.cocoon; + +/** + * Check various ways of dumping DOM objects in Flowscript (bugzilla 29381). + * + * @version $Id: $ + */ +public class FlowscriptDOMDumpTestCase + extends HtmlUnitTestCase +{ + final String pageurl = "/samples/test/flowscript-dom-dump/"; + + /** + * Check dump without XSLT transform. + */ + public void testDOMDump() + throws Exception + { + loadXmlPage(pageurl+"dom-dump"); + assertEquals("Content-type", "text/xml", response.getContentType()); + + assertXPath("//dump-without-star/root/child", "childText"); + assertXPath("//dump-with-star/root/child", "childText"); + } + + /** + * Check dump with XSLT transform. + */ + public void testDOMDumpXSLT() + throws Exception + { + loadXmlPage(pageurl+"dom-dump-xslt"); + assertEquals("Content-type", "text/xml", response.getContentType()); + + assertXPath("//dump-without-star/root/@test-transform", "true"); + assertXPath("//dump-without-star/root/child", "childText"); + assertXPath("//dump-with-star/root/@test-transform", "true"); + assertXPath("//dump-with-star/root/child", "childText"); + } +} Added: cocoon/branches/BRANCH_2_1_X/src/test/htmlunit/org/apache/cocoon/FlowscriptRecursiveTestCase.java URL: http://svn.apache.org/viewcvs/cocoon/branches/BRANCH_2_1_X/src/test/htmlunit/org/apache/cocoon/FlowscriptRecursiveTestCase.java?view=auto&rev=160377 ============================================================================== --- cocoon/branches/BRANCH_2_1_X/src/test/htmlunit/org/apache/cocoon/FlowscriptRecursiveTestCase.java (added) +++ cocoon/branches/BRANCH_2_1_X/src/test/htmlunit/org/apache/cocoon/FlowscriptRecursiveTestCase.java Thu Apr 7 00:52:00 2005 @@ -0,0 +1,39 @@ +/* + * Copyright 2005 The Apache Software Foundation + * 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.apache.cocoon; + +/** + * Check recursive calling a flowscript function. + * + * @version $Id: $ + */ +public class FlowscriptRecursiveTestCase + extends HtmlUnitTestCase +{ + final String pageurl = "/samples/flow/test/"; + + /** + * Check dump without XSLT transform. + */ + public void testFlowscriptRecursive() + throws Exception + { + loadHtmlPage(pageurl+"factorial?n=5"); + assertXPath("html/body/p[1]", "Factorial of 5 is ..."); + assertXPath("html/body/p[2]", "120.0"); + } +} Added: cocoon/branches/BRANCH_2_1_X/src/test/htmlunit/org/apache/cocoon/FlowscriptReloadTestCase.java URL: http://svn.apache.org/viewcvs/cocoon/branches/BRANCH_2_1_X/src/test/htmlunit/org/apache/cocoon/FlowscriptReloadTestCase.java?view=auto&rev=160377 ============================================================================== --- cocoon/branches/BRANCH_2_1_X/src/test/htmlunit/org/apache/cocoon/FlowscriptReloadTestCase.java (added) +++ cocoon/branches/BRANCH_2_1_X/src/test/htmlunit/org/apache/cocoon/FlowscriptReloadTestCase.java Thu Apr 7 00:52:00 2005 @@ -0,0 +1,53 @@ +/* + * Copyright 2005 The Apache Software Foundation + * 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.apache.cocoon; + +/** + * Check the reloading of flowscript source files. + * + * @version $Id: $ + */ +public class FlowscriptReloadTestCase + extends HtmlUnitTestCase +{ + final String pageurl = "/samples/flow/test/"; + final String flowscriptPath = "samples/flow/test/sendpage.js"; + final String paramToken = "@REPLACEME@"; + final String resultXPath = "html/body//p[1]"; + + public void testFlowscriptReload() + throws Exception + { + // Copy the flowscript from its source directory to the destination + // area, and replace the parameter value with 'abc' + + final String expected1 = "replaceme-abc"; + copyWebappFile(flowscriptPath, paramToken, expected1); + loadHtmlPage(pageurl+"showString"); + String result1 = evalXPath(resultXPath); + assertEquals("Original request", expected1, result1); + + // Copy the flowscript from its source directory to the destination + // area, and replace the parameter value with '123' + + final String expected2 = "replaceme-123"; + copyWebappFile(flowscriptPath, paramToken, expected2); + loadHtmlPage(pageurl+"showString"); + String result2 = evalXPath(resultXPath); + assertEquals("After flowscript was modified", expected2, result2); + } +} Added: cocoon/branches/BRANCH_2_1_X/src/test/htmlunit/org/apache/cocoon/HtmlUnitTestCase.java URL: http://svn.apache.org/viewcvs/cocoon/branches/BRANCH_2_1_X/src/test/htmlunit/org/apache/cocoon/HtmlUnitTestCase.java?view=auto&rev=160377 ============================================================================== --- cocoon/branches/BRANCH_2_1_X/src/test/htmlunit/org/apache/cocoon/HtmlUnitTestCase.java (added) +++ cocoon/branches/BRANCH_2_1_X/src/test/htmlunit/org/apache/cocoon/HtmlUnitTestCase.java Thu Apr 7 00:52:00 2005 @@ -0,0 +1,287 @@ +/* + * Copyright 2005 The Apache Software Foundation + * 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.apache.cocoon; + +import com.gargoylesoftware.htmlunit.Page; +import com.gargoylesoftware.htmlunit.SubmitMethod; +import com.gargoylesoftware.htmlunit.WebClient; +import com.gargoylesoftware.htmlunit.WebResponse; +import com.gargoylesoftware.htmlunit.html.DomNode; +import com.gargoylesoftware.htmlunit.html.HtmlPage; +import com.gargoylesoftware.htmlunit.html.xpath.HtmlUnitXPath; +import com.gargoylesoftware.htmlunit.xml.XmlPage; + +import junit.framework.TestCase; + +import org.apache.avalon.framework.logger.ConsoleLogger; +import org.apache.avalon.framework.logger.Logger; + +import org.apache.commons.httpclient.methods.DeleteMethod; +import org.apache.commons.httpclient.methods.PutMethod; +import org.apache.commons.httpclient.methods.StringRequestEntity; + +import org.apache.commons.io.FileUtils; + +import org.jaxen.SimpleNamespaceContext; +import org.jaxen.XPath; +import org.jaxen.dom.DOMXPath; + +import org.w3c.dom.Document; +import org.w3c.dom.Node; + +import java.io.File; +import java.net.URL; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Map; + +/** + * Base class to run test cases on Cocoon samples. + * <p> + * This class extends the JUnit TestCase class to setup an environment which + * makes it possible to easily test Cocoon pages. + * First call one of the load methods and then assert on the response object, + * XML document (@see loadXmlPage), or HTML document (@see loadHtmlPage). + * </p> + * <p> + * Examples: + * </p> + * <pre> + * public void testStatus() { + * loadResponse("/samples/test/status"); + * assertEquals("Status code", 200, response.getStatusCode()); + * } + * + * public void testTitle() { + * loadHtmlPage("/samples/test/title"); + * assertXPath("html/head/title"", "The Title"); + * } + * </pre> + * + * <p> + * For loading XML and HTML documents currently on GET requests with + * optional querystring are supported. Please add POST requests and + * request parameters when you need them. + * </p> + * @version $Id: $ + */ +public abstract class HtmlUnitTestCase + extends TestCase +{ + /** + * Logger for informative output by test cases. + * The default log level is WARN but may be changed by setting the + * property junit.test.loglevel to a different numeric value. + */ + protected Logger logger; + + /** + * Base URL of the running Cocoon server which is to be tested. + * Set by property htmlunit.test.baseurl usually as http://localhost:8888/. + */ + protected URL baseURL; + + /** + * Low-level access to WebClient object. + */ + protected WebClient webClient; + + /** + * Low-level access to WebResponse object. + */ + protected WebResponse response; + + /** + * Low-level access to XML document (org.w3c.dom.Document) or HTML document + * (com.gargoylesoftware.htmlunit.html.HtmlPage). + */ + protected Object document; + + /** + * Low-level access to namespace mappings for XPath expressions. + */ + protected Map namespaces = new HashMap(); + + /* (non-Javadoc) + * @see junit.framework.TestCase#setUp() + */ + protected void setUp() + throws Exception + { + super.setUp(); + + String level = System.getProperty("junit.test.loglevel", "" + ConsoleLogger.LEVEL_WARN); + this.logger = new ConsoleLogger(Integer.parseInt(level)); + + String baseurl = System.getProperty("htmlunit.test.baseurl"); + this.baseURL = new URL(baseurl); + this.webClient = new WebClient(); + this.webClient.setRedirectEnabled(false); + this.namespaces.clear(); + } + + /* (non-Javadoc) + * @see junit.framework.TestCase#tearDown() + */ + protected void tearDown() + throws Exception + { + this.response = null; + this.document = null; + + super.tearDown(); + } + + /** + * Sends HTTP GET request and loads response object. + */ + protected void loadResponse(String pageURL) + throws Exception + { + URL url = new URL(baseURL, pageURL); + this.response = webClient.loadWebResponse(url, SubmitMethod.GET, new ArrayList(0)); + } + + /** + * Sends HTTP DELETE request and loads response object. + */ + protected void loadDeleteResponse(String pageURL) + throws Exception + { + URL url = new URL(baseURL, pageURL); + DeleteMethod method = new DeleteMethod(url.toExternalForm()); + this.response = new HttpClientResponse(url, method); + } + + /** + * Sends HTTP PUT request and loads response object. + */ + protected void loadPutResponse(String pageURL, String content) + throws Exception + { + URL url = new URL(baseURL, pageURL); + PutMethod method = new PutMethod(url.toExternalForm()); + method.setRequestEntity(new StringRequestEntity(content)); + this.response = new HttpClientResponse(url, method); + } + + /** + * Sends HTTP request and parses response as HTML document. + */ + protected void loadHtmlPage(String pageURL) + throws Exception + { + URL url = new URL(baseURL, pageURL); + Page page = webClient.getPage(url); + this.response = page.getWebResponse(); + assertTrue("Response should be an HTML page", page instanceof HtmlPage); + this.document = page; + assertNotNull("Response contains invalid HTML", this.document); + } + + /** + * Sends HTTP request and parses response as XML document. + */ + protected void loadXmlPage(String pageURL) + throws Exception + { + URL url = new URL(baseURL, pageURL); + Page page = webClient.getPage(url); + this.response = page.getWebResponse(); + assertTrue("Response should be an XML page", page instanceof XmlPage); + XmlPage xmlPage = (XmlPage)page; + this.document = xmlPage.getXmlDocument(); + assertNotNull("Response contains invalid XML", this.document); + } + + /** + * Returns XPath expression as string. + * + * @param xpathExpr XPath expression + * + * @return Value of XPath expression in current document. + * Empty string if XPath not matched. + */ + protected String evalXPath(String xpathExpr) + throws Exception + { + XPath xpath = null; + if( document == null ) + return null; + else if( document instanceof HtmlPage ) + xpath = new HtmlUnitXPath(xpathExpr); + else if( document instanceof Document ) + xpath = new DOMXPath(xpathExpr); + else + fail("Document type "+document.getClass().getName()); + + xpath.setNamespaceContext(new SimpleNamespaceContext(namespaces)); + + return xpath.stringValueOf(document); + } + + /** + * Add a namespace mapping for XPath expressions. + */ + protected void addNamespace(String prefix, String uri) + throws Exception + { + namespaces.put(prefix, uri); + } + + /** + * Assert that XPath expression result matches exactly expected value. + */ + protected void assertXPath(String xpathExpr, String expected) + throws Exception + { + assertEquals(xpathExpr, expected, evalXPath(xpathExpr)); + } + + /** + * Copy file from webapp source to deployment area filtering content + * to replace parameter by value. + * The source and deployment directories are defined by the properties + * htmlunit.test.source-dir and htmlunit.test.deploy-dir. + * + * This method is most useful for testing the automatic reloading of + * changed files. + */ + protected void copyWebappFile(String filename, String param, String value) + throws Exception + { + String srcdir = System.getProperty("htmlunit.test.source-dir"); + String dstdir = System.getProperty("htmlunit.test.deploy-dir"); + File srcfile = new File(srcdir+"/"+filename); + File dstfile = new File(dstdir+"/"+filename); + + final String encoding = "ISO-8859-1"; + StringBuffer content = new StringBuffer(FileUtils.readFileToString(srcfile, encoding)); + + int index = content.indexOf(param); + while( index != -1 ) { + content.replace(index, index+param.length(), value); + index = content.indexOf(param, index+1); + } + + FileUtils.writeStringToFile(dstfile, content.toString(), encoding); + + // Leave server some time to realize that file has changed. + + Thread.sleep(1000); + } +} Added: cocoon/branches/BRANCH_2_1_X/src/test/htmlunit/org/apache/cocoon/HttpClientResponse.java URL: http://svn.apache.org/viewcvs/cocoon/branches/BRANCH_2_1_X/src/test/htmlunit/org/apache/cocoon/HttpClientResponse.java?view=auto&rev=160377 ============================================================================== --- cocoon/branches/BRANCH_2_1_X/src/test/htmlunit/org/apache/cocoon/HttpClientResponse.java (added) +++ cocoon/branches/BRANCH_2_1_X/src/test/htmlunit/org/apache/cocoon/HttpClientResponse.java Thu Apr 7 00:52:00 2005 @@ -0,0 +1,107 @@ +/* + * Copyright 2005 The Apache Software Foundation + * 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.apache.cocoon; + +import com.gargoylesoftware.htmlunit.WebResponse; + +import org.apache.commons.httpclient.HttpClient; +import org.apache.commons.httpclient.HttpMethodBase; + +import java.io.InputStream; +import java.io.IOException; +import java.net.URL; + +/** + * Wrap the result of an httpclient Method execution into an HtmlUnit + * WebResponse in order to be used by HtmlUnitTestCase. + * + * This class may become obsolete when HtmlUnit supports WebDAV methods. + * For progress on this issue see: + * https://sourceforge.net/tracker/?func=detail&atid=448269&aid=1166661&group_id=47038 + * + * @version $Id: $ + */ +class HttpClientResponse + implements WebResponse +{ + private URL url; + private HttpMethodBase method; + private int statusCode; + private long loadTime; + + HttpClientResponse(URL url, HttpMethodBase method) + throws IOException + { + long t0 = System.currentTimeMillis(); + this.url = url; + this.method = method; + HttpClient client = new HttpClient(); + statusCode = client.executeMethod(method); + long t1 = System.currentTimeMillis(); + this.loadTime = t1-t0; + } + + public int getStatusCode() { + return statusCode; + } + + public String getStatusMessage() { + return method.getStatusText(); + } + + public String getContentType() { + return method.getResponseHeader("Content-type").getValue(); + } + + public String getContentAsString() { + try { + return method.getResponseBodyAsString(); + } + catch(IOException ex) { + return null; + } + } + + public InputStream getContentAsStream() throws IOException { + return method.getResponseBodyAsStream(); + } + + public URL getUrl() { + return url; + } + + public String getResponseHeaderValue(String headerName) { + return method.getResponseHeader(headerName).getValue(); + } + + public long getLoadTimeInMilliSeconds() { + return loadTime; + } + + public String getContentCharSet() { + return method.getResponseCharSet(); + } + + public byte[] getResponseBody() { + try { + return method.getResponseBody(); + } + catch(IOException ex) { + return null; + } + } +} Added: cocoon/branches/BRANCH_2_1_X/src/test/htmlunit/org/apache/cocoon/InternalRequestTestCase.java URL: http://svn.apache.org/viewcvs/cocoon/branches/BRANCH_2_1_X/src/test/htmlunit/org/apache/cocoon/InternalRequestTestCase.java?view=auto&rev=160377 ============================================================================== --- cocoon/branches/BRANCH_2_1_X/src/test/htmlunit/org/apache/cocoon/InternalRequestTestCase.java (added) +++ cocoon/branches/BRANCH_2_1_X/src/test/htmlunit/org/apache/cocoon/InternalRequestTestCase.java Thu Apr 7 00:52:00 2005 @@ -0,0 +1,35 @@ +/* + * Copyright 2005 The Apache Software Foundation + * 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.apache.cocoon; + +/** + * HtmlUnit TestCase for internal request handling. + * + * @version $Id: $ + */ +public class InternalRequestTestCase + extends HtmlUnitTestCase +{ + static final String pageurl = "/samples/test/internal-request/"; + + public void testSimple() + throws Exception + { + loadXmlPage(pageurl+"simpletest"); + assertXPath("test/test/@file", "c"); + } +} Added: cocoon/branches/BRANCH_2_1_X/src/test/htmlunit/org/apache/cocoon/InternalSendPageTestCase.java URL: http://svn.apache.org/viewcvs/cocoon/branches/BRANCH_2_1_X/src/test/htmlunit/org/apache/cocoon/InternalSendPageTestCase.java?view=auto&rev=160377 ============================================================================== --- cocoon/branches/BRANCH_2_1_X/src/test/htmlunit/org/apache/cocoon/InternalSendPageTestCase.java (added) +++ cocoon/branches/BRANCH_2_1_X/src/test/htmlunit/org/apache/cocoon/InternalSendPageTestCase.java Thu Apr 7 00:52:00 2005 @@ -0,0 +1,26 @@ +package org.apache.cocoon; + +/** + * Check internal sendpage. + * + * @version $Id: $ + */ +public class InternalSendPageTestCase + extends HtmlUnitTestCase +{ + final String pageurl = "/samples/test/sendpage/"; + + public void testExternal() + throws Exception + { + loadResponse(pageurl+"testExternal"); + assertEquals("Status code", 200, response.getStatusCode()); + } + + public void testInternal() + throws Exception + { + loadResponse(pageurl+"testInternal"); + assertEquals("Status code", 200, response.getStatusCode()); + } +} Added: cocoon/branches/BRANCH_2_1_X/src/test/htmlunit/org/apache/cocoon/ReaderMimeTypeTestCase.java URL: http://svn.apache.org/viewcvs/cocoon/branches/BRANCH_2_1_X/src/test/htmlunit/org/apache/cocoon/ReaderMimeTypeTestCase.java?view=auto&rev=160377 ============================================================================== --- cocoon/branches/BRANCH_2_1_X/src/test/htmlunit/org/apache/cocoon/ReaderMimeTypeTestCase.java (added) +++ cocoon/branches/BRANCH_2_1_X/src/test/htmlunit/org/apache/cocoon/ReaderMimeTypeTestCase.java Thu Apr 7 00:52:00 2005 @@ -0,0 +1,152 @@ +/* + * Copyright 2005 The Apache Software Foundation + * 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.apache.cocoon; + +/** + * HtmlUnit TestCase for Content type headers returned by Cocoon readers. + * + * Each httpRequest is repeated twice to check caching pipeline. + * Check for text/xml instead of text/html in order not to be fooled + * by 404 or 500 error pages. + * + * @version $Id: $ + */ +public class ReaderMimeTypeTestCase + extends HtmlUnitTestCase +{ + static final String pageurl = "/samples/test/reader-mime-type/"; + + /** + * Check that content-type is <I>not</I> derived from URL extension. + */ + public void test10() + throws Exception + { + call10(); + call10(); + } + + private void call10() + throws Exception + { + loadResponse(pageurl+"test10.xml"); + assertEquals("Content type should be undefined", "", response.getContentType()); + } + + /** + * Check content-type derived from map:read/@src. + */ + public void test20() + throws Exception + { + call20(); + call20(); + } + + private void call20() + throws Exception + { + loadResponse(pageurl+"test20.x20"); + assertEquals("Content type", "text/xml", response.getContentType()); + } + + /** + * Check content-type derived from map:read/@mime-type. + */ + public void test30() + throws Exception + { + call30(); + call30(); + } + + private void call30() + throws Exception + { + loadResponse(pageurl+"test30.x30"); + assertEquals("Content type", "text/xml", response.getContentType()); + } + + /** + * Check content-type derived from map:reader/@mime-type. + */ + public void test40() + throws Exception + { + call40(); + call40(); + } + + private void call40() + throws Exception + { + loadResponse(pageurl+"test40.x40"); + assertEquals("Content type", "text/xml", response.getContentType()); + } + + /** + * Check that content-type is <I>not</I> inherited across cocoon:/ + * indirections + */ + public void test50() + throws Exception + { + call50(); + call50(); + } + + private void call50() + throws Exception + { + loadResponse(pageurl+"test50.xml"); + assertEquals("Content type should be undefined", "", response.getContentType()); + } + + /** + * Check content-type derived from map:read/@src. + */ + public void test60() + throws Exception + { + call60(); + call60(); + } + + private void call60() + throws Exception + { + loadResponse(pageurl+"test60.x60"); + assertEquals("Content type", "text/xml", response.getContentType()); + } + + /** + * Check content-type derived from map:read/@mime-type. + */ + public void test70() + throws Exception + { + call70(); + call70(); + } + + private void call70() + throws Exception + { + loadResponse(pageurl+"test70.x70"); + assertEquals("Content type", "text/xml", response.getContentType()); + } +} Added: cocoon/branches/BRANCH_2_1_X/src/test/htmlunit/org/apache/cocoon/RedirectTestCase.java URL: http://svn.apache.org/viewcvs/cocoon/branches/BRANCH_2_1_X/src/test/htmlunit/org/apache/cocoon/RedirectTestCase.java?view=auto&rev=160377 ============================================================================== --- cocoon/branches/BRANCH_2_1_X/src/test/htmlunit/org/apache/cocoon/RedirectTestCase.java (added) +++ cocoon/branches/BRANCH_2_1_X/src/test/htmlunit/org/apache/cocoon/RedirectTestCase.java Thu Apr 7 00:52:00 2005 @@ -0,0 +1,77 @@ +/* + * Copyright 2005 The Apache Software Foundation + * 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.apache.cocoon; + +/** + * Check redirects. + * + * @version $Id: $ + */ +public class RedirectTestCase + extends HtmlUnitTestCase +{ + final String pageurl = "/samples/test/redirect/"; + + public void testRedirectToFromSitemap() + throws Exception + { + loadResponse(pageurl+"redirect-to-from-sitemap"); + assertEquals("Status code", 302, response.getStatusCode()); + } + + public void testRedirectToInternalFromSitemap() + throws Exception + { + loadResponse(pageurl+"redirect-to-internal-from-sitemap"); + assertEquals("Status code", 200, response.getStatusCode()); + } + + public void testRedirectToFromFlow() + throws Exception + { + loadResponse(pageurl+"redirect-to-from-flow"); + assertEquals("Status code", 302, response.getStatusCode()); + } + + public void testSendStatus() + throws Exception + { + loadResponse(pageurl+"send-status"); + assertEquals("Status code", 204, response.getStatusCode()); + } + + public void testSendPage() + throws Exception + { + loadResponse(pageurl+"send-page"); + assertEquals("Status code", 200, response.getStatusCode()); + } + + public void testDoNothingFromSitemap() + throws Exception + { + loadResponse(pageurl+"donothing-from-sitemap"); + assertEquals("Status code", 404, response.getStatusCode()); + } + + public void testDoNothingFromFlow() + throws Exception + { + loadResponse(pageurl+"donothing-from-flow"); + assertEquals("Status code", 500, response.getStatusCode()); + } +} Added: cocoon/branches/BRANCH_2_1_X/src/test/htmlunit/org/apache/cocoon/SitemapReloadTestCase.java URL: http://svn.apache.org/viewcvs/cocoon/branches/BRANCH_2_1_X/src/test/htmlunit/org/apache/cocoon/SitemapReloadTestCase.java?view=auto&rev=160377 ============================================================================== --- cocoon/branches/BRANCH_2_1_X/src/test/htmlunit/org/apache/cocoon/SitemapReloadTestCase.java (added) +++ cocoon/branches/BRANCH_2_1_X/src/test/htmlunit/org/apache/cocoon/SitemapReloadTestCase.java Thu Apr 7 00:52:00 2005 @@ -0,0 +1,53 @@ +/* + * Copyright 2005 The Apache Software Foundation + * 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.apache.cocoon; + +/** + * Check the reloading of the sitemap. + * + * @version $Id: $ + */ +public class SitemapReloadTestCase + extends HtmlUnitTestCase +{ + final String pageurl = "/samples/flow/test/"; + final String sitemapPath = "samples/flow/test/sitemap.xmap"; + final String paramToken = "@PARAMETER@"; + final String resultXPath = "html/body//p[2]"; + + public void testSitemapReload() + throws Exception + { + // Copy the sitemap from its source directory to the destination + // area, and replace the parameter value with 'abc' + + final String expected1 = "abc"; + copyWebappFile(sitemapPath, paramToken, expected1); + loadHtmlPage(pageurl+"showString"); + String result1 = evalXPath(resultXPath); + assertEquals("Original request", expected1, result1); + + // Copy the sitemap from its source directory to the destination + // area, and replace the parameter value with '123' + + final String expected2 = "123"; + copyWebappFile(sitemapPath, paramToken, expected2); + loadHtmlPage(pageurl+"showString"); + String result2 = evalXPath(resultXPath); + assertEquals("After sitemap was modified", expected2, result2); + } +}