Search in sources :

Example 1 with ActionRegistryImpl

use of org.codice.ddf.ui.searchui.query.actions.ActionRegistryImpl in project ddf by codice.

the class CometdEndpointTest method setUp.

/**
     * @throws java.lang.Exception
     */
@Before
public void setUp() throws Exception {
    when(mockServerSession.getId()).thenReturn(MOCK_SESSION_ID);
    // Return a new mock of LocalSession each time newLocalSession is
    // called on the BayeuxServer
    when(bayeuxServer.newLocalSession(Mockito.anyString())).thenAnswer(new Answer<LocalSession>() {

        public LocalSession answer(InvocationOnMock invocation) {
            LocalSession localSession = mock(LocalSession.class);
            when(localSession.getServerSession()).thenReturn(mock(ServerSession.class));
            return localSession;
        }
    });
    // Mock enough of the behavior of the createChannelIfAbsent method to
    // ensure proper processing of CometD Service annotations
    when(bayeuxServer.createChannelIfAbsent(Mockito.anyString())).thenAnswer(new Answer<MarkedReference<ServerChannel>>() {

        public MarkedReference<ServerChannel> answer(InvocationOnMock invokation) {
            String channelName = invokation.getArguments()[0].toString();
            LOGGER.debug("Channel Name: {}", channelName);
            if (null == channelName) {
                return null;
            }
            ChannelId channelId = new ChannelId(channelName);
            ServerChannel serverChannel = mock(ServerChannel.class);
            when(serverChannel.getChannelId()).thenReturn(channelId);
            when(serverChannel.getId()).thenReturn(channelName);
            @SuppressWarnings("unchecked") MarkedReference<ServerChannel> markedReference = (MarkedReference<ServerChannel>) mock(MarkedReference.class);
            // Mark with value of true indicates that the serverChannel
            // did not previously exist. Implementation of test setup
            // needs to change if there is a later need to maintain
            // whether a channel has already been created
            when(markedReference.isMarked()).thenReturn(true);
            when(markedReference.getReference()).thenReturn(serverChannel);
            return markedReference;
        }
    });
    // Call the actual BayeuxServer methods, rather than the mock methods, 
    // when setting/getting the security policy.
    Mockito.doCallRealMethod().when(bayeuxServer).setSecurityPolicy(Mockito.any(SecurityPolicy.class));
    Mockito.doCallRealMethod().when(bayeuxServer).getSecurityPolicy();
    // Associate the BayeuxServer with a CometdServlet
    ServletContext servletContext = mock(ServletContext.class);
    when(servletConfig.getServletContext()).thenReturn(servletContext);
    when(servletContext.getAttribute(BayeuxServer.ATTRIBUTE)).thenReturn(bayeuxServer);
    // Create the CometdEndpoint, passing in the mocked CometdServlet
    cometdEndpoint = spy(new CometdEndpoint(mock(CatalogFramework.class), mock(FilterBuilder.class), mock(FilterAdapter.class), mock(PersistentStore.class), mock(BundleContext.class), mock(EventAdmin.class), new ActionRegistryImpl(Collections.EMPTY_LIST, Collections.EMPTY_LIST), Executors.newSingleThreadExecutor()));
    doNothing().when(cometdEndpoint).init();
}
Also used : ActionRegistryImpl(org.codice.ddf.ui.searchui.query.actions.ActionRegistryImpl) EventAdmin(org.osgi.service.event.EventAdmin) MarkedReference(org.cometd.bayeux.MarkedReference) LocalSession(org.cometd.bayeux.server.LocalSession) FilterAdapter(ddf.catalog.filter.FilterAdapter) PersistentStore(org.codice.ddf.persistence.PersistentStore) ChannelId(org.cometd.bayeux.ChannelId) ServerChannel(org.cometd.bayeux.server.ServerChannel) InvocationOnMock(org.mockito.invocation.InvocationOnMock) FilterBuilder(ddf.catalog.filter.FilterBuilder) SecurityPolicy(org.cometd.bayeux.server.SecurityPolicy) CatalogFramework(ddf.catalog.CatalogFramework) ServletContext(javax.servlet.ServletContext) BundleContext(org.osgi.framework.BundleContext) Before(org.junit.Before)

