Search in sources :

Example 21 with XStream

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;
}
Also used : AnnotationFieldKeySorter(org.apache.camel.component.salesforce.api.dto.AnnotationFieldKeySorter) TreeMarshallingStrategy(com.thoughtworks.xstream.core.TreeMarshallingStrategy) CompactWriter(com.thoughtworks.xstream.io.xml.CompactWriter) XppDriver(com.thoughtworks.xstream.io.xml.XppDriver) XStream(com.thoughtworks.xstream.XStream) FieldDictionary(com.thoughtworks.xstream.converters.reflection.FieldDictionary) DateTimeConverter(org.apache.camel.component.salesforce.api.utils.DateTimeConverter) NoNameCoder(com.thoughtworks.xstream.io.naming.NoNameCoder) HierarchicalStreamWriter(com.thoughtworks.xstream.io.HierarchicalStreamWriter) ObjectWriter(com.fasterxml.jackson.databind.ObjectWriter) Writer(java.io.Writer) CompactWriter(com.thoughtworks.xstream.io.xml.CompactWriter) PureJavaReflectionProvider(com.thoughtworks.xstream.converters.reflection.PureJavaReflectionProvider)

Example 22 with 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);
}
Also used : CompactWriter(com.thoughtworks.xstream.io.xml.CompactWriter) XppDriver(com.thoughtworks.xstream.io.xml.XppDriver) HierarchicalStreamWriter(com.thoughtworks.xstream.io.HierarchicalStreamWriter) XStream(com.thoughtworks.xstream.XStream) DateTimeConverter(org.apache.camel.component.salesforce.api.utils.DateTimeConverter) NoNameCoder(com.thoughtworks.xstream.io.naming.NoNameCoder) HierarchicalStreamWriter(com.thoughtworks.xstream.io.HierarchicalStreamWriter) Writer(java.io.Writer) CompactWriter(com.thoughtworks.xstream.io.xml.CompactWriter) Test(org.junit.Test)

Example 23 with XStream

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"));
}
Also used : XStream(com.thoughtworks.xstream.XStream) Map(java.util.Map) Test(org.junit.Test)

Example 24 with XStream

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);
}
Also used : AnnotationFieldKeySorter(org.apache.camel.component.salesforce.api.dto.AnnotationFieldKeySorter) XStream(com.thoughtworks.xstream.XStream) FieldDictionary(com.thoughtworks.xstream.converters.reflection.FieldDictionary) PureJavaReflectionProvider(com.thoughtworks.xstream.converters.reflection.PureJavaReflectionProvider) Test(org.junit.Test)

Example 25 with XStream

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);
}
Also used : XStream(com.thoughtworks.xstream.XStream) BeforeClass(org.junit.BeforeClass)

Aggregations

XStream (com.thoughtworks.xstream.XStream)183 Test (org.junit.Test)54 IOException (java.io.IOException)31 InputStream (java.io.InputStream)28 WstxDriver (com.thoughtworks.xstream.io.xml.WstxDriver)22 Metacard (ddf.catalog.data.Metacard)21 DomDriver (com.thoughtworks.xstream.io.xml.DomDriver)16 HashMap (java.util.HashMap)14 ByteArrayInputStream (java.io.ByteArrayInputStream)12 Matchers.anyString (org.mockito.Matchers.anyString)11 HierarchicalStreamWriter (com.thoughtworks.xstream.io.HierarchicalStreamWriter)10 CswRecordCollection (org.codice.ddf.spatial.ogc.csw.catalog.common.CswRecordCollection)10 GmlGeometryConverter (org.codice.ddf.spatial.ogc.wfs.catalog.converter.impl.GmlGeometryConverter)8 XStreamException (com.thoughtworks.xstream.XStreamException)7 MarshallingContext (com.thoughtworks.xstream.converters.MarshallingContext)7 StaxDriver (com.thoughtworks.xstream.io.xml.StaxDriver)7 FileNotFoundException (java.io.FileNotFoundException)7 ArrayList (java.util.ArrayList)7 ForbiddenClassException (com.thoughtworks.xstream.security.ForbiddenClassException)6 FileWriter (java.io.FileWriter)6