Package org.bson

Examples of org.bson.BSONObject


    @Test
    public void testInsertBsonInputStream() {
        assertEquals(0, testCollection.count());
       
        DefaultDBEncoder encoder = new DefaultDBEncoder();
        BSONObject bsonObject = new BasicDBObject();
        bsonObject.put("_id", "testInsertBsonString");
       
        Object result = template.requestBody("direct:insertJsonString", new ByteArrayInputStream(encoder.encode(bsonObject)));
        assertTrue(result instanceof WriteResult);
        DBObject b = testCollection.findOne("testInsertBsonString");
        assertNotNull("No record with 'testInsertBsonString' _id", b);
View Full Code Here


    @Test
    public void testInsertBsonInputStream() {
        assertEquals(0, testCollection.count());
       
        DefaultDBEncoder encoder = new DefaultDBEncoder();
        BSONObject bsonObject = new BasicDBObject();
        bsonObject.put("_id", "testInsertBsonString");
       
        Object result = template.requestBody("direct:insertJsonString", new ByteArrayInputStream(encoder.encode(bsonObject)));
        assertTrue(result instanceof WriteResult);
        DBObject b = testCollection.findOne("testInsertBsonString");
        assertNotNull("No record with 'testInsertBsonString' _id", b);
View Full Code Here

    Assert.assertEquals(1, response.getNumberReturned());
   
    client.update(new Update("test", "update", new BasicBSONObject("_id", "updateId"), new BasicBSONObject("_id", "updateId").append("name", "testname updated")));
    response = client.query(new Query("test", "update", 0, 1, new BasicBSONObject("_id", "updateId"), null));
    Assert.assertEquals(1, response.getNumberReturned());
    BSONObject result = response.getDocuments().get(0);
   
    Assert.assertEquals("updateId", result.get("_id"));
    Assert.assertEquals("testname updated", result.get("name"));
   
  }
View Full Code Here

    Assert.assertNotNull(response);
    Assert.assertEquals(1, response.getNumberReturned());
    Assert.assertEquals(0, response.getStartingFrom());
    Assert.assertEquals(query.getWaitingRequestId(), response.getHeader().getResponseTo());
   
    BSONObject resultObject = response.getDocuments().get(0);
    Assert.assertEquals("updateId", resultObject.get("_id"));
    Assert.assertEquals("test-name", resultObject.get("name"));
    Assert.assertEquals(100, resultObject.get("num"));
   
  }
View Full Code Here

    }
    @Override
    public void run() {
      for (int i = 0; i < 1000; i++) {
        int key = id * 1000 + i;
        BSONObject obj = new BasicBSONObject("_id", key)
        .append("name","name-" + key)
        .append("value", "value-" + key);
        collection.insert(obj);
        int inserted = 0;
        if ((inserted = counter.incrementAndGet()) % 2000 == 0) {
          log.info("Inserted " + inserted + " records");
        }
        BSONObject saved = collection.find(new BasicBSONObject("_id", key));
        Assert.assertNotNull(saved);
        Assert.assertEquals(obj, saved);
      }
    }
View Full Code Here

    }
    @Override
    public void run() {
      for (int i = 0; i < 1000; i++) {
        int key = id * 1000 + i;
        BSONObject obj = new BasicBSONObject("$set",new BasicBSONObject("name", "updated-name-" + key));
        collection.update(new BasicBSONObject("_id", key), obj);
        int updated = 0;
        if ((updated = counter.incrementAndGet()) % 2000 == 0) {
          log.info("Updated " + updated + " records");
        }
        BSONObject saved = collection.find(new BasicBSONObject("_id", key));
        Assert.assertNotNull(saved);
        Assert.assertEquals(key, saved.get("_id"));
        Assert.assertEquals("updated-name-" + key, saved.get("name"));
        Assert.assertEquals("value-" + key, saved.get("value"));
      }
    }
View Full Code Here

    Assert.assertNotNull(response);
    Assert.assertEquals(1, response.getNumberReturned());
    Assert.assertEquals(0, response.getStartingFrom());
    Assert.assertEquals(query.getWaitingRequestId(), response.getHeader().getResponseTo());
   
    BSONObject resultObject = response.getDocuments().get(0);
    Assert.assertEquals(1, resultObject.get("_id"));
    Assert.assertEquals("test-name", resultObject.get("name"));
    Assert.assertEquals(100, resultObject.get("integer"));
    Assert.assertEquals(1000L, resultObject.get("long"));
    Assert.assertArrayEquals("test binary".getBytes(), (byte[]) resultObject.get("binary"));
   
    // Duplicate error
    MongoException me = null;
    try {
      client.insert(
View Full Code Here

   
    collection.remove(new BasicBSONObject());
    Assert.assertEquals(0, collection.count());
   
    for (int i = 0; i < 100; i++) {
      BSONObject doc = new BasicBSONObject()
      .append("_id", i)
      .append("name", "name-" + i)
      .append("value", "value-" + i);
      collection.insert(doc);
    }
View Full Code Here

    MongoCollection collection = client.getCollection("test", "client");
    collection.remove(new BasicBSONObject());
    Assert.assertEquals(0, collection.count());
   
    for (int i = 0; i < 100; i++) {
      BSONObject doc = new BasicBSONObject()
      .append("_id", i)
      .append("name", "name-" + i)
      .append("value", "value-" + i);
      collection.insert(doc);
    }
View Full Code Here

    MongoCollection collection = client.getCollection("test", "client");
    collection.remove(new BasicBSONObject());
    Assert.assertEquals(0, collection.count());
   
    for (int i = 0; i < 100; i++) {
      BSONObject doc = new BasicBSONObject()
      .append("_id", i)
      .append("name", "name-" + i)
      .append("value", "value-" + i);
      collection.insert(doc);
    }
View Full Code Here

TOP

Related Classes of org.bson.BSONObject

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.