
package org.usergrid.mongo;

import java.net.UnknownHostException;
import java.util.Properties;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.usergrid.persistence.cassandra.EntityManagerFactoryImpl;
import org.usergrid.services.ServiceManagerFactory;

import com.mongodb.DB;
import com.mongodb.Mongo;
import com.mongodb.MongoException;
import com.mongodb.WriteConcern;

public abstract class AbstractMongoTest
{
	private static Logger LOG = LoggerFactory.getLogger(AbstractMongoTest.class);

	static MongoServer server = null;
	static boolean usersSetup = false;
	protected static Properties properties;

	protected static String access_token;

	EntityManagerFactoryImpl emf;
	ServiceManagerFactory smf;


    public AbstractMongoTest()
    {
		super();
		smf = new ServiceManagerFactory(emf, properties, null, null, null);
	}


	/**
	 * Get a db instance for testing
	 * @return
	 * @throws UnknownHostException
	 * @throws MongoException
	 */
	public static DB getDb() throws UnknownHostException, MongoException
    {
	    Mongo m = new Mongo("localhost", 27017);
        m.setWriteConcern(WriteConcern.SAFE);

        DB db = m.getDB("test-organization/test-app");
        db.authenticate("test", "test".toCharArray());
        return db;
	}
}
