Search in sources :

Example 1 with PatchTreeTestModel

use of com.linkedin.restli.client.util.test.PatchTreeTestModel 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());
}
Also used : PatchTreeTestModel(com.linkedin.restli.client.util.test.PatchTreeTestModel) RemoveFieldOp(com.linkedin.data.transform.patch.request.RemoveFieldOp) PatchTree(com.linkedin.data.transform.patch.request.PatchTree) Test(org.testng.annotations.Test)

Example 2 with PatchTreeTestModel

use of com.linkedin.restli.client.util.test.PatchTreeTestModel in project rest.li by linkedin.

the class TestPatchTreeRecorder method testSetRecordTemplate.

@Test
public void testSetRecordTemplate() {
    PatchTreeRecorder<PatchTreeTestModel> pc = makeOne();
    pc.getRecordingProxy().setFooRecordTemplate(new FooRecordTemplate().setBar(20));
    PatchTreeTestModel expectModel = new PatchTreeTestModel().setFooRecordTemplate(new FooRecordTemplate().setBar(20));
    Assert.assertEquals(pc.generatePatchTree().getDataMap(), diffEmpty(expectModel));
}
Also used : FooRecordTemplate(com.linkedin.restli.client.util.test.FooRecordTemplate) PatchTreeTestModel(com.linkedin.restli.client.util.test.PatchTreeTestModel) Test(org.testng.annotations.Test)

Example 3 with PatchTreeTestModel

use of com.linkedin.restli.client.util.test.PatchTreeTestModel in project rest.li by linkedin.

the class TestPatchTreeRecorder method testEmptyPatch.

@Test
public void testEmptyPatch() {
    PatchTreeRecorder<PatchTreeTestModel> pc = makeOne();
    Assert.assertEquals(pc.generatePatchTree().getDataMap(), new DataMap());
}
Also used : PatchTreeTestModel(com.linkedin.restli.client.util.test.PatchTreeTestModel) DataMap(com.linkedin.data.DataMap) Test(org.testng.annotations.Test)

Example 4 with PatchTreeTestModel

use of com.linkedin.restli.client.util.test.PatchTreeTestModel 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());
}
Also used : PatchTreeTestModel(com.linkedin.restli.client.util.test.PatchTreeTestModel) RemoveFieldOp(com.linkedin.data.transform.patch.request.RemoveFieldOp) PatchTree(com.linkedin.data.transform.patch.request.PatchTree) Test(org.testng.annotations.Test)

Example 5 with PatchTreeTestModel

use of com.linkedin.restli.client.util.test.PatchTreeTestModel 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());
}
Also used : PatchTreeTestModel(com.linkedin.restli.client.util.test.PatchTreeTestModel) RemoveFieldOp(com.linkedin.data.transform.patch.request.RemoveFieldOp) PatchTree(com.linkedin.data.transform.patch.request.PatchTree) DataMap(com.linkedin.data.DataMap) Test(org.testng.annotations.Test)

Aggregations

PatchTreeTestModel (com.linkedin.restli.client.util.test.PatchTreeTestModel)14 Test (org.testng.annotations.Test)14 PatchTree (com.linkedin.data.transform.patch.request.PatchTree)5 RemoveFieldOp (com.linkedin.data.transform.patch.request.RemoveFieldOp)4 DataMap (com.linkedin.data.DataMap)3 FooRecordTemplate (com.linkedin.restli.client.util.test.FooRecordTemplate)2 SetFieldOp (com.linkedin.data.transform.patch.request.SetFieldOp)1