package org.lumongo.util;

import java.net.UnknownHostException;

import com.mongodb.MongoClient;
import com.mongodb.MongoException;

public class TestHelper {
	public static final String MONGO_SERVER_PROPERTY = "mongoServer";
	public static final String MONGO_PORT_PROPERTY = "mongoPort";
	public static final String TEST_DATABASE_NAME = "lumongoUnitTest";

	public static String getMongoServer() {
		String mongoServer = System.getProperty(MONGO_SERVER_PROPERTY);
		if (mongoServer == null) {
			throw new IllegalArgumentException(MONGO_SERVER_PROPERTY + " must be defined");
		}
		return mongoServer;
	}

	public static int getMongoPort() {
		String portStr = System.getProperty(MONGO_PORT_PROPERTY);
		if (portStr == null) {
			throw new IllegalArgumentException(MONGO_PORT_PROPERTY + " must be defined");
		}
		return Integer.parseInt(portStr);
	}

	public static MongoClient getMongo() throws UnknownHostException, MongoException {
		return new MongoClient(getMongoServer(), getMongoPort());
	}
}

@@ -351,17 +351,155 @@
 tTest%22;%0A
+%09%0A%09public static final String MONGO_SERVER_PROPERTY_DEFAULT = %22127.0.0.1%22;%0A%09public static final int MONGO_PORT_PROPERTY_DEFAULT = 27017;%0A%09
 %0A
-
 %09public 
@@ -633,86 +633,44 @@
 %0A%09%09%09
-throw new IllegalArgumentException(MONGO_SERVER_PROPERTY + %22 must be defined%22)
+return MONGO_SERVER_PROPERTY_DEFAULT
 ;%0A%09%09
@@ -692,25 +692,26 @@
 oServer;%0A%09%7D%0A
+%09
 %0A
-
 %09public stat
@@ -826,84 +826,42 @@
 %0A%09%09%09
-throw new IllegalArgumentException(MONGO_PORT_PROPERTY + %22 must be defined%22)
+return MONGO_PORT_PROPERTY_DEFAULT
 ;%0A%09%09
@@ -901,16 +901,17 @@
 tr);%0A%09%7D%0A
+%09
 %0A%09public

make tests default to localhost and 27017