Skip to content

#133 - [http-client] Disable more client tests that hit github api #134

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions http-client/src/main/java/io/avaje/http/client/DHttpApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ void init() {
log.log(DEBUG, "providers for {0}", providerMap.keySet());
}

void addProvider(HttpApiProvider apiProvider) {
void addProvider(HttpApiProvider<?> apiProvider) {
providerMap.put(apiProvider.type(), apiProvider);
}

Expand All @@ -41,7 +41,7 @@ private <T> HttpApiProvider<T> lookup(Class<T> type) {
}

@SuppressWarnings("unchecked")
<T> T provideFor(Class<T> type, HttpClientContext clientContext) {
<T> T provideFor(Class<T> type, HttpClient clientContext) {
final HttpApiProvider<T> apiProvider = lookup(type);
if (apiProvider == null) {
throw new IllegalArgumentException("No registered HttpApiProvider for type: " + type);
Expand All @@ -52,7 +52,7 @@ <T> T provideFor(Class<T> type, HttpClientContext clientContext) {
/**
* Return the client implementation via service loading.
*/
static <T> T provide(Class<T> type, HttpClientContext clientContext) {
static <T> T provide(Class<T> type, HttpClient clientContext) {
return INSTANCE.provideFor(type, clientContext);
}

Expand Down
10 changes: 5 additions & 5 deletions http-client/src/test/java/io/avaje/http/client/DHttpApiTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

import static org.assertj.core.api.Assertions.assertThat;

public class DHttpApiTest {
class DHttpApiTest {

@Disabled
@Test
Expand All @@ -31,22 +31,22 @@ void test_github_listRepos() {
assertThat(repos).isNotEmpty();
}

@Disabled
@Test
void jsonb_github_listRepos() {

Jsonb jsonb = Jsonb.newBuilder()
Jsonb jsonb = Jsonb.builder()
.add(Repo.class, RepoJsonAdapter::new)
//.adapter(new JacksonAdapter())
.build();

final HttpClientContext clientContext = HttpClientContext.builder()
final HttpClient client = HttpClient.builder()
.baseUrl("https://api.github.com")
.bodyAdapter(new JsonbBodyAdapter(jsonb))
.build();

DHttpApi httpApi = new DHttpApi();
httpApi.addProvider(new Simple$HttpClient.Provider());
final Simple simple = httpApi.provideFor(Simple.class, clientContext);
final Simple simple = httpApi.provideFor(Simple.class, client);

final List<Repo> repos = simple.listRepos("rbygrave", "junk");
assertThat(repos).isNotEmpty();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import java.io.IOException;
import java.util.List;

public class GitHubServiceTest {
class GitHubServiceTest {

@Disabled
@Test
Expand All @@ -37,9 +37,6 @@ public void onFailure(Call<List<Repo>> call, Throwable throwable) {
System.out.println("onFailure: " + throwable);
}
});
// final Response<List<Repo>> res = call.execute();
// final List<Repo> body = res.body();
// System.out.println("done count: "+body.size());

final Call<String> call2 = service.list2("octocat");
final Response<String> res2 = call2.execute();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import com.fasterxml.jackson.databind.ObjectMapper;
import io.avaje.http.client.HttpApiProvider;
import io.avaje.http.client.HttpClient;
import io.avaje.http.client.HttpClientContext;
import io.avaje.http.client.JacksonBodyAdapter;
import org.example.httpclient.GitHubUsersHttpClient;
import org.junit.jupiter.api.Disabled;
Expand All @@ -14,22 +13,21 @@

import static org.assertj.core.api.Assertions.assertThat;

public class SimpleTest {
class SimpleTest {

@Disabled
@Test
void listRepos() {

final ObjectMapper objectMapper = new ObjectMapper()
.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);

final HttpClientContext clientContext =
HttpClientContext.builder()
final HttpClient client =
HttpClient.builder()
.baseUrl("https://api.github.com")
.bodyAdapter(new JacksonBodyAdapter(objectMapper))
.build();

GitHubUsers simple = clientContext.create(GitHubUsers.class);
GitHubUsers simple = client.create(GitHubUsers.class);

final List<Repo> repos = simple.listRepos("rbygrave");
System.out.println("got repos - " + repos.size());
Expand Down
11 changes: 7 additions & 4 deletions tests/test-client/src/test/java/example/github/GithubTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,36 +2,39 @@

import com.google.gson.Gson;
import io.avaje.http.client.BodyAdapter;
import io.avaje.http.client.HttpClientContext;
import io.avaje.http.client.HttpClient;
import io.avaje.http.client.JacksonBodyAdapter;
import io.avaje.http.client.gson.GsonBodyAdapter;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;

import java.util.List;

import static org.assertj.core.api.Assertions.assertThat;

public class GithubTest {
class GithubTest {

@Disabled
@Test
void test_with_jackson() {
assertListRepos(jacksonBodyAdapter());
}

@Disabled
@Test
void test_with_gson() {
assertListRepos(gsonBodyAdapter());
}

private void assertListRepos(BodyAdapter bodyAdapter) {
final HttpClientContext clientContext = HttpClientContext.builder()
final HttpClient client = HttpClient.builder()
.baseUrl("https://api.github.com")
.bodyAdapter(bodyAdapter)
// .requestLogging(false)
// .requestListener(new RequestLogger())
.build();

final Simple simple = clientContext.create(Simple.class);
final Simple simple = client.create(Simple.class);

final List<Repo> repos = simple.listRepos("rbygrave", "junk");
assertThat(repos).isNotEmpty();
Expand Down