Search in sources :

Example 16 with DataMap

use of com.linkedin.data.DataMap in project rest.li by linkedin.

the class TestFilter method testErrorMessagesForArraysFastFail.

@Test
public void testErrorMessagesForArraysFastFail() throws JsonParseException, IOException, DataProcessingException {
    DataMap data = dataMapFromString("{ 'a': [1, 2, 3, 4, 5]}".replace('\'', '"'));
    DataMap filter = dataMapFromString("{ 'a': { '$*': { 'y': 1}}}".replace('\'', '"'));
    DataComplexProcessor processor = new DataComplexProcessor(new Filter(), filter, data);
    boolean thrown = false;
    try {
        processor.run(true);
    } catch (DataProcessingException e) {
        assertEquals(e.getMessages().size(), 1, "expected exactly 1 error in non fast fail mode");
        thrown = true;
    }
    assertEquals(thrown, true, "exception should have been thrown");
}
Also used : DataComplexProcessor(com.linkedin.data.transform.DataComplexProcessor) DataMap(com.linkedin.data.DataMap) DataProcessingException(com.linkedin.data.transform.DataProcessingException) Test(org.testng.annotations.Test)

Example 17 with DataMap

use of com.linkedin.data.DataMap in project rest.li by linkedin.

the class TestPatchCreation method testDiffPatchCreationMixed.

@Test
public void testDiffPatchCreationMixed() throws Exception {
    DataMap map = new DataMap(asMap("qux", 42, "bar", new DataMap(asMap("baz", "The quick brown fox"))));
    DataMap map2 = map.copy();
    map2.remove("foo");
    ((DataMap) map2.get("bar")).remove("baz");
    map2.put("foo", 42);
    map2.remove("qux");
    PatchTree patch = new PatchTree();
    patch.addOperation(new PathSpec("foo"), PatchOpFactory.setFieldOp(42));
    patch.addOperation(new PathSpec("bar", "baz"), PatchOpFactory.REMOVE_FIELD_OP);
    patch.addOperation(new PathSpec("qux"), PatchOpFactory.REMOVE_FIELD_OP);
    //"{$set={foo=42}, bar={$delete=[baz]}, $delete=[qux]}"
    final DataMap fooMap = new DataMap();
    fooMap.put("foo", 42);
    final DataMap deleteMap = new DataMap();
    deleteMap.put(PatchConstants.DELETE_COMMAND, new DataList(Arrays.asList("baz")));
    final DataMap setBarDeleteMap = new DataMap();
    setBarDeleteMap.put(PatchConstants.SET_COMMAND, fooMap);
    setBarDeleteMap.put("bar", deleteMap);
    setBarDeleteMap.put(PatchConstants.DELETE_COMMAND, new DataList(Arrays.asList("qux")));
    assertEquals(patch.getDataMap(), setBarDeleteMap, "PatchTree DataMap must be correct");
}
Also used : DataList(com.linkedin.data.DataList) PathSpec(com.linkedin.data.schema.PathSpec) PatchTree(com.linkedin.data.transform.patch.request.PatchTree) DataMap(com.linkedin.data.DataMap) Test(org.testng.annotations.Test)

Example 18 with DataMap

use of com.linkedin.data.DataMap in project rest.li by linkedin.

the class TestPatchCreation method testDiffPatchCreationRemove.

@Test
public void testDiffPatchCreationRemove() throws Exception {
    DataMap map = new DataMap(asMap("foo", 42, "bar", new DataMap(asMap("baz", "The quick brown fox"))));
    DataMap map2 = map.copy();
    map2.remove("foo");
    ((DataMap) map2.get("bar")).remove("baz");
    PatchTree patch = PatchCreator.diff(map, map2);
    Assert.assertEquals(patch.toString(), "{bar={$delete=[baz]}, $delete=[foo]}");
}
Also used : PatchTree(com.linkedin.data.transform.patch.request.PatchTree) DataMap(com.linkedin.data.DataMap) Test(org.testng.annotations.Test)

Example 19 with DataMap

use of com.linkedin.data.DataMap in project rest.li by linkedin.

