incubator-isis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From danhayw...@apache.org
Subject svn commit: r1042630 - in /incubator/isis/trunk/alternatives/objectstore/nosql/src/test/java/org/apache/isis/alternatives/objectstore/nosql/mongo: MongoStateReaderTest.java MongoStateWriterTest.java
Date Mon, 06 Dec 2010 13:24:52 GMT
Author: danhaywood
Date: Mon Dec  6 13:24:52 2010
New Revision: 1042630

URL: http://svn.apache.org/viewvc?rev=1042630&view=rev
Log:
ensuring that Mongo tests still pass if there is no Mongo database to connect to.  (Perhaps
these should be moved to a separate suite?)

Modified:
    incubator/isis/trunk/alternatives/objectstore/nosql/src/test/java/org/apache/isis/alternatives/objectstore/nosql/mongo/MongoStateReaderTest.java
    incubator/isis/trunk/alternatives/objectstore/nosql/src/test/java/org/apache/isis/alternatives/objectstore/nosql/mongo/MongoStateWriterTest.java

Modified: incubator/isis/trunk/alternatives/objectstore/nosql/src/test/java/org/apache/isis/alternatives/objectstore/nosql/mongo/MongoStateReaderTest.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/alternatives/objectstore/nosql/src/test/java/org/apache/isis/alternatives/objectstore/nosql/mongo/MongoStateReaderTest.java?rev=1042630&r1=1042629&r2=1042630&view=diff
==============================================================================
--- incubator/isis/trunk/alternatives/objectstore/nosql/src/test/java/org/apache/isis/alternatives/objectstore/nosql/mongo/MongoStateReaderTest.java
(original)
+++ incubator/isis/trunk/alternatives/objectstore/nosql/src/test/java/org/apache/isis/alternatives/objectstore/nosql/mongo/MongoStateReaderTest.java
Mon Dec  6 13:24:52 2010
@@ -17,10 +17,14 @@
  *  under the License.
  */
 
-
 package org.apache.isis.alternatives.objectstore.nosql.mongo;
 
-import org.apache.isis.alternatives.objectstore.nosql.mongo.MongoStateReader;
+import static org.hamcrest.Matchers.is;
+import static org.hamcrest.Matchers.not;
+import static org.hamcrest.Matchers.nullValue;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assume.assumeThat;
+
 import org.apache.log4j.Level;
 import org.apache.log4j.Logger;
 import org.junit.Before;
@@ -31,9 +35,6 @@ import com.mongodb.DB;
 import com.mongodb.DBCollection;
 import com.mongodb.Mongo;
 
