Search in sources :

Example 26 with Action

use of ddf.action.Action in project ddf by codice.

the class ActivityEventPublisherTest method setupPublisher.

@Override
protected void setupPublisher() {
    actionProvider = mock(ActionProvider.class);
    Action downloadAction = mock(Action.class);
    try {
        when(actionProvider.getAction(metacard)).thenReturn(downloadAction);
        when(downloadAction.getUrl()).thenReturn(new URL("http://example.com/download"));
    } catch (Exception e) {
        LOGGER.warn("Could not set download action URL", e);
    }
    publisher = new DownloadsStatusEventPublisher(eventAdmin, ImmutableList.of(actionProvider));
    publisher.setNotificationEnabled(false);
}
Also used : ActionProvider(ddf.action.ActionProvider) Action(ddf.action.Action) URL(java.net.URL)

Example 27 with Action

use of ddf.action.Action in project ddf by codice.

the class NotificationEventPublisherTest method setupPublisher.

@Override
protected void setupPublisher() {
    actionProvider = mock(ActionProvider.class);
    Action downloadAction = mock(Action.class);
    try {
        when(actionProvider.getAction(metacard)).thenReturn(downloadAction);
        when(downloadAction.getUrl()).thenReturn(new URL("http://example.com/download"));
    } catch (Exception e) {
        LOGGER.warn("Could not set download action URL", e);
    }
    publisher = new DownloadsStatusEventPublisher(eventAdmin, ImmutableList.of(actionProvider));
    publisher.setActivityEnabled(false);
}
Also used : ActionProvider(ddf.action.ActionProvider) Action(ddf.action.Action) URL(java.net.URL)

Example 28 with Action

use of ddf.action.Action in project ddf by codice.

the class TestAtomTransformer method testSimple.

@Test
public void testSimple() 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);
    ActionProvider resourceActionProvider = mock(ActionProvider.class);
    when(resourceActionProvider.getAction(isA(Metacard.class))).thenReturn(viewAction);
    ActionProvider thumbnailActionProvider = mock(ActionProvider.class);
    when(thumbnailActionProvider.getAction(isA(Metacard.class))).thenReturn(viewAction);
    AtomTransformer transformer = new AtomTransformer();
    transformer.setViewMetacardActionProvider(viewActionProvider);
    transformer.setResourceActionProvider(resourceActionProvider);
    transformer.setMetacardTransformer(metacardTransformer);
    transformer.setThumbnailActionProvider(thumbnailActionProvider);
    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("3", "count(/atom:feed/atom:entry/atom:link)", output);
    assertXpathExists("/atom:feed/atom:entry/atom:link[@rel='alternate']", output);
    assertXpathExists("/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 29 with Action

use of ddf.action.Action in project ddf by codice.

the class AbstractMetacardActionProviderTest method getActionsWhenGetMetacardActionFails.

@Test
public void getActionsWhenGetMetacardActionFails() {
    MetacardActionProvider actionProvider = new MetacardActionProvider(ACTION_ID, TITLE, DESCRIPTION) {

        @Override
        protected URL getMetacardActionUrl(String metacardSource, Metacard metacard) throws IOException {
            throw new IOException();
        }
    };
    System.setProperty(SystemBaseUrl.HOST, "codice.org");
    Action action = actionProvider.getAction(metacard);
    assertThat(action, is(nullValue()));
}
Also used : Metacard(ddf.catalog.data.Metacard) Action(ddf.action.Action) IOException(java.io.IOException) Test(org.junit.Test)

Example 30 with Action

use of ddf.action.Action in project ddf by codice.

the class AbstractMetacardActionProviderTest method getActionsWhenMetacardSourceIdIsNull.

@Test
public void getActionsWhenMetacardSourceIdIsNull() throws Exception {
    MetacardActionProvider actionProvider = createMetacardActionProvider();
    when(metacard.getSourceId()).thenReturn(null);
    System.setProperty(SystemBaseUrl.HOST, "codice.org");
    System.setProperty(SystemInfo.SITE_NAME, "ddf");
    when(actionProvider.createMetacardAction(eq(ACTION_ID), eq(TITLE), eq(DESCRIPTION), any())).thenReturn(action);
    Action action = actionProvider.getAction(metacard);
    assertThat(action, is(this.action));
    verify(actionProvider).getMetacardAction("ddf", metacard);
}
Also used : Action(ddf.action.Action) Test(org.junit.Test)

Aggregations

Action (ddf.action.Action)44 Test (org.junit.Test)33 URL (java.net.URL)9 HashMap (java.util.HashMap)8 Metacard (ddf.catalog.data.Metacard)7 ActionProvider (ddf.action.ActionProvider)6 ArrayList (java.util.ArrayList)5 Map (java.util.Map)5 ActionImpl (ddf.action.impl.ActionImpl)3 MultiActionProvider (ddf.action.MultiActionProvider)2 BinaryContent (ddf.catalog.data.BinaryContent)2 Result (ddf.catalog.data.Result)2 MetacardImpl (ddf.catalog.data.impl.MetacardImpl)2 ResultImpl (ddf.catalog.data.impl.ResultImpl)2 SourceResponse (ddf.catalog.operation.SourceResponse)2 MetacardTransformer (ddf.catalog.transform.MetacardTransformer)2 File (java.io.File)2 FileOutputStream (java.io.FileOutputStream)2 UnsupportedEncodingException (java.io.UnsupportedEncodingException)2 Date (java.util.Date)2