Package org.apache.xindice.webadmin

Source Code of org.apache.xindice.webadmin.PutTest

/*
* 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));
    }
}
TOP

Related Classes of org.apache.xindice.webadmin.PutTest

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.