Search in sources :

Example 1 with BayeuxServer

use of org.cometd.bayeux.server.BayeuxServer in project ddf by codice.

the class SearchControllerTest method testMetacardTypeValuesCacheDisabled.

@Test
public void testMetacardTypeValuesCacheDisabled() throws Exception {
    final String ID = "id";
    Set<String> srcIds = new HashSet<String>();
    srcIds.add(ID);
    BayeuxServer bayeuxServer = mock(BayeuxServer.class);
    ServerChannel channel = mock(ServerChannel.class);
    ArgumentCaptor<ServerMessage.Mutable> reply = ArgumentCaptor.forClass(ServerMessage.Mutable.class);
    when(bayeuxServer.getChannel(any(String.class))).thenReturn(channel);
    SearchRequest request = new SearchRequest(srcIds, getQueryRequest("title LIKE 'Meta*'"), ID);
    searchController.setBayeuxServer(bayeuxServer);
    // Disable Cache
    searchController.setCacheDisabled(true);
    searchController.executeQuery(request, mockServerSession, null);
    verify(channel, timeout(1000).only()).publish(any(ServerSession.class), reply.capture());
    List<Mutable> replies = reply.getAllValues();
    assertReplies(replies);
}
Also used : Mutable(org.cometd.bayeux.server.ServerMessage.Mutable) SearchRequest(org.codice.ddf.ui.searchui.query.model.SearchRequest) ServerSession(org.cometd.bayeux.server.ServerSession) BayeuxServer(org.cometd.bayeux.server.BayeuxServer) ServerMessage(org.cometd.bayeux.server.ServerMessage) Matchers.anyString(org.mockito.Matchers.anyString) ServerChannel(org.cometd.bayeux.server.ServerChannel) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 2 with BayeuxServer

use of org.cometd.bayeux.server.BayeuxServer in project ddf by codice.

the class SearchControllerTest method testMetacardTypeValuesCacheEnabled.

@Test
public void testMetacardTypeValuesCacheEnabled() throws Exception {
    final String ID = "id";
    Set<String> srcIds = new HashSet<>();
    srcIds.add(ID);
    BayeuxServer bayeuxServer = mock(BayeuxServer.class);
    ServerChannel channel = mock(ServerChannel.class);
    ArgumentCaptor<ServerMessage.Mutable> reply = ArgumentCaptor.forClass(ServerMessage.Mutable.class);
    when(bayeuxServer.getChannel(any(String.class))).thenReturn(channel);
    SearchRequest request = new SearchRequest(srcIds, getQueryRequest("title LIKE 'Meta*'"), ID);
    searchController.setBayeuxServer(bayeuxServer);
    searchController.setCacheDisabled(false);
    searchController.executeQuery(request, mockServerSession, null);
    verify(channel, timeout(1000).times(2)).publish(any(ServerSession.class), reply.capture());
    List<Mutable> replies = reply.getAllValues();
    assertReplies(replies);
}
Also used : Mutable(org.cometd.bayeux.server.ServerMessage.Mutable) SearchRequest(org.codice.ddf.ui.searchui.query.model.SearchRequest) ServerSession(org.cometd.bayeux.server.ServerSession) BayeuxServer(org.cometd.bayeux.server.BayeuxServer) ServerMessage(org.cometd.bayeux.server.ServerMessage) Matchers.anyString(org.mockito.Matchers.anyString) ServerChannel(org.cometd.bayeux.server.ServerChannel) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 3 with BayeuxServer

use of org.cometd.bayeux.server.BayeuxServer 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)

Example 4 with BayeuxServer

use of org.cometd.bayeux.server.BayeuxServer in project ddf by codice.

the class SearchControllerTest method cacheQuery.

