Exemplo n.º 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()));
 }
Exemplo n.º 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"));
 }
Exemplo n.º 3
0
  @Test
  public void shouldReturnShortID() throws JSONException {
    Child child = new Child();
    child.setUniqueId("987654321");

    assertThat(child.getShortId(), equalTo("7654321"));
  }
Exemplo n.º 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"));
 }
Exemplo n.º 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());
  }
Exemplo n.º 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());
  }
Exemplo n.º 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"));
  }
Exemplo n.º 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\"}"));
  }
Exemplo n.º 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"));
  }
Exemplo n.º 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"));
  }
Exemplo n.º 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"));
  }
Exemplo n.º 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));
  }
Exemplo n.º 13
0
 @Test
 public void shouldReturnNamesWithLengthOneInsteadOfNull() throws JSONException {
   Child child = new Child();
   assertThat(child.names().length(), equalTo(1));
 }
Exemplo n.º 14
0
 @Test
 public void shouldDecodeInteger() throws JSONException {
   Child child = new Child("{ 'test1' : 17 }");
   assertThat(child.getInt("test1"), is(17));
 }
Exemplo n.º 15
0
 @Test
 public void shouldDecodeString() throws JSONException {
   Child child = new Child("{ 'test1' :  'value1' }");
   assertThat(child.getString("test1"), is("value1"));
 }
Exemplo n.º 16
0
 @Test
 public void shouldDecodeOwnerFromJSON() throws JSONException {
   Child child = new Child("{ 'created_by' : 'test1' }");
   assertThat(child.getOwner(), is("test1"));
 }
Exemplo n.º 17
0
 @Test
 public void shouldDecodeIDFromJSON() throws JSONException {
   Child child = new Child("{ 'unique_identifier' : 'test1' }");
   assertThat(child.getUniqueId(), is("test1"));
 }
Exemplo n.º 18
0
 @Test
 public void shouldNotBeNewIfThereIsID() throws JSONException {
   Child child = new Child();
   child.put(internal_id.getColumnName(), "xyz");
   assertThat(child.isNew(), is(false));
 }
Exemplo n.º 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"));
 }
Exemplo n.º 20
0
 @Test
 public void shouldHaveFalseSyncStatusIfTheChildObjectIsCreated() throws JSONException {
   Child child = new Child();
   assertFalse(child.isSynced());
 }
Exemplo n.º 21
0
 @Test
 public void shouldNotOverwriteIdIfAlreadyPresent() throws JSONException {
   Child child = new Child("id1", "owner1", null);
   child.generateUniqueId();
   assertThat(child.getUniqueId(), equalTo("id1"));
 }
Exemplo n.º 22
0
 @Test
 public void shouldBeNewIfThereIsNoID() throws JSONException {
   Child child = new Child("id1", "user1", "{ 'test1' : 'value1' }");
   assertThat(child.isNew(), is(true));
 }