Package com.linkedin.data.transform.patch.request

Examples of com.linkedin.data.transform.patch.request.PatchTree


    testModel.setFooRequired(100).setFooUnion(fooUnion).setFooOptional(null, SetMode.REMOVE_IF_NULL);
    testModel.getFooRecordTemplate().setBar(9001l);
    // GetMode should be irrelevant
    testModel.getFooRecordTemplate(GetMode.DEFAULT).setBaz(null, SetMode.REMOVE_IF_NULL);

    PatchTree ptExpect = PatchCreator.diff(new DataMap(),
                                           new PatchTreeTestModel().setFooRequired(100).setFooUnion(fooUnion).data());

    // Augment the patch request with the removes in the same order so we get the same patch request.
    ptExpect.addOperation(PatchTreeTestModel.fields().fooOptional(), new RemoveFieldOp());
    ptExpect.addOperation(PatchTreeTestModel.fields().fooRecordTemplate().bar(), new SetFieldOp(9001l));
    ptExpect.addOperation(PatchTreeTestModel.fields().fooRecordTemplate().baz(), new RemoveFieldOp());

    Assert.assertEquals(pc.generatePatchTree().getDataMap(),
                        ptExpect.getDataMap());
  }
View Full Code Here


  {
    PatchTreeRecorder<PatchTreeTestModel> pc = makeOne();
    PatchTreeTestModel restCommonTestModel = pc.getRecordingProxy();

    restCommonTestModel.setFooRecordTemplate(new FooRecordTemplate().setBar(10l));
    PatchTree pt1 = pc.generatePatchTree();

    restCommonTestModel.setFooRecordTemplate(new FooRecordTemplate().setBar(20l));
    PatchTree pt2 = pc.generatePatchTree();

    Assert.assertNotEquals(pt1.getDataMap(), pt2.getDataMap());
    Assert.assertEquals(pt1.getDataMap(),
                        diffEmpty(new PatchTreeTestModel().setFooRecordTemplate(new FooRecordTemplate().setBar(10l))));
    Assert.assertEquals(pt2.getDataMap(),
                        diffEmpty(new PatchTreeTestModel().setFooRecordTemplate(new FooRecordTemplate().setBar(20l))));
  }
View Full Code Here

public class TestPatchCreation
{
  @Test
  public void testExplicitPatchCreationSet()
  {
    PatchTree patch = new PatchTree();
    patch.addOperation(new PathSpec("foo"), PatchOpFactory.setFieldOp(42));
    patch.addOperation(new PathSpec("bar", "baz"), PatchOpFactory.setFieldOp("The quick brown fox"));
    Assert.assertEquals(patch.toString(), "{$set={foo=42}, bar={$set={baz=The quick brown fox}}}");
  }
View Full Code Here

  }

  @Test
  public void testExplicitPatchCreationRemove()
  {
    PatchTree patch = new PatchTree();
    patch.addOperation(new PathSpec("foo"), PatchOpFactory.REMOVE_FIELD_OP);
    patch.addOperation(new PathSpec("bar", "baz"), PatchOpFactory.REMOVE_FIELD_OP);
    Assert.assertEquals(patch.toString(), "{bar={$delete=[baz]}, $delete=[foo]}");
  }
View Full Code Here

  }

  @Test
  public void testExplicitPatchCreationMixed()
  {
    PatchTree patch = new PatchTree();
    patch.addOperation(new PathSpec("foo"), PatchOpFactory.setFieldOp(42));
    patch.addOperation(new PathSpec("bar", "baz"), PatchOpFactory.REMOVE_FIELD_OP);
    patch.addOperation(new PathSpec("qux"), PatchOpFactory.REMOVE_FIELD_OP);
    Assert.assertEquals(patch.toString(), "{$set={foo=42}, bar={$delete=[baz]}, $delete=[qux]}");
  }
View Full Code Here

    DataMap map2 = map.copy();
    map2.put("foo", 42);
    map2.put("bar", new DataMap());
    ((DataMap)map2.get("bar")).put("baz", "The quick brown fox");

    PatchTree patch = PatchCreator.diff(map, map2);
    Assert.assertEquals(patch.toString(), "{$set={foo=42, bar={baz=The quick brown fox}}}");
  }
View Full Code Here

    ));
    DataMap map2 = map.copy();
    map2.remove("foo");
    ((DataMap)map2.get("bar")).remove("baz");

    PatchTree patch = PatchCreator.diff(map, map2);
    Assert.assertEquals(patch.toString(), "{bar={$delete=[baz]}, $delete=[foo]}");
  }
View Full Code Here

    map2.remove("foo");
    ((DataMap)map2.get("bar")).remove("baz");
    map2.put("foo", 42);
    map2.remove("qux");

    PatchTree patch = new PatchTree();
    patch.addOperation(new PathSpec("foo"), PatchOpFactory.setFieldOp(42));
    patch.addOperation(new PathSpec("bar", "baz"), PatchOpFactory.REMOVE_FIELD_OP);
    patch.addOperation(new PathSpec("qux"), PatchOpFactory.REMOVE_FIELD_OP);
    Assert.assertEquals(patch.toString(), "{$set={foo=42}, bar={$delete=[baz]}, $delete=[qux]}");
  }
View Full Code Here

            "qux", 42,
            "bar", new DataMap(asMap(
                "baz", "The quick brown fox"
            ))
    ));
    PatchTree patch = PatchCreator.diff(map, map);
    Assert.assertEquals(patch.toString(), "{}");
  }
View Full Code Here

{
  private static final DataMap _emptyDataMap = new DataMap();

  public static <T extends RecordTemplate> PatchRequest<T> diff(T original, T revised)
  {
    PatchTree patch = PatchCreator.diff(original, revised);
    return PatchRequest.createFromPatchDocument(patch.getDataMap());
  }
View Full Code Here

TOP

Related Classes of com.linkedin.data.transform.patch.request.PatchTree

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.