Search in sources :

Example 66 with SourceResponse

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

the class TestCswQueryResponseTransformer method testMarshalAcknowledgement.

@Test
public void testMarshalAcknowledgement() throws WebApplicationException, IOException, JAXBException, CatalogTransformerException {
    GetRecordsType query = new GetRecordsType();
    query.setResultType(ResultType.VALIDATE);
    query.setMaxRecords(BigInteger.valueOf(6));
    query.setStartPosition(BigInteger.valueOf(4));
    SourceResponse sourceResponse = createSourceResponse(query, 22);
    Map<String, Serializable> args = new HashMap<>();
    args.put(CswConstants.RESULT_TYPE_PARAMETER, ResultType.VALIDATE);
    args.put(CswConstants.GET_RECORDS, query);
    BinaryContent content = transformer.transform(sourceResponse, args);
    String xml = new String(content.getByteArray());
    JAXBElement<?> jaxb = (JAXBElement<?>) getJaxBContext().createUnmarshaller().unmarshal(new ByteArrayInputStream(xml.getBytes("UTF-8")));
    assertThat(jaxb.getValue(), is(instanceOf(AcknowledgementType.class)));
    AcknowledgementType response = (AcknowledgementType) jaxb.getValue();
    assertThat(response.getEchoedRequest().getAny(), is(instanceOf(JAXBElement.class)));
    JAXBElement<?> jaxB = (JAXBElement<?>) response.getEchoedRequest().getAny();
    assertThat(jaxB.getValue(), is(instanceOf(GetRecordsType.class)));
}
Also used : Serializable(java.io.Serializable) SourceResponse(ddf.catalog.operation.SourceResponse) HashMap(java.util.HashMap) ByteArrayInputStream(java.io.ByteArrayInputStream) GetRecordsType(net.opengis.cat.csw.v_2_0_2.GetRecordsType) Matchers.containsString(org.hamcrest.Matchers.containsString) Matchers.anyString(org.mockito.Matchers.anyString) JAXBElement(javax.xml.bind.JAXBElement) BinaryContent(ddf.catalog.data.BinaryContent) AcknowledgementType(net.opengis.cat.csw.v_2_0_2.AcknowledgementType) Test(org.junit.Test)

Example 67 with SourceResponse

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

the class TestAtomTransformer method getSourceResponseStub.

protected SourceResponse getSourceResponseStub(String id, String wkt) {
    SourceResponse response = mock(SourceResponse.class);
    when(response.getHits()).thenReturn(new Long(1));
    when(response.getRequest()).thenReturn(getStubRequest());
    ResultImpl result = new ResultImpl();
    MetacardStub metacard = new MetacardStub("");
    metacard.setId(id);
    metacard.setLocation(wkt);
    result.setMetacard(metacard);
    when(response.getResults()).thenReturn(Arrays.asList((Result) result));
    return response;
}
Also used : SourceResponse(ddf.catalog.operation.SourceResponse) ResultImpl(ddf.catalog.data.impl.ResultImpl) Result(ddf.catalog.data.Result)

Example 68 with SourceResponse

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

the class TestAtomTransformer method testNoBinaryContentXml.

