Author: jukka
Date: Wed Feb 19 14:57:15 2014
New Revision: 1569776

URL: http://svn.apache.org/r1569776
Log:
OAK-1434: Cleanup dependencies of oak-core

RandomizedTest needs a copy of MongoUtils

Added:
    
jackrabbit/oak/trunk/oak-it/mk/src/test/java/org/apache/jackrabbit/mk/test/MongoUtils.java
   (with props)
Modified:
    
jackrabbit/oak/trunk/oak-it/mk/src/test/java/org/apache/jackrabbit/mk/test/RandomizedTest.java

Added: 
jackrabbit/oak/trunk/oak-it/mk/src/test/java/org/apache/jackrabbit/mk/test/MongoUtils.java
URL: 
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-it/mk/src/test/java/org/apache/jackrabbit/mk/test/MongoUtils.java?rev=1569776&view=auto
==============================================================================
--- 
jackrabbit/oak/trunk/oak-it/mk/src/test/java/org/apache/jackrabbit/mk/test/MongoUtils.java
 (added)
+++ 
jackrabbit/oak/trunk/oak-it/mk/src/test/java/org/apache/jackrabbit/mk/test/MongoUtils.java
 Wed Feb 19 14:57:15 2014
@@ -0,0 +1,85 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jackrabbit.mk.test;
+
+import org.apache.jackrabbit.oak.plugins.document.util.MongoConnection;
+
+import com.mongodb.BasicDBObject;
+import com.mongodb.DB;
+
+/**
+ * A utility class to get a {@link MongoConnection} to a local mongo instance
+ * and clean a test database.
+ */
+class MongoUtils {
+
+    protected static final String HOST =
+            System.getProperty("mongo.host", "127.0.0.1");
+
+    protected static final int PORT =
+            Integer.getInteger("mongo.port", 27017);
+
+    protected static final String DB =
+            System.getProperty("mongo.db", "MongoMKDB");
+
+    protected static Exception exception;
+
+    /**
+     * Get a connection if available. If not available, null is returned.
+     * 
+     * @return the connection or null
+     */
+    public static MongoConnection getConnection() {
+        return getConnection(DB);
+    }
+    
+    /**
+     * Get a connection if available. If not available, null is returned.
+     * 
+     * @param dbName the database name
+     * @return the connection or null
+     */    
+    public static MongoConnection getConnection(String dbName) {
+        if (exception != null) {
+            return null;
+        }
+        MongoConnection mongoConnection = null;
+        try {
+            mongoConnection = new MongoConnection(HOST, PORT, dbName);
+            mongoConnection.getDB().command(new BasicDBObject("ping", 1));
+            // dropCollections(mongoConnection.getDB());
+        } catch (Exception e) {
+            exception = e;
+            mongoConnection = null;
+        }
+        return mongoConnection;
+    }
+    
+    /**
+     * Drop all user defined collections. System collections are not dropped.
+     * 
+     * @param db the connection
+     */
+    public static void dropCollections(DB db) {
+        for (String name : db.getCollectionNames()) {
+            if (!name.startsWith("system.")) {
+                db.getCollection(name).drop();
+            }
+        }
+    }
+
+}

Propchange: 
jackrabbit/oak/trunk/oak-it/mk/src/test/java/org/apache/jackrabbit/mk/test/MongoUtils.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: 
jackrabbit/oak/trunk/oak-it/mk/src/test/java/org/apache/jackrabbit/mk/test/RandomizedTest.java
URL: 
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-it/mk/src/test/java/org/apache/jackrabbit/mk/test/RandomizedTest.java?rev=1569776&r1=1569775&r2=1569776&view=diff
==============================================================================
--- 
jackrabbit/oak/trunk/oak-it/mk/src/test/java/org/apache/jackrabbit/mk/test/RandomizedTest.java
 (original)
+++ 
jackrabbit/oak/trunk/oak-it/mk/src/test/java/org/apache/jackrabbit/mk/test/RandomizedTest.java
 Wed Feb 19 14:57:15 2014
@@ -30,7 +30,6 @@ import org.apache.jackrabbit.mk.json.Jso
 import org.apache.jackrabbit.mk.json.JsopBuilder;
 import org.apache.jackrabbit.mk.json.JsopTokenizer;
 import org.apache.jackrabbit.oak.plugins.document.DocumentMK;
-import org.apache.jackrabbit.oak.plugins.document.MongoUtils;
 import org.junit.Test;
 
 import com.mongodb.DB;


Reply via email to