@Override public void tearDown() throws Exception { mongo.dropDatabase( dbName ); super.tearDown(); } }
@Override public void tearDown() throws Exception { mongo.dropDatabase( dbName ); super.tearDown(); } }
@Override public void tearDown() throws Exception { mongo.dropDatabase( dbName ); super.tearDown(); } }
@Override public void close() { if (mongoDbName == null) { return; } try { Mongo mongo = new Mongo("127.0.0.1", mongoDbPort); DB db = mongo.getDB(mongoDbName); db.resetError(); db.dropDatabase(); DBObject err = db.getLastError(); if (err != null && err.get("err") != null) { logger.error("Could not drop database {}: {}", mongoDbName, err); } mongo.dropDatabase(mongoDbName); if (mongo.getDatabaseNames().contains(mongoDbName)) { logger.error("Database {} will not go away!", mongoDbName); } } catch (UnknownHostException e) { // weird } catch (MongoException e) { logger.warn("Could not drop database {}: {}", mongoDbName, e.getMessage()); } }
@Before public void setup() { Mongo mongo = getDataSource().getMongoInstance(); mongo.dropDatabase(db); }
mongo.dropDatabase(repositoryName); } catch (MongoException e) { throw new MongoOperationException(e);
@Test public void testWrapperUpdate() { MongoDataSource ds = getDataSource(); Mongo mongo = ds.getMongoInstance(); mongo.dropDatabase(DB); DBCollection coll = mongo.getDB(DB).getCollection(COLL); coll.setWriteConcern(WriteConcern.SAFE); BasicDBObject o1 = new BasicDBObject().append("name", "value"); coll.insert(o1); BasicDBObject o2 = new BasicDBObject().append("name", "newValue"); BasicDBObject update = new BasicDBObject().append("$set", o2); Assert.assertTrue(MongoUtils.wrapperUpdate(coll, o1, update)); Assert.assertEquals(1, coll.count(o2)); Assert.assertFalse(MongoUtils.wrapperUpdate(coll, o1, update)); } }
@Test public void testEnsureIndex() { MongoDataSource ds = getDataSource(); Mongo mongo = ds.getMongoInstance(); mongo.dropDatabase(DB); DBCollection coll = mongo.getDB(DB).getCollection(COLL); MongoUtils.ensureIndex(coll, "fieldName", false, false); MongoUtils.ensureIndex(coll, "fieldName", true, false); MongoUtils.ensureIndex(coll, "fieldName", true, true); MongoUtils.ensureIndex(coll, "fieldName", false, true); }
@Test public void dbNameWithSpace() throws Exception { // check initial creation assertThat(mongoClient.getDatabaseNames().contains("foo bar")).isFalse(); assertThat(mongoClient.getDatabaseNames().contains("foo%20bar")).isFalse(); ResourceState config = new DefaultResourceState(); config.putProperty("db", "foo bar"); setUpSystem(config); // check via reading from LiveOak ResourceState result = client.read(new RequestContext.Builder().build(), ADMIN_PATH); assertThat(result.getProperty("db")).isEqualTo("foo bar"); // we need to write something to the database, otherwise its not created in the database server client.create(new RequestContext.Builder().build(), "/testApp/storage/", new DefaultResourceState()); // check via what is in mongo assertThat(mongoClient.getDatabaseNames().contains("foo%20bar")).isTrue(); assertThat(mongoClient.getDatabaseNames().contains("foo bar")).isFalse(); mongoClient.dropDatabase("foo%20bar"); // check on update result.putProperty("db", "hello <world>"); ResourceState updatedResult = client.update(new RequestContext.Builder().build(), ADMIN_PATH, result); assertThat(updatedResult.getProperty("db")).isEqualTo("hello <world>"); // check what is in mongo assertThat(mongoClient.getDatabaseNames().contains("hello%20%3Cworld%3E")).isTrue(); assertThat(mongoClient.getDatabaseNames().contains("foo <world>")).isFalse(); mongoClient.dropDatabase("hello%20%3Cworld%3E"); }