-import static org.junit.Assert.assertEquals;
-
-
 public class MongoStateReaderTest {
 
     private static final String SPEC_NAME = "org.test.Object";
@@ -45,9 +46,15 @@ public class MongoStateReaderTest {
         Logger.getRootLogger().setLevel(Level.OFF);
 
         Mongo m = new Mongo();
-        m.dropDatabase("mydb");
+        try {
+            m.dropDatabase("mydb");
+        } catch (Exception e) {
+            assumeThat(true, is(false));// ie ignore test because we've had an exception
+            return;
+        }
+
         testDb = m.getDB("mydb");
-        
+
         BasicDBObject object = new BasicDBObject();
         object.put("_id", "1023");
         object.put("_type", "org.xxx.Class");
@@ -64,48 +71,47 @@ public class MongoStateReaderTest {
 
     @Test
     public void readNonexistantFieldAsNull() throws Exception {
+        assumeThat(reader, is(not(nullValue())));
         assertEquals(null, reader.readField("unknown"));
     }
-    
+
     @Test
     public void readStringField() throws Exception {
         assertEquals("Fred Smith", reader.readField("name"));
     }
-    
+
     @Test
     public void readStringFieldAsNull() throws Exception {
         assertEquals(null, reader.readField("null name"));
     }
-    
+
     @Test
     public void readNullFieldAsNull() throws Exception {
         assertEquals(null, reader.readField("null name 2"));
     }
-    
+
     @Test
     public void readType() throws Exception {
         assertEquals("org.xxx.Class", reader.readObjectType());
     }
-    
+
     @Test
     public void readNumberField() throws Exception {
         assertEquals(102L, reader.readLongField("number"));
     }
-    
+
     @Test
     public void readNumberFieldAsNull() throws Exception {
         assertEquals(0L, reader.readLongField("null number"));
     }
-    
+
     @Test
     public void readNonexistingNumberFieldAsZero() throws Exception {
         assertEquals(0L, reader.readLongField("unknown"));
     }
-    
+
     @Test
     public void readId() throws Exception {
         assertEquals("1023", reader.readId());
     }
 }
-
-

Modified: incubator/isis/trunk/alternatives/objectstore/nosql/src/test/java/org/apache/isis/alternatives/objectstore/nosql/mongo/MongoStateWriterTest.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/alternatives/objectstore/nosql/src/test/java/org/apache/isis/alternatives/objectstore/nosql/mongo/MongoStateWriterTest.java?rev=1042630&r1=1042629&r2=1042630&view=diff
==============================================================================
--- incubator/isis/trunk/alternatives/objectstore/nosql/src/test/java/org/apache/isis/alternatives/objectstore/nosql/mongo/MongoStateWriterTest.java
(original)
+++ incubator/isis/trunk/alternatives/objectstore/nosql/src/test/java/org/apache/isis/alternatives/objectstore/nosql/mongo/MongoStateWriterTest.java
Mon Dec  6 13:24:52 2010
@@ -17,10 +17,13 @@
  *  under the License.
  */
 
-
 package org.apache.isis.alternatives.objectstore.nosql.mongo;
 
-import org.apache.isis.alternatives.objectstore.nosql.mongo.MongoStateWriter;
+import static org.hamcrest.Matchers.is;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assume.assumeThat;
+
 import org.apache.log4j.Level;
 import org.apache.log4j.Logger;
 import org.junit.Before;
@@ -31,10 +34,6 @@ import com.mongodb.DBCollection;
 import com.mongodb.DBObject;
 import com.mongodb.Mongo;
 
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-
-
 public class MongoStateWriterTest {
 
     private static final String SPEC_NAME = "org.test.Object";
@@ -45,35 +44,41 @@ public class MongoStateWriterTest {
     public void setup() throws Exception {
         Logger.getRootLogger().setLevel(Level.OFF);
 
-        Mongo m = new Mongo();
-        m.dropDatabase("mydb");
-        testDb = m.getDB("mydb");
-        
+        try {
+
+            Mongo m = new Mongo();
+            m.dropDatabase("mydb");
+            testDb = m.getDB("mydb");
+        } catch (Exception e) {
+            assumeThat(true, is(false)); // ie no exceptions
+            return;
+        }
+
         writer = new MongoStateWriter(testDb, SPEC_NAME);
     }
-    
+
     @Test
     public void flushSavesObject() throws Exception {
         writer.flush();
-        
+
         DBCollection instances = testDb.getCollection(SPEC_NAME);
         assertEquals(1, instances.getCount());
     }
-    
+
     @Test
     public void objectNotSavedUntilFlush() throws Exception {
         writer.writeField("number", 1023);
         writer.writeField("string", "testing");
-        
+
         DBCollection instances = testDb.getCollection(SPEC_NAME);
         assertEquals(0, instances.getCount());
     }
-    
+
     @Test
     public void serialNumberNotStored() throws Exception {
         writer.writeId("D01");
         writer.flush();
-        
+
         DBCollection instances = testDb.getCollection(SPEC_NAME);
         assertEquals(1, instances.getCount());
         DBObject object = instances.findOne();
@@ -81,14 +86,14 @@ public class MongoStateWriterTest {
         assertEquals("D01", object.get("_id"));
         assertEquals(1, object.keySet().size());
     }
-    
+
     @Test
     public void writeFields() throws Exception {
         writer.writeType(SPEC_NAME);
         writer.writeField("number", 1023);
         writer.writeField("string", "testing");
         writer.flush();
-        
+
         DBCollection instances = testDb.getCollection(SPEC_NAME);
         assertEquals(1, instances.getCount());
         DBObject object = instances.findOne();
@@ -97,7 +102,6 @@ public class MongoStateWriterTest {
         assertEquals("testing", object.get("string"));
     }
 
-    
     @Test
     public void writeFields2() throws Exception {
         writer.writeId("3");
@@ -117,5 +121,3 @@ public class MongoStateWriterTest {
     }
 
 }
-
-



Mime
View raw message