Search in sources :

Example 71 with SourceResponse

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

the class TestAtomTransformer method testNoResourceActionProvider.

@Test
public void testNoResourceActionProvider() throws CatalogTransformerException, IOException, XpathException, SAXException {
    // given
    MetacardTransformer metacardTransformer = getXmlMetacardTransformerStub();
    Action viewAction = mock(Action.class);
    when(viewAction.getUrl()).thenReturn(new URL("http://host:80/" + SAMPLE_ID));
    ActionProvider viewActionProvider = mock(ActionProvider.class);
    when(viewActionProvider.getAction(isA(Metacard.class))).thenReturn(viewAction);
    AtomTransformer transformer = new AtomTransformer();
    transformer.setViewMetacardActionProvider(viewActionProvider);
    transformer.setMetacardTransformer(metacardTransformer);
    setDefaultSystemConfiguration();
    SourceResponse response1 = mock(SourceResponse.class);
    when(response1.getHits()).thenReturn(new Long(1));
    when(response1.getRequest()).thenReturn(getStubRequest());
    ResultImpl result1 = new ResultImpl();
    MetacardStub metacard = new MetacardStub("");
    metacard.setId(SAMPLE_ID);
    metacard.setSourceId(SAMPLE_SOURCE_ID);
    metacard.setCreatedDate(SAMPLE_DATE_TIME.toDate());
    metacard.setModifiedDate(SAMPLE_DATE_TIME.toDate());
    result1.setMetacard(metacard);
    when(response1.getResults()).thenReturn(Arrays.asList((Result) result1));
    SourceResponse response = response1;
    Double relevanceScore = 0.3345;
    result1.setRelevanceScore(relevanceScore);
    // 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);
    /* feed */
    assertBasicFeedInfo(output, "1");
    /* entry */
    assertXpathEvaluatesTo(SAMPLE_SOURCE_ID, "/atom:feed/atom:entry/fs:resultSource/@fs:sourceId", output);
    assertXpathEvaluatesTo("", "/atom:feed/atom:entry/fs:resultSource", output);
    assertXpathEvaluatesTo(AtomTransformer.URN_CATALOG_ID + SAMPLE_ID, "/atom:feed/atom:entry/atom:id", output);
    assertXpathEvaluatesTo(MetacardStub.DEFAULT_TITLE, "/atom:feed/atom:entry/atom:title", output);
    assertXpathEvaluatesTo(Double.toString(relevanceScore), "/atom:feed/atom:entry/relevance:score", output);
    assertXpathExists("/atom:feed/atom:entry/atom:content", output);
    assertXpathEvaluatesTo(atomDateFormat.format(SAMPLE_DATE_TIME.toDate()), "/atom:feed/atom:entry/atom:published", output);
    assertXpathEvaluatesTo(atomDateFormat.format(SAMPLE_DATE_TIME.toDate()), "/atom:feed/atom:entry/atom:updated", output);
    assertXpathEvaluatesTo("application/xml", "/atom:feed/atom:entry/atom:content/@type", output);
    assertXpathEvaluatesTo(MetacardStub.DEFAULT_TYPE, "/atom:feed/atom:entry/atom:category/@term", output);
    assertXpathEvaluatesTo("1", "count(/atom:feed/atom:entry/georss:where)", output);
    assertXpathEvaluatesTo("1", "count(/atom:feed/atom:entry/georss:where/gml:Point)", output);
    assertXpathEvaluatesTo("56.3 13.3", "/atom:feed/atom:entry/georss:where/gml:Point", output);
    assertXpathEvaluatesTo("1", "count(/atom:feed/atom:entry/atom:link)", output);
    assertXpathExists("/atom:feed/atom:entry/atom:link[@rel='alternate']", output);
    assertXpathNotExists("/atom:feed/atom:entry/atom:link[@rel='related']", output);
    assertXpathEvaluatesTo("http://host:80/" + SAMPLE_ID, "/atom:feed/atom:entry/atom:link/@href", output);
}
Also used : ActionProvider(ddf.action.ActionProvider) Action(ddf.action.Action) MetacardTransformer(ddf.catalog.transform.MetacardTransformer) SourceResponse(ddf.catalog.operation.SourceResponse) ResultImpl(ddf.catalog.data.impl.ResultImpl) BinaryContent(ddf.catalog.data.BinaryContent) URL(java.net.URL) Result(ddf.catalog.data.Result) Metacard(ddf.catalog.data.Metacard) FileOutputStream(java.io.FileOutputStream) File(java.io.File) Test(org.junit.Test)

Example 72 with SourceResponse

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

the class TestAtomTransformer method testThrowMetacardTransformerRuntimeException.

@Test
public void testThrowMetacardTransformerRuntimeException() throws IOException, CatalogTransformerException, XpathException, SAXException {
    // given
    MetacardTransformer metacardTransformer = mock(MetacardTransformer.class);
    when(metacardTransformer.transform(isA(Metacard.class), isNull(Map.class))).thenThrow(RuntimeException.class);
    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);
}
Also used : Metacard(ddf.catalog.data.Metacard) MetacardTransformer(ddf.catalog.transform.MetacardTransformer) SourceResponse(ddf.catalog.operation.SourceResponse) BinaryContent(ddf.catalog.data.BinaryContent) Map(java.util.Map) HashMap(java.util.HashMap) Test(org.junit.Test)

Example 73 with SourceResponse

use of ddf.catalog.operation.SourceResponse 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);
}
Also used : Metacard(ddf.catalog.data.Metacard) MetacardTransformer(ddf.catalog.transform.MetacardTransformer) SourceResponse(ddf.catalog.operation.SourceResponse) BinaryContent(ddf.catalog.data.BinaryContent) Map(java.util.Map) HashMap(java.util.HashMap) Test(org.junit.Test)

Example 74 with SourceResponse

use of ddf.catalog.operation.SourceResponse 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);
}
Also used : Metacard(ddf.catalog.data.Metacard) MetacardTransformer(ddf.catalog.transform.MetacardTransformer) SourceResponse(ddf.catalog.operation.SourceResponse) BinaryContent(ddf.catalog.data.BinaryContent) Map(java.util.Map) HashMap(java.util.HashMap) Test(org.junit.Test)

Example 75 with SourceResponse

use of ddf.catalog.operation.SourceResponse 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);
}
Also used : SourceResponse(ddf.catalog.operation.SourceResponse) BinaryContent(ddf.catalog.data.BinaryContent) 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