-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Adding module with common tests that have to be explicitly included with each MoccaHttpClient project. Plus some enhancements to MoccaJaxrsClient.
- Loading branch information
1 parent
6399ab6
commit 1e08fc9
Showing
18 changed files
with
229 additions
and
27 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
11 changes: 11 additions & 0 deletions
11
mocca-apache/src/test/java/com/paypal/mocca/client/BasicTest.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,11 @@ | ||
package com.paypal.mocca.client; | ||
|
||
import org.apache.http.impl.client.HttpClientBuilder; | ||
import org.testng.annotations.Test; | ||
|
||
@Test | ||
public class BasicTest extends BasicMoccaHttpClientTest { | ||
public BasicTest() { | ||
super(new MoccaApacheClient(HttpClientBuilder.create().build())); | ||
} | ||
} |
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
11 changes: 11 additions & 0 deletions
11
mocca-google/src/test/java/com/paypal/mocca/client/BasicTest.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,11 @@ | ||
package com.paypal.mocca.client; | ||
|
||
import com.google.api.client.http.javanet.NetHttpTransport; | ||
import org.testng.annotations.Test; | ||
|
||
@Test | ||
public class BasicTest extends BasicMoccaHttpClientTest { | ||
public BasicTest() { | ||
super(new MoccaGoogleHttpClient(new NetHttpTransport())); | ||
} | ||
} |
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
11 changes: 11 additions & 0 deletions
11
mocca-hc5/src/test/java/com/paypal/mocca/client/BasicTest.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,11 @@ | ||
package com.paypal.mocca.client; | ||
|
||
import org.apache.hc.client5.http.impl.classic.HttpClientBuilder; | ||
import org.testng.annotations.Test; | ||
|
||
@Test | ||
public class BasicTest extends BasicMoccaHttpClientTest { | ||
public BasicTest() { | ||
super(new MoccaApache5Client(HttpClientBuilder.create().build())); | ||
} | ||
} |
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,4 @@ | ||
# Introduction | ||
|
||
This module is a common test bed meant to be used by implementations of | ||
`com.paypal.mocca.client.MoccaHttpClient`. |
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,5 @@ | ||
dependencies { | ||
implementation project(':mocca-client'), | ||
lib.jetty_server, | ||
lib.testng | ||
} |
76 changes: 76 additions & 0 deletions
76
mocca-http-client-tests/src/main/java/com/paypal/mocca/client/BasicMoccaHttpClientTest.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,76 @@ | ||
package com.paypal.mocca.client; | ||
|
||
import com.paypal.mocca.client.annotation.Query; | ||
import org.eclipse.jetty.server.Request; | ||
import org.eclipse.jetty.server.Server; | ||
import org.eclipse.jetty.server.handler.AbstractHandler; | ||
import org.testng.annotations.AfterClass; | ||
import org.testng.annotations.BeforeClass; | ||
import org.testng.annotations.Test; | ||
|
||
import javax.servlet.http.HttpServletRequest; | ||
import javax.servlet.http.HttpServletResponse; | ||
import java.io.IOException; | ||
|
||
import static org.testng.Assert.assertEquals; | ||
|
||
/** | ||
* Verifies that a supplied {@link MoccaHttpClient} works for | ||
* some basic GraphQL call. The general idea being that we're | ||
* just testing the basic HTTP parts function correctly (e.g. | ||
* POST requests). | ||
* <p></p> | ||
* Unfortunately, there seems to be a Gradle or TestNG bug where | ||
* if a class contains no tests but extends one that does, then | ||
* Gradle build will not execute the test. Annotating the concrete | ||
* class with `@Test` appears to 'solve' the problem. | ||
*/ | ||
abstract class BasicMoccaHttpClientTest { | ||
// TODO solve the gradlew problem described above. Some links: | ||
// https://discuss.gradle.org/t/testng-tests-that-inherit-from-a-base-class-but-do-not-add-new-test-methods-are-not-detected/1259 | ||
// https://stackoverflow.com/questions/64087969/testng-cannot-find-test-methods-with-inheritance | ||
|
||
private static final String GRAPHQL_GREETING = "Hello!"; | ||
|
||
private final MoccaHttpClient moccaHttpClient; | ||
private Server graphqlServer; | ||
private SampleDataClient sampleDataClient; | ||
|
||
BasicMoccaHttpClientTest(MoccaHttpClient moccaHttpClient) { | ||
this.moccaHttpClient = Arguments.requireNonNull(moccaHttpClient); | ||
} | ||
|
||
@BeforeClass | ||
public void setUp() throws Exception { | ||
final int port = 0; // signals use random port | ||
graphqlServer = new Server(port); | ||
graphqlServer.setHandler(new AbstractHandler() { | ||
@Override | ||
public void handle(String target, Request baseRequest, HttpServletRequest req, HttpServletResponse resp) | ||
throws IOException { | ||
baseRequest.setHandled(true); | ||
resp.getWriter().write("{ \"data\": { \"greeting\": \"" + GRAPHQL_GREETING + "\" } }"); | ||
} | ||
}); | ||
graphqlServer.start(); | ||
sampleDataClient = MoccaClient.Builder.sync(graphqlServer.getURI().toASCIIString()) | ||
.client(moccaHttpClient) | ||
.build(SampleDataClient.class); | ||
} | ||
|
||
@AfterClass | ||
public void tearDown() throws Exception { | ||
graphqlServer.stop(); | ||
} | ||
|
||
@Test(description = "Basic GraphQL call") | ||
void testBasic() { | ||
final String greeting = sampleDataClient.greeting(); | ||
assertEquals(greeting, GRAPHQL_GREETING); | ||
} | ||
|
||
public interface SampleDataClient extends MoccaClient { | ||
@Query | ||
String greeting(); | ||
} | ||
} |
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
12 changes: 12 additions & 0 deletions
12
mocca-http2/src/test/java/com/paypal/mocca/client/BasicTest.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,12 @@ | ||
package com.paypal.mocca.client; | ||
|
||
import org.testng.annotations.Test; | ||
|
||
import java.net.http.HttpClient; | ||
|
||
@Test | ||
public class BasicTest extends BasicMoccaHttpClientTest { | ||
public BasicTest() { | ||
super(new MoccaHttp2Client(HttpClient.newBuilder().build())); | ||
} | ||
} |
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 |
---|---|---|
@@ -1,5 +1,11 @@ | ||
dependencies { | ||
implementation project(':mocca-client'), | ||
lib.feign_jaxrs2 | ||
lib.feign_jaxrs2, | ||
lib.slf4j_api | ||
api lib.jaxrs2 | ||
} | ||
|
||
testImplementation project(':mocca-http-client-tests'), | ||
lib.testng, | ||
lib.jersey_client, | ||
lib.jersey_hk2 | ||
} |
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
12 changes: 12 additions & 0 deletions
12
mocca-jaxrs2/src/test/java/com/paypal/mocca/client/BasicTest.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,12 @@ | ||
package com.paypal.mocca.client; | ||
|
||
import org.testng.annotations.Test; | ||
|
||
import javax.ws.rs.client.ClientBuilder; | ||
|
||
@Test | ||
public class BasicTest extends BasicMoccaHttpClientTest { | ||
public BasicTest() { | ||
super(new MoccaJaxrsClient(ClientBuilder.newClient())); | ||
} | ||
} |
Oops, something went wrong.