use of ddf.catalog.data.BinaryContent in project ddf by codice.
the class TestAtomTransformer method testMetacardTransformerBytesZero.
@Test
public void testMetacardTransformerBytesZero() throws IOException, CatalogTransformerException, XpathException, SAXException {
// given
MetacardTransformer metacardTransformer = mock(MetacardTransformer.class);
BinaryContent metacardTransformation = mock(BinaryContent.class);
when(metacardTransformation.getByteArray()).thenReturn(new byte[0]);
when(metacardTransformer.transform(isA(Metacard.class), isNull(Map.class))).thenReturn(metacardTransformation);
AtomTransformer transformer = getConfiguredAtomTransformer(metacardTransformer, true);
SourceResponse response = getSourceResponseStub(SAMPLE_ID, null);
// when
BinaryContent binaryContent = transformer.transform(response, null);
// then
assertThat(binaryContent.getMimeType(), is(AtomTransformer.MIME_TYPE));
byte[] bytes = binaryContent.getByteArray();
String output = new String(bytes);
assertFeedCompliant(output);
assertEntryCompliant(output);
validateAgainstAtomSchema(bytes);
assertXpathEvaluatesTo(TEXT_TYPE, "/atom:feed/atom:entry/atom:content/@type", output);
assertXpathEvaluatesTo(SAMPLE_ID, "/atom:feed/atom:entry/atom:content", output);
}
use of ddf.catalog.data.BinaryContent in project ddf by codice.
the class TestAtomTransformer method testMetacardTransformerThrowsIoException.
@Test
public void testMetacardTransformerThrowsIoException() throws IOException, CatalogTransformerException, XpathException, SAXException {
// given
MetacardTransformer metacardTransformer = mock(MetacardTransformer.class);
BinaryContent metacardTransformation = mock(BinaryContent.class);
when(metacardTransformation.getByteArray()).thenThrow(IOException.class);
when(metacardTransformer.transform(isA(Metacard.class), isNull(Map.class))).thenReturn(metacardTransformation);
AtomTransformer transformer = getConfiguredAtomTransformer(metacardTransformer, true);
SourceResponse response = getSourceResponseStub(SAMPLE_ID, null);
// when
BinaryContent binaryContent = transformer.transform(response, null);
// then
assertThat(binaryContent.getMimeType(), is(AtomTransformer.MIME_TYPE));
byte[] bytes = binaryContent.getByteArray();
String output = new String(bytes);
assertFeedCompliant(output);
assertEntryCompliant(output);
validateAgainstAtomSchema(bytes);
assertXpathEvaluatesTo(TEXT_TYPE, "/atom:feed/atom:entry/atom:content/@type", output);
assertXpathEvaluatesTo(SAMPLE_ID, "/atom:feed/atom:entry/atom:content", output);
}
use of ddf.catalog.data.BinaryContent in project ddf by codice.
the class TestAtomTransformer method testNoMetacardTransformer.
@Test
public void testNoMetacardTransformer() throws IOException, CatalogTransformerException, XpathException, SAXException {
// given
AtomTransformer transformer = getConfiguredAtomTransformer(null, true);
SourceResponse response = getSourceResponseStub(SAMPLE_ID, null);
// when
BinaryContent binaryContent = transformer.transform(response, null);
// then
assertThat(binaryContent.getMimeType(), is(AtomTransformer.MIME_TYPE));
byte[] bytes = binaryContent.getByteArray();
String output = new String(bytes);
assertFeedCompliant(output);
assertEntryCompliant(output);
validateAgainstAtomSchema(bytes);
assertXpathEvaluatesTo(TEXT_TYPE, "/atom:feed/atom:entry/atom:content/@type", output);
assertXpathEvaluatesTo(SAMPLE_ID, "/atom:feed/atom:entry/atom:content", output);
}
use of ddf.catalog.data.BinaryContent in project ddf by codice.
the class TestAtomTransformer method testNoDdfConfiguration.
/**
* Tests what happens when no system configuration can be found.
*
* @throws IOException
* @throws CatalogTransformerException
* @throws XpathException
* @throws SAXException
*/
@Test
public void testNoDdfConfiguration() throws IOException, CatalogTransformerException, XpathException, SAXException {
// given
MetacardTransformer metacardTransformer = getXmlMetacardTransformerStub();
String currentSiteName = System.getProperty(SystemInfo.SITE_NAME);
try {
System.setProperty(SystemInfo.SITE_NAME, "");
AtomTransformer transformer = new AtomTransformer();
transformer.setMetacardTransformer(metacardTransformer);
SourceResponse response = getSourceResponseStub(SAMPLE_ID, null);
// when
BinaryContent binaryContent = transformer.transform(response, null);
// then
assertThat(binaryContent.getMimeType(), is(AtomTransformer.MIME_TYPE));
byte[] bytes = binaryContent.getByteArray();
/* used to visualize */
IOUtils.write(bytes, new FileOutputStream(new File(TARGET_FOLDER + getMethodName() + ATOM_EXTENSION)));
String output = new String(bytes);
assertFeedCompliant(output);
assertEntryCompliant(output);
validateAgainstAtomSchema(bytes);
assertXpathNotExists("/atom:feed/atom:generator", output);
assertXpathEvaluatesTo(AtomTransformer.DEFAULT_AUTHOR, "/atom:feed/atom:author/atom:name", output);
} finally {
if (currentSiteName != null) {
System.setProperty(SystemInfo.SITE_NAME, currentSiteName);
}
}
}
use of ddf.catalog.data.BinaryContent in project ddf by codice.
the class TestResourceMetacardTransformer method testGetResource.
private void testGetResource(Metacard metacard, String filePath, MimeType mimeType, CatalogFramework framework, boolean expectSuccess) throws Exception {
ResourceMetacardTransformer resourceTransformer = new ResourceMetacardTransformer(framework);
BinaryContent binaryContent = resourceTransformer.transform(metacard, new HashMap<String, Serializable>());
byte[] fileContents = FileUtils.readFileToByteArray(new File(filePath));
byte[] contentsFromResults = IOUtils.toByteArray(binaryContent.getInputStream());
if (expectSuccess) {
assertEquals(binaryContent.getMimeTypeValue(), mimeType.toString());
assertTrue(Arrays.equals(fileContents, contentsFromResults));
}
}
Aggregations