You are viewing a plain text version of this content. The canonical link for it is here.
Posted to xindice-dev@xml.apache.org by vg...@apache.org on 2007/05/25 03:44:39 UTC

svn commit: r541505 - /xml/xindice/trunk/java/tests/src/org/apache/xindice/webadmin/

Author: vgritsenko
Date: Thu May 24 18:44:37 2007
New Revision: 541505

URL: http://svn.apache.org/viewvc?view=rev&rev=541505
Log:
add tests

Added:
    xml/xindice/trunk/java/tests/src/org/apache/xindice/webadmin/
    xml/xindice/trunk/java/tests/src/org/apache/xindice/webadmin/CopyTest.java   (with props)
    xml/xindice/trunk/java/tests/src/org/apache/xindice/webadmin/DeleteTest.java   (with props)
    xml/xindice/trunk/java/tests/src/org/apache/xindice/webadmin/HttpServletRequestMockup.java   (with props)
    xml/xindice/trunk/java/tests/src/org/apache/xindice/webadmin/HttpServletResponseMockup.java   (with props)
    xml/xindice/trunk/java/tests/src/org/apache/xindice/webadmin/LocationTest.java   (with props)
    xml/xindice/trunk/java/tests/src/org/apache/xindice/webadmin/MethodSetup.java   (with props)
    xml/xindice/trunk/java/tests/src/org/apache/xindice/webadmin/MkcolTest.java   (with props)
    xml/xindice/trunk/java/tests/src/org/apache/xindice/webadmin/MoveTest.java   (with props)
    xml/xindice/trunk/java/tests/src/org/apache/xindice/webadmin/PropfindTest.java   (with props)
    xml/xindice/trunk/java/tests/src/org/apache/xindice/webadmin/PutTest.java   (with props)

Added: xml/xindice/trunk/java/tests/src/org/apache/xindice/webadmin/CopyTest.java
URL: http://svn.apache.org/viewvc/xml/xindice/trunk/java/tests/src/org/apache/xindice/webadmin/CopyTest.java?view=auto&rev=541505
==============================================================================
--- xml/xindice/trunk/java/tests/src/org/apache/xindice/webadmin/CopyTest.java (added)
+++ xml/xindice/trunk/java/tests/src/org/apache/xindice/webadmin/CopyTest.java Thu May 24 18:44:37 2007
@@ -0,0 +1,206 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.xindice.webadmin;
+
+import org.apache.xindice.webadmin.webdav.components.Copy;
+import org.apache.xindice.webadmin.webdav.WebdavStatus;
+import org.apache.xindice.xml.dom.DOMParser;
+import org.apache.xindice.core.Collection;
+import org.apache.xindice.util.Configuration;
+import org.w3c.dom.Document;
+
+public class CopyTest extends MethodSetup {
+
+    public void setUp() throws Exception {
+        super.setUp();
+        method = new Copy();
+    }
+
+    public void testCopyNullCollection() throws Exception {
+        // source collection was not found
+        method.execute(request, response, new Location("/unknown"));
+        assertEquals(WebdavStatus.SC_NOT_FOUND, httpResponse.getStatus());
+    }
+
+    public void testCopyNoDestination() throws Exception {
+        // request does not have a Destination header
+        method.execute(request, response, new Location(collection.getCanonicalName()));
+        assertEquals(WebdavStatus.SC_BAD_REQUEST, httpResponse.getStatus());
+
+        method.execute(request, response, new Location(collection.getCanonicalDocumentName("test")));
+        assertEquals(WebdavStatus.SC_BAD_REQUEST, httpResponse.getStatus());
+    }
+
+    public void testCopySamePathResource() throws Exception {
+        httpRequest.setPathInfo("/db/test");
+        httpRequest.addHeader("Destination", "/db/test");
+        method.execute(request, response, new Location(collection.getCanonicalDocumentName("test")));
+        assertEquals(WebdavStatus.SC_FORBIDDEN, httpResponse.getStatus());
+    }
+
+    public void testCopySamePathCollection() throws Exception {
+        httpRequest.setPathInfo(collection.getCanonicalName());
+        httpRequest.addHeader("Destination", collection.getCanonicalName() + "/new");
+        method.execute(request, response, new Location(collection.getCanonicalName()));
+        assertEquals(WebdavStatus.SC_FORBIDDEN, httpResponse.getStatus());
+
+        httpRequest.setPathInfo(collection.getCanonicalName());
+        httpRequest.addHeader("Destination", collection.getCanonicalName());
+        method.execute(request, response, new Location(collection.getCanonicalName()));
+        assertEquals(WebdavStatus.SC_FORBIDDEN, httpResponse.getStatus());
+    }
+
+    public void testCopyResourceNullDestCollection() throws Exception {
+        // destination collection does not exist
+        httpRequest.addHeader("Destination", collection.getCanonicalName() + "/test/resource");
+
+        String xml = "<test document='true'>This is the test XML</test>";
+        Document document = DOMParser.toDocument(xml);
+
+        collection.setDocument("resource", document);
+
+        method.execute(request, response, new Location(collection.getCanonicalDocumentName("resource")));
+        assertEquals(WebdavStatus.SC_CONFLICT, httpResponse.getStatus());
+    }
+
+    public void testCopyResource() throws Exception {
+        String name = "new";
+        Collection child = collection.createCollection(name, new Configuration(
+                DOMParser.toDocument(
+                        "<collection compressed='true' name='" + name + "' inline-metadata='true'>" +
+                        "<filer class='org.apache.xindice.core.filer.BTreeFiler' />" +
+                        "</collection>"), false
+        ));
+
+        httpRequest.addHeader("Destination", child.getCanonicalDocumentName("resource"));
+
+        String xml = "<test document='true'>This is the test XML</test>";
+        Document document = DOMParser.toDocument(xml);
+
+        String docName = "resource";
+        collection.setDocument(docName, document);
+
+        method.execute(request, response, new Location(collection.getCanonicalDocumentName(docName)));
+        assertEquals(WebdavStatus.SC_CREATED, httpResponse.getStatus());
+        assertNotNull(child.getDocument(docName));
+        assertEquals(document.toString(), child.getDocument(docName).toString());
+    }
+
+    public void testCopyResourceNoOverwrite() throws Exception {
+        String name = "new";
+        Collection child = collection.createCollection(name, new Configuration(
+                DOMParser.toDocument(
+                        "<collection compressed='true' name='" + name + "' inline-metadata='true'>" +
+                        "<filer class='org.apache.xindice.core.filer.BTreeFiler' />" +
+                        "</collection>"), false
+        ));
+
+
+        httpRequest.addHeader("Destination", collection.getCanonicalName() + "/" + name + "/resource");
+        httpRequest.addHeader("Overwrite", "F");
+
+        String xml1 = "<test1 document='true'>This is the test XML</test1>";
+        Document document1 = DOMParser.toDocument(xml1);
+
+        String xml2 = "<test2 document='true'>This is the test XML</test2>";
+        Document document2 = DOMParser.toDocument(xml2);
+
+        String docName = "resource";
+        collection.setDocument(docName, document1);
+        child.setDocument(docName, document2);
+
+        method.execute(request, response, new Location(collection.getCanonicalDocumentName(docName)));
+        assertEquals(WebdavStatus.SC_PRECONDITION_FAILED, httpResponse.getStatus());
+        assertEquals(document2.toString(), child.getDocument(docName).toString());
+    }
+
+    public void testCopyCollectionZeroDepth() throws Exception {
+        String name = "new";
+
+        httpRequest.addHeader("Destination", collection.getCanonicalName() + "/" + name);
+        httpRequest.addHeader("Depth", "0");
+
+        String xml = "<test document='true'>This is the test XML</test>";
+        Document document = DOMParser.toDocument(xml);
+
+        String docName = "resource";
+        collection.setDocument(docName, document);
+
+        method.execute(request, response, new Location(collection.getCanonicalName()));
+        assertEquals(WebdavStatus.SC_CREATED, httpResponse.getStatus());
+
+        Collection child = collection.getCollection(name);
+        assertNotNull(child);
+        assertEquals(child.getDocumentCount(), 0);
+    }
+
+    public void testCopyCollection() throws Exception {
+        String childName = "col1";
+        Collection col1 = collection.createCollection(childName, new Configuration(
+                DOMParser.toDocument(
+                        "<collection compressed='true' name='" + childName + "' inline-metadata='true'>" +
+                        "<filer class='org.apache.xindice.core.filer.BTreeFiler' />" +
+                        "</collection>"), false
+        ));
+
+        int docs = 50;
+        for (int i = 0; i < docs; i++) {
+            String xml = "<test document='true'>This is the test XML " + i + "</test>";
+            Document document = DOMParser.toDocument(xml);
+
+            String docName = "resource" + i;
+            collection.setDocument(docName, document);
+        }
+
+        for (int i = 0; i < docs; i++) {
+            String xml = "<test>This is the inner collection test XML " + i + "</test>";
+            Document document = DOMParser.toDocument(xml);
+
+            String docName = "resource" + i;
+            col1.setDocument(docName, document);
+        }
+
+        Collection destParent = null;
+        try {
+            String destName = "new";
+            destParent = db.createCollection(destName, new Configuration(
+                    DOMParser.toDocument(
+                            "<collection compressed='true' name='" + destName + "' inline-metadata='true'>" +
+                            "<filer class='org.apache.xindice.core.filer.BTreeFiler' />" +
+                            "</collection>"), false
+            ));
+
+            String destColName = "dest";
+            httpRequest.addHeader("Destination", destParent.getCanonicalName() + "/" + destColName);
+
+            method.execute(request, response, new Location(collection.getCanonicalName()));
+            assertEquals(WebdavStatus.SC_CREATED, httpResponse.getStatus());
+            Collection destCollection = destParent.getCollection(destColName);
+            assertNotNull(destCollection);
+            assertEquals(destCollection.getDocumentCount(), 50);
+
+            Collection child = destCollection.getCollection(childName);
+            assertNotNull(child);
+            assertEquals(child.getDocumentCount(), 50);
+        } finally {
+            if (destParent != null) {
+                db.dropCollection(destParent);
+            }
+        }
+    }
+}

