Skip to content

Commit

Permalink
Update tests with upper case verbs
Browse files Browse the repository at this point in the history
  • Loading branch information
rbygrave committed Jun 16, 2021
1 parent e057176 commit 17a7ae3
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 30 deletions.
6 changes: 3 additions & 3 deletions client/src/test/java/io/avaje/http/client/AuthTokenTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public AuthToken obtainToken(HttpClientRequest tokenRequest) {
.url("https://foo/v2/token")
.header("content-type", "application/json")
.body(authRequestAsJson())
.post()
.POST()
.bean(AuthTokenResponse.class);

Instant validUntil = Instant.now().plusSeconds(res.expires_in).minusSeconds(60);
Expand All @@ -58,14 +58,14 @@ void sendEmail() {
.path(path)
.header("Content-Type", "application/json")
//.body(payload)
.post()
.POST()
.asString();

HttpResponse<String> res2 = ctx.request()
.path(path)
.header("Content-Type", "application/json")
//.body(payload)
.post()
.POST()
.asString();

}
Expand Down
38 changes: 20 additions & 18 deletions client/src/test/java/io/avaje/http/client/HelloControllerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@
import java.util.Map;

import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.fail;
import static org.junit.jupiter.api.Assertions.*;

class HelloControllerTest extends BaseWebTest {

Expand All @@ -22,7 +20,7 @@ void get_helloMessage() {

final HttpResponse<String> hres = clientContext.request()
.path("hello").path("message")
.get().asString();
.GET().asString();

assertThat(hres.body()).contains("hello world");
assertThat(hres.statusCode()).isEqualTo(200);
Expand All @@ -34,7 +32,7 @@ void get_helloMessage_via_url() {
final HttpResponse<String> hres = clientContext.request()
.url("http://127.0.0.1:8887")
.path("hello").path("message")
.get().asString();
.GET().asString();

assertThat(hres.body()).contains("hello world");
assertThat(hres.statusCode()).isEqualTo(200);
Expand All @@ -45,7 +43,7 @@ void get_hello_returningListOfBeans() {

final List<HelloDto> helloDtos = clientContext.request()
.path("hello")
.get().list(HelloDto.class);
.GET().list(HelloDto.class);

assertThat(helloDtos).hasSize(2);
}
Expand All @@ -54,8 +52,9 @@ void get_hello_returningListOfBeans() {
void get_withPathParamAndQueryParam_returningBean() {

final HelloDto dto = clientContext.request()
.path("hello/43/2020-03-05").queryParam("otherParam", "other").queryParam("foo", (String) null)
.get().bean(HelloDto.class);
.path("hello/43/2020-03-05").queryParam("otherParam", "other").queryParam("foo", null)
.GET()
.bean(HelloDto.class);

assertThat(dto.id).isEqualTo(43L);
assertThat(dto.name).isEqualTo("2020-03-05");
Expand All @@ -73,7 +72,7 @@ void post_bean_returningBean_usingExplicitConverters() {
final HelloDto bean = clientContext.request()
.path("hello")
.body(from.write(dto))
.post()
.POST()
.read(toDto);

assertEquals("posted", bean.name);
Expand All @@ -87,7 +86,8 @@ void post_bean_returningVoid() {

final HttpResponse<Void> res = clientContext.request()
.path("hello/savebean/foo")
.body(dto).post()
.body(dto)
.POST()
.asDiscarding();

assertThat(res.statusCode()).isEqualTo(201);
Expand All @@ -102,7 +102,7 @@ void postForm() {
.formParam("email", "[email protected]")
.formParam("url", "http://foo.com")
.formParam("startDate", "2030-12-03")
.post()
.POST()
.asDiscarding();

assertThat(res.statusCode()).isEqualTo(201);
Expand All @@ -117,7 +117,7 @@ void postForm_returningBean() {
.formParam("email", "[email protected]")
.formParam("url", "http://foo.com")
.formParam("startDate", "2030-12-03")
.post()
.POST()
.asDiscarding();

assertThat(res.statusCode()).isEqualTo(201);
Expand All @@ -128,7 +128,7 @@ void postForm_returningBean() {
.formParam("email", "[email protected]")
.formParam("url", "http://foo.com")
.formParam("startDate", "2030-12-03")
.post()
.POST()
.bean(HelloDto.class);

assertThat(bean.name).isEqualTo("Bax");
Expand All @@ -143,7 +143,7 @@ void postForm_asVoid_validResponse() {
.formParam("name", "baz")
.formParam("email", "[email protected]")
.formParam("url", "http://foo")
.post()
.POST()
.asVoid();

assertEquals(201, res.statusCode());
Expand All @@ -156,7 +156,7 @@ void postForm_asVoid_invokesValidation_expect_badRequest_extractError() {
.path("hello/saveform")
.formParam("email", "[email protected]")
.formParam("url", "notAValidUrl")
.post()
.POST()
.asVoid();

fail();
Expand All @@ -183,7 +183,7 @@ void postForm_asBytes_validation_expect_badRequest_extractError() {
.path("hello/saveform")
.formParam("email", "[email protected]")
.formParam("url", "notAValidUrl")
.post().asVoid();
.POST().asVoid();

fail();

Expand Down Expand Up @@ -212,7 +212,8 @@ void delete() {
final HttpResponse<Void> res =
clientContext.request()
.path("hello/52")
.delete().asDiscarding();
.DELETE()
.asDiscarding();

assertThat(res.statusCode()).isEqualTo(204);
}
Expand All @@ -226,7 +227,8 @@ void get_withMatrixParam() {
.matrixParam("country", "nz")
.path("foo")
.queryParam("extra", "banana")
.get().asString();
.GET()
.asString();

assertEquals(200, httpRes.statusCode());
assertEquals("yr:2011 au:rob co:nz other:foo extra:banana", httpRes.body());
Expand Down
2 changes: 1 addition & 1 deletion client/src/test/java/io/avaje/http/client/RetryTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ void retryTest() {

HttpResponse<String> res = clientContext.request()
.path("hello/retry")
.get()
.GET()
.asString();

assertThat(res.body()).isEqualTo("All good at 3rd attempt");
Expand Down
4 changes: 2 additions & 2 deletions client/src/test/java/io/avaje/http/client/UrlBuilderTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ void matrixParam_path() {

@Test
void param() {
assertThat(foo().queryParam("bar", (String) null).build()).isEqualTo("https://foo");
assertThat(foo().queryParam("bar", null).build()).isEqualTo("https://foo");
assertThat(foo().queryParam("bar", "a").build()).isEqualTo("https://foo?bar=a");
assertThat(foo().queryParam("bar", "a").queryParam("baz", "b").build()).isEqualTo("https://foo?bar=a&baz=b");
}
Expand All @@ -75,7 +75,7 @@ void param_encode() {

@Test
void queryParam_when_null() {
assertThat(foo().queryParam("bar", (String) null).build()).isEqualTo("https://foo");
assertThat(foo().queryParam("bar", null).build()).isEqualTo("https://foo");
assertThat(foo().queryParam("bar", (Boolean) null).build()).isEqualTo("https://foo");
assertThat(foo().queryParam("bar", (Integer) null).build()).isEqualTo("https://foo");
assertThat(foo().queryParam("bar", (Long) null).build()).isEqualTo("https://foo");
Expand Down
4 changes: 2 additions & 2 deletions client/src/test/java/io/avaje/http/client/VerbTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ void post() {

HttpResponse<String> res2 = clientContext.request()
.path("post")
.post()
.POST()
.asString();

assertThat(res2.body()).isEqualTo("post");
Expand All @@ -41,7 +41,7 @@ void put() {

HttpResponse<String> res2 = clientContext.request()
.path("put")
.put()
.PUT()
.asString();

assertThat(res2.body()).isEqualTo("put");
Expand Down
8 changes: 4 additions & 4 deletions client/src/test/java/org/example/github/SimpleHttpClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public List<Repo> listRepos(String user, String other) throws HttpException {
return context.request()
.path("users").path(user).path("repos")
.queryParam("other", other)
.get().list(Repo.class);
.GET().list(Repo.class);
}

@Post("users")
Expand All @@ -38,23 +38,23 @@ public Repo post(Repo repo) throws HttpException {
return context.request()
.path("foo/users")
.body(writeRepo.write(repo))
.post().read(readRepo);
.POST().read(readRepo);
}

@Get("users/{id}")
@Override
public Repo getById(String id) {
return context.request()
.path("users").path(id)
.get().bean(Repo.class);
.GET().bean(Repo.class);
}

public InputStream getById2(String id, InputStream is) {
final HttpResponse<InputStream> response =
context.request()
.path("users").path(id).path("stream")
.body(() -> is)
.get().withResponseHandler(HttpResponse.BodyHandlers.ofInputStream());
.GET().withResponseHandler(HttpResponse.BodyHandlers.ofInputStream());

context.checkResponse(response);
return response.body();
Expand Down

0 comments on commit 17a7ae3

Please sign in to comment.