package org.mongodb.morphia;


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


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

    protected TestBase() {
        try {
            mongo = new MongoClient(new MongoClientURI(System.getProperty("MONGO_URI", "mongodb://localhost:27017")));
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }

    @Before
    public void setUp() {
        setDb(getMongo().getDB("morphia_test"));
        setDs(getMorphia().createDatastore(getMongo(), getDb().getName()));
        setAds((AdvancedDatastore) getDs());
    }

    protected void cleanup() {
        for (final MappedClass mc : getMorphia().getMapper().getMappedClasses()) {
            getDb().getCollection(mc.getCollectionName()).drop();
        }

    }

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

    public AdvancedDatastore getAds() {
        return ads;
    }

    public DB getDb() {
        return db;
    }

    public Datastore getDs() {
        return ds;
    }

    public Mongo getMongo() {
        return mongo;
    }

    public Morphia getMorphia() {
        return morphia;
    }

    public void setDb(final DB db) {
        this.db = db;
    }

    public void setDs(final Datastore ds) {
        this.ds = ds;
    }

    public void setAds(final AdvancedDatastore ads) {
        this.ads = ads;
    }
}

@@ -164,16 +164,41 @@
 .After;%0A
+import org.junit.Assume;%0A
 import o
@@ -1211,32 +1211,555 @@
 close();%0A    %7D%0A%0A
+    /**%0A     * @param version  must be a major version, e.g. 1.8, 2,0, 2.2%0A     * @return true if server is at least specified version%0A     */%0A    protected boolean serverIsAtLeastVersion(double version) %7B%0A        String serverVersion = (String) getMongo().getDB(%22admin%22).command(%22serverStatus%22).get(%22version%22);%0A        return Double.parseDouble(serverVersion.substring(0, 3)) %3E= version;%0A    %7D%0A%0A    protected void checkServerVersion(double version) %7B%0A        Assume.assumeTrue(serverIsAtLeastVersion(version));%0A    %7D%0A    %0A
     public Advan

add server version check