Package org.springframework.test.web.client

Examples of org.springframework.test.web.client.MockRestServiceServer


    assertEquals(endTime, eventTimeSlotData.get("endTime").toString());
  }

 
  private MockRestServiceServer setupMockRestServiceServer(NFJSLoader loader, int numberOfLoads) {
    MockRestServiceServer mockServer = MockRestServiceServer.createServer(loader.getRestTemplate());
    for (int i=0; i < numberOfLoads; i++) {
      mockServer.expect(
          requestTo("https://springone2gx.com/m/data/show_short.json?showId=" + SHOW_ID))
          .andExpect(method(GET))
          .andRespond(ResponseCreators.withSuccess(new ClassPathResource("show_short.json", NFJSLoaderTest.class), APPLICATION_JSON));
      mockServer.expect(
          requestTo("https://springone2gx.com/m/data/show_schedule.json?showId=" + SHOW_ID))
          .andExpect(method(GET))
          .andRespond(ResponseCreators.withSuccess(new ClassPathResource("show_schedule.json", NFJSLoaderTest.class), APPLICATION_JSON));
      mockServer.expect(
          requestTo("https://springone2gx.com/m/data/show_speakers.json?showId=" + SHOW_ID))
          .andExpect(method(GET))
          .andRespond(ResponseCreators.withSuccess(new ClassPathResource("show_speakers.json", NFJSLoaderTest.class), APPLICATION_JSON));
      mockServer.expect(
          requestTo("https://springone2gx.com/m/data/show_topics.json?showId=" + SHOW_ID))
          .andExpect(method(GET))
          .andRespond(ResponseCreators.withSuccess(new ClassPathResource("show_topics.json", NFJSLoaderTest.class), APPLICATION_JSON));
    }
    return mockServer;
View Full Code Here


    }
    return mockServer;
  }
 
  private void setupMockRestServiceServerWithUpdates(NFJSLoader loader) {
    MockRestServiceServer mockServer = setupMockRestServiceServer(loader, 1); // setup initial load
    mockServer.expect(
        requestTo("https://springone2gx.com/m/data/show_short.json?showId=" + SHOW_ID))
        .andExpect(method(GET))
        .andRespond(ResponseCreators.withSuccess(new ClassPathResource("show_short_updated.json", NFJSLoaderTest.class), APPLICATION_JSON));
    mockServer.expect(
        requestTo("https://springone2gx.com/m/data/show_schedule.json?showId=" + SHOW_ID))
        .andExpect(method(GET))
        .andRespond(ResponseCreators.withSuccess(new ClassPathResource("show_schedule_updated.json", NFJSLoaderTest.class), APPLICATION_JSON));
    mockServer.expect(
        requestTo("https://springone2gx.com/m/data/show_speakers.json?showId=" + SHOW_ID))
        .andExpect(method(GET))
        .andRespond(ResponseCreators.withSuccess(new ClassPathResource("show_speakers_updated.json", NFJSLoaderTest.class), APPLICATION_JSON));
    mockServer.expect(
        requestTo("https://springone2gx.com/m/data/show_topics.json?showId=" + SHOW_ID))
        .andExpect(method(GET))
        .andRespond(ResponseCreators.withSuccess(new ClassPathResource("show_topics_updated.json", NFJSLoaderTest.class), APPLICATION_JSON));   
  }