Propchange: xml/xindice/trunk/java/tests/src/org/apache/xindice/webadmin/CopyTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: xml/xindice/trunk/java/tests/src/org/apache/xindice/webadmin/CopyTest.java
------------------------------------------------------------------------------
    svn:keywords = Id Revision Author Date

Added: xml/xindice/trunk/java/tests/src/org/apache/xindice/webadmin/DeleteTest.java
URL: http://svn.apache.org/viewvc/xml/xindice/trunk/java/tests/src/org/apache/xindice/webadmin/DeleteTest.java?view=auto&rev=541505
==============================================================================
--- xml/xindice/trunk/java/tests/src/org/apache/xindice/webadmin/DeleteTest.java (added)
+++ xml/xindice/trunk/java/tests/src/org/apache/xindice/webadmin/DeleteTest.java Thu May 24 18:44:37 2007
@@ -0,0 +1,73 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.xindice.webadmin;
+
+import org.apache.xindice.webadmin.webdav.components.Delete;
+import org.apache.xindice.webadmin.webdav.WebdavStatus;
+import org.apache.xindice.xml.dom.DOMParser;
+import org.apache.xindice.util.Configuration;
+import org.apache.xindice.core.Collection;
+
+public class DeleteTest extends MethodSetup {
+
+    public void setUp() throws Exception {
+        super.setUp();
+        method = new Delete();
+    }
+
+    public void testDeleteNullCollection() throws Exception {
+        // collection was not found: one or more intermediate collections do not exist
+        method.execute(request, response, new Location("/unknown"));
+        assertEquals(WebdavStatus.SC_NOT_FOUND, httpResponse.getStatus());
+    }
+
+    public void testDeleteNotExistingResource() throws Exception {
+        method.execute(request, response, new Location(collection.getCanonicalName() +  "/doesnotexist"));
+        assertEquals(WebdavStatus.SC_NOT_FOUND, httpResponse.getStatus());
+    }
+
+    public void testDeleteExistingResource() throws Exception {
+        String name = "resource";
+        collection.setDocument(name, DOMParser.toDocument("<test/>"));
+        method.execute(request, response, new Location(collection.getCanonicalDocumentName(name)));
+        assertEquals(WebdavStatus.SC_NO_CONTENT, httpResponse.getStatus());
+        assertNull(collection.getDocument(name));
+    }
+
+    public void testDeleteCollectionWithDepth() throws Exception {
+        httpRequest.addHeader("Depth", "0");
+        method.execute(request, response, new Location(collection.getCanonicalName()));
+        assertEquals(WebdavStatus.SC_BAD_REQUEST, httpResponse.getStatus());
+    }
+
+    public void testDeleteCollection() throws Exception {
+        String name = "new";
+        Collection child = collection.createCollection(name, new Configuration(
+                DOMParser.toDocument(
+                        "<collection compressed='true' name='" + name + "' inline-metadata='true'>" +
+                        "<filer class='org.apache.xindice.core.filer.BTreeFiler' />" +
+                        "</collection>"), false
+        ));
+
+        method.execute(request, response, new Location(child.getCanonicalName()));
+        assertEquals(WebdavStatus.SC_NO_CONTENT, httpResponse.getStatus());
+        assertNull(collection.getCollection(name));
+    }
+
+    //TODO: test SC_FORBIDDEN
+}

Propchange: xml/xindice/trunk/java/tests/src/org/apache/xindice/webadmin/DeleteTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: xml/xindice/trunk/java/tests/src/org/apache/xindice/webadmin/DeleteTest.java
------------------------------------------------------------------------------
    svn:keywords = Id Revision Author Date

