use of ddf.catalog.transform.MetacardTransformer in project ddf by codice.
the class TestAtomTransformer method testNoCreatedDate.
@Test
public void testNoCreatedDate() throws IOException, CatalogTransformerException, XpathException, SAXException {
// given
AtomTransformer transformer = new AtomTransformer();
MetacardTransformer metacardTransformer = getXmlMetacardTransformerStub();
transformer.setMetacardTransformer(metacardTransformer);
setDefaultSystemConfiguration();
SourceResponse response = mock(SourceResponse.class);
when(response.getHits()).thenReturn(new Long(1));
when(response.getRequest()).thenReturn(getStubRequest());
ResultImpl result1 = new ResultImpl();
MetacardStub metacard = new MetacardStub("");
metacard.setId(SAMPLE_ID);
metacard.setCreatedDate(null);
result1.setMetacard(metacard);
when(response.getResults()).thenReturn(Arrays.asList((Result) result1));
result1.setRelevanceScore(0.3345);
// 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);
assertXpathNotExists("atom:feed/atom:entry/atom:published", output);
}
use of ddf.catalog.transform.MetacardTransformer in project ddf by codice.
the class TestAtomTransformer method testNoModifiedDate.
@Test
public void testNoModifiedDate() throws IOException, CatalogTransformerException, XpathException, SAXException {
// given
AtomTransformer transformer = new AtomTransformer();
MetacardTransformer metacardTransformer = getXmlMetacardTransformerStub();
transformer.setMetacardTransformer(metacardTransformer);
setDefaultSystemConfiguration();
SourceResponse response = mock(SourceResponse.class);
when(response.getHits()).thenReturn(new Long(1));
when(response.getRequest()).thenReturn(getStubRequest());
ResultImpl result1 = new ResultImpl();
MetacardStub metacard = new MetacardStub("");
metacard.setId(SAMPLE_ID);
metacard.setModifiedDate(null);
result1.setMetacard(metacard);
when(response.getResults()).thenReturn(Arrays.asList((Result) result1));
result1.setRelevanceScore(0.3345);
// 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);
assertXpathExists("atom:feed/atom:entry/atom:updated", output);
}
use of ddf.catalog.transform.MetacardTransformer in project ddf by codice.
the class TestAtomTransformer method testItemsPerPageNegativeInteger.
@Test
public void testItemsPerPageNegativeInteger() throws IOException, CatalogTransformerException, XpathException, SAXException {
// given
AtomTransformer transformer = new AtomTransformer();
MetacardTransformer metacardTransformer = getXmlMetacardTransformerStub();
transformer.setMetacardTransformer(metacardTransformer);
setDefaultSystemConfiguration();
SourceResponse response = mock(SourceResponse.class);
when(response.getHits()).thenReturn(new Long(1));
QueryImpl query = new QueryImpl(FILTER_BUILDER.attribute(Metacard.METADATA).text("you"));
query.setPageSize(-1);
query.setStartIndex(2);
query.setRequestsTotalResultsCount(true);
QueryRequestImpl queryRequestImpl = new QueryRequestImpl(query);
when(response.getRequest()).thenReturn(queryRequestImpl);
ResultImpl result1 = new ResultImpl();
MetacardStub metacard = new MetacardStub("");
metacard.setId(SAMPLE_ID);
result1.setMetacard(metacard);
when(response.getResults()).thenReturn(Arrays.asList((Result) result1));
// 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("1", "/atom:feed/os:itemsPerPage", output);
}
use of ddf.catalog.transform.MetacardTransformer in project ddf by codice.
the class DumpCommand method exportMetacard.
private void exportMetacard(File dumpLocation, Metacard metacard) throws IOException, CatalogTransformerException {
if (SERIALIZED_OBJECT_ID.matches(transformerId)) {
try (ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream(getOutputFile(dumpLocation, metacard)))) {
oos.writeObject(new MetacardImpl(metacard));
oos.flush();
}
} else {
BinaryContent binaryContent;
if (metacard != null) {
try (FileOutputStream fos = new FileOutputStream(getOutputFile(dumpLocation, metacard))) {
for (MetacardTransformer transformer : transformers) {
binaryContent = transformer.transform(metacard, new HashMap<>());
if (binaryContent != null) {
fos.write(binaryContent.getByteArray());
break;
}
}
}
}
}
}
use of ddf.catalog.transform.MetacardTransformer in project ddf by codice.
the class AtomTransformerTest method testNoModifiedDate.
@Test
public void testNoModifiedDate() throws IOException, CatalogTransformerException, XpathException, SAXException {
// given
AtomTransformer transformer = new AtomTransformer();
MetacardTransformer metacardTransformer = getXmlMetacardTransformerStub();
transformer.setMetacardTransformer(metacardTransformer);
setDefaultSystemConfiguration();
SourceResponse response = mock(SourceResponse.class);
when(response.getHits()).thenReturn(new Long(1));
when(response.getRequest()).thenReturn(getStubRequest());
ResultImpl result1 = new ResultImpl();
MetacardStub metacard = new MetacardStub("");
metacard.setId(SAMPLE_ID);
metacard.setModifiedDate(null);
result1.setMetacard(metacard);
when(response.getResults()).thenReturn(Arrays.asList((Result) result1));
result1.setRelevanceScore(0.3345);
// 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);
assertXpathExists("atom:feed/atom:entry/atom:updated", output);
}
Aggregations