Search in sources :

Example 21 with MarshallingContext

use of com.thoughtworks.xstream.converters.MarshallingContext in project ddf by codice.

the class TestCswRecordConverter method testMarshalBriefRecord.

@Test
public void testMarshalBriefRecord() throws IOException, JAXBException, SAXException, XpathException {
    Metacard metacard = getTestMetacard();
    StringWriter stringWriter = new StringWriter();
    PrettyPrintWriter writer = new PrettyPrintWriter(stringWriter);
    MarshallingContext context = new TreeMarshaller(writer, null, null);
    context.put(CswConstants.ELEMENT_SET_TYPE, ElementSetType.BRIEF);
    converter.marshal(metacard, writer, context);
    String xml = stringWriter.toString();
    assertThat(xml, containsString(CswConstants.CSW_BRIEF_RECORD));
    assertRecordXml(xml, metacard, BRIEF);
}
Also used : TreeMarshaller(com.thoughtworks.xstream.core.TreeMarshaller) Metacard(ddf.catalog.data.Metacard) StringWriter(java.io.StringWriter) PrettyPrintWriter(com.thoughtworks.xstream.io.xml.PrettyPrintWriter) MarshallingContext(com.thoughtworks.xstream.converters.MarshallingContext) Matchers.containsString(org.hamcrest.Matchers.containsString) Test(org.junit.Test)

Example 22 with MarshallingContext

use of com.thoughtworks.xstream.converters.MarshallingContext in project ddf by codice.

the class TestCswRecordConverter method testMarshalRecordWithNamespaces.

@Test
public void testMarshalRecordWithNamespaces() throws IOException, JAXBException, SAXException, XpathException {
    Metacard metacard = getTestMetacard();
    StringWriter stringWriter = new StringWriter();
    PrettyPrintWriter writer = new PrettyPrintWriter(stringWriter);
    MarshallingContext context = new TreeMarshaller(writer, null, null);
    context.put(CswConstants.WRITE_NAMESPACES, true);
    converter.marshal(metacard, writer, context);
    String xml = stringWriter.toString();
    XMLUnit.setIgnoreWhitespace(true);
    assertXMLEqual(getControlRecord(), xml);
}
Also used : TreeMarshaller(com.thoughtworks.xstream.core.TreeMarshaller) Metacard(ddf.catalog.data.Metacard) StringWriter(java.io.StringWriter) PrettyPrintWriter(com.thoughtworks.xstream.io.xml.PrettyPrintWriter) MarshallingContext(com.thoughtworks.xstream.converters.MarshallingContext) Matchers.containsString(org.hamcrest.Matchers.containsString) Test(org.junit.Test)

Example 23 with MarshallingContext

use of com.thoughtworks.xstream.converters.MarshallingContext in project ddf by codice.

the class TestCswRecordConverter method testMarshalRecord.

@Test
public void testMarshalRecord() throws IOException, JAXBException, SAXException, XpathException {
    Metacard metacard = getTestMetacard();
    StringWriter stringWriter = new StringWriter();
    PrettyPrintWriter writer = new PrettyPrintWriter(stringWriter);
    MarshallingContext context = new TreeMarshaller(writer, null, null);
    converter.marshal(metacard, writer, context);
    String xml = stringWriter.toString();
    assertThat(xml, containsString(CswConstants.CSW_RECORD));
    assertRecordXml(xml, metacard, FULL);
}
Also used : TreeMarshaller(com.thoughtworks.xstream.core.TreeMarshaller) Metacard(ddf.catalog.data.Metacard) StringWriter(java.io.StringWriter) PrettyPrintWriter(com.thoughtworks.xstream.io.xml.PrettyPrintWriter) MarshallingContext(com.thoughtworks.xstream.converters.MarshallingContext) Matchers.containsString(org.hamcrest.Matchers.containsString) Test(org.junit.Test)

Example 24 with MarshallingContext

use of com.thoughtworks.xstream.converters.MarshallingContext in project ddf by codice.

the class TestCswRecordConverter method testMarshalSummaryRecord.

