Examples of CodeWScope


Examples of org.bson.types.CodeWScope

            super(serializer);
        }

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

Examples of org.bson.types.CodeWScope

            Integer ts = ((Number) tsObject.get("t")).intValue();
            Integer inc = ((Number) tsObject.get("i")).intValue();
            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"));
View Full Code Here

Examples of org.bson.types.CodeWScope

    @Test
    public void testCode()
      throws IOException{
        BSONObject scope = new BasicBSONObject( "x", 1 );
        CodeWScope c = new CodeWScope( "function() { x += 1; }" , scope );
        BSONObject code_object = new BasicBSONObject( "map" , c);
        _test( code_object , 53 , "52918d2367533165bfc617df50335cbb" );
    }
View Full Code Here

Examples of org.bson.types.CodeWScope

    }

    @Test
    public void testSerializeCodeWScope() throws Exception {
        BSONObject scope = new BasicBSONObject("t", 1);
        CodeWScope object = new CodeWScope("function() {}", scope);

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

        objectOutputStream.writeObject(object);

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

        assertEquals(object.getCode(), object2.getCode());
        assertEquals(object.getScope().get("t"), object2.getScope().get("t"));
    }
View Full Code Here

Examples of org.bson.types.CodeWScope

    @Test
    public void testWhereCodeWScopeQuery() throws Exception {
        getDs().save(new PhotoWithKeywords());
        //        CodeWScope hasKeyword = new CodeWScope("for (kw in this.keywords) { if(kw.keyword == kwd) return true; } return false;
        // ", new BasicDBObject("kwd","california"));
        final CodeWScope hasKeyword = new CodeWScope("this.keywords != null", new BasicDBObject());
        assertNotNull(getDs().find(PhotoWithKeywords.class).where(hasKeyword).get());
    }
View Full Code Here

Examples of org.bson.types.CodeWScope

    }

    @Test
    public void testWhereWithInvalidStringQuery() throws Exception {
        getDs().save(new PhotoWithKeywords());
        final CodeWScope hasKeyword = new CodeWScope("keywords != null", new BasicDBObject());
        try {
            // must fail
            assertNotNull(getDs().find(PhotoWithKeywords.class).where(hasKeyword.getCode()).get());
            Assert.fail("Invalid javascript magically isn't invalid anymore?");
        } catch (MongoInternalException e) {
            // fine
        } catch (MongoException e) {
            // fine
View Full Code Here

Examples of org.bson.types.CodeWScope

  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

Examples of org.bson.types.CodeWScope

  public void parseCode() throws Exception {
    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");
View Full Code Here

Examples of org.bson.types.CodeWScope

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

    BSONObject obj = generateAndParse(data);

    CodeWScope result = (CodeWScope) obj.get("javaScript");
    assertNotNull(result);
    assertEquals(javaScript.getCode(), result.getCode());
    Map<?, ?> returnedScope = result.getScope().toMap();
    assertEquals(returnedScope, scope);
  }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.