Added: xml/xindice/trunk/java/tests/src/org/apache/xindice/webadmin/HttpServletRequestMockup.java
URL: http://svn.apache.org/viewvc/xml/xindice/trunk/java/tests/src/org/apache/xindice/webadmin/HttpServletRequestMockup.java?view=auto&rev=541505
==============================================================================
--- xml/xindice/trunk/java/tests/src/org/apache/xindice/webadmin/HttpServletRequestMockup.java (added)
+++ xml/xindice/trunk/java/tests/src/org/apache/xindice/webadmin/HttpServletRequestMockup.java Thu May 24 18:44:37 2007
@@ -0,0 +1,259 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.xindice.webadmin;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.Cookie;
+import javax.servlet.http.HttpSession;
+import javax.servlet.ServletInputStream;
+import javax.servlet.RequestDispatcher;
+import java.util.Enumeration;
+import java.util.Map;
+import java.util.Locale;
+import java.util.HashMap;
+import java.security.Principal;
+import java.io.UnsupportedEncodingException;
+import java.io.IOException;
+import java.io.BufferedReader;
+import java.io.ByteArrayInputStream;
+import java.io.InputStream;
+
+class HttpServletRequestMockup implements HttpServletRequest {
+    byte[] input;
+    private int contentLength;
+    private HashMap headers = new HashMap();
+    private String pathInfo;
+
+    public String getAuthType() {
+        return null;
+    }
+
+    public Cookie[] getCookies() {
+        return new Cookie[0];
+    }
+
+    public long getDateHeader(String header) {
+        return 0;
+    }
+
+    public String getHeader(String header) {
+        return (String) headers.get(header);
+    }
+
+    public void addHeader(String header, String value) {
+        headers.put(header, value);
+    }
+
+    public Enumeration getHeaders(String header) {
+        return null;
+    }
+
+    public Enumeration getHeaderNames() {
+        return null;
+    }
+
+    public int getIntHeader(String header) {
+        return 0;
+    }
+
+    public String getMethod() {
+        return null;
+    }
+
+    public String getPathInfo() {
+        return pathInfo;
+    }
+
+    public String getPathTranslated() {
+        return null;
+    }
+
+    public String getContextPath() {
+        return "";
+    }
+
+    public String getQueryString() {
+        return null;
+    }
+
+    public String getRemoteUser() {
+        return null;
+    }
+
+    public boolean isUserInRole(String docNum) {
+        return false;
+    }
+
+    public Principal getUserPrincipal() {
+        return null;
+    }
+
+    public String getRequestedSessionId() {
+        return null;
+    }
+
+    public String getRequestURI() {
+        return null;
+    }
+
+    public StringBuffer getRequestURL() {
+        return null;
+    }
+
+    public String getServletPath() {
+        return "";
+    }
+
+    public HttpSession getSession(boolean b) {
+        return null;
+    }
+
+    public HttpSession getSession() {
+        return null;
+    }
+
+    public boolean isRequestedSessionIdValid() {
+        return false;
+    }
+
+    public boolean isRequestedSessionIdFromCookie() {
+        return false;
+    }
+
+    public boolean isRequestedSessionIdFromURL() {
+        return false;
+    }
+
+    public boolean isRequestedSessionIdFromUrl() {
+        return false;
+    }
+
+    public Object getAttribute(String docNum) {
+        return null;
+    }
+
+    public Enumeration getAttributeNames() {
+        return null;
+    }
+
+    public String getCharacterEncoding() {
+        return null;
+    }
+
+    public void setCharacterEncoding(String docNum) throws UnsupportedEncodingException {
+
+    }
+
+    public int getContentLength() {
+        return contentLength;
+    }
+
+    public String getContentType() {
+        return null;
+    }
+
+    public void setInput(String input) {
+        this.input = input.getBytes();
+        contentLength = input.length();
+    }
+
+    public ServletInputStream getInputStream() throws IOException {
+        final InputStream in = new ByteArrayInputStream(input);
+        return new ServletInputStream() {
+            public int read() throws IOException {
+                return in.read();
+            }
+        };
+    }
+
+    public String getParameter(String docNum) {
+        return null;
+    }
+
+    public Enumeration getParameterNames() {
+        return null;
+    }
+
+    public String[] getParameterValues(String docNum) {
+        return new String[0];
+    }
+
+    public Map getParameterMap() {
+        return null;
+    }
+
+    public String getProtocol() {
+        return "HTTP/1.1";
+    }
+
+    public String getScheme() {
+        return null;
+    }
+
+    public String getServerName() {
+        return null;
+    }
+
+    public int getServerPort() {
+        return 0;
+    }
+
+    public BufferedReader getReader() throws IOException {
+        return null;
+    }
+
+    public String getRemoteAddr() {
+        return null;
+    }
+
+    public String getRemoteHost() {
+        return null;
+    }
+
+    public void setAttribute(String docNum, Object object) {
+
+    }
+
+    public void removeAttribute(String docNum) {
+
+    }
+
+    public Locale getLocale() {
+        return null;
+    }
+
+    public Enumeration getLocales() {
+        return null;
+    }
+
+    public boolean isSecure() {
+        return false;
+    }
+
+    public RequestDispatcher getRequestDispatcher(String docNum) {
+        return null;
+    }
+
+    public String getRealPath(String docNum) {
+        return null;
+    }
+
+    public void setPathInfo(String pathInfo) {
+        this.pathInfo = pathInfo;
+    }
+}

Propchange: xml/xindice/trunk/java/tests/src/org/apache/xindice/webadmin/HttpServletRequestMockup.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: xml/xindice/trunk/java/tests/src/org/apache/xindice/webadmin/HttpServletRequestMockup.java
------------------------------------------------------------------------------
    svn:keywords = Id Revision Author Date

Added: xml/xindice/trunk/java/tests/src/org/apache/xindice/webadmin/HttpServletResponseMockup.java
URL: http://svn.apache.org/viewvc/xml/xindice/trunk/java/tests/src/org/apache/xindice/webadmin/HttpServletResponseMockup.java?view=auto&rev=541505
==============================================================================
--- xml/xindice/trunk/java/tests/src/org/apache/xindice/webadmin/HttpServletResponseMockup.java (added)
+++ xml/xindice/trunk/java/tests/src/org/apache/xindice/webadmin/HttpServletResponseMockup.java Thu May 24 18:44:37 2007
@@ -0,0 +1,163 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.xindice.webadmin;
+
+import javax.servlet.http.HttpServletResponse;
+import javax.servlet.http.Cookie;
+import javax.servlet.ServletOutputStream;
+import java.io.IOException;
+import java.io.PrintWriter;
+import java.io.ByteArrayOutputStream;
+import java.util.Locale;
+
+public class HttpServletResponseMockup implements HttpServletResponse {
+    private int status;
+    private ByteArrayOutputStream out = new ByteArrayOutputStream(1024);
+
+    public void addCookie(Cookie cookie) {
+
+    }
+
+    public boolean containsHeader(String docNum) {
+        return false;
+    }
+
+    public String encodeURL(String docNum) {
+        return null;
+    }
+
+    public String encodeRedirectURL(String docNum) {
+        return null;
+    }
+
+    public String encodeUrl(String docNum) {
+        return null;
+    }
+
+    public String encodeRedirectUrl(String docNum) {
+        return null;
+    }
+
+    public void sendError(int i, String docNum) throws IOException {
+
+    }
+
+    public void sendError(int i) throws IOException {
+
+    }
+
+    public void sendRedirect(String docNum) throws IOException {
+
+    }
+
+    public void setDateHeader(String docNum, long l) {
+
+    }
+
+    public void addDateHeader(String docNum, long l) {
+
+    }
+
+    public void setHeader(String docNum, String docNum1) {
+
+    }
+
+    public void addHeader(String docNum, String docNum1) {
+
+    }
+
+    public void setIntHeader(String docNum, int i) {
+
+    }
+
+    public void addIntHeader(String docNum, int i) {
+
+    }
+
+    public void setStatus(int i) {
+        status = i;
+    }
+
+    public void setStatus(int i, String docNum) {
+
+    }
+
+    public String getCharacterEncoding() {
+        return null;
+    }
+
+    public ServletOutputStream getOutputStream() throws IOException {
+        return new ServletOutputStream() {
+            public void write(int b) {
+                out.write(b);
+            }
+        };
+    }
+
+    public String getResponse() {
+        return out.toString();
+    }
+
+    public PrintWriter getWriter() throws IOException {
+        return null;
+    }
+
+    public void setContentLength(int i) {
+
+    }
+
+    public void setContentType(String docNum) {
+
+    }
+
+    public void setBufferSize(int i) {
+
+    }
+
+    public int getBufferSize() {
+        return 0;
+    }
+
+    public void flushBuffer() throws IOException {
+
+    }
+
+    public void resetBuffer() {
+
+    }
+
+    public boolean isCommitted() {
+        return false;
+    }
+
+    public void reset() {
+
+    }
+
+    public void setLocale(Locale locale) {
+
+    }
+
+    public Locale getLocale() {
+        return null;
+    }
+
+    public int getStatus() {
+        return status;
+    }
+}

