public class ClientSupport
extends java.lang.Object
implements java.lang.AutoCloseable
JerseyClient support for direct web tests (complete dropwizard startup).
Client support maintains single JerseyClient instance. It may be used for calling any urls (not just
application). Class provides many utility methods for automatic construction of base context paths, so
tests could be completely independent from actual configuration.
| Constructor and Description |
|---|
ClientSupport(io.dropwizard.testing.DropwizardTestSupport<?> support) |
| Modifier and Type | Method and Description |
|---|---|
java.lang.String |
basePathAdmin()
For example, with default configuration it would be "http://localhost:8080/".
|
java.lang.String |
basePathMain()
For example, with default configuration it would be "http://localhost:8080/".
|
java.lang.String |
basePathRest()
For example, with default configuration it would be "http://localhost:8080/".
|
void |
close() |
int |
getAdminPort() |
org.glassfish.jersey.client.JerseyClient |
getClient()
Single client instance maintained within test and method will always return the same instance.
|
int |
getPort() |
javax.ws.rs.client.WebTarget |
target(java.lang.String... paths)
Unbounded (universal)
WebTarget construction shortcut. |
javax.ws.rs.client.WebTarget |
targetAdmin(java.lang.String... paths)
Shortcut for
WebTarget creation for admin context path. |
javax.ws.rs.client.WebTarget |
targetMain(java.lang.String... paths)
Shortcut for
WebTarget creation for main context path. |
javax.ws.rs.client.WebTarget |
targetRest(java.lang.String... paths)
Shortcut for
WebTarget creation for rest context path. |
public ClientSupport(io.dropwizard.testing.DropwizardTestSupport<?> support)
public org.glassfish.jersey.client.JerseyClient getClient()
public int getPort()
java.lang.NullPointerException - for guicey testpublic int getAdminPort()
java.lang.NullPointerException - for guicey testpublic java.lang.String basePathMain()
Returned path will always end with slash.
java.lang.NullPointerException - for guicey testpublic java.lang.String basePathAdmin()
Returned path will always end with slash.
java.lang.NullPointerException - for guicey testpublic java.lang.String basePathRest()
Returned path will always end with slash.
java.lang.NullPointerException - for guicey testpublic javax.ws.rs.client.WebTarget target(java.lang.String... paths)
WebTarget construction shortcut. First url part must contain host (port) target.
When multiple parameters provided, they are connected with "/", avoiding duplicate slash appearances
so, for example, "app, path", "app/, /path" or any other variation would always lead to correct "app/path").
Essentially this is the same as using WebTarget.path(String) multiple times (after initial target
creation).
Example: .target("http://localhotst:8080/smth/").request().buildGet().invoke()
NOTE: safe to use with guicey-only tests (when web part not started) to call any external url.
paths - one or more path parts (joined with '/')public javax.ws.rs.client.WebTarget targetMain(java.lang.String... paths)
WebTarget creation for main context path. Method abstracts you from actual configuration
so you can just call servlets by their registration uri.
Without parameters it will target main context root: .targetMain().request().buildGet().invoke() would
call "http://localhost:8080/".
Additional paths may be provided to construct urls:
.targetMain("something").request().buildGet().invoke() would call "http://localhost:8080/something"
and .targetMain("foo", "bar").request().buildGet().invoke() would call "http://localhost:8080/foo/bar".
Last example is equivalent to jersey api (kind of shortcut):
.targetMain().path("foo").path("bar").request().buildGet().invoke().
paths - zero, one or more path parts (joined with '/') and appended to base pathjava.lang.NullPointerException - for guicey testfor base use construction detailspublic javax.ws.rs.client.WebTarget targetAdmin(java.lang.String... paths)
WebTarget creation for admin context path. Method abstracts you from actual configuration
so you can just call servlets by their registration uri.
Without parameters it will target admin context root: .targetAdmin().request().buildGet().invoke() would
call "http://localhost:8081/". For simple server it would be "http://localhost:8080/admin/".
Additional paths may be provided to construct urls:
.targetAdmin("something").request().buildGet().invoke() would call "http://localhost:8081/something"
and .targetAdmin("foo", "bar").request().buildGet().invoke() would call "http://localhost:8081/foo/bar".
Last example is equivalent to jersey api (kind of shortcut):
.targetAdmin().path("foo").path("bar").request().buildGet().invoke().
paths - zero, one or more path parts (joined with '/') and appended to base pathjava.lang.NullPointerException - for guicey testfor base use construction detailspublic javax.ws.rs.client.WebTarget targetRest(java.lang.String... paths)
WebTarget creation for rest context path. Method abstracts you from actual configuration
so you can just call rest resources by their registration uri.
Without parameters it will target rest context root: .targetRest().request().buildGet().invoke() would
call "http://localhost:8080/".
Additional paths may be provided to construct urls:
.targetRest("something").request().buildGet().invoke() would call "http://localhost:8080/something"
and .targetRest("foo", "bar").request().buildGet().invoke() would call "http://localhost:8080/foo/bar".
Last example is equivalent to jersey api (kind of shortcut):
.targetRest().path("foo").path("bar").request().buildGet().invoke().
paths - zero, one or more path parts (joined with '/') and appended to base pathjava.lang.NullPointerException - for guicey testfor base use construction detailspublic void close()
throws java.lang.Exception
close in interface java.lang.AutoCloseablejava.lang.Exception