use of com.linkedin.data.transform.patch.request.PatchTree in project rest.li by linkedin.
the class TestPatchGeneration method testDiffFromNull.
@Test
public void testDiffFromNull() throws Exception {
Group g1 = new Group();
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 testRoundtripAddEscapedField.
@Test
void testRoundtripAddEscapedField() throws Exception {
Group g1 = new Group();
g1.setId(17);
g1.setDescription("Some description");
Group g2 = new Group(g1.data().copy());
g2.data().put("$foo", "value");
PatchTree update = PatchCreator.diff(g1, g2);
//"{$set={$foo=value}}"
final DataMap setMap = new DataMap();
final DataMap fooMap = new DataMap();
fooMap.put("$foo", "value");
setMap.put(PatchConstants.SET_COMMAND, fooMap);
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);
}
use of com.linkedin.data.transform.patch.request.PatchTree in project rest.li by linkedin.
the class TestPatchGeneration method testExplicitUpdate.
@Test
public void testExplicitUpdate() {
PatchTree explicitUpdateSpec = new PatchTree();
explicitUpdateSpec.addOperation(Group.fields().id(), PatchOpFactory.setFieldOp(42));
explicitUpdateSpec.addOperation(Group.fields().name(), PatchOpFactory.setFieldOp("Foo"));
explicitUpdateSpec.addOperation(Group.fields().description(), PatchOpFactory.REMOVE_FIELD_OP);
//"{$set={id=42, name=Foo}, $delete=[description]}"
final DataMap setDeleteMap = new DataMap();
final DataMap idNameMap = new DataMap();
idNameMap.put("id", 42);
idNameMap.put("name", "Foo");
setDeleteMap.put(PatchConstants.SET_COMMAND, idNameMap);
setDeleteMap.put(PatchConstants.DELETE_COMMAND, new DataList(Arrays.asList("description")));
assertEquals(explicitUpdateSpec.getDataMap(), setDeleteMap, "PatchTree DataMap should be correct");
}
use of com.linkedin.data.transform.patch.request.PatchTree in project rest.li by linkedin.
the class TestPatchGeneration method testDiffFromOverwrittenNested.
@Test
public void testDiffFromOverwrittenNested() throws Exception {
Group g1 = new Group();
Location loc1 = new Location();
loc1.setLatitude(0.0f);
loc1.setLongitude(0.0f);
g1.setLocation(loc1);
Group g2 = new Group(g1.data().copy());
Location loc2 = new Location();
loc2.setLatitude(42.0f);
loc2.setLongitude(17.0f);
g2.setLocation(loc2);
PatchTree update = PatchCreator.diff(g1, g2);
//"{location={$set={longitude=17.0, latitude=42.0}}}"
final DataMap setMap = new DataMap();
final DataMap longLatMap = new DataMap();
longLatMap.put("longitude", 17.0f);
longLatMap.put("latitude", 42.0f);
setMap.put(PatchConstants.SET_COMMAND, longLatMap);
final DataMap locationMap = new DataMap();
locationMap.put("location", setMap);
Assert.assertEquals(update.getDataMap(), locationMap, "PatchTree DataMap should be correct");
}
use of com.linkedin.data.transform.patch.request.PatchTree in project rest.li by linkedin.
the class TestPatchGeneration method testDiffRemove.
@Test
void testDiffRemove() throws Exception {
Group g1 = new Group();
g1.setId(17);
g1.setDescription("Some description");
Group g2 = new Group(g1.data().copy());
g2.removeDescription();
PatchTree update = PatchCreator.diff(g1, g2);
//"{$delete=[description]}"
final DataMap deleteMap = new DataMap();
final DataList descriptionList = new DataList();
descriptionList.add("description");
deleteMap.put(PatchConstants.DELETE_COMMAND, descriptionList);
assertEquals(update.getDataMap(), deleteMap, "PatchTree DataMap should be correct");
}
Aggregations