Skip to content

Commit b810543

Browse files
committed
Unify ClientSupport and StubRest client APIs
- New api is a wrapper above jersey client api to simplify test-specific configuration and validation (jersey api is still available). The request builder unifies all possible configurations in one place. - New common base class TestClient (and TestRestClient for rest clients, adding rest-specific methods) - ClientSupport is a TestClient, but also could provide 3 special clients: appClient(), adminClient(), restClient() (restClient() is the same as StubRest client) - New sub clients could be created by applying additional path segments: client.subClient("/sub/path/) - External api client could be created with support.customClient("som external url") - New client rest api based on real method calls: restClient(RestClass.class).method(mock -> mock.restMethod(args)).invoke() (target path and method type resolved from annotations, arguments used for request configuration) - Helper api for testing multipart requests: restClient(..).multipartMethod(..) (simplifies multipart method arguments creation) - Defaults mechanism: it is possible to declare default headers, cookies, etc. on the client to be applied for all requests (evolution of StubRest client ideas) - Add PATCH method shortcuts - Add builder-style response assertions like: client.do_request.assertHeader("Name", val) This allows checking response headers, cookies, status code, etc. in a chained calls style without additional variables - Add connector switching api to ClientSupport: apacheClient(), urlconnectorClient() This allows using different connectors within one test (note that apache connector is required for PATCH calls and urlconnector better handles multipart requests) - (BREAKING) previous target(String... path) methods replaced with string format: target(String, Object...args) - (BREAKING) deprecated targetMain(): replaced with targetApp() - (BREAKING) StubRest default status declaration removed as not useful (required status could be declared now with the new request builder)
1 parent f434dc0 commit b810543

111 files changed

Lines changed: 13313 additions & 951 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

CHANGELOG.md

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55
- Add `useApacheClient` (shortcut) configuration into `@TestGuiceyApp` and `@TestDropwizardApp`
66
to simplify usage of ApacheTestClientFactory with annotations
77
- Add `useApacheClient()` (shortcut) method into extension and generic builders
8-
* @StubRest RestClient:
9-
- Add patch method shortcuts
108
* Shared state:
119
- State objects, implementing AutoClosable, now would be closed on application shutdown
1210
- Add SharedConfigurationState.lookupOrCreate method to simplify static state usage
@@ -18,6 +16,31 @@
1816
automatically mapped into url path and query params in this case)
1917
- General utility for resource methods analysis: ResourceAnalyzer (could be used in
2018
various api, based on resource (stub) call)
19+
* Unify ClientSupport and StubRest client APIs
20+
- New api is a wrapper above jersey client api to simplify test-specific configuration and validation
21+
(jersey api is still available). The request builder unifies all possible configurations in one place.
22+
- New common base class TestClient (and TestRestClient for rest clients, adding rest-specific methods)
23+
- ClientSupport is a TestClient, but also could provide 3 special clients: appClient(), adminClient(), restClient()
24+
(restClient() is the same as StubRest client)
25+
- New sub clients could be created by applying additional path segments:
26+
client.subClient("/sub/path/)
27+
- External api client could be created with support.customClient("som external url")
28+
- New client rest api based on real method calls: restClient(RestClass.class).method(mock -> mock.restMethod(args)).invoke()
29+
(target path and method type resolved from annotations, arguments used for request configuration)
30+
- Helper api for testing multipart requests: restClient(..).multipartMethod(..)
31+
(simplifies multipart method arguments creation)
32+
- Defaults mechanism: it is possible to declare default headers, cookies, etc.
33+
on the client to be applied for all requests (evolution of StubRest client ideas)
34+
- Add PATCH method shortcuts
35+
- Add builder-style response assertions like: client.do_request.assertHeader("Name", val)
36+
This allows checking response headers, cookies, status code, etc. in a chained calls style without additional variables
37+
- Add connector switching api to ClientSupport: apacheClient(), urlconnectorClient()
38+
This allows using different connectors within one test
39+
(note that apache connector is required for PATCH calls and urlconnector better handles multipart requests)
40+
- (BREAKING) previous target(String... path) methods replaced with string format: target(String, Object...args)
41+
- (BREAKING) deprecated targetMain(): replaced with targetApp()
42+
- (BREAKING) StubRest default status declaration removed as not useful
43+
(required status could be declared now with the new request builder)
2144

2245
### 7.2.1 (2025-05-12)
2346
* Fix NoClassDefFoundError on guicey startup due to junit classes leak into core (#428)

dropwizard-guicey/src/doc/docs/guide/test/general/client.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ Example usage:
1818
client.targetRest("some").request().buildGet().invoke()
1919

2020
// GET {main context path}/servlet
21-
client.targetMain("servlet").request().buildGet().invoke()
21+
client.targetApp("servlet").request().buildGet().invoke()
2222

2323
// GET {admin context path}/adminServlet
2424
client.targetAdmin("adminServlet").request().buildGet().invoke()
@@ -50,7 +50,7 @@ Also, if you want to use other client, client object can simply provide required
5050
client.getPort() // app port (8080)
5151
client.getAdminPort() // app admin port (8081)
5252
client.basePathRoot() // root server path (http://localhost:8080/)
53-
client.basePathMain() // main context path (http://localhost:8080/)
53+
client.basePathApp() // main context path (http://localhost:8080/)
5454
client.basePathAdmin() // admin context path (http://localhost:8081/)
5555
client.basePathRest() // rest context path (http://localhost:8080/)
5656
```

dropwizard-guicey/src/doc/docs/guide/test/junit5/client.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ Example usages:
2727
client.targetRest("some").request().buildGet().invoke()
2828

2929
// GET {main context path}/servlet
30-
client.targetMain("servlet").request().buildGet().invoke()
30+
client.targetApp("servlet").request().buildGet().invoke()
3131

3232
// GET {admin context path}/adminServlet
3333
client.targetAdmin("adminServlet").request().buildGet().invoke()
@@ -59,7 +59,7 @@ Also, if you want to use other client, client object can simply provide required
5959
client.getPort() // app port (8080)
6060
client.getAdminPort() // app admin port (8081)
6161
client.basePathRoot() // root server path (http://localhost:8080/)
62-
client.basePathMain() // main context path (http://localhost:8080/)
62+
client.basePathApp() // main context path (http://localhost:8080/)
6363
client.basePathAdmin() // admin context path (http://localhost:8081/)
6464
client.basePathRest() // rest context path (http://localhost:8080/)
6565
```

dropwizard-guicey/src/doc/docs/guide/test/junit5/nested.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ public class ClientSupportDwTest {
104104
// test to apply for multiple environments
105105
@Test
106106
default void callClient(ClientSupport client) {
107-
Assertions.assertEquals("main", client.targetMain("servlet")
107+
Assertions.assertEquals("main", client.targetApp("servlet")
108108
.request().buildGet().invoke().readEntity(String.class));
109109
}
110110
}
@@ -115,7 +115,7 @@ public class ClientSupportDwTest {
115115

116116
@Test
117117
void testClient(ClientSupport client) {
118-
Assertions.assertEquals("http://localhost:8080/", client.basePathMain());
118+
Assertions.assertEquals("http://localhost:8080/", client.basePathApp());
119119
}
120120
}
121121

@@ -128,7 +128,7 @@ public class ClientSupportDwTest {
128128

129129
@Test
130130
void testClient(ClientSupport client) {
131-
Assertions.assertEquals("http://localhost:8080/app/", client.basePathMain());
131+
Assertions.assertEquals("http://localhost:8080/app/", client.basePathApp());
132132
}
133133
}
134134
}

dropwizard-guicey/src/doc/docs/guide/test/junit5/run.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ class WebModuleTest {
126126
public void checkWebBindings(ClientSupport client) {
127127

128128
Assertions.assertEquals("Sample filter and service called",
129-
client.targetMain("servlet").request().buildGet().invoke().readEntity(String.class));
129+
client.targetApp("servlet").request().buildGet().invoke().readEntity(String.class));
130130

131131
Assertions.assertTrur(service.isCalled());
132132
```

dropwizard-guicey/src/doc/docs/guide/test/spock.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ Example usages:
210210
client.targetRest("some").request().buildGet().invoke()
211211
212212
// GET {main context path}/servlet
213-
client.targetMain("servlet").request().buildGet().invoke()
213+
client.targetApp("servlet").request().buildGet().invoke()
214214
215215
// GET {admin context path}/adminServlet
216216
client.targetAdmin("adminServlet").request().buildGet().invoke()
@@ -240,7 +240,7 @@ Also, if you want to use other client, client object can simply provide required
240240
```groovy
241241
client.getPort() // app port (8080)
242242
client.getAdminPort() // app admin port (8081)
243-
client.basePathMain() // main context path (http://localhost:8080/)
243+
client.basePathApp() // main context path (http://localhost:8080/)
244244
client.basePathAdmin() // admin context path (http://localhost:8081/)
245245
client.basePathRest() // rest context path (http://localhost:8080/)
246246
```

dropwizard-guicey/src/main/java/ru/vyarus/dropwizard/guice/module/installer/util/StackUtils.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,14 @@ private StackUtils() {
3535
* @param skip classes to skip in stack
3636
* @return caller stack frame
3737
*/
38+
@SuppressWarnings("checkstyle:BooleanExpressionComplexity")
3839
public static Optional<StackWalker.StackFrame> getCaller(final List<Class<?>> skip) {
3940
return WALKER.walk(stream ->
4041
stream.dropWhile(frame -> {
4142
final Class<?> type = frame.getDeclaringClass();
4243
return type.equals(StackUtils.class)
44+
|| type.getPackageName().startsWith("java.")
45+
|| type.getPackageName().startsWith("jakarta.")
4346
|| type.getPackage().getName().startsWith("org.codehaus.groovy.vmplugin")
4447
|| skip.contains(type)
4548
|| skip.contains(type.getEnclosingClass());

0 commit comments

Comments
 (0)