the class TestPatchCreation method testDiffPatchCreationSet.

@Test
public void testDiffPatchCreationSet() throws Exception {
    DataMap map = new DataMap();
    DataMap map2 = map.copy();
    map2.put("foo", 42);
    map2.put("bar", new DataMap());
    ((DataMap) map2.get("bar")).put("baz", "The quick brown fox");
    PatchTree patch = PatchCreator.diff(map, map2);
    //"{$set={foo=42, bar={baz=The quick brown fox}}}"
    final DataMap bazMap = new DataMap();
    bazMap.put("baz", "The quick brown fox");
    final DataMap fooBarMap = new DataMap();
    fooBarMap.put("foo", 42);
    fooBarMap.put("bar", bazMap);
    final DataMap setMap = new DataMap();
    setMap.put(PatchConstants.SET_COMMAND, fooBarMap);
    assertEquals(patch.getDataMap(), setMap, "PatchTree DataMap must be correct");
}
Also used : PatchTree(com.linkedin.data.transform.patch.request.PatchTree) DataMap(com.linkedin.data.DataMap) Test(org.testng.annotations.Test)

Example 20 with DataMap

use of com.linkedin.data.DataMap in project rest.li by linkedin.

the class TestPatchCreation method testExplicitPatchCreationMixed.

@Test
public void testExplicitPatchCreationMixed() {
    PatchTree patch = new PatchTree();
    patch.addOperation(new PathSpec("foo"), PatchOpFactory.setFieldOp(42));
    patch.addOperation(new PathSpec("bar", "baz"), PatchOpFactory.REMOVE_FIELD_OP);
    patch.addOperation(new PathSpec("qux"), PatchOpFactory.REMOVE_FIELD_OP);
    //"{$set={foo=42}, bar={$delete=[baz]}, $delete=[qux]}"
    final DataMap fooMap = new DataMap();
    fooMap.put("foo", 42);
    final DataMap deleteMap = new DataMap();
    deleteMap.put(PatchConstants.DELETE_COMMAND, new DataList(Arrays.asList("baz")));
    final DataMap setBarDeleteMap = new DataMap();
    setBarDeleteMap.put(PatchConstants.SET_COMMAND, fooMap);
    setBarDeleteMap.put("bar", deleteMap);
    setBarDeleteMap.put(PatchConstants.DELETE_COMMAND, new DataList(Arrays.asList("qux")));
    assertEquals(patch.getDataMap(), setBarDeleteMap, "PatchTree DataMap must be correct");
}
Also used : DataList(com.linkedin.data.DataList) PathSpec(com.linkedin.data.schema.PathSpec) PatchTree(com.linkedin.data.transform.patch.request.PatchTree) DataMap(com.linkedin.data.DataMap) Test(org.testng.annotations.Test)

Aggregations

DataMap (com.linkedin.data.DataMap)471 Test (org.testng.annotations.Test)238 DataList (com.linkedin.data.DataList)130 ByteString (com.linkedin.data.ByteString)110 HashMap (java.util.HashMap)56 TestUtil.dataMapFromString (com.linkedin.data.TestUtil.dataMapFromString)49 RecordDataSchema (com.linkedin.data.schema.RecordDataSchema)47 TestUtil.dataSchemaFromString (com.linkedin.data.TestUtil.dataSchemaFromString)46 DataSchema (com.linkedin.data.schema.DataSchema)45 Map (java.util.Map)45 ArrayList (java.util.ArrayList)31 MaskTree (com.linkedin.data.transform.filter.request.MaskTree)23 PathSpec (com.linkedin.data.schema.PathSpec)21 RecordTemplate (com.linkedin.data.template.RecordTemplate)21 DataProvider (org.testng.annotations.DataProvider)20 HashSet (java.util.HashSet)19 ArrayDataSchema (com.linkedin.data.schema.ArrayDataSchema)18 PatchTree (com.linkedin.data.transform.patch.request.PatchTree)18 CompoundKey (com.linkedin.restli.common.CompoundKey)18 IOException (java.io.IOException)18