Uh... not really. It's just that I haven't yet figured out how to automate a test environment for Xindice. Not having a server running is a bit a showstopper to me, since I can'r really understand how to write, say, an Xupdate test

I'm writing integration tests but only testing the embed driver (I'm lazy, I know). Anyway, I wrote yesterday evening a few tests for the XPath and XUpdate services. I've attached the file (since I don't have cvs access) so feel free to commit it and write other tests (or modify the current tests if you think that they are not accurate enough).


I also consider myself a beginner in Junit: maybe you could write some docs about writing tests on Xindice, how about it?

Next on my list :-) But you can start by writing unit tests (they are easier than the integration tests) for testing a single class. I think it's the best start if you're new to JUnit.


-Vladimir

--
Vladimir R. Bossicard
Apache Xindice - http://xml.apache.org/xindice
/*
 * The Apache Software License, Version 1.1
 *
 *
 * Copyright (c) 1999 The Apache Software Foundation.  All rights
 * reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 *
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 *
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in
 *    the documentation and/or other materials provided with the
 *    distribution.
 *
 * 3. The end-user documentation included with the redistribution,
 *    if any, must include the following acknowledgment:
 *       "This product includes software developed by the
 *        Apache Software Foundation (http://www.apache.org/)."
 *    Alternately, this acknowledgment may appear in the software itself,
 *    if and wherever such third-party acknowledgments normally appear.
 *
 * 4. The names "Xindice" and "Apache Software Foundation" must
 *    not be used to endorse or promote products derived from this
 *    software without prior written permission. For written
 *    permission, please contact [EMAIL PROTECTED]
 *
 * 5. Products derived from this software may not be called "Apache",
 *    nor may "Apache" appear in their name, without prior written
 *    permission of the Apache Software Foundation.
 *
 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 * ====================================================================
 *
 * This software consists of voluntary contributions made by many
 * individuals on behalf of the Apache Software Foundation and was
 * originally based on software copyright (c) 1999-2001, The dbXML
 * Group, L.L.C., http://www.dbxmlgroup.com.  For more
 * information on the Apache Software Foundation, please see
 * <http://www.apache.org/>.
 *
 * $Id: IntegrationTests.java,v 1.1 2002/11/28 08:12:26 vladimir Exp $
 */

package org.apache.xindice.integration.client.services;

import org.apache.xindice.integration.client.AbstractXmlDbClientTest;

import org.xmldb.api.base.Collection;
import org.xmldb.api.base.ResourceIterator;
import org.xmldb.api.base.ResourceSet;
import org.xmldb.api.modules.XPathQueryService;

import java.util.ArrayList;
import java.util.List;

/**
 * @version $Revision: 1.1 $, $Date: 2002/11/28 08:12:26 $
 * @author Vladimir R. Bossicard <[EMAIL PROTECTED]>
 */
public class XPathQueryTest
        extends AbstractXmlDbClientTest {

    public void setUp()
            throws Exception {
        super.setUp();

        String document1 = "<?xml version=\"1.0\"?>" +
                "<person>" +
                "<first>John</first>" +
                "<last>Smith</last>" +
                "<phone type=\"work\">555-345-6789</phone>" +
                "</person>";
        String document2 = "<?xml version=\"1.0\"?>" +
                "<person>" +
                "<first>Sally</first>" +
                "<last>Smith</last>" +
                "<phone type=\"work\">555-345-6789</phone>" +
                "</person>";

        this.client.insertDocument(TEST_COLLECTION_PATH, "doc1", document1);
        this.client.insertDocument(TEST_COLLECTION_PATH, "doc2", document2);
    }

    public void tearDown()
            throws Exception {
        this.client.removeDocument(TEST_COLLECTION_PATH, "doc1");
        this.client.removeDocument(TEST_COLLECTION_PATH, "doc2");

        super.tearDown();
    }

    public void testSimpleQuery()
            throws Exception {
        String query = "//person[last='Smith']";

        Collection col = this.client.getCollection(TEST_COLLECTION_PATH);
        XPathQueryService xpathservice = (XPathQueryService) 
col.getService("XPathQueryService", "1.0");
        ResourceSet resultSet = xpathservice.query(query);

        ResourceIterator results = resultSet.getIterator();

        List res = toList(results);
        assertEquals(2, res.size());
    }

    public void testSimpleAndQuery()
            throws Exception {
        String query = "//person[first='John' and last='Smith']";

        Collection col = this.client.getCollection(TEST_COLLECTION_PATH);
        XPathQueryService xpathservice = (XPathQueryService) 
col.getService("XPathQueryService", "1.0");
        ResourceSet resultSet = xpathservice.query(query);

        ResourceIterator results = resultSet.getIterator();

        List res = toList(results);
        assertEquals(1, res.size());
    }

    public void testSimpleOrQuery()
            throws Exception {
        String query = "//person[first='John' or last='Smith']";

        Collection col = this.client.getCollection(TEST_COLLECTION_PATH);
        XPathQueryService xpathservice = (XPathQueryService) 
col.getService("XPathQueryService", "1.0");
        ResourceSet resultSet = xpathservice.query(query);

        ResourceIterator results = resultSet.getIterator();

        List res = toList(results);
        assertEquals(2, res.size());
    }

    public void testMultipleOrQuery()
            throws Exception {
        String query = "//person[first='John' or first='Sally']";

        Collection col = this.client.getCollection(TEST_COLLECTION_PATH);
        XPathQueryService xpathservice = (XPathQueryService) 
col.getService("XPathQueryService", "1.0");
        ResourceSet resultSet = xpathservice.query(query);

        ResourceIterator results = resultSet.getIterator();

        List res = toList(results);
        assertEquals(2, res.size());
    }

    public void testAndOrQuery()
            throws Exception {
        String query = "//person[last='Smith' and (first='John' or 
first='Sally')]";

        Collection col = this.client.getCollection(TEST_COLLECTION_PATH);
        XPathQueryService xpathservice = (XPathQueryService) 
col.getService("XPathQueryService", "1.0");
        ResourceSet resultSet = xpathservice.query(query);

        ResourceIterator results = resultSet.getIterator();

        List res = toList(results);
        assertEquals(2, res.size());
    }

    public static List toList(ResourceIterator iter)
            throws Exception {
        List result = null;
        if (iter != null) {
            result = new ArrayList();
            while (iter.hasMoreResources()) {
                result.add(iter.nextResource());
            }
        }
        return result;
    }

}

Reply via email to