Propchange: xml/xindice/trunk/java/tests/src/org/apache/xindice/webadmin/HttpServletResponseMockup.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: xml/xindice/trunk/java/tests/src/org/apache/xindice/webadmin/HttpServletResponseMockup.java
------------------------------------------------------------------------------
    svn:keywords = Id Revision Author Date

Added: xml/xindice/trunk/java/tests/src/org/apache/xindice/webadmin/LocationTest.java
URL: http://svn.apache.org/viewvc/xml/xindice/trunk/java/tests/src/org/apache/xindice/webadmin/LocationTest.java?view=auto&rev=541505
==============================================================================
--- xml/xindice/trunk/java/tests/src/org/apache/xindice/webadmin/LocationTest.java (added)
+++ xml/xindice/trunk/java/tests/src/org/apache/xindice/webadmin/LocationTest.java Thu May 24 18:44:37 2007
@@ -0,0 +1,82 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.xindice.webadmin;
+
+import junit.framework.TestCase;
+import org.apache.xindice.core.Database;
+import org.apache.xindice.core.DatabaseTest;
+import org.apache.xindice.core.Collection;
+import org.apache.xindice.util.Configuration;
+import org.apache.xindice.xml.dom.DOMParser;
+
+
+public class LocationTest extends TestCase {
+    private Database db;
+    private Collection collection;
+
+    public void setUp() throws Exception {
+        String name = getClass().getName();
+        db = Database.getDatabase(new Configuration(DOMParser.toDocument(DatabaseTest.DATABASE)));
+        collection = db.createCollection(name, new Configuration(
+                DOMParser.toDocument(
+                        "<collection compressed=\"true\" name=\"" + name + "\" inline-metadata=\"true\">" +
+                        "<filer class=\"org.apache.xindice.core.filer.BTreeFiler\" />" +
+                        "</collection>"), false
+        ));
+    }
+
+    public void tearDown() throws Exception {
+        db.dropCollection(collection);
+        db.close();
+    }
+
+    public void testRootLocation() throws Exception {
+        Location location = new Location("");
+        assertTrue(location.isRoot());
+        assertNull(location.getCollection());
+        assertNull(location.getName());
+    }
+
+    public void testDbLocation() throws Exception {
+        Location location = new Location(db.getCanonicalName());
+        assertFalse(location.isRoot());
+        assertEquals(location.getCollection(), db);
+        assertNull(location.getName());
+    }
+
+    public void testCollectionNoResourceLocation() throws Exception {
+        Location location = new Location(collection.getCanonicalName());
+        assertFalse(location.isRoot());
+        assertEquals(location.getCollection(), collection);
+        assertNull(location.getName());
+    }
+
+    public void testCollectionResourceLocation() throws Exception {
+        Location location = new Location(collection.getCanonicalDocumentName("doesnotexist"));
+        assertFalse(location.isRoot());
+        assertEquals(location.getCollection(), collection);
+        assertEquals(location.getName(), "doesnotexist");
+    }
+
+    public void testNoCollectionLocation() throws Exception {
+        Location location = new Location(collection.getCanonicalName() + "/doesnotexist/doesnotexist1");
+        assertFalse(location.isRoot());
+        assertNull(location.getCollection());
+        assertNull(location.getName());
+    }
+}

Propchange: xml/xindice/trunk/java/tests/src/org/apache/xindice/webadmin/LocationTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: xml/xindice/trunk/java/tests/src/org/apache/xindice/webadmin/LocationTest.java
------------------------------------------------------------------------------
    svn:keywords = Id Revision Author Date

Added: xml/xindice/trunk/java/tests/src/org/apache/xindice/webadmin/MethodSetup.java
URL: http://svn.apache.org/viewvc/xml/xindice/trunk/java/tests/src/org/apache/xindice/webadmin/MethodSetup.java?view=auto&rev=541505
==============================================================================
--- xml/xindice/trunk/java/tests/src/org/apache/xindice/webadmin/MethodSetup.java (added)
+++ xml/xindice/trunk/java/tests/src/org/apache/xindice/webadmin/MethodSetup.java Thu May 24 18:44:37 2007
@@ -0,0 +1,58 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.xindice.webadmin;
+
+import junit.framework.TestCase;
+import org.apache.xindice.webadmin.webdav.DAVRequest;
+import org.apache.xindice.webadmin.webdav.DAVResponse;
+import org.apache.xindice.webadmin.webdav.components.DAVComponent;
+import org.apache.xindice.core.Database;
+import org.apache.xindice.core.DatabaseTest;
+import org.apache.xindice.core.Collection;
+import org.apache.xindice.util.Configuration;
+import org.apache.xindice.xml.dom.DOMParser;
+
+public class MethodSetup extends TestCase {
+    protected DAVComponent method;
+    protected HttpServletRequestMockup httpRequest = new HttpServletRequestMockup();
+    protected HttpServletResponseMockup httpResponse = new HttpServletResponseMockup();
+    protected DAVRequest request;
+    protected DAVResponse response;
+    protected Database db;
+    protected Collection collection;
+
+    public void setUp() throws Exception {
+        request = new DAVRequest(httpRequest);
+        response = new DAVResponse(httpResponse);
+
+        db = Database.getDatabase(new Configuration(DOMParser.toDocument(DatabaseTest.DATABASE)));
+
+        String name = "webdav_test";
+        collection = db.createCollection(name, new Configuration(
+                DOMParser.toDocument(
+                        "<collection compressed='true' name='" + name + "' inline-metadata='true'>" +
+                        "<filer class='org.apache.xindice.core.filer.BTreeFiler' />" +
+                        "</collection>"), false
+        ));
+    }
+
+    public void tearDown() throws Exception {
+        db.dropCollection(collection);
+        db.close();
+    }
+}

