Package org.springframework.test.web.servlet

Examples of org.springframework.test.web.servlet.MockMvc.perform()


    context.register(ResourceServerContext.class);
    context.refresh();
    MockMvc mvc = MockMvcBuilders.webAppContextSetup(context)
        .addFilters(new DelegatingFilterProxy(context.getBean("springSecurityFilterChain", Filter.class)))
        .build();
    mvc.perform(MockMvcRequestBuilders.get("/")).andExpect(MockMvcResultMatchers.status().isUnauthorized());
    context.close();
  }

  @Test
  public void testCustomTokenServices() throws Exception {
View Full Code Here


    context.register(TokenServicesContext.class);
    context.refresh();
    MockMvc mvc = MockMvcBuilders.webAppContextSetup(context)
        .addFilters(new DelegatingFilterProxy(context.getBean("springSecurityFilterChain", Filter.class)))
        .build();
    mvc.perform(MockMvcRequestBuilders.get("/")).andExpect(MockMvcResultMatchers.status().isUnauthorized());
    context.close();
  }

  @Test
  public void testCustomTokenExtractor() throws Exception {
View Full Code Here

    context.register(TokenExtractorContext.class);
    context.refresh();
    MockMvc mvc = MockMvcBuilders.webAppContextSetup(context)
        .addFilters(new DelegatingFilterProxy(context.getBean("springSecurityFilterChain", Filter.class)))
        .build();
    mvc.perform(MockMvcRequestBuilders.get("/").header("Authorization", "Bearer BAR")).andExpect(
        MockMvcResultMatchers.status().isNotFound());
    context.close();
  }

  @Configuration
View Full Code Here

    AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext();
    context.setServletContext(new MockServletContext());
    context.register(ClientContext.class);
    context.refresh();
    MockMvc mvc = MockMvcBuilders.webAppContextSetup(context).addFilters(new OAuth2ClientContextFilter()).build();
    mvc.perform(MockMvcRequestBuilders.get("/photos"))
        .andExpect(MockMvcResultMatchers.status().isFound())
        .andExpect(
            MockMvcResultMatchers.header().string("Location",
                CoreMatchers.startsWith("http://example.com/authorize")));
    context.close();
View Full Code Here

    MockMvc mockMvc =
      standaloneSetup(new PersonController())
        .setViewResolvers(cnViewResolver, new InternalResourceViewResolver())
        .build();

    mockMvc.perform(get("/person/Corea"))
      .andExpect(status().isOk())
      .andExpect(model().size(1))
      .andExpect(model().attributeExists("person"))
      .andExpect(forwardedUrl("person/show"));
View Full Code Here

      .andExpect(status().isOk())
      .andExpect(model().size(1))
      .andExpect(model().attributeExists("person"))
      .andExpect(forwardedUrl("person/show"));

    mockMvc.perform(get("/person/Corea").accept(MediaType.APPLICATION_JSON))
      .andExpect(status().isOk())
      .andExpect(content().contentType(MediaType.APPLICATION_JSON))
      .andExpect(jsonPath("$.person.name").value("Corea"));

    mockMvc.perform(get("/person/Corea").accept(MediaType.APPLICATION_XML))
View Full Code Here

    mockMvc.perform(get("/person/Corea").accept(MediaType.APPLICATION_JSON))
      .andExpect(status().isOk())
      .andExpect(content().contentType(MediaType.APPLICATION_JSON))
      .andExpect(jsonPath("$.person.name").value("Corea"));

    mockMvc.perform(get("/person/Corea").accept(MediaType.APPLICATION_XML))
      .andExpect(status().isOk())
      .andExpect(content().contentType(MediaType.APPLICATION_XML))
      .andExpect(xpath("/person/name/text()").string(equalTo("Corea")));
  }
View Full Code Here

    usersConnectionRepository.createConnectionRepository("habuma").addConnection(connectionFactory1.createConnection(
      new ConnectionData("oauth1Provider", "provider1User1", null, null, null, null, null, null, null)));
    ProviderSignInController providerSignInController = new ProviderSignInController(connectionFactoryLocator, usersConnectionRepository, null);
    providerSignInController.afterPropertiesSet();
    MockMvc mockMvc = standaloneSetup(providerSignInController).build();
    mockMvc.perform(post("/signin/oauth1Provider"))
      .andExpect(redirectedUrl("https://someprovider.com/oauth/authorize?oauth_token=requestToken"))
      .andExpect(request().sessionAttribute("oauthToken", samePropertyValuesAs(new OAuthToken("requestToken", "requestTokenSecret"))));
  }

  @Test
View Full Code Here

    usersConnectionRepository.createConnectionRepository("habuma").addConnection(connectionFactory1.createConnection(
      new ConnectionData("oauth1Provider", "provider1User1", null, null, null, null, null, null, null)));
    ProviderSignInController providerSignInController = new ProviderSignInController(connectionFactoryLocator, usersConnectionRepository, null);
    providerSignInController.afterPropertiesSet();
    MockMvc mockMvc = standaloneSetup(providerSignInController).build();
    mockMvc.perform(post("/signin/oauth1Provider"))
      .andExpect(redirectedUrl("/signin?error=provider"));
  }

  @Test
  public void oauth1Callback_noMatchingUser() throws Exception {
View Full Code Here

    connectionFactoryLocator.addConnectionFactory(connectionFactory1);
    StubUsersConnectionRepository usersConnectionRepository = new StubUsersConnectionRepository();
    ProviderSignInController providerSignInController = new ProviderSignInController(connectionFactoryLocator, usersConnectionRepository, null);
    providerSignInController.afterPropertiesSet();
    MockMvc mockMvc = standaloneSetup(providerSignInController).build();
    mockMvc.perform(get("/signin/oauth1Provider").param("verifier", "verifier").param("oauth_token", "requestToken"))
      .andExpect(redirectedUrl("/signup"))
      .andExpect(request().sessionAttribute(ProviderSignInAttempt.class.getName(), notNullValue()));
    // TODO: Assert attempt contents
  }
View Full Code Here

TOP
Copyright © 2018 www.massapi.com. 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.