Search in sources :

Example 1 with Action

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

the class AdminPollerTest method testAllSourceInfo.

@Test
public void testAllSourceInfo() {
    Action operatorActionOne = getTestAction("operationIdOne", "operationTitle1", "operationDescription1", "https://localhost:8993/provider/someAction");
    Action operatorActionTwo = getTestAction("operationIdTwo", "operationTitleTwo", "operationDescriptionTwo", "https://localhost:8993/provider/someAction");
    ImmutableList<MultiActionProvider> operationActions = ImmutableList.of(getHandleableTestActionProvider(operatorActionOne), getNotHandleableTestActionProvider(), getHandleableTestActionProvider(operatorActionTwo));
    poller.setOperationActionProviders(operationActions);
    Action reportActionOne = getTestAction("reportId", "reportTitle", "reportDescription", "https://localhost:8993/provider/someAction");
    ImmutableList<MultiActionProvider> reportActions = ImmutableList.of(getHandleableTestActionProvider(reportActionOne), getNotHandleableTestActionProvider(), getNotHandleableTestActionProvider());
    poller.setReportActionProviders(reportActions);
    List<Map<String, Object>> sources = poller.allSourceInfo();
    assertThat(sources, notNullValue());
    assertThat(sources.size(), is(2));
    assertThat(sources.get(0), not(hasKey("configurations")));
    assertThat(sources.get(1), hasKey("configurations"));
    List<Map<String, Object>> configurations = (List) sources.get(1).get("configurations");
    assertThat(configurations, hasSize(1));
    Map<String, Object> configurationMap = configurations.get(0);
    assertThat(configurationMap, hasKey("operation_actions"));
    assertThat(configurationMap, hasKey("report_actions"));
    List<Map<String, Object>> operationActionsList = (List) configurationMap.get("operation_actions");
    Map<String, String> operatorActionOneMap = getMapFromAction(operatorActionOne);
    Map<String, String> operatorActionTwoMap = getMapFromAction(operatorActionTwo);
    assertThat(operationActionsList, contains(operatorActionOneMap, operatorActionTwoMap));
    List<Map<String, Object>> reportActionsList = (List) configurationMap.get("report_actions");
    Map<String, String> reportActionMap = getMapFromAction(reportActionOne);
    assertThat(reportActionsList, contains(reportActionMap));
}
Also used : Action(ddf.action.Action) MultiActionProvider(ddf.action.MultiActionProvider) ArrayList(java.util.ArrayList) ImmutableList(com.google.common.collect.ImmutableList) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map) Matchers.anyMap(org.mockito.Matchers.anyMap) Test(org.junit.Test)

Example 2 with Action

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

the class AdminPollerServiceBean method getActions.

private List<Map<String, String>> getActions(Configuration config, List<MultiActionProvider> providers) {
    List<Map<String, String>> actions = new ArrayList<>();
    for (MultiActionProvider provider : providers) {
        if (!provider.canHandle(config)) {
            continue;
        }
        List<Action> curActionList = provider.getActions(config);
        for (Action action : curActionList) {
            Map<String, String> actionProperties = new HashMap<>();
            actionProperties.put(MAP_ENTRY_ACTION_ID, action.getId());
            actionProperties.put(MAP_ENTRY_ACTION_TITLE, action.getTitle());
            actionProperties.put(MAP_ENTRY_ACTION_DESCRIPTION, action.getDescription());
            actionProperties.put(MAP_ENTRY_ACTION_URL, action.getUrl().toString());
            actions.add(actionProperties);
        }
    }
    return actions;
}
Also used : MultiActionProvider(ddf.action.MultiActionProvider) Action(ddf.action.Action) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) HashMap(java.util.HashMap) Map(java.util.Map)

Example 3 with Action

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

the class AdminPollerTest method getTestAction.

private Action getTestAction(String id, String title, String description, String urlString) {
    Action action = mock(Action.class);
    when(action.getId()).thenReturn(id);
    when(action.getTitle()).thenReturn(title);
    when(action.getDescription()).thenReturn(description);
    try {
        URL url = new URL(urlString);
        when(action.getUrl()).thenReturn(url);
    } catch (MalformedURLException e) {
    // do nothing
    }
    return action;
}
Also used : Action(ddf.action.Action) MalformedURLException(java.net.MalformedURLException) URL(java.net.URL)

Example 4 with Action

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

the class AbstractMetacardActionProviderTest method getActionsWhenSubclassCannotHandleMetacard.

@Test
public void getActionsWhenSubclassCannotHandleMetacard() throws Exception {
    MetacardActionProvider actionProvider = createMetacardActionProvider();
    when(actionProvider.canHandleMetacard(metacard)).thenReturn(false);
    Action action = actionProvider.getAction(metacard);
    assertThat(action, is(nullValue()));
    verify(actionProvider, never()).getMetacardAction(any(), any());
}
Also used : Action(ddf.action.Action) Test(org.junit.Test)

Example 5 with Action

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

the class AbstractMetacardActionProviderTest method getActionsWithNonMetacard.

@Test
public void getActionsWithNonMetacard() throws Exception {
    MetacardActionProvider actionProvider = createMetacardActionProvider();
    Action action = actionProvider.getAction("blah");
    assertThat(action, is(nullValue()));
    verify(actionProvider, never()).getMetacardAction(any(), any());
}
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