Search in sources :

Example 6 with RestError

use of org.apache.camel.component.salesforce.api.dto.RestError in project camel by apache.

the class SObjectTreeResponseTest method shouldDeserializeXmlFromSalesforceFailureExample.

@Test
public void shouldDeserializeXmlFromSalesforceFailureExample() throws Exception {
    final String xml = //
    "<Result>\n" + //
    "    <hasErrors>true</hasErrors>\n" + //
    "    <results>\n" + //
    "        <errors>\n" + //
    "            <fields>Email</fields>\n" + //
    "            <message>Email: invalid email address: 123</message>\n" + //
    "            <statusCode>INVALID_EMAIL_ADDRESS</statusCode>\n" + //
    "        </errors>\n" + //
    "        <referenceId>ref2</referenceId>\n" + //
    "    </results>\n" + "</Result>";
    final XStream xStream = new XStream();
    xStream.processAnnotations(new Class[] { SObjectTreeResponse.class });
    final SObjectTreeResponse response = (SObjectTreeResponse) xStream.fromXML(xml);
    assertNotNull("Response should be parsed", response);
    assertTrue("`hasErrors` flag should be true", response.hasErrors());
    assertEquals("Should read one reference", 1, response.getResults().size());
    assertThat("The reference should be read as expected", response.getResults(), hasItems(new ReferenceId("ref2", null, Arrays.asList(new RestError("INVALID_EMAIL_ADDRESS", "Email: invalid email address: 123", Arrays.asList("Email"))))));
}
Also used : XStream(com.thoughtworks.xstream.XStream) RestError(org.apache.camel.component.salesforce.api.dto.RestError) Test(org.junit.Test)

Example 7 with RestError

use of org.apache.camel.component.salesforce.api.dto.RestError in project camel by apache.

the class SObjectTreeResponseTest method shouldDeserializeJsonFromSalesforceFailureExample.

@Test
public void shouldDeserializeJsonFromSalesforceFailureExample() throws Exception {
    final String json = //
    "{\n" + //
    "   \"hasErrors\" : true,\n" + //
    "   \"results\" : [{\n" + //
    "     \"referenceId\" : \"ref2\",\n" + //
    "     \"errors\" : [{\n" + //
    "       \"statusCode\" : \"INVALID_EMAIL_ADDRESS\",\n" + //
    "       \"message\" : \"Email: invalid email address: 123\",\n" + //
    "       \"fields\" : [ \"Email\" ]\n" + //
    "       }]\n" + //
    "     }]\n" + "}";
    final ObjectMapper mapper = new ObjectMapper();
    final ObjectReader reader = mapper.readerFor(SObjectTreeResponse.class);
    final SObjectTreeResponse response = reader.readValue(json);
    assertNotNull("Response should be parsed", response);
    assertTrue("`hasErrors` flag should be true", response.hasErrors());
    assertEquals("Should read one reference", 1, response.getResults().size());
    assertThat("The reference should be read as expected", response.getResults(), hasItems(new ReferenceId("ref2", null, Arrays.asList(new RestError("INVALID_EMAIL_ADDRESS", "Email: invalid email address: 123", Arrays.asList("Email"))))));
}
Also used : RestError(org.apache.camel.component.salesforce.api.dto.RestError) ObjectReader(com.fasterxml.jackson.databind.ObjectReader) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test)

Aggregations

RestError (org.apache.camel.component.salesforce.api.dto.RestError)7 SalesforceException (org.apache.camel.component.salesforce.api.SalesforceException)3 IOException (java.io.IOException)2 Test (org.junit.Test)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 ObjectReader (com.fasterxml.jackson.databind.ObjectReader)1 XStream (com.thoughtworks.xstream.XStream)1 ArrayList (java.util.ArrayList)1 SalesforceMultipleChoicesException (org.apache.camel.component.salesforce.api.SalesforceMultipleChoicesException)1 Error (org.apache.camel.component.salesforce.api.dto.bulk.Error)1 LoginError (org.apache.camel.component.salesforce.internal.dto.LoginError)1 LoginToken (org.apache.camel.component.salesforce.internal.dto.LoginToken)1 RestChoices (org.apache.camel.component.salesforce.internal.dto.RestChoices)1 RestErrors (org.apache.camel.component.salesforce.internal.dto.RestErrors)1