Package org.springframework.test.web.servlet

Examples of org.springframework.test.web.servlet.MockMvc


    connectionFactoryLocator.addConnectionFactory(connectionFactory2);
    StubUsersConnectionRepository usersConnectionRepository = new StubUsersConnectionRepository(asList("testuser1", "testuser2"));
    ProviderSignInController controller = new ProviderSignInController(connectionFactoryLocator, usersConnectionRepository, null);
    controller.afterPropertiesSet();
    controller.setSignInUrl("/customsignin?someparameter=1234");
    MockMvc mockMvc = standaloneSetup(controller).build();
    mockMvc.perform(get("/signin/oauth2Provider").param("code", "authcode"))
      .andExpect(redirectedUrl("/customsignin?someparameter=1234&error=multiple_users"));
  }
View Full Code Here


  public void oauth2Callback_errorWhileExchangingForAccessToken() throws Exception {
    ConnectionFactoryRegistry connectionFactoryLocator = new ConnectionFactoryRegistry();
    ConnectionFactory<TestApi2> connectionFactory2 = new StubOAuth2ConnectionFactory("clientId", "clientSecret", StubOAuthTemplateBehavior.THROW_EXCEPTION);
    connectionFactoryLocator.addConnectionFactory(connectionFactory2);
    StubUsersConnectionRepository usersConnectionRepository = new StubUsersConnectionRepository(asList("testuser1"));
    MockMvc mockMvc = standaloneSetup(new ProviderSignInController(connectionFactoryLocator, usersConnectionRepository, null)).build();
    mockMvc.perform(get("/signin/oauth2Provider").param("code", "authcode"))
      .andExpect(redirectedUrl("/signin?error=provider"));
  }
View Full Code Here

    ProviderSignInController controller = new ProviderSignInController(connectionFactoryLocator, usersConnectionRepository, signInAdapter);
    controller.afterPropertiesSet();
    if (postSignInUrl != null) {
      controller.setPostSignInUrl(postSignInUrl);
    }
    MockMvc mockMvc = standaloneSetup(controller).build();
    mockMvc.perform(get("/signin/oauth2Provider").param("code", "authcode"))
      .andExpect(redirectedUrl(calculateExpectedRedirectUrl(originalUrl, postSignInUrl)));
    // TODO: Verify that the connection is updated (connectionRepository.updateConnection() is called)
  }
View Full Code Here

  @Test
  public void recordsHttpInteractionsWithTemplateVariable() throws Exception {
    AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(
        Config.class, MetricFilterAutoConfiguration.class);
    Filter filter = context.getBean(Filter.class);
    MockMvc mvc = MockMvcBuilders.standaloneSetup(new MetricFilterTestController())
        .addFilter(filter).build();
    mvc.perform(get("/templateVarTest/foo")).andExpect(status().isOk());

    verify(context.getBean(CounterService.class)).increment(
        "status.200.templateVarTest.someVariable");
    verify(context.getBean(GaugeService.class)).submit(
        eq("response.templateVarTest.someVariable"), anyDouble());
View Full Code Here

  public void recordsKnown404HttpInteractionsAsSingleMetricWithPathAndTemplateVariable()
      throws Exception {
    AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(
        Config.class, MetricFilterAutoConfiguration.class);
    Filter filter = context.getBean(Filter.class);
    MockMvc mvc = MockMvcBuilders.standaloneSetup(new MetricFilterTestController())
        .addFilter(filter).build();
    mvc.perform(get("/knownPath/foo")).andExpect(status().isNotFound());

    verify(context.getBean(CounterService.class)).increment(
        "status.404.knownPath.someVariable");
    verify(context.getBean(GaugeService.class)).submit(
        eq("response.knownPath.someVariable"), anyDouble());
View Full Code Here

  @Test
  public void records404HttpInteractionsAsSingleMetric() throws Exception {
    AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(
        Config.class, MetricFilterAutoConfiguration.class);
    Filter filter = context.getBean(Filter.class);
    MockMvc mvc = MockMvcBuilders.standaloneSetup(new MetricFilterTestController())
        .addFilter(filter).build();
    mvc.perform(get("/unknownPath/1")).andExpect(status().isNotFound());

    mvc.perform(get("/unknownPath/2")).andExpect(status().isNotFound());

    verify(context.getBean(CounterService.class), times(2)).increment(
        "status.404.unmapped");
    verify(context.getBean(GaugeService.class), times(2)).submit(
        eq("response.unmapped"), anyDouble());
View Full Code Here

  @Ignore("Revisit this and assert/fix expectations")
  public void connect_noSuchProvider() throws Exception {
    ConnectionFactoryRegistry connectionFactoryLocator = new ConnectionFactoryRegistry();
    ConnectionFactory<TestApi2> connectionFactory = new StubOAuth2ConnectionFactory("clientId", "clientSecret");
    connectionFactoryLocator.addConnectionFactory(connectionFactory);
    MockMvc mockMvc = standaloneSetup(new ConnectController(connectionFactoryLocator, null)).build();
    mockMvc.perform(post("/connect/noSuchProvider"));
  }
View Full Code Here

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

  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"))
      .andExpect(request().sessionAttribute("social_addConnection_duplicate", nullValue()))
      .andExpect(request().attribute("social_addConnection_duplicate", true));

    mockMvc.perform(get("/connect/oauth2Provider").sessionAttr("social_provider_error", new HttpClientErrorException(HttpStatus.INTERNAL_SERVER_ERROR)))
      .andExpect(view().name("connect/oauth2ProviderConnect"))
      .andExpect(request().sessionAttribute("social_provider_error", nullValue()))
      .andExpect(request().attribute("social_provider_error", true));
}
View Full Code Here

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

TOP

Related Classes of org.springframework.test.web.servlet.MockMvc

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.