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();
}
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());
}
Aggregations