Search in sources :

Example 6 with MetacardTransformer

use of ddf.catalog.transform.MetacardTransformer 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 7 with MetacardTransformer

use of ddf.catalog.transform.MetacardTransformer 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 8 with MetacardTransformer

use of ddf.catalog.transform.MetacardTransformer 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 9 with MetacardTransformer

use of ddf.catalog.transform.MetacardTransformer 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 10 with MetacardTransformer

use of ddf.catalog.transform.MetacardTransformer 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)

Aggregations

MetacardTransformer (ddf.catalog.transform.MetacardTransformer)30 BinaryContent (ddf.catalog.data.BinaryContent)26 Test (org.junit.Test)21 SourceResponse (ddf.catalog.operation.SourceResponse)19 Metacard (ddf.catalog.data.Metacard)16 Result (ddf.catalog.data.Result)12 HashMap (java.util.HashMap)12 ResultImpl (ddf.catalog.data.impl.ResultImpl)10 FileOutputStream (java.io.FileOutputStream)9 Map (java.util.Map)9 File (java.io.File)8 CatalogTransformerException (ddf.catalog.transform.CatalogTransformerException)4 ServiceReference (org.osgi.framework.ServiceReference)4 BinaryContentImpl (ddf.catalog.data.impl.BinaryContentImpl)3 MetacardImpl (ddf.catalog.data.impl.MetacardImpl)3 Serializable (java.io.Serializable)3 Matchers.anyString (org.mockito.Matchers.anyString)3 Action (ddf.action.Action)2 ActionProvider (ddf.action.ActionProvider)2 CatalogFramework (ddf.catalog.CatalogFramework)2