vgritsenko 2003/12/23 04:10:37
Modified: java/tests/src/org/apache/xindice/client/xmldb/resources
BinaryResourceTest.java
Log:
Add testRemove
Revision Changes Path
1.3 +37 -25
xml-xindice/java/tests/src/org/apache/xindice/client/xmldb/resources/BinaryResourceTest.java
Index: BinaryResourceTest.java
===================================================================
RCS file:
/home/cvs/xml-xindice/java/tests/src/org/apache/xindice/client/xmldb/resources/BinaryResourceTest.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- BinaryResourceTest.java 7 Aug 2003 20:13:26 -0000 1.2
+++ BinaryResourceTest.java 23 Dec 2003 12:10:37 -0000 1.3
@@ -75,28 +75,21 @@
*/
public class BinaryResourceTest extends TestCase {
- private static final String BINARY_COLLECTION_NAME = "binary";
private static final String TEST_COLLECTION_PATH =
XmlDbClientSetup.INSTANCE_NAME + "/" + XmlDbClientSetup.TEST_COLLECTION_NAME +
"/current";
private Database database;
- private XmlDbClient xmldbClient;
+ private XmlDbClient client;
public BinaryResourceTest() throws Exception {
-
- String driver = "org.apache.xindice.client.xmldb.DatabaseImpl";
- Class cls = Class.forName(driver);
-
+ Class cls =
Class.forName("org.apache.xindice.client.xmldb.DatabaseImpl");
database = (Database) cls.newInstance();
DatabaseManager.registerDatabase(database);
-
- xmldbClient = new XmlDbClient("xmldb:xindice-embed://");
+ client = new XmlDbClient("xmldb:xindice-embed://");
}
public void setUp() throws Exception {
-
- xmldbClient.createCollection(XmlDbClientSetup.INSTANCE_NAME,
XmlDbClientSetup.TEST_COLLECTION_NAME);
-
- xmldbClient.createCollection(
+ client.createCollection(XmlDbClientSetup.INSTANCE_NAME,
XmlDbClientSetup.TEST_COLLECTION_NAME);
+ client.createCollection(
XmlDbClientSetup.INSTANCE_NAME + "/" +
XmlDbClientSetup.TEST_COLLECTION_NAME,
"current",
DOMParser.toDocument(
@@ -106,15 +99,13 @@
}
public void tearDown() throws Exception {
-
- xmldbClient.dropCollection(XmlDbClientSetup.INSTANCE_NAME + "/"
+ XmlDbClientSetup.TEST_COLLECTION_NAME, "current");
- xmldbClient.dropCollection(XmlDbClientSetup.INSTANCE_NAME,
XmlDbClientSetup.TEST_COLLECTION_NAME);
+ client.dropCollection(XmlDbClientSetup.INSTANCE_NAME + "/" +
XmlDbClientSetup.TEST_COLLECTION_NAME, "current");
+ client.dropCollection(XmlDbClientSetup.INSTANCE_NAME,
XmlDbClientSetup.TEST_COLLECTION_NAME);
}
public void testRoundTrip() throws Exception {
-
- Collection testCollection =
xmldbClient.getCollection(TEST_COLLECTION_PATH);
- if (testCollection == null) {
+ Collection collection =
client.getCollection(TEST_COLLECTION_PATH);
+ if (collection == null) {
throw new Exception("getCollection(" +
TEST_COLLECTION_PATH + ") returned null");
}
@@ -123,26 +114,47 @@
* then retrieve it and verify that the data comes back right.
*/
- BinaryResource newResource = new BinaryResourceImpl(null, new
byte[] { 0x00, 0x10, 0x01, 0x11 });
- testCollection.storeResource(newResource);
+ Resource newResource = collection.createResource(null,
"BinaryResource");
+ newResource.setContent(new byte[] { 0x00, 0x10, 0x01, 0x11 });
+ collection.storeResource(newResource);
String id = newResource.getId();
- Resource foundResource = testCollection.getResource(id);
+ Resource foundResource = collection.getResource(id);
assertNotNull("We know you're in there...", foundResource);
-
assertEquals("The resource type is supposed be
'BinaryResource'", "BinaryResource", foundResource.getResourceType());
-
assertTrue("The resource is an instance of BinaryResource",
foundResource instanceof BinaryResource);
byte[] newBytes = (byte[]) newResource.getContent();
byte[] foundBytes = (byte[]) foundResource.getContent();
assertEquals("The size of the found and saved resource should
be the same...", newBytes.length, foundBytes.length);
-
for (int i = 0; i < newBytes.length; ++i) {
assertEquals("The resources differ in byte " + i,
newBytes[i], foundBytes[i]);
}
}
+ public void testRemove() throws Exception {
+ Collection collection =
client.getCollection(TEST_COLLECTION_PATH);
+ if (collection == null) {
+ throw new Exception("getCollection(" +
TEST_COLLECTION_PATH + ") returned null");
+ }
+
+ /*
+ * Create a binary resource, save it in the 'current'
collection,
+ * then remove it and verify that it was indeed removed.
+ */
+
+ Resource newResource = collection.createResource(null,
"BinaryResource");
+ newResource.setContent(new byte[] { 0x00, 0x10, 0x01, 0x11 });
+ collection.storeResource(newResource);
+ String id = newResource.getId();
+
+ Resource foundResource = collection.getResource(id);
+ assertNotNull("It should be in there", foundResource);
+
+ collection.removeResource(foundResource);
+ foundResource = collection.getResource(id);
+ assertNull("It should not be in there anymore", foundResource);
+ }
}