Example 2 with ActionRegistryImpl

use of org.codice.ddf.ui.searchui.query.actions.ActionRegistryImpl in project ddf by codice.

the class SearchControllerTest method testFailingQuery.

@Test
public void testFailingQuery() throws Exception {
    // Setup
    framework = mock(CatalogFramework.class);
    QueryResponse response = mock(QueryResponse.class);
    when(response.getResults()).thenThrow(new RuntimeException("Getting results failed"));
    when(framework.query(any(QueryRequest.class))).thenReturn(response);
    searchController = new SearchController(framework, new ActionRegistryImpl(Collections.emptyList(), Collections.emptyList()), new GeotoolsFilterAdapterImpl(), new SequentialExecutorService());
    final String ID = "id";
    Set<String> srcIds = new HashSet<>();
    srcIds.add(ID);
    SearchRequest request = new SearchRequest(srcIds, getQueryRequest("anyText LIKE '*'"), "queryId");
    BayeuxServer bayeuxServer = mock(BayeuxServer.class);
    ServerChannel channel = mock(ServerChannel.class);
    when(bayeuxServer.getChannel(any(String.class))).thenReturn(channel);
    searchController.setBayeuxServer(bayeuxServer);
    searchController.setCacheDisabled(true);
    // Perform Test
    searchController.executeQuery(request, mockServerSession, null);
    // Verify
    verify(channel, times(1)).publish(any(), any());
}
Also used : SearchRequest(org.codice.ddf.ui.searchui.query.model.SearchRequest) QueryRequest(ddf.catalog.operation.QueryRequest) ActionRegistryImpl(org.codice.ddf.ui.searchui.query.actions.ActionRegistryImpl) Matchers.anyString(org.mockito.Matchers.anyString) ServerChannel(org.cometd.bayeux.server.ServerChannel) BayeuxServer(org.cometd.bayeux.server.BayeuxServer) QueryResponse(ddf.catalog.operation.QueryResponse) CatalogFramework(ddf.catalog.CatalogFramework) GeotoolsFilterAdapterImpl(ddf.catalog.filter.proxy.adapter.GeotoolsFilterAdapterImpl) HashSet(java.util.HashSet) Test(org.junit.Test)

Aggregations

CatalogFramework (ddf.catalog.CatalogFramework)2 ActionRegistryImpl (org.codice.ddf.ui.searchui.query.actions.ActionRegistryImpl)2 ServerChannel (org.cometd.bayeux.server.ServerChannel)2 FilterAdapter (ddf.catalog.filter.FilterAdapter)1 FilterBuilder (ddf.catalog.filter.FilterBuilder)1 GeotoolsFilterAdapterImpl (ddf.catalog.filter.proxy.adapter.GeotoolsFilterAdapterImpl)1 QueryRequest (ddf.catalog.operation.QueryRequest)1 QueryResponse (ddf.catalog.operation.QueryResponse)1 HashSet (java.util.HashSet)1 ServletContext (javax.servlet.ServletContext)1 PersistentStore (org.codice.ddf.persistence.PersistentStore)1 SearchRequest (org.codice.ddf.ui.searchui.query.model.SearchRequest)1 ChannelId (org.cometd.bayeux.ChannelId)1 MarkedReference (org.cometd.bayeux.MarkedReference)1 BayeuxServer (org.cometd.bayeux.server.BayeuxServer)1 LocalSession (org.cometd.bayeux.server.LocalSession)1 SecurityPolicy (org.cometd.bayeux.server.SecurityPolicy)1 Before (org.junit.Before)1 Test (org.junit.Test)1 Matchers.anyString (org.mockito.Matchers.anyString)1