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 2004/06/10 16:46:48 UTC

cvs commit: xml-xindice/java/tests/src/org/apache/xindice/integration/client/services MetaTest.java

vgritsenko    2004/06/10 07:46:48

  Modified:    .        status.xml
               java/src/org/apache/xindice/core/meta MetaData.java
               java/tests/src/org/apache/xindice/integration/client/services
                        MetaTest.java
  Log:
  fix save/restore of custom meta data documents, add unit test
  
  Revision  Changes    Path
  1.45      +3 -0      xml-xindice/status.xml
  
  Index: status.xml
  ===================================================================
  RCS file: /home/cvs/xml-xindice/status.xml,v
  retrieving revision 1.44
  retrieving revision 1.45
  diff -u -r1.44 -r1.45
  --- status.xml	25 May 2004 15:58:46 -0000	1.44
  +++ status.xml	10 Jun 2004 14:46:47 -0000	1.45
  @@ -74,6 +74,9 @@
   
       <changes>
           <release version="1.1b5-dev">
  +            <action dev="VG" type="fix">
  +                Fixed saving of custom meta data documents.
  +            </action>
               <action dev="VG" type="fix" fixes-bug="27187" due-to="Fredy Dobler">
                   Fixed addmultiple command with local (-l) database
               </action>
  
  
  
  1.16      +10 -16    xml-xindice/java/src/org/apache/xindice/core/meta/MetaData.java
  
  Index: MetaData.java
  ===================================================================
  RCS file: /home/cvs/xml-xindice/java/src/org/apache/xindice/core/meta/MetaData.java,v
  retrieving revision 1.15
  retrieving revision 1.16
  diff -u -r1.15 -r1.16
  --- MetaData.java	20 Mar 2004 13:43:23 -0000	1.15
  +++ MetaData.java	10 Jun 2004 14:46:48 -0000	1.16
  @@ -496,7 +496,6 @@
           }
   
           if (null != custom) {
  -            // TODO: customElement is not used. Bug?
               Element customElement = null;
               if (!USE_NS) {
                   customElement = doc.createElement(E_CUSTOM);
  @@ -504,8 +503,9 @@
                   customElement = doc.createElementNS(NS_URI, E_CUSTOM);
               }
   
  -            root.appendChild(
  +            customElement.appendChild(
                       doc.importNode(custom.getDocumentElement(), true));
  +            root.appendChild(customElement);
           }
   
           return root;
  @@ -531,15 +531,9 @@
           this.attrs = null;
           this.custom = null;
   
  -        String systemElemName = E_SYSTEM;
  -        String attrsElemName = E_ATTRS;
  -        String customElemName = E_CUSTOM;
  -        String attrElemName = E_ATTR;
  -
           NodeList list = source.getChildNodes();
           for (int i = 0; i < list.getLength(); i++) {
               Node node = list.item(i);
  -
               if (node.getNodeType() != Node.ELEMENT_NODE) {
                   continue;
               }
  @@ -548,7 +542,7 @@
               String elementName = element.getNodeName();
               // String prefix = element.getPrefix();
   
  -            if (systemElemName.equals(elementName)) {
  +            if (E_SYSTEM.equals(elementName)) {
                   String attrStr = element.getAttribute(A_TYPE);
                   if (null != attrStr) {
                       this.type = parseTypeString(attrStr);
  @@ -570,7 +564,7 @@
                           String childName = child.getNodeName();
   
   
  -                        if (attrElemName.equals(childName)) {
  +                        if (E_ATTR.equals(childName)) {
                               String nameStr = child.getAttribute(A_NAME);
                               String valueStr = child.getAttribute(A_VALUE);
                               if (null != nameStr && null != valueStr) {
  @@ -587,8 +581,8 @@
                           }
                       }
                   }
  -            } else if (attrsElemName.equals(elementName)) {
  -                NodeList attrList = element.getElementsByTagName(attrElemName);
  +            } else if (E_ATTRS.equals(elementName)) {
  +                NodeList attrList = element.getElementsByTagName(E_ATTR);
                   for (int j = 0; j < attrList.getLength(); j++) {
                       Element e = (Element) attrList.item(j);
   
  @@ -602,9 +596,9 @@
                       }
                       this.attrs.put(attrName, e.getAttribute(A_VALUE));
                   }
  -            } else if (customElemName.equals(elementName)) {
  +            } else if (E_CUSTOM.equals(elementName)) {
                   this.custom = new DocumentImpl();
  -                Node custdoc = this.custom.importNode(element, true);
  +                Node custdoc = this.custom.importNode(element.getFirstChild(), true);
   
                   /* if you want really verbose debugging try this */
                   if (log.isTraceEnabled()) {
  
  
  
  1.5       +21 -2     xml-xindice/java/tests/src/org/apache/xindice/integration/client/services/MetaTest.java
  
  Index: MetaTest.java
  ===================================================================
  RCS file: /home/cvs/xml-xindice/java/tests/src/org/apache/xindice/integration/client/services/MetaTest.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- MetaTest.java	8 Feb 2004 03:57:02 -0000	1.4
  +++ MetaTest.java	10 Jun 2004 14:46:48 -0000	1.5
  @@ -21,6 +21,8 @@
   import org.apache.xindice.client.xmldb.services.MetaService;
   import org.apache.xindice.core.meta.MetaData;
   import org.apache.xindice.integration.client.AbstractXmlDbClientTest;
  +import org.apache.xindice.xml.TextWriter;
  +import org.apache.xindice.xml.dom.DOMParser;
   
   import org.xmldb.api.base.Collection;
   
  @@ -218,5 +220,22 @@
           data = service.getMetaData(DOCUMENT_ID1);
           String value1 = (String)data.getAttribute(ATTRIBUTE_ID);
           assertEquals("Attribute value does not match!", value0, value1);
  +    }
  +
  +    public void testSetDocumentCustomMetaData() throws Exception {
  +        // Get meta service
  +        Collection col = this.client.getCollection(TEST_COLLECTION_PATH);
  +        MetaService service = (MetaService) col.getService("MetaService", "1.0");
  +
  +        String custom0 = "<?xml version=\"1.0\"?>\n<mycustom xmlns=\"\">meta</mycustom>";
  +        // Get meta & set custom document
  +        MetaData data = service.getMetaData(DOCUMENT_ID1);
  +        data.setCustomDocument(DOMParser.toDocument(custom0));
  +        service.setMetaData(DOCUMENT_ID1, data);
  +
  +        // Get metadata again
  +        data = service.getMetaData(DOCUMENT_ID1);
  +        String custom1 = TextWriter.toString(data.getCustomDocument());
  +        assertEquals("Custom meta document does not match", custom0, custom1);
       }
   }