Propchange: xml/xindice/trunk/java/tests/src/org/apache/xindice/webadmin/MethodSetup.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: xml/xindice/trunk/java/tests/src/org/apache/xindice/webadmin/MethodSetup.java
------------------------------------------------------------------------------
    svn:keywords = Id Revision Author Date

Added: xml/xindice/trunk/java/tests/src/org/apache/xindice/webadmin/MkcolTest.java
URL: http://svn.apache.org/viewvc/xml/xindice/trunk/java/tests/src/org/apache/xindice/webadmin/MkcolTest.java?view=auto&rev=541505
==============================================================================
--- xml/xindice/trunk/java/tests/src/org/apache/xindice/webadmin/MkcolTest.java (added)
+++ xml/xindice/trunk/java/tests/src/org/apache/xindice/webadmin/MkcolTest.java Thu May 24 18:44:37 2007
@@ -0,0 +1,57 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.xindice.webadmin;
+
+import org.apache.xindice.webadmin.webdav.components.Mkcol;
+import org.apache.xindice.webadmin.webdav.WebdavStatus;
+
+public class MkcolTest extends MethodSetup {
+
+    public void setUp() throws Exception {
+        super.setUp();
+        method = new Mkcol();
+    }
+
+    public void testMkcolNullCollection() throws Exception {
+        // collection was not found: one or more intermediate collections do not exist
+        method.execute(request, response, new Location("/unknown"));
+        assertEquals(WebdavStatus.SC_CONFLICT, httpResponse.getStatus());
+    }
+
+    public void testMkcolExistingCollection() throws Exception {
+        // collection already exists
+        method.execute(request, response, new Location(collection.getCanonicalName()));
+        assertEquals(WebdavStatus.SC_METHOD_NOT_ALLOWED, httpResponse.getStatus());
+    }
+
+    public void testMkcolCollection() throws Exception {
+        String name = "new";
+
+        method.execute(request, response, new Location(collection.getCanonicalDocumentName(name)));
+        assertEquals(WebdavStatus.SC_CREATED, httpResponse.getStatus());
+        assertNotNull(collection.getCollection(name));
+    }
+
+    public void testMkcolCollectionRequestBody() throws Exception {
+        httpRequest.setInput("<test/>");
+        method.execute(request, response, new Location(collection.getCanonicalDocumentName("new")));
+        assertEquals(WebdavStatus.SC_UNSUPPORTED_MEDIA_TYPE, httpResponse.getStatus());
+    }
+
+    //TODO: test SC_FORBIDDEN
+}

Propchange: xml/xindice/trunk/java/tests/src/org/apache/xindice/webadmin/MkcolTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: xml/xindice/trunk/java/tests/src/org/apache/xindice/webadmin/MkcolTest.java
------------------------------------------------------------------------------
    svn:keywords = Id Revision Author Date

Added: xml/xindice/trunk/java/tests/src/org/apache/xindice/webadmin/MoveTest.java
URL: http://svn.apache.org/viewvc/xml/xindice/trunk/java/tests/src/org/apache/xindice/webadmin/MoveTest.java?view=auto&rev=541505
==============================================================================
--- xml/xindice/trunk/java/tests/src/org/apache/xindice/webadmin/MoveTest.java (added)
+++ xml/xindice/trunk/java/tests/src/org/apache/xindice/webadmin/MoveTest.java Thu May 24 18:44:37 2007
@@ -0,0 +1,190 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.xindice.webadmin;
+
+import org.apache.xindice.webadmin.webdav.components.Move;
+import org.apache.xindice.webadmin.webdav.WebdavStatus;
+import org.apache.xindice.xml.dom.DOMParser;
+import org.apache.xindice.core.Collection;
+import org.apache.xindice.util.Configuration;
+import org.w3c.dom.Document;
+
+public class MoveTest extends MethodSetup {
+
+    public void setUp() throws Exception {
+        super.setUp();
+        method = new Move();
+    }
+
+    public void testMoveNullCollection() throws Exception {
+        // source collection was not found
+        method.execute(request, response, new Location("/unknown"));
+        assertEquals(WebdavStatus.SC_NOT_FOUND, httpResponse.getStatus());
+    }
+
+    public void testMoveNoDestination() throws Exception {
+        // request does not have a Destination header
+        method.execute(request, response, new Location(collection.getCanonicalName()));
+        assertEquals(WebdavStatus.SC_BAD_REQUEST, httpResponse.getStatus());
+
+        method.execute(request, response, new Location(collection.getCanonicalDocumentName("test")));
+        assertEquals(WebdavStatus.SC_BAD_REQUEST, httpResponse.getStatus());
+    }
+
+    public void testMoveSamePathResource() throws Exception {
+        httpRequest.setPathInfo("/db/test");
+        httpRequest.addHeader("Destination", "/db/test");
+        method.execute(request, response, new Location(collection.getCanonicalDocumentName("test")));
+        assertEquals(WebdavStatus.SC_FORBIDDEN, httpResponse.getStatus());
+    }
+
+    public void testMoveSamePathCollection() throws Exception {
+        httpRequest.setPathInfo(collection.getCanonicalName());
+        httpRequest.addHeader("Destination", collection.getCanonicalName() + "/new");
+        method.execute(request, response, new Location(collection.getCanonicalName()));
+        assertEquals(WebdavStatus.SC_FORBIDDEN, httpResponse.getStatus());
+
+        httpRequest.setPathInfo(collection.getCanonicalName());
+        httpRequest.addHeader("Destination", collection.getCanonicalName());
+        method.execute(request, response, new Location(collection.getCanonicalName()));
+        assertEquals(WebdavStatus.SC_FORBIDDEN, httpResponse.getStatus());
+    }
+
+    public void testMoveResourceNullDestCollection() throws Exception {
+        // destination collection does not exist
+        httpRequest.addHeader("Destination", collection.getCanonicalName() + "/test/resource");
+
+        String xml = "<test document='true'>This is the test XML</test>";
+        Document document = DOMParser.toDocument(xml);
+
+        collection.setDocument("resource", document);
+
+        method.execute(request, response, new Location(collection.getCanonicalDocumentName("resource")));
+        assertEquals(WebdavStatus.SC_CONFLICT, httpResponse.getStatus());
+    }
+
+    public void testMoveResource() throws Exception {
+        String name = "new";
+        Collection child = collection.createCollection(name, new Configuration(
+                DOMParser.toDocument(
+                        "<collection compressed='true' name='" + name + "' inline-metadata='true'>" +
+                        "<filer class='org.apache.xindice.core.filer.BTreeFiler' />" +
+                        "</collection>"), false
+        ));
+
+        httpRequest.addHeader("Destination", collection.getCanonicalName() + "/" + name + "/resource");
+
+        String xml = "<test document='true'>This is the test XML</test>";
+        Document document = DOMParser.toDocument(xml);
+
+        String docName = "resource";
+        collection.setDocument(docName, document);
+
+        method.execute(request, response, new Location(collection.getCanonicalDocumentName(docName)));
+        assertEquals(WebdavStatus.SC_CREATED, httpResponse.getStatus());
+        assertNotNull(child.getDocument(docName));
+        assertEquals(document.toString(), child.getDocument(docName).toString());
+        assertNull(collection.getDocument(docName));
+    }
+
+    public void testMoveResourceNoOverwrite() throws Exception {
+        String name = "new";
+        Collection child = collection.createCollection(name, new Configuration(
+                DOMParser.toDocument(
+                        "<collection compressed='true' name='" + name + "' inline-metadata='true'>" +
+                        "<filer class='org.apache.xindice.core.filer.BTreeFiler' />" +
+                        "</collection>"), false
+        ));
+
+
+        httpRequest.addHeader("Destination", collection.getCanonicalName() + "/" + name + "/resource");
+        httpRequest.addHeader("Overwrite", "F");
+
+        String xml1 = "<test1 document='true'>This is the test XML</test1>";
+        Document document1 = DOMParser.toDocument(xml1);
+
+        String xml2 = "<test2 document='true'>This is the test XML</test2>";
+        Document document2 = DOMParser.toDocument(xml2);
+
+        String docName = "resource";
+        collection.setDocument(docName, document1);
+        child.setDocument(docName, document2);
+
+        method.execute(request, response, new Location(collection.getCanonicalDocumentName(docName)));
+        assertEquals(WebdavStatus.SC_PRECONDITION_FAILED, httpResponse.getStatus());
+        assertNotNull(collection.getDocument(docName));
+        assertEquals(document2.toString(), child.getDocument(docName).toString());
+    }
+
+    public void testMoveCollection() throws Exception {
+        String childName = "col1";
+        Collection col1 = collection.createCollection(childName, new Configuration(
+                DOMParser.toDocument(
+                        "<collection compressed='true' name='" + childName + "' inline-metadata='true'>" +
+                        "<filer class='org.apache.xindice.core.filer.BTreeFiler' />" +
+                        "</collection>"), false
+        ));
+
+        int docs = 50;
+        for (int i = 0; i < docs; i++) {
+            String xml = "<test document='true'>This is the test XML " + i + "</test>";
+            Document document = DOMParser.toDocument(xml);
+
+            String docName = "resource" + i;
+            collection.setDocument(docName, document);
+        }
+
+        for (int i = 0; i < docs; i++) {
+            String xml = "<test>This is the inner collection test XML " + i + "</test>";
+            Document document = DOMParser.toDocument(xml);
+
+            String docName = "resource" + i;
+            col1.setDocument(docName, document);
+        }
+
+        Collection destParent = null;
+        try {
+            String destName = "new";
+            destParent = db.createCollection(destName, new Configuration(
+                    DOMParser.toDocument(
+                            "<collection compressed='true' name='" + destName + "' inline-metadata='true'>" +
+                            "<filer class='org.apache.xindice.core.filer.BTreeFiler' />" +
+                            "</collection>"), false
+            ));
+
+            String destColName = "dest";
+            httpRequest.addHeader("Destination", destParent.getCanonicalName() + "/" + destColName);
+
+            method.execute(request, response, new Location(collection.getCanonicalName()));
+            assertEquals(WebdavStatus.SC_CREATED, httpResponse.getStatus());
+            Collection destCollection = destParent.getCollection(destColName);
+            assertNotNull(destCollection);
+            assertEquals(destCollection.getDocumentCount(), 50);
+
+            Collection child = destCollection.getCollection(childName);
+            assertNotNull(child);
+            assertEquals(child.getDocumentCount(), 50);
+
+            assertNull(db.getCollection(collection.getName()));
+        } finally {
+            if (destParent != null) {
+                db.dropCollection(destParent);
+            }
+        }
+    }
+}

