Search in sources :

Example 1 with MultiActionProvider

use of ddf.action.MultiActionProvider 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 MultiActionProvider

use of ddf.action.MultiActionProvider 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 MultiActionProvider

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

the class AdminPollerTest method getHandleableTestActionProvider.

private MultiActionProvider getHandleableTestActionProvider(Action action) {
    MultiActionProvider actionProvider = mock(MultiActionProvider.class);
    when(actionProvider.canHandle(any(Configuration.class))).thenReturn(true);
    when(actionProvider.getActions(any(Class.class))).thenReturn(CollectionUtils.asList(action));
    return actionProvider;
}
Also used : MultiActionProvider(ddf.action.MultiActionProvider) Configuration(org.osgi.service.cm.Configuration)

Example 4 with MultiActionProvider

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

the class AdminPollerTest method getNotHandleableTestActionProvider.

private MultiActionProvider getNotHandleableTestActionProvider() {
    MultiActionProvider actionProvider = mock(MultiActionProvider.class);
    when(actionProvider.canHandle(any(Configuration.class))).thenReturn(false);
    return actionProvider;
}
Also used : MultiActionProvider(ddf.action.MultiActionProvider) Configuration(org.osgi.service.cm.Configuration)

Aggregations

MultiActionProvider (ddf.action.MultiActionProvider)4 Action (ddf.action.Action)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 Configuration (org.osgi.service.cm.Configuration)2 ImmutableList (com.google.common.collect.ImmutableList)1 List (java.util.List)1 Test (org.junit.Test)1 Matchers.anyMap (org.mockito.Matchers.anyMap)1