dviner      2002/12/27 15:21:42

  Modified:    java/tests/src/org/apache/xindice UnitTests.java
  Added:       java/tests/src/org/apache/xindice/core/meta MetaTest.java
  Log:
  initial set of tests for the MetaData class.
  --dviner
  
  Revision  Changes    Path
  1.9       +5 -2      
xml-xindice/java/tests/src/org/apache/xindice/UnitTests.java
  
  Index: UnitTests.java
  ===================================================================
  RCS file: 
/home/cvs/xml-xindice/java/tests/src/org/apache/xindice/UnitTests.java,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- UnitTests.java    16 Dec 2002 05:56:38 -0000      1.8
  +++ UnitTests.java    27 Dec 2002 23:21:42 -0000      1.9
  @@ -66,6 +66,7 @@
   import org.apache.xindice.core.filer.*;
   import org.apache.xindice.tools.XMLToolsTest;
   import org.apache.xindice.util.ConfigurationTest;
  +import org.apache.xindice.core.meta.MetaTest;
   
   import junit.framework.Test;
   import junit.framework.TestSuite;
  @@ -108,6 +109,8 @@
         suite.addTest(new TestSuite(XMLToolsTest.class));
   
         suite.addTest(new TestSuite(ConfigurationTest.class));
  +      
  +      suite.addTest(new TestSuite(MetaTest.class));
   
         return new TestSetup(suite) {
   
  
  
  
  1.1                  
xml-xindice/java/tests/src/org/apache/xindice/core/meta/MetaTest.java
  
  Index: MetaTest.java
  ===================================================================
  /*
   * 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: MetaTest.java,v 1.1 2002/12/27 23:21:42 dviner Exp $
   */
  
  package org.apache.xindice.core.meta;
  
  import junit.framework.TestCase;
  import org.apache.xindice.xml.TextWriter;
  import org.apache.xindice.xml.dom.DocumentImpl;
  import org.apache.xindice.xml.dom.DOMParser;
  import org.w3c.dom.*;
  
  /**
   * @version $Revision: 1.1 $, $Date: 2002/12/27 23:21:42 $
   * @author Dave Viner <[EMAIL PROTECTED]>
   */
  public class MetaTest extends TestCase {
  
  
     /* make sure we can make 2 metadata objects that are identical */  
     public void testMetaSimpleComparison() {
            MetaData m1 = new MetaData(MetaData.UNKNOWN, "test1", 0, 0);
                MetaData m2 = new MetaData(MetaData.UNKNOWN, "test1", 0, 0);
                assertEquals(m1.toString(), m2.toString());                 
     }
  
     /* make sure we can make 2 metadata objects that are different */
     public void testMetaComplexCreation() {
                MetaData m1 = new MetaData(MetaData.UNKNOWN, "test1", 0, 0);
                MetaData m2 = new MetaData(MetaData.COLLECTION, "test1", 0, 0);
                assertFalse(m1.toString().equals(m2.toString()));
        }
        
        /* make sure we can get and set attributes */
        public void testMetaAttrs() {
                MetaData m1 = new MetaData(MetaData.UNKNOWN, "test1", 0, 0);
                m1.setAttribute("test", "cases");
                String s = (String)m1.getAttribute("test");
                assertEquals(s, "cases");
                
                s = (String)m1.getAttribute("not there");
                assertNull(s);
                
        }
        
        /* make sure we can get and set custom documents */
        public void testMetaCustomDocument() {
                MetaData m1 = new MetaData(MetaData.UNKNOWN, "test1", 0, 0);
                
                Document doc_init = m1.getCustomDocument();
                assertNull(doc_init);
                
                String cust = "<custom_xml>" +
                                "<mycool>xml document that looks <like />"+
                                "whatever i want</mycool>" +
                                "</custom_xml>";
                Document doc = null;
                try {
                        doc = DOMParser.toDocument(cust);
                } catch(Exception e) {
                        fail("Can't parse xml document! "+e.getMessage());
                }
                m1.setCustomDocument(doc);
                
                Document doc2 = m1.getCustomDocument();
                
                assertEquals(TextWriter.toString(doc), 
TextWriter.toString(doc2));
        }
        
        /* make sure we can create a metadata object from xml
           and make sure we can stream it back to xml without any changes */
        public void testMetaFromXml() {
                String xml = "<?xml version=\"1.0\"?>\n" +
                        "<meta xmlns=\"http://apache.org/xindice/metadata\";>" +
                    "<system type=\"doc\">" +
                    "<attr name=\"created\" value=\"0\" />" +
                        "<attr name=\"modified\" value=\"0\" />" +
                        "</system></meta>";
                Document doc = null;
                try {
                    doc = DOMParser.toDocument(xml);
                } catch (Exception e) {
                        fail("Can't parse xml document! "+e.getMessage());
                }
                MetaData meta = new MetaData();
                meta.streamFromXML(doc.getDocumentElement(), true);
                Document doc2 = new DocumentImpl();
                meta.streamToXML(doc2, true);
                assertEquals(TextWriter.toString(doc), 
TextWriter.toString(doc2));
        }
  }
  
  
  

Reply via email to