connectionFactoryLocator.addConnectionFactory(connectionFactory1);
ConnectionFactory<TestApi2> connectionFactory2 = new StubOAuth2ConnectionFactory("clientId", "clientSecret", THROW_EXCEPTION);
connectionFactoryLocator.addConnectionFactory(connectionFactory2);
StubConnectionRepository connectionRepository = new StubConnectionRepository();
connectionRepository.addConnection(connectionFactory1.createConnection(new ConnectionData("oauth1Provider", "provider1User1", null, null, null, null, null, null, null)));
MockMvc mockMvc = standaloneSetup(new ConnectController(connectionFactoryLocator, connectionRepository)).build();
mockMvc.perform(get("/connect"))
.andExpect(view().name("connect/status"))
.andExpect(model().attribute("providerIds", new HashSet<String>(asList("oauth1Provider", "oauth2Provider"))))
.andExpect(model().attributeExists("connectionMap"));
mockMvc.perform(get("/connect/oauth1Provider"))
.andExpect(view().name("connect/oauth1ProviderConnected"))
.andExpect(model().attributeExists("connections"))
.andExpect(request().attribute("social.addConnection.duplicate", nullValue()))
.andExpect(request().attribute("social.provider.error", nullValue()));
mockMvc.perform(get("/connect/oauth2Provider"))
.andExpect(view().name("connect/oauth2ProviderConnect"))
.andExpect(request().attribute("social.addConnection.duplicate", nullValue()))
.andExpect(request().attribute("social.provider.error", nullValue()));
}