Search in sources :

Example 16 with BinaryContent

use of ddf.catalog.data.BinaryContent in project ddf by codice.

the class TestAtomTransformer method testNoEntries.

@Test
public void testNoEntries() throws IOException, CatalogTransformerException, XpathException, SAXException {
    // given
    AtomTransformer transformer = new AtomTransformer();
    MetacardTransformer metacardTransformer = getXmlMetacardTransformerStub();
    transformer.setMetacardTransformer(metacardTransformer);
    setDefaultSystemConfiguration();
    SourceResponse response = mock(SourceResponse.class);
    when(response.getRequest()).thenReturn(getStubRequest());
    when(response.getResults()).thenReturn(new ArrayList<Result>());
    // when
    BinaryContent binaryContent = transformer.transform(response, null);
    // then
    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);
    assertBasicFeedInfo(output, "0");
}
Also used : MetacardTransformer(ddf.catalog.transform.MetacardTransformer) SourceResponse(ddf.catalog.operation.SourceResponse) FileOutputStream(java.io.FileOutputStream) BinaryContent(ddf.catalog.data.BinaryContent) File(java.io.File) Result(ddf.catalog.data.Result) Test(org.junit.Test)

Example 17 with BinaryContent

use of ddf.catalog.data.BinaryContent in project ddf by codice.

the class TestAtomTransformer method testTotalResultsNegative.

@Test
public void testTotalResultsNegative() 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);
    assertXpathNotExists("/atom:feed/os:totalResults", output);
}
Also used : QueryImpl(ddf.catalog.operation.impl.QueryImpl) MetacardTransformer(ddf.catalog.transform.MetacardTransformer) SourceResponse(ddf.catalog.operation.SourceResponse) QueryRequestImpl(ddf.catalog.operation.impl.QueryRequestImpl) ResultImpl(ddf.catalog.data.impl.ResultImpl) BinaryContent(ddf.catalog.data.BinaryContent) Result(ddf.catalog.data.Result) Test(org.junit.Test)

Example 18 with BinaryContent

use of ddf.catalog.data.BinaryContent in project ddf by codice.

the class TestCswRecordConverter method testMarshalNullInput.

@Test
public void testMarshalNullInput() throws CatalogTransformerException {
    Metacard expectedMetacard = getTestMetacard();
    BinaryContent bc = converter.transform(expectedMetacard, null);
    assertThat(bc, notNullValue());
}
Also used : Metacard(ddf.catalog.data.Metacard) BinaryContent(ddf.catalog.data.BinaryContent) Test(org.junit.Test)

Example 19 with BinaryContent

use of ddf.catalog.data.BinaryContent in project ddf by codice.

the class TestCswRecordConverter method testMetacardTransform.

@Test
public void testMetacardTransform() throws IOException, JAXBException, SAXException, XpathException, CatalogTransformerException {
    Metacard metacard = getTestMetacard();
    Map<String, Serializable> args = new HashMap<>();
    args.put(CswConstants.WRITE_NAMESPACES, true);
    BinaryContent content = converter.transform(metacard, args);
    String xml = IOUtils.toString(content.getInputStream());
    assertThat(xml, containsString("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>"));
    XMLUnit.setIgnoreWhitespace(true);
    assertXMLEqual(getControlRecord(), xml);
}
Also used : Metacard(ddf.catalog.data.Metacard) Serializable(java.io.Serializable) HashMap(java.util.HashMap) Matchers.containsString(org.hamcrest.Matchers.containsString) BinaryContent(ddf.catalog.data.BinaryContent) Test(org.junit.Test)

Example 20 with BinaryContent

use of ddf.catalog.data.BinaryContent in project ddf by codice.

the class TestCswRecordConverter method testMetacardTransformWithCswRecordMetadata.

@Test
public void testMetacardTransformWithCswRecordMetadata() throws IOException, JAXBException, SAXException, XpathException, CatalogTransformerException {
    Metacard metacard = getCswRecordMetacard();
    Map<String, Serializable> args = new HashMap<>();
    args.put(CswConstants.WRITE_NAMESPACES, true);
    BinaryContent content = converter.transform(metacard, args);
    String xml = IOUtils.toString(content.getInputStream());
    assertThat(xml, containsString("<?xml version=\"1.0\" encoding=\"UTF-8\"?>"));
    XMLUnit.setIgnoreWhitespace(true);
    assertXMLEqual(cswRecordXml, xml);
}
Also used : Metacard(ddf.catalog.data.Metacard) Serializable(java.io.Serializable) HashMap(java.util.HashMap) Matchers.containsString(org.hamcrest.Matchers.containsString) BinaryContent(ddf.catalog.data.BinaryContent) Test(org.junit.Test)

Aggregations

BinaryContent (ddf.catalog.data.BinaryContent)214 Test (org.junit.Test)164 Metacard (ddf.catalog.data.Metacard)87 SourceResponse (ddf.catalog.operation.SourceResponse)78 MetacardTransformer (ddf.catalog.transform.MetacardTransformer)51 MetacardImpl (ddf.catalog.data.impl.MetacardImpl)44 HashMap (java.util.HashMap)42 Result (ddf.catalog.data.Result)41 Map (java.util.Map)39 Serializable (java.io.Serializable)33 CatalogTransformerException (ddf.catalog.transform.CatalogTransformerException)27 ResultImpl (ddf.catalog.data.impl.ResultImpl)26 LineString (ddf.geo.formatter.LineString)21 MultiLineString (ddf.geo.formatter.MultiLineString)21 Date (java.util.Date)21 File (java.io.File)20 JSONObject (org.json.simple.JSONObject)20 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)19 FileOutputStream (java.io.FileOutputStream)18 ByteArrayInputStream (java.io.ByteArrayInputStream)17