001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017: package org.apache.cocoon;
018:
019: import java.net.URLEncoder;
020:
021: /**
022: * Check basic TraversableGenerator functionality.
023: *
024: * @version $Id: $
025: */
026: public class WebdavStep3TestCase extends HtmlUnitTestCase {
027: static final String pageurl = "/samples/blocks/webdav/";
028:
029: /**
030: * Testing basic TraversableGenerator functionality.
031: */
032: public void testTraversableGenerator() throws Exception {
033: loadXmlPage(pageurl + "step1/repo/");
034: addNamespace("collection",
035: "http://apache.org/cocoon/collection/1.0");
036:
037: // FIXME: why XPath namespaces not working?
038:
039: final String xpathName = "/collection:collection/collection:resource/@name";
040: String name = evalXPath(xpathName);
041: if (name.length() != 0) {
042: logger.info("Good, XPath namespaces finally working");
043: assertXPath(xpathName, "contentA.xml");
044: } else {
045: logger.info("Damnit, XPath namespaces still not working");
046: assertXPath(
047: "/*[name(.)='collection:collection']/*[name(.)='collection:resource']/@name",
048: "contentA.xml");
049: }
050: }
051:
052: public void testContentB() throws Exception {
053: final String step3url = pageurl
054: + "step3/repo/dir2/contentB.xml";
055:
056: final String xpathTitle = "/html/body/form/p/input[@name='title']/@value";
057: final String xpathPara1 = "(/html/body/form/p/textarea)[1]";
058: final String xpathPara2 = "(/html/body/form/p/textarea)[2]";
059: final String xpathAction = "/html/body/form/@action";
060:
061: final String xpathSuccess = "/page/sourceResult/execution";
062: final String valueSuccess = "success";
063:
064: final String oldTitle = "Content B";
065: final String oldPara1 = "First Paragraph";
066: final String oldPara2 = "Second Paragraph";
067:
068: final String newTitle = "Title changed by WebdavStep3TestCase";
069: final String newPara1 = "test1";
070: final String newPara2 = "test2";
071:
072: // Check contents of contentB.xml
073:
074: loadHtmlPage(step3url);
075: //assertXPath(xpathTitle, oldTitle);
076: //assertXPath(xpathPara1, oldPara1);
077: //assertXPath(xpathPara2, oldPara2);
078: String action1 = evalXPath(xpathAction);
079:
080: // Change contents of contentB.xml
081:
082: loadXmlPage(action1 + "?title=" + URLEncoder.encode(newTitle)
083: + "¶=" + URLEncoder.encode(newPara1) + "¶="
084: + URLEncoder.encode(newPara2));
085: assertXPath(xpathSuccess, valueSuccess);
086:
087: // Check changes
088:
089: Thread.sleep(1000);
090: loadHtmlPage(step3url);
091: assertXPath(xpathTitle, newTitle);
092: assertXPath(xpathPara1, newPara1);
093: assertXPath(xpathPara2, newPara2);
094: String action2 = evalXPath(xpathAction);
095:
096: // Undo changes
097:
098: loadXmlPage(action2 + "?title=" + URLEncoder.encode(oldTitle)
099: + "¶=" + URLEncoder.encode(oldPara1) + "¶="
100: + URLEncoder.encode(oldPara2));
101: assertXPath(xpathSuccess, valueSuccess);
102:
103: // Check success of undo
104:
105: Thread.sleep(1000);
106: loadHtmlPage(step3url);
107: assertXPath(xpathTitle, oldTitle);
108: assertXPath(xpathPara1, oldPara1);
109: assertXPath(xpathPara2, oldPara2);
110: }
111: }
|