예제 #1
0
 /** Test of toJson method, of class Patch. */
 @Test
 public void testToJson() throws Exception {
   JsonPatch instance = new JsonPatch();
   instance.addOperation(new Operation(Op.replace, "name", "Ged corrigée"));
   instance.addOperation(new Operation(Op.replace, "versionning", "false"));
   instance.addOperation(new Operation(Op.remove, "xmlForm", ""));
   String expResult =
       "[{\"op\":\"replace\",\"path\":\"name\",\"value\":\"Ged "
           + "corrigée\"},{\"op\":\"replace\",\"path\":\"versionning\",\"value\":\"false\"},{"
           + "\"op\":\"remove\",\"path\":\"xmlForm\",\"value\":\"\"}]";
   String result = instance.toJson();
   assertThat(result, is(expResult));
 }
예제 #2
0
  /** Test of fromJson method, of class Patch. */
  @Test
  public void testFromJson() throws Exception {
    String json =
        "[{\"op\":\"replace\",\"path\":\"name\",\"value\":\"Ged "
            + "corrigée\"},{\"op\":\"replace\",\"path\":\"versionning\",\"value\":\"false\"},{"
            + "\"op\":\"remove\",\"path\":\"xmlForm\",\"value\":\"\"}]";
    JsonPatch instance = new JsonPatch();
    instance.fromJson(json);
    assertThat(instance, is(notNullValue()));
    assertThat(instance.getOperations(), is(notNullValue()));
    assertThat(instance.getOperations(), hasSize(3));
    Operation operation = instance.getOperationByPath("name");
    assertThat(operation, is(notNullValue()));
    assertThat(operation.getOp(), is(Op.replace));
    assertThat(operation.getValue(), is("Ged corrigée"));
    assertThat(operation.getPath(), is("name"));

    operation = instance.getOperationByPath("versionning");
    assertThat(operation, is(notNullValue()));
    assertThat(operation.getOp(), is(Op.replace));
    assertThat(operation.getValue(), is("false"));
    assertThat(operation.getPath(), is("versionning"));

    operation = instance.getOperationByPath("xmlForm");
    assertThat(operation, is(notNullValue()));
    assertThat(operation.getOp(), is(Op.remove));
    assertThat(operation.getValue(), is(""));
    assertThat(operation.getPath(), is("xmlForm"));

    operation = instance.getOperationByPath("miguel");
    assertThat(operation, is(nullValue()));
  }
예제 #3
0
 /** Test of serialize an instance. */
 @Test
 public void testSerialize() throws Exception {
   String json =
       "[{\"op\":\"replace\",\"path\":\"name\",\"value\":\"Ged "
           + "corrigée\"},{\"op\":\"replace\",\"path\":\"versionning\",\"value\":\"false\"},{"
           + "\"op\":\"remove\",\"path\":\"xmlForm\",\"value\":\"\"}]";
   JsonPatch instance = new JsonPatch();
   instance.fromJson(json);
   assertThat(instance, is(notNullValue()));
   assertThat(instance.getOperations(), is(notNullValue()));
   assertThat(instance.getOperations(), hasSize(3));
   ByteArrayOutputStream buffer = new ByteArrayOutputStream(512);
   ObjectOutputStream out = new ObjectOutputStream(buffer);
   try {
     out.writeObject(instance);
   } finally {
     IOUtils.closeQuietly(out);
   }
 }