Package org.springframework.test.web.servlet

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


    tokenStore.storeAccessToken(token, authentication);
    AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext();
    context.setServletContext(new MockServletContext());
    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();
  }
View Full Code Here


    tokenStore.storeAccessToken(token, authentication);
    AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext();
    context.setServletContext(new MockServletContext());
    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();
  }
View Full Code Here

    tokenStore.storeAccessToken(token, authentication);
    AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext();
    context.setServletContext(new MockServletContext());
    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();
  }
View Full Code Here

  public void testAuthCodeRedirect() throws Exception {
    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

    ContentNegotiatingViewResolver cnViewResolver = new ContentNegotiatingViewResolver();
    cnViewResolver.setDefaultViews(viewList);
    cnViewResolver.setContentNegotiationManager(manager);
    cnViewResolver.afterPropertiesSet();

    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"));

    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

  private RestTemplate restTemplate;


  @Before
  public void setup() {
    MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(this.wac).alwaysExpect(status().isOk()).build();
    this.restTemplate = new RestTemplate(new MockMvcClientHttpRequestFactory(mockMvc));
  }
View Full Code Here

    StubUsersConnectionRepository usersConnectionRepository = new StubUsersConnectionRepository();
    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"))));
  }
View Full Code Here

    StubUsersConnectionRepository usersConnectionRepository = new StubUsersConnectionRepository();
    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"));
  }
View Full Code Here

    ConnectionFactory<TestApi1> connectionFactory1 = new StubOAuth1ConnectionFactory("clientId", "clientSecret");
    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

    connectionFactoryLocator.addConnectionFactory(connectionFactory1);
    StubUsersConnectionRepository usersConnectionRepository = new StubUsersConnectionRepository();
    ProviderSignInController providerSignInController = new ProviderSignInController(connectionFactoryLocator, usersConnectionRepository, null);
    providerSignInController.setSignUpUrl("/register");
    providerSignInController.afterPropertiesSet();
    MockMvc mockMvc = standaloneSetup(providerSignInController).build();
    mockMvc.perform(get("/signin/oauth1Provider").param("verifier", "verifier").param("oauth_token", "requestToken"))
      .andExpect(redirectedUrl("/register"))
      .andExpect(request().sessionAttribute(ProviderSignInAttempt.class.getName(), notNullValue()));
    // TODO: Assert attempt contents
  }
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.