-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
285 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
src/test/java/com/chavaillaz/client/common/apache/ApacheHttpTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package com.chavaillaz.client.common.apache; | ||
|
||
import static com.chavaillaz.client.common.apache.ApacheHttpUtils.defaultHttpClientBuilder; | ||
import static com.chavaillaz.client.common.model.UserApi.stubForUserApi; | ||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertNotNull; | ||
|
||
import com.chavaillaz.client.common.model.User; | ||
import com.chavaillaz.client.common.security.AnonymousAuthentication; | ||
import com.github.tomakehurst.wiremock.junit5.WireMockRuntimeInfo; | ||
import com.github.tomakehurst.wiremock.junit5.WireMockTest; | ||
import org.apache.hc.client5.http.impl.async.CloseableHttpAsyncClient; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
|
||
@WireMockTest | ||
class ApacheHttpTest { | ||
|
||
@BeforeEach | ||
void setup() { | ||
stubForUserApi(); | ||
} | ||
|
||
@Test | ||
void testApache(WireMockRuntimeInfo wiremock) throws Exception { | ||
CloseableHttpAsyncClient client = defaultHttpClientBuilder(null).build(); | ||
try (var api = new ApacheHttpUserApi(client, wiremock.getHttpBaseUrl(), new AnonymousAuthentication())) { | ||
User user = api.getUser().join(); | ||
assertNotNull(user); | ||
assertEquals("WireMock", user.getUsername()); | ||
} | ||
} | ||
|
||
} |
22 changes: 22 additions & 0 deletions
22
src/test/java/com/chavaillaz/client/common/apache/ApacheHttpUserApi.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package com.chavaillaz.client.common.apache; | ||
|
||
import static org.apache.hc.client5.http.async.methods.SimpleRequestBuilder.get; | ||
|
||
import java.util.concurrent.CompletableFuture; | ||
|
||
import com.chavaillaz.client.common.model.User; | ||
import com.chavaillaz.client.common.model.UserApi; | ||
import com.chavaillaz.client.common.security.Authentication; | ||
import org.apache.hc.client5.http.impl.async.CloseableHttpAsyncClient; | ||
|
||
public class ApacheHttpUserApi extends AbstractApacheHttpClient implements UserApi { | ||
|
||
public ApacheHttpUserApi(CloseableHttpAsyncClient client, String baseUrl, Authentication authentication) { | ||
super(client, baseUrl, authentication); | ||
} | ||
|
||
public CompletableFuture<User> getUser() { | ||
return sendAsync(requestBuilder(get(), URL_USER), User.class); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
src/test/java/com/chavaillaz/client/common/java/JavaHttpTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package com.chavaillaz.client.common.java; | ||
|
||
import static com.chavaillaz.client.common.java.JavaHttpUtils.defaultHttpClientBuilder; | ||
import static com.chavaillaz.client.common.model.UserApi.stubForUserApi; | ||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertNotNull; | ||
|
||
import java.net.http.HttpClient; | ||
|
||
import com.chavaillaz.client.common.model.User; | ||
import com.chavaillaz.client.common.security.AnonymousAuthentication; | ||
import com.github.tomakehurst.wiremock.junit5.WireMockRuntimeInfo; | ||
import com.github.tomakehurst.wiremock.junit5.WireMockTest; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
|
||
@WireMockTest | ||
class JavaHttpTest { | ||
|
||
@BeforeEach | ||
void setup() { | ||
stubForUserApi(); | ||
} | ||
|
||
@Test | ||
void testJava(WireMockRuntimeInfo wiremock) { | ||
HttpClient client = defaultHttpClientBuilder(null).build(); | ||
try (var api = new JavaHttpUserApi(client, wiremock.getHttpBaseUrl(), new AnonymousAuthentication())) { | ||
User user = api.getUser().join(); | ||
assertNotNull(user); | ||
assertEquals("WireMock", user.getUsername()); | ||
} | ||
} | ||
|
||
} |
21 changes: 21 additions & 0 deletions
21
src/test/java/com/chavaillaz/client/common/java/JavaHttpUserApi.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package com.chavaillaz.client.common.java; | ||
|
||
import java.net.http.HttpClient; | ||
import java.util.concurrent.CompletableFuture; | ||
|
||
import com.chavaillaz.client.common.model.User; | ||
import com.chavaillaz.client.common.model.UserApi; | ||
import com.chavaillaz.client.common.security.Authentication; | ||
|
||
public class JavaHttpUserApi extends AbstractJavaHttpClient implements UserApi { | ||
|
||
public JavaHttpUserApi(HttpClient client, String baseUrl, Authentication authentication) { | ||
super(client, baseUrl, authentication); | ||
} | ||
|
||
@Override | ||
public CompletableFuture<User> getUser() { | ||
return sendAsync(requestBuilder(URL_USER).GET(), User.class); | ||
} | ||
|
||
} |
10 changes: 10 additions & 0 deletions
10
src/test/java/com/chavaillaz/client/common/model/User.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package com.chavaillaz.client.common.model; | ||
|
||
import lombok.Data; | ||
|
||
@Data | ||
public class User { | ||
|
||
private String username; | ||
|
||
} |
28 changes: 28 additions & 0 deletions
28
src/test/java/com/chavaillaz/client/common/model/UserApi.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package com.chavaillaz.client.common.model; | ||
|
||
import static com.github.tomakehurst.wiremock.client.WireMock.aResponse; | ||
import static com.github.tomakehurst.wiremock.client.WireMock.get; | ||
import static com.github.tomakehurst.wiremock.client.WireMock.stubFor; | ||
import static com.github.tomakehurst.wiremock.common.ContentTypes.APPLICATION_JSON; | ||
|
||
import java.util.concurrent.CompletableFuture; | ||
|
||
public interface UserApi extends AutoCloseable { | ||
|
||
String URL_USER = "/user"; | ||
|
||
static void stubForUserApi() { | ||
stubFor(get("/user").willReturn(aResponse() | ||
.withStatus(200) | ||
.withHeader("Content-Type", APPLICATION_JSON) | ||
.withBody("{\"username\": \"WireMock\"}"))); | ||
} | ||
|
||
/** | ||
* Gets the current user. | ||
* | ||
* @return A {@link CompletableFuture} with the user | ||
*/ | ||
CompletableFuture<User> getUser(); | ||
|
||
} |
34 changes: 34 additions & 0 deletions
34
src/test/java/com/chavaillaz/client/common/okhttp/OkHttpTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package com.chavaillaz.client.common.okhttp; | ||
|
||
import static com.chavaillaz.client.common.model.UserApi.stubForUserApi; | ||
import static com.chavaillaz.client.common.okhttp.OkHttpUtils.defaultHttpClientBuilder; | ||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertNotNull; | ||
|
||
import com.chavaillaz.client.common.model.User; | ||
import com.chavaillaz.client.common.security.AnonymousAuthentication; | ||
import com.github.tomakehurst.wiremock.junit5.WireMockRuntimeInfo; | ||
import com.github.tomakehurst.wiremock.junit5.WireMockTest; | ||
import okhttp3.OkHttpClient; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
|
||
@WireMockTest | ||
class OkHttpTest { | ||
|
||
@BeforeEach | ||
void setup() { | ||
stubForUserApi(); | ||
} | ||
|
||
@Test | ||
void testOkHttp(WireMockRuntimeInfo wiremock) throws Exception { | ||
OkHttpClient client = defaultHttpClientBuilder(null).build(); | ||
try (var api = new OkHttpUserApi(client, wiremock.getHttpBaseUrl(), new AnonymousAuthentication())) { | ||
User user = api.getUser().join(); | ||
assertNotNull(user); | ||
assertEquals("WireMock", user.getUsername()); | ||
} | ||
} | ||
|
||
} |
21 changes: 21 additions & 0 deletions
21
src/test/java/com/chavaillaz/client/common/okhttp/OkHttpUserApi.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package com.chavaillaz.client.common.okhttp; | ||
|
||
import java.util.concurrent.CompletableFuture; | ||
|
||
import com.chavaillaz.client.common.model.User; | ||
import com.chavaillaz.client.common.model.UserApi; | ||
import com.chavaillaz.client.common.security.Authentication; | ||
import okhttp3.OkHttpClient; | ||
|
||
public class OkHttpUserApi extends AbstractOkHttpClient implements UserApi { | ||
|
||
public OkHttpUserApi(OkHttpClient client, String baseUrl, Authentication authentication) { | ||
super(client, baseUrl, authentication); | ||
} | ||
|
||
@Override | ||
public CompletableFuture<User> getUser() { | ||
return sendAsync(requestBuilder(URL_USER).get(), User.class); | ||
} | ||
|
||
} |
35 changes: 35 additions & 0 deletions
35
src/test/java/com/chavaillaz/client/common/vertx/VertxHttpTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package com.chavaillaz.client.common.vertx; | ||
|
||
import static com.chavaillaz.client.common.model.UserApi.stubForUserApi; | ||
import static com.chavaillaz.client.common.vertx.VertxUtils.defaultWebClientOptions; | ||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertNotNull; | ||
|
||
import com.chavaillaz.client.common.model.User; | ||
import com.chavaillaz.client.common.security.AnonymousAuthentication; | ||
import com.github.tomakehurst.wiremock.junit5.WireMockRuntimeInfo; | ||
import com.github.tomakehurst.wiremock.junit5.WireMockTest; | ||
import io.vertx.core.Vertx; | ||
import io.vertx.ext.web.client.WebClient; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
|
||
@WireMockTest | ||
class VertxHttpTest { | ||
|
||
@BeforeEach | ||
void setup() { | ||
stubForUserApi(); | ||
} | ||
|
||
@Test | ||
void testVertx(WireMockRuntimeInfo wiremock) throws Exception { | ||
WebClient client = WebClient.create(Vertx.vertx(), defaultWebClientOptions(null)); | ||
try (var api = new VertxHttpUserApi(client, wiremock.getHttpBaseUrl(), new AnonymousAuthentication())) { | ||
User user = api.getUser().join(); | ||
assertNotNull(user); | ||
assertEquals("WireMock", user.getUsername()); | ||
} | ||
} | ||
|
||
} |
23 changes: 23 additions & 0 deletions
23
src/test/java/com/chavaillaz/client/common/vertx/VertxHttpUserApi.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package com.chavaillaz.client.common.vertx; | ||
|
||
import static io.vertx.core.http.HttpMethod.GET; | ||
|
||
import java.util.concurrent.CompletableFuture; | ||
|
||
import com.chavaillaz.client.common.model.User; | ||
import com.chavaillaz.client.common.model.UserApi; | ||
import com.chavaillaz.client.common.security.Authentication; | ||
import io.vertx.ext.web.client.WebClient; | ||
|
||
public class VertxHttpUserApi extends AbstractVertxHttpClient implements UserApi { | ||
|
||
protected VertxHttpUserApi(WebClient client, String baseUrl, Authentication authentication) { | ||
super(client, baseUrl, authentication); | ||
} | ||
|
||
@Override | ||
public CompletableFuture<User> getUser() { | ||
return handleAsync(requestBuilder(GET, URL_USER).send(), User.class); | ||
} | ||
|
||
} |