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
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidCalled after the tests of the class are ran.voidCalled before the tests of the class are ran.protected abstract voidStarts the application.protected voidRemoves all the cookies saved from a previous response.protected ConnectRequestBuilderStarts an Https Client builder for a CONNECT method.protected ConnectRequestBuilderStarts an Https Client builder for a CONNECT method.protected ConnectRequestBuilderStarts an Http(s) Client builder for a CONNECT method.protected final com.google.inject.InjectorThe test class must implement this method to create the Guice injector.protected StringcreateTestUrl(String path) Creates an URL to the started HTTPS server.protected StringcreateTestUrl(String path, boolean isHttps) Creates an URL to the started HTTP(S) server.protected StringcreateTestUrl(String pathOrUrl, boolean isFullUrl, boolean isHttps) Creates an URL to the started HTTP(S) server.protected StringcreateTestUrl(String host, String path, boolean isHttps) protected DeleteRequestBuilderStarts an Https Client builder for a DELETE method.protected DeleteRequestBuilderStarts an Https Client builder for a DELETE method.protected DeleteRequestBuilderStarts an Http(s) Client builder for a DELETE method.protected StringformatDate(Date date) Format a date so it can be used in a HTTP header.protected GetRequestBuilderStarts an Https Client builder for a GET method.protected GetRequestBuilderStarts an Https Client builder for a GET method.protected GetRequestBuilderStarts an Http(s) Client builder for a GET method.protected abstract AppTestingConfigsWe force test classes to provide information about the required testing configurations.protected CookieFactoryprotected Set<com.google.inject.Key<?>>Extra exact bindings to remvoe before the plugins are applied.protected com.google.inject.ModuleCan be overriden with something like :protected List<SpincastPlugin>The extra required plugins.protected final com.google.inject.ModuleIf an overriding Module is to be added using the Guice tweaker.protected final List<SpincastPlugin>The extra required plugins.protected HttpClientprotected CookiegetPreviousResponseCookie(String cookieName) TheCookies returned by the previousHttpResponse.protected Serverprotected final Class<? extends SpincastConfig>The implementation to use for theSpincastConfigbinding, when running tests.protected HeadRequestBuilderStarts an Https Client builder for a HEAD method.protected HeadRequestBuilderStarts an Https Client builder for a HEAD method.protected HeadRequestBuilderStarts an Http(s) Client builder for a HEAD method.protected final booleanprotected booleanBy default, for the tests, by disable the SSL certificate errors.protected booleanprotected booleanWill setCookie.setSecure(boolean)tofalseon cookies added to thegetPreviousResponseCookies()so their can be resend in tests file using HTTP (not HTTPS).protected OptionsRequestBuilderStarts an Https Client builder for a OPTIONS method.protected OptionsRequestBuilderStarts an Https Client builder for a OPTIONS method.protected OptionsRequestBuilderStarts an Http(s) Client builder for a OPTIONS method.protected DateParse a date from a HTTP header to a Date object.protected PatchRequestBuilderStarts an Https Client builder for a PATCH method.protected PatchRequestBuilderStarts an Https Client builder for a PATCH method.protected PatchRequestBuilderStarts an Http(s) Client builder for a PATCH method.protected PostRequestBuilderStarts an Https Client builder for a POST method.protected PostRequestBuilderStarts an Https Client builder for a POST method.protected PostRequestBuilderStarts an Http(s) Client builder for a POST method.protected PutRequestBuilderStarts an Https Client builder for a PUT method.protected PutRequestBuilderStarts an Https Client builder for a PUT method.protected PutRequestBuilderStarts an Http(s) Client builder for a PUT method.protected voidsaveResponseCookies(HttpResponse response) Saves the current response's cookies.protected voidprotected TraceRequestBuilderStarts an Https Client builder for a TRACE method.protected TraceRequestBuilderStarts an Https Client builder for a TRACE method.protected TraceRequestBuilderStarts an Http(s) Client builder for a TRACE method.protected voidtweakConfigurations(GuiceTweaker guiceTweaker) Since an App is used, it will probably use it own AppConfig interface for the config.protected voidvalidateCreatedInjector(com.google.inject.Injector guice) Validates the created Injector, before the dependencies are injected in the test class.protected WebsocketRequestBuilderprotected WebsocketRequestBuilderprotected WebsocketRequestBuilderMethods 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:BeforeAfterClassMethodsProviderCalled before the tests of the class are ran.- Specified by:
beforeClassin interfaceBeforeAfterClassMethodsProvider- Overrides:
beforeClassin classSpincastTestBase
-
createInjector
protected final com.google.inject.Injector createInjector()Description copied from class:SpincastTestBaseThe 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:
createInjectorin classSpincastTestBase
-
getTestingConfigImplementationClass
Description copied from class:SpincastTestBaseThe implementation to use for theSpincastConfigbinding, when running tests.- Overrides:
getTestingConfigImplementationClassin classSpincastTestBase
-
isDisableBindCurrentClass
protected final boolean isDisableBindCurrentClass()- Overrides:
isDisableBindCurrentClassin classSpincastTestBase
-
getExtraExactBindingsToRemoveBeforePlugins
Description copied from class:SpincastTestBaseExtra exact bindings to remvoe before the plugins are applied.- Overrides:
getExtraExactBindingsToRemoveBeforePluginsin classSpincastTestBase
-
getGuiceTweakerExtraOverridingModule
protected final com.google.inject.Module getGuiceTweakerExtraOverridingModule()Description copied from class:SpincastTestBaseIf 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:
getGuiceTweakerExtraOverridingModulein classSpincastTestBase
-
tweakConfigurations
Since an App is used, it will probably use it own AppConfig interface for the config. Often, this interface will extendsSpincastConfigso 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:
tweakConfigurationsin 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:
getGuiceTweakerExtraPluginsin 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:SpincastTestBaseValidates the created Injector, before the dependencies are injected in the test class.- Overrides:
validateCreatedInjectorin classSpincastTestBase
-
afterClass
public void afterClass()Description copied from interface:BeforeAfterClassMethodsProviderCalled 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:
afterClassin interfaceBeforeAfterClassMethodsProvider- Overrides:
afterClassin 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
TheCookies 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)tofalseon 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
nullto 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
Serverhere, since the target application is supposed to do it by itself, in general in an "@Inject init()" method!
-