kward 2002/06/10 21:28:58
Modified: java/scratchpad/tests/src CollectionManagerTest.java
Log:
Modified assertTrue() statements
Revision Changes Path
1.3 +84 -85
xml-xindice/java/scratchpad/tests/src/CollectionManagerTest.java
Index: CollectionManagerTest.java
===================================================================
RCS file:
/home/cvs/xml-xindice/java/scratchpad/tests/src/CollectionManagerTest.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- CollectionManagerTest.java 10 Jun 2002 02:10:28 -0000 1.2
+++ CollectionManagerTest.java 11 Jun 2002 04:28:58 -0000 1.3
@@ -83,6 +83,7 @@
fail( e.getMessage() );
}
+ // see if the collection was created
Hashtable message = new Hashtable();
message.put("message", "ListCollections");
message.put("collection", "/" + INSTANCE_NAME + "/" +
TEST_COLLECTION_NAME);
@@ -98,8 +99,33 @@
assert(((String) enum.nextElement()).equals("child1"));
}
- dropCollection("child1");
+ // try creating the same collection, should generate a duplicate error
+
+ try {
+ createCollection("child1");
+ } catch(Exception e) {
+ assert(e.getMessage().lastIndexOf("Duplicate Collection") > 0);
+ }
+
+ // try creating a nameless collection, should generate a no name error
+ exceptioncaught = false;
+ Hashtable badmessage = new Hashtable();
+
+ badmessage.put("message", "CreateCollection");
+ badmessage.put("collection", "/" + INSTANCE_NAME + "/" +
TEST_COLLECTION_NAME);
+ badmessage.put("name", "");
+
+ Vector badparams = new Vector();
+
+ badparams.addElement(badmessage);
+ try {
+ client.execute("run", badparams);
+ } catch(Exception e) {
+ assert(e.getMessage().lastIndexOf("No name specified") > 0);
+ }
+
+ dropCollection("child1");
}
@@ -131,17 +157,13 @@
// Try dropping the collection we just dropped
try {
- exceptioncaught = false;
dropCollection("coltodrop");
} catch(Exception e) {
- exceptioncaught = true ;
- } finally {
- assertTrue( exceptioncaught );
+ assert(e.getMessage().lastIndexOf("could not be found") > 0);
}
// Try dropping a collection with an empty name
- exceptioncaught = false;
Hashtable badmessage = new Hashtable();
badmessage.put("message", "RemoveCollection");
@@ -154,9 +176,7 @@
try {
client.execute("run", badparams);
} catch(Exception e) {
- exceptioncaught = true;
- } finally {
- assertTrue( exceptioncaught );
+ assert(e.getMessage().lastIndexOf("Collection name must begin with
a '/'") > 0);
}
}
@@ -164,29 +184,57 @@
public void testCreateIndexer() throws Exception {
- // try a normal indexer
+ // try a normal index
try {
createIndexer( "goodindexer", "goodindexer" );
} catch( Exception e ) {
fail( e.getMessage() );
}
- // try adding the same indexer, should result in duplicate error
+ // now see if it's there
+ Hashtable message = new Hashtable();
+ message.put("message", "ListIndexers");
+ message.put("collection", "/" + INSTANCE_NAME + "/" +
TEST_COLLECTION_NAME);
+
+ Vector params = new Vector();
+ params.addElement(message);
+
+ Hashtable result = (Hashtable) client.execute("run", params);
+
+ Vector list = (Vector) result.get("result");
+ Enumeration enum = list.elements();
+ while ( enum.hasMoreElements() ) {
+ assertTrue(((String) enum.nextElement()).equals("goodindexer"));
+ }
+
+ // try adding the same index
try {
- exceptioncaught = false;
createIndexer( "goodindexer", "goodindexer" );
} catch( Exception e ) {
exceptioncaught = true;
+ assertTrue(e.getMessage().lastIndexOf("Duplicate Index") > 0);
} finally {
assertTrue( exceptioncaught );
}
- // try adding a nameless indexer
+ // try adding a nameless index
+ exceptioncaught = false;
+ Hashtable badmessage = new Hashtable();
+
+ badmessage.put("message", "CreateIndexer");
+ badmessage.put("collection", "/" + INSTANCE_NAME + "/" +
TEST_COLLECTION_NAME);
+ badmessage.put("name", "");
+ badmessage.put("pattern", "yeehaw");
+
+ Vector badparams = new Vector();
+
+ badparams.addElement(badmessage);
+
try {
- exceptioncaught = false;
- createIndexer( "", "nonamepattern" );
- } catch( Exception e ) {
+ client.execute("run", badparams);
+ } catch(Exception e) {
exceptioncaught = true;
+ assertTrue(e.getMessage().lastIndexOf("No name specified") > 0);
} finally {
assertTrue( exceptioncaught );
}
@@ -200,6 +248,7 @@
createIndexer("index2drop", "pattern1");
+ // drop the newly created index
try {
dropIndexer("index2drop");
} catch (Exception e) {
@@ -208,89 +257,39 @@
exceptioncaught = false ;
+ // try to drop the same index again
try {
dropIndexer("index2drop");
} catch (Exception e) {
exceptioncaught = true;
+ assertTrue(e.getMessage().lastIndexOf("Index Value Null") > 0);
} finally {
assert( exceptioncaught );
}
- exceptioncaught = false ;
-
- try {
- dropIndexer("");
- } catch (Exception e) {
- exceptioncaught = true;
- } finally {
- assert( exceptioncaught );
- }
-
-
- }
-
-
- // Utility functions
-
+ // try dropping a nameless index
+ exceptioncaught = false;
+ Hashtable badmessage = new Hashtable();
- protected void createCollection(String collection) throws Exception {
- Hashtable message = new Hashtable();
+ badmessage.put("message", "RemoveIndexer");
+ badmessage.put("collection", "/" + INSTANCE_NAME + "/" +
TEST_COLLECTION_NAME);
+ badmessage.put("name", "");
- message.put("message", "CreateCollection");
- message.put("collection", "/" + INSTANCE_NAME + "/" +
TEST_COLLECTION_NAME );
- message.put("name", collection);
+ Vector badparams = new Vector();
- Vector params = new Vector();
+ badparams.addElement(badmessage);
- params.addElement(message);
+ try {
+ client.execute("run", badparams);
+ } catch(Exception e) {
+ exceptioncaught = true;
+ assertTrue(e.getMessage().lastIndexOf("Index Value Null") > 0);
+ } finally {
+ assertTrue( exceptioncaught );
+ }
- client.execute("run", params);
}
- protected void dropCollection(String collection) throws Exception {
- Hashtable message = new Hashtable();
-
- message.put("message", "RemoveCollection");
- message.put("collection", "/" + INSTANCE_NAME + "/" +
TEST_COLLECTION_NAME + "/" + collection);
-
- Vector params = new Vector();
-
- params.addElement(message);
-
- client.execute("run", params);
-
- }
-
- protected void createIndexer(String name, String pattern) throws
Exception {
- Hashtable message = new Hashtable();
-
- message.put("message", "CreateIndexer");
- message.put("collection", "/" + INSTANCE_NAME + "/" +
TEST_COLLECTION_NAME );
- message.put("name", name);
- message.put("pattern", pattern);
-
- Vector params = new Vector();
-
- params.addElement(message);
-
- client.execute("run", params);
-
- }
-
- protected void dropIndexer(String name) throws Exception {
- Hashtable message = new Hashtable();
-
- message.put("message", "RemoveIndexer");
- message.put("collection", "/" + INSTANCE_NAME + "/" +
TEST_COLLECTION_NAME );
- message.put("name", name);
-
- Vector params = new Vector();
-
- params.addElement(message);
-
- client.execute("run", params);
-
- }
}