コード例 #1
0
 @Test
 public void shouldDecodeArrayOfStrings() throws JSONException {
   Child child = new Child("{ 'test1' : ['value1', 'value2', 'value3' ]}");
   assertThat(
       child.getJSONArray("test1").toString(),
       is(new JSONArray(Arrays.asList("value1", "value2", "value3")).toString()));
 }
コード例 #2
0
 @Test
 public void shouldGenerateWithIdAndOwnerAndContent() throws JSONException {
   Child child = new Child("id1", "owner1", "{ 'test1' : 'value1' }");
   assertThat(child.getUniqueId(), is("id1"));
   assertThat(child.getOwner(), is("owner1"));
   assertThat(child.getString("test1"), is("value1"));
 }
コード例 #3
0
  @Test
  public void shouldReturnShortID() throws JSONException {
    Child child = new Child();
    child.setUniqueId("987654321");

    assertThat(child.getShortId(), equalTo("7654321"));
  }
コード例 #4
0
 @Test
 public void shouldNotOverwriteCreatedAtIfGiven() throws JSONException {
   Child child =
       new Child(
           String.format(
               "{ 'created_at' :  '%s' }", new RapidFtrDateTime(10, 2, 2012).defaultFormat()));
   assertThat(child.getCreatedAt(), is("2012-02-10 00:00:00"));
 }
コード例 #5
0
  @Test
  public void shouldRemoveFieldIfBlank() throws JSONException {
    Child child = new Child();
    child.put("name", "test");
    assertThat(child.values().names().length(), equalTo(1));

    child.put("name", "\r  \n  \r  \n");
    assertNull(child.values().names());
  }
コード例 #6
0
  @Test
  public void shouldRemoveFieldIfJSONArrayIsEmtpy() throws JSONException {
    Child child = new Child();
    child.put("name", new JSONArray(Arrays.asList("one")));
    assertThat(child.values().names().length(), equalTo(1));

    child.put("name", new JSONArray());
    assertNull(child.values().names());
  }
コード例 #7
0
  @Test
  public void shouldGenerateUniqueId() throws JSONException {
    Child child = new Child(null, "rapidftr", null);
    child = spy(child);

    doReturn("xyz").when(child).createUniqueId();

    child.generateUniqueId();
    assertThat(child.getUniqueId(), equalTo("xyz"));
  }
コード例 #8
0
  @Test
  public void valuesShouldReturnAllExceptSystemFields() throws JSONException, IOException {
    Child child = new Child();
    child.put("test1", "value1");
    for (Database.ChildTableColumn column : Database.ChildTableColumn.systemFields()) {
      child.put(column.getColumnName(), "test");
    }

    assertThat(child.values(), equalJSONIgnoreOrder("{\"test1\":\"value1\"}"));
  }
コード例 #9
0
  @Test
  public void shouldRemoveFieldIfNull() throws JSONException {
    Child child = new Child();
    child.put("name", "test");

    assertEquals(child.get("name"), "test");

    Object value = null;
    child.put("name", value);
    assertNull(child.opt("name"));
  }
コード例 #10
0
  public void shouldReturnListOfChangeLogsBasedOnChanges() throws JSONException {
    Child oldChild = new Child("id", "user", "{'name' : 'old-name'}");
    Child updatedChild = new Child("id", "user", "{'name' : 'updated-name'}");
    List<Child.History> histories = updatedChild.changeLogs(oldChild);

    JSONObject changesMap = (JSONObject) histories.get(0).get(CHANGES);
    HashMap fromTo = (HashMap) changesMap.get("name");

    assertThat(histories.size(), is(1));
    assertThat(histories.get(0).get(USER_NAME).toString(), is(updatedChild.getOwner()));
    assertThat(changesMap.names().get(0).toString(), is("name"));
    assertThat(fromTo.get(FROM).toString(), is("old-name"));
    assertThat(fromTo.get(TO).toString(), is("updated-name"));
  }