@Test
public void testMarshalSummaryRecord() throws IOException, JAXBException, SAXException, XpathException {
    Metacard metacard = getTestMetacard();
    StringWriter stringWriter = new StringWriter();
    PrettyPrintWriter writer = new PrettyPrintWriter(stringWriter);
    MarshallingContext context = new TreeMarshaller(writer, null, null);
    context.put(CswConstants.ELEMENT_SET_TYPE, ElementSetType.SUMMARY);
    converter.marshal(metacard, writer, context);
    String xml = stringWriter.toString();
    assertThat(xml, containsString(CswConstants.CSW_SUMMARY_RECORD));
    assertRecordXml(xml, metacard, SUMMARY);
}
Also used : TreeMarshaller(com.thoughtworks.xstream.core.TreeMarshaller) Metacard(ddf.catalog.data.Metacard) StringWriter(java.io.StringWriter) PrettyPrintWriter(com.thoughtworks.xstream.io.xml.PrettyPrintWriter) MarshallingContext(com.thoughtworks.xstream.converters.MarshallingContext) Matchers.containsString(org.hamcrest.Matchers.containsString) Test(org.junit.Test)

Example 25 with MarshallingContext

use of com.thoughtworks.xstream.converters.MarshallingContext in project ddf by codice.

the class TestGetRecordsResponseConverter method testMarshalRecordCollectionById.

@Ignore
public void testMarshalRecordCollectionById() throws UnsupportedEncodingException, JAXBException {
    final int totalResults = 2;
    XStream xstream = createXStream(CswConstants.GET_RECORD_BY_ID_RESPONSE);
    CswRecordCollection collection = createCswRecordCollection(null, totalResults);
    collection.setById(true);
    ArgumentCaptor<MarshallingContext> captor = ArgumentCaptor.forClass(MarshallingContext.class);
    String xml = xstream.toXML(collection);
    // Verify the context arguments were set correctly
    verify(mockProvider, times(totalResults)).marshal(any(Object.class), any(HierarchicalStreamWriter.class), captor.capture());
    MarshallingContext context = captor.getValue();
    assertThat(context, not(nullValue()));
    assertThat(context.get(CswConstants.OUTPUT_SCHEMA_PARAMETER), is(CswConstants.CSW_OUTPUT_SCHEMA));
    assertThat(context.get(CswConstants.ELEMENT_SET_TYPE), is(nullValue()));
    assertThat(context.get(CswConstants.ELEMENT_NAMES), is(nullValue()));
    JAXBElement<GetRecordByIdResponseType> jaxb = (JAXBElement<GetRecordByIdResponseType>) getJaxBContext().createUnmarshaller().unmarshal(new ByteArrayInputStream(xml.getBytes("UTF-8")));
    GetRecordByIdResponseType response = jaxb.getValue();
    // Assert the GetRecordsResponse elements and attributes
    assertThat(response, not(nullValue()));
}
Also used : GetRecordByIdResponseType(net.opengis.cat.csw.v_2_0_2.GetRecordByIdResponseType) HierarchicalStreamWriter(com.thoughtworks.xstream.io.HierarchicalStreamWriter) ByteArrayInputStream(java.io.ByteArrayInputStream) XStream(com.thoughtworks.xstream.XStream) CswRecordCollection(org.codice.ddf.spatial.ogc.csw.catalog.common.CswRecordCollection) MarshallingContext(com.thoughtworks.xstream.converters.MarshallingContext) Matchers.anyString(org.mockito.Matchers.anyString) JAXBElement(javax.xml.bind.JAXBElement) Ignore(jdk.nashorn.internal.ir.annotations.Ignore)

Aggregations

MarshallingContext (com.thoughtworks.xstream.converters.MarshallingContext)38 Test (org.junit.Test)23 HierarchicalStreamWriter (com.thoughtworks.xstream.io.HierarchicalStreamWriter)22 TreeMarshaller (com.thoughtworks.xstream.core.TreeMarshaller)18 StringWriter (java.io.StringWriter)18 XStream (com.thoughtworks.xstream.XStream)12 PrettyPrintWriter (com.thoughtworks.xstream.io.xml.PrettyPrintWriter)12 Metacard (ddf.catalog.data.Metacard)12 ByteArrayInputStream (java.io.ByteArrayInputStream)12 JAXBElement (javax.xml.bind.JAXBElement)10 CswRecordCollection (org.codice.ddf.spatial.ogc.csw.catalog.common.CswRecordCollection)10 GetRecordsResponseType (net.opengis.cat.csw.v_2_0_2.GetRecordsResponseType)8 GetRecordsType (net.opengis.cat.csw.v_2_0_2.GetRecordsType)8 ObjectFactory (net.opengis.cat.csw.v_2_0_2.ObjectFactory)8 QueryType (net.opengis.cat.csw.v_2_0_2.QueryType)8 SearchResultsType (net.opengis.cat.csw.v_2_0_2.SearchResultsType)8 Matchers.containsString (org.hamcrest.Matchers.containsString)8 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)7 Matchers.anyString (org.mockito.Matchers.anyString)7 WstxDriver (com.thoughtworks.xstream.io.xml.WstxDriver)6