use of ddf.catalog.data.BinaryContent in project ddf by codice.
the class TestGmdTransformer method testMetacardTransformNullMetacard.
@Test
public void testMetacardTransformNullMetacard() throws IOException, CatalogTransformerException {
BinaryContent content = new GmdTransformer(gmdMetacardType).transform((Metacard) null, null);
String xml = IOUtils.toString(content.getInputStream());
assertThat(xml.trim(), is(XML_DECLARATION));
}
use of ddf.catalog.data.BinaryContent in project ddf by codice.
the class TestCswQueryResponseTransformer method testMarshalAcknowledgement.
@Test
public void testMarshalAcknowledgement() throws WebApplicationException, IOException, JAXBException, CatalogTransformerException {
GetRecordsType query = new GetRecordsType();
query.setResultType(ResultType.VALIDATE);
query.setMaxRecords(BigInteger.valueOf(6));
query.setStartPosition(BigInteger.valueOf(4));
SourceResponse sourceResponse = createSourceResponse(query, 22);
Map<String, Serializable> args = new HashMap<>();
args.put(CswConstants.RESULT_TYPE_PARAMETER, ResultType.VALIDATE);
args.put(CswConstants.GET_RECORDS, query);
BinaryContent content = transformer.transform(sourceResponse, args);
String xml = new String(content.getByteArray());
JAXBElement<?> jaxb = (JAXBElement<?>) getJaxBContext().createUnmarshaller().unmarshal(new ByteArrayInputStream(xml.getBytes("UTF-8")));
assertThat(jaxb.getValue(), is(instanceOf(AcknowledgementType.class)));
AcknowledgementType response = (AcknowledgementType) jaxb.getValue();
assertThat(response.getEchoedRequest().getAny(), is(instanceOf(JAXBElement.class)));
JAXBElement<?> jaxB = (JAXBElement<?>) response.getEchoedRequest().getAny();
assertThat(jaxB.getValue(), is(instanceOf(GetRecordsType.class)));
}
use of ddf.catalog.data.BinaryContent in project ddf by codice.
the class TestCswQueryResponseTransformer method whenQueryByIdThenExpectOnlyOneXMLNode.
@Test
public void whenQueryByIdThenExpectOnlyOneXMLNode() throws CatalogTransformerException, IOException {
// when
when(mockPrintWriterProvider.build((Class<Metacard>) notNull())).thenReturn(mockPrintWriter);
when(mockPrintWriter.makeString()).thenReturn(new String());
when(mockSourceResponse.getResults()).thenReturn(Collections.emptyList());
when(mockSourceResponse.getRequest()).thenReturn(mockQueryRequest);
when(mockQueryRequest.getQuery()).thenReturn(mockQuery);
when(mockArguments.get(CswConstants.RESULT_TYPE_PARAMETER)).thenReturn(ResultType.RESULTS);
when(mockArguments.get(CswConstants.IS_BY_ID_QUERY)).thenReturn(true);
when(mockTransformerManager.getTransformerBySchema(anyString())).thenReturn(mockMetacardTransformer);
// given
transformer.init();
BinaryContent bc = transformer.transform(mockSourceResponse, mockArguments);
transformer.destroy();
// then
ArgumentCaptor<String> strArgCaptor = ArgumentCaptor.forClass(String.class);
verify(mockPrintWriter, times(1)).startNode(strArgCaptor.capture());
List<String> values = strArgCaptor.getAllValues();
assertThat("Missing root GetRecordByIdResponse node.", values.get(0), is(CswQueryResponseTransformer.RECORD_BY_ID_RESPONSE_QNAME));
}
use of ddf.catalog.data.BinaryContent in project ddf by codice.
the class TestGmdTransformer method testMetacardTransformNoDeclaration.
@Test
public void testMetacardTransformNoDeclaration() throws IOException, CatalogTransformerException {
Metacard metacard = getTestMetacard();
Map<String, Serializable> args = new HashMap<>();
args.put(CswConstants.OMIT_XML_DECLARATION, true);
BinaryContent content = new GmdTransformer(gmdMetacardType).transform(metacard, args);
String xml = IOUtils.toString(content.getInputStream());
assertThat(xml, not(startsWith(XML_DECLARATION)));
}
use of ddf.catalog.data.BinaryContent in project ddf by codice.
the class TestAtomTransformer method getXmlMetacardTransformerStub.
protected MetacardTransformer getXmlMetacardTransformerStub() throws IOException, CatalogTransformerException {
MetacardTransformer metacardTransformer = mock(MetacardTransformer.class);
BinaryContent metacardTransformation = mock(BinaryContent.class);
when(metacardTransformation.getByteArray()).thenReturn("<sample:note xmlns:sample=\"http://www.lockheedmartin.com/schema/sample\"><to>me</to><from>you</from></sample:note>".getBytes());
when(metacardTransformer.transform(isA(Metacard.class), isA(Map.class))).thenReturn(metacardTransformation);
return metacardTransformer;
}
Aggregations