use of com.tonyodev.fetch2.Request in project retrofit by square.
the class RequestBuilderTest method customMethodNoBody.
@Test
public void customMethodNoBody() {
class Example {
@HTTP(method = "CUSTOM1", path = "/foo")
Call<ResponseBody> method() {
return null;
}
}
Request request = buildRequest(Example.class);
assertThat(request.method()).isEqualTo("CUSTOM1");
assertThat(request.url().toString()).isEqualTo("http://example.com/foo");
assertThat(request.body()).isNull();
}
use of com.tonyodev.fetch2.Request in project retrofit by square.
the class RequestBuilderTest method multipartPartsShouldBeInOrder.
@Test
public void multipartPartsShouldBeInOrder() throws IOException {
class Example {
@Multipart
@POST("/foo")
Call<ResponseBody> get(@Part("first") String data, @Part("second") String dataTwo, @Part("third") String dataThree) {
return null;
}
}
Request request = buildRequest(Example.class, "firstParam", "secondParam", "thirdParam");
MultipartBody body = (MultipartBody) request.body();
Buffer buffer = new Buffer();
body.writeTo(buffer);
String readBody = buffer.readUtf8();
assertThat(readBody.indexOf("firstParam")).isLessThan(readBody.indexOf("secondParam"));
assertThat(readBody.indexOf("secondParam")).isLessThan(readBody.indexOf("thirdParam"));
}
use of com.tonyodev.fetch2.Request in project retrofit by square.
the class RequestBuilderTest method getWithUrlAbsoluteSameHost.
@Test
public void getWithUrlAbsoluteSameHost() {
class Example {
@GET
Call<ResponseBody> method(@Url String url) {
return null;
}
}
Request request = buildRequest(Example.class, "http://example.com/foo/bar/");
assertThat(request.method()).isEqualTo("GET");
assertThat(request.headers().size()).isZero();
assertThat(request.url().toString()).isEqualTo("http://example.com/foo/bar/");
assertThat(request.body()).isNull();
}
use of com.tonyodev.fetch2.Request in project retrofit by square.
the class RequestBuilderTest method getWithHeaderMap.
@Test
public void getWithHeaderMap() {
class Example {
@GET("/search")
Call<ResponseBody> method(@HeaderMap Map<String, Object> headers) {
return null;
}
}
Map<String, Object> headers = new LinkedHashMap<>();
headers.put("Accept", "text/plain");
headers.put("Accept-Charset", "utf-8");
Request request = buildRequest(Example.class, headers);
assertThat(request.method()).isEqualTo("GET");
assertThat(request.url().toString()).isEqualTo("http://example.com/search");
assertThat(request.body()).isNull();
assertThat(request.headers().size()).isEqualTo(2);
assertThat(request.header("Accept")).isEqualTo("text/plain");
assertThat(request.header("Accept-Charset")).isEqualTo("utf-8");
}
use of com.tonyodev.fetch2.Request in project keywhiz by square.
the class XsrfServletFilterIntegrationTest method rejectsForAdminUrlWithoutXsrf.
@Test
public void rejectsForAdminUrlWithoutXsrf() throws Exception {
noXsrfClient.newCall(buildLoginPost(DbSeedCommand.defaultUser, DbSeedCommand.defaultPassword)).execute();
Request request = new Request.Builder().url(testUrl("/admin/clients")).get().build();
Response response = noXsrfClient.newCall(request).execute();
assertThat(response.code()).isEqualTo(401);
}
Aggregations