Class AppBasedTestingBase<R extends RequestContext<?>,W extends WebsocketContext<?>>
- All Implemented Interfaces:
BeforeAfterClassMethodsProvider
,CanBeDisabled
,RepeatedClassAfterMethodProvider
,TestFailureListener
- Direct Known Subclasses:
AppBasedDefaultContextTypesTestingBase
,AppBasedWebsocketTestingBase
,NoAppStartHttpServerCustomContextTypesTestingBase
-
Field Summary
Fields inherited from class org.spincast.testing.core.SpincastTestBase
logger, spincastConfig
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
Called after the tests of the class are ran.void
Called before the tests of the class are ran.protected abstract void
Starts the application.protected void
Removes all the cookies saved from a previous response.protected ConnectRequestBuilder
Starts an Https Client builder for a CONNECT method.protected ConnectRequestBuilder
Starts an Https Client builder for a CONNECT method.protected ConnectRequestBuilder
Starts an Http(s) Client builder for a CONNECT method.protected final com.google.inject.Injector
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
Starts an Https Client builder for a DELETE method.protected DeleteRequestBuilder
Starts an Https Client builder for a DELETE method.protected DeleteRequestBuilder
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
Starts an Https Client builder for a GET method.protected GetRequestBuilder
Starts an Https Client builder for a GET method.protected GetRequestBuilder
Starts an Http(s) Client builder for a GET method.protected abstract AppTestingConfigs
We force test classes to provide information about the required testing configurations.protected CookieFactory
protected Set<com.google.inject.Key<?>>
Extra exact bindings to remvoe before the plugins are applied.protected com.google.inject.Module
Can be overriden with something like :protected List<SpincastPlugin>
The extra required plugins.protected final com.google.inject.Module
If an overriding Module is to be added using the Guice tweaker.protected final List<SpincastPlugin>
The extra required plugins.protected HttpClient
protected Cookie
getPreviousResponseCookie
(String cookieName) TheCookie
s returned by the previousHttpResponse
.protected Server
protected final Class<? extends SpincastConfig>
The implementation to use for theSpincastConfig
binding, when running tests.protected HeadRequestBuilder
Starts an Https Client builder for a HEAD method.protected HeadRequestBuilder
Starts an Https Client builder for a HEAD method.protected HeadRequestBuilder
Starts an Http(s) Client builder for a HEAD method.protected final boolean
protected boolean
By default, for the tests, by disable the SSL certificate errors.protected boolean
protected boolean
Will setCookie.setSecure(boolean)
tofalse
on cookies added to thegetPreviousResponseCookies()
so their can be resend in tests file using HTTP (not HTTPS).protected OptionsRequestBuilder
Starts an Https Client builder for a OPTIONS method.protected OptionsRequestBuilder
Starts an Https Client builder for a OPTIONS method.protected OptionsRequestBuilder
Starts an Http(s) Client builder for a OPTIONS method.protected Date
Parse a date from a HTTP header to a Date object.protected PatchRequestBuilder
Starts an Https Client builder for a PATCH method.protected PatchRequestBuilder
Starts an Https Client builder for a PATCH method.protected PatchRequestBuilder
Starts an Http(s) Client builder for a PATCH method.protected PostRequestBuilder
Starts an Https Client builder for a POST method.protected PostRequestBuilder
Starts an Https Client builder for a POST method.protected PostRequestBuilder
Starts an Http(s) Client builder for a POST method.protected PutRequestBuilder
Starts an Https Client builder for a PUT method.protected PutRequestBuilder
Starts an Https Client builder for a PUT method.protected PutRequestBuilder
Starts an Http(s) Client builder for a PUT method.protected void
saveResponseCookies
(HttpResponse response) Saves the current response's cookies.protected void
protected TraceRequestBuilder
Starts an Https Client builder for a TRACE method.protected TraceRequestBuilder
Starts an Https Client builder for a TRACE method.protected TraceRequestBuilder
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
protected WebsocketRequestBuilder
protected WebsocketRequestBuilder
Methods inherited from class org.spincast.testing.core.SpincastTestBase
addExtraSystemProperties, afterClassLoops, afterTest, beforeClassException, beforeTest, createGuiceTweaker, createTestingDir, createTestingFilePath, createTestingFilePath, deleteTestingWritableTempDir, getExtraSystemProperties, getGuiceTweakerFromThreadLocal, getGuiceTweakerPluginsToDisable, getInjector, getSpincastConfig, getTestingWritableTempDir, isTestClassDisabledPostBeforeClass, isTestClassDisabledPreBeforeClass, resetSystemProperties, testFailure
-
Constructor Details
-
AppBasedTestingBase
public AppBasedTestingBase()
-
-
Method Details
-
beforeClass
public void beforeClass()Description copied from interface:BeforeAfterClassMethodsProvider
Called before the tests of the class are ran.- Specified by:
beforeClass
in interfaceBeforeAfterClassMethodsProvider
- Overrides:
beforeClass
in classSpincastTestBase
-
createInjector
protected final com.google.inject.Injector createInjector()Description copied from class:SpincastTestBase
The test class must implement this method to create the Guice injector. It can be done by starting a real application (with amain(...)
method) or by creating a custom Injector.- Specified by:
createInjector
in classSpincastTestBase
-
getTestingConfigImplementationClass
Description copied from class:SpincastTestBase
The implementation to use for theSpincastConfig
binding, when running tests.- Overrides:
getTestingConfigImplementationClass
in classSpincastTestBase
-
isDisableBindCurrentClass
protected final boolean isDisableBindCurrentClass()- Overrides:
isDisableBindCurrentClass
in classSpincastTestBase
-
getExtraExactBindingsToRemoveBeforePlugins
Description copied from class:SpincastTestBase
Extra exact bindings to remvoe before the plugins are applied.- Overrides:
getExtraExactBindingsToRemoveBeforePlugins
in classSpincastTestBase
-
getGuiceTweakerExtraOverridingModule
protected final com.google.inject.Module getGuiceTweakerExtraOverridingModule()Description copied from class:SpincastTestBase
If an overriding Module is to be added using the Guice tweaker.Can be overriden with something like :
return Modules.override(super.getGuiceTweakerExtraOverridingModule()).with(new SpincastGuiceModuleBase() { protected void configure() { // ... } });
- Overrides:
getGuiceTweakerExtraOverridingModule
in classSpincastTestBase
-
tweakConfigurations
Since an App is used, it will probably use it own AppConfig interface for the config. Often, this interface will extendsSpincastConfig
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 inSpincastConfigTestingDefault
.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!
- Overrides:
tweakConfigurations
in classSpincastTestBase
-
isIgnoreMethodsAnnotatedWithInjectDuringConfigurationsTweaking
protected boolean isIgnoreMethodsAnnotatedWithInjectDuringConfigurationsTweaking() -
getExtraOverridingModule
protected com.google.inject.Module getExtraOverridingModule()Can be overriden with something like :return Modules.override(super.getExtraOverridingModule()).with(new SpincastGuiceModuleBase() { protected void configure() { // ... } });
-
getGuiceTweakerExtraPlugins
The extra required plugins.- Overrides:
getGuiceTweakerExtraPlugins
in classSpincastTestBase
-
getExtraPlugins
The extra required plugins. Example:List<SpincastPlugin> extraPlugins = super.getExtraPlugins(); extraPlugins.add(new XXX()); return extraPlugins;
-
validateCreatedInjector
protected void validateCreatedInjector(com.google.inject.Injector guice) Description copied from class:SpincastTestBase
Validates the created Injector, before the dependencies are injected in the test class.- Overrides:
validateCreatedInjector
in classSpincastTestBase
-
afterClass
public void afterClass()Description copied from interface:BeforeAfterClassMethodsProvider
Called after the tests of the class are ran.This will only be called if the beforeClass() method completed successfully, so you can be sure that the instanciation of the class is complete here.
- Specified by:
afterClass
in interfaceBeforeAfterClassMethodsProvider
- Overrides:
afterClass
in classSpincastTestBase
-
stopServer
protected void stopServer() -
getHttpClient
-
getRouter
-
getCookieFactory
-
getServer
-
createTestUrl
Creates an URL to the started HTTPS server.- Parameters:
path
- the relative path to be appended to the base test URL.
-
createTestUrl
Creates an URL to the started HTTP(S) server.- Parameters:
path
- the relative path to be appended to the base test URL.isHttps
- iftrue
, "https:" will be used instead of "http:".
-
createTestUrl
Creates an URL to the started HTTP(S) server.- Parameters:
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
- iftrue
, "https:" will be used instead of "http:".
-
createTestUrl
-
websocket
-
websocket
-
websocket
-
GET
Starts an Https Client builder for a GET method. A cookie store is automatically added.- Parameters:
path
- the relative path to be appended to the base test URL.
-
GET
Starts an Https Client builder for a GET method. A cookie store is automatically added.- Parameters:
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.
-
GET
Starts an Http(s) Client builder for a GET method. A cookie store is automatically added.- Parameters:
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
- iftrue
, "https:" will be used instead of "http:".
-
isDisableSllCetificateErrors
protected boolean isDisableSllCetificateErrors()By default, for the tests, by disable the SSL certificate errors. -
POST
Starts an Https Client builder for a POST method. A cookie store is automatically added.- Parameters:
path
- the relative path to be appended to the base test URL.
-
POST
Starts an Https Client builder for a POST method. A cookie store is automatically added.- Parameters:
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.
-
POST
Starts an Http(s) Client builder for a POST method. A cookie store is automatically added.- Parameters:
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
- iftrue
, "https:" will be used instead of "http:".
-
PUT
Starts an Https Client builder for a PUT method. A cookie store is automatically added.- Parameters:
path
- the relative path to be appended to the base test URL.
-
PUT
Starts an Https Client builder for a PUT method. A cookie store is automatically added.- Parameters:
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.
-
PUT
Starts an Http(s) Client builder for a PUT method. A cookie store is automatically added.- Parameters:
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
- iftrue
, "https:" will be used instead of "http:".
-
DELETE
Starts an Https Client builder for a DELETE method. A cookie store is automatically added.- Parameters:
path
- the relative path to be appended to the base test URL.
-
DELETE
Starts an Https Client builder for a DELETE method. A cookie store is automatically added.- Parameters:
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.
-
DELETE
Starts an Http(s) Client builder for a DELETE method. A cookie store is automatically added.- Parameters:
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
- iftrue
, "https:" will be used instead of "http:".
-
OPTIONS
Starts an Https Client builder for a OPTIONS method. A cookie store is automatically added.- Parameters:
path
- the relative path to be appended to the base test URL.
-
OPTIONS
Starts an Https Client builder for a OPTIONS method. A cookie store is automatically added.- Parameters:
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.
-
OPTIONS
Starts an Http(s) Client builder for a OPTIONS method. A cookie store is automatically added.- Parameters:
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
- iftrue
, "https:" will be used instead of "http:".
-
TRACE
Starts an Https Client builder for a TRACE method. A cookie store is automatically added.- Parameters:
path
- the relative path to be appended to the base test URL.
-
TRACE
Starts an Https Client builder for a TRACE method. A cookie store is automatically added.- Parameters:
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.
-
TRACE
Starts an Http(s) Client builder for a TRACE method. A cookie store is automatically added.- Parameters:
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
- iftrue
, "https:" will be used instead of "http:".
-
CONNECT
Starts an Https Client builder for a CONNECT method. A cookie store is automatically added.- Parameters:
path
- the relative path to be appended to the base test URL.
-
CONNECT
Starts an Https Client builder for a CONNECT method. A cookie store is automatically added.- Parameters:
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.
-
CONNECT
Starts an Http(s) Client builder for a CONNECT method. A cookie store is automatically added.- Parameters:
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
- iftrue
, "https:" will be used instead of "http:".
-
PATCH
Starts an Https Client builder for a PATCH method. A cookie store is automatically added.- Parameters:
path
- the relative path to be appended to the base test URL.
-
PATCH
Starts an Https Client builder for a PATCH method. A cookie store is automatically added.- Parameters:
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.
-
PATCH
Starts an Http(s) Client builder for a PATCH method. A cookie store is automatically added.- Parameters:
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
- iftrue
, "https:" will be used instead of "http:".
-
HEAD
Starts an Https Client builder for a HEAD method. A cookie store is automatically added.- Parameters:
path
- the relative path to be appended to the base test URL.
-
HEAD
Starts an Https Client builder for a HEAD method. A cookie store is automatically added.- Parameters:
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.
-
HEAD
Starts an Http(s) Client builder for a HEAD method. A cookie store is automatically added.- Parameters:
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
- iftrue
, "https:" will be used instead of "http:".
-
formatDate
Format a date so it can be used in a HTTP header. -
parseDate
Parse a date from a HTTP header to a Date object. -
getPreviousResponseCookies
TheCookie
s returned by the previousHttpResponse
. 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! -
getPreviousResponseCookie
-
clearPreviousResponseCookies
protected void clearPreviousResponseCookies()Removes all the cookies saved from a previous response. -
saveResponseCookies
Saves the current response's cookies.You would then be able to resend them in a request by using
getPreviousResponseCookies()
. Example:GET("/").addCookies(getPreviousResponseCookies())...
-
isSetSecureFalseOnCookiesFromBag
protected boolean isSetSecureFalseOnCookiesFromBag()Will setCookie.setSecure(boolean)
tofalse
on cookies added to thegetPreviousResponseCookies()
so their can be resend in tests file using HTTP (not HTTPS). -
getAppTestingConfigs
We force test classes to provide information about the required testing configurations.The bindings for those components will be automatically created.
- Returns:
- the testing configs informations or
null
to disable this process (you will then have to add the required config bindings by yourself).
-
callAppMainMethod
protected abstract void callAppMainMethod()Starts the application.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!
-