use of com.thoughtworks.xstream.XStream in project camel by apache.
the class DefaultCompositeApiClient method configureXStream.
static XStream configureXStream() {
final PureJavaReflectionProvider reflectionProvider = new PureJavaReflectionProvider(new FieldDictionary(new AnnotationFieldKeySorter()));
final XppDriver hierarchicalStreamDriver = new XppDriver(new NoNameCoder()) {
@Override
public HierarchicalStreamWriter createWriter(final Writer out) {
return new CompactWriter(out, getNameCoder());
}
};
final XStream xStream = new XStream(reflectionProvider, hierarchicalStreamDriver);
xStream.aliasSystemAttribute(null, "class");
xStream.ignoreUnknownElements();
XStreamUtils.addDefaultPermissions(xStream);
xStream.registerConverter(new DateTimeConverter());
xStream.setMarshallingStrategy(new TreeMarshallingStrategy());
xStream.processAnnotations(ADDITIONAL_TYPES);
return xStream;
}
use of com.thoughtworks.xstream.XStream in project camel by apache.
the class ApprovalRequestsTest method shouldSerializeAsXml.
@Test
public void shouldSerializeAsXml() {
final String xml = //
"<ProcessApprovalRequest>" + //
"<requests>" + //
"<actionType>Submit</actionType>" + //
"<contextActorId>005D00000015rZy</contextActorId>" + //
"<contextId>001D000000I8mIm</contextId>" + //
"<comments>this is a test 1</comments>" + //
"<nextApproverIds>005D00000015rY9</nextApproverIds>" + //
"<processDefinitionNameOrId>PTO_Request_Process</processDefinitionNameOrId>" + //
"<skipEntryCriteria>true</skipEntryCriteria>" + //
"</requests>" + //
"<requests>" + //
"<actionType>Submit</actionType>" + //
"<contextActorId>005D00000015rZy</contextActorId>" + //
"<contextId>001D000000I8dIm</contextId>" + //
"<comments>this is a test 2</comments>" + //
"<nextApproverIds>005D00000015xY9</nextApproverIds>" + //
"<processDefinitionNameOrId>PTO_Request_Process</processDefinitionNameOrId>" + //
"<skipEntryCriteria>true</skipEntryCriteria>" + //
"</requests>" + "</ProcessApprovalRequest>";
final XStream xStream = new XStream(new XppDriver(new NoNameCoder()) {
@Override
public HierarchicalStreamWriter createWriter(final Writer out) {
return new CompactWriter(out, getNameCoder());
}
});
xStream.ignoreUnknownElements();
XStreamUtils.addDefaultPermissions(xStream);
xStream.registerConverter(new DateTimeConverter());
xStream.processAnnotations(ApprovalRequests.class);
final String serialized = xStream.toXML(requests);
assertEquals("Approval requests should serialize as XML", xml, serialized);
}
use of com.thoughtworks.xstream.XStream in project camel by apache.
the class SObjectBatchResponseTest method shouldDeserializeFromXml.
@Test
public void shouldDeserializeFromXml() {
final String xml = //
"<batchResults>\n" + //
" <hasErrors>false</hasErrors>\n" + //
" <results>\n" + //
" <batchResult>\n" + //
" <statusCode>204</statusCode>\n" + //
" <result/>\n" + //
" </batchResult>\n" + //
" <batchResult>\n" + //
" <statusCode>200</statusCode>\n" + //
" <result>\n" + //
" <Account type=\"Account\" url=\"/services/data/v34.0/sobjects/Account/001D000000K0fXOIAZ\">\n" + //
" <Id>001D000000K0fXOIAZ</Id>\n" + //
" <Name>NewName</Name>\n" + //
" <BillingPostalCode>94105</BillingPostalCode>" + //
" </Account>\n" + //
" </result>\n" + //
" </batchResult>\n" + //
" </results>\n" + "</batchResults>";
final XStream xStream = new XStream();
xStream.processAnnotations(new Class[] { SObjectBatchResponse.class });
final SObjectBatchResponse response = (SObjectBatchResponse) xStream.fromXML(xml);
assertNotNull("Response should be parsed", response);
assertFalse("It should not have errors", response.hasErrors());
final List<SObjectBatchResult> results = response.getResults();
assertEquals("It should contain 2 results", 2, results.size());
final SObjectBatchResult firstResult = results.get(0);
assertEquals("First result should have status code of 204", 204, firstResult.getStatusCode());
assertTrue("First result contain no data", ((Map) firstResult.getResult()).isEmpty());
final SObjectBatchResult secondResult = results.get(1);
assertEquals("Second result should have status code of 200", 200, secondResult.getStatusCode());
@SuppressWarnings("unchecked") final Map<String, Object> secondResultMap = (Map<String, Object>) secondResult.getResult();
@SuppressWarnings("unchecked") final Map<String, Object> account = (Map<String, Object>) secondResultMap.get("Account");
@SuppressWarnings("unchecked") final Map<String, String> attributes = (Map<String, String>) account.get("attributes");
assertEquals("Second result data should have attribute type set to `Account`", "Account", attributes.get("type"));
assertEquals("Second result data should have attribute url set as expected", "/services/data/v34.0/sobjects/Account/001D000000K0fXOIAZ", attributes.get("url"));
assertEquals("Second result data should have `NewName` set as expected", "NewName", account.get("Name"));
assertEquals("Second result data should have `BillingPostalCode` set as expected", "94105", account.get("BillingPostalCode"));
assertEquals("Second result data should have `Id` set as expected", "001D000000K0fXOIAZ", account.get("Id"));
}
use of com.thoughtworks.xstream.XStream in project camel by apache.
the class SObjectBatchTest method shouldSerializeToXml.
@Test
public void shouldSerializeToXml() {
final String xml = //
"<batch>\n" + //
" <batchRequests>\n" + //
" <batchRequest>\n" + //
" <method>POST</method>\n" + //
" <url>v37.0/sobjects/Account/</url>\n" + //
" <richInput>\n" + //
" <Account>\n" + //
" <Name>NewAccountName</Name>\n" + //
" <Industry>Environmental</Industry>\n" + //
" </Account>\n" + //
" </richInput>\n" + //
" </batchRequest>\n" + //
" <batchRequest>\n" + //
" <method>DELETE</method>\n" + //
" <url>v37.0/sobjects/Account/001D000000K0fXOIAZ</url>\n" + //
" </batchRequest>\n" + //
" <batchRequest>\n" + //
" <method>GET</method>\n" + //
" <url>v37.0/sobjects/Account/001D000000K0fXOIAZ?fields=Name,BillingPostalCode</url>\n" + //
" </batchRequest>\n" + //
" <batchRequest>\n" + //
" <method>GET</method>\n" + //
" <url>v37.0/sobjects/Account/EPK/12345</url>\n" + //
" </batchRequest>\n" + //
" <batchRequest>\n" + //
" <method>GET</method>\n" + //
" <url>v37.0/sobjects/Account/001D000000K0fXOIAZ/CreatedBy?fields=Name</url>\n" + //
" </batchRequest>\n" + //
" <batchRequest>\n" + //
" <method>GET</method>\n" + //
" <url>v37.0/limits/</url>\n" + //
" </batchRequest>\n" + //
" <batchRequest>\n" + //
" <method>PATCH</method>\n" + //
" <url>v37.0/sobjects/Account/001D000000K0fXOIAZ</url>\n" + //
" <richInput>\n" + //
" <Account>\n" + //
" <Name>NewName</Name>\n" + //
" <AccountNumber>AC12345</AccountNumber>\n" + //
" </Account>\n" + //
" </richInput>\n" + //
" </batchRequest>\n" + //
" <batchRequest>\n" + //
" <method>PATCH</method>\n" + //
" <url>v37.0/sobjects/Account/EPK/12345</url>\n" + //
" <richInput>\n" + //
" <Account>\n" + //
" <Name>NewName</Name>\n" + //
" </Account>\n" + //
" </richInput>\n" + //
" </batchRequest>\n" + //
" <batchRequest>\n" + //
" <method>PATCH</method>\n" + //
" <url>v37.0/sobjects/Account/EPK/12345</url>\n" + //
" <richInput>\n" + //
" <Account>\n" + //
" <Name>NewName</Name>\n" + //
" </Account>\n" + //
" </richInput>\n" + //
" </batchRequest>\n" + //
" <batchRequest>\n" + //
" <method>PATCH</method>\n" + //
" <url>v37.0/some/url</url>\n" + //
" </batchRequest>\n" + //
" <batchRequest>\n" + //
" <method>GET</method>\n" + //
" <url>v37.0/query/?q=SELECT Name FROM Account</url>\n" + //
" </batchRequest>\n" + //
" <batchRequest>\n" + //
" <method>GET</method>\n" + //
" <url>v37.0/queryAll/?q=SELECT Name FROM Account</url>\n" + //
" </batchRequest>\n" + //
" <batchRequest>\n" + //
" <method>GET</method>\n" + //
" <url>v37.0/search/?q=FIND {joe}</url>\n" + //
" </batchRequest>\n" + //
" </batchRequests>\n" + "</batch>";
final PureJavaReflectionProvider reflectionProvider = new PureJavaReflectionProvider(new FieldDictionary(new AnnotationFieldKeySorter()));
final XStream xStream = new XStream(reflectionProvider);
xStream.aliasSystemAttribute(null, "class");
xStream.processAnnotations(SObjectBatch.class);
xStream.processAnnotations(batch.objectTypes());
final String serialized = xStream.toXML(batch);
assertEquals("Should serialize as expected by Salesforce", xml, serialized);
}
use of com.thoughtworks.xstream.XStream in project camel by apache.
the class MultiSelectPicklistXmlTest method beforeClass.
@BeforeClass
public static void beforeClass() throws Exception {
xStream = new XStream();
xStream.processAnnotations(MSPTest.class);
}
Aggregations