Search in sources :

Example 76 with SourceResponse

use of ddf.catalog.operation.SourceResponse 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);
        }
    }
}
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) Test(org.junit.Test)

Example 77 with SourceResponse

use of ddf.catalog.operation.SourceResponse 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 78 with SourceResponse

use of ddf.catalog.operation.SourceResponse in project ddf by codice.

the class TestAtomTransformer method basicSetup.

protected SourceResponse basicSetup(AtomTransformer transformer) throws IOException, CatalogTransformerException {
    MetacardTransformer metacardTransformer = getXmlMetacardTransformerStub();
    transformer.setMetacardTransformer(metacardTransformer);
    setDefaultSystemConfiguration();
    SourceResponse response = mock(SourceResponse.class);
    when(response.getRequest()).thenReturn(getStubRequest());
    ResultImpl result = new ResultImpl();
    MetacardStub metacard = new MetacardStub("");
    metacard.setId(SAMPLE_ID);
    metacard.setSourceId(SAMPLE_SOURCE_ID);
    result.setMetacard(metacard);
    when(response.getResults()).thenReturn(Arrays.asList((Result) result));
    return response;
}
Also used : MetacardTransformer(ddf.catalog.transform.MetacardTransformer) SourceResponse(ddf.catalog.operation.SourceResponse) ResultImpl(ddf.catalog.data.impl.ResultImpl) Result(ddf.catalog.data.Result)

Example 79 with SourceResponse

use of ddf.catalog.operation.SourceResponse 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 80 with SourceResponse

use of ddf.catalog.operation.SourceResponse in project ddf by codice.

the class TestAtomTransformer method testBadGeo.

@Test
public void testBadGeo() throws CatalogTransformerException, IOException, XpathException, SAXException {
    AtomTransformer atomTransformer = new AtomTransformer();
    atomTransformer.setMetacardTransformer(getXmlMetacardTransformerStub());
    setDefaultSystemConfiguration();
    SourceResponse response = getSourceResponseStub(SAMPLE_ID, BAD_WKT);
    byte[] bytes = atomTransformer.transform(response, null).getByteArray();
    String output = new String(bytes);
    /* used to visualize */
    IOUtils.write(bytes, new FileOutputStream(new File(TARGET_FOLDER + getMethodName() + ATOM_EXTENSION)));
    assertFeedCompliant(output);
    assertEntryCompliant(output);
    validateAgainstAtomSchema(bytes);
    assertXpathNotExists("//gml:Polygon", output);
    assertXpathNotExists("//georss:where", output);
}
Also used : SourceResponse(ddf.catalog.operation.SourceResponse) FileOutputStream(java.io.FileOutputStream) File(java.io.File) Test(org.junit.Test)

Aggregations

SourceResponse (ddf.catalog.operation.SourceResponse)199 Test (org.junit.Test)146 QueryRequestImpl (ddf.catalog.operation.impl.QueryRequestImpl)99 QueryImpl (ddf.catalog.operation.impl.QueryImpl)95 Result (ddf.catalog.data.Result)79 Metacard (ddf.catalog.data.Metacard)73 Filter (org.opengis.filter.Filter)58 QueryRequest (ddf.catalog.operation.QueryRequest)52 BinaryContent (ddf.catalog.data.BinaryContent)40 ResultImpl (ddf.catalog.data.impl.ResultImpl)29 SourceResponseImpl (ddf.catalog.operation.impl.SourceResponseImpl)25 ArrayList (java.util.ArrayList)25 HashMap (java.util.HashMap)24 Matchers.containsString (org.hamcrest.Matchers.containsString)24 Matchers.anyString (org.mockito.Matchers.anyString)21 MetacardImpl (ddf.catalog.data.impl.MetacardImpl)20 Serializable (java.io.Serializable)20 MetacardTransformer (ddf.catalog.transform.MetacardTransformer)19 SortByImpl (ddf.catalog.filter.impl.SortByImpl)18 Map (java.util.Map)16