private List<String> cacheQuery(Set<String> srcIds, int queryRequestCount) throws CQLException, UnsupportedQueryException, SourceUnavailableException, FederationException {
    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);
    ArgumentCaptor<QueryRequest> queryRequestCaptor = ArgumentCaptor.forClass(QueryRequest.class);
    searchController.setCacheDisabled(false);
    searchController.setNormalizationDisabled(false);
    searchController.setBayeuxServer(bayeuxServer);
    // Perform Test
    searchController.executeQuery(request, mockServerSession, null);
    // Verify
    verify(framework, times(queryRequestCount)).query(queryRequestCaptor.capture());
    List<QueryRequest> capturedQueryRequests = queryRequestCaptor.getAllValues();
    List<String> modes = new ArrayList<>(queryRequestCount);
    for (QueryRequest queryRequest : capturedQueryRequests) {
        for (String key : queryRequest.getProperties().keySet()) {
            modes.add((String) queryRequest.getPropertyValue(key));
        }
    }
    return modes;
}
Also used : SearchRequest(org.codice.ddf.ui.searchui.query.model.SearchRequest) QueryRequest(ddf.catalog.operation.QueryRequest) BayeuxServer(org.cometd.bayeux.server.BayeuxServer) ArrayList(java.util.ArrayList) Matchers.anyString(org.mockito.Matchers.anyString) ServerChannel(org.cometd.bayeux.server.ServerChannel)

Example 5 with BayeuxServer

use of org.cometd.bayeux.server.BayeuxServer in project ddf by codice.

the class SearchControllerTest method testExecuteQueryCacheDisabled.

/**
     * Verify that the CatalogFramework does not use the cache (i.e. the CatalogFramework
     * is called WITHOUT the query request property mode=cache).
     */
@Test
public void testExecuteQueryCacheDisabled() throws Exception {
    // Setup
    final String ID = "id";
    Set<String> srcIds = new HashSet<>(1);
    srcIds.add(ID);
    SearchRequest request = new SearchRequest(srcIds, getQueryRequest("title LIKE 'Meta*'"), ID);
    BayeuxServer bayeuxServer = mock(BayeuxServer.class);
    ServerChannel channel = mock(ServerChannel.class);
    when(bayeuxServer.getChannel(any(String.class))).thenReturn(channel);
    ArgumentCaptor<QueryRequest> queryRequestCaptor = ArgumentCaptor.forClass(QueryRequest.class);
    // Enable Cache
    searchController.setCacheDisabled(true);
    searchController.setBayeuxServer(bayeuxServer);
    // Perform Test
    searchController.executeQuery(request, mockServerSession, null);
    // Verify
    verify(framework).query(queryRequestCaptor.capture());
    assertThat(queryRequestCaptor.getValue().getProperties().size(), is(0));
}
Also used : SearchRequest(org.codice.ddf.ui.searchui.query.model.SearchRequest) QueryRequest(ddf.catalog.operation.QueryRequest) BayeuxServer(org.cometd.bayeux.server.BayeuxServer) Matchers.anyString(org.mockito.Matchers.anyString) ServerChannel(org.cometd.bayeux.server.ServerChannel) HashSet(java.util.HashSet) Test(org.junit.Test)

Aggregations

BayeuxServer (org.cometd.bayeux.server.BayeuxServer)6 ServerChannel (org.cometd.bayeux.server.ServerChannel)6 SearchRequest (org.codice.ddf.ui.searchui.query.model.SearchRequest)5 Matchers.anyString (org.mockito.Matchers.anyString)5 HashSet (java.util.HashSet)4 Test (org.junit.Test)4 QueryRequest (ddf.catalog.operation.QueryRequest)3 ServerMessage (org.cometd.bayeux.server.ServerMessage)3 ServerSession (org.cometd.bayeux.server.ServerSession)3 Mutable (org.cometd.bayeux.server.ServerMessage.Mutable)2 CatalogFramework (ddf.catalog.CatalogFramework)1 GeotoolsFilterAdapterImpl (ddf.catalog.filter.proxy.adapter.GeotoolsFilterAdapterImpl)1 QueryResponse (ddf.catalog.operation.QueryResponse)1 ArrayList (java.util.ArrayList)1 ActionRegistryImpl (org.codice.ddf.ui.searchui.query.actions.ActionRegistryImpl)1 SearchService (org.codice.ddf.ui.searchui.query.service.SearchService)1 UserService (org.codice.ddf.ui.searchui.query.service.UserService)1 WorkspaceService (org.codice.ddf.ui.searchui.query.service.WorkspaceService)1 ServerAnnotationProcessor (org.cometd.annotation.ServerAnnotationProcessor)1 DefaultSecurityPolicy (org.cometd.server.DefaultSecurityPolicy)1