Search in sources :

Example 11 with PatchTreeTestModel

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

the class TestPatchTreeRecorder method testMethodsInheritedFromObjectOnProxy.

@Test
public void testMethodsInheritedFromObjectOnProxy() {
    PatchTreeRecorder<PatchTreeTestModel> pc = makeOne();
    PatchTreeTestModel testModel = pc.getRecordingProxy();
    Assert.assertEquals(testModel.hashCode(), testModel.hashCode());
    Assert.assertNotNull(testModel.toString());
    Assert.assertTrue(testModel.equals(testModel));
    Assert.assertFalse(testModel.equals(new PatchTreeTestModel()));
}
Also used : PatchTreeTestModel(com.linkedin.restli.client.util.test.PatchTreeTestModel) Test(org.testng.annotations.Test)

Example 12 with PatchTreeTestModel

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

the class TestPatchTreeRecorder method testFluentSet.

@Test
public void testFluentSet() {
    PatchTreeRecorder<PatchTreeTestModel> pc = makeOne();
    PatchTreeTestModel testModel = pc.getRecordingProxy();
    testModel.setFooOptional(100).setFooEnum(FooEnum.B);
    Assert.assertEquals(pc.generatePatchTree().getDataMap(), diffEmpty(new PatchTreeTestModel().setFooOptional(100).setFooEnum(FooEnum.B)));
}
Also used : PatchTreeTestModel(com.linkedin.restli.client.util.test.PatchTreeTestModel) Test(org.testng.annotations.Test)

Example 13 with PatchTreeTestModel

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

the class TestPatchTreeRecorder method testSimpleSetRemoveOptionalIfNullWithValue.

@Test
public void testSimpleSetRemoveOptionalIfNullWithValue() {
    PatchTreeRecorder<PatchTreeTestModel> pc = makeOne();
    PatchTreeTestModel testModel = pc.getRecordingProxy();
    testModel.setFooOptional(10l, SetMode.REMOVE_OPTIONAL_IF_NULL);
    Assert.assertEquals(pc.generatePatchTree().getDataMap(), diffEmpty(new PatchTreeTestModel().setFooOptional(10l)));
}
Also used : PatchTreeTestModel(com.linkedin.restli.client.util.test.PatchTreeTestModel) Test(org.testng.annotations.Test)

Example 14 with PatchTreeTestModel

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