use of com.google.api.client.testing.http.MockHttpTransport in project google-api-java-client by google.
the class BatchRequestTest method testExecute_checkWriteTo.
public void testExecute_checkWriteTo() throws Exception {
String request1Method = HttpMethods.POST;
String request1Url = "http://test/dummy/url1";
String request1ContentType = "application/json";
String request1Content = "{\"data\":{\"foo\":{\"v1\":{}}}}";
String request2Method = HttpMethods.GET;
String request2Url = "http://test/dummy/url2";
final StringBuilder expectedOutput = new StringBuilder();
expectedOutput.append("--__END_OF_PART__\r\n");
expectedOutput.append("Content-Length: 118\r\n");
expectedOutput.append("Content-Type: application/http\r\n");
expectedOutput.append("content-id: 1\r\n");
expectedOutput.append("content-transfer-encoding: binary\r\n");
expectedOutput.append("\r\n");
expectedOutput.append("POST http://test/dummy/url1 HTTP/1.1\r\n");
expectedOutput.append("Content-Length: 26\r\n");
expectedOutput.append("Content-Type: " + request1ContentType + "\r\n");
expectedOutput.append("\r\n");
expectedOutput.append(request1Content + "\r\n");
expectedOutput.append("--__END_OF_PART__\r\n");
expectedOutput.append("Content-Length: 39\r\n");
expectedOutput.append("Content-Type: application/http\r\n");
expectedOutput.append("content-id: 2\r\n");
expectedOutput.append("content-transfer-encoding: binary\r\n");
expectedOutput.append("\r\n");
expectedOutput.append("GET http://test/dummy/url2 HTTP/1.1\r\n");
expectedOutput.append("\r\n");
expectedOutput.append("\r\n");
expectedOutput.append("--__END_OF_PART__--\r\n");
MockHttpTransport transport = new MockHttpTransport();
HttpRequest request1 = transport.createRequestFactory().buildRequest(request1Method, new GenericUrl(request1Url), new ByteArrayContent(request1ContentType, request1Content.getBytes(UTF_8)));
HttpRequest request2 = transport.createRequestFactory().buildRequest(request2Method, new GenericUrl(request2Url), null);
subtestExecute_checkWriteTo(expectedOutput.toString(), request1, request2);
}
use of com.google.api.client.testing.http.MockHttpTransport in project google-api-java-client by google.
the class BatchRequestTest method testExecute_checkWriteToNoHeaders.
public void testExecute_checkWriteToNoHeaders() throws Exception {
MockHttpTransport transport = new MockHttpTransport();
HttpRequest request1 = transport.createRequestFactory().buildPostRequest(HttpTesting.SIMPLE_GENERIC_URL, new HttpContent() {
@Override
public long getLength() {
return -1;
}
@Override
public String getType() {
return null;
}
@Override
public void writeTo(OutputStream out) {
}
@Override
public boolean retrySupported() {
return true;
}
});
subtestExecute_checkWriteTo(new StringBuilder().append("--__END_OF_PART__\r\n").append("Content-Length: 36\r\n").append("Content-Type: application/http\r\n").append("content-id: 1\r\n").append("content-transfer-encoding: binary\r\n").append("\r\n").append("POST http://google.com/ HTTP/1.1\r\n").append("\r\n").append("\r\n").append("--__END_OF_PART__--\r\n").toString(), request1);
}
use of com.google.api.client.testing.http.MockHttpTransport in project google-api-java-client by google.
the class GoogleAuthorizationCodeTokenRequestTest method test.
public void test() {
GoogleAuthorizationCodeTokenRequest request = new GoogleAuthorizationCodeTokenRequest(new MockHttpTransport(), new JacksonFactory(), CLIENT_ID, CLIENT_SECRET, CODE, REDIRECT_URI);
ClientParametersAuthentication clientAuthentication = (ClientParametersAuthentication) request.getClientAuthentication();
assertEquals(CLIENT_ID, clientAuthentication.getClientId());
assertEquals(CLIENT_SECRET, clientAuthentication.getClientSecret());
assertEquals(CODE, request.getCode());
assertEquals(REDIRECT_URI, request.getRedirectUri());
assertEquals("authorization_code", request.getGrantType());
assertNull(request.getScopes());
assertNotNull(request.getTokenServerUrl());
}
use of com.google.api.client.testing.http.MockHttpTransport in project google-api-java-client by google.
the class GooglePublicKeysManagerTest method testBuilder.
public void testBuilder() throws Exception {
HttpTransport transport = new MockHttpTransport();
JsonFactory jsonFactory = new JacksonFactory();
GooglePublicKeysManager.Builder builder = new GooglePublicKeysManager.Builder(transport, jsonFactory);
GooglePublicKeysManager certs = builder.build();
assertEquals(transport, certs.getTransport());
assertEquals(jsonFactory, certs.getJsonFactory());
}
use of com.google.api.client.testing.http.MockHttpTransport in project google-api-java-client by google.
the class GooglePublicKeysManagerTest method testGetCacheTimeInSec.
public void testGetCacheTimeInSec() throws Exception {
GooglePublicKeysManager certs = new GooglePublicKeysManager.Builder(new MockHttpTransport(), new JacksonFactory()).build();
assertEquals(12000, certs.getCacheTimeInSec(new HttpHeaders().setAge(345L).setCacheControl("max-age=" + MAX_AGE)));
assertEquals(0, certs.getCacheTimeInSec(new HttpHeaders()));
assertEquals(0, certs.getCacheTimeInSec(new HttpHeaders().setAge(345L)));
assertEquals(0, certs.getCacheTimeInSec(new HttpHeaders().setAge(345L).setCacheControl("max-age=300")));
}
Aggregations