@Test public void testLessThanEqPositive() throws Exception { MockObject mockObject = insertMockObject(); DBCursor<MockObject> cursor = coll.find().lessThanEquals("integer", 10); assertThat(cursor.hasNext(), equalTo(true)); assertThat(cursor.next(), equalTo(mockObject)); }
@Test public void testInCollectionPositive() throws Exception { MockObject mockObject = insertMockObject(); DBCursor<MockObject> cursor = coll.find().in("integer", Arrays.asList(9, 10, 11)); assertThat(cursor.hasNext(), equalTo(true)); assertThat(cursor.next(), equalTo(mockObject)); }
@Test public void testGreaterThanPositive() throws Exception { MockObject mockObject = insertMockObject(); DBCursor<MockObject> cursor = coll.find().greaterThan("integer", 9); assertThat(cursor.hasNext(), equalTo(true)); assertThat(cursor.next(), equalTo(mockObject)); }
@Test public void testSerializationFromInFind() throws Exception { MockObject mockObject = insertMockObjectWithEmbedded(); DBCursor<MockObject> cursor = coll.find(DBQuery.in("object", mockObject.object)); assertThat(cursor.hasNext(), equalTo(true)); assertThat(cursor.next(), equalTo(mockObject)); }
@Test(expected = MongoException.class) public void testQueryAfterExecution() throws Exception { insertMockObject(); DBCursor<MockObject> cursor = coll.find(); cursor.hasNext(); cursor.in("blah", "blah"); }
@Test public void testWherePositive() throws Exception { MockObject mockObject = insertMockObject(); DBCursor<MockObject> cursor = coll.find().where("this.integer > 9"); assertThat(cursor.hasNext(), equalTo(true)); assertThat(cursor.next(), equalTo(mockObject)); }
@Test public void testNotExistsPositive() throws Exception { MockObject mockObject = insertMockObject(); DBCursor<MockObject> cursor = coll.find().notExists("integerfun"); assertThat(cursor.hasNext(), equalTo(true)); assertThat(cursor.next(), equalTo(mockObject)); }
@Test public void testRegexPositive() throws Exception { MockObject mockObject = insertMockObject(); DBCursor<MockObject> cursor = coll.find().regex("string", Pattern.compile("h.llo")); assertThat(cursor.hasNext(), equalTo(true)); assertThat(cursor.next(), equalTo(mockObject)); }
@Test public void testOrNegative() throws Exception { insertMockObject(); DBCursor<MockObject> cursor = coll.find().or(DBQuery.is("integer", 9), DBQuery.lessThan("integer", 9)); assertThat(cursor.hasNext(), equalTo(false)); }
@Test public void testAllPositive() throws Exception { MockObject mockObject = insertMockObject(); DBCursor<MockObject> cursor = coll.find().all("simpleList", "a", "b"); assertThat(cursor.hasNext(), equalTo(true)); assertThat(cursor.next(), equalTo(mockObject)); }
@Test public void testElemMatchNegative() throws Exception { insertMockObjectWithComplexList(); DBCursor<MockObject> cursor = coll.find().elemMatch("complexList", DBQuery.in("value", "foo", "la").size("list", 2)); assertThat(cursor.hasNext(), equalTo(false)); }
@Test public void testNorNegative() throws Exception { insertMockObject(); DBCursor<MockObject> cursor = coll.find() .and( DBQuery.lessThan("integer", 9), DBQuery.is("string", "hello"), DBQuery.greaterThan("integer", 11)); assertThat(cursor.hasNext(), equalTo(false)); }
@Test public void testGreaterThanEqNegative() throws Exception { insertMockObject(); DBCursor<MockObject> cursor = coll.find().greaterThanEquals("integer", 11); assertThat(cursor.hasNext(), equalTo(false)); }
@Test public void testWhereNegative() throws Exception { insertMockObject(); DBCursor<MockObject> cursor = coll.find().where("this.integer < 9"); assertThat(cursor.hasNext(), equalTo(false)); }
@Test public void testSizeNegative() throws Exception { insertMockObject(); DBCursor<MockObject> cursor = coll.find().size("simpleList", 4); assertThat(cursor.hasNext(), equalTo(false)); }
@Test public void testRegexNegative() throws Exception { insertMockObject(); DBCursor<MockObject> cursor = coll.find().regex("string", Pattern.compile("hllo")); assertThat(cursor.hasNext(), equalTo(false)); }
@Test public void testLessThanNegative() throws Exception { insertMockObject(); DBCursor<MockObject> cursor = coll.find().lessThan("integer", 10); assertThat(cursor.hasNext(), equalTo(false)); }
@Test public void testAllNegative() throws Exception { insertMockObject(); DBCursor<MockObject> cursor = coll.find().all("simpleList", "a", "banana", "b"); assertThat(cursor.hasNext(), equalTo(false)); }
@Test public void testNotExistsNegative() throws Exception { insertMockObject(); DBCursor<MockObject> cursor = coll.find().notExists("integer"); assertThat(cursor.hasNext(), equalTo(false)); }