Vladimir,
Ok, here's a test case for the examples XUpdate.java. There is a
little problem here with using JUnit. The XUpdate class catches the
XMLDBException and doesn't rethrow anything so there is nothing for
JUnit to error when the XMLDBException occurs. The easiest way around
this for now is to just insert a rethrow in the catch block for the
XMLDBException in XUpdate.java. That's what the diff is below. Not
pretty but works good. The only other way is to peer at the data
inside the database which was rather ugly and had its own problems. To
fix/test a specific Exception problem this is better. We can devise
something else later if you want to keep the test around.
The test drops the 'addressbook' collection, then recreates it, then
adds two documents to it, and then tries to run an XUpdate
modification. The only Exception that JUnit can see is the one that we
exposed in XUpdate so the test only fails when XUpdate fails.
-Gerry Reno
XUpdateTest.java:
------------------------------------------------------------------
package org.apache.xindice.examples;
import org.apache.xindice.client.xmldb.services.*;
import org.apache.xindice.xml.dom.*;
import org.xmldb.api.base.*;
import org.xmldb.api.modules.*;
import org.xmldb.api.*;
import junit.framework.Assert;
import junit.framework.TestCase;
import junit.framework.Test;
import junit.framework.TestSuite;
/**
* @author Gerry Reno ([EMAIL PROTECTED])
*
*/
public class XUpdateTest extends TestCase {
/**
* Constructor for XUpdateTest.
* @param arg0
*/
public XUpdateTest(String arg0) {
super(arg0);
}
public void testXUpdate() throws XMLDBException, Exception {
String[] dd1args = { "java/examples/guide/xml/address1.xml" };
String[] dd2args = { "java/examples/guide/xml/address2.xml" };
String[] ad1args = dd1args;
String[] ad2args = dd2args;
String[] xuargs = null;
DeleteDocument dd = new DeleteDocument();
AddDocument ad = new AddDocument();
XUpdate xu = new XUpdate();
String driver =
"org.apache.xindice.client.xmldb.DatabaseImpl";
Class c = Class.forName(driver);
Database database = (Database) c.newInstance();
DatabaseManager.registerDatabase(database);
Collection col =
DatabaseManager.getCollection("xmldb:xindice:///db/");
CollectionManager service = (CollectionManager)
col.getService("CollectionManager", "1.0");
String collectionName = "addressbook";
String collectionConfig =
"<collection compressed=\"true\" name=\"" + collectionName
+ "\">" +
" <filer
class=\"org.apache.xindice.core.filer.BTreeFiler\" gzip=\"true\"/>" +
"</collection>";
// drop addressbook collection
service.dropCollection(collectionName);
System.out.println("Collection " + collectionName + "
dropped.");
// create addressbook collection
service.createCollection(collectionName,
DOMParser.toDocument(collectionConfig));
System.out.println("Collection " + collectionName + "
created.");
// dd.main(dd1args);
// dd.main(dd2args);
// add documents to addressbook collection
ad.main(dd1args);
ad.main(dd2args);
// xupdate documents in addressbook collection
xu.main(xuargs);
}
public static void main(String[] args) {
junit.textui.TestRunner.run(XUpdateTest.class);
}
/**
* @see TestCase#setUp()
*/
protected void setUp() throws Exception {
super.setUp();
}
/**
* @see TestCase#tearDown()
*/
protected void tearDown() throws Exception {
super.tearDown();
}
public static Test suite() {
TestSuite suite = new TestSuite("Test for
org.apache.xindice.examples.XUpdate");
//$JUnit-BEGIN$
suite.addTest(new TestSuite(XUpdateTest.class));
//$JUnit-END$
return suite;
}
}
------------------------------------------------------------------
cvs diff XUpdate.java:
------------------------------------------------------------------
RCS file:
/home/cvspublic/xml-xindice/java/examples/guide/src/org/apache/xindice
/examples/XUpdate.java,v
retrieving revision 1.3
diff -r1.3 XUpdate.java
96a97,98
> // rethrow exception for JUnit testing
> throw new XMLDBException();
------------------------------------------------------------------
__________________________________________________
Do you Yahoo!?
Yahoo! Mail Plus - Powerful. Affordable. Sign up now.
http://mailplus.yahoo.com