コード例 #11
0
  @Test
  public void shouldReturnListOfChangeLogsForNewFieldValueToExistingChild() throws JSONException {
    Child oldChild = new Child("id", "user", "{'gender' : 'male', 'name' : 'old-name'}");
    Child updatedChild =
        new Child(
            "id", "user", "{'gender' : 'male','nationality' : 'Indian', 'name' : 'new-name'}");
    List<Child.History> histories = updatedChild.changeLogs(oldChild);

    JSONObject changesMap = (JSONObject) histories.get(0).get(CHANGES);
    JSONObject fromTo = (JSONObject) changesMap.get("nationality");

    assertThat(histories.size(), is(2));
    assertThat(changesMap.names().get(0).toString(), is("nationality"));
    assertThat(fromTo.get(FROM).toString(), is(""));
    assertThat(fromTo.get(TO).toString(), is("Indian"));

    changesMap = (JSONObject) histories.get(1).get(CHANGES);
    fromTo = (JSONObject) changesMap.get("name");

    assertThat(changesMap.names().get(0).toString(), is("name"));
    assertThat(fromTo.get(FROM).toString(), is("old-name"));
    assertThat(fromTo.get(TO).toString(), is("new-name"));
  }
コード例 #12
0
  @Test
  public void testAtLeastOneFieldIsFilledExcludingIdAndOwner() throws JSONException {
    Child child = new Child("id1", "owner1", null);
    assertThat(child.isValid(), is(false));

    child.put("test1", "value1");
    assertThat(child.isValid(), is(true));

    child.remove("test1");
    assertThat(child.isValid(), is(false));
  }
コード例 #13
0
 @Test
 public void shouldReturnNamesWithLengthOneInsteadOfNull() throws JSONException {
   Child child = new Child();
   assertThat(child.names().length(), equalTo(1));
 }
コード例 #14
0
 @Test
 public void shouldDecodeInteger() throws JSONException {
   Child child = new Child("{ 'test1' : 17 }");
   assertThat(child.getInt("test1"), is(17));
 }
コード例 #15
0
 @Test
 public void shouldDecodeString() throws JSONException {
   Child child = new Child("{ 'test1' :  'value1' }");
   assertThat(child.getString("test1"), is("value1"));
 }
コード例 #16
0
 @Test
 public void shouldDecodeOwnerFromJSON() throws JSONException {
   Child child = new Child("{ 'created_by' : 'test1' }");
   assertThat(child.getOwner(), is("test1"));
 }
コード例 #17
0
 @Test
 public void shouldDecodeIDFromJSON() throws JSONException {
   Child child = new Child("{ 'unique_identifier' : 'test1' }");
   assertThat(child.getUniqueId(), is("test1"));
 }
コード例 #18
0
 @Test
 public void shouldNotBeNewIfThereIsID() throws JSONException {
   Child child = new Child();
   child.put(internal_id.getColumnName(), "xyz");
   assertThat(child.isNew(), is(false));
 }
コード例 #19
0
 @Test
 public void shouldTrimFieldValues() throws JSONException {
   Child child = new Child();
   child.put("name", "\r\n line1 \r\n line2 \r\n \r\n");
   assertThat(child.getString("name"), equalTo("line1 \r\n line2"));
 }
コード例 #20
0
 @Test
 public void shouldHaveFalseSyncStatusIfTheChildObjectIsCreated() throws JSONException {
   Child child = new Child();
   assertFalse(child.isSynced());
 }
コード例 #21
0
 @Test
 public void shouldNotOverwriteIdIfAlreadyPresent() throws JSONException {
   Child child = new Child("id1", "owner1", null);
   child.generateUniqueId();
   assertThat(child.getUniqueId(), equalTo("id1"));
 }
コード例 #22
0
 @Test
 public void shouldBeNewIfThereIsNoID() throws JSONException {
   Child child = new Child("id1", "user1", "{ 'test1' : 'value1' }");
   assertThat(child.isNew(), is(true));
 }