kevinoneill    2003/08/05 22:49:50

  Modified:    java/tests/src/org/apache/xindice/integration/client/services
                        XPathQueryTest.java
  Log:
  PR: 22155, 22156
  Added tests that expose issues in the handling of non element result types 
for queries.
  
  Revision  Changes    Path
  1.7       +122 -6    
xml-xindice/java/tests/src/org/apache/xindice/integration/client/services/XPathQueryTest.java
  
  Index: XPathQueryTest.java
  ===================================================================
  RCS file: 
/home/cvs/xml-xindice/java/tests/src/org/apache/xindice/integration/client/services/XPathQueryTest.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- XPathQueryTest.java       4 Aug 2003 23:56:36 -0000       1.6
  +++ XPathQueryTest.java       6 Aug 2003 05:49:50 -0000       1.7
  @@ -67,6 +67,7 @@
   import org.xmldb.api.base.Collection;
   import org.xmldb.api.base.ResourceIterator;
   import org.xmldb.api.base.ResourceSet;
  +import org.xmldb.api.base.XMLDBException;
   import org.xmldb.api.modules.XMLResource;
   import org.xmldb.api.modules.XPathQueryService;
   
  @@ -76,6 +77,7 @@
   /**
    * @version $Revision$, $Date$
    * @author Vladimir R. Bossicard <[EMAIL PROTECTED]>
  + * @author <a href="mailto:[EMAIL PROTECTED]">Kevin O'Neill</a>
    */
   public class XPathQueryTest
           extends AbstractXmlDbClientTest {
  @@ -254,10 +256,8 @@
                XPathQueryService xpathservice = (XPathQueryService) 
col.getService("XPathQueryService", "1.0");
                ResourceSet resultSet = xpathservice.query(query);
   
  -             ResourceIterator results = resultSet.getIterator();
  -
  -             List res = asList(results);
  -             assertEquals(1, res.size());
  +        assertEquals(1L, resultSet.getSize());
  +        assertEquals("John", resultSet.getResource(0).getContent());
      }
       
        public void testGetMultipleTextNodes() throws Exception
  @@ -310,7 +310,123 @@
                this.client.removeDocument(TEST_COLLECTION_PATH, "doc3");
        }
        
  +    public void testFetchMultipleAttributeNode() throws Exception
  +    {
  +        String document3 = "<?xml version=\"1.0\"?>" +
  +                  "<foo bar='foo'>" +
  +                  "<bar foo='bar' bar='bar'/>" +
  +                  "</foo>";
  +        
  +        client.insertDocument(TEST_COLLECTION_PATH, "doc3", document3);
  +
  +        String query = "//@bar";
  +       
  +        Collection col = this.client.getCollection(TEST_COLLECTION_PATH);
  +        XPathQueryService xpathservice = (XPathQueryService) 
col.getService("XPathQueryService", "1.0");
  +        
  +        ResourceSet resultSet = null;
  +        try
  +        {
  +            resultSet = xpathservice.query(query);
  +        }
  +        catch (Exception e)
  +        {
  +            fail(e.getMessage());
  +        }
  +
  +        ResourceIterator results = resultSet.getIterator();
  +        List res = asList(results);
  +        assertEquals(2, res.size());
  +
  +        XMLResource resource = (XMLResource) resultSet.getResource(0);
  +        
  +        Node node = resource.getContentAsDOM();
  +
  +        client.removeDocument(TEST_COLLECTION_PATH, "doc3");
  +    }
       
  +    public void testFetchAttributeNode() throws Exception
  +    {
  +        String document3 = "<?xml version=\"1.0\"?>" +
  +                  "<foo bar='foo'>" +
  +                  "<bar foo='bar' bar='bar'/>" +
  +                  "</foo>";
  +        
  +        client.insertDocument(TEST_COLLECTION_PATH, "doc3", document3);
  +
  +        String query = "//foo/@bar";
  +       
  +        Collection col = this.client.getCollection(TEST_COLLECTION_PATH);
  +        XPathQueryService xpathservice = (XPathQueryService) 
col.getService("XPathQueryService", "1.0");
  +        
  +        ResourceSet resultSet = null;
  +        try
  +        {
  +            resultSet = xpathservice.query(query);
  +        }
  +        catch (Exception e)
  +        {
  +            fail(e.getMessage());
  +        }
  +
  +        assertEquals(1L, resultSet.getSize());
  +        assertEquals("foo", 
resultSet.getResource(0).getContent().toString());
  +    }
  +
  +    public void testFetchBoolean() throws Exception
  +    {
  +        String query = "boolean(//person)";
  +        
  +        Collection col = client.getCollection(TEST_COLLECTION_PATH);
  +        XPathQueryService xpathservice = (XPathQueryService) 
col.getService("XPathQueryService", "1.0");
  +        try {
  +            ResourceSet resultSet = xpathservice.query(query);
  +
  +            // when we do support it the following tests will be run
  +            assertEquals(1L, resultSet.getSize());
  +            assertEquals("true", resultSet.getResource(1L).getContent());
  +            
  +        } catch (XMLDBException e) {
  +            fail(e.getMessage());
  +        }
  +    }
  +    
  +    public void testFetchString() throws Exception
  +    {
  +        String query = "string(//person[first='John' and 
last='Smith']/first)";
  +        
  +        Collection col = client.getCollection(TEST_COLLECTION_PATH);
  +        XPathQueryService xpathservice = (XPathQueryService) 
col.getService("XPathQueryService", "1.0");
  +        try {
  +            ResourceSet resultSet = xpathservice.query(query);
  +
  +            // when we do support it the following tests will be run
  +            assertEquals(1L, resultSet.getSize());
  +            assertEquals("John", resultSet.getResource(1L).getContent());
  +            
  +        } catch (XMLDBException e) {
  +            fail(e.getMessage());
  +        }
  +    }
  +
  +    public void testFetchNumber() throws Exception
  +    {
  +        String query = "count(//person[first='John' and last='Smith'])";
  +        
  +        Collection col = client.getCollection(TEST_COLLECTION_PATH);
  +        XPathQueryService xpathservice = (XPathQueryService) 
col.getService("XPathQueryService", "1.0");
  +        try {
  +            ResourceSet resultSet = xpathservice.query(query);
  +
  +            // when we do support it the following tests will be run
  +            assertEquals(1L, resultSet.getSize());
  +            assertEquals("1", resultSet.getResource(1L).getContent());
  +            
  +        } catch (XMLDBException e) {
  +            fail(e.getMessage());
  +        }
  +    }
  +
       public void testSrcAddedToRootOnly() throws Exception
       {
           String query = "//person[first='John' and last='Smith']";
  
  
  

Reply via email to