KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > cocoon > components > source > impl > WebDAVSourceTestCase


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.components.source.impl;
17
18 import org.apache.cocoon.core.container.ContainerTestCase;
19 import org.apache.excalibur.source.SourceResolver;
20 import org.apache.webdav.lib.WebdavResource;
21
22 /**
23  * @version $Id: WebDAVSourceTestCase.java 55454 2004-10-24 18:02:39Z cziegeler $
24  */

25 public class WebDAVSourceTestCase extends ContainerTestCase {
26     
27     private String JavaDoc m_scheme = "webdav";
28     private String JavaDoc m_credentials = "usr:pwd";
29     private String JavaDoc m_authority = "localhost:8888";
30     private String JavaDoc m_path = "/webdav/";
31     private String JavaDoc m_name = "files";
32     private String JavaDoc m_location = m_scheme + "://" + m_credentials + "@" + m_authority + m_path + m_name;
33     private String JavaDoc m_secure = m_scheme + "://" + m_authority + m_path + m_name;
34     private String JavaDoc m_options = "?cocoon:webdav-action=" + WebdavResource.NOACTION + "&cocoon:webdav-depth=0";
35     
36     
37     public void testResolve() throws Exception JavaDoc {
38         SourceResolver resolver = (SourceResolver) lookup(SourceResolver.ROLE);
39         String JavaDoc uri = m_location + m_options;
40         WebDAVSource source = (WebDAVSource) resolver.resolveURI(uri);
41         assertEquals(m_location, source.getURI());
42         assertEquals(m_scheme, source.getScheme());
43         assertEquals(m_name, source.getName());
44         assertEquals(m_secure, source.getSecureURI());
45         resolver.release(source);
46     }
47
48     public void testTraversal() throws Exception JavaDoc {
49 // SourceResolver resolver = (SourceResolver) lookup(SourceResolver.ROLE);
50
// String uri = m_location + m_options;
51
// TraversableSource source = (TraversableSource) resolver.resolveURI(uri);
52
// assertTrue(source.isCollection());
53
// assertTrue(source.exists());
54
// Iterator children = source.getChildren().iterator();
55
// if (children.hasNext()) {
56
// TraversableSource child = (TraversableSource) children.next();
57
// assertEquals(m_scheme, child.getScheme());
58
// TraversableSource parent = (TraversableSource) child.getParent();
59
// assertEquals(m_scheme, parent.getScheme());
60
// assertEquals(m_name, parent.getName());
61
// assertTrue(parent.isCollection());
62
// resolver.release(child);
63
// }
64
//
65
// TraversableSource child = (TraversableSource) source.getChild("childcollection");
66
// assertEquals(child.getURI(), m_location + "/childcollection");
67
//
68
// TraversableSource parent = (TraversableSource) child.getParent();
69
// assertEquals(m_name, parent.getName());
70
//
71
// resolver.release(source);
72
}
73
74     public void testModification() throws Exception JavaDoc {
75 // SourceResolver resolver = (SourceResolver) lookup(SourceResolver.ROLE);
76
// String uri = m_location + m_options;
77
//
78
// ModifiableTraversableSource source = (ModifiableTraversableSource) resolver.resolveURI(uri);
79
// ModifiableTraversableSource child = (ModifiableTraversableSource) source.getChild("newdoc.txt");
80
// assertTrue(!child.exists());
81
//
82
// // create document
83
// String hello = "hello world";
84
// OutputStream out = child.getOutputStream();
85
// out.write(hello.getBytes());
86
// out.close();
87
//
88
// assertTrue(child.exists());
89
//
90
// // read contents
91
// byte[] read = new byte[hello.length()];
92
// InputStream in = child.getInputStream();
93
// in.read(read);
94
//
95
// // compare
96
// assertEquals(hello, new String(read));
97
//
98
// child.delete();
99
// assertTrue(!child.exists());
100
//
101
// resolver.release(source);
102
// resolver.release(child);
103
}
104     
105     public void testMakeCollection() throws Exception JavaDoc {
106 // SourceResolver resolver = (SourceResolver) lookup(SourceResolver.ROLE);
107
// String uri = m_location + m_options;
108
// ModifiableTraversableSource source = (ModifiableTraversableSource) resolver.resolveURI(uri);
109
// ModifiableTraversableSource child = (ModifiableTraversableSource) source.getChild("child");
110
// ModifiableTraversableSource descendant = (ModifiableTraversableSource) source.getChild("child/decendant");
111
//
112
// assertTrue(!child.exists());
113
// descendant.makeCollection();
114
// assertTrue(child.exists());
115
// assertTrue(descendant.exists());
116
// child.delete();
117
// assertTrue(!child.exists());
118
// descendant.refresh();
119
// assertTrue(!descendant.exists());
120
//
121
// resolver.release(child);
122
// resolver.release(source);
123
}
124 }
125
Popular Tags