Package org.springframework.social.connect.web.test

Examples of org.springframework.social.connect.web.test.StubConnectionRepository


    ConnectionFactoryRegistry connectionFactoryLocator = new ConnectionFactoryRegistry();
    ConnectionFactory<TestApi1> connectionFactory1 = new StubOAuth1ConnectionFactory("clientId", "clientSecret", THROW_EXCEPTION);
    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"))))
View Full Code Here


  @Test
  public void connectionStatus_withErrorsInFlashScope() throws Exception {
    ConnectionFactoryRegistry connectionFactoryLocator = new ConnectionFactoryRegistry();
    ConnectionFactory<TestApi2> connectionFactory2 = new StubOAuth2ConnectionFactory("clientId", "clientSecret", THROW_EXCEPTION);
    connectionFactoryLocator.addConnectionFactory(connectionFactory2);       
    StubConnectionRepository connectionRepository = new StubConnectionRepository();
    MockMvc mockMvc = standaloneSetup(new ConnectController(connectionFactoryLocator, connectionRepository)).build();
   
    // Should convert errors in "flash" scope to model attributes and remove them from "flash"
    mockMvc.perform(get("/connect/oauth2Provider").sessionAttr("social_addConnection_duplicate", new DuplicateConnectionException(null)))
      .andExpect(view().name("connect/oauth2ProviderConnect"))
View Full Code Here

  @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);
View Full Code Here

  @Test
  public void removeConnection() 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("oauth2Provider", "provider1User1", null, null, null, null, null, null, null)));
    connectionRepository.addConnection(connectionFactory.createConnection(new ConnectionData("oauth2Provider", "provider1User2", null, null, null, null, null, null, null)));
    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/provider1User1"))
      .andExpect(redirectedUrl("/connect/oauth2Provider"));
    assertEquals(1, 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);
