Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Removed spring-social-test project; now relying on spring-test-mvc

  • Loading branch information...
commit 2933df7056799738e3ad58e356981951318284ab 1 parent 3b02cac
Craig Walls authored
Showing with 0 additions and 1,635 deletions.
  1. +0 −9 build.gradle
  2. +0 −1  settings.gradle
  3. +0 −67 spring-social-test/src/main/java/org/springframework/social/test/client/AssertionErrors.java
  4. +0 −113 spring-social-test/src/main/java/org/springframework/social/test/client/MockClientHttpRequest.java
  5. +0 −74 spring-social-test/src/main/java/org/springframework/social/test/client/MockClientHttpRequestFactory.java
  6. +0 −82 spring-social-test/src/main/java/org/springframework/social/test/client/MockClientHttpResponse.java
  7. +0 −58 spring-social-test/src/main/java/org/springframework/social/test/client/MockHttpRequest.java
  8. +0 −103 spring-social-test/src/main/java/org/springframework/social/test/client/MockRestServiceServer.java
  9. +0 −40 spring-social-test/src/main/java/org/springframework/social/test/client/RequestMatcher.java
  10. +0 −150 spring-social-test/src/main/java/org/springframework/social/test/client/RequestMatchers.java
  11. +0 −39 spring-social-test/src/main/java/org/springframework/social/test/client/ResponseActions.java
  12. +0 −36 spring-social-test/src/main/java/org/springframework/social/test/client/ResponseCreator.java
  13. +0 −103 spring-social-test/src/main/java/org/springframework/social/test/client/ResponseCreators.java
  14. +0 −39 spring-social-test/src/main/java/org/springframework/social/test/client/UriMatcher.java
  15. +0 −5 spring-social-test/src/main/java/org/springframework/social/test/client/package-info.java
  16. +0 −47 spring-social-test/src/test/java/org/springframework/social/connect/oauth1/StubOAuth1Operations.java
  17. +0 −1  spring-social-test/src/test/java/org/springframework/social/connect/oauth1/accessToken.formencoded
  18. +0 −1  spring-social-test/src/test/java/org/springframework/social/connect/oauth1/requestToken.formencoded
  19. +0 −41 spring-social-test/src/test/java/org/springframework/social/connect/oauth2/StubOAuth2Operations.java
  20. +0 −1  spring-social-test/src/test/java/org/springframework/social/connect/oauth2/accessToken.facebook
  21. +0 −8 spring-social-test/src/test/java/org/springframework/social/connect/oauth2/accessToken.json
  22. +0 −70 spring-social-test/src/test/java/org/springframework/social/oauth1/OAuth1RequestInterceptorTest.java
  23. +0 −202 spring-social-test/src/test/java/org/springframework/social/oauth1/OAuth1TemplateTest.java
  24. +0 −1  spring-social-test/src/test/java/org/springframework/social/oauth1/accessToken.formencoded
  25. +0 −1  spring-social-test/src/test/java/org/springframework/social/oauth1/requestToken.formencoded
  26. +0 −64 spring-social-test/src/test/java/org/springframework/social/oauth2/OAuth2RequestInterceptorTest.java
  27. +0 −229 spring-social-test/src/test/java/org/springframework/social/oauth2/OAuth2TemplateTest.java
  28. +0 −1  spring-social-test/src/test/java/org/springframework/social/oauth2/accessToken.facebook
  29. +0 −8 spring-social-test/src/test/java/org/springframework/social/oauth2/accessToken.json
  30. +0 −8 ...ng-social-test/src/test/java/org/springframework/social/oauth2/accessToken_expiresInAsNonNumericString.json
  31. +0 −8 spring-social-test/src/test/java/org/springframework/social/oauth2/accessToken_expiresInAsString.json
  32. +0 −7 spring-social-test/src/test/java/org/springframework/social/oauth2/accessToken_noExpiresIn.json
  33. +0 −5 spring-social-test/src/test/java/org/springframework/social/oauth2/accessToken_noExpiresInOrScope.json
  34. +0 −7 spring-social-test/src/test/java/org/springframework/social/oauth2/refreshToken.json
  35. +0 −6 spring-social-test/src/test/java/org/springframework/social/oauth2/refreshToken_noExpiresIn.json
