Search in sources :

Example 21 with DataComplexProcessor

use of com.linkedin.data.transform.DataComplexProcessor in project rest.li by linkedin.

the class TestFilter method testIncorrectFilter.

@Test
public void testIncorrectFilter() throws JsonParseException, IOException, DataProcessingException {
    DataMap data = dataMapFromString("{ 'a': [1, 2, 3, 4, 5]}".replace('\'', '"'));
    DataMap filter = dataMapFromString("{ 'a': { '$*': 'hola'}}".replace('\'', '"'));
    DataComplexProcessor processor = new DataComplexProcessor(new Filter(), filter, data);
    boolean thrown = false;
    try {
        processor.run(false);
    } 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 22 with DataComplexProcessor

use of com.linkedin.data.transform.DataComplexProcessor in project rest.li by linkedin.

the class TestFilter method testNonFastFailError.

@Test
public void testNonFastFailError() throws JsonParseException, IOException, DataProcessingException {
    DataMap data = dataMapFromString("{ 'a': { 'x': 'a'}, 'b': 'b'}".replace('\'', '"'));
    DataMap filter = dataMapFromString("{ 'a': { 'x': { 'y': 1}}, 'b': { 'z': 1}}".replace('\'', '"'));
    DataComplexProcessor processor = new DataComplexProcessor(new Filter(), filter, data);
    boolean thrown = false;
    try {
        processor.run(false);
    } catch (DataProcessingException e) {
        assertEquals(e.getMessages().size(), 2, "expected exactly 2 errors 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 23 with DataComplexProcessor

use of com.linkedin.data.transform.DataComplexProcessor in project rest.li by linkedin.

the class TestFilter method testMaskCompositionDuringFilteringDoesNotOverwriteOriginalMask.

@Test
public void testMaskCompositionDuringFilteringDoesNotOverwriteOriginalMask() throws JsonParseException, IOException, DataProcessingException {
    DataMap data = dataMapFromString("{ 'a': { 'b': 'b'}}".replace('\'', '"'));
    DataMap filter = dataMapFromString("{ '$*': { 'c': { 'd': 0}}, 'a': 1}".replace('\'', '"'));
    String originalFilter = filter.toString();
    DataComplexProcessor processor = new DataComplexProcessor(new Filter(), filter, data);
    processor.run(false);
    assertEquals(filter.toString(), originalFilter, "filter should not be modified");
}
Also used : TestUtil.dataMapFromString(com.linkedin.data.TestUtil.dataMapFromString) DataComplexProcessor(com.linkedin.data.transform.DataComplexProcessor) DataMap(com.linkedin.data.DataMap) Test(org.testng.annotations.Test)

Example 24 with DataComplexProcessor

use of com.linkedin.data.transform.DataComplexProcessor in project rest.li by linkedin.

the class TestFilter method testPathIncludedInError.

@Test
public void testPathIncludedInError() throws JsonParseException, IOException, DataProcessingException {
    DataMap data = dataMapFromString("{ 'a': { 'x': 'a'}}".replace('\'', '"'));
    DataMap filter = dataMapFromString("{ 'a': { 'x': { '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");
        Message m = e.getMessages().get(0);
        assertNotNull(m.getPath(), "path should be set on a message");
        assertEquals(m.getPath(), new Object[] { "a", "x" });
        thrown = true;
    }
    assertEquals(thrown, true, "exception should have been thrown");
}
Also used : Message(com.linkedin.data.message.Message) DataComplexProcessor(com.linkedin.data.transform.DataComplexProcessor) DataMap(com.linkedin.data.DataMap) DataProcessingException(com.linkedin.data.transform.DataProcessingException) Test(org.testng.annotations.Test)

Example 25 with DataComplexProcessor

use of com.linkedin.data.transform.DataComplexProcessor in project rest.li by linkedin.

the class TestPatchGeneration method testRoundtripModifyEscapedField.

@Test(groups = { TestConstants.TESTNG_GROUP_KNOWN_ISSUE })
void testRoundtripModifyEscapedField() throws Exception {
    Group g1 = new Group();
    g1.data().put("$foo", new DataMap());
    Group g2 = new Group(g1.data().copy());
    ((DataMap) g2.data().get("$foo")).put("bar", 42);
    PatchTree update = PatchCreator.diff(g1, g2);
    // "{$$foo={$set={bar=42}}}"
    final DataMap setMap = new DataMap();
    final DataMap barMap = new DataMap();
    barMap.put("bar", 42);
    setMap.put(PatchConstants.SET_COMMAND, barMap);
    final DataMap fooMap = new DataMap();
    fooMap.put("$$foo", setMap);
    assertEquals(update.getDataMap(), fooMap, "PatchTree DataMap must 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