package com.google.code.morphia;


import org.junit.After;
import org.junit.Before;
import com.google.code.morphia.mapping.MappedClass;
import com.mongodb.DB;
import com.mongodb.Mongo;
import com.mongodb.MongoClient;


public abstract class TestBase {
  protected Mongo             mongo;
  protected DB                db;
  protected Datastore         ds;
  protected AdvancedDatastore ads;
  protected final Morphia morphia = new Morphia();

  protected TestBase() {
    try {
      mongo = new MongoClient();
    } catch (Exception e) {
      throw new RuntimeException(e);
    }
  }

  @Before
  public void setUp() {
    db = mongo.getDB("morphia_test");
    ds = morphia.createDatastore(mongo, db.getName());
    ads = (AdvancedDatastore) ds;
    //ads.setDecoderFact(LazyDBDecoder.FACTORY);
  }

  protected void cleanup() {
    //this.mongo.dropDatabase("morphia_test");
    for (final MappedClass mc : morphia.getMapper().getMappedClasses())
    //			if( mc.getEntityAnnotation() != null )
    {
      db.getCollection(mc.getCollectionName()).drop();
    }

  }

  @After
  public void tearDown() {
    cleanup();
    mongo.close();
  }
}

@@ -210,16 +210,51 @@
 Client;%0A
+import com.mongodb.MongoClientURI;%0A
 %0A%0Apublic
@@ -298,28 +298,16 @@
 d Mongo 
-            
 mongo;%0A 
@@ -320,31 +320,16 @@
 cted DB 
-               
 db;%0A  pr
@@ -346,24 +346,16 @@
 tastore 
-        
 ds;%0A  pr
@@ -502,16 +502,96 @@
 oClient(
+new MongoClientURI(System.getProperty(%22MONGO_URI%22, %22mongodb://localhost:27017%22))
 );%0A    %7D
@@ -828,135 +828,39 @@
 ;%0A  
-  //ads.setDecoderFact(LazyDBDecoder.FACTORY);%0A  %7D%0A%0A  protected void cleanup() %7B%0A    //this.mongo.dropDatabase(%22morphia_test%22);
+%7D%0A%0A  protected void cleanup() %7B
 %0A   
@@ -931,60 +931,8 @@
 s())
-%0A    //%09%09%09if( mc.getEntityAnnotation() != null )%0A   
  %7B%0A 

support MONGO_URI properties for jenkins testing