use of org.cometd.bayeux.MarkedReference 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();
}
Aggregations