@Test
public void testNoBinaryContentXml() throws IOException, CatalogTransformerException, XpathException, SAXException {
    // given
    MetacardTransformer metacardTransformer = mock(MetacardTransformer.class);
    when(metacardTransformer.transform(isA(Metacard.class), isNull(Map.class))).thenReturn(null);
    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 69 with SourceResponse

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

the class TestAtomTransformer method testMetacardIsNull.

/**
     * The following rules must be followed in order to be compliant with the Atom specification as
     * defined by http://tools.ietf.org/html/rfc4287#section-4.1.2 <br/>
     * "The following child elements are defined by this specification (note that the presence of
     * some of these elements is required):
     * <p>
     * <li/>atom:entry elements MUST contain one or more atom:author elements, unless the atom:entry
     * contains an atom:source element that contains an atom:author element or, in an Atom Feed
     * Document, the atom:feed element contains an atom:author element itself.
     * <p>
     * <li/>atom:entry elements MAY contain any number of atom:category elements.
     * <p>
     * <li/>atom:entry elements MUST NOT contain more than one atom:content element.
     * <p>
     * <li/>atom:entry elements MAY contain any number of atom:contributor elements.
     * <p>
     * <li/>atom:entry elements MUST contain exactly one atom:id element.
     * <p>
     * <li/>atom:entry elements that contain no child atom:content element MUST contain at least one
     * atom:link element with a rel attribute value of "alternate".
     * <p>
     * <li/>atom:entry elements MUST NOT contain more than one atom:link element with a rel
     * attribute value of "alternate" that has the same combination of type and hreflang attribute
     * values.
     * <p>
     * <li/>atom:entry elements MAY contain additional atom:link elements beyond those described
     * above.
     * <p>
     * <li/>atom:entry elements MUST NOT contain more than one atom:published element.
     * <p>
     * <li/>atom:entry elements MUST NOT contain more than one atom:rights element.
     * <p>
     * <li/>atom:entry elements MUST NOT contain more than one atom:source element.
     * <p>
     * <li/>atom:entry elements MUST contain an atom:summary element in either of the following
     * cases:
     * <p>
     * <ul>
     * the atom:entry contains an atom:content that has a "src" attribute (and is thus empty).
     * </ul>
     * <p>
     * <ul>
     * the atom:entry contains content that is encoded in Base64; i.e., the "type" attribute of
     * atom:content is a MIME media type [MIMEREG], but is not an XML media type [RFC3023], does not
     * begin with "text/", and does not end with "/xml" or "+xml".
     * </ul>
     * <p>
     * <li/>atom:entry elements MUST NOT contain more than one atom:summary element.
     * <p>
     * <li/>atom:entry elements MUST contain exactly one atom:title element.
     * <p>
     * <li/>atom:entry elements MUST contain exactly one atom:updated element."
     *
     * @throws CatalogTransformerException
     * @throws IOException
     * @throws SAXException
     * @throws XpathException
     */
@Test
public void testMetacardIsNull() 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());
    ResultImpl result1 = new ResultImpl();
    ResultImpl result2 = new ResultImpl();
    MetacardStub metacard = new MetacardStub("");
    metacard.setId(SAMPLE_ID);
    metacard.setSourceId(SAMPLE_SOURCE_ID);
    result1.setMetacard(metacard);
    result2.setMetacard(null);
    when(response.getResults()).thenReturn(Arrays.asList((Result) result1, result2));
    // 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);
    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);
    assertXpathExists("/atom:feed/atom:entry/atom:updated", output);
    assertXpathExists("/atom:feed/atom:entry/atom:content", output);
}
Also used : MetacardTransformer(ddf.catalog.transform.MetacardTransformer) SourceResponse(ddf.catalog.operation.SourceResponse) FileOutputStream(java.io.FileOutputStream) ResultImpl(ddf.catalog.data.impl.ResultImpl) BinaryContent(ddf.catalog.data.BinaryContent) File(java.io.File) Result(ddf.catalog.data.Result) Test(org.junit.Test)

Example 70 with SourceResponse

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

the class TestAtomTransformer method testThrowMetacardTransformerCatalogTransformerException.

@Test
public void testThrowMetacardTransformerCatalogTransformerException() throws IOException, CatalogTransformerException, XpathException, SAXException {
    // given
    MetacardTransformer metacardTransformer = mock(MetacardTransformer.class);
    when(metacardTransformer.transform(isA(Metacard.class), isNull(Map.class))).thenThrow(CatalogTransformerException.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();
    /* 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);
    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) FileOutputStream(java.io.FileOutputStream) BinaryContent(ddf.catalog.data.BinaryContent) Map(java.util.Map) HashMap(java.util.HashMap) 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