Search in sources :

Example 11 with DataProcessingException

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

the class TestPatchOnData method testMergingSimpleTypeValueWithComplexPatchNotSupported.

@Test
public void testMergingSimpleTypeValueWithComplexPatchNotSupported() throws JsonParseException, IOException, DataProcessingException {
    DataComplexProcessor processor = new DataComplexProcessor(new Patch(), //command $set should be used
    dataMapFromString("{ \"a\": { \"b\": 1} }"), dataMapFromString("{\"a\": 1}"));
    boolean thrown = false;
    try {
        processor.run(false);
    } catch (DataProcessingException e) {
        thrown = true;
    }
    if (!thrown)
        fail("expected DataProcessingException to be thrown");
}
Also used : DataComplexProcessor(com.linkedin.data.transform.DataComplexProcessor) DataProcessingException(com.linkedin.data.transform.DataProcessingException) Test(org.testng.annotations.Test)

Example 12 with DataProcessingException

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

the class TestPatchOnData method testSetAndBeBranchAtSameTime.

@Test
public void testSetAndBeBranchAtSameTime() throws JsonParseException, IOException, DataProcessingException {
    DataComplexProcessor processor = new DataComplexProcessor(new Patch(), dataMapFromString(//command $set should be used
    "{ \"b\": { \"$set\": { \"b\": 1} }, \"$set\": {\"b\": 1} }"), dataMapFromString("{\"a\": 1}"));
    boolean thrown = false;
    try {
        processor.run(false);
    } catch (DataProcessingException e) {
        thrown = true;
    }
    if (!thrown)
        fail("expected DataProcessingException to be thrown");
}
Also used : DataComplexProcessor(com.linkedin.data.transform.DataComplexProcessor) DataProcessingException(com.linkedin.data.transform.DataProcessingException) Test(org.testng.annotations.Test)

Example 13 with DataProcessingException

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

the class AbstractFilter method compose.

/**
   * Returns composition of two masks. This method does not modify any of the parameters
   * and returned mask is new object. Composition is achieved by invoking separate data
   * processing. If there was an error during mask composition, then null is returned.
   *
   * @param mask1 first mask
   * @param mask2 second mask
   * @return composed masks or null if there was an error during composition fast-fail
   *         mode
   */
private DataMap compose(String fieldName, DataMap mask1, DataMap mask2) {
    // precondition:
    assert mask2 != null;
    assert mask1 != null;
    try {
        final DataMap clone = mask1.copy();
        new DataComplexProcessor(new MaskComposition(), mask2, clone).run(true);
        return clone;
    } catch (CloneNotSupportedException e) {
        onError(fieldName, "could not clone mask: %1$s, exception: %2$s", mask1, e);
    } catch (DataProcessingException e) {
        onError(fieldName, "error composing mask %1$s with %2$s, exception: %3$s", mask1, mask2, e);
    }
    return null;
}
Also used : DataComplexProcessor(com.linkedin.data.transform.DataComplexProcessor) DataMap(com.linkedin.data.DataMap) DataProcessingException(com.linkedin.data.transform.DataProcessingException)

Example 14 with DataProcessingException

use of com.linkedin.data.transform.DataProcessingException 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 15 with DataProcessingException

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

the class TestFilter method testErrorMessagesForArraysNotFastFail.

@Test
public void testErrorMessagesForArraysNotFastFail() 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(false);
    } catch (DataProcessingException e) {
        assertEquals(e.getMessages().size(), 5, "expected exactly 5 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)

Aggregations

DataProcessingException (com.linkedin.data.transform.DataProcessingException)26 DataComplexProcessor (com.linkedin.data.transform.DataComplexProcessor)16 Test (org.testng.annotations.Test)13 DataMap (com.linkedin.data.DataMap)10 UpdateResponse (com.linkedin.restli.server.UpdateResponse)10 PatchRequest (com.linkedin.restli.common.PatchRequest)3 Message (com.linkedin.data.message.Message)2 Greeting (com.linkedin.restli.examples.greetings.api.Greeting)2 GroupMembership (com.linkedin.restli.examples.groups.api.GroupMembership)2 BatchPatchRequest (com.linkedin.restli.server.BatchPatchRequest)2 BatchUpdateResult (com.linkedin.restli.server.BatchUpdateResult)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 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 Patch (com.linkedin.data.transform.patch.Patch)1 ComplexResourceKey (com.linkedin.restli.common.ComplexResourceKey)1