Propchange: xml/xindice/trunk/java/tests/src/org/apache/xindice/webadmin/MoveTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: xml/xindice/trunk/java/tests/src/org/apache/xindice/webadmin/MoveTest.java
------------------------------------------------------------------------------
    svn:keywords = Id Revision Author Date

Added: xml/xindice/trunk/java/tests/src/org/apache/xindice/webadmin/PropfindTest.java
URL: http://svn.apache.org/viewvc/xml/xindice/trunk/java/tests/src/org/apache/xindice/webadmin/PropfindTest.java?view=auto&rev=541505
==============================================================================
--- xml/xindice/trunk/java/tests/src/org/apache/xindice/webadmin/PropfindTest.java (added)
+++ xml/xindice/trunk/java/tests/src/org/apache/xindice/webadmin/PropfindTest.java Thu May 24 18:44:37 2007
@@ -0,0 +1,310 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.xindice.webadmin;
+
+import org.apache.xindice.webadmin.webdav.components.Propfind;
+import org.apache.xindice.webadmin.webdav.components.props.CreationDate;
+import org.apache.xindice.webadmin.webdav.components.props.LastModified;
+import org.apache.xindice.webadmin.webdav.WebdavStatus;
+import org.apache.xindice.xml.dom.DOMParser;
+import org.apache.xindice.util.Configuration;
+import org.apache.xindice.core.Collection;
+import org.apache.xindice.core.data.Entry;
+import org.custommonkey.xmlunit.XMLAssert;
+import org.xml.sax.SAXException;
+
+public class PropfindTest extends MethodSetup {
+    private CreationDate creationDate = new CreationDate();
+    private LastModified lastModified = new LastModified();
+    private final String DOC_NAME1 = "testDoc1";
+    private final String DOC_NAME2 = "testDoc2";
+    private Collection child;
+
+    public void setUp() throws Exception {
+        super.setUp();
+        String doc = "<test>Test document</test>";
+        collection.insertDocument(DOC_NAME1, DOMParser.toDocument(doc));
+        child = collection.createCollection("child", new Configuration(
+                DOMParser.toDocument(
+                        "<collection compressed='true' name='" + "child" + "' inline-metadata='true'>" +
+                        "<filer class='org.apache.xindice.core.filer.BTreeFiler' />" +
+                        "</collection>"), false
+        ));
+
+        child.insertDocument(DOC_NAME2, DOMParser.toDocument(doc));
+        method = new Propfind();
+    }
+
+    public void testListNullCollection() throws Exception {
+        // source collection was not found
+        method.execute(request, response, new Location("/unknown"));
+        assertEquals(WebdavStatus.SC_NOT_FOUND, httpResponse.getStatus());
+    }
+
+    public void testListNullResource() throws Exception {
+        String path = collection.getCanonicalDocumentName("unknown");
+        httpRequest.setPathInfo(path);
+        httpRequest.setInput("<?xml version='1.0' encoding='utf-8' ?>" +
+                             "<propfind xmlns='DAV:'><allprop/></propfind>");
+        method.execute(request, response, new Location(path));
+        assertEquals(WebdavStatus.SC_NOT_FOUND, httpResponse.getStatus());
+    }
+
+    public void testListEmptyRequestBody() throws Exception {
+        httpRequest.setPathInfo(collection.getCanonicalName());
+        httpRequest.setInput("<?xml version='1.0' encoding='utf-8' ?>" +
+                             "<propfind xmlns='DAV:'><allprop/></propfind>");
+        method.execute(request, response, new Location(collection.getCanonicalName()));
+
+        Entry entry1 = collection.getEntry(DOC_NAME1);
+        Entry entry2 = child.getEntry(DOC_NAME2);
+        assertEquals(WebdavStatus.SC_MULTI_STATUS, httpResponse.getStatus());
+        String expected =
+                "<?xml version='1.0' encoding='utf-8' ?>" +
+                "<multistatus xmlns='DAV:'>\n" +
+                    "<response>" +
+                        "<href>" + collection.getCanonicalName() + "/</href>" +
+                        "<propstat>" +
+                            "<prop>" +
+                                "<resourcetype><collection/></resourcetype>" +
+                                "<getlastmodified>" + lastModified.getProperty(collection).getValue() + "</getlastmodified>" +
+                                "<displayname>" + collection.getName() + "</displayname>" +
+                                "<creationdate>" + creationDate.getProperty(collection).getValue() + "</creationdate>" +
+                            "</prop>" +
+                            "<status>HTTP/1.1 200 OK</status>" +
+                        "</propstat>" +
+                    "</response>\n" +
+                    "<response>" +
+                        "<href>" + collection.getCanonicalDocumentName(DOC_NAME1) + "</href>" +
+                        "<propstat>" +
+                            "<prop>" +
+                                "<resourcetype/>" +
+                                "<getcontenttype>text/xml</getcontenttype>" +
+                                "<getlastmodified>" + lastModified.getProperty(entry1).getValue() + "</getlastmodified>" +
+                                "<displayname>" + DOC_NAME1 + "</displayname>" +
+                                "<creationdate>" + creationDate.getProperty(entry1).getValue() + "</creationdate>" +
+                            "</prop>" +
+                            "<status>HTTP/1.1 200 OK</status>" +
+                        "</propstat>" +
+                    "</response>\n" +
+                    "<response>" +
+                        "<href>" + child.getCanonicalName() + "/</href>" +
+                        "<propstat>" +
+                            "<prop>" +
+                                "<resourcetype><collection/></resourcetype>" +
+                                "<getlastmodified>" + lastModified.getProperty(child).getValue() + "</getlastmodified>" +
+                                "<displayname>" + child.getName() + "</displayname>" +
+                                "<creationdate>" + creationDate.getProperty(child).getValue() + "</creationdate>" +
+                            "</prop>" +
+                            "<status>HTTP/1.1 200 OK</status>" +
+                        "</propstat>" +
+                    "</response>\n" +
+                    "<response>" +
+                        "<href>" + child.getCanonicalDocumentName(DOC_NAME2) + "</href>" +
+                        "<propstat>" +
+                            "<prop>" +
+                                "<resourcetype/>" +
+                                "<getcontenttype>text/xml</getcontenttype>" +
+                                "<getlastmodified>" + lastModified.getProperty(entry2).getValue() + "</getlastmodified>" +
+                                "<displayname>" + DOC_NAME2 + "</displayname>" +
+                                "<creationdate>" + creationDate.getProperty(entry2).getValue() + "</creationdate>" +
+                            "</prop>" +
+                            "<status>HTTP/1.1 200 OK</status>" +
+                        "</propstat>" +
+                    "</response>\n" +
+                "</multistatus>";
+
+        assertXMLEqual(expected, httpResponse.getResponse());
+    }
+
+    public void testListAllProp() throws Exception {
+        // request does not have a body, should be treated as allprop
+        httpRequest.addHeader("Depth", "0");
+        httpRequest.setPathInfo(collection.getCanonicalName());
+        method.execute(request, response, new Location(collection.getCanonicalName()));
+
+        assertEquals(WebdavStatus.SC_MULTI_STATUS, httpResponse.getStatus());
+        String expected =
+                "<?xml version='1.0' encoding='utf-8' ?>" +
+                "<multistatus xmlns='DAV:'>\n" +
+                    "<response>" +
+                        "<href>" + collection.getCanonicalName() + "/</href>" +
+                        "<propstat>" +
+                            "<prop>" +
+                                "<resourcetype><collection/></resourcetype>" +
+                                "<getlastmodified>" + lastModified.getProperty(collection).getValue() + "</getlastmodified>" +
+                                "<displayname>" + collection.getName() + "</displayname>" +
+                                "<creationdate>" + creationDate.getProperty(collection).getValue() + "</creationdate>" +
+                            "</prop>" +
+                            "<status>HTTP/1.1 200 OK</status>" +
+                        "</propstat>" +
+                    "</response>\n" +
+                "</multistatus>";
+
+        assertXMLEqual(expected, httpResponse.getResponse());
+    }
+
+    public void testListNamedProperties() throws Exception {
+        httpRequest.addHeader("Depth", "infinity");
+        httpRequest.setPathInfo(collection.getCanonicalName());
+        httpRequest.setInput("<?xml version='1.0' encoding='utf-8' ?>" +
+                             "<propfind xmlns='DAV:'>" +
+                             "<prop>" +
+                             "<displayname/><resourcetype/><unknown/><getcontenttype/>" +
+                             "</prop>" +
+                             "</propfind>");
+        method.execute(request, response, new Location(collection.getCanonicalName()));
+
+        assertEquals(WebdavStatus.SC_MULTI_STATUS, httpResponse.getStatus());
+        String expected =
+                "<?xml version='1.0' encoding='utf-8' ?>" +
+                "<multistatus xmlns='DAV:'>\n" +
+                    "<response>" +
+                        "<href>" + collection.getCanonicalName() + "/</href>" +
+                        "<propstat>" +
+                            "<prop>" +
+                                "<resourcetype><collection/></resourcetype>" +
+                                "<displayname>" + collection.getName() + "</displayname>" +
+                            "</prop>" +
+                            "<status>HTTP/1.1 200 OK</status>" +
+                        "</propstat>" +
+                        "<propstat>" +
+                            "<prop>" +
+                                "<unknown/>" +
+                                "<getcontenttype/>" +
+                            "</prop>" +
+                            "<status>HTTP/1.1 404 Not Found</status>" +
+                        "</propstat>" +
+                    "</response>\n" +
+                    "<response>" +
+                        "<href>" + collection.getCanonicalDocumentName(DOC_NAME1) + "</href>" +
+                        "<propstat>" +
+                            "<prop>" +
+                                "<resourcetype/>" +
+                                "<getcontenttype>text/xml</getcontenttype>" +
+                                "<displayname>" + DOC_NAME1 + "</displayname>" +
+                            "</prop>" +
+                            "<status>HTTP/1.1 200 OK</status>" +
+                        "</propstat>" +
+                        "<propstat>" +
+                            "<prop>" +
+                                "<unknown/>" +
+                            "</prop>" +
+                            "<status>HTTP/1.1 404 Not Found</status>" +
+                        "</propstat>" +
+                    "</response>\n" +
+                    "<response>" +
+                        "<href>" + child.getCanonicalName() + "/</href>" +
+                        "<propstat>" +
+                            "<prop>" +
+                                "<resourcetype><collection/></resourcetype>" +
+                                "<displayname>" + child.getName() + "</displayname>" +
+                            "</prop>" +
+                            "<status>HTTP/1.1 200 OK</status>" +
+                        "</propstat>" +
+                        "<propstat>" +
+                            "<prop>" +
+                                "<unknown/>" +
+                                "<getcontenttype/>" +
+                            "</prop>" +
+                            "<status>HTTP/1.1 404 Not Found</status>" +
+                        "</propstat>" +
+                    "</response>\n" +
+                    "<response>" +
+                        "<href>" + child.getCanonicalDocumentName(DOC_NAME2) + "</href>" +
+                        "<propstat>" +
+                            "<prop>" +
+                                "<resourcetype/>" +
+                                "<getcontenttype>text/xml</getcontenttype>" +
+                                "<displayname>" + DOC_NAME2 + "</displayname>" +
+                            "</prop>" +
+                            "<status>HTTP/1.1 200 OK</status>" +
+                        "</propstat>" +
+                        "<propstat>" +
+                            "<prop>" +
+                                "<unknown/>" +
+                            "</prop>" +
+                            "<status>HTTP/1.1 404 Not Found</status>" +
+                        "</propstat>" +
+                    "</response>\n" +
+                "</multistatus>";
+
+        assertXMLEqual(expected, httpResponse.getResponse());
+    }
+
+    public void testListPropertyNames() throws Exception {
+        httpRequest.addHeader("Depth", "1");
+        httpRequest.setPathInfo(collection.getCanonicalName());
+        httpRequest.setInput("<?xml version='1.0' encoding='utf-8' ?>" +
+                             "<propfind xmlns='DAV:'><propname/></propfind>");
+        method.execute(request, response, new Location(collection.getCanonicalName()));
+
+        assertEquals(WebdavStatus.SC_MULTI_STATUS, httpResponse.getStatus());
+        String expected =
+                "<?xml version='1.0' encoding='utf-8' ?>" +
+                "<multistatus xmlns='DAV:'>\n" +
+                    "<response>" +
+                        "<href>" + collection.getCanonicalName() + "/</href>" +
+                        "<propstat>" +
+                            "<prop>" +
+                                "<resourcetype/>" +
+                                "<displayname/>" +
+                                "<getlastmodified/>" +
+                                "<creationdate/>" +
+                            "</prop>" +
+                            "<status>HTTP/1.1 200 OK</status>" +
+                        "</propstat>" +
+                    "</response>\n" +
+                    "<response>" +
+                        "<href>" + collection.getCanonicalDocumentName(DOC_NAME1) + "</href>" +
+                        "<propstat>" +
+                            "<prop>" +
+                                "<resourcetype/>" +
+                                "<displayname/>" +
+                                "<getcontenttype/>" +
+                                "<getlastmodified/>" +
+                                "<creationdate/>" +
+                            "</prop>" +
+                            "<status>HTTP/1.1 200 OK</status>" +
+                        "</propstat>" +
+                    "</response>\n" +
+                    "<response>" +
+                        "<href>" + child.getCanonicalName() + "/</href>" +
+                        "<propstat>" +
+                            "<prop>" +
+                                "<resourcetype/>" +
+                                "<displayname/>" +
+                                "<getlastmodified/>" +
+                                "<creationdate/>" +
+                            "</prop>" +
+                            "<status>HTTP/1.1 200 OK</status>" +
+                        "</propstat>" +
+                    "</response>\n" +
+                "</multistatus>";
+
+        assertXMLEqual(expected, httpResponse.getResponse());
+    }
+
+    protected void assertXMLEqual(String control, String result) throws Exception {
+        try {
+            XMLAssert.assertXMLEqual(control, result);
+        } catch (SAXException e) {
+            fail(e.getLocalizedMessage());
+        }
+    }
+}

