use of okhttp3.HttpUrl in project scribejava by scribejava.
the class AbstractClientTest method shouldCallCallback.
@Test
public void shouldCallCallback() throws Exception {
final String expectedResponseBody = "response body for test shouldCallCallback";
final MockWebServer server = new MockWebServer();
server.enqueue(new MockResponse().setBody(expectedResponseBody));
server.start();
final HttpUrl baseUrl = server.url("/testUrl");
final OAuthRequest request = new OAuthRequest(Verb.GET, baseUrl.toString());
final TestCallback callback = new TestCallback();
oAuthService.execute(request, callback).get();
assertEquals(expectedResponseBody, callback.getResponse().getBody());
server.shutdown();
}
use of okhttp3.HttpUrl in project scribejava by scribejava.
the class AbstractClientTest method shouldReadResponseStream.
@Test
public void shouldReadResponseStream() throws Exception {
final String expectedResponseBody = "response body for test shouldReadResponseStream";
final MockWebServer server = new MockWebServer();
server.enqueue(new MockResponse().setBody(expectedResponseBody));
server.start();
final HttpUrl baseUrl = server.url("/testUrl");
final OAuthRequest request = new OAuthRequest(Verb.GET, baseUrl.toString());
final Response response = oAuthService.execute(request, null).get(30, TimeUnit.SECONDS);
assertEquals(expectedResponseBody, StreamUtils.getStreamContents(response.getStream()));
final RecordedRequest recordedRequest = server.takeRequest();
assertEquals("GET", recordedRequest.getMethod());
server.shutdown();
}
use of okhttp3.HttpUrl in project scribejava by scribejava.
the class AbstractClientTest method shouldPassErrors.
@Test
public void shouldPassErrors() throws Exception {
final MockWebServer server = new MockWebServer();
server.enqueue(new MockResponse().setResponseCode(500));
server.start();
final HttpUrl baseUrl = server.url("/testUrl");
final OAuthRequest request = new OAuthRequest(Verb.GET, baseUrl.toString());
final TestCallback callback = new TestCallback();
final Response response = oAuthService.execute(request, callback).get();
assertEquals(500, response.getCode());
assertEquals(500, callback.getResponse().getCode());
server.shutdown();
}
use of okhttp3.HttpUrl in project scribejava by scribejava.
the class AbstractClientTest method shouldSendPostRequest.
@Test
public void shouldSendPostRequest() throws Exception {
final String expectedResponseBody = "response body for test shouldSendPostRequest";
final String expectedRequestBody = "request body";
final MockWebServer server = new MockWebServer();
server.enqueue(new MockResponse().setBody(expectedResponseBody));
server.enqueue(new MockResponse().setBody(expectedResponseBody));
server.start();
final HttpUrl baseUrl = server.url("/testUrl");
// request with body
OAuthRequest request = new OAuthRequest(Verb.POST, baseUrl.toString());
request.setPayload(expectedRequestBody);
Response response = oAuthService.execute(request, null).get(30, TimeUnit.SECONDS);
assertEquals(expectedResponseBody, response.getBody());
RecordedRequest recordedRequest = server.takeRequest();
assertEquals("POST", recordedRequest.getMethod());
assertEquals(expectedRequestBody, recordedRequest.getBody().readUtf8());
// request with empty body
request = new OAuthRequest(Verb.POST, baseUrl.toString());
response = oAuthService.execute(request, null).get(30, TimeUnit.SECONDS);
assertEquals(expectedResponseBody, response.getBody());
recordedRequest = server.takeRequest();
assertEquals("POST", recordedRequest.getMethod());
assertEquals("", recordedRequest.getBody().readUtf8());
server.shutdown();
}
use of okhttp3.HttpUrl in project MiMangaNu by raulhaag.
the class NineManga method generateNeededCookie.
/**
* Helper function to generate the Cookie needed by NineManga.
*/
private static void generateNeededCookie() {
long aTime = System.currentTimeMillis() / 1000 - (int) (Math.random() * 100);
HttpUrl url = HttpUrl.parse("https://www.ninemanga.com/");
// pasring the valid constant URL will never fail
assert url != null;
Navigator.getCookieJar().saveFromResponse(url, Arrays.asList(Cookie.parse(url, "ninemanga_country_code=AR; Domain=ninemanga.com"), Cookie.parse(url, "__utma=128769555.619121721." + aTime + "." + aTime + "." + aTime + ".1; Domain=ninemanga.com"), Cookie.parse(url, "__utmc=128769555; Domain=ninemanga.com"), Cookie.parse(url, "__utmz=128769555." + aTime + ".1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none); Domain=ninemanga.com")));
cookieInit = true;
}
Aggregations