diff --git a/bson/pom.xml b/bson/pom.xml
new file mode 100644
index 00000000000..0d1a07e9816
--- /dev/null
+++ b/bson/pom.xml
@@ -0,0 +1,25 @@
+
+
+ 4.0.0
+
+ org.mongodb
+ mongodb-parent
+ 2.4-SNAPSHOT
+ ../pom.xml
+
+ org.bson
+ bson
+ BSON
+ BSON Encoding/Decoding Tools
+ http://bsonspec.org/
+
+
+
+ The Apache Software License, Version 2.0
+ http://www.apache.org/licenses/LICENSE-2.0.txt
+ repo
+
+
+
+
diff --git a/src/main/org/bson/BSON.java b/bson/src/main/java/org/bson/BSON.java
similarity index 100%
rename from src/main/org/bson/BSON.java
rename to bson/src/main/java/org/bson/BSON.java
diff --git a/src/main/org/bson/BSONCallback.java b/bson/src/main/java/org/bson/BSONCallback.java
similarity index 100%
rename from src/main/org/bson/BSONCallback.java
rename to bson/src/main/java/org/bson/BSONCallback.java
diff --git a/src/main/org/bson/BSONDecoder.java b/bson/src/main/java/org/bson/BSONDecoder.java
similarity index 99%
rename from src/main/org/bson/BSONDecoder.java
rename to bson/src/main/java/org/bson/BSONDecoder.java
index efb104fe178..079fc93eddd 100644
--- a/src/main/org/bson/BSONDecoder.java
+++ b/bson/src/main/java/org/bson/BSONDecoder.java
@@ -2,7 +2,6 @@
package org.bson;
-import com.mongodb.BasicDBObject;
import static org.bson.BSON.*;
import java.io.*;
diff --git a/src/main/org/bson/BSONEncoder.java b/bson/src/main/java/org/bson/BSONEncoder.java
similarity index 90%
rename from src/main/org/bson/BSONEncoder.java
rename to bson/src/main/java/org/bson/BSONEncoder.java
index 2ecebd2e287..03b7c05936b 100644
--- a/src/main/org/bson/BSONEncoder.java
+++ b/bson/src/main/java/org/bson/BSONEncoder.java
@@ -2,18 +2,48 @@
package org.bson;
-import static org.bson.BSON.*;
-
-import java.lang.reflect.*;
-import java.nio.*;
-import java.nio.charset.*;
-import java.util.*;
+import static org.bson.BSON.ARRAY;
+import static org.bson.BSON.BINARY;
+import static org.bson.BSON.BOOLEAN;
+import static org.bson.BSON.B_BINARY;
+import static org.bson.BSON.B_UUID;
+import static org.bson.BSON.CODE;
+import static org.bson.BSON.CODE_W_SCOPE;
+import static org.bson.BSON.DATE;
+import static org.bson.BSON.EOO;
+import static org.bson.BSON.NULL;
+import static org.bson.BSON.NUMBER;
+import static org.bson.BSON.NUMBER_INT;
+import static org.bson.BSON.NUMBER_LONG;
+import static org.bson.BSON.OBJECT;
+import static org.bson.BSON.OID;
+import static org.bson.BSON.REGEX;
+import static org.bson.BSON.STRING;
+import static org.bson.BSON.SYMBOL;
+import static org.bson.BSON.TIMESTAMP;
+import static org.bson.BSON.UNDEFINED;
+import static org.bson.BSON.regexFlags;
+
+import java.lang.reflect.Array;
+import java.nio.Buffer;
+import java.util.Date;
+import java.util.List;
+import java.util.Map;
import java.util.Map.Entry;
-import java.util.concurrent.atomic.*;
-import java.util.regex.*;
-
-import org.bson.io.*;
-import org.bson.types.*;
+import java.util.Set;
+import java.util.UUID;
+import java.util.concurrent.atomic.AtomicInteger;
+import java.util.concurrent.atomic.AtomicLong;
+import java.util.regex.Pattern;
+
+import org.bson.io.BasicOutputBuffer;
+import org.bson.io.OutputBuffer;
+import org.bson.types.BSONTimestamp;
+import org.bson.types.Binary;
+import org.bson.types.Code;
+import org.bson.types.CodeWScope;
+import org.bson.types.ObjectId;
+import org.bson.types.Symbol;
/**
* this is meant to be pooled or cached
@@ -319,7 +349,7 @@ protected void putBinary( String name , byte[] data ){
_buf.write( data );
int after = _buf.getPosition();
- com.mongodb.util.MyAsserts.assertEquals( after - before , data.length );
+ assert(after - before == data.length );
}
protected void putBinary( String name , Binary val ){
diff --git a/src/main/org/bson/BSONObject.java b/bson/src/main/java/org/bson/BSONObject.java
similarity index 100%
rename from src/main/org/bson/BSONObject.java
rename to bson/src/main/java/org/bson/BSONObject.java
diff --git a/src/main/org/bson/BasicBSONCallback.java b/bson/src/main/java/org/bson/BasicBSONCallback.java
similarity index 100%
rename from src/main/org/bson/BasicBSONCallback.java
rename to bson/src/main/java/org/bson/BasicBSONCallback.java
diff --git a/src/main/org/bson/BasicBSONObject.java b/bson/src/main/java/org/bson/BasicBSONObject.java
similarity index 100%
rename from src/main/org/bson/BasicBSONObject.java
rename to bson/src/main/java/org/bson/BasicBSONObject.java
diff --git a/src/main/org/bson/Transformer.java b/bson/src/main/java/org/bson/Transformer.java
similarity index 100%
rename from src/main/org/bson/Transformer.java
rename to bson/src/main/java/org/bson/Transformer.java
diff --git a/src/main/org/bson/io/BasicOutputBuffer.java b/bson/src/main/java/org/bson/io/BasicOutputBuffer.java
similarity index 100%
rename from src/main/org/bson/io/BasicOutputBuffer.java
rename to bson/src/main/java/org/bson/io/BasicOutputBuffer.java
diff --git a/src/main/org/bson/io/Bits.java b/bson/src/main/java/org/bson/io/Bits.java
similarity index 100%
rename from src/main/org/bson/io/Bits.java
rename to bson/src/main/java/org/bson/io/Bits.java
diff --git a/src/main/org/bson/io/OutputBuffer.java b/bson/src/main/java/org/bson/io/OutputBuffer.java
similarity index 100%
rename from src/main/org/bson/io/OutputBuffer.java
rename to bson/src/main/java/org/bson/io/OutputBuffer.java
diff --git a/src/main/org/bson/io/PoolOutputBuffer.java b/bson/src/main/java/org/bson/io/PoolOutputBuffer.java
similarity index 100%
rename from src/main/org/bson/io/PoolOutputBuffer.java
rename to bson/src/main/java/org/bson/io/PoolOutputBuffer.java
diff --git a/src/main/org/bson/io/UTF8Encoding.java b/bson/src/main/java/org/bson/io/UTF8Encoding.java
similarity index 100%
rename from src/main/org/bson/io/UTF8Encoding.java
rename to bson/src/main/java/org/bson/io/UTF8Encoding.java
diff --git a/src/main/org/bson/types/BSONTimestamp.java b/bson/src/main/java/org/bson/types/BSONTimestamp.java
similarity index 100%
rename from src/main/org/bson/types/BSONTimestamp.java
rename to bson/src/main/java/org/bson/types/BSONTimestamp.java
diff --git a/src/main/org/bson/types/BasicBSONList.java b/bson/src/main/java/org/bson/types/BasicBSONList.java
similarity index 100%
rename from src/main/org/bson/types/BasicBSONList.java
rename to bson/src/main/java/org/bson/types/BasicBSONList.java
diff --git a/src/main/org/bson/types/Binary.java b/bson/src/main/java/org/bson/types/Binary.java
similarity index 100%
rename from src/main/org/bson/types/Binary.java
rename to bson/src/main/java/org/bson/types/Binary.java
diff --git a/src/main/org/bson/types/Code.java b/bson/src/main/java/org/bson/types/Code.java
similarity index 100%
rename from src/main/org/bson/types/Code.java
rename to bson/src/main/java/org/bson/types/Code.java
diff --git a/src/main/org/bson/types/CodeWScope.java b/bson/src/main/java/org/bson/types/CodeWScope.java
similarity index 100%
rename from src/main/org/bson/types/CodeWScope.java
rename to bson/src/main/java/org/bson/types/CodeWScope.java
diff --git a/src/main/org/bson/types/ObjectId.java b/bson/src/main/java/org/bson/types/ObjectId.java
similarity index 100%
rename from src/main/org/bson/types/ObjectId.java
rename to bson/src/main/java/org/bson/types/ObjectId.java
diff --git a/src/main/org/bson/types/Symbol.java b/bson/src/main/java/org/bson/types/Symbol.java
similarity index 100%
rename from src/main/org/bson/types/Symbol.java
rename to bson/src/main/java/org/bson/types/Symbol.java
diff --git a/src/main/org/bson/util/ClassMap.java b/bson/src/main/java/org/bson/util/ClassMap.java
similarity index 100%
rename from src/main/org/bson/util/ClassMap.java
rename to bson/src/main/java/org/bson/util/ClassMap.java
diff --git a/src/main/org/bson/util/SimplePool.java b/bson/src/main/java/org/bson/util/SimplePool.java
similarity index 100%
rename from src/main/org/bson/util/SimplePool.java
rename to bson/src/main/java/org/bson/util/SimplePool.java
diff --git a/build.xml b/build.xml
deleted file mode 100644
index 9ce2e5f7f42..00000000000
--- a/build.xml
+++ /dev/null
@@ -1,218 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/lib/testng-5.8-jdk15.jar b/lib/testng-5.8-jdk15.jar
deleted file mode 100644
index 80a3bbe4e38..00000000000
Binary files a/lib/testng-5.8-jdk15.jar and /dev/null differ
diff --git a/maven-bson.xml b/maven-bson.xml
deleted file mode 100644
index e4a1244ad68..00000000000
--- a/maven-bson.xml
+++ /dev/null
@@ -1,27 +0,0 @@
-
-
- 4.0.0
- org.bson
- bson
- jar
- BSON
- $VERSION
- BSON Encoding/Decoding Tools
- http://bsonspec.org/
-
-
-
- The Apache Software License, Version 2.0
- http://www.apache.org/licenses/LICENSE-2.0.txt
- repo
-
-
-
-
- http://github.com/mongodb/mongo-java-driver
-
-
-
-
-
-
diff --git a/maven-mongo.xml b/maven-mongo.xml
deleted file mode 100644
index 24ea91a2b33..00000000000
--- a/maven-mongo.xml
+++ /dev/null
@@ -1,27 +0,0 @@
-
-
- 4.0.0
- org.mongodb
- mongo-java-driver
- jar
- MongoDB Java Driver
- $VERSION
- Java Driver for MongoDB
- http://mongodb.org/
-
-
-
- The Apache Software License, Version 2.0
- http://www.apache.org/licenses/LICENSE-2.0.txt
- repo
-
-
-
-
- http://github.com/mongodb/mongo-java-driver
-
-
-
-
-
-
diff --git a/mavenPush.py b/mavenPush.py
deleted file mode 100755
index 82f8087a235..00000000000
--- a/mavenPush.py
+++ /dev/null
@@ -1,56 +0,0 @@
-#!/usr/bin/python
-
-# http://repo1.maven.org/maven2/org/mongodb/mongo-java-driver/
-
-import os
-import sys
-import shutil
-import subprocess
-
-if len( sys.argv ) == 1:
- print "Usage: mavenPush.py VERSION [PUBDIR]"
- print "VERSION - version you want to publish"
- print "PUBDIR - directory to publish to. default = /ebs/maven/"
- sys.exit()
-
-version = sys.argv[1]
-
-if len( sys.argv ) > 2:
- root = os.path.expanduser( sys.argv[2] )
-else:
- root = "/ebs/maven/"
-
-p = subprocess.Popen( [ "/usr/bin/ant" , "clean" ] , stdout=subprocess.PIPE ).communicate()
-p = subprocess.Popen( [ "/usr/bin/ant" , "alljars" ] , stdout=subprocess.PIPE ).communicate()
-
-if p[0].find( "SUCCESSFUL" ) < 0:
- print( p[0] )
- print( p[1] )
- raise( "build failed" )
-
-def go( shortName , longName ):
- dir = root + "/org/mongodb/" + longName + "/" + version
- if not os.path.exists( dir ):
- os.makedirs( dir )
-
- fileRoot = dir + "/" + longName + "-" + version
-
- for x in [ "" , "-sources" , "-javadoc" ]:
- shutil.copy2( shortName + x + ".jar" , fileRoot + x + ".jar" )
-
- pom = open( "maven-" + shortName + ".xml" , "r" ).read()
- pom = pom.replace( "$VERSION" , version )
-
- out = open( fileRoot + ".pom" , 'w' )
- out.write( pom )
- out.close()
-
- p = subprocess.Popen( [ "sha1sum" , fileRoot + ".jar" ] , stdout=subprocess.PIPE ).communicate()
- sha1 = p[0].split( ' ' )[0]
- out = open( fileRoot + ".jar.sha1" , 'w' )
- out.write( sha1 )
- out.close()
-
-
-go( "mongo" , "mongo-java-driver" )
-go( "bson" , "bson" )
diff --git a/mongodb/pom.xml b/mongodb/pom.xml
new file mode 100644
index 00000000000..04be2006756
--- /dev/null
+++ b/mongodb/pom.xml
@@ -0,0 +1,46 @@
+
+
+ 4.0.0
+
+ org.mongodb
+ mongodb-parent
+ 2.4-SNAPSHOT
+ ../pom.xml
+
+ mongo-java-driver
+ MongoDB Java Driver
+ Java Driver for MongoDB
+
+
+
+ org.apache.maven.plugins
+ maven-jar-plugin
+ 2.3.1
+
+
+ true
+
+ false
+
+
+ 2
+ MongoDB
+ com.mongodb
+ ${pom.version}
+ com.mongodb, com.mongodb.io, com.mongodb.util,
+ com.mongodb.gridfs, org.bson, org.bson.util, org.bson.types,
+ org.bson.io
+
+
+
+
+
+
+
+ org.bson
+ bson
+ 2.4-SNAPSHOT
+
+
+
diff --git a/examples/QuickTour.java b/mongodb/src/examples/QuickTour.java
similarity index 100%
rename from examples/QuickTour.java
rename to mongodb/src/examples/QuickTour.java
diff --git a/examples/QuickTourAdmin.java b/mongodb/src/examples/QuickTourAdmin.java
similarity index 100%
rename from examples/QuickTourAdmin.java
rename to mongodb/src/examples/QuickTourAdmin.java
diff --git a/examples/ReadOplog.java b/mongodb/src/examples/ReadOplog.java
similarity index 100%
rename from examples/ReadOplog.java
rename to mongodb/src/examples/ReadOplog.java
diff --git a/src/main/com/mongodb/BasicDBList.java b/mongodb/src/main/java/com/mongodb/BasicDBList.java
similarity index 100%
rename from src/main/com/mongodb/BasicDBList.java
rename to mongodb/src/main/java/com/mongodb/BasicDBList.java
diff --git a/src/main/com/mongodb/BasicDBObject.java b/mongodb/src/main/java/com/mongodb/BasicDBObject.java
similarity index 100%
rename from src/main/com/mongodb/BasicDBObject.java
rename to mongodb/src/main/java/com/mongodb/BasicDBObject.java
diff --git a/src/main/com/mongodb/BasicDBObjectBuilder.java b/mongodb/src/main/java/com/mongodb/BasicDBObjectBuilder.java
similarity index 100%
rename from src/main/com/mongodb/BasicDBObjectBuilder.java
rename to mongodb/src/main/java/com/mongodb/BasicDBObjectBuilder.java
diff --git a/src/main/com/mongodb/Bytes.java b/mongodb/src/main/java/com/mongodb/Bytes.java
similarity index 100%
rename from src/main/com/mongodb/Bytes.java
rename to mongodb/src/main/java/com/mongodb/Bytes.java
diff --git a/src/main/com/mongodb/CommandResult.java b/mongodb/src/main/java/com/mongodb/CommandResult.java
similarity index 100%
rename from src/main/com/mongodb/CommandResult.java
rename to mongodb/src/main/java/com/mongodb/CommandResult.java
diff --git a/src/main/com/mongodb/DB.java b/mongodb/src/main/java/com/mongodb/DB.java
similarity index 100%
rename from src/main/com/mongodb/DB.java
rename to mongodb/src/main/java/com/mongodb/DB.java
diff --git a/src/main/com/mongodb/DBAddress.java b/mongodb/src/main/java/com/mongodb/DBAddress.java
similarity index 100%
rename from src/main/com/mongodb/DBAddress.java
rename to mongodb/src/main/java/com/mongodb/DBAddress.java
diff --git a/src/main/com/mongodb/DBApiLayer.java b/mongodb/src/main/java/com/mongodb/DBApiLayer.java
similarity index 100%
rename from src/main/com/mongodb/DBApiLayer.java
rename to mongodb/src/main/java/com/mongodb/DBApiLayer.java
diff --git a/src/main/com/mongodb/DBCallback.java b/mongodb/src/main/java/com/mongodb/DBCallback.java
similarity index 100%
rename from src/main/com/mongodb/DBCallback.java
rename to mongodb/src/main/java/com/mongodb/DBCallback.java
diff --git a/src/main/com/mongodb/DBCollection.java b/mongodb/src/main/java/com/mongodb/DBCollection.java
similarity index 100%
rename from src/main/com/mongodb/DBCollection.java
rename to mongodb/src/main/java/com/mongodb/DBCollection.java
diff --git a/src/main/com/mongodb/DBConnector.java b/mongodb/src/main/java/com/mongodb/DBConnector.java
similarity index 100%
rename from src/main/com/mongodb/DBConnector.java
rename to mongodb/src/main/java/com/mongodb/DBConnector.java
diff --git a/src/main/com/mongodb/DBCursor.java b/mongodb/src/main/java/com/mongodb/DBCursor.java
similarity index 100%
rename from src/main/com/mongodb/DBCursor.java
rename to mongodb/src/main/java/com/mongodb/DBCursor.java
diff --git a/src/main/com/mongodb/DBObject.java b/mongodb/src/main/java/com/mongodb/DBObject.java
similarity index 100%
rename from src/main/com/mongodb/DBObject.java
rename to mongodb/src/main/java/com/mongodb/DBObject.java
diff --git a/src/main/com/mongodb/DBPointer.java b/mongodb/src/main/java/com/mongodb/DBPointer.java
similarity index 100%
rename from src/main/com/mongodb/DBPointer.java
rename to mongodb/src/main/java/com/mongodb/DBPointer.java
diff --git a/src/main/com/mongodb/DBPort.java b/mongodb/src/main/java/com/mongodb/DBPort.java
similarity index 100%
rename from src/main/com/mongodb/DBPort.java
rename to mongodb/src/main/java/com/mongodb/DBPort.java
diff --git a/src/main/com/mongodb/DBPortPool.java b/mongodb/src/main/java/com/mongodb/DBPortPool.java
similarity index 100%
rename from src/main/com/mongodb/DBPortPool.java
rename to mongodb/src/main/java/com/mongodb/DBPortPool.java
diff --git a/src/main/com/mongodb/DBRef.java b/mongodb/src/main/java/com/mongodb/DBRef.java
similarity index 100%
rename from src/main/com/mongodb/DBRef.java
rename to mongodb/src/main/java/com/mongodb/DBRef.java
diff --git a/src/main/com/mongodb/DBRefBase.java b/mongodb/src/main/java/com/mongodb/DBRefBase.java
similarity index 100%
rename from src/main/com/mongodb/DBRefBase.java
rename to mongodb/src/main/java/com/mongodb/DBRefBase.java
diff --git a/src/main/com/mongodb/DBTCPConnector.java b/mongodb/src/main/java/com/mongodb/DBTCPConnector.java
similarity index 100%
rename from src/main/com/mongodb/DBTCPConnector.java
rename to mongodb/src/main/java/com/mongodb/DBTCPConnector.java
diff --git a/src/main/com/mongodb/MapReduceOutput.java b/mongodb/src/main/java/com/mongodb/MapReduceOutput.java
similarity index 100%
rename from src/main/com/mongodb/MapReduceOutput.java
rename to mongodb/src/main/java/com/mongodb/MapReduceOutput.java
diff --git a/src/main/com/mongodb/Mongo.java b/mongodb/src/main/java/com/mongodb/Mongo.java
similarity index 100%
rename from src/main/com/mongodb/Mongo.java
rename to mongodb/src/main/java/com/mongodb/Mongo.java
diff --git a/src/main/com/mongodb/MongoException.java b/mongodb/src/main/java/com/mongodb/MongoException.java
similarity index 100%
rename from src/main/com/mongodb/MongoException.java
rename to mongodb/src/main/java/com/mongodb/MongoException.java
diff --git a/src/main/com/mongodb/MongoInternalException.java b/mongodb/src/main/java/com/mongodb/MongoInternalException.java
similarity index 100%
rename from src/main/com/mongodb/MongoInternalException.java
rename to mongodb/src/main/java/com/mongodb/MongoInternalException.java
diff --git a/src/main/com/mongodb/MongoOptions.java b/mongodb/src/main/java/com/mongodb/MongoOptions.java
similarity index 100%
rename from src/main/com/mongodb/MongoOptions.java
rename to mongodb/src/main/java/com/mongodb/MongoOptions.java
diff --git a/src/main/com/mongodb/MongoURI.java b/mongodb/src/main/java/com/mongodb/MongoURI.java
similarity index 100%
rename from src/main/com/mongodb/MongoURI.java
rename to mongodb/src/main/java/com/mongodb/MongoURI.java
diff --git a/src/main/com/mongodb/OutMessage.java b/mongodb/src/main/java/com/mongodb/OutMessage.java
similarity index 100%
rename from src/main/com/mongodb/OutMessage.java
rename to mongodb/src/main/java/com/mongodb/OutMessage.java
diff --git a/src/main/com/mongodb/QueryBuilder.java b/mongodb/src/main/java/com/mongodb/QueryBuilder.java
similarity index 100%
rename from src/main/com/mongodb/QueryBuilder.java
rename to mongodb/src/main/java/com/mongodb/QueryBuilder.java
diff --git a/src/main/com/mongodb/QueryOperators.java b/mongodb/src/main/java/com/mongodb/QueryOperators.java
similarity index 100%
rename from src/main/com/mongodb/QueryOperators.java
rename to mongodb/src/main/java/com/mongodb/QueryOperators.java
diff --git a/src/main/com/mongodb/RawDBObject.java b/mongodb/src/main/java/com/mongodb/RawDBObject.java
similarity index 100%
rename from src/main/com/mongodb/RawDBObject.java
rename to mongodb/src/main/java/com/mongodb/RawDBObject.java
diff --git a/src/main/com/mongodb/ReflectionDBObject.java b/mongodb/src/main/java/com/mongodb/ReflectionDBObject.java
similarity index 100%
rename from src/main/com/mongodb/ReflectionDBObject.java
rename to mongodb/src/main/java/com/mongodb/ReflectionDBObject.java
diff --git a/src/main/com/mongodb/ReplicaSetStatus.java b/mongodb/src/main/java/com/mongodb/ReplicaSetStatus.java
similarity index 100%
rename from src/main/com/mongodb/ReplicaSetStatus.java
rename to mongodb/src/main/java/com/mongodb/ReplicaSetStatus.java
diff --git a/src/main/com/mongodb/Response.java b/mongodb/src/main/java/com/mongodb/Response.java
similarity index 100%
rename from src/main/com/mongodb/Response.java
rename to mongodb/src/main/java/com/mongodb/Response.java
diff --git a/src/main/com/mongodb/ServerAddress.java b/mongodb/src/main/java/com/mongodb/ServerAddress.java
similarity index 100%
rename from src/main/com/mongodb/ServerAddress.java
rename to mongodb/src/main/java/com/mongodb/ServerAddress.java
diff --git a/src/main/com/mongodb/ServerError.java b/mongodb/src/main/java/com/mongodb/ServerError.java
similarity index 100%
rename from src/main/com/mongodb/ServerError.java
rename to mongodb/src/main/java/com/mongodb/ServerError.java
diff --git a/src/main/com/mongodb/WriteConcern.java b/mongodb/src/main/java/com/mongodb/WriteConcern.java
similarity index 100%
rename from src/main/com/mongodb/WriteConcern.java
rename to mongodb/src/main/java/com/mongodb/WriteConcern.java
diff --git a/src/main/com/mongodb/WriteResult.java b/mongodb/src/main/java/com/mongodb/WriteResult.java
similarity index 100%
rename from src/main/com/mongodb/WriteResult.java
rename to mongodb/src/main/java/com/mongodb/WriteResult.java
diff --git a/src/main/com/mongodb/gridfs/CLI.java b/mongodb/src/main/java/com/mongodb/gridfs/CLI.java
similarity index 100%
rename from src/main/com/mongodb/gridfs/CLI.java
rename to mongodb/src/main/java/com/mongodb/gridfs/CLI.java
diff --git a/src/main/com/mongodb/gridfs/GridFS.java b/mongodb/src/main/java/com/mongodb/gridfs/GridFS.java
similarity index 100%
rename from src/main/com/mongodb/gridfs/GridFS.java
rename to mongodb/src/main/java/com/mongodb/gridfs/GridFS.java
diff --git a/src/main/com/mongodb/gridfs/GridFSDBFile.java b/mongodb/src/main/java/com/mongodb/gridfs/GridFSDBFile.java
similarity index 100%
rename from src/main/com/mongodb/gridfs/GridFSDBFile.java
rename to mongodb/src/main/java/com/mongodb/gridfs/GridFSDBFile.java
diff --git a/src/main/com/mongodb/gridfs/GridFSFile.java b/mongodb/src/main/java/com/mongodb/gridfs/GridFSFile.java
similarity index 100%
rename from src/main/com/mongodb/gridfs/GridFSFile.java
rename to mongodb/src/main/java/com/mongodb/gridfs/GridFSFile.java
diff --git a/src/main/com/mongodb/gridfs/GridFSInputFile.java b/mongodb/src/main/java/com/mongodb/gridfs/GridFSInputFile.java
similarity index 100%
rename from src/main/com/mongodb/gridfs/GridFSInputFile.java
rename to mongodb/src/main/java/com/mongodb/gridfs/GridFSInputFile.java
diff --git a/src/main/com/mongodb/gridfs/package.html b/mongodb/src/main/java/com/mongodb/gridfs/package.html
similarity index 100%
rename from src/main/com/mongodb/gridfs/package.html
rename to mongodb/src/main/java/com/mongodb/gridfs/package.html
diff --git a/src/main/com/mongodb/io/ByteBufferFactory.java b/mongodb/src/main/java/com/mongodb/io/ByteBufferFactory.java
similarity index 100%
rename from src/main/com/mongodb/io/ByteBufferFactory.java
rename to mongodb/src/main/java/com/mongodb/io/ByteBufferFactory.java
diff --git a/src/main/com/mongodb/io/ByteBufferHolder.java b/mongodb/src/main/java/com/mongodb/io/ByteBufferHolder.java
similarity index 100%
rename from src/main/com/mongodb/io/ByteBufferHolder.java
rename to mongodb/src/main/java/com/mongodb/io/ByteBufferHolder.java
diff --git a/src/main/com/mongodb/io/ByteBufferInputStream.java b/mongodb/src/main/java/com/mongodb/io/ByteBufferInputStream.java
similarity index 100%
rename from src/main/com/mongodb/io/ByteBufferInputStream.java
rename to mongodb/src/main/java/com/mongodb/io/ByteBufferInputStream.java
diff --git a/src/main/com/mongodb/io/ByteBufferOutputStream.java b/mongodb/src/main/java/com/mongodb/io/ByteBufferOutputStream.java
similarity index 100%
rename from src/main/com/mongodb/io/ByteBufferOutputStream.java
rename to mongodb/src/main/java/com/mongodb/io/ByteBufferOutputStream.java
diff --git a/src/main/com/mongodb/io/ByteStream.java b/mongodb/src/main/java/com/mongodb/io/ByteStream.java
similarity index 100%
rename from src/main/com/mongodb/io/ByteStream.java
rename to mongodb/src/main/java/com/mongodb/io/ByteStream.java
diff --git a/src/main/com/mongodb/io/StreamUtil.java b/mongodb/src/main/java/com/mongodb/io/StreamUtil.java
similarity index 100%
rename from src/main/com/mongodb/io/StreamUtil.java
rename to mongodb/src/main/java/com/mongodb/io/StreamUtil.java
diff --git a/src/main/com/mongodb/io/ZipUtil.java b/mongodb/src/main/java/com/mongodb/io/ZipUtil.java
similarity index 100%
rename from src/main/com/mongodb/io/ZipUtil.java
rename to mongodb/src/main/java/com/mongodb/io/ZipUtil.java
diff --git a/src/main/com/mongodb/package.html b/mongodb/src/main/java/com/mongodb/package.html
similarity index 100%
rename from src/main/com/mongodb/package.html
rename to mongodb/src/main/java/com/mongodb/package.html
diff --git a/src/main/com/mongodb/util/Args.java b/mongodb/src/main/java/com/mongodb/util/Args.java
similarity index 100%
rename from src/main/com/mongodb/util/Args.java
rename to mongodb/src/main/java/com/mongodb/util/Args.java
diff --git a/src/main/com/mongodb/util/FastStack.java b/mongodb/src/main/java/com/mongodb/util/FastStack.java
similarity index 100%
rename from src/main/com/mongodb/util/FastStack.java
rename to mongodb/src/main/java/com/mongodb/util/FastStack.java
diff --git a/src/main/com/mongodb/util/Hash.java b/mongodb/src/main/java/com/mongodb/util/Hash.java
similarity index 100%
rename from src/main/com/mongodb/util/Hash.java
rename to mongodb/src/main/java/com/mongodb/util/Hash.java
diff --git a/src/main/com/mongodb/util/IdentitySet.java b/mongodb/src/main/java/com/mongodb/util/IdentitySet.java
similarity index 100%
rename from src/main/com/mongodb/util/IdentitySet.java
rename to mongodb/src/main/java/com/mongodb/util/IdentitySet.java
diff --git a/src/main/com/mongodb/util/JSON.java b/mongodb/src/main/java/com/mongodb/util/JSON.java
similarity index 100%
rename from src/main/com/mongodb/util/JSON.java
rename to mongodb/src/main/java/com/mongodb/util/JSON.java
diff --git a/src/main/com/mongodb/util/JSONCallback.java b/mongodb/src/main/java/com/mongodb/util/JSONCallback.java
similarity index 100%
rename from src/main/com/mongodb/util/JSONCallback.java
rename to mongodb/src/main/java/com/mongodb/util/JSONCallback.java
diff --git a/src/main/com/mongodb/util/MyAsserts.java b/mongodb/src/main/java/com/mongodb/util/MyAsserts.java
similarity index 100%
rename from src/main/com/mongodb/util/MyAsserts.java
rename to mongodb/src/main/java/com/mongodb/util/MyAsserts.java
diff --git a/src/main/com/mongodb/util/OptionMap.java b/mongodb/src/main/java/com/mongodb/util/OptionMap.java
similarity index 100%
rename from src/main/com/mongodb/util/OptionMap.java
rename to mongodb/src/main/java/com/mongodb/util/OptionMap.java
diff --git a/src/main/com/mongodb/util/SimplePool.java b/mongodb/src/main/java/com/mongodb/util/SimplePool.java
similarity index 100%
rename from src/main/com/mongodb/util/SimplePool.java
rename to mongodb/src/main/java/com/mongodb/util/SimplePool.java
diff --git a/src/main/com/mongodb/util/StringBuilderPool.java b/mongodb/src/main/java/com/mongodb/util/StringBuilderPool.java
similarity index 100%
rename from src/main/com/mongodb/util/StringBuilderPool.java
rename to mongodb/src/main/java/com/mongodb/util/StringBuilderPool.java
diff --git a/src/main/com/mongodb/util/StringParseUtil.java b/mongodb/src/main/java/com/mongodb/util/StringParseUtil.java
similarity index 100%
rename from src/main/com/mongodb/util/StringParseUtil.java
rename to mongodb/src/main/java/com/mongodb/util/StringParseUtil.java
diff --git a/src/main/com/mongodb/util/StringRangeSet.java b/mongodb/src/main/java/com/mongodb/util/StringRangeSet.java
similarity index 100%
rename from src/main/com/mongodb/util/StringRangeSet.java
rename to mongodb/src/main/java/com/mongodb/util/StringRangeSet.java
diff --git a/src/main/com/mongodb/util/TestCase.java b/mongodb/src/main/java/com/mongodb/util/TestCase.java
similarity index 100%
rename from src/main/com/mongodb/util/TestCase.java
rename to mongodb/src/main/java/com/mongodb/util/TestCase.java
diff --git a/src/main/com/mongodb/util/TestNGListener.java b/mongodb/src/main/java/com/mongodb/util/TestNGListener.java
similarity index 100%
rename from src/main/com/mongodb/util/TestNGListener.java
rename to mongodb/src/main/java/com/mongodb/util/TestNGListener.java
diff --git a/src/main/com/mongodb/util/ThreadPool.java b/mongodb/src/main/java/com/mongodb/util/ThreadPool.java
similarity index 100%
rename from src/main/com/mongodb/util/ThreadPool.java
rename to mongodb/src/main/java/com/mongodb/util/ThreadPool.java
diff --git a/src/main/com/mongodb/util/ThreadUtil.java b/mongodb/src/main/java/com/mongodb/util/ThreadUtil.java
similarity index 100%
rename from src/main/com/mongodb/util/ThreadUtil.java
rename to mongodb/src/main/java/com/mongodb/util/ThreadUtil.java
diff --git a/src/main/com/mongodb/util/TimeConstants.java b/mongodb/src/main/java/com/mongodb/util/TimeConstants.java
similarity index 100%
rename from src/main/com/mongodb/util/TimeConstants.java
rename to mongodb/src/main/java/com/mongodb/util/TimeConstants.java
diff --git a/src/main/com/mongodb/util/UniqueList.java b/mongodb/src/main/java/com/mongodb/util/UniqueList.java
similarity index 100%
rename from src/main/com/mongodb/util/UniqueList.java
rename to mongodb/src/main/java/com/mongodb/util/UniqueList.java
diff --git a/src/main/com/mongodb/util/Util.java b/mongodb/src/main/java/com/mongodb/util/Util.java
similarity index 100%
rename from src/main/com/mongodb/util/Util.java
rename to mongodb/src/main/java/com/mongodb/util/Util.java
diff --git a/src/main/com/mongodb/util/WeakBag.java b/mongodb/src/main/java/com/mongodb/util/WeakBag.java
similarity index 100%
rename from src/main/com/mongodb/util/WeakBag.java
rename to mongodb/src/main/java/com/mongodb/util/WeakBag.java
diff --git a/src/util/ApiToolsTaglet.java b/mongodb/src/util/ApiToolsTaglet.java
similarity index 100%
rename from src/util/ApiToolsTaglet.java
rename to mongodb/src/util/ApiToolsTaglet.java
diff --git a/pom.xml b/pom.xml
new file mode 100644
index 00000000000..1bd79b53a8a
--- /dev/null
+++ b/pom.xml
@@ -0,0 +1,29 @@
+
+
+ 4.0.0
+ org.mongodb
+ mongodb-parent
+ 2.4-SNAPSHOT
+ pom
+ MongoDB Java Driver
+ Parent project for java driver MongoDB
+ http://mongodb.org/
+
+
+
+ The Apache Software License, Version 2.0
+ http://www.apache.org/licenses/LICENSE-2.0.txt
+ repo
+
+
+
+
+ http://github.com/mongodb/mongo-java-driver
+
+
+ mongodb
+ bson
+
+
+
diff --git a/src/main/META-INF/MANIFEST.MF b/src/main/META-INF/MANIFEST.MF
deleted file mode 100644
index a33b6c0d7c8..00000000000
--- a/src/main/META-INF/MANIFEST.MF
+++ /dev/null
@@ -1,6 +0,0 @@
-Manifest-Version: 1.0
-Bundle-ManifestVersion: 2
-Bundle-Name: MongoDB
-Bundle-SymbolicName: com.mongodb
-Bundle-Version: 2.1.0
-Export-Package: com.mongodb, com.mongodb.io, com.mongodb.util, com.mongodb.gridfs, org.bson, org.bson.util, org.bson.types, org.bson.io
diff --git a/src/test/com/mongodb/BasicDBObjectTest.java b/src/test/com/mongodb/BasicDBObjectTest.java
deleted file mode 100644
index 6acc7118edd..00000000000
--- a/src/test/com/mongodb/BasicDBObjectTest.java
+++ /dev/null
@@ -1,129 +0,0 @@
-// BasicDBObjectTest.java
-
-/**
- * Copyright (C) 2008 10gen Inc.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.mongodb;
-
-import org.testng.annotations.*;
-
-import com.mongodb.util.*;
-
-public class BasicDBObjectTest extends TestCase {
-
- @Test(groups = {"basic"})
- public void testBasic(){
- BasicDBObject a = new BasicDBObject( "x" , 1 );
- BasicDBObject b = new BasicDBObject( "x" , 1 );
- assert( a.equals( b ) );
-
- Object x = JSON.parse( "{ 'x' : 1 }" );
- assert( a.equals( x ) );
- }
-
-
- @Test(groups = {"basic"})
- public void testBasic2(){
- BasicDBObject a = new BasicDBObject( "x" , 1 );
- DBObject b = BasicDBObjectBuilder.start().append( "x" , 1 ).get();
- assert( a.equals( b ) );
- assert( a.equals( JSON.parse( "{ 'x' : 1 }" ) ) );
- assert( ! a.equals( JSON.parse( "{ 'x' : 2 }" ) ) );
- }
-
-
- @Test(groups = {"basic"})
- public void testBuilderIsEmpty(){
- BasicDBObjectBuilder b = BasicDBObjectBuilder.start();
- assert( b.isEmpty() );
- b.append( "a" , 1 );
- assert( !b.isEmpty() );
- assert( b.get().equals( JSON.parse( "{ 'a' : 1 }" ) ) );
- }
-
- @Test(groups = {"basic"})
- public void testBuilderNested(){
- BasicDBObjectBuilder b = BasicDBObjectBuilder.start();
- b.add( "a", 1 );
- b.push( "b" ).append( "c", 2 ).pop();
- DBObject a = b.get();
- assert( a.equals( JSON.parse( "{ 'a' : 1, 'b' : { 'c' : 2 } }" ) ) );
- }
-
- @Test(groups = {"basic"})
- public void testDown1(){
- BasicDBObjectBuilder b = BasicDBObjectBuilder.start();
- b.append( "x" , 1 );
- b.push("y");
- b.append( "a" , 2 );
- b.pop();
- b.push( "z" );
- b.append( "b" , 3 );
-
-
- Object x = b.get();
- Object y = JSON.parse( "{ 'x' : 1 , 'y' : { 'a' : 2 } , 'z' : { 'b' : 3 } }" );
-
- assert( x.equals( y ) );
- }
-
- void _equal( BasicDBObject x , BasicDBObject y ){
- assert( x.equals( y ) );
- assert( y.equals( x ) );
- }
-
- void _notequal( BasicDBObject x , BasicDBObject y ){
- assert( ! x.equals( y ) );
- assert( ! y.equals( x ) );
- }
-
- @Test
- public void testEquals(){
- BasicDBObject a = new BasicDBObject();
- BasicDBObject b = new BasicDBObject();
-
-
- _equal( a , b );
-
- a.put( "x" , 1 );
- _notequal( a , b );
-
- b.put( "x" , 1 );
- _equal( a , b );
-
- a.removeField( "x" );
- _notequal( a , b );
-
- b.removeField( "x" );
- _equal( a , b );
-
- a.put( "x" , null );
- b.put( "x" , 2 );
- _notequal( a , b );
-
- a.put( "x" , 2 );
- b.put( "x" , null );
- _notequal( a , b );
- }
-
-
- public static void main( String args[] )
- throws Exception {
- (new BasicDBObjectTest()).runConsole();
-
- }
-
-}
diff --git a/src/test/com/mongodb/ByteTest.java b/src/test/com/mongodb/ByteTest.java
deleted file mode 100644
index c6c2cc24884..00000000000
--- a/src/test/com/mongodb/ByteTest.java
+++ /dev/null
@@ -1,442 +0,0 @@
-/**
- * Copyright (C) 2008 10gen Inc.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.mongodb;
-
-import java.io.*;
-import java.util.*;
-import java.util.regex.*;
-import java.io.IOException;
-
-import org.testng.annotations.Test;
-
-import com.mongodb.util.*;
-
-import org.bson.*;
-import org.bson.types.*;
-
-
-public class ByteTest extends TestCase {
-
- public ByteTest()
- throws IOException , MongoException {
- super();
- cleanupMongo = new Mongo( "127.0.0.1" );
- cleanupDB = "com_mongodb_unittest_ByteTest";
- _db = cleanupMongo.getDB( cleanupDB );
-
-
- }
-
- @Test(groups = {"basic"})
- public void testObject1(){
- DBObject o = new BasicDBObject();
- o.put( "eliot" , "horowitz" );
- o.put( "num" , 517 );
-
-
- BSONObject read = BSON.decode( BSON.encode( o ) );
-
- assertEquals( "horowitz" , read.get( "eliot" ).toString() );
- assertEquals( 517.0 , ((Integer)read.get( "num" )).doubleValue() );
- }
-
- @Test(groups = {"basic"})
- public void testString()
- throws Exception {
-
- String eliot = java.net.URLDecoder.decode( "horowitza%C3%BCa" , "UTF-8" );
-
- DBObject o = new BasicDBObject();
- o.put( "eliot" , eliot );
- o.put( "num" , 517 );
-
- BSONObject read = BSON.decode( BSON.encode( o ) );
-
- assertEquals( eliot , read.get( "eliot" ).toString() );
- assertEquals( 517.0 , ((Integer)read.get( "num" )).doubleValue() );
-
- }
-
- @Test(groups = {"basic"})
- public void testObject2(){
- DBObject o = new BasicDBObject();
- o.put( "eliot" , "horowitz" );
- o.put( "num" , 517.3 );
- o.put( "z" , "y" );
- o.put( "asd" , null );
-
- DBObject o2 = new BasicDBObject();
- o2.put( "a" , "b" );
- o2.put( "b" , "a" );
- o.put( "next" , o2 );
-
- BSONObject read = BSON.decode( BSON.encode( o ) );
-
- assertEquals( "horowitz" , read.get( "eliot" ).toString() );
- assertEquals( 517.3 , ((Double)read.get( "num" )).doubleValue() );
- assertEquals( "b" , ((BSONObject)read.get( "next" ) ).get( "a" ).toString() );
- assertEquals( "a" , ((BSONObject)read.get( "next" ) ).get( "b" ).toString() );
- assertEquals( "y" , read.get( "z" ).toString() );
- assertEquals( o.keySet().size() , read.keySet().size() );
-
- }
-
- @Test(groups = {"basic"})
- public void testArray1(){
- DBObject o = new BasicDBObject();
- o.put( "eliot" , "horowitz" );
- o.put( "num" , 517 );
- o.put( "z" , "y" );
- o.put( "asd" , null );
- o.put( "myt" , true );
- o.put( "myf" , false );
-
- List a = new ArrayList();
- a.add( "A" );
- a.add( "B" );
- a.add( "C" );
- o.put( "a" , a );
-
- o.put( "d" , new Date() );
- //o.put( "r" , Pattern.compile( "\\d+" , "i" ) );
-
- BSONObject read = BSON.decode( BSON.encode( o ) );
-
- assertEquals( "horowitz" , read.get( "eliot" ).toString() );
- assertEquals( 517 , ((Integer)read.get( "num" )).intValue() );
- assertEquals( "y" , read.get( "z" ).toString() );
- assertEquals( o.keySet().size() , read.keySet().size() );
- assertEquals( 3 , a.size() );
- assertEquals( a.size() , ((List)read.get( "a" ) ).size() );
- assertEquals( "A" , ((List)read.get( "a" ) ).get( 0 ).toString() );
- assertEquals( "B" , ((List)read.get( "a" ) ).get( 1 ).toString() );
- assertEquals( "C" , ((List)read.get( "a" ) ).get( 2 ).toString() );
- assertEquals( ((Date)o.get("d")).getTime() , ((Date)read.get("d")).getTime() );
- assertEquals( true , (Boolean)o.get("myt") );
- assertEquals( false , (Boolean)o.get("myf") );
- //assertEquals( o.get( "r" ).toString() , read.get("r").toString() );
-
- }
-
- @Test
- public void testArray2(){
- DBObject x = new BasicDBObject();
- x.put( "a" , new String[]{ "a" , "b" , "c" } );
- x.put( "b" , new int[]{ 1 , 2 , 3 } );
-
- BSONObject y = BSON.decode( BSON.encode( x ) );
-
- List l = (List)y.get("a");
- assertEquals( 3 , l.size() );
- assertEquals( "a" , l.get(0) );
- assertEquals( "b" , l.get(1) );
- assertEquals( "c" , l.get(2) );
-
- l = (List)y.get("b");
- assertEquals( 3 , l.size() );
- assertEquals( 1 , l.get(0) );
- assertEquals( 2 , l.get(1) );
- assertEquals( 3 , l.get(2) );
- }
-
- @Test(groups = {"basic"})
- public void testObjcetId(){
- assertTrue( (new ObjectId()).compareTo( new ObjectId() ) < 0 );
- assertTrue( (new ObjectId(0 , 0 , 0 )).compareTo( new ObjectId() ) < 0 );
- assertTrue( (new ObjectId(0 , 0 , 0 )).compareTo( new ObjectId( 0 , 0 , 1 ) ) < 0 );
-
- assertTrue( (new ObjectId(5 , 5 , 5 )).compareTo( new ObjectId( 5 , 5 , 6 ) ) < 0 );
- assertTrue( (new ObjectId(5 , 5 , 5 )).compareTo( new ObjectId( 5 , 6 , 5 ) ) < 0 );
- assertTrue( (new ObjectId(5 , 5 , 5 )).compareTo( new ObjectId( 6 , 5 , 5 ) ) < 0 );
-
- }
-
-
- @Test(groups = {"basic"})
- public void testBinary() {
- byte barray[] = new byte[256];
- for( int i=0; i<256; i++ ) {
- barray[i] = (byte)(i-128);
- }
-
- DBObject o = new BasicDBObject();
- o.put( "bytes", barray );
-
- byte[] encoded = BSON.encode( o );
- assertEquals( 277 , encoded.length );
-
- BSONObject read = BSON.decode( encoded );
- byte[] b = (byte[])read.get( "bytes" );
- for( int i=0; i<256; i++ ) {
- assertEquals( b[i], barray[i] );
- }
- assertEquals( o.keySet().size() , read.keySet().size() );
- }
-
- private void go( DBObject o , int serialized_len ) {
- go( o, serialized_len, 0 );
- }
-
- private void go( DBObject o , int serialized_len, int transient_fields ) {
- byte[] encoded = BSON.encode( o );
- assertEquals( serialized_len , encoded.length );
-
- BSONObject read = BSON.decode( encoded );
- assertEquals( o.keySet().size() - transient_fields, read.keySet().size() );
- if ( transient_fields == 0 )
- assertEquals( o , read );
- }
-
- @Test(groups = {"basic"})
- public void testEncodeDecode() {
- ArrayList t = new ArrayList();
- Object obj = null;
-
- // null object
- boolean threw = false;
- try {
- go( (DBObject)null, 0 );
- }
- catch( RuntimeException e ) {
- threw = true;
- }
- assertEquals( threw, true );
- threw = false;
-
- DBObject o = new BasicDBObject();
- int serialized_len = 5;
-
- // empty obj
- go( o, 5 );
-
- // _id == null
- o.put( "_id" , obj );
- assertEquals( Bytes.getType( obj ), Bytes.NULL );
- go( o, 10 );
-
- // _id == non-objid
- obj = new ArrayList();
- o.put( "_id" , obj );
- assertEquals( Bytes.getType( obj ), Bytes.ARRAY );
- go( o, 15 );
-
- // _id == ObjectId
- obj = new ObjectId();
- o.put( "_id" , obj );
- assertEquals( Bytes.getType( obj ), Bytes.OID );
- go( o, 22 );
-
- // dbcollection
- try {
- obj = _db.getCollection( "test" );
- o.put( "_id" , obj );
- assertEquals( Bytes.getType( obj ), 0 );
- go( o, 22 );
- }
- catch( RuntimeException e ) {
- threw = true;
- }
- assertEquals( threw, true );
- threw = false;
-
- t.add( "collection" );
- o = new BasicDBObject();
- o.put( "collection" , _db.getCollection( "test" ) );
- o.put( "_transientFields" , t );
- go( o, 5, 2 );
- t.clear();
-
- // transientFields
- o = new BasicDBObject();
- o.put( "_transientFields", new ArrayList() );
- go( o, 5, 1 );
-
- t.add( "foo" );
- o = new BasicDBObject();
- o.put( "_transientFields", t );
- o.put( "foo", "bar" );
- go( o, 5, 2 );
- t.clear();
-
- o = new BasicDBObject();
- o.put( "z" , "" );
- go( o, 13 );
- t.clear();
-
- // $where
- /*o = new BasicDBObject();
- o.put( "$where", "eval( true )" );
- go( o, 30 );
- */
-
- obj = 5;
- o = new BasicDBObject();
- o.put( "$where", obj );
- assertEquals( Bytes.getType( obj ), Bytes.NUMBER );
- go( o, 17 );
- }
-
- @Test(groups = {"basic"})
- public void testPatternFlags() {
- boolean threw = false;
- assertEquals( 0, Bytes.regexFlags( "" ) );
- assertEquals( "", Bytes.regexFlags( 0 ) );
-
- try {
- Bytes.regexFlags( "f" );
- }
- catch( RuntimeException e ) {
- threw = true;
- }
- assertEquals( threw, true );
- threw = false;
-
- try {
- Bytes.regexFlags( 513 );
- }
- catch( RuntimeException e ) {
- threw = true;
- }
- assertEquals( threw, true );
-
- Pattern lotsoflags = Pattern.compile( "foo", Pattern.CANON_EQ |
- Pattern.DOTALL |
- Pattern.CASE_INSENSITIVE |
- Pattern.UNIX_LINES |
- Pattern.MULTILINE |
- Pattern.LITERAL |
- Pattern.UNICODE_CASE |
- Pattern.COMMENTS |
- 256 );
-
- String s = Bytes.regexFlags( lotsoflags.flags() );
- char prev = s.charAt( 0 );
- for( int i=1; i got ){
- assertEquals( want.length , got.size() );
- int pos = 0;
- for ( String s : got ){
- assertEquals( want[pos++] , s );
- }
- }
-
- @Test(groups = {"basic"})
- public void testBytes2(){
- DBObject x = BasicDBObjectBuilder.start( "x" , 1 ).add( "y" , "asdasd" ).get();
- byte[] b = Bytes.encode( x );
- assertEquals( x , Bytes.decode( b ) );
- }
-
- @Test
- public void testMany()
- throws IOException {
-
- DBObject orig = new BasicDBObject();
- orig.put( "a" , 5 );
- orig.put( "ab" , 5.1 );
- orig.put( "abc" , 5123L );
- orig.put( "abcd" , "asdasdasd" );
- orig.put( "abcde" , "asdasdasdasdasdasdasdasd" );
- orig.put( "abcdef" , Arrays.asList( new String[]{ "asdasdasdasdasdasdasdasd" , "asdasdasdasdasdasdasdasd" } ) );
-
- byte[] b = Bytes.encode( orig );
- final int n = 1000;
-
- ByteArrayOutputStream out = new ByteArrayOutputStream();
- for ( int i=0; i expectedKeys = new ArrayList();
- final BasicDBObject o = new BasicDBObject();
- for (int i = 1; i < 1000; i++) {
- final String key = String.valueOf(i);
- expectedKeys.add(key);
- o.put(key, "Test" + key);
- }
- final List keysFromKeySet = new ArrayList(o.keySet());
- final List keysFromEntrySet = new ArrayList();
- for (final Map.Entry entry : o.entrySet()) {
- keysFromEntrySet.add(entry.getKey());
- }
- assertEquals(keysFromKeySet, expectedKeys);
- assertEquals(keysFromEntrySet, expectedKeys);
- }
-
- private DB _db;
-
- public static void main( String args[] ) {
- (new DBObjectTest()).runConsole();
- }
-}
-
diff --git a/src/test/com/mongodb/DBRefTest.java b/src/test/com/mongodb/DBRefTest.java
deleted file mode 100644
index a745bda74f9..00000000000
--- a/src/test/com/mongodb/DBRefTest.java
+++ /dev/null
@@ -1,156 +0,0 @@
-/**
- * Copyright (C) 2008 10gen Inc.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.mongodb;
-
-import java.net.*;
-import java.util.*;
-
-import org.bson.*;
-import org.bson.types.*;
-import org.testng.annotations.*;
-
-import com.mongodb.util.*;
-
-public class DBRefTest extends TestCase {
-
- public DBRefTest() {
- try {
- cleanupMongo = new Mongo( "127.0.0.1" );
- cleanupDB = "com_monogodb_unittest_DBRefTest";
- _db = cleanupMongo.getDB( cleanupDB );
- }
- catch(UnknownHostException e) {
- throw new MongoException("couldn't connect");
- }
- }
-
- @Test(groups = {"basic"})
- public void testDBRefBaseToString(){
-
- ObjectId id = new ObjectId("123456789012345678901234");
- DBRefBase ref = new DBRefBase(_db, "foo.bar", id);
-
- assertEquals("{ \"$ref\" : \"foo.bar\", \"$id\" : \"123456789012345678901234\" }", ref.toString());
- }
-
- @Test(groups = {"basic"})
- public void testDBRef(){
-
- DBRef ref = new DBRef(_db, "hello", (Object)"world");
- DBObject o = new BasicDBObject("!", ref);
-
- OutMessage out = new OutMessage( cleanupMongo );
- out.putObject( o );
-
- DBCallback cb = new DBCallback( null );
- BSONDecoder decoder = new BSONDecoder();
- decoder.decode( out.toByteArray() , cb );
- DBObject read = cb.dbget();
-
- String correct = null;
- correct = "{\"!\":{\"$ref\":\"hello\",\"$id\":\"world\"}}";
-
- String got = read.toString().replaceAll( " +" , "" );
- assertEquals( correct , got );
- }
-
- @Test(groups = {"basic"})
- public void testDBRefFetches(){
- DBCollection coll = _db.getCollection("x");
- coll.drop();
-
- BasicDBObject obj = new BasicDBObject("_id", 321325243);
- coll.save(obj);
-
- DBRef ref = new DBRef(_db, "x", 321325243);
- DBObject deref = ref.fetch();
-
- assertTrue(deref != null);
- assertEquals(321325243, ((Number)deref.get("_id")).intValue());
-
- DBObject refobj = BasicDBObjectBuilder.start().add("$ref", "x").add("$id", 321325243).get();
- deref = DBRef.fetch(_db, refobj);
-
- assertTrue(deref != null);
- assertEquals(321325243, ((Number)deref.get("_id")).intValue());
- }
-
- @SuppressWarnings("unchecked")
- @Test
- public void testRefListRoundTrip(){
- DBCollection a = _db.getCollection( "reflistfield" );
- List refs = new ArrayList();
- refs.add(new DBRef(_db, "other", 12));
- refs.add(new DBRef(_db, "other", 14));
- refs.add(new DBRef(_db, "other", 16));
- a.save( BasicDBObjectBuilder.start( "refs" , refs).get() );
-
- DBObject loaded = a.findOne();
- assertNotNull( loaded );
- List refsLoaded = (List) loaded.get("refs");
- assertNotNull( refsLoaded );
- assertEquals(3, refsLoaded.size());
- assertEquals(DBRef.class, refsLoaded.get(0).getClass());
- assertEquals(12, refsLoaded.get(0).getId());
- assertEquals(14, refsLoaded.get(1).getId());
- assertEquals(16, refsLoaded.get(2).getId());
-
- }
-
-
- @Test
- public void testRoundTrip(){
- DBCollection a = _db.getCollection( "refroundtripa" );
- DBCollection b = _db.getCollection( "refroundtripb" );
- a.drop();
- b.drop();
-
- a.save( BasicDBObjectBuilder.start( "_id" , 17 ).add( "n" , 111 ).get() );
- b.save( BasicDBObjectBuilder.start( "n" , 12 ).add( "l" , new DBRef( _db , "refroundtripa" , 17 ) ).get() );
-
- assertEquals( 12 , b.findOne().get( "n" ) );
- assertEquals( DBRef.class , b.findOne().get( "l" ).getClass() );
- assertEquals( 111 , ((DBRef)(b.findOne().get( "l" ))).fetch().get( "n" ) );
-
- }
-
- @Test
- public void testFindByDBRef(){
- DBCollection b = _db.getCollection( "b" );
- b.drop();
- DBRef ref = new DBRef( _db , "fake" , 17 );
-
- b.save( BasicDBObjectBuilder.start( "n" , 12 ).add( "l" , ref ).get() );
-
- assertEquals( 12 , b.findOne().get( "n" ) );
- assertEquals( DBRef.class , b.findOne().get( "l" ).getClass() );
-
- DBObject loaded = b.findOne(BasicDBObjectBuilder.start( "l" , ref ).get() );
- assertEquals( 12 , loaded.get( "n" ) );
- assertEquals( DBRef.class , loaded.get( "l" ).getClass() );
- assertEquals( ref.getId(), ((DBRef)loaded.get( "l" )).getId());
- assertEquals( ref.getRef(), ((DBRef)loaded.get( "l" )).getRef());
- assertEquals( ref.getDB(), ((DBRef)loaded.get( "l" )).getDB());
- }
-
- DB _db;
-
- public static void main( String args[] ) {
- (new DBRefTest()).runConsole();
- }
-}
-
diff --git a/src/test/com/mongodb/DBTest.java b/src/test/com/mongodb/DBTest.java
deleted file mode 100644
index 471df7b9b97..00000000000
--- a/src/test/com/mongodb/DBTest.java
+++ /dev/null
@@ -1,144 +0,0 @@
-/**
- * Copyright (C) 2008 10gen Inc.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.mongodb;
-
-import java.io.*;
-import java.net.UnknownHostException;
-import java.util.*;
-import java.util.regex.*;
-
-import org.testng.annotations.Test;
-
-import com.mongodb.util.*;
-
-public class DBTest extends TestCase {
-
- public DBTest()
- throws UnknownHostException {
- super();
- cleanupMongo = new Mongo( "127.0.0.1" );
- cleanupDB = "com_mongodb_unittest_DBTest";
- _db = cleanupMongo.getDB( cleanupDB );
- }
-
- @Test(groups = {"basic"})
- public void testCreateCollection() {
- _db.getCollection( "foo1" ).drop();
- _db.getCollection( "foo2" ).drop();
- _db.getCollection( "foo3" ).drop();
- _db.getCollection( "foo4" ).drop();
-
- BasicDBObject o1 = new BasicDBObject("capped", false);
- DBCollection c = _db.createCollection("foo1", o1);
-
- DBObject o2 = BasicDBObjectBuilder.start().add("capped", true)
- .add("size", 100).get();
- c = _db.createCollection("foo2", o2);
- for (int i=0; i<30; i++) {
- c.insert(new BasicDBObject("x", i));
- }
- assertTrue(c.find().count() < 10);
-
- DBObject o3 = BasicDBObjectBuilder.start().add("capped", true)
- .add("size", 1000).add("max", 2).get();
- c = _db.createCollection("foo3", o3);
- for (int i=0; i<30; i++) {
- c.insert(new BasicDBObject("x", i));
- }
- assertEquals(c.find().count(), 2);
-
- try {
- DBObject o4 = BasicDBObjectBuilder.start().add("capped", true)
- .add("size", -20).get();
- c = _db.createCollection("foo4", o4);
- }
- catch(MongoException e) {
- return;
- }
- assertEquals(0, 1);
- }
-
- @Test(groups = {"basic"})
- public void testForCollectionExistence()
- {
- _db.getCollection( "foo1" ).drop();
- _db.getCollection( "foo2" ).drop();
- _db.getCollection( "foo3" ).drop();
- _db.getCollection( "foo4" ).drop();
-
- assertFalse(_db.collectionExists( "foo1" ));
-
- BasicDBObject o1 = new BasicDBObject("capped", false);
- DBCollection c = _db.createCollection("foo1", o1);
-
- assertTrue(_db.collectionExists( "foo1" ), "Collection 'foo' was supposed to be created, but 'collectionExists' did not return true.");
- assertTrue(_db.collectionExists( "FOO1" ));
- assertTrue(_db.collectionExists( "fOo1" ));
-
- _db.getCollection( "foo1" ).drop();
-
- assertFalse(_db.collectionExists( "foo1" ));
- }
-
- /*public static class Person extends DBObject {
-
- public Person(){
-
- }
-
- Person( String name ){
- _name = name;
- }
-
- public String getName(){
- return _name;
- }
-
- public void setName(String name){
- _name = name;
- }
-
- String _name;
- }
-
- public DBTest()
- throws IOException {
- _db = new Mongo( "127.0.0.1" , "dbbasetest" );
- }
-
-
- @Test
- public void test1(){
- DBCollection c = _db.getCollection( "persen.test1" );
- c.drop();
- c.setObjectClass( Person.class );
-
- Person p = new Person( "eliot" );
- c.save( p );
-
- DBObject out = c.findOne();
- assertEquals( "eliot" , out.get( "Name" ) );
- assertTrue( out instanceof Person , "didn't come out as Person" );
- }
- */
-
- final DB _db;
-
- public static void main( String args[] )
- throws Exception {
- (new DBTest()).runConsole();
- }
-}
diff --git a/src/test/com/mongodb/DBTests.java b/src/test/com/mongodb/DBTests.java
deleted file mode 100644
index 3cdf23c2969..00000000000
--- a/src/test/com/mongodb/DBTests.java
+++ /dev/null
@@ -1,62 +0,0 @@
-package com.mongodb;
-
-import java.util.*;
-
-import org.testng.annotations.Test;
-
-import com.mongodb.util.*;
-
-/**
- * Tests aspect of the DB - not really driver tests
- */
-public class DBTests extends TestCase {
-
- final Mongo _mongo;
- final DB _db;
-
- public DBTests()
- throws Exception {
- _mongo = new Mongo();
- cleanupMongo = new Mongo( "127.0.0.1" );
- cleanupDB = "java_com_mongodb_unittest_DBTests";
- _db = cleanupMongo.getDB( cleanupDB );
- }
-
- @Test
- public void testGetCollectionNames() throws MongoException {
- String name = "testGetCollectionNames";
- DBCollection c = _db.getCollection( name );
- c.drop();
- assertFalse( _db.getCollectionNames().contains( name ) );
- c.save( new BasicDBObject( "x" , 1 ) );
- assertTrue( _db.getCollectionNames().contains( name ) );
-
- }
-
-
- @Test
- public void testRename() throws MongoException {
- String namea = "testRenameA";
- String nameb = "testRenameB";
- DBCollection a = _db.getCollection( namea );
- DBCollection b = _db.getCollection( nameb );
-
- a.drop();
- b.drop();
-
- assertEquals( 0 , a.find().count() );
- assertEquals( 0 , b.find().count() );
-
- a.save( new BasicDBObject( "x" , 1 ) );
- assertEquals( 1 , a.find().count() );
- assertEquals( 0 , b.find().count() );
-
- DBCollection b2 = a.rename( nameb );
- assertEquals( 0 , a.find().count() );
- assertEquals( 1 , b.find().count() );
- assertEquals( 1 , b2.find().count() );
-
- assertEquals( b.getName() , b2.getName() );
-
- }
-}
diff --git a/src/test/com/mongodb/ErrorTest.java b/src/test/com/mongodb/ErrorTest.java
deleted file mode 100644
index 35f0871098d..00000000000
--- a/src/test/com/mongodb/ErrorTest.java
+++ /dev/null
@@ -1,97 +0,0 @@
-/**
- * Copyright (C) 2008 10gen Inc.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.mongodb;
-
-import org.testng.annotations.*;
-
-import com.mongodb.util.*;
-
-/**
- *
- */
-public class ErrorTest extends TestCase {
-
- DB _db;
-
- @BeforeClass
- public void setUp() throws Exception{
- cleanupMongo = new Mongo( "127.0.0.1" );
- cleanupDB = "com_mongodb_unittest_ErrorTest";
- _db = cleanupMongo.getDB(cleanupDB);
- }
-
- @Test
- public void testLastError()
- throws MongoException {
-
- _db.resetError();
- assert(_db.getLastError().get("err") == null);
-
- _db.forceError();
-
- assert(_db.getLastError().get("err") != null);
-
- _db.resetError();
- assert(_db.getLastError().get("err") == null);
- }
-
- @Test
- public void testLastErrorWithConcern()
- throws MongoException {
-
- _db.resetError();
- CommandResult cr = _db.getLastError(WriteConcern.FSYNC_SAFE);
- assert(cr.get("err") == null);
- assert(cr.containsField("fsyncFiles"));
- }
-
- @Test
- public void testLastErrorWithConcernAndW()
- throws MongoException {
- if ( /* TODO: running with slaves */ false ){
- _db.resetError();
- CommandResult cr = _db.getLastError(WriteConcern.REPLICAS_SAFE);
- assert(cr.get("err") == null);
- assert(cr.containsField("wtime"));
- }
- }
-
- @Test
- public void testPrevError()
- throws MongoException {
-
- _db.resetError();
-
- assert(_db.getLastError().get("err") == null);
- assert(_db.getPreviousError().get("err") == null);
-
- _db.forceError();
-
- assert(_db.getLastError().get("err") != null);
- assert(_db.getPreviousError().get("err") != null);
-
- _db.getCollection("misc").insert(new BasicDBObject("foo", 1));
-
- assert(_db.getLastError().get("err") == null);
- assert(_db.getPreviousError().get("err") != null);
-
- _db.resetError();
-
- assert(_db.getLastError().get("err") == null);
- assert(_db.getPreviousError().get("err") == null);
- }
-}
diff --git a/src/test/com/mongodb/JavaClientTest.java b/src/test/com/mongodb/JavaClientTest.java
deleted file mode 100644
index ae99e2c3827..00000000000
--- a/src/test/com/mongodb/JavaClientTest.java
+++ /dev/null
@@ -1,686 +0,0 @@
-// JavaClientTest.java
-/**
- * Copyright (C) 2008 10gen Inc.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.mongodb;
-
-import java.io.*;
-import java.nio.*;
-import java.util.*;
-import java.util.regex.*;
-
-import org.bson.*;
-import org.bson.types.*;
-import org.testng.annotations.*;
-
-import com.mongodb.util.*;
-
-public class JavaClientTest extends TestCase {
-
- public JavaClientTest()
- throws IOException , MongoException {
- _mongo = new Mongo( "127.0.0.1" );
- cleanupMongo = _mongo;
- cleanupDB = "com_mongodb_unittest_JavaClientTest";
- _db = cleanupMongo.getDB( cleanupDB );
- }
-
- @Test
- public void test1()
- throws MongoException {
- DBCollection c = _db.getCollection( "test1" );;
- c.drop();
-
- DBObject m = new BasicDBObject();
- m.put( "name" , "eliot" );
- m.put( "state" , "ny" );
-
- c.save( m );
- System.out.println( m.keySet() );
- assert( m.containsField( "_id" ) );
-
- Map out = (Map)(c.findOne( m.get( "_id" )));
- assertEquals( "eliot" , out.get( "name" ) );
- assertEquals( "ny" , out.get( "state" ) );
- }
-
- @Test
- public void test2()
- throws MongoException {
- DBCollection c = _db.getCollection( "test2" );;
- c.drop();
-
- DBObject m = new BasicDBObject();
- m.put( "name" , "eliot" );
- m.put( "state" , "ny" );
-
- Map sub = new HashMap();
- sub.put( "bar" , "1z" );
- m.put( "foo" , sub );
-
- c.save( m );
-
- assert( m.containsField( "_id" ) );
-
- Map out = (Map)(c.findOne( m.get( "_id" )));
- assertEquals( "eliot" , out.get( "name" ) );
- assertEquals( "ny" , out.get( "state" ) );
-
- Map z = (Map)out.get( "foo" );
- assertNotNull( z );
- assertEquals( "1z" , z.get( "bar" ) );
- }
-
- @Test
- public void testWhere1()
- throws MongoException {
- DBCollection c = _db.getCollection( "testWhere1" );
- c.drop();
- assertNull( c.findOne() );
-
- c.save( BasicDBObjectBuilder.start().add( "a" , 1 ).get() );
- assertNotNull( c.findOne() != null );
-
- assertNotNull( c.findOne( BasicDBObjectBuilder.start().add( "$where" , "this.a == 1" ).get() ) );
- assertNull( c.findOne( BasicDBObjectBuilder.start().add( "$where" , "this.a == 2" ).get() ) );
- }
-
- @Test
- public void testCodeWScope()
- throws MongoException {
- DBCollection c = _db.getCollection( "testCodeWScope" );
- c.drop();
- assertNull( c.findOne() );
-
- c.save( BasicDBObjectBuilder.start().add( "a" , 1 ).get() );
- assertNotNull( c.findOne() != null );
-
- assertNotNull( c.findOne( BasicDBObjectBuilder.start().add( "$where" , new CodeWScope( "this.a == x" , new BasicDBObject( "x" , 1 ) ) ).get() ) );
- assertNull( c.findOne( BasicDBObjectBuilder.start().add( "$where" , new CodeWScope( "this.a == x" , new BasicDBObject( "x" , 2 ) ) ).get() ) );
-
-
- c.drop();
- BasicDBObject in = new BasicDBObject();
- in.put( "_id" , 1 );
- in.put( "a" , new Code("x=5") );
- in.put( "b" , new CodeWScope( "x=5" , new BasicDBObject( "x" , 2 ) ) );
- c.insert( in );
-
- DBObject out = c.findOne();
-
- assertEquals( in , out );
- }
-
-
- @Test
- public void testCount()
- throws MongoException {
- DBCollection c = _db.getCollection("testCount");
-
- c.drop();
- assertNull(c.findOne());
- assertTrue(c.getCount() == 0);
-
- for (int i=0; i < 100; i++) {
- c.insert(new BasicDBObject("i", i));
- }
-
- assertEquals( 100 , c.getCount() );
- assertEquals( 100 , c.find().count() );
- assertEquals( 100 , c.find().limit(10).count() );
- assertEquals( 10 , c.find().limit(10).size() );
- assertEquals( 90 , c.find().skip(10).size() );
- }
-
- @Test
- public void testIndex()
- throws MongoException {
- DBCollection c = _db.getCollection("testIndex");
-
- c.drop();
- assertNull(c.findOne());
-
- for (int i=0; i < 100; i++) {
- c.insert(new BasicDBObject("i", i));
- }
-
- assertTrue(c.getCount() == 100);
-
- c.createIndex(new BasicDBObject("i", 1));
-
- List list = c.getIndexInfo();
-
- assertTrue(list.size() == 2);
- assertTrue(list.get(1).get("name").equals("i_1"));
- }
-
- @Test
- public void testBinary()
- throws MongoException {
- DBCollection c = _db.getCollection( "testBinary" );
- c.drop();
- c.save( BasicDBObjectBuilder.start().add( "a" , "eliot".getBytes() ).get() );
-
- DBObject out = c.findOne();
- byte[] b = (byte[])(out.get( "a" ) );
- assertEquals( "eliot" , new String( b ) );
-
- {
- byte[] raw = new byte[9];
- ByteBuffer bb = ByteBuffer.wrap( raw );
- bb.order( Bytes.ORDER );
- bb.putInt( 5 );
- bb.put( "eliot".getBytes() );
- out.put( "a" , new Binary( (byte)2 , raw ) );
- c.save( out );
-
- out = c.findOne();
- b = (byte[])(out.get( "a" ) );
- assertEquals( "eliot" , new String( b ) );
-
- out.put( "a" , new Binary( (byte)111 , raw ) );
- c.save( out );
- Binary blah = (Binary)c.findOne().get( "a" );
- assertEquals( 111 , blah.getType() );
- assertEquals( Util.toHex( raw ) , Util.toHex( blah.getData() ) );
- }
-
- }
- @Test
- public void testUUID()
- throws MongoException {
- DBCollection c = _db.getCollection( "testUUID" );
- c.drop();
- c.save( BasicDBObjectBuilder.start().add( "a" , new UUID(1,2)).add("x",5).get() );
-
- DBObject out = c.findOne();
- UUID b = (UUID)(out.get( "a" ) );
- assertEquals( new UUID(1,2), b);
- assertEquals( 5 , out.get("x" ) );
- }
-
- @Test
- public void testEval()
- throws MongoException {
- assertEquals( 17 , ((Number)(_db.eval( "return 17" ))).intValue() );
- assertEquals( 18 , ((Number)(_db.eval( "function(x){ return 17 + x; }" , 1 ))).intValue() );
- }
-
- @Test
- public void testPartial1()
- throws MongoException {
- DBCollection c = _db.getCollection( "partial1" );
- c.drop();
-
- c.save( BasicDBObjectBuilder.start().add( "a" , 1 ).add( "b" , 2 ).get() );
-
- DBObject out = c.find().next();
- assertEquals( 1 , out.get( "a" ) );
- assertEquals( 2 , out.get( "b" ) );
-
- out = c.find( new BasicDBObject() , BasicDBObjectBuilder.start().add( "a" , 1 ).get() ).next();
- assertEquals( 1 , out.get( "a" ) );
- assertNull( out.get( "b" ) );
-
- out = c.find( null , BasicDBObjectBuilder.start().add( "a" , 1 ).get() ).next();
- assertEquals( 1 , out.get( "a" ) );
- assertNull( out.get( "b" ) );
-
- }
-
- @Test
- public void testGroup()
- throws MongoException {
-
- DBCollection c = _db.getCollection( "group1" );
- c.drop();
- c.save( BasicDBObjectBuilder.start().add( "x" , "a" ).get() );
- c.save( BasicDBObjectBuilder.start().add( "x" , "a" ).get() );
- c.save( BasicDBObjectBuilder.start().add( "x" , "a" ).get() );
- c.save( BasicDBObjectBuilder.start().add( "x" , "b" ).get() );
-
- DBObject g = c.group( new BasicDBObject( "x" , 1 ) , null , new BasicDBObject( "count" , 0 ) ,
- "function( o , p ){ p.count++; }" );
-
- List l = (List)g;
- assertEquals( 2 , l.size() );
- }
-
- @Test
- public void testSet()
- throws MongoException {
-
- DBCollection c = _db.getCollection( "group1" );
- c.drop();
- c.save( BasicDBObjectBuilder.start().add( "id" , 1 ).add( "x" , true ).get() );
- assertEquals( Boolean.class , c.findOne().get( "x" ).getClass() );
-
- c.update( new BasicDBObject( "id" , 1 ) ,
- new BasicDBObject( "$set" ,
- new BasicDBObject( "x" , 5.5 ) ) );
- assertEquals( Double.class , c.findOne().get( "x" ).getClass() );
-
- }
-
- @Test
- public void testKeys1()
- throws MongoException {
-
- DBCollection c = _db.getCollection( "keys1" );
- c.drop();
- c.save( BasicDBObjectBuilder.start().push( "a" ).add( "x" , 1 ).get() );
-
- assertEquals( 1, ((DBObject)c.findOne().get("a")).get("x" ) );
- c.update( new BasicDBObject() , BasicDBObjectBuilder.start().push( "$set" ).add( "a.x" , 2 ).get() );
- assertEquals( 1 , c.find().count() );
- assertEquals( 2, ((DBObject)c.findOne().get("a")).get("x" ) );
-
- }
-
- @Test
- public void testTimestamp()
- throws MongoException {
-
- DBCollection c = _db.getCollection( "ts1" );
- c.drop();
- c.save( BasicDBObjectBuilder.start().add( "y" , new BSONTimestamp() ).get() );
-
- BSONTimestamp t = (BSONTimestamp)c.findOne().get("y");
- assert( t.getTime() > 0 );
- assert( t.getInc() > 0 );
- }
-
- @Test
- public void testStrictWriteSetInCollection(){
- DBCollection c = _db.getCollection( "write1" );
- c.drop();
- c.setWriteConcern( WriteConcern.SAFE);
- c.insert( new BasicDBObject( "_id" , 1 ) );
- boolean gotError = false;
- try {
- c.insert( new BasicDBObject( "_id" , 1 ) );
- }
- catch ( MongoException.DuplicateKey e ){
- gotError = true;
- }
- assertEquals( true , gotError );
-
- assertEquals( 1 , c.find().count() );
- }
-
- @Test
- public void testStrictWriteSetInMethod(){
- DBCollection c = _db.getCollection( "write1" );
- c.drop();
- c.insert( new BasicDBObject( "_id" , 1 ));
- boolean gotError = false;
- try {
- c.insert( new BasicDBObject( "_id" , 1 ) , WriteConcern.SAFE);
- }
- catch ( MongoException.DuplicateKey e ){
- gotError = true;
- }
- assertEquals( true , gotError );
-
- assertEquals( 1 , c.find().count() );
- }
-
- @Test
- public void testPattern(){
- DBCollection c = _db.getCollection( "jp1" );
- c.drop();
-
- c.insert( new BasicDBObject( "x" , "a" ) );
- c.insert( new BasicDBObject( "x" , "A" ) );
-
- assertEquals( 1 , c.find( new BasicDBObject( "x" , Pattern.compile( "a" ) ) ).itcount() );
- assertEquals( 1 , c.find( new BasicDBObject( "x" , Pattern.compile( "A" ) ) ).itcount() );
- assertEquals( 2 , c.find( new BasicDBObject( "x" , Pattern.compile( "a" , Pattern.CASE_INSENSITIVE ) ) ).itcount() );
- assertEquals( 2 , c.find( new BasicDBObject( "x" , Pattern.compile( "A" , Pattern.CASE_INSENSITIVE ) ) ).itcount() );
- }
-
-
- @Test
- public void testDates(){
- DBCollection c = _db.getCollection( "dates1" );
- c.drop();
-
- DBObject in = new BasicDBObject( "x" , new java.util.Date() );
- c.insert( in );
- DBObject out = c.findOne();
- assertEquals( java.util.Date.class , in.get("x").getClass() );
- assertEquals( in.get( "x" ).getClass() , out.get( "x" ).getClass() );
- }
-
- @Test
- public void testMapReduce(){
- DBCollection c = _db.getCollection( "jmr1" );
- c.drop();
-
- c.save( new BasicDBObject( "x" , new String[]{ "a" , "b" } ) );
- c.save( new BasicDBObject( "x" , new String[]{ "b" , "c" } ) );
- c.save( new BasicDBObject( "x" , new String[]{ "c" , "d" } ) );
-
- MapReduceOutput out =
- c.mapReduce( "function(){ for ( var i=0; i m = new HashMap();
- for ( DBObject r : out.results() ){
- m.put( r.get( "_id" ).toString() , ((Number)(r.get( "value" ))).intValue() );
- }
-
- assertEquals( 4 , m.size() );
- assertEquals( 1 , m.get( "a" ).intValue() );
- assertEquals( 2 , m.get( "b" ).intValue() );
- assertEquals( 2 , m.get( "c" ).intValue() );
- assertEquals( 1 , m.get( "d" ).intValue() );
-
- }
-
- String _testMulti( DBCollection c ){
- String s = "";
- for ( DBObject z : c.find().sort( new BasicDBObject( "_id" , 1 ) ) ){
- if ( s.length() > 0 )
- s += ",";
- s += z.get( "x" );
- }
- return s;
- }
-
- @Test
- public void testMulti(){
- DBCollection c = _db.getCollection( "multi1" );
- c.drop();
-
- c.insert( BasicDBObjectBuilder.start( "_id" , 1 ).add( "x" , 1 ).get() );
- c.insert( BasicDBObjectBuilder.start( "_id" , 2 ).add( "x" , 5 ).get() );
-
- assertEquals( "1,5" , _testMulti( c ) );
-
- c.update( new BasicDBObject() , BasicDBObjectBuilder.start().push( "$inc" ).add( "x" , 1 ).get() );
- assertEquals( "2,5" , _testMulti( c ) );
-
- c.update( new BasicDBObject( "_id" , 2 ) , BasicDBObjectBuilder.start().push( "$inc" ).add( "x" , 1 ).get() );
- assertEquals( "2,6" , _testMulti( c ) );
-
- c.updateMulti( new BasicDBObject() , BasicDBObjectBuilder.start().push( "$inc" ).add( "x" , 1 ).get() );
- assertEquals( "3,7" , _testMulti( c ) );
-
- }
-
- @Test
- public void testAuth(){
- assertEquals( "26e3d12bd197368526409177b3e8aab6" , _db._hash( "e" , new char[]{ 'j' } ) );
-
- DBCollection u = _db.getCollection( "system.users" );
-
- try {
- assertEquals( 0 , u.find().count() );
-
- _db.addUser( "xx" , new char[]{ 'e' } );
- assertEquals( 1 , u.find().count() );
-
- assertEquals( false , _db.authenticate( "xx" , new char[]{ 'f' } ) );
- assertEquals( true , _db.authenticate( "xx" , new char[]{ 'e' } ) );
- }
- finally {
- u.remove( new BasicDBObject() );
- assertEquals( 0 , u.find().count() );
- }
-
- }
-
- @Test
- public void testTransformers(){
- DBCollection c = _db.getCollection( "tt" );
- c.drop();
-
- c.save( BasicDBObjectBuilder.start( "_id" , 1 ).add( "x" , 1.1 ).get() );
- assertEquals( Double.class , c.findOne().get( "x" ).getClass() );
-
- Bytes.addEncodingHook( Double.class , new Transformer(){
- public Object transform( Object o ){
- return o.toString();
- }
- } );
-
- c.save( BasicDBObjectBuilder.start( "_id" , 1 ).add( "x" , 1.1 ).get() );
- assertEquals( String.class , c.findOne().get( "x" ).getClass() );
-
- Bytes.clearAllHooks();
- c.save( BasicDBObjectBuilder.start( "_id" , 1 ).add( "x" , 1.1 ).get() );
- assertEquals( Double.class , c.findOne().get( "x" ).getClass() );
-
- Bytes.addDecodingHook( Double.class , new Transformer(){
- public Object transform( Object o ){
- return o.toString();
- }
- } );
- assertEquals( String.class , c.findOne().get( "x" ).getClass() );
- Bytes.clearAllHooks();
- assertEquals( Double.class , c.findOne().get( "x" ).getClass() );
- }
-
-
- @Test
- public void testObjectIdCompat(){
- DBCollection c = _db.getCollection( "oidc" );
- c.drop();
-
- c.save( new BasicDBObject( "x" , 1 ) );
- _db.eval( "db.oidc.insert( { x : 2 } );" );
-
- List l = c.find().toArray();
- assertEquals( 2 , l.size() );
-
- ObjectId a = (ObjectId)(l.get(0).get("_id"));
- ObjectId b = (ObjectId)(l.get(1).get("_id"));
-
- assertLess( Math.abs( a.getTime() - b.getTime() ) , 10000 );
- }
-
- @Test
- public void testObjectIdCompat2(){
- DBCollection c = _db.getCollection( "oidc" );
- c.drop();
-
- c.save( new BasicDBObject( "x" , 1 ) );
-
- Object o = _db.eval( "return db.oidc.findOne()._id.toString()" );
- String x = c.findOne().get( "_id" ).toString();
- assertEquals( x , o );
- }
-
-
- @Test
- public void testLargeBulkInsert(){
- DBCollection c = _db.getCollection( "largebulk" );
- c.drop();
- String s = "asdasdasd";
- while ( s.length() < 10000 )
- s += s;
- List l = new ArrayList();
- final int num = 3 * ( Bytes.MAX_OBJECT_SIZE / s.length() );
-
- for ( int i=0; i Bytes.MAX_OBJECT_SIZE );
-
- boolean worked = false;
- try {
- c.save( new BasicDBObject( "foo" , s ) );
- worked = true;
- }
- catch ( IllegalArgumentException ie ){}
- assertFalse( worked );
-
- assertEquals( num , c.find().count() );
- }
-
- @Test
- public void testUpdate5(){
- DBCollection c = _db.getCollection( "udpate5" );
- c.drop();
-
- c.insert( new BasicDBObject( "x" , new Integer( 5 ) ) );
- assertEquals( Integer.class , c.findOne().get("x").getClass() );
- assertEquals( new Integer(5) , c.findOne().get("x") );
-
- c.update( new BasicDBObject() , new BasicDBObject( "$set" , new BasicDBObject( "x" , 5.6D ) ) );
- assertEquals( Double.class , c.findOne().get("x").getClass() );
- assertEquals( 5.6 , c.findOne().get("x") );
-
-
- }
-
- @Test
- public void testIn(){
- DBCollection c = _db.getCollection( "in1" );
- c.drop();
-
- c.insert( new BasicDBObject( "x" , 1 ) );
- c.insert( new BasicDBObject( "x" , 2 ) );
- c.insert( new BasicDBObject( "x" , 3 ) );
- c.insert( new BasicDBObject( "x" , 4 ) );
-
- List a = c.find( new BasicDBObject( "x" , new BasicDBObject( "$in" , new Integer[]{ 2 , 3 } ) ) ).toArray();
- assertEquals( 2 , a.size() );
- }
-
- @Test
- public void testWriteResultWithGetLastErrorWithDifferentConcerns(){
- DBCollection c = _db.getCollection( "writeresultwfle1" );
- c.drop();
-
- WriteResult res = c.insert( new BasicDBObject( "_id" , 1 ) );
- res = c.update( new BasicDBObject( "_id" , 1 ) , new BasicDBObject( "$inc" , new BasicDBObject( "x" , 1 ) ) );
- assertEquals( 1 , res.getN() );
- assertTrue( res.isLazy() );
-
- CommandResult cr = res.getLastError( WriteConcern.FSYNC_SAFE );
- assertEquals( 1 , cr.getInt( "n" ) );
- assertTrue( cr.containsField( "fsyncFiles" ));
-
- CommandResult cr2 = res.getLastError( WriteConcern.FSYNC_SAFE );
- assertTrue( cr == cr2 );
-
- CommandResult cr3 = res.getLastError( WriteConcern.NONE );
- assertTrue( cr != cr3 && cr2 != cr3 );
-
- }
-
- @Test
- public void testWriteResult(){
- DBCollection c = _db.getCollection( "writeresult1" );
- c.drop();
-
- WriteResult res = c.insert( new BasicDBObject( "_id" , 1 ) );
- res = c.update( new BasicDBObject( "_id" , 1 ) , new BasicDBObject( "$inc" , new BasicDBObject( "x" , 1 ) ) );
- assertEquals( 1 , res.getN() );
- assertTrue( res.isLazy() );
-
- c.setWriteConcern( WriteConcern.SAFE);
- res = c.update( new BasicDBObject( "_id" , 1 ) , new BasicDBObject( "$inc" , new BasicDBObject( "x" , 1 ) ) );
- assertEquals( 1 , res.getN() );
- assertFalse( res.isLazy() );
- }
-
- @Test
- public void testWriteResultMethodLevelWriteConcern(){
- DBCollection c = _db.getCollection( "writeresult2" );
- c.drop();
-
- WriteResult res = c.insert( new BasicDBObject( "_id" , 1 ) );
- res = c.update( new BasicDBObject( "_id" , 1 ) , new BasicDBObject( "$inc" , new BasicDBObject( "x" , 1 ) ) );
- assertEquals( 1 , res.getN() );
- assertTrue( res.isLazy() );
-
- res = c.update( new BasicDBObject( "_id" , 1 ) , new BasicDBObject( "$inc" , new BasicDBObject( "x" , 1 ) ) , false , false , WriteConcern.SAFE);
- assertEquals( 1 , res.getN() );
- assertFalse( res.isLazy() );
- }
-
- @Test
- public void testWriteConcernValueOf() {
- WriteConcern wc1 = WriteConcern.NORMAL;
- WriteConcern wc2 = WriteConcern.valueOf( "normal" );
- WriteConcern wc3 = WriteConcern.valueOf( "NORMAL" );
-
- assertEquals( wc1._w, wc2._w );
- assertEquals( wc1._w, wc3._w );
- }
-
- @Test
- public void testFindAndModify(){
- DBCollection c = _db.getCollection( "findandmodify" );
- c.drop();
-
- c.insert( new BasicDBObject( "_id" , 1 ) );
- //return old one
- DBObject dbObj = c.findAndModify( new BasicDBObject( "_id" , 1 ) , null, new BasicDBObject( "x", 1));
- assertEquals( 1 , dbObj.keySet().size());
- assertEquals( 1 , c.findOne(new BasicDBObject( "_id" , 1 ) ).get( "x" ));
-
- //return new one
- dbObj = c.findAndModify( new BasicDBObject( "_id" , 1 ) , null, null, false, new BasicDBObject( "x", 5), true, false);
- assertEquals( 2 , dbObj.keySet().size());
- assertEquals( 5 , dbObj.get( "x" ));
- assertEquals( 5 , c.findOne(new BasicDBObject( "_id" , 1 ) ).get( "x" ));
-
- //remove it, and return old one
- dbObj = c.findAndRemove( new BasicDBObject( "_id" , 1 ) );
- assertEquals( 2 , dbObj.keySet().size());
- assertEquals( 5 , dbObj.get( "x" ));
- assertNull( c.findOne(new BasicDBObject( "_id" , 1 ) ));
-
- }
-
- @Test
- public void testGetCollectionFromString(){
- DBCollection c = _db.getCollectionFromString( "foo" );
- assertEquals( "foo" , c.getName() );
-
- c = _db.getCollectionFromString( "foo.bar" );
- assertEquals( "foo.bar" , c.getName() );
-
- c = _db.getCollectionFromString( "foo.bar.zoo" );
- assertEquals( "foo.bar.zoo" , c.getName() );
-
- c = _db.getCollectionFromString( "foo.bar.zoo.dork" );
- assertEquals( "foo.bar.zoo.dork" , c.getName() );
-
- }
-
- final Mongo _mongo;
- final DB _db;
-
- public static void main( String args[] )
- throws Exception {
- JavaClientTest ct = new JavaClientTest();
- ct.runConsole();
- }
-}
diff --git a/src/test/com/mongodb/MongoTest.java b/src/test/com/mongodb/MongoTest.java
deleted file mode 100644
index 31101d15fa0..00000000000
--- a/src/test/com/mongodb/MongoTest.java
+++ /dev/null
@@ -1,43 +0,0 @@
-// MongoTest.java
-
-/**
- * Copyright (C) 2008 10gen Inc.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.mongodb;
-
-import java.io.*;
-import java.util.*;
-import java.util.regex.*;
-
-import org.testng.annotations.Test;
-
-import com.mongodb.util.*;
-
-public class MongoTest extends TestCase {
-
- public MongoTest()
- throws IOException , MongoException {
- _db = new Mongo().getDB( "mongotest" );
- }
-
- final DB _db;
-
- public static void main( String args[] )
- throws Exception {
- (new MongoTest()).runConsole();
- }
-
-}
diff --git a/src/test/com/mongodb/MongoURITest.java b/src/test/com/mongodb/MongoURITest.java
deleted file mode 100644
index 6b557c0a96f..00000000000
--- a/src/test/com/mongodb/MongoURITest.java
+++ /dev/null
@@ -1,70 +0,0 @@
-// MongoURITest.java
-
-/**
- * Copyright (C) 2008 10gen Inc.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.mongodb;
-
-import java.util.*;
-import java.util.regex.*;
-import java.io.IOException;
-
-import org.testng.annotations.Test;
-
-import com.mongodb.util.*;
-
-import org.bson.*;
-import org.bson.types.*;
-
-
-public class MongoURITest extends TestCase {
-
- @Test()
- public void testBasic1(){
- MongoURI u = new MongoURI( "mongodb://foo/bar" );
- assertEquals( 1 , u.getHosts().size() );
- assertEquals( "foo" , u.getHosts().get(0) );
- assertEquals( "bar" , u.getDatabase() );
- assertEquals( null , u.getCollection() );
- assertEquals( null , u.getUsername() );
- assertEquals( null , u.getPassword() );
- }
-
- @Test()
- public void testBasic2(){
- MongoURI u = new MongoURI( "mongodb://foo/bar.goo" );
- assertEquals( 1 , u.getHosts().size() );
- assertEquals( "foo" , u.getHosts().get(0) );
- assertEquals( "bar" , u.getDatabase() );
- assertEquals( "goo" , u.getCollection() );
- }
-
- @Test()
- public void testUserPass(){
- MongoURI u = new MongoURI( "mongodb://aaa@bbb:foo/bar" );
- assertEquals( 1 , u.getHosts().size() );
- assertEquals( "foo" , u.getHosts().get(0) );
- assertEquals( "aaa" , u.getUsername() );
- assertEquals( "bbb" , new String( u.getPassword() ) );
- }
-
- public static void main( String args[] )
- throws Exception {
- (new MongoURITest()).runConsole();
-
- }
-
-}
diff --git a/src/test/com/mongodb/ObjectIdTest.java b/src/test/com/mongodb/ObjectIdTest.java
deleted file mode 100644
index 2abc2dd9f47..00000000000
--- a/src/test/com/mongodb/ObjectIdTest.java
+++ /dev/null
@@ -1,148 +0,0 @@
-// ObjectIdTest.java
-
-/**
- * Copyright (C) 2008 10gen Inc.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.mongodb;
-
-import java.util.*;
-
-import org.testng.annotations.Test;
-
-import com.mongodb.util.*;
-import org.bson.*;
-import org.bson.types.*;
-
-public class ObjectIdTest extends TestCase {
-
- final Mongo _mongo;
- final DB _db;
-
- public ObjectIdTest()
- throws Exception {
- _mongo = new Mongo();
- cleanupMongo = _mongo;
- cleanupDB = "com_mongodb_unittest_ObjectIdTest";
- _db = cleanupMongo.getDB(cleanupDB);
- }
-
- /*
- @Test(groups = {"basic"})
- public void testTSM(){
-
- ObjectId a = new ObjectId( 2667563522304714314L , -1912742877 );
- assertEquals( "4a26c3e2e316052523dcfd8d" , a.toStringMongod() );
- assertEquals( "250516e3e2c3264a8dfddc23" , a.toStringBabble() );
- assertEquals( "4a26c3e2e316052523dcfd8d" , a.toString() );
- }
- */
-
- @Test(groups = {"basic"})
- public void testRT1(){
- ObjectId a = new ObjectId();
- assertEquals( a.toStringBabble() , (new ObjectId( a.toStringBabble() , true ) ).toStringBabble() );
- assertEquals( a.toStringMongod() , (new ObjectId( a.toStringMongod() , false ) ).toStringMongod() );
- assertEquals( a.toStringMongod() , (new ObjectId( a.toStringMongod() ) ).toStringMongod() );
- assertEquals( a.toString() , (new ObjectId( a.toString() , false ) ).toString() );
- }
-
- @Test(groups = {"basic"})
- public void testBabbleToMongo(){
- ObjectId a = new ObjectId();
- assertEquals( a.toStringMongod() , ObjectId.babbleToMongod( a.toStringBabble() ) );
- }
-
- @Test
- public void testBytes(){
- ObjectId a = new ObjectId();
- assertEquals( a , new ObjectId( a.toByteArray() ) );
-
- byte b[] = new byte[12];
- java.util.Random r = new java.util.Random( 17 );
- for ( int i=0; i 0 )
- assertEquals( Y , y );
- }
-
- @Test
- public void testFlip(){
-
- _testFlip( 1 , 16777216 );
- _testFlip( 1231231 , 2143883776 );
- _testFlip( 0x12345678 , 0x78563412 );
-
- Random r = new Random( 12312312 );
- for ( int i=0; i<1000; i++ ){
- int x = r.nextInt();
- _testFlip( r.nextInt() , 0 );
- }
-
- }
- public static void main( String args[] )
- throws Exception {
- (new ObjectIdTest()).runConsole();
-
- long num = 5000000;
-
- long start = System.currentTimeMillis();
- for ( long i=0; i batches = new ArrayList();
- for (int i=0; i batch = new ArrayList();
- for (int j=0; jQueryBuilder
- * @author Julson Lim
- *
- */
-public class QueryBuilderTest extends TestCase {
- private static TestDB _testDB;
-
- @BeforeClass
- public static void setup() {
- _testDB = new TestDB("queryBuilderTest");
- }
-
- @Test
- public void greaterThanTest() {
- String key = "x";
- DBCollection collection = _testDB.getCollection("gt-test");
- saveTestDocument(collection, key, 0);
-
- DBObject queryTrue = QueryBuilder.start(key).greaterThan(-1).get();
- assertTrue(testQuery(collection, queryTrue));
-
- DBObject queryFalse = QueryBuilder.start(key).greaterThan(0).get();
- assertFalse(testQuery(collection, queryFalse));
- }
-
- @Test
- public void greaterThanEqualsTest() {
- String key = "x";
- DBCollection collection = _testDB.getCollection("gte-test");
- saveTestDocument(collection, key, 0);
-
- DBObject queryTrue = QueryBuilder.start(key).greaterThanEquals(0).get();
- assertTrue(testQuery(collection, queryTrue));
-
- DBObject queryTrue2 = QueryBuilder.start(key).greaterThanEquals(-1).get();
- assertTrue(testQuery(collection, queryTrue2));
-
- DBObject queryFalse = QueryBuilder.start(key).greaterThanEquals(1).get();
- assertFalse(testQuery(collection, queryFalse));
-
- }
-
- @Test
- public void lessThanTest() {
- String key = "x";
- DBCollection collection = _testDB.getCollection("lt-test");
- saveTestDocument(collection, key, 0);
-
- DBObject queryTrue = QueryBuilder.start(key).lessThan(1).get();
- assertTrue(testQuery(collection, queryTrue));
-
- DBObject queryFalse = QueryBuilder.start(key).lessThan(0).get();
- assertFalse(testQuery(collection, queryFalse));
-
- }
-
- @Test
- public void lessThanEqualsTest() {
- String key = "x";
- DBCollection collection = _testDB.getCollection("lte-test");
- saveTestDocument(collection, key, 0);
-
- DBObject queryTrue = QueryBuilder.start(key).lessThanEquals(1).get();
- assertTrue(testQuery(collection, queryTrue));
-
- DBObject queryTrue2 = QueryBuilder.start(key).lessThanEquals(0).get();
- assertTrue(testQuery(collection, queryTrue2));
-
- DBObject queryFalse = QueryBuilder.start(key).lessThanEquals(-1).get();
- assertFalse(testQuery(collection, queryFalse));
- }
-
- @Test
- public void isTest() {
- String key = "x";
- DBCollection collection = _testDB.getCollection("is-test");
- saveTestDocument(collection, key, "test");
-
- DBObject queryTrue = QueryBuilder.start(key).is("test").get();
- assertTrue(testQuery(collection, queryTrue));
-
- DBObject queryFalse = QueryBuilder.start(key).is("test1").get();
- assertFalse(testQuery(collection, queryFalse));
- }
-
- @Test
- public void notEqualsTest() {
- String key = "x";
- DBCollection collection = _testDB.getCollection("ne-test");
- saveTestDocument(collection, key, "test");
-
- DBObject queryTrue = QueryBuilder.start(key).notEquals("test1").get();
- assertTrue(testQuery(collection, queryTrue));
-
- DBObject queryFalse = QueryBuilder.start(key).notEquals("test").get();
- assertFalse(testQuery(collection, queryFalse));
-
- }
-
- @Test
- public void inTest() {
- String key = "x";
- DBCollection collection = _testDB.getCollection("in-test");
- saveTestDocument(collection, key, 1);
-
- DBObject queryTrue = QueryBuilder.start(key).in(Arrays.asList(1, 2, 3)).get();
- assertTrue(testQuery(collection, queryTrue));
-
- DBObject queryFalse = QueryBuilder.start(key).in(Arrays.asList(2, 3, 4)).get();
- assertFalse(testQuery(collection, queryFalse));
- }
-
- @Test
- public void notInTest() {
- String key = "x";
- DBCollection collection = _testDB.getCollection("nin-test");
- saveTestDocument(collection, key, 1);
-
- DBObject queryTrue = QueryBuilder.start(key).notIn(Arrays.asList(2, 3, 4)).get();
- assertTrue(testQuery(collection, queryTrue));
-
- DBObject queryFalse = QueryBuilder.start(key).notIn(Arrays.asList(1, 2, 3)).get();
- assertFalse(testQuery(collection, queryFalse));
- }
-
- @Test
- public void modTest() {
- String key = "x";
- DBCollection collection = _testDB.getCollection("mod-test");
- saveTestDocument(collection, key, 9);
-
- DBObject queryTrue = QueryBuilder.start(key).mod(Arrays.asList(2, 1)).get();
- assertTrue(testQuery(collection, queryTrue));
-
- DBObject queryFalse = QueryBuilder.start(key).mod(Arrays.asList(2, 0)).get();
- assertFalse(testQuery(collection, queryFalse));
- }
-
- @Test
- public void allTest() {
- String key = "x";
- DBCollection collection = _testDB.getCollection("all-test");
- saveTestDocument(collection, key, Arrays.asList(1, 2, 3));
-
- DBObject query = QueryBuilder.start(key).all(Arrays.asList(1, 2, 3)).get();
- assertTrue(testQuery(collection, query));
-
- DBObject queryFalse = QueryBuilder.start(key).all(Arrays.asList(2, 3, 4)).get();
- assertFalse(testQuery(collection, queryFalse));
- }
-
- @Test
- public void sizeTest() {
- String key = "x";
- DBCollection collection = _testDB.getCollection("size-test");
- saveTestDocument(collection, key, Arrays.asList(1, 2, 3));
-
- DBObject queryTrue = QueryBuilder.start(key).size(3).get();
- assertTrue(testQuery(collection, queryTrue));
-
- DBObject queryFalse = QueryBuilder.start(key).size(4).get();
- assertFalse(testQuery(collection, queryFalse));
-
- DBObject queryFalse2 = QueryBuilder.start(key).size(2).get();
- assertFalse(testQuery(collection, queryFalse2));
- }
-
- @Test
- public void existsTest() {
- String key = "x";
- DBCollection collection = _testDB.getCollection("exists-test");
- saveTestDocument(collection, key, "test");
-
- DBObject queryTrue = QueryBuilder.start(key).exists(true).get();
- assertTrue(testQuery(collection, queryTrue));
-
- DBObject queryFalse = QueryBuilder.start(key).exists(false).get();
- assertFalse(testQuery(collection, queryFalse));
- }
-
- @Test
- public void regexTest() {
- String key = "x";
- DBCollection collection = _testDB.getCollection("regex-test");
- saveTestDocument(collection, key, "test");
-
- DBObject queryTrue = QueryBuilder.start(key).regex(Pattern.compile("\\w*")).get();
- assertTrue(testQuery(collection, queryTrue));
- }
-
- @Test
- public void rangeChainTest() {
- String key = "x";
- DBCollection collection = _testDB.getCollection("range-test");
- saveTestDocument(collection, key, 2);
-
- DBObject queryTrue = QueryBuilder.start(key).greaterThan(0).lessThan(3).get();
- assertTrue(testQuery(collection, queryTrue));
- }
-
- @Test
- public void compoundChainTest() {
- String key = "x";
- String key2 = "y";
- String value = key;
- DBCollection collection = _testDB.getCollection("compound-test");
- DBObject testDocument = new BasicDBObject();
- testDocument.put(key, value);
- testDocument.put(key2, 9);
- collection.save(testDocument);
-
- DBObject queryTrue = QueryBuilder.start(key).is(value).and(key2).mod(Arrays.asList(2,1)).get();
- assertTrue(testQuery(collection, queryTrue));
- }
-
- @Test
- public void arrayChainTest() {
- String key = "x";
- DBCollection collection = _testDB.getCollection("array-test");
- saveTestDocument(collection, key, Arrays.asList(1, 2, 3));
-
- DBObject queryTrue = QueryBuilder.start(key).all(Arrays.asList(1,2,3)).size(3).get();
- assertTrue(testQuery(collection, queryTrue));
- }
-
- @Test
- public void failureTest() {
- boolean thrown = false;
- try {
- QueryBuilder.start("x").get();
- } catch(QueryBuilderException e) {
- thrown = true;
- }
- assertTrue(thrown);
-
- boolean thrown2 = false;
- try {
- QueryBuilder.start("x").exists(true).and("y").get();
- } catch(QueryBuilderException e) {
- thrown2 = true;
- }
- assertTrue(thrown2);
-
- boolean thrown3 = false;
- try {
- QueryBuilder.start("x").and("y").get();
- } catch(QueryBuilderException e) {
- thrown3 = true;
- }
- assertTrue(thrown3);
- }
-
- @Test
- public void testOr() {
- DBCollection c = _testDB.getCollection( "or1" );
- c.drop();
- c.insert( new BasicDBObject( "a" , 1 ) );
- c.insert( new BasicDBObject( "b" , 1 ) );
-
- DBObject q = QueryBuilder.start()
- .or( new BasicDBObject( "a" , 1 ) ,
- new BasicDBObject( "b" , 1 ) )
- .get();
-
- assertEquals( 2 , c.find( q ).itcount() );
- }
-
- @AfterClass
- public static void tearDown() {
- _testDB.cleanup();
- }
-
- /**
- * Convenience method that
- * creates a new MongoDB Document with a key-value pair and saves it inside the specified collection
- * @param collection Collection to save the new document to
- * @param key key of the field to be inserted to the new document
- * @param value value of the field to be inserted to the new document
- */
- private void saveTestDocument(DBCollection collection, String key, Object value) {
- DBObject testDocument = new BasicDBObject();
- testDocument.put(key, value);
- collection.save(testDocument);
- }
-
- private boolean testQuery(DBCollection collection, DBObject query) {
- DBCursor cursor = collection.find(query);
- return cursor.hasNext();
- }
-
-}
diff --git a/src/test/com/mongodb/ReflectionTest.java b/src/test/com/mongodb/ReflectionTest.java
deleted file mode 100644
index 4ff420fe8bb..00000000000
--- a/src/test/com/mongodb/ReflectionTest.java
+++ /dev/null
@@ -1,121 +0,0 @@
-/**
- * Copyright (C) 2008 10gen Inc.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.mongodb;
-
-import java.io.*;
-
-import org.testng.annotations.Test;
-
-import com.mongodb.util.*;
-
-public class ReflectionTest extends TestCase {
-
- public static class Person extends ReflectionDBObject {
-
- public Person(){
-
- }
-
- Person( String name ){
- _name = name;
- }
-
- public String getName(){
- return _name;
- }
-
- public void setName(String name){
- _name = name;
- }
-
- String _name;
- }
-
- public ReflectionTest()
- throws IOException , MongoException {
- cleanupMongo = new Mongo( "127.0.0.1" );
- cleanupDB = "com_mongodb_unittest_ReflectionTest";
- _db = cleanupMongo.getDB( cleanupDB );
- }
-
- @Test
- public void test1()
- throws MongoException {
- DBCollection c = _db.getCollection( "persen.test1" );
- c.drop();
- c.setObjectClass( Person.class );
-
- Person p = new Person( "eliot" );
- c.save( p );
-
- DBObject out = c.findOne();
- assertEquals( "eliot" , out.get( "Name" ) );
- assertTrue( out instanceof Person , "didn't come out as Person" );
- }
-
- public static class Outer extends ReflectionDBObject {
- private Inner mInclude;
- private String mName;
-
- public void setName(final String pName) { mName = pName; }
- public String getName() { return mName; }
-
- public Inner getInner() { return mInclude; }
- public void setInner(final Inner pV) { mInclude = pV; }
- }
-
- public static class Inner extends ReflectionDBObject {
-
- public int mNumber;
-
- public Inner(){}
- public Inner( int n ){ mNumber = n; }
-
- public int getNumber() { return mNumber; }
- public void setNumber(final int pV) { mNumber = pV; }
- }
-
- @Test
- public void test2()
- throws MongoException {
-
- DBCollection c = _db.getCollection( "embedref1" );
- c.drop();
- c.setObjectClass( Outer.class );
-
- Outer o = new Outer();
- o.setName( "eliot" );
- o.setInner( new Inner( 17 ) );
-
- c.save( o );
-
- DBObject out = c.findOne();
- assertEquals( "eliot" , out.get( "Name" ) );
- assertTrue( out instanceof Outer , "didn't come out as Person" );
- o = (Outer)out;
- assertEquals( "eliot" , o.getName() );
- assertEquals( 17 , o.getInner().getNumber() );
- }
-
- final DB _db;
-
- public static void main( String args[] )
- throws Exception {
- (new ReflectionTest()).runConsole();
- }
-
-}
diff --git a/src/test/com/mongodb/ReplPairTest.java b/src/test/com/mongodb/ReplPairTest.java
deleted file mode 100644
index 8488be11ed7..00000000000
--- a/src/test/com/mongodb/ReplPairTest.java
+++ /dev/null
@@ -1,68 +0,0 @@
-// ReplPairTest.java
-
-package com.mongodb;
-
-import java.util.*;
-
-public class ReplPairTest {
-
- static class R extends Thread {
- R( ServerAddress a ){
- _a = a;
- _mongo = new Mongo(a);
- _db = _mongo.getDB( "test" );
- _coll = _db.getCollection( "foo" );
-
- _coll.slaveOk();
- }
-
- public void run(){
- while ( true ){
- try {
- Thread.sleep( 500 );
- _coll.findOne();
- }
- catch ( NullPointerException n ){
- n.printStackTrace();
- }
- catch ( Exception e ){
- System.out.println( _a + "\t" + e );
- }
- }
- }
-
- final ServerAddress _a;
- final Mongo _mongo;
- final DB _db;
- final DBCollection _coll;
- }
-
- public static void main( String args[] )
- throws Exception {
-
- List addrs = new ArrayList();
- addrs.add( new ServerAddress( "localhost" , 9998 ) );
- addrs.add( new ServerAddress( "localhost" , 9999 ) );
-
- Mongo m = new Mongo ( addrs );
- DB db = m.getDB( "test" );
- DBCollection c = db.getCollection( "foo" );
- c.insert( new BasicDBObject( "_id" , 17 ) );
- c.slaveOk();
-
- for ( ServerAddress a : addrs ){
- new R(a).start();
- }
-
- while ( true ){
- Thread.sleep( 500 );
- try {
- System.out.println( c.findOne() );
- c.update( new BasicDBObject( "_id" , 17 ) , new BasicDBObject( "$inc" , new BasicDBObject( "x" , 1 ) ) );
- }
- catch ( Exception e ){
- e.printStackTrace();
- }
- }
- }
-}
diff --git a/src/test/com/mongodb/ReplSetTest.java b/src/test/com/mongodb/ReplSetTest.java
deleted file mode 100644
index 1509f7de817..00000000000
--- a/src/test/com/mongodb/ReplSetTest.java
+++ /dev/null
@@ -1,79 +0,0 @@
-// ReplSetTest.java
-
-package com.mongodb;
-
-import java.util.*;
-
-public class ReplSetTest {
-
- static void _sleep()
- throws InterruptedException {
- //Thread.sleep( 500 );
- }
-
- static class R extends Thread {
- R( ServerAddress a ){
- _a = a;
- _mongo = new Mongo(a);
- _db = _mongo.getDB( "test" );
- _coll = _db.getCollection( "foo" );
-
- _coll.slaveOk();
- }
-
- public void run(){
- while ( true ){
- try {
- _sleep();
- _coll.findOne();
- }
- catch ( NullPointerException n ){
- n.printStackTrace();
- }
- catch ( Exception e ){
- System.out.println( _a + "\t" + e );
- }
- }
- }
-
- final ServerAddress _a;
- final Mongo _mongo;
- final DB _db;
- final DBCollection _coll;
- }
-
- public static void main( String args[] )
- throws Exception {
-
- boolean rs = true;
-
- List addrs = new ArrayList();
- if ( rs ){
- addrs.add( new ServerAddress( "localhost" , 27017 ) );
- addrs.add( new ServerAddress( "localhost" , 27018 ) );
- addrs.add( new ServerAddress( "localhost" , 27019 ) );
- }
-
- Mongo m = rs ? new Mongo( addrs ) : new Mongo();
- DB db = m.getDB( "test" );
- DBCollection c = db.getCollection( "foo" );
- c.insert( new BasicDBObject( "_id" , 17 ) );
- c.slaveOk();
-
- for ( ServerAddress a : addrs ){
- new R(a).start();
- }
-
- while ( true ){
- _sleep();
- try {
- DBObject x = c.findOne();
- //System.out.println( x );
- c.update( new BasicDBObject( "_id" , 17 ) , new BasicDBObject( "$inc" , new BasicDBObject( "x" , 1 ) ) );
- }
- catch ( Exception e ){
- e.printStackTrace();
- }
- }
- }
-}
diff --git a/src/test/com/mongodb/TestDB.java b/src/test/com/mongodb/TestDB.java
deleted file mode 100644
index f8fb741932c..00000000000
--- a/src/test/com/mongodb/TestDB.java
+++ /dev/null
@@ -1,51 +0,0 @@
-// TestDB.java
-
-/**
- * Copyright (C) 2010 10gen Inc.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.mongodb;
-
-/**
- * Simple DB setup for testing
- * @author Julson Lim
- *
- */
-public class TestDB {
-
- private static final String HOST = "127.0.0.1";
-
- TestDB(String dbName) {
- try {
- _mongo = new Mongo(HOST);
- _db = _mongo.getDB(dbName);
- _db.dropDatabase();
- } catch (Exception e) {
- throw new RuntimeException(e);
- }
- }
-
- public DBCollection getCollection(String collName) {
- DBCollection collection = _db.getCollection(collName);
- return collection;
- }
-
- public void cleanup() {
- _db.dropDatabase();
- }
-
- private final Mongo _mongo;
- private final DB _db;
-}
diff --git a/src/test/com/mongodb/ThreadingTest.java b/src/test/com/mongodb/ThreadingTest.java
deleted file mode 100644
index 8fea231042d..00000000000
--- a/src/test/com/mongodb/ThreadingTest.java
+++ /dev/null
@@ -1,56 +0,0 @@
-// ThreadingTest.java
-
-/**
- * Copyright (C) 2008 10gen Inc.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.mongodb;
-
-import java.io.*;
-import java.nio.*;
-import java.util.*;
-import java.util.regex.*;
-
-import org.bson.*;
-import org.bson.types.*;
-import org.testng.annotations.*;
-
-import com.mongodb.util.*;
-
-public class ThreadingTest extends TestCase {
-
- final static String DB = "java_threading_tests";
-
- public ThreadingTest(){
- cleanupDB = DB;
- }
-
- @Test
- public void test2Mongos()
- throws Exception {
- Mongo a = new Mongo();
- a.getDB( DB ).getCollection( "test2Mongos" ).insert( new BasicDBObject( "_id" , 1 ) );
- assertEquals( 1 , a.getDB( DB ).getCollection( "test2Mongos" ).findOne().get( "_id" ) );
-
- Mongo b = new Mongo();
- assertEquals( 1 , b.getDB( DB ).getCollection( "test2Mongos" ).findOne().get( "_id" ) );
- }
-
- public static void main( String args[] )
- throws Exception {
- (new ThreadingTest()).runConsole();
- }
-
-}
diff --git a/src/test/com/mongodb/framework/Admin.java b/src/test/com/mongodb/framework/Admin.java
deleted file mode 100644
index 026a6a9d089..00000000000
--- a/src/test/com/mongodb/framework/Admin.java
+++ /dev/null
@@ -1,30 +0,0 @@
-/**
- * Copyright (C) 2008 10gen Inc.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.mongodb.framework;
-
-import java.util.*;
-import java.net.*;
-
-import com.mongodb.*;
-import com.mongodb.util.*;
-
-public class Admin {
-
- public static void main(String[] args) {
- throw new RuntimeException( "admin stuff not supported yet." );
- }
-}
diff --git a/src/test/com/mongodb/framework/Capped.java b/src/test/com/mongodb/framework/Capped.java
deleted file mode 100644
index ae85fdacd7e..00000000000
--- a/src/test/com/mongodb/framework/Capped.java
+++ /dev/null
@@ -1,57 +0,0 @@
-/**
- * Copyright (C) 2008 10gen Inc.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.mongodb.framework;
-
-import java.util.*;
-import java.net.*;
-
-import com.mongodb.*;
-import com.mongodb.util.*;
-
-
-public class Capped {
-
- public static void main(String[] args)
- throws MongoException , UnknownHostException {
-
- DB db = new Mongo().getDB( "driver_test_framework" );
- DBObject foo = new BasicDBObject();
- foo.put( "create", "capped1" );
- foo.put( "capped", true );
- foo.put( "size", 500 );
- DBObject dbobj = db.command( foo );
- DBCollection c = db.getCollection( "capped1" );
-
- DBObject obj1 = new BasicDBObject();
- obj1.put( "x", 1 );
- c.save( obj1 );
- DBObject obj2 = new BasicDBObject();
- obj2.put( "x", 2 );
- c.save( obj2 );
-
- foo.put( "create", "capped2" );
- foo.put( "size", 1000 );
- db.command( foo );
- String s = "";
- c = db.getCollection( "capped2" );
- for( int i=1; i<= 100; i++ ) {
- DBObject obj = new BasicDBObject();
- obj.put( "dashes", s );
- c.save( obj );
- s = s+"-";
- }
- }
-}
diff --git a/src/test/com/mongodb/framework/Circular.java b/src/test/com/mongodb/framework/Circular.java
deleted file mode 100644
index cb868df9176..00000000000
--- a/src/test/com/mongodb/framework/Circular.java
+++ /dev/null
@@ -1,51 +0,0 @@
-/**
- * Copyright (C) 2008 10gen Inc.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.mongodb.framework;
-
-import java.util.*;
-import java.net.*;
-
-import com.mongodb.*;
-import com.mongodb.util.*;
-
-import org.bson.*;
-import org.bson.types.*;
-
-public class Circular {
-
- public static void main(String[] args)
- throws Exception {
-
- DB db = new Mongo().getDB( "driver_test_framework" );
- DBObject foo = new BasicDBObject();
- DBCollection b = db.getCollection( "b" );
- foo.put( "c", b );
- db.getCollection( "a" ).save( foo );
-
- foo = new BasicDBObject();
- foo.put( "c", 1 );
- b.save( foo );
-
- ObjectId id = new ObjectId();
- foo = new BasicDBObject();
- foo.put( "_id", id );
- foo.put( "that", 2 );
- DBPointer ref = new DBPointer( "c", id );
- foo.put( "thiz", ref );
- db.getCollection( "c" ).save( foo );
-
- }
-}
diff --git a/src/test/com/mongodb/framework/Count1.java b/src/test/com/mongodb/framework/Count1.java
deleted file mode 100644
index db9092aecb5..00000000000
--- a/src/test/com/mongodb/framework/Count1.java
+++ /dev/null
@@ -1,47 +0,0 @@
-/**
- * Copyright (C) 2008 10gen Inc.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.mongodb.framework;
-
-import java.util.*;
-import java.net.*;
-
-import com.mongodb.*;
-import com.mongodb.util.*;
-
-
-public class Count1 {
-
- public static void main(String[] args)
- throws Exception {
-
- DB db = new Mongo().getDB( "driver_test_framework" );
- System.out.println( db.getCollection( "test1" ).find().count() );
- System.out.println( db.getCollection( "test2" ).find().count() );
- DBCollection coll = db.getCollection( "test3" );
-
- DBObject foo = new BasicDBObject();
- foo.put( "i", "a" );
- System.out.println( coll.find( foo ).count() );
-
- foo.put( "i", 3 );
- System.out.println( coll.find( foo ).count() );
-
- DBObject bar = new BasicDBObject();
- bar.put( "$gte" , 67 );
- foo.put( "i", bar );
- System.out.println( coll.find( foo ).count() );
- }
-}
diff --git a/src/test/com/mongodb/framework/Dbs.java b/src/test/com/mongodb/framework/Dbs.java
deleted file mode 100644
index 4ede5052ee0..00000000000
--- a/src/test/com/mongodb/framework/Dbs.java
+++ /dev/null
@@ -1,63 +0,0 @@
-/**
- * Copyright (C) 2008 10gen Inc.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.mongodb.framework;
-
-import java.util.*;
-import java.net.*;
-
-import com.mongodb.*;
-import com.mongodb.util.*;
-
-public class Dbs {
-
- public static void main(String[] args)
- throws UnknownHostException , MongoException {
-
- DB db = new Mongo().getDB( "driver_test_framework" );
- DBCollection coll = db.getCollection( "dbs_1" );
- DBObject o = new BasicDBObject();
- o.put( "foo", "bar" );
- coll.save( o );
-
- coll = db.getCollection( "dbs_2" );
- o = new BasicDBObject();
- o.put( "psi", "phi" );
- coll.save( o );
-
- Set set = db.getCollectionNames();
- String[] strs = set.toArray( new String[0] );
- Arrays.sort( strs );
- for( String s : strs ) {
- if( s.startsWith( "dbs" ) ) {
- System.out.println( s );
- }
- }
-
- db.getCollection( "dbs_1" ).drop();
- o = new BasicDBObject();
- o.put( "create", "dbs_3" );
- db.command( o );
-
- set = db.getCollectionNames();
- strs = set.toArray( new String[0] );
- Arrays.sort( strs );
- for( String s : strs ) {
- if( s.startsWith( "dbs" ) ) {
- System.out.println( s );
- }
- }
- }
-}
diff --git a/src/test/com/mongodb/framework/Find.java b/src/test/com/mongodb/framework/Find.java
deleted file mode 100644
index 68654f99005..00000000000
--- a/src/test/com/mongodb/framework/Find.java
+++ /dev/null
@@ -1,35 +0,0 @@
-/**
- * Copyright (C) 2008 10gen Inc.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.mongodb.framework;
-
-import java.net.*;
-
-import com.mongodb.*;
-
-public class Find {
-
- public static void main(String[] args)
- throws Exception {
-
- DB db = new Mongo().getDB( "driver_test_framework" );
- DBCollection c = db.getCollection( "test" );
-
- DBObject foo = new BasicDBObject();
- foo.put( "a", 2 );
- c.save( foo );
- }
-}
diff --git a/src/test/com/mongodb/framework/Find1.java b/src/test/com/mongodb/framework/Find1.java
deleted file mode 100644
index b2dfeb27873..00000000000
--- a/src/test/com/mongodb/framework/Find1.java
+++ /dev/null
@@ -1,41 +0,0 @@
-/**
- * Copyright (C) 2008 10gen Inc.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.mongodb.framework;
-
-import java.util.*;
-import java.net.*;
-
-import com.mongodb.*;
-import com.mongodb.util.*;
-
-
-public class Find1 {
-
- public static void main(String[] args)
- throws Exception {
-
- DB db = new Mongo().getDB( "driver_test_framework" );
- DBObject foo = new BasicDBObject();
- foo.put( "x", 1 );
- DBObject bar = new BasicDBObject();
- bar.put( "y", 1 );
- DBCursor cursor = db.getCollection( "c" ).find( foo ).sort( bar ).skip( 20 ).limit( 10 );
-
- while( cursor.hasNext() ) {
- System.out.println( cursor.next().get( "z" ) );
- }
- }
-}
diff --git a/src/test/com/mongodb/framework/Remove.java b/src/test/com/mongodb/framework/Remove.java
deleted file mode 100644
index 9b6e586200a..00000000000
--- a/src/test/com/mongodb/framework/Remove.java
+++ /dev/null
@@ -1,38 +0,0 @@
-/**
- * Copyright (C) 2008 10gen Inc.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.mongodb.framework;
-
-import java.util.*;
-import java.net.*;
-
-import com.mongodb.*;
-import com.mongodb.util.*;
-
-
-public class Remove {
-
- public static void main(String[] args)
- throws Exception {
-
- DB db = new Mongo().getDB( "driver_test_framework" );
- DBObject foo = new BasicDBObject();
- db.getCollection( "remove1" ).remove( foo );
-
- foo.put( "a", 3 );
- db.getCollection( "remove2" ).remove( foo );
- }
-}
diff --git a/src/test/com/mongodb/framework/Stress1.java b/src/test/com/mongodb/framework/Stress1.java
deleted file mode 100644
index b07be79d1d1..00000000000
--- a/src/test/com/mongodb/framework/Stress1.java
+++ /dev/null
@@ -1,66 +0,0 @@
-/**
- * Copyright (C) 2008 10gen Inc.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.mongodb.framework;
-
-import java.util.*;
-import java.net.*;
-
-import com.mongodb.*;
-import com.mongodb.util.*;
-
-public class Stress1 {
-
- public static void doStuff( DBCollection c, int count )
- throws MongoException {
- DBObject obj = new BasicDBObject();
- obj.put( "id", count );
- DBObject x = c.findOne( obj );
- x.put( "subarray", "foo" + count );
- c.save( x );
- }
-
- public static void main(String[] args)
- throws UnknownHostException , MongoException {
-
- DB db = new Mongo().getDB( "driver_test_framework" );
- DBCollection c = db.getCollection( "stress1" );
-
- String blah = "lksjhasoh1298alshasoidiohaskjasiouashoasasiugoas" +
- "lksjhasoh1298alshasoidiohaskjasiouashoasasiugoas" +
- "lksjhasoh1298alshasoidiohaskjasiouashoasasiugoas" +
- "lksjhasoh1298alshasoidiohaskjasiouashoasasiugoas" +
- "lksjhasoh1298alshasoidiohaskjasiouashoasasiugoas" +
- "lksjhasoh1298alshasoidiohaskjasiouashoasasiugoas";
-
- for( int i=0; i<50000; i++ ) {
- DBObject foo = new BasicDBObject();
- foo.put( "name", "asdf"+i );
- foo.put( "date", new Date() );
- foo.put( "id", i );
- foo.put( "blah", blah );
- c.save( foo );
- }
-
- for( int count=0; count<10000; count++ ) {
- doStuff( c, count );
- }
-
- DBObject idx = new BasicDBObject();
- idx.put( "date", 1 );
- c.ensureIndex( idx );
- }
-}
diff --git a/src/test/com/mongodb/framework/Test1.java b/src/test/com/mongodb/framework/Test1.java
deleted file mode 100644
index ce3c4fc6512..00000000000
--- a/src/test/com/mongodb/framework/Test1.java
+++ /dev/null
@@ -1,40 +0,0 @@
-
-/**
- * Copyright (C) 2008 10gen Inc.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.mongodb.framework;
-
-import java.util.*;
-import java.net.*;
-
-import com.mongodb.*;
-import com.mongodb.util.*;
-
-public class Test1 {
-
- public static void main(String[] args)
- throws Exception {
-
- DB db = new Mongo().getDB( "driver_test_framework" );
- DBCollection coll = db.getCollection( "part1" );
-
- for( int i=0; i<100; i++) {
- DBObject o = new BasicDBObject();
- o.put( "x", i );
- coll.save( o );
- }
- }
-}
diff --git a/src/test/com/mongodb/framework/dispatch b/src/test/com/mongodb/framework/dispatch
deleted file mode 100755
index e9c2dbc4e70..00000000000
--- a/src/test/com/mongodb/framework/dispatch
+++ /dev/null
@@ -1,34 +0,0 @@
-#!/bin/bash
-
-export CLASSPATH=$CLASSPATH:../../../../../build
-begintime=`date`
-if [[ "$1" = "test1" ]]; then
- java com.mongodb.framework.Test1
-#elif [[ "$1" = "count1" ]]; then
-# java com.mongodb.framework.Count1 > $2
-elif [[ "$1" = "find" ]]; then
- java com.mongodb.framework.Find
-elif [[ "$1" = "find1" ]]; then
- java com.mongodb.framework.Find1 > $2
-elif [[ "$1" = "remove" ]]; then
- java com.mongodb.framework.Remove
-elif [[ "$1" = "capped" ]]; then
- java com.mongodb.framework.Capped
-#elif [[ "$1" = "circular" ]]; then
-# java com.mongodb.framework.Circular
-elif [[ "$1" = "dbs" ]]; then
- java com.mongodb.framework.Dbs > $2
-elif [[ "$1" = "stress1" ]]; then
- java com.mongodb.framework.Stress1
-#elif [[ "$1" = "admin" ]]; then
-# java com.mongodb.framework.Admin > $2
-else
- exit 0
-fi
-exitval=$?
-endtime=`date`
-
-echo "begintime:$begintime" >> $2
-echo "endtime:$endtime" >> $2
-echo "exit_code:$exitval" >> $2
-
diff --git a/src/test/com/mongodb/gridfs/GridFSTest.java b/src/test/com/mongodb/gridfs/GridFSTest.java
deleted file mode 100644
index b933bdbadec..00000000000
--- a/src/test/com/mongodb/gridfs/GridFSTest.java
+++ /dev/null
@@ -1,170 +0,0 @@
-/**
- * Copyright (C) 2008 10gen Inc.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.mongodb.gridfs;
-
-import java.io.*;
-
-import org.testng.annotations.*;
-
-import com.mongodb.*;
-import com.mongodb.util.*;
-
-public class GridFSTest extends TestCase {
-
- public GridFSTest()
- throws IOException , MongoException {
- super();
- try {
- cleanupMongo = new Mongo( "127.0.0.1" );
- cleanupDB = "com_mongodb_unittest_GridFSTest";
- _db = cleanupMongo.getDB( cleanupDB );
- _fs = new GridFS( _db );
- }
- catch ( MongoException e ){
- e.printStackTrace();
- throw e;
- }
- catch ( IOException io ){
- io.printStackTrace();
- throw io;
- }
- catch ( RuntimeException re ){
- re.printStackTrace();
- throw re;
- }
- catch ( Throwable t ){
- t.printStackTrace();
- throw new RuntimeException( t );
- }
- }
-
- int[] _get(){
- int[] i = new int[2];
- i[0] = _fs._filesCollection.find().count();
- i[1] = _fs._chunkCollection.find().count();
- return i;
- }
-
- void testInOut( String s )
- throws Exception {
-
- int[] start = _get();
-
- GridFSInputFile in = _fs.createFile( s.getBytes() );
- in.save();
- GridFSDBFile out = _fs.findOne( new BasicDBObject( "_id" , in.getId() ) );
- assert( out.getId().equals( in.getId() ) );
- assert( out.getChunkSize() == (long)GridFS.DEFAULT_CHUNKSIZE );
-
- ByteArrayOutputStream bout = new ByteArrayOutputStream();
- out.writeTo( bout );
- String outString = new String( bout.toByteArray() );
- assert( outString.equals( s ) );
-
- out.remove();
- int[] end = _get();
- assertEquals( start[0] , end[0] );
- assertEquals( start[1] , end[1] );
- }
-
- @Test(groups = {"basic"})
- public void testSmall()
- throws Exception {
- testInOut( "this is a simple test" );
- }
-
- @Test(groups = {"basic"})
- public void testBig()
- throws Exception {
- int target = GridFS.DEFAULT_CHUNKSIZE * 3;
- StringBuilder buf = new StringBuilder( target );
- while ( buf.length() < target )
- buf.append( "asdasdkjasldkjasldjlasjdlajsdljasldjlasjdlkasjdlaskjdlaskjdlsakjdlaskjdasldjsad" );
- String s = buf.toString();
- testInOut( s );
- }
-
- void testOutStream( String s ) throws Exception {
-
- int[] start = _get();
-
- GridFSInputFile in = _fs.createFile();
- OutputStream writeStream = in.getOutputStream();
- writeStream.write( s.getBytes(), 0, s.length() );
- writeStream.close();
- GridFSDBFile out = _fs.findOne( new BasicDBObject( "_id" , in.getId() ) );
- assert ( out.getId().equals( in.getId() ) );
- assert ( out.getChunkSize() == (long) GridFS.DEFAULT_CHUNKSIZE );
-
- ByteArrayOutputStream bout = new ByteArrayOutputStream();
- out.writeTo( bout );
- String outString = new String( bout.toByteArray() );
- assert (outString.equals( s ));
-
- out.remove();
- int[] end = _get();
- assertEquals( start[0], end[0] );
- assertEquals( start[1], end[1] );
- }
-
- @Test(groups = { "basic" })
- public void testOutStreamSmall() throws Exception {
- testOutStream( "this is a simple test" );
- }
-
- @Test(groups = { "basic" })
- public void testOutStreamBig() throws Exception {
- int target = (int) (GridFS.DEFAULT_CHUNKSIZE * 3.5);
- StringBuilder buf = new StringBuilder( target );
- while ( buf.length() < target ) {
- buf.append( "asdasdkjasldkjasldjlasjdlajsdljasldjlasjdlkasjdlaskjdlaskjdlsakjdlaskjdasldjsad" );
- }
- String s = buf.toString();
- testOutStream( s );
- }
-
- @Test(groups = { "basic" })
- public void testOutStreamBigAligned() throws Exception {
- int target = (int) (GridFS.DEFAULT_CHUNKSIZE * 4);
- StringBuilder buf = new StringBuilder( target );
- while ( buf.length() < target ) {
- buf.append( "a" );
- }
- String s = buf.toString();
- testOutStream( s );
- }
-
- @Test(groups = {"basic"})
- public void testMetadata()
- throws Exception {
-
- GridFSInputFile in = _fs.createFile( "foo".getBytes() );
- in.put("meta", 5);
- in.save();
- GridFSDBFile out = _fs.findOne( new BasicDBObject( "_id" , in.getId() ) );
- assert( out.get("meta").equals( 5 ) );
- }
-
- final DB _db;
- final GridFS _fs;
-
- public static void main( String args[] )
- throws Exception {
- (new GridFSTest()).runConsole();
- }
-
-}
diff --git a/src/test/com/mongodb/io/ByteBufferStreamTest.java b/src/test/com/mongodb/io/ByteBufferStreamTest.java
deleted file mode 100644
index 305ae675bea..00000000000
--- a/src/test/com/mongodb/io/ByteBufferStreamTest.java
+++ /dev/null
@@ -1,129 +0,0 @@
-// ByteBufferStreamTest.java
-
-/**
- * Copyright (C) 2008 10gen Inc.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.mongodb.io;
-
-import java.io.*;
-import java.nio.*;
-import java.util.*;
-import java.util.zip.*;
-
-import org.testng.annotations.Test;
-
-import com.mongodb.util.*;
-
-public class ByteBufferStreamTest extends TestCase {
-
- @Test(groups = {"basic"})
- public void test1()
- throws IOException {
- _testInOut( 16 , 128 );
- _testInOut( 16 , 4 );
- _testInOut( 1024 , 128 );
- _testInOut( 1024 , 2048 );
- }
-
- private void _testInOut( int dataSize , int bufSize )
- throws IOException {
- String s = _getData( dataSize );
- byte[] bytes = s.getBytes();
-
- ByteBufferOutputStream bout = new ByteBufferOutputStream( bufSize );
- bout.write( bytes );
-
- assertEquals( (int)Math.ceil( (double)(bytes.length) / bufSize ) , bout.getBuffers().size() );
-
- ByteBufferInputStream bin = new ByteBufferInputStream( bout.getBuffers() , true );
- String out = new String( StreamUtil.readBytesFully( bin ) );
- assertEquals( s , out );
-
- }
-
- @Test(groups = {"basic"})
- public void testplay()
- throws IOException {
- _testplay( 16 , 128 );
- _testplay( 16 , 4 );
- _testplay( 1024 , 128 );
- _testplay( 1024 , 2048 );
- _testplay( 20000 , 200 );
- }
-
- private void _testplay( int dataSize , int bufSize )
- throws IOException {
- String s = _getData( dataSize );
- byte[] bytes = s.getBytes();
-
- ByteBufferOutputStream bout = new ByteBufferOutputStream( bufSize );
- bout.write( bytes );
-
- assertEquals( (int)Math.ceil( (double)(bytes.length) / bufSize ) , bout.getBuffers().size() );
-
- ByteBufferInputStream bin = new ByteBufferInputStream( bout.getBuffers() , true );
- ByteArrayInputStream arr = new ByteArrayInputStream( bytes );
-
- assertEquals( bin.available() , arr.available() );
- while ( arr.available() > 0 ){
- assertEquals( bin.available() , arr.available() );
- assertEquals( bin.read() , arr.read() );
- assertEquals( bin.read( new byte[12] ) , arr.read( new byte[12] ) );
- }
-
- assertEquals( bin.available() , arr.available() );
- }
-
-
- @Test(groups = {"basic"})
- public void testZip1()
- throws IOException {
- _testZip( 128 , 2048 );
- _testZip( 1024 , 128 );
- }
-
- void _testZip( int dataSize , int bufSize )
- throws IOException {
-
- String s = _getData( dataSize );
-
- ByteBufferOutputStream bout = new ByteBufferOutputStream( bufSize );
-
- GZIPOutputStream gout = new GZIPOutputStream( bout );
- gout.write( s.getBytes() );
- gout.flush();
- gout.close();
-
- ByteBufferInputStream bin = new ByteBufferInputStream( bout.getBuffers() , true );
- GZIPInputStream gin = new GZIPInputStream( bin );
- String out = new String( StreamUtil.readBytesFully( gin ) );
-
- assertEquals( s , out );
- }
-
- String _getData( int size ){
- StringBuilder buf = new StringBuilder( size + 200 );
- while ( buf.length() < size )
- buf.append( "eliot was here " + _rand.nextDouble() );
- return buf.toString();
- }
-
- static final Random _rand = new Random( 123123 );
-
- public static void main( String args[] ){
- (new ByteBufferStreamTest()).runConsole();
- }
-}
diff --git a/src/test/com/mongodb/util/JSONTest.java b/src/test/com/mongodb/util/JSONTest.java
deleted file mode 100644
index a904bf221e1..00000000000
--- a/src/test/com/mongodb/util/JSONTest.java
+++ /dev/null
@@ -1,307 +0,0 @@
-// JSONTest.java
-
-/**
- * Copyright (C) 2008 10gen Inc.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.mongodb.util;
-
-import java.util.*;
-
-import java.util.regex.*;
-
-import java.text.*;
-
-import org.bson.types.*;
-
-import com.mongodb.*;
-
-import org.testng.annotations.Test;
-
-public class JSONTest extends com.mongodb.util.TestCase {
-
- @org.testng.annotations.Test(groups = {"basic"})
- public void testNumbers(){
- assertEquals(JSON.serialize(JSON.parse("{'x' : 5 }")), "{ \"x\" : 5}");
- assertEquals(JSON.serialize(JSON.parse("{'x' : 5.0 }")), "{ \"x\" : 5.0}");
- assertEquals(JSON.serialize(JSON.parse("{'x' : 0 }")), "{ \"x\" : 0}");
- assertEquals(JSON.serialize(JSON.parse("{'x' : 0.0 }")), "{ \"x\" : 0.0}");
- assertEquals(JSON.serialize(JSON.parse("{'x' : 500 }")), "{ \"x\" : 500}");
- assertEquals(JSON.serialize(JSON.parse("{'x' : 500.0 }")), "{ \"x\" : 500.0}");
- assertEquals(JSON.serialize(JSON.parse("{'x' : 0.500 }")), "{ \"x\" : 0.5}");
- assertEquals(JSON.serialize(JSON.parse("{'x' : 5. }")), "{ \"x\" : 5.0}");
- assertEquals(JSON.serialize(JSON.parse("{'x' : 5.0e+1 }")), "{ \"x\" : 50.0}");
- assertEquals(JSON.serialize(JSON.parse("{'x' : 5.0E-1 }")), "{ \"x\" : 0.5}");
- }
-
- @org.testng.annotations.Test(groups = {"basic"})
- public void testLongValues() {
- Long val = Integer.MAX_VALUE + 1L;
- String test = String.format("{ \"x\" : %d}", val);
- assertEquals(JSON.serialize(JSON.parse(test)), test);
- }
-
- @org.testng.annotations.Test(groups = {"basic"})
- public void testSimple() {
- assertEquals(JSON.serialize(JSON.parse("{'csdf' : true}")), "{ \"csdf\" : true}");
- assertEquals(JSON.serialize(JSON.parse("{'csdf' : false}")), "{ \"csdf\" : false}");
- assertEquals(JSON.serialize(JSON.parse("{'csdf' : null}")), "{ \"csdf\" : null }");
- }
-
- @org.testng.annotations.Test(groups = {"basic"})
- public void testString() {
- assertEquals(JSON.serialize(JSON.parse("{'csdf' : \"foo\"}")), "{ \"csdf\" : \"foo\"}") ;
- assertEquals(JSON.serialize(JSON.parse("{'csdf' : \'foo\'}")), "{ \"csdf\" : \"foo\"}") ;
- assertEquals(JSON.serialize(JSON.parse("{'csdf' : \"a\\\"b\"}")), "{ \"csdf\" : \"a\\\"b\"}");
- assertEquals(JSON.serialize(JSON.parse("{\n\t\"id\":\"1689c12eb234c54a84ebd100\",\n}")),
- "{ \"id\" : \"1689c12eb234c54a84ebd100\"}");
- }
-
- @org.testng.annotations.Test(groups = {"basic"})
- public void testArray() {
- assertEquals(JSON.serialize(JSON.parse("{'csdf' : [\"foo\"]}")), "{ \"csdf\" : [ \"foo\"]}") ;
- assertEquals(JSON.serialize(JSON.parse("{'csdf' : [3, 5, \'foo\', null]}")), "{ \"csdf\" : [ 3 , 5 , \"foo\" , null ]}") ;
- assertEquals(JSON.serialize(JSON.parse("{'csdf' : [3.0, 5.0, \'foo\', null]}")), "{ \"csdf\" : [ 3.0 , 5.0 , \"foo\" , null ]}") ;
- assertEquals(JSON.serialize(JSON.parse("{'csdf' : [[],[[]],false]}")), "{ \"csdf\" : [ [ ] , [ [ ]] , false]}");
- }
-
- @org.testng.annotations.Test(groups = {"basic"})
- public void testObject() {
- assertEquals(JSON.serialize(JSON.parse("{'csdf' : {}}")), "{ \"csdf\" : { }}") ;
- assertEquals(JSON.serialize(JSON.parse("{'csdf' : {\"foo\":\"bar\"}}")), "{ \"csdf\" : { \"foo\" : \"bar\"}}") ;
- assertEquals(JSON.serialize(JSON.parse("{'csdf' : {\'hi\':{\'hi\':[{}]}}}")), "{ \"csdf\" : { \"hi\" : { \"hi\" : [ { }]}}}");
- }
-
- @org.testng.annotations.Test(groups = {"basic"})
- public void testMulti() {
- assertEquals(JSON.serialize(JSON.parse("{\'\' : \"\", \"34\" : -52.5}")), "{ \"\" : \"\" , \"34\" : -52.5}") ;
- }
-
- @org.testng.annotations.Test(groups = {"basic"})
- public void testUnicode() {
- assertEquals(JSON.serialize(JSON.parse("{'x' : \"hi\\u0020\"}")),"{ \"x\" : \"hi \"}") ;
- assertEquals(JSON.serialize(JSON.parse("{ \"x\" : \"\\u0E01\\u2702\\uF900\"}")), "{ \"x\" : \"\u0E01\u2702\uF900\"}");
- assertEquals(JSON.serialize(JSON.parse("{ \"x\" : \"foo\\u0020bar\"}")), "{ \"x\" : \"foo bar\"}");
- }
-
- @org.testng.annotations.Test(groups = {"basic"})
- public void testBin() {
- byte b[] = {'a', 'b', 0, 'd'};
- DBObject obj = BasicDBObjectBuilder.start().add("b", b).get();
- assertEquals(JSON.serialize(obj), "{ \"b\" : }");
- }
-
-
- @org.testng.annotations.Test(groups = {"basic"})
- public void testErrors(){
- boolean threw = false;
- try {
- JSON.parse("{\"x\" : \"");
- }
- catch(JSONParseException e) {
- threw = true;
- }
- assertEquals(threw, true);
- threw = false;
- try {
- JSON.parse("{\"x\" : \"\\");
- }
- catch(JSONParseException e) {
- threw = true;
- }
- assertEquals(threw, true);
- threw = false;
- try {
- JSON.parse("{\"x\" : 5.2");
- }
- catch(JSONParseException e) {
- threw = true;
- }
- assertEquals(threw, true);
- threw = false;
- try {
- JSON.parse("{\"x\" : 5");
- }
- catch(JSONParseException e) {
- threw = true;
- }
- assertEquals(threw, true);
- threw = false;
- try {
- JSON.parse("{\"x\" : 5,");
- }
- catch(JSONParseException e) {
- threw = true;
- }
- assertEquals(threw, true);
- threw = false;
- }
-
- @org.testng.annotations.Test(groups = {"basic"})
- public void testBasic(){
- assertEquals( JSON.serialize(JSON.parse("{}")), "{ }");
- assertEquals( JSON.parse(""), null );
- assertEquals( JSON.parse(" "), null);
- assertEquals( JSON.parse(null), null);
-
- boolean threw = false;
- try {
- JSON.parse("{");
- }
- catch(JSONParseException e) {
- threw = true;
- }
- assertEquals(threw, true);
- threw = false;
-
- try {
- JSON.parse("}");
- }
- catch(JSONParseException e) {
- threw = true;
- }
- assertEquals(threw, true);
- threw = false;
-
- try {
- JSON.parse("{{}");
- }
- catch(JSONParseException e) {
- threw = true;
- }
- assertEquals(threw, true);
- threw = false;
-
- try {
- JSON.parse("4");
- }
- catch(JSONParseException e) {
- threw = true;
- }
- assertEquals(threw, false);
- threw = false;
-
- assertEquals( 4 , JSON.parse( "4" ) );
- }
-
- @org.testng.annotations.Test
- public void testNumbers2(){
- DBObject x = new BasicDBObject( "x" , 123 );
- assertEquals( x , JSON.parse( x.toString() ) );
-
- x = new BasicDBObject( "x" , 123123123123L );
- assertEquals( x , JSON.parse( x.toString() ) );
-
- x = new BasicDBObject( "x" , 123123123 );
- assertEquals( x , JSON.parse( x.toString() ) );
- }
-
- void _escapeChar( String s ){
- String thingy = "va" + s + "lue";
- DBObject x = new BasicDBObject( "name" , thingy );
- x = (DBObject)JSON.parse( x.toString() );
- assertEquals( thingy , x.get( "name" ) );
-
- thingy = "va" + s + s + s + "lue" + s;
- x = new BasicDBObject( "name" , thingy );
- x = (DBObject)JSON.parse( x.toString() );
- assertEquals( thingy , x.get( "name" ) );
- }
-
-
-
- @org.testng.annotations.Test
- public void testEscape1(){
- String raw = "a\nb";
-
- DBObject x = new BasicDBObject( "x" , raw );
- assertEquals( "\"a\\nb\"" , JSON.serialize( raw ) );
- assertEquals( x , JSON.parse( x.toString() ) );
- assertEquals( raw , ((DBObject)JSON.parse( x.toString() ) ).get( "x" ) );
-
- x = new BasicDBObject( "x" , "a\nb\bc\td\re" );
- assertEquals( x , JSON.parse( x.toString() ) );
-
-
- String thingy = "va\"lue";
- x = new BasicDBObject( "name" , thingy );
- x = (DBObject)JSON.parse( x.toString() );
- assertEquals( thingy , x.get( "name" ) );
-
- thingy = "va\\lue";
- x = new BasicDBObject( "name" , thingy );
- x = (DBObject)JSON.parse( x.toString() );
- assertEquals( thingy , x.get( "name" ) );
-
- assertEquals( "va/lue" , (String)JSON.parse("\"va\\/lue\"") );
- assertEquals( "value" , (String)JSON.parse("\"va\\lue\"") );
- assertEquals( "va\\lue" , (String)JSON.parse("\"va\\\\lue\"") );
-
- _escapeChar( "\t" );
- _escapeChar( "\b" );
- _escapeChar( "\n" );
- _escapeChar( "\r" );
- _escapeChar( "\'" );
- _escapeChar( "\"" );
- _escapeChar( "\\" );
- }
-
- @org.testng.annotations.Test
- public void testPattern() {
- String x = "^Hello$";
- String serializedPattern =
- "{ \"$regex\" : \"" + x + "\" , \"$options\" : \"" + "i\"}";
-
- Pattern pattern = Pattern.compile( x , Pattern.CASE_INSENSITIVE);
- assertEquals( serializedPattern, JSON.serialize(pattern));
-
- BasicDBObject a = new BasicDBObject( "x" , pattern );
- assertEquals( "{ \"x\" : " + serializedPattern + "}" , a.toString() );
-
- DBObject b = (DBObject)JSON.parse( a.toString() );
- assertEquals( b.get("x").getClass(), Pattern.class );
- assertEquals( a.toString() , b.toString() );
- }
-
- @org.testng.annotations.Test
- public void testObjectId() {
- ObjectId oid = new ObjectId(new Date());
-
- String serialized = JSON.serialize(oid);
- assertEquals("{ \"$oid\" : \"" + oid + "\"}", serialized);
-
- ObjectId oid2 = (ObjectId)JSON.parse(serialized);
- assertEquals(oid, oid2);
- }
-
- @org.testng.annotations.Test
- public void testDate() {
- Date d = new Date();
- SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");
- format.setCalendar(new GregorianCalendar(new SimpleTimeZone(0, "GMT")));
- String formattedDate = format.format(d);
-
- String serialized = JSON.serialize(d);
- assertEquals("{ \"$date\" : \"" + formattedDate + "\"}", serialized);
-
- Date d2 = (Date)JSON.parse(serialized);
- assertEquals(d.toString(), d2.toString());
- }
-
- public static void main( String args[] ){
- (new JSONTest()).runConsole();
- }
-
-}
diff --git a/src/test/com/mongodb/util/SimplePoolTest.java b/src/test/com/mongodb/util/SimplePoolTest.java
deleted file mode 100644
index b433319f8e6..00000000000
--- a/src/test/com/mongodb/util/SimplePoolTest.java
+++ /dev/null
@@ -1,112 +0,0 @@
-// SimplePoolTest.java
-
-/**
- * Copyright (C) 2008 10gen Inc.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.mongodb.util;
-
-import org.testng.annotations.Test;
-
-public class SimplePoolTest extends com.mongodb.util.TestCase {
-
- class MyPool extends SimplePool {
-
- MyPool( int maxToKeep , int maxTotal ){
- super( "blah" , maxToKeep , maxTotal );
- }
-
- public Integer createNew(){
- return _num++;
- }
-
- int _num = 0;
- }
-
- @org.testng.annotations.Test
- public void testBasic1(){
- MyPool p = new MyPool( 10 , 10 );
-
- int a = p.get();
- assertEquals( 0 , a );
-
- int b = p.get();
- assertEquals( 1 , b );
-
- p.done( a );
- a = p.get();
- assertEquals( 0 , a );
- }
-
- @org.testng.annotations.Test
- public void testBasic2(){
- MyPool p = new MyPool( 0 , 0 );
-
- int a = p.get();
- assertEquals( 0 , a );
-
- int b = p.get();
- assertEquals( 1 , b );
-
- p.done( a );
- a = p.get();
- assertEquals( 2 , a );
- }
-
- @org.testng.annotations.Test
- public void testMax1(){
- MyPool p = new MyPool( 10 , 2 );
-
- int a = p.get();
- assertEquals( 0 , a );
-
- int b = p.get();
- assertEquals( 1 , b );
-
- assertNull( p.get( 0 ) );
- }
-
- @org.testng.annotations.Test
- public void testMax2(){
- MyPool p = new MyPool( 10 , 3 );
-
- int a = p.get();
- assertEquals( 0 , a );
-
- int b = p.get();
- assertEquals( 1 , b );
-
- assertEquals( 2 , (int)p.get( -1 ) );
- }
-
- @org.testng.annotations.Test
- public void testMax3(){
- MyPool p = new MyPool( 10 , 3 );
-
- int a = p.get();
- assertEquals( 0 , a );
-
- int b = p.get();
- assertEquals( 1 , b );
-
- assertEquals( 2 , (int)p.get( 1 ) );
- }
-
-
- public static void main( String args[] ){
- SimplePoolTest t = new SimplePoolTest();
- t.runConsole();
- }
-}
diff --git a/src/test/com/mongodb/util/StringRangeSetTest.java b/src/test/com/mongodb/util/StringRangeSetTest.java
deleted file mode 100644
index 76e09f173c7..00000000000
--- a/src/test/com/mongodb/util/StringRangeSetTest.java
+++ /dev/null
@@ -1,48 +0,0 @@
-/**
- * Copyright (C) 2010 10gen Inc.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.mongodb.util;
-
-import java.util.ArrayList;
-import java.util.Arrays;
-
-import org.testng.annotations.Test;
-
-public class StringRangeSetTest extends com.mongodb.util.TestCase {
-
- @org.testng.annotations.Test
- public void rangeOfSizeProducesCorrectIteration() {
- int len = 250;
- StringRangeSet set = new StringRangeSet(len);
- int i = 0;
- for (String num : set) {
- assertEquals(num, String.valueOf(i++));
- }
- assertEquals(i, 250);
- }
-
- @org.testng.annotations.Test
- public void testToArray() {
- int len = 1000;
- StringRangeSet set = new StringRangeSet(len);
- String[] array = (String[]) set.toArray();
- for (int i = 0; i < len; ++i)
- assertEquals(array[i], String.valueOf(i));
- }
-
- public static void main(String args[]) {
- (new StringRangeSetTest()).runConsole();
- }
-}
diff --git a/src/test/com/mongodb/util/ThreadPoolTest.java b/src/test/com/mongodb/util/ThreadPoolTest.java
deleted file mode 100644
index f500dcae721..00000000000
--- a/src/test/com/mongodb/util/ThreadPoolTest.java
+++ /dev/null
@@ -1,49 +0,0 @@
-// ThreadPoolTest.java
-
-/**
- * Copyright (C) 2008 10gen Inc.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.mongodb.util;
-
-import org.testng.annotations.Test;
-
-public class ThreadPoolTest extends com.mongodb.util.TestCase {
-
- @org.testng.annotations.Test
- public void test1()
- throws Exception {
- ThreadPool tp = new ThreadPool( "blah" , 2 ){
-
- public void handle( Object o ){
- throw new Error();
- }
-
- public void handleError( Object o , Exception e ){
- System.err.println( "handleError called" );
- }
- };
-
- tp.offer( "silly" );
- Thread.sleep( 20 );
-
- assertEquals( 0 , tp.inProgress() );
- assertEquals( 0 , tp.numThreads() );
- }
-
- public static void main( String args[] ){
- (new ThreadPoolTest()).runConsole();
- }
-}
diff --git a/src/test/com/mongodb/util/UniqueListTest.java b/src/test/com/mongodb/util/UniqueListTest.java
deleted file mode 100644
index 681bbba8628..00000000000
--- a/src/test/com/mongodb/util/UniqueListTest.java
+++ /dev/null
@@ -1,37 +0,0 @@
-/**
- * Copyright (C) 2008 10gen Inc.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.mongodb.util;
-
-import org.testng.annotations.Test;
-
-public class UniqueListTest extends com.mongodb.util.TestCase {
-
- @org.testng.annotations.Test
- public void test1(){
- UniqueList l = new UniqueList();
- l.add( "a" );
- assertEquals( 1 , l.size() );
- l.add( "a" );
- assertEquals( 1 , l.size() );
- l.add( "b" );
- assertEquals( 2 , l.size() );
- }
-
- public static void main( String args[] ){
- (new UniqueListTest()).runConsole();
- }
-}
diff --git a/src/test/org/bson/BSONTest.java b/src/test/org/bson/BSONTest.java
deleted file mode 100644
index 8f3b9d21f0b..00000000000
--- a/src/test/org/bson/BSONTest.java
+++ /dev/null
@@ -1,326 +0,0 @@
-// BSONTest.java
-
-/**
- * Copyright (C) 2008 10gen Inc.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.bson;
-
-import java.io.*;
-import java.util.*;
-
-import org.bson.io.*;
-import org.bson.types.*;
-import org.testng.annotations.*;
-
-import com.mongodb.util.*;
-
-public class BSONTest extends TestCase {
-
-
- public BSONTest(){
- for ( int x = 8; x<2048; x*=2 ){
- StringBuilder buf = new StringBuilder();
- while ( buf.length() < x )
- buf.append( x );
- _data.add( buf.toString() );
- }
- }
-
-
- void _test( BSONObject o , int size , String hash )
- throws IOException {
- BSONEncoder e = new BSONEncoder();
- OutputBuffer buf = new BasicOutputBuffer();
- e.set( buf );
- e.putObject( o );
- assertEquals( size , buf.size() );
- assertEquals( hash , buf.md5() );
- e.done();
-
- BSONDecoder d = new BSONDecoder();
- BasicBSONCallback cb = new BasicBSONCallback();
- int s = d.decode( new ByteArrayInputStream( buf.toByteArray() ) , cb );
- assertEquals( size , s );
-
- OutputBuffer buf2 = new BasicOutputBuffer();
- e.set( buf2 );
- e.putObject( (BSONObject)cb.get() );
- assertEquals( size , buf2.size() );
- assertEquals( hash , buf2.md5() );
-
- }
-
- @Test
- public void testBasic1()
- throws IOException {
-// BSONObject o = new BasicBSONObject();
- _test( new BasicBSONObject( "x" , true ) , 9 , "6fe24623e4efc5cf07f027f9c66b5456" );
-
- _test( new BasicBSONObject( "x" , null ) , 8 , "12d43430ff6729af501faf0638e68888" );
- _test( new BasicBSONObject( "x" , 5.2 ) , 16 , "aaeeac4a58e9c30eec6b0b0319d0dff2" );
- _test( new BasicBSONObject( "x" , "eliot" ), 18 , "331a3b8b7cbbe0706c80acdb45d4ebbe" );
- _test( new BasicBSONObject( "x" , 5.2 ).append( "y" , "truth" ).append( "z" , 1.1 ) ,
- 40 , "7c77b3a6e63e2f988ede92624409da58" );
-
- _test( new BasicBSONObject( "a" , new BasicBSONObject( "b" , 1.1 ) ) , 24 , "31887a4b9d55cd9f17752d6a8a45d51f" );
- _test( new BasicBSONObject( "x" , 5.2 ).append( "y" , new BasicBSONObject( "a" , "eliot" ).append( "b" , true ) ).append( "z" , null ) , 44 , "b3de8a0739ab329e7aea138d87235205" );
- _test( new BasicBSONObject( "x" , 5.2 ).append( "y" , new Object[]{ "a" , "eliot" , "b" , true } ).append( "z" , null ) , 62 , "cb7bad5697714ba0cbf51d113b6a0ee8" );
-
- _test( new BasicBSONObject( "x" , 4 ) , 12 , "d1ed8dbf79b78fa215e2ded74548d89d" );
- }
-
- @Test
- public void testArray()
- throws IOException {
- _test( new BasicBSONObject( "x" , new int[]{ 1 , 2 , 3 , 4} ) , 41 , "e63397fe37de1349c50e1e4377a45e2d" );
- }
-
- @Test
- public void testOB1(){
- BasicOutputBuffer buf = new BasicOutputBuffer();
- buf.write( "eliot".getBytes() );
- assertEquals( 5 , buf.getPosition() );
- assertEquals( 5 , buf.size() );
-
- assertEquals( "eliot" , buf.asString() );
-
- buf.setPosition( 2 );
- buf.write( "z".getBytes() );
- assertEquals( "elzot" , buf.asString() );
-
- buf.seekEnd();
- buf.write( "foo".getBytes() );
- assertEquals( "elzotfoo" , buf.asString() );
-
- buf.seekStart();
- buf.write( "bar".getBytes() );
- assertEquals( "barotfoo" , buf.asString() );
-
- }
-
- @Test
- public void testCode()
- throws IOException{
- BSONObject scope = new BasicBSONObject( "x", 1 );
- CodeWScope c = new CodeWScope( "function() { x += 1; }" , scope );
- BSONObject code_object = new BasicBSONObject( "map" , c);
- _test( code_object , 53 , "52918d2367533165bfc617df50335cbb" );
- }
-
- @Test
- public void testBinary()
- throws IOException{
- byte[] data = new byte[10000];
- for(int i=0; i<10000; i++) {
- data[i] = 1;
- }
- BSONObject binary_object = new BasicBSONObject( "bin" , data);
- _test( binary_object , 10019 , "682d9a636619b135fa9801ac42c48a10" );
- }
-
- @Test
- public void testOBBig1(){
- BasicOutputBuffer a = new BasicOutputBuffer();
- StringBuilder b = new StringBuilder();
- for ( String x : _data ){
- a.write( x.getBytes() );
- b.append( x );
- }
- assertEquals( a.asString() , b.toString() );
- }
-
- @Test
- public void testUTF8(){
- for ( int i=1; i<=Character.MAX_CODE_POINT; i++ ){
-
- if ( ! Character.isValidCodePoint( i ) )
- continue;
-
- String orig = new String( Character.toChars( i ) );
- BSONObject a = new BasicBSONObject( orig , orig );
- BSONObject b = BSON.decode( BSON.encode( a ) );
- assertEquals( a , b );
- }
-
- }
-
- @Test
- public void testCustomEncoders()
- throws IOException{
- // If clearEncodingHooks isn't working the first test will fail.
- Transformer tf = new TestDateTransformer();
- BSON.addEncodingHook( TestDate.class, tf );
- BSON.clearEncodingHooks();
- TestDate td = new TestDate( 2009 , 01 , 23 , 10 , 53 , 42 );
- BSONObject o = new BasicBSONObject( "date" , td );
- BSONEncoder e = new BSONEncoder();
- BSONDecoder d = new BSONDecoder();
- BasicBSONCallback cb = new BasicBSONCallback();
- OutputBuffer buf = new BasicOutputBuffer();
- e.set( buf );
- boolean encodeFailed = false;
- try {
- e.putObject( o );
- }
- catch ( IllegalArgumentException ieE ) {
- encodeFailed = true;
- }
- assertTrue( encodeFailed, "Expected encoding to fail but it didn't." );
- // Reset the buffer
- buf.seekStart();
- assertTrue( td instanceof TestDate );
- assertTrue( tf.transform( td ) instanceof java.util.Date, "Transforming a TestDate should yield a JDK Date" );
-
- BSON.addEncodingHook( TestDate.class, tf );
- e.putObject( o );
- e.done();
-
- d.decode( new ByteArrayInputStream( buf.toByteArray() ), cb );
- Object result = cb.get();
- assertTrue( result instanceof BSONObject, "Expected to retrieve a BSONObject but got '" + result.getClass() + "' instead." );
- BSONObject bson = (BSONObject) result;
- assertNotNull( bson.get( "date" ) );
- assertTrue( bson.get( "date" ) instanceof java.util.Date );
-
- // Check that the hooks registered
- assertNotNull( BSON.getEncodingHooks( TestDate.class ) );
- Vector expect = new Vector( 1 );
- expect.add( tf );
- assertEquals( BSON.getEncodingHooks( TestDate.class ), expect );
- assertTrue( BSON.getEncodingHooks( TestDate.class ).contains( tf ) );
- BSON.removeEncodingHook( TestDate.class, tf );
- assertFalse( BSON.getEncodingHooks( TestDate.class ).contains( tf ) );
- }
-
- @Test
- @SuppressWarnings( "deprecation" )
- public void testCustomDecoders()
- throws IOException{
- // If clearDecodingHooks isn't working this whole test will fail.
- Transformer tf = new TestDateTransformer();
- BSON.addDecodingHook( Date.class, tf );
- BSON.clearDecodingHooks();
- TestDate td = new TestDate( 2009 , 01 , 23 , 10 , 53 , 42 );
- Date dt = new Date( 2009 , 01 , 23 , 10 , 53 , 42 );
- BSONObject o = new BasicBSONObject( "date" , dt );
- BSONDecoder d = new BSONDecoder();
- BSONEncoder e = new BSONEncoder();
- BasicBSONCallback cb = new BasicBSONCallback();
- OutputBuffer buf = new BasicOutputBuffer();
- e.set( buf );
- e.putObject( o );
- e.done();
-
- d.decode( new ByteArrayInputStream( buf.toByteArray() ), cb );
- Object result = cb.get();
- assertTrue( result instanceof BSONObject, "Expected to retrieve a BSONObject but got '" + result.getClass() + "' instead." );
- BSONObject bson = (BSONObject) result;
- assertNotNull( bson.get( "date" ) );
- assertTrue( bson.get( "date" ) instanceof java.util.Date );
-
- BSON.addDecodingHook( Date.class, tf );
-
- d.decode( new ByteArrayInputStream( buf.toByteArray() ), cb );
- bson = (BSONObject) cb.get();
- assertNotNull( bson.get( "date" ) );
- assertTrue( bson.get( "date" ) instanceof TestDate );
- assertEquals( bson.get( "date" ), td );
-
- // Check that the hooks registered
- assertNotNull( BSON.getDecodingHooks( Date.class ) );
- Vector expect = new Vector( 1 );
- expect.add( tf );
- assertEquals( BSON.getDecodingHooks( Date.class ), expect );
- assertTrue( BSON.getDecodingHooks( Date.class ).contains( tf ) );
- BSON.removeDecodingHook( Date.class, tf );
- assertFalse( BSON.getDecodingHooks( Date.class ).contains( tf ) );
-
- }
-
- private class TestDate {
- final int year;
- final int month;
- final int date;
- final int hour;
- final int minute;
- final int second;
-
- public TestDate(int year , int month , int date , int hour , int minute , int second) {
- this.year = year;
- this.month = month;
- this.date = date;
- this.hour = hour;
- this.minute = minute;
- this.second = second;
- }
-
- public TestDate(int year , int month , int date) {
- this( year , month , date , 0 , 0 , 0 );
- }
-
- @Override
- public boolean equals( Object other ){
- if ( this == other )
- return true;
- if ( !( other instanceof TestDate ) )
- return false;
-
- TestDate otherDt = (TestDate) other;
- return ( otherDt.year == this.year && otherDt.month == this.month && otherDt.date == this.date && otherDt.hour == this.hour
- && otherDt.minute == this.minute && otherDt.second == this.second );
- }
-
- @Override
- public String toString(){
- return year + "-" + month + "-" + date + " " + hour + ":" + minute + ":" + second;
- }
- }
-
- private class TestDateTransformer implements Transformer {
- @SuppressWarnings( "deprecation" )
- public Object transform( Object o ){
- if ( o instanceof TestDate ) {
- TestDate td = (TestDate) o;
- return new java.util.Date( td.year , td.month , td.date , td.hour , td.minute , td.second );
- }
- else if ( o instanceof java.util.Date ) {
- Date d = (Date) o;
- return new TestDate( d.getYear() , d.getMonth() , d.getDate() , d.getHours() , d.getMinutes() , d.getSeconds() );
- }
- else
- return o;
- }
- }
-
- void _roundTrip( BSONObject o ){
- assertEquals( o , BSON.decode( BSON.encode( o ) ) );
- }
-
- @Test
- public void testRandomRoundTrips(){
- _roundTrip( new BasicBSONObject( "a" , "" ) );
- _roundTrip( new BasicBSONObject( "a" , "a" ) );
- _roundTrip( new BasicBSONObject( "a" , "b" ) );
- }
-
- List _data = new ArrayList();
-
-
- public static void main( String args[] ){
- (new BSONTest()).runConsole();
- }
-
-}
diff --git a/src/test/org/bson/PoolOutputBufferTest.java b/src/test/org/bson/PoolOutputBufferTest.java
deleted file mode 100644
index 1f90d127a73..00000000000
--- a/src/test/org/bson/PoolOutputBufferTest.java
+++ /dev/null
@@ -1,82 +0,0 @@
-// PoolOutputBufferTest.java
-
-/**
- * Copyright (C) 2008 10gen Inc.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.bson;
-
-import java.io.*;
-import java.nio.*;
-import java.util.*;
-import java.util.zip.*;
-
-import org.testng.annotations.Test;
-
-import com.mongodb.util.*;
-import org.bson.io.*;
-
-public class PoolOutputBufferTest extends TestCase {
-
- public PoolOutputBufferTest(){
- for ( int x = 8; x<(PoolOutputBuffer.BUF_SIZE*3); x*=2 ){
- StringBuilder buf = new StringBuilder();
- while ( buf.length() < x )
- buf.append( x );
- _data.add( buf.toString() );
- }
- }
-
- @Test
- public void testBasic1(){
- PoolOutputBuffer buf = new PoolOutputBuffer();
- buf.write( "eliot".getBytes() );
- assertEquals( 5 , buf.getPosition() );
- assertEquals( 5 , buf.size() );
-
- assertEquals( "eliot" , buf.asString() );
-
- buf.setPosition( 2 );
- buf.write( "z".getBytes() );
- assertEquals( "elzot" , buf.asString() );
-
- buf.seekEnd();
- buf.write( "foo".getBytes() );
- assertEquals( "elzotfoo" , buf.asString() );
-
- buf.seekStart();
- buf.write( "bar".getBytes() );
- assertEquals( "barotfoo" , buf.asString() );
-
- }
-
- @Test
- public void testBig1(){
- PoolOutputBuffer a = new PoolOutputBuffer();
- StringBuilder b = new StringBuilder();
- for ( String x : _data ){
- a.write( x.getBytes() );
- b.append( x );
- }
- assertEquals( a.asString() , b.toString() );
- }
-
- List _data = new ArrayList();
-
- public static void main( String args[] ){
- (new PoolOutputBufferTest()).runConsole();
- }
-
-}
diff --git a/src/test/org/bson/util/ClassMapTest.java b/src/test/org/bson/util/ClassMapTest.java
deleted file mode 100644
index 23728256626..00000000000
--- a/src/test/org/bson/util/ClassMapTest.java
+++ /dev/null
@@ -1,54 +0,0 @@
-// ClassMapTest.java
-
-/**
- * Copyright (C) 2008 10gen Inc.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.bson.util;
-
-import java.io.Serializable;
-import org.testng.annotations.Test;
-
-public class ClassMapTest extends com.mongodb.util.TestCase {
-
- @org.testng.annotations.Test
- public void test(){
- // maps Classes to Strings
- ClassMap m = new ClassMap();
-
- m.put(Object.class, "Object");
- m.put(Boolean.class, "Boolean");
- assertEquals(m.get(Object.class), "Object");
- assertEquals(m.get(Boolean.class), "Boolean");
- assertEquals(m.get(Integer.class), "Object");
-
- m.put(String.class, "String");
- m.put(Serializable.class, "Serializable");
-
- assertEquals(m.get(String.class), "String");
- assertEquals(m.get(Integer.class), "Serializable");
-
- m.put(Number.class, "Number");
- assertEquals(m.get(Integer.class), "Number");
-
- m.put(Integer.class, "Integer");
- assertEquals(m.get(Integer.class), "Integer");
- }
-
- public static void main( String args[] ){
- ClassMapTest t = new ClassMapTest();
- t.runConsole();
- }
-}
diff --git a/test.sh b/test.sh
deleted file mode 100755
index e1eefdde1c6..00000000000
--- a/test.sh
+++ /dev/null
@@ -1,2 +0,0 @@
-
-ant && javac -cp build/main foo.java && java -cp build/main:build/test:. -Xmx256m $1Test
diff --git a/testng.xml b/testng.xml
deleted file mode 100644
index 16edbce4146..00000000000
--- a/testng.xml
+++ /dev/null
@@ -1,40 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-