Search in sources :

Example 46 with MetacardTransformer

use of ddf.catalog.transform.MetacardTransformer in project ddf by codice.

the class AtomTransformerTest 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 47 with MetacardTransformer

use of ddf.catalog.transform.MetacardTransformer in project ddf by codice.

the class AtomTransformerTest method basicSetup.

private 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 48 with MetacardTransformer

use of ddf.catalog.transform.MetacardTransformer in project ddf by codice.

the class AtomTransformerTest method testItemsPerPageNegativeInteger.

@Test
public void testItemsPerPageNegativeInteger() 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);
    assertXpathEvaluatesTo("1", "/atom:feed/os:itemsPerPage", 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 49 with MetacardTransformer

use of ddf.catalog.transform.MetacardTransformer in project ddf by codice.

the class AtomTransformerTest method testThrowMetacardTransformerRuntimeException.

@Test
public void testThrowMetacardTransformerRuntimeException() throws IOException, CatalogTransformerException, XpathException, SAXException {
    // given
    MetacardTransformer metacardTransformer = mock(MetacardTransformer.class);
    when(metacardTransformer.transform(isA(Metacard.class), isNull())).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) Test(org.junit.Test)

Example 50 with MetacardTransformer

use of ddf.catalog.transform.MetacardTransformer in project ddf by codice.

the class DumpCommandTest method testNoFileDumpedWhenTransformFails.

/**
 * If a transform fails, assert that no file is dumped
 *
 * @throws Exception
 */
@Test
public void testNoFileDumpedWhenTransformFails() throws Exception {
    // mock transformer to throw exception
    MetacardTransformer transformer = mock(MetacardTransformer.class);
    when(transformer.transform(any(), any())).thenThrow(CatalogTransformerException.class);
    List<MetacardTransformer> transformers = new ArrayList<>();
    transformers.add(transformer);
    // given
    List<Result> resultList = getResultList("id1", "id2");
    MetacardImpl metacard1 = new MetacardImpl(resultList.get(0).getMetacard());
    MetacardImpl metacard2 = new MetacardImpl(resultList.get(1).getMetacard());
    metacard1.setResourceURI(new URI("content:" + metacard1.getId()));
    metacard2.setResourceURI(new URI("content:" + metacard2.getId() + "#preview"));
    TestDumpCommand dumpCommand = new TestDumpCommand(transformers, signer);
    dumpCommand.catalogFramework = givenCatalogFramework(resultList);
    dumpCommand.filterBuilder = new GeotoolsFilterBuilder();
    File outputDirectory = testFolder.newFolder("somedirectory");
    String outputDirectoryPath = outputDirectory.getAbsolutePath();
    dumpCommand.dirPath = outputDirectoryPath;
    dumpCommand.transformerId = "someOtherTransformer";
    dumpCommand.securityLogger = mock(SecurityLogger.class);
    // when
    dumpCommand.executeWithSubject();
    // then
    assertThat(consoleOutput.getOutput(), containsString(" 0 file(s) dumped in "));
}
Also used : MetacardTransformer(ddf.catalog.transform.MetacardTransformer) GeotoolsFilterBuilder(ddf.catalog.filter.proxy.builder.GeotoolsFilterBuilder) ArrayList(java.util.ArrayList) Matchers.containsString(org.hamcrest.Matchers.containsString) URI(java.net.URI) File(java.io.File) MetacardImpl(ddf.catalog.data.impl.MetacardImpl) Result(ddf.catalog.data.Result) SecurityLogger(ddf.security.audit.SecurityLogger) Test(org.junit.Test)

Aggregations

MetacardTransformer (ddf.catalog.transform.MetacardTransformer)54 BinaryContent (ddf.catalog.data.BinaryContent)48 Test (org.junit.Test)40 SourceResponse (ddf.catalog.operation.SourceResponse)38 Metacard (ddf.catalog.data.Metacard)28 Result (ddf.catalog.data.Result)25 ResultImpl (ddf.catalog.data.impl.ResultImpl)20 FileOutputStream (java.io.FileOutputStream)18 File (java.io.File)17 HashMap (java.util.HashMap)15 Map (java.util.Map)10 CatalogTransformerException (ddf.catalog.transform.CatalogTransformerException)7 MetacardImpl (ddf.catalog.data.impl.MetacardImpl)5 Action (ddf.action.Action)4 ActionProvider (ddf.action.ActionProvider)4 BinaryContentImpl (ddf.catalog.data.impl.BinaryContentImpl)4 QueryImpl (ddf.catalog.operation.impl.QueryImpl)4 QueryRequestImpl (ddf.catalog.operation.impl.QueryRequestImpl)4 Serializable (java.io.Serializable)4 URL (java.net.URL)4