Skip to content

Commit

Permalink
Start of fixing jaxrs client 31
Browse files Browse the repository at this point in the history
HTTP client func test tweaks

 paypal#31 paypal#32
  • Loading branch information
Samuel Cox committed Aug 30, 2021
1 parent a78cd27 commit 5bf1943
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

abstract class BasicMoccaHttpClientTest {

private static final String GRAPHQL_GREETING = "Hello!";

private final MoccaHttpClient moccaHttpClient;
private Server graphqlServer;
private SampleDataClient sampleDataClient;
Expand All @@ -33,7 +35,7 @@ public void setUp() throws Exception {
public void handle(String target, Request baseRequest, HttpServletRequest req, HttpServletResponse resp)
throws IOException {
baseRequest.setHandled(true);
resp.getWriter().write("Hi!");
resp.getWriter().write("{ \"data\": { \"greeting\": \"" + GRAPHQL_GREETING + "\" } }");
}
});
graphqlServer.start();
Expand All @@ -50,7 +52,7 @@ public void tearDown() throws Exception {
@Test(description = "Basic GraphQL call")
void testBasic() {
final String greeting = sampleDataClient.greeting();
assertEquals(greeting, "hi!");
assertEquals(greeting, GRAPHQL_GREETING);
}

public interface SampleDataClient extends MoccaClient {
Expand Down
8 changes: 7 additions & 1 deletion mocca-jaxrs2/build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
dependencies {
implementation project(':mocca-client'),
lib.feign_jaxrs2
api lib.jaxrs2
api lib.jaxrs2,
lib.slf4j_api

testImplementation project(':mocca-http-client-tests'),
lib.testng,
lib.jersey_client,
lib.jersey_hk2
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.paypal.mocca.client;

import feign.jaxrs2.JAXRSClient;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.net.ssl.HostnameVerifier;
import javax.net.ssl.SSLContext;
Expand Down Expand Up @@ -32,12 +34,13 @@ public MoccaJaxrsClient(final Client client) {
}

private static class StubbornClientBuilder extends ClientBuilder {
private static Logger log = LoggerFactory.getLogger(StubbornClientBuilder.class);
private static final String USAGE_ERR_MSG = "Only #build can be called.";

final Client client;
private final Client client;

private StubbornClientBuilder(final Client client) {
this.client = Arguments.requireNonNull(client);
public StubbornClientBuilder(Client client) {
this.client = client;
}

@Override
Expand All @@ -47,97 +50,115 @@ public Client build() {

@Override
public ClientBuilder withConfig(Configuration config) {
throw new UnsupportedOperationException(USAGE_ERR_MSG);
log.debug(USAGE_ERR_MSG);
return this;
}

@Override
public ClientBuilder sslContext(SSLContext sslContext) {
throw new UnsupportedOperationException(USAGE_ERR_MSG);
log.debug(USAGE_ERR_MSG);
return this;
}

@Override
public ClientBuilder keyStore(KeyStore keyStore, char[] password) {
throw new UnsupportedOperationException(USAGE_ERR_MSG);
log.debug(USAGE_ERR_MSG);
return this;
}

@Override
public ClientBuilder trustStore(KeyStore trustStore) {
throw new UnsupportedOperationException(USAGE_ERR_MSG);
log.debug(USAGE_ERR_MSG);
return this;
}

@Override
public ClientBuilder hostnameVerifier(HostnameVerifier verifier) {
throw new UnsupportedOperationException(USAGE_ERR_MSG);
log.debug(USAGE_ERR_MSG);
return this;
}

@Override
public ClientBuilder executorService(ExecutorService executorService) {
throw new UnsupportedOperationException(USAGE_ERR_MSG);
log.debug(USAGE_ERR_MSG);
return this;
}

@Override
public ClientBuilder scheduledExecutorService(ScheduledExecutorService scheduledExecutorService) {
throw new UnsupportedOperationException(USAGE_ERR_MSG);
log.debug(USAGE_ERR_MSG);
return this;
}

@Override
public ClientBuilder connectTimeout(long timeout, TimeUnit unit) {
throw new UnsupportedOperationException(USAGE_ERR_MSG);
log.debug(USAGE_ERR_MSG);
return this;
}

@Override
public ClientBuilder readTimeout(long timeout, TimeUnit unit) {
throw new UnsupportedOperationException(USAGE_ERR_MSG);
log.debug(USAGE_ERR_MSG);
return this;
}

@Override
public Configuration getConfiguration() {
throw new UnsupportedOperationException(USAGE_ERR_MSG);
return client.getConfiguration();
}

@Override
public ClientBuilder property(String name, Object value) {
throw new UnsupportedOperationException(USAGE_ERR_MSG);
log.debug(USAGE_ERR_MSG);
return this;
}

@Override
public ClientBuilder register(Class<?> componentClass) {
throw new UnsupportedOperationException(USAGE_ERR_MSG);
log.debug(USAGE_ERR_MSG);
return this;
}

@Override
public ClientBuilder register(Class<?> componentClass, int priority) {
throw new UnsupportedOperationException(USAGE_ERR_MSG);
log.debug(USAGE_ERR_MSG);
return this;
}

@Override
public ClientBuilder register(Class<?> componentClass, Class<?>... contracts) {
throw new UnsupportedOperationException(USAGE_ERR_MSG);
log.debug(USAGE_ERR_MSG);
return this;
}

@Override
public ClientBuilder register(Class<?> componentClass, Map<Class<?>, Integer> contracts) {
throw new UnsupportedOperationException(USAGE_ERR_MSG);
log.debug(USAGE_ERR_MSG);
return this;
}

@Override
public ClientBuilder register(Object component) {
throw new UnsupportedOperationException(USAGE_ERR_MSG);
log.debug(USAGE_ERR_MSG);
return this;
}

@Override
public ClientBuilder register(Object component, int priority) {
throw new UnsupportedOperationException(USAGE_ERR_MSG);
log.debug(USAGE_ERR_MSG);
return this;
}

@Override
public ClientBuilder register(Object component, Class<?>... contracts) {
throw new UnsupportedOperationException(USAGE_ERR_MSG);
log.debug(USAGE_ERR_MSG);
return this;
}

@Override
public ClientBuilder register(Object component, Map<Class<?>, Integer> contracts) {
throw new UnsupportedOperationException(USAGE_ERR_MSG);
log.debug(USAGE_ERR_MSG);
return this;
}
}
}
5 changes: 3 additions & 2 deletions mocca-okhttp/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ dependencies {
lib.feign_okhttp
api lib.okhttp_client

testImplementation lib.testng,
project(':mocca-http-client-tests')

testImplementation project(':mocca-http-client-tests'),
lib.testng
}

0 comments on commit 5bf1943

Please sign in to comment.