Propchange: xml/xindice/trunk/java/tests/src/org/apache/xindice/webadmin/PropfindTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: xml/xindice/trunk/java/tests/src/org/apache/xindice/webadmin/PropfindTest.java
------------------------------------------------------------------------------
    svn:keywords = Id Revision Author Date

Added: xml/xindice/trunk/java/tests/src/org/apache/xindice/webadmin/PutTest.java
URL: http://svn.apache.org/viewvc/xml/xindice/trunk/java/tests/src/org/apache/xindice/webadmin/PutTest.java?view=auto&rev=541505
==============================================================================
--- xml/xindice/trunk/java/tests/src/org/apache/xindice/webadmin/PutTest.java (added)
+++ xml/xindice/trunk/java/tests/src/org/apache/xindice/webadmin/PutTest.java Thu May 24 18:44:37 2007
@@ -0,0 +1,86 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.xindice.webadmin;
+
+import org.apache.xindice.webadmin.webdav.WebdavStatus;
+import org.apache.xindice.webadmin.webdav.components.Put;
+import org.apache.xindice.xml.TextWriter;
+import org.apache.xindice.xml.dom.DOMParser;
+import org.w3c.dom.Document;
+
+public class PutTest extends MethodSetup {
+
+    public void setUp() throws Exception {
+        super.setUp();
+        method = new Put();
+    }
+
+    public void testPutNullCollection() throws Exception {
+        // collection was not found: one or more intermediate collections do not exist
+        method.execute(request, response, new Location("/unknown"));
+        assertEquals(WebdavStatus.SC_CONFLICT, httpResponse.getStatus());
+    }
+
+    public void testPutCollection() throws Exception {
+        // PUT method is not implemented for collections
+        method.execute(request, response, new Location(collection.getCanonicalName()));
+        assertEquals(WebdavStatus.SC_METHOD_NOT_ALLOWED, httpResponse.getStatus());
+    }
+
+    public void testPutXMLResource() throws Exception {
+        String xml = "<test document='true'>This is the test XML</test>";
+        Document document = DOMParser.toDocument(xml);
+        String inStr = document.toString();
+
+        httpRequest.setInput(inStr);
+        String name = "resource";
+
+        method.execute(request, response, new Location(collection.getCanonicalDocumentName(name)));
+        assertEquals(WebdavStatus.SC_CREATED, httpResponse.getStatus());
+        Document out = collection.getDocument(name);
+        assertNotNull(out);
+        String outStr = TextWriter.toString(out);
+        assertEquals("Documents do not match", inStr, outStr);
+
+        method.execute(request, response, new Location(collection.getCanonicalDocumentName(name)));
+        assertEquals(WebdavStatus.SC_NO_CONTENT, httpResponse.getStatus());
+        out = collection.getDocument(name);
+        assertNotNull(out);
+        outStr = TextWriter.toString(out);
+        assertEquals("Documents do not match", inStr, outStr);
+    }
+
+    public void testPutBinaryResource() throws Exception {
+        String inStr = "This is the test binary resource";
+        httpRequest.setInput(inStr);
+        String name = "binary";
+        method.execute(request, response, new Location(collection.getCanonicalDocumentName(name)));
+
+        assertEquals(WebdavStatus.SC_CREATED, httpResponse.getStatus());
+        byte[] binary = collection.getBinary(name);
+        assertNotNull(binary);
+        assertEquals("Binary resources do not match", inStr, new String(binary));
+
+        method.execute(request, response, new Location(collection.getCanonicalDocumentName(name)));
+
+        assertEquals(WebdavStatus.SC_NO_CONTENT, httpResponse.getStatus());
+        binary = collection.getBinary(name);
+        assertNotNull(binary);
+        assertEquals("Binary resources do not match", inStr, new String(binary));
+    }
+}

Propchange: xml/xindice/trunk/java/tests/src/org/apache/xindice/webadmin/PutTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: xml/xindice/trunk/java/tests/src/org/apache/xindice/webadmin/PutTest.java
------------------------------------------------------------------------------
    svn:keywords = Id Revision Author Date