Package de.undercouch.bson4jackson.types

Examples of de.undercouch.bson4jackson.types.JavaScript


    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");
    assertEquals("alert('test');", c1.getCode());
    assertEquals("alert('Hello');", c2.getCode());
    Map<String, Object> c1scope = c1.getScope();
    assertEquals(5, c1scope.get("Int32"));
  }
View Full Code Here


        case BsonConstants.TYPE_DBPOINTER:
          _currToken = handleDBPointer();
          break;
         
        case BsonConstants.TYPE_JAVASCRIPT:
          ctx.value = new JavaScript(readString());
          _currToken = JsonToken.VALUE_EMBEDDED_OBJECT;
          break;
         
        case BsonConstants.TYPE_SYMBOL:
          ctx.value = readSymbol();
View Full Code Here

  protected JsonToken handleJavascriptWithScope() throws IOException {
    //skip size
    _in.readInt();
    String code = readString();
    Map<String, Object> doc = readDocument();
    getContext().value = new JavaScript(code, doc);
    return JsonToken.VALUE_EMBEDDED_OBJECT;
  }
View Full Code Here

   * Tests {@link BsonJavaScriptSerializer}
   * @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

    assertEquals(timestamp.getTime(), result.getTime());
  }

  @Test
  public void javascript() throws Exception {
    JavaScript javaScript = new JavaScript("a < 100");
    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

  @Test
  public void javascriptWithScope() throws Exception {
    Map<String, Object> scope = new LinkedHashMap<String, Object>();
    scope.put("a", 99);
    scope.put("b", 80);
    JavaScript javaScript = new JavaScript("a < 100", scope);
    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

Related Classes of de.undercouch.bson4jackson.types.JavaScript

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.