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"))))));
}
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"))))));
}
Aggregations