use of ddf.catalog.data.BinaryContent in project ddf by codice.
the class CatalogFrameworkImplTest method testQueryTransform.
@Test
public void testQueryTransform() throws Exception {
BundleContext context = mock(BundleContext.class);
QueryResponseTransformer transformer = mock(QueryResponseTransformer.class);
ServiceReference reference = mock(ServiceReference.class);
ServiceReference[] serviceReferences = new ServiceReference[] { reference };
when(context.getServiceReferences(anyString(), anyString())).thenReturn(serviceReferences);
when(context.getService(isA(ServiceReference.class))).thenReturn(transformer);
when(transformer.transform(isA(SourceResponse.class), isA(Map.class))).thenReturn(new BinaryContentImpl(null));
CatalogFramework framework = this.createDummyCatalogFramework(provider, storageProvider, context, eventAdmin, true);
SourceResponse response = new SourceResponseImpl(null, null);
BinaryContent content = framework.transform(response, "NONE", new HashMap<String, Serializable>());
assertNotNull(content);
}
use of ddf.catalog.data.BinaryContent in project ddf by codice.
the class CswRecordConverter method transform.
@Override
public BinaryContent transform(Metacard metacard, Map<String, Serializable> arguments) throws CatalogTransformerException {
if (StringUtils.isNotBlank(metacard.getMetadata())) {
// Check if the metadata is csw:Record
try {
StringReader xml = new StringReader(metacard.getMetadata());
XMLEventReader reader = factory.createXMLEventReader(xml);
boolean rootFound = false;
while (reader.hasNext() && !rootFound) {
XMLEvent event = reader.nextEvent();
if (event.isStartElement()) {
rootFound = true;
QName name = event.asStartElement().getName();
if (StringUtils.equals(CswConstants.CSW_RECORD_LOCAL_NAME, name.getLocalPart()) && StringUtils.equals(CswConstants.CSW_OUTPUT_SCHEMA, name.getNamespaceURI())) {
return new BinaryContentImpl(IOUtils.toInputStream(metacard.getMetadata()), XML_MIME_TYPE);
}
}
}
} catch (Exception e) {
// Ignore and proceed with the transform.
}
}
StringWriter stringWriter = new StringWriter();
Boolean omitXmlDec = null;
if (arguments != null) {
omitXmlDec = (Boolean) arguments.get(CswConstants.OMIT_XML_DECLARATION);
}
if (omitXmlDec == null || !omitXmlDec) {
stringWriter.append("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n");
}
PrettyPrintWriter writer = new PrettyPrintWriter(stringWriter);
MarshallingContext context = new TreeMarshaller(writer, null, null);
context.put(CswConstants.WRITE_NAMESPACES, true);
copyArgumentsToContext(context, arguments);
this.marshal(metacard, writer, context);
BinaryContent transformedContent;
ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(stringWriter.toString().getBytes(StandardCharsets.UTF_8));
transformedContent = new BinaryContentImpl(byteArrayInputStream, XML_MIME_TYPE);
return transformedContent;
}
use of ddf.catalog.data.BinaryContent in project ddf by codice.
the class TestXmlResponseQueueTransformer method testMimeTypeInitException.
@Test(expected = ExceptionInInitializerError.class)
public void testMimeTypeInitException() throws IOException, CatalogTransformerException, XmlPullParserException, MimeTypeParseException {
SourceResponse response = givenSourceResponse(new MetacardStub("source1", "id1"));
PrintWriterProvider pwp = new PrintWriterProviderImpl();
MetacardMarshaller mockMetacardMarshaller = mock(MetacardMarshaller.class);
MimeType mockMimeType = mock(MimeType.class);
doThrow(new MimeTypeParseException("")).when(mockMimeType).setSubType(anyString());
XmlResponseQueueTransformer xrqt = new XmlResponseQueueTransformer(parser, FJP, pwp, mockMetacardMarshaller, mockMimeType);
xrqt.setThreshold(2);
BinaryContent bc = xrqt.transform(response, null);
// then exception
}
use of ddf.catalog.data.BinaryContent in project ddf by codice.
the class TestXmlResponseQueueTransformer method testMetacardTypeNameEmpty.
/**
* No {@link MetacardType} name should use the default name.
*
* @throws CatalogTransformerException
* @throws IOException
* @throws SAXException
* @throws XpathException
*/
@Test
public void testMetacardTypeNameEmpty() throws CatalogTransformerException, IOException, XpathException, SAXException {
// given
transformer.setThreshold(2);
SourceResponse response = givenMetacardTypeName("");
// when
BinaryContent binaryContent = transformer.transform(response, null);
// then
assertThat(binaryContent.getMimeType(), is(mimeType));
byte[] bytes = binaryContent.getByteArray();
String output = new String(bytes);
print(output, verboseDebug);
assertXpathEvaluatesTo(DEFAULT_TYPE_NAME, "/mc:metacards/mc:metacard/mc:type", output);
}
use of ddf.catalog.data.BinaryContent in project ddf by codice.
the class TestZipCompression method testCompressionWithDerivedContent.
@Test
public void testCompressionWithDerivedContent() throws Exception {
SourceResponse sourceResponse = createSourceResponseWithURISchemes(CONTENT_SCHEME, "content:id3#preview");
BinaryContent binaryContent = zipCompression.transform(sourceResponse, filePathArgument);
assertThat(binaryContent, notNullValue());
assertZipContents(binaryContent, METACARD_RESULT_LIST_WITH_CONTENT_AND_DERIVED_RESOURCES);
}
Aggregations