KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > cocoon > WebdavStep3TestCase


1 /*
2  * Copyright 1999-2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 package org.apache.cocoon;
17
18 import java.net.URLEncoder JavaDoc;
19
20 /**
21  * Check basic TraversableGenerator functionality.
22  *
23  * @version $Id: $
24  */

25 public class WebdavStep3TestCase
26     extends HtmlUnitTestCase
27 {
28     static final String JavaDoc pageurl = "/samples/blocks/webdav/";
29     /**
30      * Testing basic TraversableGenerator functionality.
31      */

32     public void testTraversableGenerator()
33         throws Exception JavaDoc
34     {
35         loadXmlPage(pageurl+"step1/repo/");
36         addNamespace("collection", "http://apache.org/cocoon/collection/1.0");
37
38         // FIXME: why XPath namespaces not working?
39

40         final String JavaDoc xpathName = "/collection:collection/collection:resource/@name";
41         String JavaDoc name = evalXPath(xpathName);
42         if( name.length() != 0 ) {
43             logger.info("Good, XPath namespaces finally working");
44             assertXPath(xpathName, "contentA.xml");
45         }
46         else {
47             logger.info("Damnit, XPath namespaces still not working");
48             assertXPath("/*[name(.)='collection:collection']/*[name(.)='collection:resource']/@name", "contentA.xml");
49         }
50     }
51
52     public void testContentB()
53         throws Exception JavaDoc
54     {
55         final String JavaDoc step3url = pageurl+"step3/repo/dir2/contentB.xml";
56
57         final String JavaDoc xpathTitle = "/html/body/form/p/input[@name='title']/@value";
58         final String JavaDoc xpathPara1 = "(/html/body/form/p/textarea)[1]";
59         final String JavaDoc xpathPara2 = "(/html/body/form/p/textarea)[2]";
60         final String JavaDoc xpathAction = "/html/body/form/@action";
61
62         final String JavaDoc xpathSuccess = "/page/sourceResult/execution";
63         final String JavaDoc valueSuccess = "success";
64
65         final String JavaDoc oldTitle = "Content B";
66         final String JavaDoc oldPara1 = "First Paragraph";
67         final String JavaDoc oldPara2 = "Second Paragraph";
68
69         final String JavaDoc newTitle = "Title changed by WebdavStep3TestCase";
70         final String JavaDoc newPara1 = "test1";
71         final String JavaDoc newPara2 = "test2";
72
73         // Check contents of contentB.xml
74

75         loadHtmlPage(step3url);
76         //assertXPath(xpathTitle, oldTitle);
77
//assertXPath(xpathPara1, oldPara1);
78
//assertXPath(xpathPara2, oldPara2);
79
String JavaDoc action1 = evalXPath(xpathAction);
80
81         // Change contents of contentB.xml
82

83         loadXmlPage(action1+"?title="+URLEncoder.encode(newTitle)+"&para="+URLEncoder.encode(newPara1)+"&para="+URLEncoder.encode(newPara2));
84         assertXPath(xpathSuccess, valueSuccess);
85
86         // Check changes
87

88         Thread.sleep(1000);
89         loadHtmlPage(step3url);
90         assertXPath(xpathTitle, newTitle);
91         assertXPath(xpathPara1, newPara1);
92         assertXPath(xpathPara2, newPara2);
93         String JavaDoc action2 = evalXPath(xpathAction);
94
95         // Undo changes
96

97         loadXmlPage(action2+"?title="+URLEncoder.encode(oldTitle)+"&para="+URLEncoder.encode(oldPara1)+"&para="+URLEncoder.encode(oldPara2));
98         assertXPath(xpathSuccess, valueSuccess);
99
100         // Check success of undo
101

102         Thread.sleep(1000);
103         loadHtmlPage(step3url);
104         assertXPath(xpathTitle, oldTitle);
105         assertXPath(xpathPara1, oldPara1);
106         assertXPath(xpathPara2, oldPara2);
107     }
108 }
109
Popular Tags