use of ddf.catalog.data.BinaryContent in project ddf by codice.
the class CswQueryResponseTransformer method transform.
@Override
public BinaryContent transform(SourceResponse sourceResponse, Map<String, Serializable> arguments) throws CatalogTransformerException {
validateInput(sourceResponse, arguments);
CswRecordCollection recordCollection = buildCollection(sourceResponse, arguments);
ByteArrayInputStream bais;
if (ResultType.VALIDATE.equals(recordCollection.getResultType())) {
ByteArrayOutputStream baos = writeAcknowledgement(recordCollection.getRequest());
bais = new ByteArrayInputStream(baos.toByteArray());
} else {
// "catches" recordCollection.getResultType() == null
List<Result> results = sourceResponse.getResults();
String xmlString = convert(recordCollection, results, arguments);
bais = new ByteArrayInputStream(xmlString.getBytes(StandardCharsets.UTF_8));
}
BinaryContent transformedContent = new BinaryContentImpl(bais, CswRecordConverter.XML_MIME_TYPE);
return transformedContent;
}
use of ddf.catalog.data.BinaryContent in project ddf by codice.
the class TestCswRecordConverter method testMetacardTransformOmitXmlDeclaration.
@Test
public void testMetacardTransformOmitXmlDeclaration() throws IOException, JAXBException, SAXException, XpathException, CatalogTransformerException {
Metacard metacard = getTestMetacard();
Map<String, Serializable> args = new HashMap<>();
args.put(CswConstants.WRITE_NAMESPACES, true);
args.put(CswConstants.OMIT_XML_DECLARATION, true);
BinaryContent content = converter.transform(metacard, args);
String xml = IOUtils.toString(content.getInputStream());
assertThat(xml, not(containsString("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>")));
XMLUnit.setIgnoreWhitespace(true);
assertXMLEqual(getControlRecord(), xml);
}
use of ddf.catalog.data.BinaryContent in project ddf by codice.
the class TestCswRecordConverter method testMetacardTransformOmitNamespaces.
@Test
public void testMetacardTransformOmitNamespaces() throws IOException, JAXBException, SAXException, XpathException, CatalogTransformerException {
Metacard metacard = getTestMetacard();
Map<String, Serializable> args = new HashMap<>();
args.put(CswConstants.WRITE_NAMESPACES, false);
BinaryContent content = converter.transform(metacard, args);
String xml = IOUtils.toString(content.getInputStream());
assertThat(xml, containsString("<csw:Record>"));
}
use of ddf.catalog.data.BinaryContent in project ddf by codice.
the class MetacardBackupPluginTest method testGetContentBytes.
@Test
public void testGetContentBytes() throws Exception {
BinaryContent binaryContent = mock(BinaryContent.class);
byte[] content = { 'a' };
when(binaryContent.getByteArray()).thenReturn(content);
byte[] bytes = metacardBackupPlugin.getContentBytes(binaryContent, "metacard");
assertThat(bytes, equalTo(content));
}
use of ddf.catalog.data.BinaryContent in project ddf by codice.
the class MetacardBackupPluginTest method setUp.
@SuppressWarnings("unchecked")
@Before
public void setUp() throws Exception {
metacardTransformer = mock(MetacardTransformer.class);
BinaryContent binaryContent = new BinaryContentImpl(new ByteArrayInputStream(XML_METADATA.getBytes(StandardCharsets.UTF_8)));
when(metacardTransformer.transform(any(Metacard.class), anyMap())).thenReturn(binaryContent);
doThrow(new MetacardBackupException("Not Implemented")).when(mockProvider).store(any(), any());
doThrow(new MetacardBackupException("Not Implemented")).when(mockProvider).delete(any());
doReturn(MOCK_ID).when(mockProvider).getId();
metacardBackupPlugin = new MetacardBackupPlugin();
metacardBackupPlugin.setMetacardTransformerId(METACARD_TRANSFORMER_ID);
metacardBackupPlugin.setMetacardTransformer(metacardTransformer);
createRequest = generateProcessRequest(ProcessCreateItem.class, true);
updateRequest = generateProcessRequest(ProcessUpdateItem.class, true);
deleteRequest = generateDeleteRequest();
fileStorageProvider.setId(FILE_STORAGE_PROVIDER_ID);
fileStorageProvider.setOutputDirectory(OUTPUT_DIRECTORY);
metacardBackupPlugin.setMetacardOutputProviderIds(Collections.singletonList(FILE_STORAGE_PROVIDER_ID));
metacardBackupPlugin.setStorageBackupPlugins(Arrays.asList(new MetacardBackupStorageProvider[] { fileStorageProvider }));
}
Aggregations