public abstract class AppBasedTestingBase<R extends RequestContext<?>,W extends WebsocketContext<?>> extends SpincastTestBase
logger, spincastConfig| Constructor and Description |
|---|
AppBasedTestingBase() |
| Modifier and Type | Method and Description |
|---|---|
void |
afterClass()
Called after the tests of the class are ran.
|
void |
beforeClass()
Called before the tests of the class are ran.
|
protected abstract void |
callAppMainMethod()
Starts the application.
|
protected void |
clearPreviousResponseCookies()
Removes all the cookies saved from a previous
response.
|
protected ConnectRequestBuilder |
CONNECT(String path)
Starts an Https Client builder for a CONNECT method.
|
protected ConnectRequestBuilder |
CONNECT(String pathOrUrl,
boolean isFullUrl)
Starts an Https Client builder for a CONNECT method.
|
protected ConnectRequestBuilder |
CONNECT(String pathOrUrl,
boolean isFullUrl,
boolean isHttps)
Starts an Http(s) Client builder for a CONNECT method.
|
protected com.google.inject.Injector |
createInjector()
The test class must implement this method to create
the Guice injector.
|
protected String |
createTestUrl(String path)
Creates an URL to the started HTTPS server.
|
protected String |
createTestUrl(String path,
boolean isHttps)
Creates an URL to the started HTTP(S) server.
|
protected String |
createTestUrl(String pathOrUrl,
boolean isFullUrl,
boolean isHttps)
Creates an URL to the started HTTP(S) server.
|
protected String |
createTestUrl(String host,
String path,
boolean isHttps) |
protected DeleteRequestBuilder |
DELETE(String path)
Starts an Https Client builder for a DELETE method.
|
protected DeleteRequestBuilder |
DELETE(String pathOrUrl,
boolean isFullUrl)
Starts an Https Client builder for a DELETE method.
|
protected DeleteRequestBuilder |
DELETE(String pathOrUrl,
boolean isFullUrl,
boolean isHttps)
Starts an Http(s) Client builder for a DELETE method.
|
protected String |
formatDate(Date date)
Format a date so it can be used in a HTTP header.
|
protected GetRequestBuilder |
GET(String path)
Starts an Https Client builder for a GET method.
|
protected GetRequestBuilder |
GET(String pathOrUrl,
boolean isFullUrl)
Starts an Https Client builder for a GET method.
|
protected GetRequestBuilder |
GET(String pathOrUrl,
boolean isFullUrl,
boolean isHttps)
Starts an Http(s) Client builder for a GET method.
|
protected abstract AppTestingConfigs |
getAppTestingConfigs()
We force test classes to provide information about
the required testing configurations.
|
protected CookieFactory |
getCookieFactory() |
protected Set<com.google.inject.Key<?>> |
getExtraExactBindingsToRemoveBeforePlugins()
Extra exact bindings to remvoe before the
plugins are applied.
|
protected com.google.inject.Module |
getExtraOverridingModule()
Can be overriden with something like :
|
protected List<SpincastPlugin> |
getExtraPlugins()
The extra required plugins.
|
protected com.google.inject.Module |
getGuiceTweakerExtraOverridingModule()
If an overriding Module is to be added using the
Guice tweaker.
|
protected List<SpincastPlugin> |
getGuiceTweakerExtraPlugins()
The extra required plugins.
|
protected HttpClient |
getHttpClient() |
protected Cookie |
getPreviousResponseCookie(String cookieName) |
protected Set<Cookie> |
getPreviousResponseCookies()
The
Cookies returned by the previous
HttpResponse. |
protected Router<R,W> |
getRouter() |
protected Server |
getServer() |
protected Class<? extends SpincastConfig> |
getTestingConfigImplementationClass()
The implementation to use for the
SpincastConfig binding,
when running tests. |
protected HeadRequestBuilder |
HEAD(String path)
Starts an Https Client builder for a HEAD method.
|
protected HeadRequestBuilder |
HEAD(String pathOrUrl,
boolean isFullUrl)
Starts an Https Client builder for a HEAD method.
|
protected HeadRequestBuilder |
HEAD(String pathOrUrl,
boolean isFullUrl,
boolean isHttps)
Starts an Http(s) Client builder for a HEAD method.
|
protected boolean |
isDisableBindCurrentClass() |
protected boolean |
isDisableSllCetificateErrors()
By default, for the tests, by disable the
SSL certificate errors.
|
protected boolean |
isIgnoreMethodsAnnotatedWithInjectDuringConfigurationsTweaking() |
protected boolean |
isSetSecureFalseOnCookiesFromBag()
Will set
Cookie.setSecure(boolean) to
false on cookies added to the
getPreviousResponseCookies() so their can be resend
in tests file using HTTP (not HTTPS). |
protected OptionsRequestBuilder |
OPTIONS(String path)
Starts an Https Client builder for a OPTIONS method.
|
protected OptionsRequestBuilder |
OPTIONS(String pathOrUrl,
boolean isFullUrl)
Starts an Https Client builder for a OPTIONS method.
|
protected OptionsRequestBuilder |
OPTIONS(String pathOrUrl,
boolean isFullUrl,
boolean isHttps)
Starts an Http(s) Client builder for a OPTIONS method.
|
protected Date |
parseDate(String dateHeaderValue)
Parse a date from a HTTP header to a Date object.
|
protected PatchRequestBuilder |
PATCH(String path)
Starts an Https Client builder for a PATCH method.
|
protected PatchRequestBuilder |
PATCH(String pathOrUrl,
boolean isFullUrl)
Starts an Https Client builder for a PATCH method.
|
protected PatchRequestBuilder |
PATCH(String pathOrUrl,
boolean isFullUrl,
boolean isHttps)
Starts an Http(s) Client builder for a PATCH method.
|
protected PostRequestBuilder |
POST(String path)
Starts an Https Client builder for a POST method.
|
protected PostRequestBuilder |
POST(String pathOrUrl,
boolean isFullUrl)
Starts an Https Client builder for a POST method.
|
protected PostRequestBuilder |
POST(String pathOrUrl,
boolean isFullUrl,
boolean isHttps)
Starts an Http(s) Client builder for a POST method.
|
protected PutRequestBuilder |
PUT(String path)
Starts an Https Client builder for a PUT method.
|
protected PutRequestBuilder |
PUT(String pathOrUrl,
boolean isFullUrl)
Starts an Https Client builder for a PUT method.
|
protected PutRequestBuilder |
PUT(String pathOrUrl,
boolean isFullUrl,
boolean isHttps)
Starts an Http(s) Client builder for a PUT method.
|
protected void |
saveResponseCookies(HttpResponse response)
Saves the current response's cookies.
|
protected void |
stopServer() |
protected TraceRequestBuilder |
TRACE(String path)
Starts an Https Client builder for a TRACE method.
|
protected TraceRequestBuilder |
TRACE(String pathOrUrl,
boolean isFullUrl)
Starts an Https Client builder for a TRACE method.
|
protected TraceRequestBuilder |
TRACE(String pathOrUrl,
boolean isFullUrl,
boolean isHttps)
Starts an Http(s) Client builder for a TRACE method.
|
protected void |
tweakConfigurations(GuiceTweaker guiceTweaker)
Since an App is used, it will probably use it own
AppConfig interface for the config.
|
protected void |
validateCreatedInjector(com.google.inject.Injector guice)
Validates the created Injector, before the
dependencies are injected in the test class.
|
protected WebsocketRequestBuilder |
websocket(String path) |
protected WebsocketRequestBuilder |
websocket(String pathOrUrl,
boolean isFullUrl) |
protected WebsocketRequestBuilder |
websocket(String pathOrUrl,
boolean isFullUrl,
boolean isHttps) |
addExtraSystemProperties, afterClassLoops, afterTest, beforeClassException, beforeTest, createGuiceTweaker, createTestingDir, createTestingFilePath, createTestingFilePath, deleteTestingWritableTempDir, getExtraSystemProperties, getGuiceTweakerFromThreadLocal, getInjector, getSpincastConfig, getTestingWritableTempDir, resetSystemProperties, testFailurepublic void beforeClass()
BeforeAfterClassMethodsProviderbeforeClass in interface BeforeAfterClassMethodsProviderbeforeClass in class SpincastTestBaseprotected final com.google.inject.Injector createInjector()
SpincastTestBasemain(...) method) or by
creating a custom Injector.createInjector in class SpincastTestBaseprotected final Class<? extends SpincastConfig> getTestingConfigImplementationClass()
SpincastTestBaseSpincastConfig binding,
when running tests.getTestingConfigImplementationClass in class SpincastTestBaseprotected final boolean isDisableBindCurrentClass()
isDisableBindCurrentClass in class SpincastTestBaseprotected Set<com.google.inject.Key<?>> getExtraExactBindingsToRemoveBeforePlugins()
SpincastTestBasegetExtraExactBindingsToRemoveBeforePlugins in class SpincastTestBaseprotected final com.google.inject.Module getGuiceTweakerExtraOverridingModule()
SpincastTestBaseCan be overriden with something like :
return Modules.override(super.getGuiceTweakerExtraOverridingModule()).with(new SpincastGuiceModuleBase() {
protected void configure() {
// ...
}
});
getGuiceTweakerExtraOverridingModule in class SpincastTestBaseprotected void tweakConfigurations(GuiceTweaker guiceTweaker)
SpincastConfig so all configs are available from
the same instance: those for the application and the default
ones required by Spincast.
But, during tests, we also want to easily reuse the testing configs values defined
in SpincastConfigTestingDefault (for example for a free port
to be used to start the HTTPS server)... Without having to extends
AppConfig and add a binding that redefine all those testing values available in
SpincastConfigTestingDefault.
But that means that two bound interfaces must use those testing configs, AppConfig and SpincastConfig. To be able to defined testing configs *once*, we add an AOP interceptor: all methods on AppConfig inherited from SpincastConfig (such as "getHttpsServerPort()") will be intercepted and the ones from the testing impl bound to SpincastConfig will be used instead!
tweakConfigurations in class SpincastTestBaseprotected boolean isIgnoreMethodsAnnotatedWithInjectDuringConfigurationsTweaking()
protected com.google.inject.Module getExtraOverridingModule()
return Modules.override(super.getExtraOverridingModule()).with(new SpincastGuiceModuleBase() {
protected void configure() {
// ...
}
});
protected final List<SpincastPlugin> getGuiceTweakerExtraPlugins()
getGuiceTweakerExtraPlugins in class SpincastTestBaseprotected List<SpincastPlugin> getExtraPlugins()
List<SpincastPlugin> extraPlugins = super.getExtraPlugins(); extraPlugins.add(new XXX()); return extraPlugins;
protected void validateCreatedInjector(com.google.inject.Injector guice)
SpincastTestBasevalidateCreatedInjector in class SpincastTestBasepublic void afterClass()
BeforeAfterClassMethodsProviderThis will only be called if the beforeClass() method completed successfully, so you can be sure that the instanciation of the class is complete here.
afterClass in interface BeforeAfterClassMethodsProviderafterClass in class SpincastTestBaseprotected void stopServer()
protected HttpClient getHttpClient()
protected CookieFactory getCookieFactory()
protected Server getServer()
protected String createTestUrl(String path)
path - the relative path to be appended to the
base test URL.protected String createTestUrl(String path, boolean isHttps)
path - the relative path to be appended to the
base test URL.isHttps - if true, "https:" will be used
instead of "http:".protected String createTestUrl(String pathOrUrl, boolean isFullUrl, boolean isHttps)
pathOrUrl - a relative path OR a full URL.isFullUrl - if the 'pathOrUrl' parameter a full URL? If
so, it will be used as is. Otherwise it will be appended to the
base test URL.isHttps - if true, "https:" will be used
instead of "http:".protected WebsocketRequestBuilder websocket(String path)
protected WebsocketRequestBuilder websocket(String pathOrUrl, boolean isFullUrl)
protected WebsocketRequestBuilder websocket(String pathOrUrl, boolean isFullUrl, boolean isHttps)
protected GetRequestBuilder GET(String path)
path - the relative path to be appended to the
base test URL.protected GetRequestBuilder GET(String pathOrUrl, boolean isFullUrl)
pathOrUrl - a relative path or a full URL.isFullUrl - if the 'pathOrUrl' parameter a full URL? If
so, it will be used as is. Otherwise it will be appended to the
base test URL.protected GetRequestBuilder GET(String pathOrUrl, boolean isFullUrl, boolean isHttps)
pathOrUrl - a relative path or a full URL.isFullUrl - if the 'pathOrUrl' parameter a full URL? If
so, it will be used as is. Otherwise it will be appended to the
base test URL.isHttps - if true, "https:" will be used
instead of "http:".protected boolean isDisableSllCetificateErrors()
protected PostRequestBuilder POST(String path)
path - the relative path to be appended to the
base test URL.protected PostRequestBuilder POST(String pathOrUrl, boolean isFullUrl)
pathOrUrl - a relative path or a full URL.isFullUrl - if the 'pathOrUrl' parameter a full URL? If
so, it will be used as is. Otherwise it will be appended to the
base test URL.protected PostRequestBuilder POST(String pathOrUrl, boolean isFullUrl, boolean isHttps)
pathOrUrl - a relative path or a full URL.isFullUrl - if the 'pathOrUrl' parameter a full URL? If
so, it will be used as is. Otherwise it will be appended to the
base test URL.isHttps - if true, "https:" will be used
instead of "http:".protected PutRequestBuilder PUT(String path)
path - the relative path to be appended to the
base test URL.protected PutRequestBuilder PUT(String pathOrUrl, boolean isFullUrl)
pathOrUrl - a relative path or a full URL.isFullUrl - if the 'pathOrUrl' parameter a full URL? If
so, it will be used as is. Otherwise it will be appended to the
base test URL.protected PutRequestBuilder PUT(String pathOrUrl, boolean isFullUrl, boolean isHttps)
pathOrUrl - a relative path or a full URL.isFullUrl - if the 'pathOrUrl' parameter a full URL? If
so, it will be used as is. Otherwise it will be appended to the
base test URL.isHttps - if true, "https:" will be used
instead of "http:".protected DeleteRequestBuilder DELETE(String path)
path - the relative path to be appended to the
base test URL.protected DeleteRequestBuilder DELETE(String pathOrUrl, boolean isFullUrl)
pathOrUrl - a relative path or a full URL.isFullUrl - if the 'pathOrUrl' parameter a full URL? If
so, it will be used as is. Otherwise it will be appended to the
base test URL.protected DeleteRequestBuilder DELETE(String pathOrUrl, boolean isFullUrl, boolean isHttps)
pathOrUrl - a relative path or a full URL.isFullUrl - if the 'pathOrUrl' parameter a full URL? If
so, it will be used as is. Otherwise it will be appended to the
base test URL.isHttps - if true, "https:" will be used
instead of "http:".protected OptionsRequestBuilder OPTIONS(String path)
path - the relative path to be appended to the
base test URL.protected OptionsRequestBuilder OPTIONS(String pathOrUrl, boolean isFullUrl)
pathOrUrl - a relative path or a full URL.isFullUrl - if the 'pathOrUrl' parameter a full URL? If
so, it will be used as is. Otherwise it will be appended to the
base test URL.protected OptionsRequestBuilder OPTIONS(String pathOrUrl, boolean isFullUrl, boolean isHttps)
pathOrUrl - a relative path or a full URL.isFullUrl - if the 'pathOrUrl' parameter a full URL? If
so, it will be used as is. Otherwise it will be appended to the
base test URL.isHttps - if true, "https:" will be used
instead of "http:".protected TraceRequestBuilder TRACE(String path)
path - the relative path to be appended to the
base test URL.protected TraceRequestBuilder TRACE(String pathOrUrl, boolean isFullUrl)
pathOrUrl - a relative path or a full URL.isFullUrl - if the 'pathOrUrl' parameter a full URL? If
so, it will be used as is. Otherwise it will be appended to the
base test URL.protected TraceRequestBuilder TRACE(String pathOrUrl, boolean isFullUrl, boolean isHttps)
pathOrUrl - a relative path or a full URL.isFullUrl - if the 'pathOrUrl' parameter a full URL? If
so, it will be used as is. Otherwise it will be appended to the
base test URL.isHttps - if true, "https:" will be used
instead of "http:".protected ConnectRequestBuilder CONNECT(String path)
path - the relative path to be appended to the
base test URL.protected ConnectRequestBuilder CONNECT(String pathOrUrl, boolean isFullUrl)
pathOrUrl - a relative path or a full URL.isFullUrl - if the 'pathOrUrl' parameter a full URL? If
so, it will be used as is. Otherwise it will be appended to the
base test URL.protected ConnectRequestBuilder CONNECT(String pathOrUrl, boolean isFullUrl, boolean isHttps)
pathOrUrl - a relative path or a full URL.isFullUrl - if the 'pathOrUrl' parameter a full URL? If
so, it will be used as is. Otherwise it will be appended to the
base test URL.isHttps - if true, "https:" will be used
instead of "http:".protected PatchRequestBuilder PATCH(String path)
path - the relative path to be appended to the
base test URL.protected PatchRequestBuilder PATCH(String pathOrUrl, boolean isFullUrl)
pathOrUrl - a relative path or a full URL.isFullUrl - if the 'pathOrUrl' parameter a full URL? If
so, it will be used as is. Otherwise it will be appended to the
base test URL.protected PatchRequestBuilder PATCH(String pathOrUrl, boolean isFullUrl, boolean isHttps)
pathOrUrl - a relative path or a full URL.isFullUrl - if the 'pathOrUrl' parameter a full URL? If
so, it will be used as is. Otherwise it will be appended to the
base test URL.isHttps - if true, "https:" will be used
instead of "http:".protected HeadRequestBuilder HEAD(String path)
path - the relative path to be appended to the
base test URL.protected HeadRequestBuilder HEAD(String pathOrUrl, boolean isFullUrl)
pathOrUrl - a relative path or a full URL.isFullUrl - if the 'pathOrUrl' parameter a full URL? If
so, it will be used as is. Otherwise it will be appended to the
base test URL.protected HeadRequestBuilder HEAD(String pathOrUrl, boolean isFullUrl, boolean isHttps)
pathOrUrl - a relative path or a full URL.isFullUrl - if the 'pathOrUrl' parameter a full URL? If
so, it will be used as is. Otherwise it will be appended to the
base test URL.isHttps - if true, "https:" will be used
instead of "http:".protected Date parseDate(String dateHeaderValue)
protected Set<Cookie> getPreviousResponseCookies()
Cookies returned by the previous
HttpResponse. This allows you to simulate
a real browser which would automatically resend
cookies on a particular domain. Example:
GET("/").addCookies(getPreviousResponseCookies())...
Note that for this to work, you have to manually
save the cookies using saveResponseCookies(HttpResponse)
when a response is received!
protected void clearPreviousResponseCookies()
protected void saveResponseCookies(HttpResponse response)
You would then be able to resend them in a
request by using getPreviousResponseCookies().
Example:
GET("/").addCookies(getPreviousResponseCookies())...
protected boolean isSetSecureFalseOnCookiesFromBag()
Cookie.setSecure(boolean) to
false on cookies added to the
getPreviousResponseCookies() so their can be resend
in tests file using HTTP (not HTTPS).protected abstract AppTestingConfigs getAppTestingConfigs()
The bindings for those components will be automatically created.
null
to disable this process (you will then have to add the
required config bindings by yourself).protected abstract void callAppMainMethod()
In this method, you should call your
application main() method.
There is no need to start the
Server here, since the target
application is supposed to do it by itself,
in general in an "@Inject init()"
method!
Copyright © 2019. All rights reserved.