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.components.source.impl;
018:
019: import org.apache.cocoon.core.container.ContainerTestCase;
020: import org.apache.excalibur.source.SourceResolver;
021: import org.apache.webdav.lib.WebdavResource;
022:
023: /**
024: * @version $Id: WebDAVSourceTestCase.java 433543 2006-08-22 06:22:54Z crossley $
025: */
026: public class WebDAVSourceTestCase extends ContainerTestCase {
027:
028: private String m_scheme = "webdav";
029: private String m_credentials = "usr:pwd";
030: private String m_authority = "localhost:8888";
031: private String m_path = "/webdav/";
032: private String m_name = "files";
033: private String m_location = m_scheme + "://" + m_credentials + "@"
034: + m_authority + m_path + m_name;
035: private String m_secure = m_scheme + "://" + m_authority + m_path
036: + m_name;
037: private String m_options = "?cocoon:webdav-action="
038: + WebdavResource.NOACTION + "&cocoon:webdav-depth=0";
039:
040: public void testResolve() throws Exception {
041: SourceResolver resolver = (SourceResolver) lookup(SourceResolver.ROLE);
042: String uri = m_location + m_options;
043: WebDAVSource source = (WebDAVSource) resolver.resolveURI(uri);
044: assertEquals(m_location, source.getURI());
045: assertEquals(m_scheme, source.getScheme());
046: assertEquals(m_name, source.getName());
047: assertEquals(m_secure, source.getSecureURI());
048: resolver.release(source);
049: }
050:
051: public void testTraversal() throws Exception {
052: // SourceResolver resolver = (SourceResolver) lookup(SourceResolver.ROLE);
053: // String uri = m_location + m_options;
054: // TraversableSource source = (TraversableSource) resolver.resolveURI(uri);
055: // assertTrue(source.isCollection());
056: // assertTrue(source.exists());
057: // Iterator children = source.getChildren().iterator();
058: // if (children.hasNext()) {
059: // TraversableSource child = (TraversableSource) children.next();
060: // assertEquals(m_scheme, child.getScheme());
061: // TraversableSource parent = (TraversableSource) child.getParent();
062: // assertEquals(m_scheme, parent.getScheme());
063: // assertEquals(m_name, parent.getName());
064: // assertTrue(parent.isCollection());
065: // resolver.release(child);
066: // }
067: //
068: // TraversableSource child = (TraversableSource) source.getChild("childcollection");
069: // assertEquals(child.getURI(), m_location + "/childcollection");
070: //
071: // TraversableSource parent = (TraversableSource) child.getParent();
072: // assertEquals(m_name, parent.getName());
073: //
074: // resolver.release(source);
075: }
076:
077: public void testModification() throws Exception {
078: // SourceResolver resolver = (SourceResolver) lookup(SourceResolver.ROLE);
079: // String uri = m_location + m_options;
080: //
081: // ModifiableTraversableSource source = (ModifiableTraversableSource) resolver.resolveURI(uri);
082: // ModifiableTraversableSource child = (ModifiableTraversableSource) source.getChild("newdoc.txt");
083: // assertTrue(!child.exists());
084: //
085: // // create document
086: // String hello = "hello world";
087: // OutputStream out = child.getOutputStream();
088: // out.write(hello.getBytes());
089: // out.close();
090: //
091: // assertTrue(child.exists());
092: //
093: // // read contents
094: // byte[] read = new byte[hello.length()];
095: // InputStream in = child.getInputStream();
096: // in.read(read);
097: //
098: // // compare
099: // assertEquals(hello, new String(read));
100: //
101: // child.delete();
102: // assertTrue(!child.exists());
103: //
104: // resolver.release(source);
105: // resolver.release(child);
106: }
107:
108: public void testMakeCollection() throws Exception {
109: // SourceResolver resolver = (SourceResolver) lookup(SourceResolver.ROLE);
110: // String uri = m_location + m_options;
111: // ModifiableTraversableSource source = (ModifiableTraversableSource) resolver.resolveURI(uri);
112: // ModifiableTraversableSource child = (ModifiableTraversableSource) source.getChild("child");
113: // ModifiableTraversableSource descendant = (ModifiableTraversableSource) source.getChild("child/decendant");
114: //
115: // assertTrue(!child.exists());
116: // descendant.makeCollection();
117: // assertTrue(child.exists());
118: // assertTrue(descendant.exists());
119: // child.delete();
120: // assertTrue(!child.exists());
121: // descendant.refresh();
122: // assertTrue(!descendant.exists());
123: //
124: // resolver.release(child);
125: // resolver.release(source);
126: }
127: }
|