View
9 build.gradle
@@ -168,15 +168,6 @@ project('spring-social-web') {
metaInf << files("src/main/resources/tld/spring-social.tld")
}
-project('spring-social-test') {
- description = 'Rest Template Test Support'
- dependencies {
- compile project(':spring-social-core')
- compile ("org.springframework:spring-web:$springVersion")
- testCompile "org.codehaus.jackson:jackson-mapper-asl:$jacksonVersion"
- }
-}
-
// -----------------------------------------------------------------------------
// Configuration for the docs subproject
// -----------------------------------------------------------------------------
View
1  settings.gradle
@@ -19,4 +19,3 @@ rootProject.name = 'spring-social'
include 'docs'
include 'spring-social-core'
include 'spring-social-web'
-include 'spring-social-test'
View
67 spring-social-test/src/main/java/org/springframework/social/test/client/AssertionErrors.java
@@ -1,67 +0,0 @@
-/*
- * Copyright 2011 the original author or authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.springframework.social.test.client;
-
-/**
- * JUnit independent assertion class.
- *
- * @author Lukas Krecan
- * @author Arjen Poutsma
- * @author Craig Walls
- */
-public abstract class AssertionErrors {
-
- private AssertionErrors() {
- }
-
- /**
- * Fails a test with the given message.
- *
- * @param message the message
- */
- public static void fail(String message) {
- throw new AssertionError(message);
- }
-
- /**
- * Asserts that a condition is {@code true}. If not, throws an {@link AssertionError} with the given message.
- *
- * @param message the message
- * @param condition the condition to test for
- */
- public static void assertTrue(String message, boolean condition) {
- if (!condition) {
- fail(message);
- }
- }
-
- /**
- * Asserts that two objects are equal. If not, an {@link AssertionError} is thrown with the given message.
- *
- * @param message the message
- * @param expected the expected value
- * @param actual the actual value
- */
- public static void assertEquals(String message, Object expected, Object actual) {
- if (expected == null && actual == null) {
- return;
- }
- if (expected != null && expected.equals(actual)) {
- return;
- }
- fail(message + " expected:<" + expected + "> but was:<" + actual + ">");
- }
-}
View
113 ...cial-test/src/main/java/org/springframework/social/test/client/MockClientHttpRequest.java
@@ -1,113 +0,0 @@
-/*
- * Copyright 2011 the original author or authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.springframework.social.test.client;
-
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
-import java.io.OutputStream;
-import java.net.URI;
-import java.util.LinkedList;
-import java.util.List;
-
-import org.springframework.http.HttpHeaders;
-import org.springframework.http.HttpMethod;
-import org.springframework.http.client.ClientHttpRequest;
-import org.springframework.http.client.ClientHttpResponse;
-import org.springframework.util.Assert;
-
-/**
- * Mock implementation of {@link ClientHttpRequest}. Implements {@link ResponseActions} to form a fluent API.
- *
- * @author Arjen Poutsma
- * @author Lukas Krecan
- * @author Craig Walls
- */
-public class MockClientHttpRequest implements ClientHttpRequest, ResponseActions {
-
- private final List<RequestMatcher> requestMatchers = new LinkedList<RequestMatcher>();
-
- private ResponseCreator responseCreator;
-
- private URI uri;
-
- private HttpMethod httpMethod;
-
- private HttpHeaders httpHeaders = new HttpHeaders();
-
- private ByteArrayOutputStream bodyStream = new ByteArrayOutputStream();
-
- public void setUri(URI uri) {
- this.uri = uri;
- }
-
- public void setHttpMethod(HttpMethod httpMethod) {
- this.httpMethod = httpMethod;
- }
-
- void addRequestMatcher(RequestMatcher requestMatcher) {
- Assert.notNull(requestMatcher, "'requestMatcher' must not be null");
- requestMatchers.add(requestMatcher);
- }
-
- // ResponseActions implementation
-
- public ResponseActions andExpect(RequestMatcher requestMatcher) {
- addRequestMatcher(requestMatcher);
- return this;
- }
-
- public void andRespond(ResponseCreator responseCreator) {
- Assert.notNull(responseCreator, "'responseCreator' must not be null");
- this.responseCreator = responseCreator;
- }
-
- public HttpMethod getMethod() {
- return httpMethod;
- }
-
- public URI getURI() {
- return uri;
- }
-
- public HttpHeaders getHeaders() {
- return httpHeaders;
- }
-
- public OutputStream getBody() throws IOException {
- return bodyStream;
- }
-
- public String getBodyContent() throws IOException {
- return bodyStream.toString("UTF-8");
- }
-
- public ClientHttpResponse execute() throws IOException {
- if (!requestMatchers.isEmpty()) {
- for (RequestMatcher requestMatcher : requestMatchers) {
- requestMatcher.match(this);
- }
- } else {
- throw new AssertionError("Unexpected execute()");
- }
-
- if (responseCreator != null) {
- return responseCreator.createResponse(this);
- } else {
- return null;
- }
- }
-
-}
View
74 ...st/src/main/java/org/springframework/social/test/client/MockClientHttpRequestFactory.java
@@ -1,74 +0,0 @@
-/*
- * Copyright 2011 the original author or authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.springframework.social.test.client;
-
-import java.io.IOException;
-import java.net.URI;
-import java.util.Iterator;
-import java.util.LinkedList;
-import java.util.List;
-
-import org.springframework.http.HttpMethod;
-import org.springframework.http.client.ClientHttpRequestFactory;
-import org.springframework.util.Assert;
-
-/**
- * Mock implementation of {@link ClientHttpRequestFactory}. Contains a list of expected {@link MockClientHttpRequest}s,
- * and iterates over those.
- *
- * @author Arjen Poutsma
- * @author Lukas Krecan
- * @author Craig Walls
- */
-public class MockClientHttpRequestFactory implements ClientHttpRequestFactory {
-
- private final List<MockClientHttpRequest> expectedRequests = new LinkedList<MockClientHttpRequest>();
-
- private Iterator<MockClientHttpRequest> requestIterator;
-
- public MockClientHttpRequest createRequest(URI uri, HttpMethod httpMethod) throws IOException {
- Assert.notNull(uri, "'uri' must not be null");
- Assert.notNull(httpMethod, "'httpMethod' must not be null");
-
- if (requestIterator == null) {
- requestIterator = expectedRequests.iterator();
- }
- if (!requestIterator.hasNext()) {
- throw new AssertionError("No further requests expected");
- }
-
- MockClientHttpRequest currentRequest = requestIterator.next();
- currentRequest.setUri(uri);
- currentRequest.setHttpMethod(httpMethod);
- return currentRequest;
- }
-
- MockClientHttpRequest expectNewRequest() {
- Assert.state(requestIterator == null, "Can not expect another request, the test is already underway");
- MockClientHttpRequest request = new MockClientHttpRequest();
- expectedRequests.add(request);
- return request;
- }
-
- void verifyRequests() {
- if (expectedRequests.isEmpty()) {
- return;
- }
- if (requestIterator == null || requestIterator.hasNext()) {
- throw new AssertionError("Further request(s) expected");
- }
- }
-}
View
82 ...ial-test/src/main/java/org/springframework/social/test/client/MockClientHttpResponse.java
@@ -1,82 +0,0 @@
-/*
- * Copyright 2011 the original author or authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.springframework.social.test.client;
-
-import java.io.ByteArrayInputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.UnsupportedEncodingException;
-
-import org.springframework.http.HttpHeaders;
-import org.springframework.http.HttpStatus;
-import org.springframework.http.client.ClientHttpResponse;
-import org.springframework.util.FileCopyUtils;
-
-/**
- * Mock implementation of {@link ClientHttpResponse}.
- *
- * @author Arjen Poutsma
- * @author Lukas Krecan
- * @author Craig Walls
- */
-public class MockClientHttpResponse implements ClientHttpResponse {
- private InputStream bodyStream;
- private byte[] body;
- private final HttpHeaders headers;
- private final HttpStatus statusCode;
- private final String statusText;
-
- public MockClientHttpResponse(String body, HttpHeaders headers, HttpStatus statusCode, String statusText) {
- this(stringToInputStream(body), headers, statusCode, statusText);
- }
-
- public MockClientHttpResponse(InputStream bodyStream, HttpHeaders headers, HttpStatus statusCode, String statusText) {
- this.bodyStream = bodyStream;
- this.headers = headers;
- this.statusCode = statusCode;
- this.statusText = statusText;
- }
-
- public InputStream getBody() throws IOException {
- if (body == null) {
- body = FileCopyUtils.copyToByteArray(bodyStream);
- }
- return new ByteArrayInputStream(body);
- }
-
- public HttpHeaders getHeaders() {
- return headers;
- }
-
- public HttpStatus getStatusCode() throws IOException {
- return statusCode;
- }
-
- public String getStatusText() throws IOException {
- return statusText;
- }
-
- public void close() {
- }
-
- private static InputStream stringToInputStream(String in) {
- try {
- return new ByteArrayInputStream(in.getBytes("UTF-8"));
- } catch (UnsupportedEncodingException shouldntHappen) {
- return null;
- }
- }
-}
View
58 spring-social-test/src/main/java/org/springframework/social/test/client/MockHttpRequest.java
@@ -1,58 +0,0 @@
-/*
- * Copyright 2011 the original author or authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.springframework.social.test.client;
-
-import java.net.URI;
-import java.net.URISyntaxException;
-
-import org.springframework.http.HttpHeaders;
-import org.springframework.http.HttpMethod;
-import org.springframework.http.HttpRequest;
-
-public class MockHttpRequest implements HttpRequest {
-
- private final HttpHeaders headers = new HttpHeaders();
-
- private HttpMethod method;
-
- private URI uri;
-
- public MockHttpRequest(String uri) {
- this(HttpMethod.GET, uri);
- }
-
- public MockHttpRequest(HttpMethod method, String uri) {
- try {
- this.uri = new URI(uri);
- } catch (URISyntaxException e) {
- throw new IllegalArgumentException("Invalid uri: '"+ uri + "'", e);
- }
- this.method = method;
- }
-
- public HttpHeaders getHeaders() {
- return headers;
- }
-
- public HttpMethod getMethod() {
- return method;
- }
-
- public URI getURI() {
- return uri;
- }
-
-}
View
103 ...cial-test/src/main/java/org/springframework/social/test/client/MockRestServiceServer.java
@@ -1,103 +0,0 @@
-/*
- * Copyright 2011 the original author or authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.springframework.social.test.client;
-
-import org.springframework.util.Assert;
-import org.springframework.web.client.RestTemplate;
-import org.springframework.web.client.support.RestGatewaySupport;
-
-/**
- * <strong>Main entry point for client-side REST testing</strong>. Typically used to test a {@link RestTemplate}, set up
- * expectations on request messages, and create response messages.
- * <p/>
- * The typical usage of this class is:
- * <ol>
- * <li>Create a {@code MockRestServiceServer} instance by calling {@link #createServer(RestTemplate)}.
- * <li>Set up request expectations by calling {@link #expect(RequestMatcher)}, possibly by using the default
- * {@link RequestMatcher} implementations provided in {@link RequestMatchers} (which can be statically imported).
- * Multiple expectations can be set up by chaining {@link ResponseActions#andExpect(RequestMatcher)} calls.</li>
- * <li>Create an appropriate response message by calling {@link ResponseActions#andRespond(ResponseCreator)
- * andRespond(ResponseCreator)}, possibly by using the default {@link ResponseCreator} implementations provided in
- * {@link ResponseCreators} (which can be statically imported).</li>
- * <li>Use the {@code RestTemplate} as normal, either directly of through client code.</li>
- * <li>Call {@link #verify()}.
- * </ol>
- * Note that because of the 'fluent' API offered by this class (and related classes), you can typically use the Code
- * Completion features (i.e. ctrl-space) in your IDE to set up the mocks.
- *
- * @author Arjen Poutsma
- * @author Lukas Krecan
- * @author Craig Walls
- */
-public class MockRestServiceServer {
- private final MockClientHttpRequestFactory mockRequestFactory;
-
- private MockRestServiceServer(MockClientHttpRequestFactory mockRequestFactory) {
- Assert.notNull(mockRequestFactory, "'mockRequestFactory' must not be null");
- this.mockRequestFactory = mockRequestFactory;
- }
-
- /**
- * Creates a {@code MockRestServiceServer} instance based on the given {@link RestTemplate}.
- *
- * @param restTemplate
- * the RestTemplate
- * @return the created server
- */
- public static MockRestServiceServer createServer(RestTemplate restTemplate) {
- Assert.notNull(restTemplate, "'restTemplate' must not be null");
-
- MockClientHttpRequestFactory mockRequestFactory = new MockClientHttpRequestFactory();
- restTemplate.setRequestFactory(mockRequestFactory);
-
- return new MockRestServiceServer(mockRequestFactory);
- }
-
- /**
- * Creates a {@code MockRestServiceServer} instance based on the given {@link RestGatewaySupport}.
- *
- * @param gatewaySupport the client class
- * @return the created server
- */
- public static MockRestServiceServer createServer(RestGatewaySupport gatewaySupport) {
- Assert.notNull(gatewaySupport, "'gatewaySupport' must not be null");
- return createServer(gatewaySupport.getRestTemplate());
- }
-
- /**
- * Records an expectation specified by the given {@link RequestMatcher}. Returns a {@link ResponseActions} object
- * that allows for creating the response, or to set up more expectations.
- *
- * @param requestMatcher
- * the request matcher expected
- * @return the response actions
- */
- public ResponseActions expect(RequestMatcher requestMatcher) {
- MockClientHttpRequest request = mockRequestFactory.expectNewRequest();
- request.addRequestMatcher(requestMatcher);
- return request;
- }
-
- /**
- * Verifies that all expectations were met.
- *
- * @throws AssertionError
- * in case of unmet expectations
- */
- public void verify() {
- mockRequestFactory.verifyRequests();
- }
-}
View
40 spring-social-test/src/main/java/org/springframework/social/test/client/RequestMatcher.java
@@ -1,40 +0,0 @@
-/*
- * Copyright 2011 the original author or authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.springframework.social.test.client;
-
-import java.io.IOException;
-
-import org.springframework.http.client.ClientHttpRequest;
-
-/**
- * Defines the contract for matching requests to expectations.
- *
- * @author Arjen Poutsma
- * @author Lukas Krecan
- * @author Craig Walls
- */
-public interface RequestMatcher {
-
- /**
- * Matches the given request message against the expectations.
- *
- * @param request the request to make assertions on
- * @throws IOException in case of I/O errors
- * @throws AssertionError if expectations are not met
- */
- void match(ClientHttpRequest request) throws IOException, AssertionError;
-
-}
View
150 spring-social-test/src/main/java/org/springframework/social/test/client/RequestMatchers.java
@@ -1,150 +0,0 @@
-/*
- * Copyright 2011 the original author or authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.springframework.social.test.client;
-
-import java.io.IOException;
-import java.net.URI;
-import java.util.List;
-
-import org.springframework.http.HttpMethod;
-import org.springframework.http.client.ClientHttpRequest;
-import org.springframework.util.Assert;
-
-/**
- * Factory methods for {@link RequestMatcher} classes. Typically used to provide input for
- * {@link MockRestServiceServer#expect(RequestMatcher)}.
- *
- * @author Arjen Poutsma
- * @author Craig Walls
- */
-public abstract class RequestMatchers {
- private RequestMatchers() {
- }
-
- /**
- * Expects any request.
- *
- * @return the request matcher
- */
- public static RequestMatcher anything() {
- return new RequestMatcher() {
- public void match(ClientHttpRequest request) throws AssertionError {
- }
- };
- }
-
- /**
- * Expects the given {@link HttpMethod}.
- *
- * @param method the HTTP method
- * @return the request matcher
- */
- public static RequestMatcher method(final HttpMethod method) {
- Assert.notNull(method, "'method' must not be null");
- return new RequestMatcher() {
- public void match(ClientHttpRequest request) throws AssertionError {
- AssertionErrors.assertEquals("Unexpected HttpMethod", method, request.getMethod());
- }
- };
- }
-
- /**
- * Expects a request to the given URI.
- *
- * @param uri the request URI
- * @return the request matcher
- */
- public static RequestMatcher requestTo(String uri) {
- Assert.notNull(uri, "'uri' must not be null");
- return requestTo(URI.create(uri));
- }
-
- /**
- * Expects a request to the given URI.
- *
- * @param uri the request URI
- * @return the request matcher
- */
- public static RequestMatcher requestTo(URI uri) {
- Assert.notNull(uri, "'uri' must not be null");
- return new UriMatcher(uri);
- }
-
- /**
- * Expects the given request header
- *
- * @param header the header name
- * @param value the header value
- * @return the request matcher
- */
- public static RequestMatcher header(final String header, final String value) {
- Assert.notNull(header, "'header' must not be null");
- Assert.notNull(value, "'value' must not be null");
- return new RequestMatcher() {
- public void match(ClientHttpRequest request) throws AssertionError {
- List<String> actual = request.getHeaders().get(header);
- AssertionErrors.assertTrue("Expected header in request: " + header, actual != null);
- AssertionErrors.assertTrue("Unexpected header", actual.contains(value));
- }
- };
- }
-
- /**
- * Expects that the specified request header contains a subtring
- *
- * @param header the header name
- * @param substring the substring that must appear in the header
- * @return the request matcher
- */
- public static RequestMatcher headerContains(final String header, final String substring) {
- Assert.notNull(header, "'header' must not be null");
- Assert.notNull(substring, "'substring' must not be null");
- return new RequestMatcher() {
- public void match(ClientHttpRequest request) throws AssertionError {
- List<String> actualHeaders = request.getHeaders().get(header);
- AssertionErrors.assertTrue("Expected header in request: " + header, actualHeaders != null);
-
- boolean foundMatch = false;
- for (String headerValue : actualHeaders) {
- if (headerValue.contains(substring)) {
- foundMatch = true;
- break;
- }
- }
-
- AssertionErrors.assertTrue("Header \"" + header + "\" didn't contain expected text <" + substring + ">",
- foundMatch);
- }
- };
- }
-
- /**
- * Expects the given request body content
- *
- * @param body the request body
- * @return the request matcher
- */
- public static RequestMatcher body(final String body) {
- Assert.notNull(body, "'body' must not be null");
- return new RequestMatcher() {
- public void match(ClientHttpRequest request) throws AssertionError, IOException {
- MockClientHttpRequest mockRequest = (MockClientHttpRequest) request;
- AssertionErrors.assertEquals("Unexpected body content", body,
- mockRequest.getBodyContent());
- }
- };
- }
-}
View
39 spring-social-test/src/main/java/org/springframework/social/test/client/ResponseActions.java
@@ -1,39 +0,0 @@
-/*
- * Copyright 2011 the original author or authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.springframework.social.test.client;
-
-/**
- * Allows for setting up responses and additional expectations. Implementations of this interface are returned by
- * {@link MockRestServiceServer#expect(RequestMatcher)}.
- *
- * @author Arjen Poutsma
- * @author Lukas Krecan
- * @author Craig Walls
- */
-public interface ResponseActions {
-
- /**
- * Allows for further expectations to be set on the request.
- * @return the request expectations
- */
- ResponseActions andExpect(RequestMatcher requestMatcher);
-
- /**
- * Sets the {@link ResponseCreator} for this mock.
- * @param responseCreator the response creator
- */
- void andRespond(ResponseCreator responseCreator);
-}
View
36 spring-social-test/src/main/java/org/springframework/social/test/client/ResponseCreator.java
@@ -1,36 +0,0 @@
-/*
- * Copyright 2011 the original author or authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.springframework.social.test.client;
-
-import org.springframework.http.client.ClientHttpRequest;
-import org.springframework.http.client.ClientHttpResponse;
-
-/**
- * Allows for creating up responses. Implementations of this interface are returned by {@link ResponseCreators}.
- *
- * @author Arjen Poutsma
- * @author Lukas Krecan
- * @author Craig Walls
- */
-public interface ResponseCreator {
-
- /**
- * Create a response for the given request
- *
- * @param request the request
- */
- ClientHttpResponse createResponse(ClientHttpRequest request);
-}
View
103 ...ng-social-test/src/main/java/org/springframework/social/test/client/ResponseCreators.java
@@ -1,103 +0,0 @@
-/*
- * Copyright 2011 the original author or authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.springframework.social.test.client;
-
-import java.io.BufferedReader;
-import java.io.IOException;
-import java.io.InputStreamReader;
-
-import org.springframework.core.io.Resource;
-import org.springframework.http.HttpHeaders;
-import org.springframework.http.HttpStatus;
-import org.springframework.http.client.ClientHttpRequest;
-import org.springframework.util.Assert;
-
-/**
- * Factory methods for {@link ResponseCreator} classes. Typically used to provide input for {@link
- * ResponseActions#andRespond(ResponseCreator)}.
- *
- * @author Arjen Poutsma
- * @author Craig Walls
- */
-public abstract class ResponseCreators {
- private ResponseCreators() {
- }
-
- /**
- * Respond with a given response body, headers, status code, and status text.
- *
- * @param responseBody the body of the response
- * @param headers the response headers
- * @param statusCode the response status code
- * @param statusText the response status text
- * @return a {@link ResponseCreator}
- */
- public static ResponseCreator withResponse(final String responseBody, final HttpHeaders headers,
- final HttpStatus statusCode, final String statusText) {
- Assert.notNull(responseBody, "'responseBody' must not be null");
- return new ResponseCreator() {
- public MockClientHttpResponse createResponse(ClientHttpRequest request) {
- return new MockClientHttpResponse(responseBody, headers, statusCode, statusText);
- }
- };
- }
-
- /**
- * Response with a given response body and headers. The response status code is HTTP 200 (OK).
- * @param responseBody the body of the response
- * @param headers the response headers
- * @return a {@link ResponseCreator}
- */
- public static ResponseCreator withResponse(String responseBody, HttpHeaders headers) {
- return withResponse(responseBody, headers, HttpStatus.OK, "");
- }
-
- /**
- * Respond with a given response body (from a {@link Resource}) and headers. The response status code is HTTP 200 (OK).
- *
- * @param responseBodyResource a {@link Resource} containing the body of the response
- * @param headers the response headers
- * @param statusCode the response status code
- * @param statusText the response status text
- * @return a {@link ResponseCreator}
- */
- public static ResponseCreator withResponse(final Resource responseBodyResource, final HttpHeaders headers,
- final HttpStatus statusCode, final String statusText) {
- return withResponse(readResource(responseBodyResource), headers, statusCode, statusText);
- }
-
- /**
- * Response with a given response body and headers. The response status code is HTTP 200 (OK).
- * @param responseBody the body of the response
- * @param headers the response headers
- * @return a {@link ResponseCreator}
- */
- public static ResponseCreator withResponse(Resource responseBody, HttpHeaders headers) {
- return withResponse(responseBody, headers, HttpStatus.OK, "");
- }
-
- private static String readResource(Resource resource) {
- StringBuilder resourceText = new StringBuilder();
- try {
- BufferedReader reader = new BufferedReader(new InputStreamReader(resource.getInputStream()));
- while (reader.ready()) {
- resourceText.append(reader.readLine() + "\n");
- }
- } catch (IOException e) {
- }
- return resourceText.toString();
- }
-}
View
39 spring-social-test/src/main/java/org/springframework/social/test/client/UriMatcher.java
@@ -1,39 +0,0 @@
-/*
- * Copyright 2011 the original author or authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.springframework.social.test.client;
-
-import java.net.URI;
-
-import org.springframework.http.client.ClientHttpRequest;
-
-/**
- * Matches {@link URI}s.
- *
- * @author Arjen Poutsma
- * @author Craig Walls
- */
-class UriMatcher implements RequestMatcher {
-
- private final URI expected;
-
- UriMatcher(URI expected) {
- this.expected = expected;
- }
-
- public void match(ClientHttpRequest request) {
- AssertionErrors.assertEquals("Unexpected request", expected, request.getURI());
- }
-}
View
5 spring-social-test/src/main/java/org/springframework/social/test/client/package-info.java
@@ -1,5 +0,0 @@
-/**
- * Test framework for ServiceProvider APIs.
- */
-package org.springframework.social.test.client;
-
View
47 ...al-test/src/test/java/org/springframework/social/connect/oauth1/StubOAuth1Operations.java
@@ -1,47 +0,0 @@
-/*
- * Copyright 2011 the original author or authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.springframework.social.connect.oauth1;
-
-import org.springframework.social.oauth1.AuthorizedRequestToken;
-import org.springframework.social.oauth1.OAuth1Operations;
-import org.springframework.social.oauth1.OAuth1Parameters;
-import org.springframework.social.oauth1.OAuth1Version;
-import org.springframework.social.oauth1.OAuthToken;
-import org.springframework.util.MultiValueMap;
-
-class StubOAuth1Operations implements OAuth1Operations {
-
- public OAuth1Version getVersion() {
- return OAuth1Version.CORE_10_REVISION_A;
- }
-
- public OAuthToken fetchRequestToken(String callbackUrl, MultiValueMap<String, String> additionalParameters) {
- return new OAuthToken("12345", "23456");
- }
-
- public String buildAuthorizeUrl(String requestToken, OAuth1Parameters parameters) {
- return "http://springsource.org/oauth/authorize?request_token=" + requestToken;
- }
-
- public String buildAuthenticateUrl(String requestToken, OAuth1Parameters parameters) {
- return "http://springsource.org/oauth/authenticate?request_token=" + requestToken;
- }
-
- public OAuthToken exchangeForAccessToken(AuthorizedRequestToken requestToken, MultiValueMap<String, String> additionalParameters) {
- return new OAuthToken("34567", "45678");
- }
-
-}
View
1  ...cial-test/src/test/java/org/springframework/social/connect/oauth1/accessToken.formencoded
@@ -1 +0,0 @@
-oauth_token=9876543210&oauth_token_secret=ponmlkjihgfedcba
View
1  ...ial-test/src/test/java/org/springframework/social/connect/oauth1/requestToken.formencoded
@@ -1 +0,0 @@
-oauth_token=1234567890&oauth_token_secret=abcdefghijklmnop
View
41 ...al-test/src/test/java/org/springframework/social/connect/oauth2/StubOAuth2Operations.java
@@ -1,41 +0,0 @@
-/*
- * Copyright 2011 the original author or authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.springframework.social.connect.oauth2;
-
-import org.springframework.social.oauth2.AccessGrant;
-import org.springframework.social.oauth2.OAuth2Parameters;
-import org.springframework.social.oauth2.GrantType;
-import org.springframework.social.oauth2.OAuth2Operations;
-import org.springframework.util.MultiValueMap;
-
-class StubOAuth2Operations implements OAuth2Operations {
-
- public String buildAuthorizeUrl(GrantType grantType, OAuth2Parameters parameters) {
- return "http://springsource.org/oauth/authorize?scope=" + parameters.getScope();
- }
-
- public String buildAuthenticateUrl(GrantType grantType, OAuth2Parameters parameters) {
- return buildAuthorizeUrl(grantType, parameters);
- }
-
- public AccessGrant exchangeForAccess(String authorizationGrant, String redirectUri, MultiValueMap<String, String> additionalParameters) {
- return new AccessGrant("12345", null, "23456", 3600);
- }
-
- public AccessGrant refreshAccess(String refreshToken, String scope, MultiValueMap<String, String> additionalParameters) {
- return new AccessGrant("12345", null, "23456", 3600);
- }
-}
View
1  ...-social-test/src/test/java/org/springframework/social/connect/oauth2/accessToken.facebook
@@ -1 +0,0 @@
-access_token=162868103756545|bf4de6ed613f7901204c222g-738140579|YAufyoV9n7LmEAgzRKqnc300B0B
View
8 spring-social-test/src/test/java/org/springframework/social/connect/oauth2/accessToken.json
@@ -1,8 +0,0 @@
-{
- "expires_at":"Wed, 09 Feb 2011 16:38:34 -0000",
- "scope":"read",
- "username":"cwagon",
- "expires_in":40735,
- "access_token":"8d0a88a5c4f1ae4937ad864cafa8e857",
- "refresh_token":"6b0411401bf8751e34f57feb29fb8e32"
-}
View
70 ...al-test/src/test/java/org/springframework/social/oauth1/OAuth1RequestInterceptorTest.java
@@ -1,70 +0,0 @@
-/*
- * Copyright 2011 the original author or authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.springframework.social.oauth1;
-
-import static org.junit.Assert.*;
-
-import java.io.IOException;
-import java.util.HashMap;
-import java.util.Map;
-
-import org.junit.Test;
-import org.springframework.http.HttpMethod;
-import org.springframework.http.HttpRequest;
-import org.springframework.http.MediaType;
-import org.springframework.http.client.ClientHttpRequestExecution;
-import org.springframework.http.client.ClientHttpResponse;
-import org.springframework.social.test.client.MockHttpRequest;
-
-public class OAuth1RequestInterceptorTest {
-
- @Test
- public void beforeExecution() throws Exception {
- OAuth1RequestInterceptor interceptor = new OAuth1RequestInterceptor(new OAuth1Credentials("consumer_key", "consumer_secret", "access_token", "token_secret"));
- byte[] body = "status=Hello+there".getBytes();
- MockHttpRequest request = new MockHttpRequest(HttpMethod.POST, "https://api.someprovider.com/status/update");
- request.getHeaders().setContentType(MediaType.APPLICATION_FORM_URLENCODED);
-
- ClientHttpRequestExecution execution = new ClientHttpRequestExecution() {
- public ClientHttpResponse execute(HttpRequest request, byte[] body) throws IOException {
- String authorizationHeader = request.getHeaders().getFirst("Authorization");
- Map<String, String> headerParameters = extractHeaderParameters(authorizationHeader);
- // TODO: Figure out how to test this more precisely with a fixed nonce and timestamp (and thus a fixed signature)
- assertEquals("1.0", headerParameters.get("oauth_version"));
- assertTrue(headerParameters.containsKey("oauth_nonce"));
- assertEquals("HMAC-SHA1", headerParameters.get("oauth_signature_method"));
- assertEquals("consumer_key", headerParameters.get("oauth_consumer_key"));
- assertEquals("access_token", headerParameters.get("oauth_token"));
- assertTrue(headerParameters.containsKey("oauth_timestamp"));
- assertTrue(headerParameters.containsKey("oauth_signature"));
- assertEquals(MediaType.APPLICATION_FORM_URLENCODED, request.getHeaders().getContentType());
- return null;
- }
- };
- interceptor.intercept(request, body, execution);
- }
-
- private Map<String, String> extractHeaderParameters(String authorizationHeader) {
- String[] keysAndValues = authorizationHeader.substring(6).split(",\\s");
- Map<String, String> parameters = new HashMap<String, String>();
- for (String keyAndValue : keysAndValues) {
- String[] keyValuePair = keyAndValue.split("=");
- String value = keyValuePair[1].substring(1, keyValuePair[1].length() - 1);
- parameters.put(keyValuePair[0], value);
- }
- return parameters;
- }
-}
View
202 spring-social-test/src/test/java/org/springframework/social/oauth1/OAuth1TemplateTest.java
@@ -1,202 +0,0 @@
-/*
- * Copyright 2011 the original author or authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.springframework.social.oauth1;
-
-import static org.junit.Assert.*;
-import static org.springframework.http.HttpMethod.*;
-import static org.springframework.social.test.client.RequestMatchers.*;
-import static org.springframework.social.test.client.ResponseCreators.*;
-
-import org.junit.Before;
-import org.junit.Test;
-import org.springframework.core.io.ClassPathResource;
-import org.springframework.http.HttpHeaders;
-import org.springframework.http.MediaType;
-import org.springframework.social.test.client.MockRestServiceServer;
-import org.springframework.util.MultiValueMap;
-
-public class OAuth1TemplateTest {
-
- private static final String ACCESS_TOKEN_URL = "http://www.someprovider.com/oauth/accessToken";
-
- private static final String AUTHENTICATE_URL = "https://www.someprovider.com/oauth/authenticate";
-
- private static final String AUTHORIZE_URL = "https://www.someprovider.com/oauth/authorize";
-
- private static final String REQUEST_TOKEN_URL = "https://www.someprovider.com/oauth/requestToken";
-
- private OAuth1Template oauth10a;
-
- private OAuth1Template oauth10;
-
- private OAuth1Template customOauth10;
-
- @Before
- public void setup() {
- oauth10a = new OAuth1Template("consumer_key", "consumer_secret", REQUEST_TOKEN_URL, AUTHORIZE_URL, null, ACCESS_TOKEN_URL, OAuth1Version.CORE_10_REVISION_A);
- oauth10 = new OAuth1Template("consumer_key", "consumer_secret", REQUEST_TOKEN_URL, AUTHORIZE_URL, AUTHENTICATE_URL, ACCESS_TOKEN_URL, OAuth1Version.CORE_10);
-
- customOauth10 = new OAuth1Template("consumer_key", "consumer_secret", REQUEST_TOKEN_URL,
- AUTHORIZE_URL, null, ACCESS_TOKEN_URL, OAuth1Version.CORE_10) {
- protected void addCustomAuthorizationParameters(MultiValueMap<String,String> parameters) {
- parameters.set("custom_parameter", "custom_parameter_value");
- };
- };
-}
-
- @Test
- public void buildAuthorizeUrl() {
- OAuth1Parameters parameters = new OAuth1Parameters(null);
- parameters.setCallbackUrl("http://www.someclient.com/oauth/callback");
- assertEquals(AUTHORIZE_URL + "?oauth_token=request_token",
- oauth10a.buildAuthorizeUrl("request_token", OAuth1Parameters.NONE));
- assertEquals(AUTHORIZE_URL + "?oauth_token=request_token&oauth_callback=http%3A%2F%2Fwww.someclient.com%2Foauth%2Fcallback",
- oauth10.buildAuthorizeUrl("request_token", parameters));
- }
-
- @Test
- public void buildAuthorizeUrl_customAuthorizeParameters() {
- OAuth1Parameters parameters = new OAuth1Parameters(null);
- parameters.setCallbackUrl("http://www.someclient.com/oauth/callback");
- assertEquals(AUTHORIZE_URL + "?oauth_token=request_token&oauth_callback=http%3A%2F%2Fwww.someclient.com%2Foauth%2Fcallback&custom_parameter=custom_parameter_value",
- 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\""))
- .andExpect(headerContains("Authorization", "oauth_consumer_key=\"consumer_key\""))
- .andExpect(headerContains("Authorization", "oauth_nonce=\""))
- .andExpect(headerContains("Authorization", "oauth_signature=\""))
- .andExpect(headerContains("Authorization", "oauth_timestamp=\""))
- .andRespond(
- withResponse(new ClassPathResource("requestToken.formencoded", getClass()), responseHeaders));
-
- OAuthToken requestToken = oauth10a.fetchRequestToken("http://www.someclient.com/oauth/callback", null);
- assertEquals("1234567890", requestToken.getValue());
- 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=\""))
- .andExpect(headerContains("Authorization", "oauth_signature=\""))
- .andExpect(headerContains("Authorization", "oauth_timestamp=\""))
- .andRespond(withResponse(new ClassPathResource("requestToken.formencoded", getClass()), responseHeaders));
-
- OAuthToken requestToken = oauth10.fetchRequestToken("http://www.someclient.com/oauth/callback", null);
- assertEquals("1234567890", requestToken.getValue());
- 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\""))
- .andExpect(headerContains("Authorization", "oauth_token=\"1234567890\""))
- .andExpect(headerContains("Authorization", "oauth_verifier=\"verifier\""))
- .andExpect(headerContains("Authorization", "oauth_nonce=\""))
- .andExpect(headerContains("Authorization", "oauth_signature=\""))
- .andExpect(headerContains("Authorization", "oauth_timestamp=\""))
- .andRespond(withResponse(new ClassPathResource("accessToken.formencoded", getClass()), responseHeaders));
-
- OAuthToken requestToken = new OAuthToken("1234567890", "abcdefghijklmnop");
- OAuthToken accessToken = oauth10a.exchangeForAccessToken(new AuthorizedRequestToken(requestToken, "verifier"), null);
- assertEquals("9876543210", accessToken.getValue());
- 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\""))
- .andExpect(headerContains("Authorization", "oauth_token=\"1234567890\""))
- .andExpect(headerContains("Authorization", "oauth_nonce=\""))
- .andExpect(headerContains("Authorization", "oauth_signature=\""))
- .andExpect(headerContains("Authorization", "oauth_timestamp=\""))
- .andRespond(withResponse(new ClassPathResource("accessToken.formencoded", getClass()), responseHeaders));
-
- OAuthToken requestToken = new OAuthToken("1234567890", "abcdefghijklmnop");
- OAuthToken accessToken = oauth10.exchangeForAccessToken(new AuthorizedRequestToken(requestToken, "verifier"), null);
- assertEquals("9876543210", accessToken.getValue());
- assertEquals("ponmlkjihgfedcba", accessToken.getSecret());
- }
-
- // parameter assertion tests
-
- @Test(expected = IllegalArgumentException.class)
- public void construct_nullConsumerKey() {
- new OAuth1Template(null, "secret", REQUEST_TOKEN_URL, AUTHORIZE_URL, ACCESS_TOKEN_URL);
- }
-
- @Test(expected = IllegalArgumentException.class)
- public void construct_nullConsumerSecret() {
- new OAuth1Template("key", null, REQUEST_TOKEN_URL, AUTHORIZE_URL, ACCESS_TOKEN_URL);
- }
-
- @Test(expected = IllegalArgumentException.class)
- public void construct_nullRequestTokenUrl() {
- new OAuth1Template("key", "secret", null, AUTHORIZE_URL, ACCESS_TOKEN_URL);
- }
-
- @Test(expected = IllegalArgumentException.class)
- public void construct_nullAuthorizeUrl() {
- new OAuth1Template("key", "secret", REQUEST_TOKEN_URL, null, ACCESS_TOKEN_URL);
- }
-
- @Test(expected = IllegalArgumentException.class)
- public void construct_nullAcessTokenUrl() {
- new OAuth1Template("key", "secret", REQUEST_TOKEN_URL, AUTHORIZE_URL, null);
- }
-
- @Test(expected = IllegalArgumentException.class)
- public void setRequestFactory_null() {
- oauth10a.setRequestFactory(null);
- }
-
-}
View
1  spring-social-test/src/test/java/org/springframework/social/oauth1/accessToken.formencoded
@@ -1 +0,0 @@
-oauth_token=9876543210&oauth_token_secret=ponmlkjihgfedcba
View
1  spring-social-test/src/test/java/org/springframework/social/oauth1/requestToken.formencoded
@@ -1 +0,0 @@
-oauth_token=1234567890&oauth_token_secret=abcdefghijklmnop
View
64 ...al-test/src/test/java/org/springframework/social/oauth2/OAuth2RequestInterceptorTest.java
@@ -1,64 +0,0 @@
-/*
- * Copyright 2011 the original author or authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.springframework.social.oauth2;
-
-import static org.junit.Assert.*;
-
-import java.io.IOException;
-
-import org.junit.Test;
-import org.springframework.http.HttpMethod;
-import org.springframework.http.HttpRequest;
-import org.springframework.http.MediaType;
-import org.springframework.http.client.ClientHttpRequestExecution;
-import org.springframework.http.client.ClientHttpResponse;
-import org.springframework.social.test.client.MockHttpRequest;
-
-public class OAuth2RequestInterceptorTest {
-
- @Test
- public void currentOAuth2SpecInterceptor() throws Exception {
- OAuth2RequestInterceptor interceptor = new OAuth2RequestInterceptor("access_token", OAuth2Version.BEARER);
- assertThatInterceptorWritesAuthorizationHeader(interceptor, "Bearer access_token");
- }
-
- @Test
- public void draft10Interceptor() throws Exception {
- OAuth2RequestInterceptor interceptor = new OAuth2RequestInterceptor("access_token", OAuth2Version.DRAFT_10);
- assertThatInterceptorWritesAuthorizationHeader(interceptor, "OAuth access_token");
- }
-
- @Test
- public void draft8Interceptor() throws Exception {
- OAuth2RequestInterceptor interceptor = new OAuth2RequestInterceptor("access_token", OAuth2Version.DRAFT_8);
- assertThatInterceptorWritesAuthorizationHeader(interceptor, "Token token=\"access_token\"");
- }
-
- private void assertThatInterceptorWritesAuthorizationHeader(OAuth2RequestInterceptor interceptor, final String expected) throws Exception {
- byte[] body = "status=Hello+there".getBytes();
- MockHttpRequest request = new MockHttpRequest(HttpMethod.POST, "https://api.someprovider.com/status/update");
- request.getHeaders().setContentType(MediaType.APPLICATION_FORM_URLENCODED);
- ClientHttpRequestExecution execution = new ClientHttpRequestExecution() {
- public ClientHttpResponse execute(HttpRequest request, byte[] body) throws IOException {
- String authorizationHeader = request.getHeaders().getFirst("Authorization");
- assertEquals(expected, authorizationHeader);
- assertEquals(MediaType.APPLICATION_FORM_URLENCODED, request.getHeaders().getContentType());
- return null;
- }
- };
- interceptor.intercept(request, body, execution);
- }
-}
View
229 spring-social-test/src/test/java/org/springframework/social/oauth2/OAuth2TemplateTest.java
@@ -1,229 +0,0 @@
-/*
- * Copyright 2011 the original author or authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.springframework.social.oauth2;
-
-import static org.junit.Assert.*;
-import static org.springframework.http.HttpMethod.*;
-import static org.springframework.social.test.client.RequestMatchers.*;
-import static org.springframework.social.test.client.ResponseCreators.*;
-
-import org.junit.Before;
-import org.junit.Test;
-import org.springframework.core.io.ClassPathResource;
-import org.springframework.http.HttpHeaders;
-import org.springframework.http.MediaType;
-import org.springframework.social.test.client.MockRestServiceServer;
-
-public class OAuth2TemplateTest {
-
- private static final String AUTHORIZE_URL = "http://www.someprovider.com/oauth/authorize";
-
- private static final String ACCESS_TOKEN_URL = "http://www.someprovider.com/oauth/accessToken";
-
- private OAuth2Template oAuth2Template;
-
- @Before
- public void setup() {
- oAuth2Template = new OAuth2Template("client_id", "client_secret", AUTHORIZE_URL, null, ACCESS_TOKEN_URL);
- }
-
- @Test
- public void buildAuthorizeUrl_codeResponseType() {
- OAuth2Parameters parameters = new OAuth2Parameters();
- parameters.setRedirectUri("http://www.someclient.com/connect/foo");
- parameters.setScope("read,write");
- String expected = AUTHORIZE_URL + "?client_id=client_id&response_type=code&redirect_uri=http%3A%2F%2Fwww.someclient.com%2Fconnect%2Ffoo&scope=read%2Cwrite";
- String actual = oAuth2Template.buildAuthorizeUrl(GrantType.AUTHORIZATION_CODE, parameters);
- assertEquals(expected, actual);
- }
-
- @Test
- public void buildAuthorizeUrl_tokenResponseType() {
- OAuth2Parameters parameters = new OAuth2Parameters();
- parameters.setRedirectUri("http://www.someclient.com/connect/foo");
- parameters.setScope("read,write");
- String expected = AUTHORIZE_URL + "?client_id=client_id&response_type=token&redirect_uri=http%3A%2F%2Fwww.someclient.com%2Fconnect%2Ffoo&scope=read%2Cwrite";
- String actual = oAuth2Template.buildAuthorizeUrl(GrantType.IMPLICIT_GRANT, parameters);
- assertEquals(expected, actual);
- }
-
- @Test
- public void buildAuthorizeUrl_noScopeInParameters() {
- OAuth2Parameters parameters = new OAuth2Parameters();
- parameters.setRedirectUri("http://www.someclient.com/connect/foo");
- String expected = AUTHORIZE_URL + "?client_id=client_id&response_type=code&redirect_uri=http%3A%2F%2Fwww.someclient.com%2Fconnect%2Ffoo";
- String actual = oAuth2Template.buildAuthorizeUrl(GrantType.AUTHORIZATION_CODE, parameters);
- assertEquals(expected, actual);
- }
-
- @Test
- public void buildAuthorizeUrl_additionalParameters() {
- OAuth2Parameters parameters = new OAuth2Parameters();
- parameters.setRedirectUri("http://www.someclient.com/connect/foo");
- parameters.setScope("read,write");
- parameters.add("display", "touch");
- parameters.add("anotherparam", "somevalue1");
- parameters.add("anotherparam", "somevalue2");
- String expected = AUTHORIZE_URL + "?client_id=client_id&response_type=token&redirect_uri=http%3A%2F%2Fwww.someclient.com%2Fconnect%2Ffoo&scope=read%2Cwrite&display=touch&anotherparam=somevalue1&anotherparam=somevalue2";
- String actual = oAuth2Template.buildAuthorizeUrl(GrantType.IMPLICIT_GRANT, parameters);
- assertEquals(expected, actual);
- }
-
- @Test
- public void exchangeForAccess_jsonResponse() {
- // The OAuth 2 spec draft specifies JSON as the response content type. Gowalla and Github return the access token this way.
- MediaType responseContentType = MediaType.APPLICATION_JSON;
- String responseFile = "accessToken.json";
- AccessGrant accessGrant = getAccessGrant(responseContentType, responseFile);
- assertEquals("8d0a88a5c4f1ae4937ad864cafa8e857", accessGrant.getAccessToken());
- assertEquals("6b0411401bf8751e34f57feb29fb8e32", accessGrant.getRefreshToken());
- long approximateExpirationTime = System.currentTimeMillis() + 40735000;
- long actualExpirationTime = (long) accessGrant.getExpireTime();
- //allow for 1 second of wiggle room on expiration time.
- assertTrue(approximateExpirationTime - actualExpirationTime < 1000);
- assertEquals("read", accessGrant.getScope());
- }
-
- @Test
- public void exchangeForAccess_jsonResponse_noExpiresIn() {
- // The OAuth 2 spec draft specifies JSON as the response content type. Gowalla and Github return the access token this way.
- MediaType responseContentType = MediaType.APPLICATION_JSON;
- String responseFile = "accessToken_noExpiresIn.json";
- AccessGrant accessGrant = getAccessGrant(responseContentType, responseFile);
- assertEquals("8d0a88a5c4f1ae4937ad864cafa8e857", accessGrant.getAccessToken());
- assertEquals("6b0411401bf8751e34f57feb29fb8e32", accessGrant.getRefreshToken());
- assertNull(accessGrant.getExpireTime());
- assertEquals("read", accessGrant.getScope());
- }
-
- @Test
- public void exchangeForAccess_jsonResponse_noExpiresInOrScope() {
- MediaType responseContentType = MediaType.APPLICATION_JSON;
- String responseFile = "accessToken_noExpiresInOrScope.json";
- AccessGrant accessGrant = getAccessGrant(responseContentType, responseFile);
- assertEquals("8d0a88a5c4f1ae4937ad864cafa8e857", accessGrant.getAccessToken());
- assertEquals("6b0411401bf8751e34f57feb29fb8e32", accessGrant.getRefreshToken());
- assertNull(accessGrant.getExpireTime());
- assertNull(accessGrant.getScope());
- }
-
- @Test
- public void exchangeForAccess_jsonResponse_expiresInAsString() {
- MediaType responseContentType = MediaType.APPLICATION_JSON;
- String responseFile = "accessToken_expiresInAsString.json";
- AccessGrant accessGrant = getAccessGrant(responseContentType, responseFile);
- assertEquals("8d0a88a5c4f1ae4937ad864cafa8e857", accessGrant.getAccessToken());
- assertEquals("6b0411401bf8751e34f57feb29fb8e32", accessGrant.getRefreshToken());
- long approximateExpirationTime = System.currentTimeMillis() + 40735000;
- long actualExpirationTime = (long) accessGrant.getExpireTime();
- //allow for 1 second of wiggle room on expiration time.
- assertTrue(approximateExpirationTime - actualExpirationTime < 1000);
- assertEquals("read", accessGrant.getScope());
- }
-
- @Test
- public void exchangeForAccess_jsonResponse_expiresInAsNonNumericString() {
- MediaType responseContentType = MediaType.APPLICATION_JSON;
- String responseFile = "accessToken_expiresInAsNonNumericString.json";
- AccessGrant accessGrant = getAccessGrant(responseContentType, responseFile);
- assertEquals("8d0a88a5c4f1ae4937ad864cafa8e857", accessGrant.getAccessToken());
- assertEquals("6b0411401bf8751e34f57feb29fb8e32", accessGrant.getRefreshToken());
- assertNull(accessGrant.getExpireTime());
- assertEquals("read", accessGrant.getScope());
- }
-
- @Test
- public void refreshAccessToken_jsonResponse() {
- MediaType responseContentType = MediaType.APPLICATION_JSON;
- String responseFile = "refreshToken.json";
- AccessGrant accessGrant = refreshToken(responseContentType, responseFile);
- assertEquals("8d0a88a5c4f1ae4937ad864cafa8e857", accessGrant.getAccessToken());
- assertEquals("6b0411401bf8751e34f57feb29fb8e32", accessGrant.getRefreshToken());
- long approximateExpirationTime = System.currentTimeMillis() + 40735000;
- long actualExpirationTime = (long) accessGrant.getExpireTime();
- //allow for 1 second of wiggle room on expiration time.
- assertTrue(approximateExpirationTime - actualExpirationTime < 1000);
- assertNull(accessGrant.getScope());
- }
-
- @Test
- public void refreshAccessToken_jsonResponse_noExpiresIn() {
- MediaType responseContentType = MediaType.APPLICATION_JSON;
- String responseFile = "refreshToken_noExpiresIn.json";
- AccessGrant accessGrant = refreshToken(responseContentType, responseFile);
- assertEquals("8d0a88a5c4f1ae4937ad864cafa8e857", accessGrant.getAccessToken());
- assertEquals("6b0411401bf8751e34f57feb29fb8e32", accessGrant.getRefreshToken());
- assertNull(accessGrant.getExpireTime());
- assertNull(accessGrant.getScope());
- }
-
- // parameter assertion tests
-
- @Test(expected = IllegalArgumentException.class)
- public void construct_nullClientId() {
- new OAuth2Template(null, "secret", AUTHORIZE_URL, ACCESS_TOKEN_URL);
- }
-
- @Test(expected = IllegalArgumentException.class)
- public void construct_nullClientSecret() {
- new OAuth2Template("id", null, AUTHORIZE_URL, ACCESS_TOKEN_URL);
- }
-
- @Test(expected = IllegalArgumentException.class)
- public void construct_nullAuthorizeUrl() {
- new OAuth2Template("id", "secret", null, ACCESS_TOKEN_URL);
- }
-
- @Test(expected = IllegalArgumentException.class)
- public void construct_nullAccessTokenUrl() {
- new OAuth2Template("id", "secret", AUTHORIZE_URL, null);
- }
-
- @Test(expected = IllegalArgumentException.class)
- public void setRequestFactory_null() {
- oAuth2Template.setRequestFactory(null);
- }
-
-
- // private helpers
-
- private AccessGrant getAccessGrant(MediaType responseContentType, String responseFile) {
- HttpHeaders responseHeaders = new HttpHeaders();
- responseHeaders.setContentType(responseContentType);
- MockRestServiceServer mockServer = MockRestServiceServer.createServer(oAuth2Template.getRestTemplate());
- mockServer.expect(requestTo(ACCESS_TOKEN_URL))
- .andExpect(method(POST))
- .andExpect(body("client_id=client_id&client_secret=client_secret&code=code&"
- + "redirect_uri=http%3A%2F%2Fwww.someclient.com%2Fcallback&grant_type=authorization_code"))
- .andRespond(withResponse(new ClassPathResource(responseFile, getClass()), responseHeaders));
- AccessGrant accessGrant = oAuth2Template.exchangeForAccess("code", "http://www.someclient.com/callback", null);
- return accessGrant;
- }
-
- private AccessGrant refreshToken(MediaType responseContentType, String responseFile) {
- HttpHeaders responseHeaders = new HttpHeaders();
- responseHeaders.setContentType(responseContentType);
- MockRestServiceServer mockServer = MockRestServiceServer.createServer(oAuth2Template.getRestTemplate());
- mockServer.expect(requestTo(ACCESS_TOKEN_URL))
- .andExpect(method(POST))
- .andExpect(body("client_id=client_id&client_secret=client_secret&refresh_token=r3fr35h_t0k3n&"
- + "grant_type=refresh_token"))
- .andRespond(withResponse(new ClassPathResource(responseFile, getClass()), responseHeaders));
- AccessGrant accessGrant = oAuth2Template.refreshAccess("r3fr35h_t0k3n", null, null);
- return accessGrant;
- }
-
-}
View
1  spring-social-test/src/test/java/org/springframework/social/oauth2/accessToken.facebook
@@ -1 +0,0 @@
-access_token=162868103756545|bf4de6ed613f7901204c222g-738140579|YAufyoV9n7LmEAgzRKqnc300B0B
View
8 spring-social-test/src/test/java/org/springframework/social/oauth2/accessToken.json
@@ -1,8 +0,0 @@
-{
- "expires_at":"Wed, 09 Feb 2011 16:38:34 -0000",
- "scope":"read",
- "username":"cwagon",
- "expires_in":40735,
- "access_token":"8d0a88a5c4f1ae4937ad864cafa8e857",
- "refresh_token":"6b0411401bf8751e34f57feb29fb8e32"
-}
View
8 .../test/java/org/springframework/social/oauth2/accessToken_expiresInAsNonNumericString.json
@@ -1,8 +0,0 @@
-{
- "expires_at":"Wed, 09 Feb 2011 16:38:34 -0000",
- "scope":"read",
- "expires_in":"Not a number",
- "username":"cwagon",
- "access_token":"8d0a88a5c4f1ae4937ad864cafa8e857",
- "refresh_token":"6b0411401bf8751e34f57feb29fb8e32"
-}
View
8 ...l-test/src/test/java/org/springframework/social/oauth2/accessToken_expiresInAsString.json
@@ -1,8 +0,0 @@
-{
- "expires_at":"Wed, 09 Feb 2011 16:38:34 -0000",
- "scope":"read",
- "expires_in":"40735",
- "username":"cwagon",
- "access_token":"8d0a88a5c4f1ae4937ad864cafa8e857",
- "refresh_token":"6b0411401bf8751e34f57feb29fb8e32"
-}
View
7 ...-social-test/src/test/java/org/springframework/social/oauth2/accessToken_noExpiresIn.json
@@ -1,7 +0,0 @@
-{
- "expires_at":"Wed, 09 Feb 2011 16:38:34 -0000",
- "scope":"read",
- "username":"cwagon",
- "access_token":"8d0a88a5c4f1ae4937ad864cafa8e857",
- "refresh_token":"6b0411401bf8751e34f57feb29fb8e32"
-}
View
5 ...-test/src/test/java/org/springframework/social/oauth2/accessToken_noExpiresInOrScope.json
@@ -1,5 +0,0 @@
-{
- "username":"cwagon",
- "access_token":"8d0a88a5c4f1ae4937ad864cafa8e857",
- "refresh_token":"6b0411401bf8751e34f57feb29fb8e32"
-}
View
7 spring-social-test/src/test/java/org/springframework/social/oauth2/refreshToken.json
@@ -1,7 +0,0 @@
-{
- "expires_at":"Wed, 09 Feb 2011 16:38:34 -0000",
- "username":"cwagon",
- "expires_in":40735,
- "access_token":"8d0a88a5c4f1ae4937ad864cafa8e857",
- "refresh_token":"6b0411401bf8751e34f57feb29fb8e32"
-}
View
6 ...social-test/src/test/java/org/springframework/social/oauth2/refreshToken_noExpiresIn.json
@@ -1,6 +0,0 @@
-{
- "expires_at":"Wed, 09 Feb 2011 16:38:34 -0000",
- "username":"cwagon",
- "access_token":"8d0a88a5c4f1ae4937ad864cafa8e857",
- "refresh_token":"6b0411401bf8751e34f57feb29fb8e32"
-}

0 comments on commit 2933df7

Please sign in to comment.
Something went wrong with that request. Please try again.