use of com.linkedin.data.transform.patch.request.PatchTree in project rest.li by linkedin.
the class TestPatchTreeRecorder method testPatchGeneratesDeepCopiesOfInternalState.
@Test
public void testPatchGeneratesDeepCopiesOfInternalState() {
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))));
}
use of com.linkedin.data.transform.patch.request.PatchTree in project rest.li by linkedin.
the class TestPatchTreeRecorder method testComplexDeepSetAndRemoves.
@Test
public void testComplexDeepSetAndRemoves() {
PatchTreeRecorder<PatchTreeTestModel> pc = makeOne();
PatchTreeTestModel testModel = pc.getRecordingProxy();
PatchTreeTestModel.FooUnion fooUnion = new PatchTreeTestModel.FooUnion();
fooUnion.setInt(10);
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());
}
use of com.linkedin.data.transform.patch.request.PatchTree in project rest.li by linkedin.
the class TestPatchGeneration method testDiffFromNonNull.
@Test
void testDiffFromNonNull() throws Exception {
Group g1 = new Group();
g1.setId(17);
g1.setDescription("Some description");
Group g2 = new Group(g1.data().copy());
g2.setId(42);
g2.setName("Some Group");
PatchTree update = PatchCreator.diff(g1, g2);
//"{$set={id=42, name=Some Group}}"
final DataMap internalSetMap = new DataMap();
internalSetMap.put("id", 42);
internalSetMap.put("name", "Some Group");
final DataMap setMap = new DataMap();
setMap.put(PatchConstants.SET_COMMAND, internalSetMap);
assertEquals(update.getDataMap(), setMap, "PatchTree DataMap should be correct");
}
use of com.linkedin.data.transform.patch.request.PatchTree in project rest.li by linkedin.
the class TestPatchGeneration method testRoundtripModifyEscapedField.
@Test(groups = { TestConstants.TESTNG_GROUP_KNOWN_ISSUE })
void testRoundtripModifyEscapedField() throws Exception {
Group g1 = new Group();
g1.data().put("$foo", new DataMap());
Group g2 = new Group(g1.data().copy());
((DataMap) g2.data().get("$foo")).put("bar", 42);
PatchTree update = PatchCreator.diff(g1, g2);
//"{$$foo={$set={bar=42}}}"
final DataMap setMap = new DataMap();
final DataMap barMap = new DataMap();
barMap.put("bar", 42);
setMap.put(PatchConstants.SET_COMMAND, barMap);
final DataMap fooMap = new DataMap();
fooMap.put("$$foo", setMap);
assertEquals(update.getDataMap(), fooMap, "PatchTree DataMap must be correct");
assertFalse(g1.equals(g2));
DataComplexProcessor processor = new DataComplexProcessor(new Patch(), update.getDataMap(), g1.data());
processor.run(false);
assertEquals(g1, g2);
}
use of com.linkedin.data.transform.patch.request.PatchTree in project rest.li by linkedin.
the class TestPatchGeneration method testRoundtripAddFields.
@Test
void testRoundtripAddFields() throws Exception {
Group g1 = new Group();
g1.setId(17);
g1.setDescription("Some description");
Group g2 = new Group(g1.data().copy());
g2.setId(42);
g2.setName("Some Group");
PatchTree update = PatchCreator.diff(g1, g2);
//"{$set={id=42, name=Some Group}}"
final DataMap setMap = new DataMap();
final DataMap idNameMap = new DataMap();
idNameMap.put("id", 42);
idNameMap.put("name", "Some Group");
setMap.put(PatchConstants.SET_COMMAND, idNameMap);
assertEquals(update.getDataMap(), setMap, "PatchTree DataMap should be correct");
assertFalse(g1.equals(g2));
DataComplexProcessor processor = new DataComplexProcessor(new Patch(), update.getDataMap(), g1.data());
processor.run(false);
assertEquals(g1, g2);
}
Aggregations