@Test
public void removeConnections() throws Exception {
ConnectionFactoryRegistry connectionFactoryLocator = new ConnectionFactoryRegistry();
ConnectionFactory<TestApi2> connectionFactory = new StubOAuth2ConnectionFactory("clientId", "clientSecret", THROW_EXCEPTION);
connectionFactoryLocator.addConnectionFactory(connectionFactory);
StubConnectionRepository connectionRepository = new StubConnectionRepository();
connectionRepository.addConnection(connectionFactory.createConnection(new ConnectionData("provider1", "provider1User1", null, null, null, null, null, null, null)));
connectionRepository.addConnection(connectionFactory.createConnection(new ConnectionData("provider1", "provider1User2", null, null, null, null, null, null, null)));
connectionRepository.addConnection(connectionFactory.createConnection(new ConnectionData("oauth2Provider", "provider2User1", null, null, null, null, null, null, null)));
connectionRepository.addConnection(connectionFactory.createConnection(new ConnectionData("oauth2Provider", "provider2User2", null, null, null, null, null, null, null)));
assertEquals(2, connectionRepository.findConnections("provider1").size());
assertEquals(2, connectionRepository.findConnections("oauth2Provider").size());
ConnectController connectController = new ConnectController(connectionFactoryLocator, connectionRepository);
List<DisconnectInterceptor<?>> interceptors = getDisconnectInterceptor();
connectController.setDisconnectInterceptors(interceptors);
MockMvc mockMvc = standaloneSetup(connectController).build();
mockMvc.perform(delete("/connect/oauth2Provider"))
.andExpect(redirectedUrl("/connect/oauth2Provider"));
assertEquals(2, connectionRepository.findConnections("provider1").size());
assertEquals(0, connectionRepository.findConnections("oauth2Provider").size());
assertFalse(((TestConnectInterceptor<?>)(interceptors.get(0))).preDisconnectInvoked);
assertFalse(((TestConnectInterceptor<?>)(interceptors.get(0))).postDisconnectInvoked);
assertNull(((TestConnectInterceptor<?>)(interceptors.get(0))).connectionFactory);
assertTrue(((TestConnectInterceptor<?>)(interceptors.get(1))).preDisconnectInvoked);
assertTrue(((TestConnectInterceptor<?>)(interceptors.get(1))).postDisconnectInvoked);