use of com.linkedin.data.transform.patch.request.RemoveFieldOp in project rest.li by linkedin.
the class TestPatchTreeRecorder method testSimpleSetRemoveIfNullSetMode.
@Test
public void testSimpleSetRemoveIfNullSetMode() {
PatchTreeRecorder<PatchTreeTestModel> pc = makeOne();
PatchTreeTestModel testModel = pc.getRecordingProxy();
testModel.setFooOptional(null, SetMode.REMOVE_IF_NULL);
// Augment the patch request with the removes
PatchTree ptExpect = new PatchTree();
ptExpect.addOperation(PatchTreeTestModel.fields().fooOptional(), new RemoveFieldOp());
Assert.assertEquals(pc.generatePatchTree().getDataMap(), ptExpect.getDataMap());
}
use of com.linkedin.data.transform.patch.request.RemoveFieldOp in project rest.li by linkedin.
the class TestPatchTreeRecorder method testSimpleSetRemoveOptionalIfNullOnOptionalFieldPass.
@Test
public void testSimpleSetRemoveOptionalIfNullOnOptionalFieldPass() {
PatchTreeRecorder<PatchTreeTestModel> pc = makeOne();
PatchTreeTestModel restCommonTestModel = pc.getRecordingProxy();
restCommonTestModel.setFooOptional(null, SetMode.REMOVE_OPTIONAL_IF_NULL);
// Augment the patch request with the removes
PatchTree ptExpect = new PatchTree();
ptExpect.addOperation(PatchTreeTestModel.fields().fooOptional(), new RemoveFieldOp());
Assert.assertEquals(pc.generatePatchTree().getDataMap(), ptExpect.getDataMap());
}
use of com.linkedin.data.transform.patch.request.RemoveFieldOp in project rest.li by linkedin.
the class TestPatchTreeRecorder method testFluentSetWithRemove.
@Test
public void testFluentSetWithRemove() {
PatchTreeRecorder<PatchTreeTestModel> pc = makeOne();
PatchTreeTestModel testModel = pc.getRecordingProxy();
PatchTreeTestModel.FooUnion fooUnion = new PatchTreeTestModel.FooUnion();
fooUnion.setInt(10);
testModel.setFooRequired(100).setFooUnion(fooUnion).setFooRecordTemplate(null, SetMode.REMOVE_IF_NULL).removeFooOptional();
PatchTree ptExpect = PatchCreator.diff(new DataMap(), new PatchTreeTestModel().setFooRequired(100).setFooUnion(fooUnion).data());
// Augment the patch request with the removes
ptExpect.addOperation(PatchTreeTestModel.fields().fooRecordTemplate(), new RemoveFieldOp());
ptExpect.addOperation(PatchTreeTestModel.fields().fooOptional(), new RemoveFieldOp());
Assert.assertEquals(pc.generatePatchTree().getDataMap(), ptExpect.getDataMap());
}
use of com.linkedin.data.transform.patch.request.RemoveFieldOp 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());
}
Aggregations