View Full Code Here

  @Test
  public void oauth1Callback() throws Exception {
    ConnectionFactoryRegistry connectionFactoryLocator = new ConnectionFactoryRegistry();
    ConnectionFactory<TestApi1> connectionFactory = new StubOAuth1ConnectionFactory("clientId", "clientSecret");
    connectionFactoryLocator.addConnectionFactory(connectionFactory);
    StubConnectionRepository connectionRepository = new StubConnectionRepository();
    ConnectController connectController = new ConnectController(connectionFactoryLocator, connectionRepository);
    List<ConnectInterceptor<?>> interceptors = getConnectInterceptor();
    connectController.setConnectInterceptors(interceptors);
    connectController.afterPropertiesSet();
    MockMvc mockMvc = standaloneSetup(connectController).build();
    assertEquals(0, connectionRepository.findConnections("oauth2Provider").size());   
    mockMvc.perform(get("/connect/oauth1Provider")
            .sessionAttr("oauthToken", new OAuthToken("requestToken", "requestTokenSecret"))
            .param("oauth_token", "requestToken")
            .param("oauth_verifier", "verifier"))
      .andExpect(redirectedUrl("/connect/oauth1Provider"));
    List<Connection<?>> connections = connectionRepository.findConnections("oauth1Provider");
    assertEquals(1, connections.size());
    assertEquals("oauth1Provider", connections.get(0).getKey().getProviderId());
    // Check for postConnect() only. The preConnect() is only invoked during the initial portion of the flow
    TestConnectInterceptor<?> testInterceptor1 = (TestConnectInterceptor<?>)(interceptors.get(0));
    assertTrue(testInterceptor1.postConnectInvoked);
View Full Code Here

  @Test
  public void oauth1Callback_exceptionWhileFetchingAccessToken() throws Exception {
    ConnectionFactoryRegistry connectionFactoryLocator = new ConnectionFactoryRegistry();
    ConnectionFactory<TestApi1> connectionFactory = new StubOAuth1ConnectionFactory("clientId", "clientSecret", THROW_EXCEPTION);
    connectionFactoryLocator.addConnectionFactory(connectionFactory);
    StubConnectionRepository connectionRepository = new StubConnectionRepository();
    MockMvc mockMvc = standaloneSetup(new ConnectController(connectionFactoryLocator, connectionRepository)).build();
    assertEquals(0, connectionRepository.findConnections("oauth2Provider").size());   
    mockMvc.perform(get("/connect/oauth1Provider")
            .sessionAttr("oauthToken", new OAuthToken("requestToken", "requestTokenSecret"))
            .param("oauth_token", "requestToken")
            .param("oauth_verifier", "verifier"))
      .andExpect(redirectedUrl("/connect/oauth1Provider"))
      .andExpect(request().sessionAttribute("social_provider_error", notNullValue()));
    assertEquals(0, connectionRepository.findConnections("oauth2Provider").size());   
  }
View Full Code Here

  @Test
  public void oauth2Callback() throws Exception {
    ConnectionFactoryRegistry connectionFactoryLocator = new ConnectionFactoryRegistry();
    ConnectionFactory<TestApi2> connectionFactory = new StubOAuth2ConnectionFactory("clientId", "clientSecret");
    connectionFactoryLocator.addConnectionFactory(connectionFactory);
    StubConnectionRepository connectionRepository = new StubConnectionRepository();
    ConnectController connectController = new ConnectController(connectionFactoryLocator, connectionRepository);
    List<ConnectInterceptor<?>> interceptors = getConnectInterceptor();
    connectController.setConnectInterceptors(interceptors);
    connectController.afterPropertiesSet();
    MockMvc mockMvc = standaloneSetup(connectController).build();
    assertEquals(0, connectionRepository.findConnections("oauth2Provider").size());   
    mockMvc.perform(get("/connect/oauth2Provider").param("code", "oauth2Code"))
      .andExpect(redirectedUrl("/connect/oauth2Provider"));
    List<Connection<?>> connections = connectionRepository.findConnections("oauth2Provider");
    assertEquals(1, connections.size());
    assertEquals("oauth2Provider", connections.get(0).getKey().getProviderId());
    // Check for postConnect() only. The preConnect() is only invoked during the initial portion of the flow
    assertFalse(((TestConnectInterceptor<?>)(interceptors.get(0))).postConnectInvoked);
    TestConnectInterceptor<?> testInterceptor2 = (TestConnectInterceptor<?>)(interceptors.get(1));
View Full Code Here

  @Test
  public void oauth2Callback_exceptionWhileFetchingAccessToken() throws Exception {
    ConnectionFactoryRegistry connectionFactoryLocator = new ConnectionFactoryRegistry();
    ConnectionFactory<TestApi2> connectionFactory = new StubOAuth2ConnectionFactory("clientId", "clientSecret", THROW_EXCEPTION);
    connectionFactoryLocator.addConnectionFactory(connectionFactory);
    StubConnectionRepository connectionRepository = new StubConnectionRepository();
    MockMvc mockMvc = standaloneSetup(new ConnectController(connectionFactoryLocator, connectionRepository)).build();
    assertEquals(0, connectionRepository.findConnections("oauth2Provider").size());   
    mockMvc.perform(get("/connect/oauth2Provider").param("code", "oauth2Code"))
      .andExpect(redirectedUrl("/connect/oauth2Provider"))
      .andExpect(request().sessionAttribute("social_provider_error", notNullValue()));
    assertEquals(0, connectionRepository.findConnections("oauth2Provider").size());   
  }
View Full Code Here

  @Test
  public void oauth2ErrorCallback() throws Exception {
    ConnectionFactoryRegistry connectionFactoryLocator = new ConnectionFactoryRegistry();
    ConnectionFactory<TestApi2> connectionFactory = new StubOAuth2ConnectionFactory("clientId", "clientSecret", THROW_EXCEPTION);
    connectionFactoryLocator.addConnectionFactory(connectionFactory);
    StubConnectionRepository connectionRepository = new StubConnectionRepository();
    MockMvc mockMvc = standaloneSetup(new ConnectController(connectionFactoryLocator, connectionRepository)).build();
    assertEquals(0, connectionRepository.findConnections("oauth2Provider").size());   
    HashMap<String, String> expectedError = new HashMap<String, String>();
    expectedError.put("error", "access_denied");
    expectedError.put("errorDescription", "The user said no.");
    expectedError.put("errorUri", "http://provider.com/user/said/no");
    mockMvc.perform(get("/connect/oauth2Provider").param("error", "access_denied")
View Full Code Here

  @Test
  public void oauth2ErrorCallback_noDescriptionOrUri() throws Exception {
    ConnectionFactoryRegistry connectionFactoryLocator = new ConnectionFactoryRegistry();
    ConnectionFactory<TestApi2> connectionFactory = new StubOAuth2ConnectionFactory("clientId", "clientSecret", THROW_EXCEPTION);
    connectionFactoryLocator.addConnectionFactory(connectionFactory);
    StubConnectionRepository connectionRepository = new StubConnectionRepository();
    MockMvc mockMvc = standaloneSetup(new ConnectController(connectionFactoryLocator, connectionRepository)).build();
    assertEquals(0, connectionRepository.findConnections("oauth2Provider").size());   
    HashMap<String, String> expectedError = new HashMap<String, String>();
    expectedError.put("error", "access_denied");
    mockMvc.perform(get("/connect/oauth2Provider").param("error", "access_denied"))
      .andExpect(redirectedUrl("/connect/oauth2Provider"))
      .andExpect(request().sessionAttribute("social_authorization_error", notNullValue()))
View Full Code Here

TOP

Related Classes of org.springframework.social.connect.web.test.StubConnectionRepository

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.