Search in sources :

Example 26 with DataComplexProcessor

use of com.linkedin.data.transform.DataComplexProcessor 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);
}
Also used : Group(com.linkedin.restli.examples.groups.api.Group) DataComplexProcessor(com.linkedin.data.transform.DataComplexProcessor) Patch(com.linkedin.data.transform.patch.Patch) PatchTree(com.linkedin.data.transform.patch.request.PatchTree) DataMap(com.linkedin.data.DataMap) Test(org.testng.annotations.Test)

Example 27 with DataComplexProcessor

use of com.linkedin.data.transform.DataComplexProcessor 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);
}
Also used : Group(com.linkedin.restli.examples.groups.api.Group) DataComplexProcessor(com.linkedin.data.transform.DataComplexProcessor) Patch(com.linkedin.data.transform.patch.Patch) PatchTree(com.linkedin.data.transform.patch.request.PatchTree) DataMap(com.linkedin.data.DataMap) Test(org.testng.annotations.Test)

Aggregations

DataComplexProcessor (com.linkedin.data.transform.DataComplexProcessor)27 Test (org.testng.annotations.Test)19 DataProcessingException (com.linkedin.data.transform.DataProcessingException)17 DataMap (com.linkedin.data.DataMap)15 Patch (com.linkedin.data.transform.patch.Patch)6 TestUtil.dataMapFromString (com.linkedin.data.TestUtil.dataMapFromString)5 PatchTree (com.linkedin.data.transform.patch.request.PatchTree)4 Group (com.linkedin.restli.examples.groups.api.Group)4 Message (com.linkedin.data.message.Message)2 DataList (com.linkedin.data.DataList)1 SimpleDataElement (com.linkedin.data.element.SimpleDataElement)1 ValidationOptions (com.linkedin.data.schema.validation.ValidationOptions)1 ValidationResult (com.linkedin.data.schema.validation.ValidationResult)1 RecordTemplate (com.linkedin.data.template.RecordTemplate)1 MaskComposition (com.linkedin.data.transform.filter.MaskComposition)1 PatchRequest (com.linkedin.restli.common.PatchRequest)1