Package org.bson.types

Examples of org.bson.types.Code


        assert (pat.flags() == (pat2.flags()));
        ObjectId oid = (ObjectId) a.get("oid");
        assert (oid.equals(new ObjectId("4d83ab3ea39562db9c1ae2ae")));
        DBRef ref = (DBRef) a.get("ref");
        assert (ref.equals(new DBRef(null, "test.test", new ObjectId("4d83ab59a39562db9c1ae2af"))));
        assert (a.get("code").equals(new Code("asdfdsa")));
        assert (a.get("codews").equals(new CodeWScope("ggggg", new BasicBSONObject())));
        assert (a.get("ts").equals(new BSONTimestamp(1300474885, 10)));
        assert (a.get("uuid").equals(UUID.fromString("60f65152-6d4a-4f11-9c9b-590b575da7b5")));
        String json2 = JSON.serialize(a);
        BasicDBObject b = (BasicDBObject) JSON.parse(json2);
View Full Code Here


        buf = new StringBuilder();
        serializer.serialize(testObj, buf);
        assertEquals(buf.toString(), "{ \"byte_array\" : <Binary Data>}");
       
        // test  CODE
        testObj = new BasicDBObject("code", new Code("test code"));
        buf = new StringBuilder();
        serializer.serialize(testObj, buf);
        assertEquals(buf.toString(), "{ \"code\" : { \"$code\" : \"test code\"}}");
       
        // test  CODE_W_SCOPE
View Full Code Here

            super(serializer);
        }

        @Override
        public void serialize(Object obj, StringBuilder buf) {
            Code c = (Code) obj;
            BasicDBObject temp = new BasicDBObject();
            temp.put("$code", c.getCode());
            serializer.serialize(temp, buf);
        }
View Full Code Here

            o = new BSONTimestamp(ts, inc);
        } else if (b.containsField("$code")) {
            if (b.containsField("$scope")) {
                o = new CodeWScope((String) b.get("$code"), (DBObject) b.get("$scope"));
            } else {
                o = new Code((String) b.get("$code"));
            }
        } else if (b.containsField("$ref")) {
            o = new DBRef(null, (String) b.get("$ref"), b.get("$id"));
        } else if (b.containsField("$minKey")) {
            o = new MinKey();
View Full Code Here

        assertEquals(object.getInc(), object2.getInc());
    }

    @Test
    public void testSerializeCode() throws Exception {
        Code object = new Code("function() {}");

        ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
        ObjectOutputStream objectOutputStream = new ObjectOutputStream(outputStream);

        objectOutputStream.writeObject(object);

        ByteArrayInputStream inputStream = new ByteArrayInputStream(outputStream.toByteArray());
        ObjectInputStream objectInputStream = new ObjectInputStream(inputStream);
        Code object2 = (Code) objectInputStream.readObject();

        assertEquals(object.getCode(), object2.getCode());
    }
View Full Code Here

   * Tests if {@code JavaScript} objects can be deserialized
   * @throws Exception if something goes wrong
   */
  @Test
  public void javascript() throws Exception {
    Code code = new Code("code");
    TC.J obj = generateAndParse(code, TC.J.class);
    assertEquals(code.getCode(), obj.obj.getCode());
   
    CodeWScope codews = new CodeWScope("code", new BasicBSONObject("key", "value"));
    obj = generateAndParse(codews, TC.J.class);
    assertEquals(code.getCode(), obj.obj.getCode());
    assertEquals(codews.getScope().toMap(), obj.obj.getScope());
  }
View Full Code Here

    BSONObject scope = new BasicBSONObject();
    scope.put("Int32", 5);
   
    BSONObject o = new BasicBSONObject();
    o.put("Code1", new CodeWScope("alert('test');", scope));
    o.put("Code2", new Code("alert('Hello');"));
   
    Map<?, ?> data = parseBsonObject(o);
    assertEquals(2, data.size());
    JavaScript c1 = (JavaScript)data.get("Code1");
    JavaScript c2 = (JavaScript)data.get("Code2");
View Full Code Here

   * @throws Exception if something goes wrong
   */
  @Test
  public void javascript() throws Exception {
    JavaScript js = new JavaScript("code");
    Code code = (Code)generateAndParse(js);
    assertEquals(js.getCode(), code.getCode());
  }
View Full Code Here

    Map<String, Object> data = new LinkedHashMap<String, Object>();
    data.put("javaScript", javaScript);

    BSONObject obj = generateAndParse(data);

    Code result = (Code) obj.get("javaScript");
    assertNotNull(result);
    assertEquals(javaScript.getCode(), result.getCode());
  }
View Full Code Here

    lock = new Object();
    DBCollection systemJs = dao.getDB().getCollection("system.js");
    systemJs.remove(new BasicDBObject("_id", "mongoSessionClean"));
    systemJs.insert(new BasicDBObject("_id", "mongoSessionClean").append(
        "value",
        new Code(Files.read(Files.findFile("org/nutz/mongo/session/mongoSessionClean.js")))));
    cleaner = new Thread("MongoSessionCleaner") {
      public void run() {
        while (!stop) {
          try {
            context.getMongoDao().getDB().eval("mongoSessionClean()");
View Full Code Here

TOP

Related Classes of org.bson.types.Code

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.