Exemple #1
0
  @Test
  public void shouldKeepParametersCase() {
    Person p = Person.create("name", "Joe", "last_name", "Schmoe");

    Map map = JsonHelper.toMap(p.toJson(true));
    a(map.get("name")).shouldBeEqual("Joe");
    a(map.get("last_name")).shouldBeEqual("Schmoe");

    map = JsonHelper.toMap(p.toJson(true, "Name", "Last_Name"));
    a(map.get("Name")).shouldBeEqual("Joe");
    a(map.get("Last_Name")).shouldBeEqual("Schmoe");
  }
Exemple #2
0
  @Test
  public void shouldGenerateSimpleJson() {
    deleteAndPopulateTable("people");
    Person p = Person.findFirst("name = ? and last_name = ? ", "John", "Smith");
    // test no indent
    String json = p.toJson(false, "name", "last_name", "dob");
    Map map = JsonHelper.toMap(json);

    a(map.get("name")).shouldBeEqual("John");
    a(map.get("last_name")).shouldBeEqual("Smith");
    a(map.get("dob")).shouldBeEqual("1934-12-01");
  }
Exemple #3
0
  @Test
  public void shouldReturnSecondsInDateTime() throws ParseException {
    Person p = new Person();
    p.set("name", "john", "last_name", "doe").saveIt();
    p.refresh();
    String json = p.toJson(true);

    System.out.println(json);
    @SuppressWarnings("unchecked")
    Map<String, String> map = JsonHelper.toMap(json);

    Date d = new ISO8601DateFormat().parse(map.get("created_at"));
    // difference between date in Json and in original model instance should be less than 1000
    // milliseconds
    a(Math.abs(d.getTime() - p.getTimestamp("created_at").getTime()) < 1000L).shouldBeTrue();
  }