View Full Code Here

  private AccessGrant getAccessGrant(String responseFile) {
    return getAccessGrant(oAuth2Template, "", "Basic Y2xpZW50X2lkOmNsaWVudF9zZWNyZXQ=", responseFile);
  }
 
  private AccessGrant getAccessGrant(OAuth2Template oauthTemplate, String expectedClientParams, String expectedAuthorizationHeader, String responseFile) {
    MockRestServiceServer mockServer = MockRestServiceServer.createServer(oauthTemplate.getRestTemplate());
    ResponseActions responseActions = mockServer.expect(requestTo(ACCESS_TOKEN_URL))
        .andExpect(method(POST))
        .andExpect(content().string(expectedClientParams + "code=code&redirect_uri=http%3A%2F%2Fwww.someclient.com%2Fcallback&grant_type=authorization_code"));
    if (expectedAuthorizationHeader != null) {
      responseActions.andExpect(header("Authorization", expectedAuthorizationHeader));
    }
View Full Code Here

  private AccessGrant passwordGrant(String responseFile) {
    return passwordGrant(oAuth2Template, "", "Basic Y2xpZW50X2lkOmNsaWVudF9zZWNyZXQ=", responseFile);
  }
 
  private AccessGrant passwordGrant(OAuth2Template oauthTemplate, String expectedClientParams, String expectedAuthorizationHeader, String responseFile) {
    MockRestServiceServer mockServer = MockRestServiceServer.createServer(oauthTemplate.getRestTemplate());
    ResponseActions responseActions = mockServer.expect(requestTo(ACCESS_TOKEN_URL))
        .andExpect(method(POST))
        .andExpect(content().string(expectedClientParams + "username=habuma&password=letmein01&grant_type=password&scope=read%2Cwrite"));
    if (expectedAuthorizationHeader != null) {
      responseActions.andExpect(header("Authorization", expectedAuthorizationHeader));
    }
View Full Code Here

  private AccessGrant clientCredentials(String responseFile) {
    return clientCredentials(oAuth2Template, "", "Basic Y2xpZW50X2lkOmNsaWVudF9zZWNyZXQ=", responseFile);
  }

    private AccessGrant clientCredentials(OAuth2Template oauthTemplate, String expectedClientParams, String expectedAuthorizationHeader, String responseFile) {
    MockRestServiceServer mockServer = MockRestServiceServer.createServer(oauthTemplate.getRestTemplate());
    ResponseActions responseActions = mockServer.expect(requestTo(ACCESS_TOKEN_URL))
        .andExpect(method(POST))
        .andExpect(content().string(expectedClientParams + "grant_type=client_credentials&scope=read%2Cwrite"));
    if (expectedAuthorizationHeader != null) {
      responseActions.andExpect(header("Authorization", expectedAuthorizationHeader));
    }
View Full Code Here

  private AccessGrant refreshToken(String responseFile) {
    return refreshToken(oAuth2Template, "", "Basic Y2xpZW50X2lkOmNsaWVudF9zZWNyZXQ=", responseFile);
  }
 
  private AccessGrant refreshToken(OAuth2Template oauthTemplate, String expectedClientParams, String expectedAuthorizationHeader, String responseFile) {
    MockRestServiceServer mockServer = MockRestServiceServer.createServer(oauthTemplate.getRestTemplate());
    ResponseActions responseActions = mockServer.expect(requestTo(ACCESS_TOKEN_URL))
        .andExpect(method(POST))
        .andExpect(content().string(expectedClientParams + "refresh_token=r3fr35h_t0k3n&grant_type=refresh_token"));
    if (expectedAuthorizationHeader != null) {
      responseActions.andExpect(header("Authorization", expectedAuthorizationHeader));
    }
View Full Code Here

        customOauth10.buildAuthorizeUrl("request_token", parameters));
  }

  @Test
  public void fetchNewRequestToken_OAuth10a() {
    MockRestServiceServer mockServer = MockRestServiceServer.createServer(oauth10a.getRestTemplate());
    HttpHeaders responseHeaders = new HttpHeaders();
    responseHeaders.setContentType(MediaType.APPLICATION_FORM_URLENCODED);
   
    mockServer
        .expect(requestTo(REQUEST_TOKEN_URL))
        .andExpect(method(POST))
        .andExpect(headerContains("Authorization", "oauth_callback=\"http%3A%2F%2Fwww.someclient.com%2Foauth%2Fcallback\""))
        .andExpect(headerContains("Authorization", "oauth_version=\"1.0\""))
        .andExpect(headerContains("Authorization", "oauth_signature_method=\"HMAC-SHA1\""))
View Full Code Here

    assertEquals("abcdefghijklmnop", requestToken.getSecret());
  }

  @Test
  public void fetchNewRequestToken_OAuth10() {
    MockRestServiceServer mockServer = MockRestServiceServer.createServer(oauth10.getRestTemplate());
    HttpHeaders responseHeaders = new HttpHeaders();
    responseHeaders.setContentType(MediaType.APPLICATION_FORM_URLENCODED);
    mockServer.expect(requestTo(REQUEST_TOKEN_URL))
        .andExpect(method(POST))
        .andExpect(headerContains("Authorization", "oauth_version=\"1.0\""))
        .andExpect(headerContains("Authorization", "oauth_signature_method=\"HMAC-SHA1\""))
        .andExpect(headerContains("Authorization", "oauth_consumer_key=\"consumer_key\""))
        .andExpect(headerContains("Authorization", "oauth_nonce=\""))
View Full Code Here

    assertEquals("abcdefghijklmnop", requestToken.getSecret());
  }

  @Test
  public void exchangeForAccessToken_OAuth10a() {
    MockRestServiceServer mockServer = MockRestServiceServer.createServer(oauth10a.getRestTemplate());
    HttpHeaders responseHeaders = new HttpHeaders();
    responseHeaders.setContentType(MediaType.APPLICATION_FORM_URLENCODED);
    mockServer
        .expect(requestTo(ACCESS_TOKEN_URL))
        .andExpect(method(POST))
        .andExpect(headerContains("Authorization", "oauth_version=\"1.0\""))
        .andExpect(headerContains("Authorization", "oauth_signature_method=\"HMAC-SHA1\""))
        .andExpect(headerContains("Authorization", "oauth_consumer_key=\"consumer_key\""))
View Full Code Here

    assertEquals("ponmlkjihgfedcba", accessToken.getSecret());
  }

  @Test
  public void exchangeForAccessToken_OAuth10() {
    MockRestServiceServer mockServer = MockRestServiceServer.createServer(oauth10.getRestTemplate());
    HttpHeaders responseHeaders = new HttpHeaders();
    responseHeaders.setContentType(MediaType.APPLICATION_FORM_URLENCODED);
    mockServer
        .expect(requestTo(ACCESS_TOKEN_URL))
        .andExpect(method(POST))
        .andExpect(headerContains("Authorization", "oauth_version=\"1.0\""))
        .andExpect(headerContains("Authorization", "oauth_signature_method=\"HMAC-SHA1\""))
        .andExpect(headerContains("Authorization", "oauth_consumer_key=\"consumer_key\""))
View Full Code Here

TOP

Related Classes of org.springframework.test.web.client.MockRestServiceServer

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.