Search in sources :

Example 1 with BinaryContent

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

the class TestGmdTransformer method testMetacardTransformNullMetacard.

@Test
public void testMetacardTransformNullMetacard() throws IOException, CatalogTransformerException {
    BinaryContent content = new GmdTransformer(gmdMetacardType).transform((Metacard) null, null);
    String xml = IOUtils.toString(content.getInputStream());
    assertThat(xml.trim(), is(XML_DECLARATION));
}
Also used : BinaryContent(ddf.catalog.data.BinaryContent) Test(org.junit.Test)

Example 2 with BinaryContent

use of ddf.catalog.data.BinaryContent 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 3 with BinaryContent

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

the class TestCswQueryResponseTransformer method whenQueryByIdThenExpectOnlyOneXMLNode.

@Test
public void whenQueryByIdThenExpectOnlyOneXMLNode() throws CatalogTransformerException, IOException {
    // when
    when(mockPrintWriterProvider.build((Class<Metacard>) notNull())).thenReturn(mockPrintWriter);
    when(mockPrintWriter.makeString()).thenReturn(new String());
    when(mockSourceResponse.getResults()).thenReturn(Collections.emptyList());
    when(mockSourceResponse.getRequest()).thenReturn(mockQueryRequest);
    when(mockQueryRequest.getQuery()).thenReturn(mockQuery);
    when(mockArguments.get(CswConstants.RESULT_TYPE_PARAMETER)).thenReturn(ResultType.RESULTS);
    when(mockArguments.get(CswConstants.IS_BY_ID_QUERY)).thenReturn(true);
    when(mockTransformerManager.getTransformerBySchema(anyString())).thenReturn(mockMetacardTransformer);
    // given
    transformer.init();
    BinaryContent bc = transformer.transform(mockSourceResponse, mockArguments);
    transformer.destroy();
    // then
    ArgumentCaptor<String> strArgCaptor = ArgumentCaptor.forClass(String.class);
    verify(mockPrintWriter, times(1)).startNode(strArgCaptor.capture());
    List<String> values = strArgCaptor.getAllValues();
    assertThat("Missing root GetRecordByIdResponse node.", values.get(0), is(CswQueryResponseTransformer.RECORD_BY_ID_RESPONSE_QNAME));
}
Also used : Metacard(ddf.catalog.data.Metacard) Matchers.containsString(org.hamcrest.Matchers.containsString) Matchers.anyString(org.mockito.Matchers.anyString) BinaryContent(ddf.catalog.data.BinaryContent) Test(org.junit.Test)

Example 4 with BinaryContent

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

the class TestGmdTransformer method testMetacardTransformNoDeclaration.

@Test
public void testMetacardTransformNoDeclaration() throws IOException, CatalogTransformerException {
    Metacard metacard = getTestMetacard();
    Map<String, Serializable> args = new HashMap<>();
    args.put(CswConstants.OMIT_XML_DECLARATION, true);
    BinaryContent content = new GmdTransformer(gmdMetacardType).transform(metacard, args);
    String xml = IOUtils.toString(content.getInputStream());
    assertThat(xml, not(startsWith(XML_DECLARATION)));
}
Also used : Metacard(ddf.catalog.data.Metacard) Serializable(java.io.Serializable) HashMap(java.util.HashMap) BinaryContent(ddf.catalog.data.BinaryContent) Test(org.junit.Test)

Example 5 with BinaryContent

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

the class TestAtomTransformer method getXmlMetacardTransformerStub.

protected MetacardTransformer getXmlMetacardTransformerStub() throws IOException, CatalogTransformerException {
    MetacardTransformer metacardTransformer = mock(MetacardTransformer.class);
    BinaryContent metacardTransformation = mock(BinaryContent.class);
    when(metacardTransformation.getByteArray()).thenReturn("<sample:note xmlns:sample=\"http://www.lockheedmartin.com/schema/sample\"><to>me</to><from>you</from></sample:note>".getBytes());
    when(metacardTransformer.transform(isA(Metacard.class), isA(Map.class))).thenReturn(metacardTransformation);
    return metacardTransformer;
}
Also used : Metacard(ddf.catalog.data.Metacard) MetacardTransformer(ddf.catalog.transform.MetacardTransformer) BinaryContent(ddf.catalog.data.BinaryContent) Map(java.util.Map) HashMap(java.util.HashMap)

Aggregations

BinaryContent (ddf.catalog.data.BinaryContent)112 Test (org.junit.Test)79 Metacard (ddf.catalog.data.Metacard)42 SourceResponse (ddf.catalog.operation.SourceResponse)41 HashMap (java.util.HashMap)30 MetacardTransformer (ddf.catalog.transform.MetacardTransformer)28 Map (java.util.Map)24 Result (ddf.catalog.data.Result)22 MetacardImpl (ddf.catalog.data.impl.MetacardImpl)19 CatalogTransformerException (ddf.catalog.transform.CatalogTransformerException)19 Matchers.anyString (org.mockito.Matchers.anyString)18 Serializable (java.io.Serializable)17 ByteArrayInputStream (java.io.ByteArrayInputStream)15 Date (java.util.Date)12 LineString (ddf.geo.formatter.LineString)11 MultiLineString (ddf.geo.formatter.MultiLineString)11 File (java.io.File)11 BinaryContentImpl (ddf.catalog.data.impl.BinaryContentImpl)10 ResultImpl (ddf.catalog.data.impl.ResultImpl)10 IOException (java.io.IOException)10