All Downloads are FREE. Search and download functionalities are using the official Maven repository.

public.javadoc.org.spincast.testing.core.AppBasedTestingBase.html Maven / Gradle / Ivy

There is a newer version: 2.2.0
Show newest version






AppBasedTestingBase (org.spincast:spincast-framework 1.0.0 API)












org.spincast.testing.core

Class AppBasedTestingBase<R extends RequestContext<?>,W extends WebsocketContext<?>>

    • Constructor Detail

      • AppBasedTestingBase

        public AppBasedTestingBase()
    • Method Detail

      • 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 a main(...) method) or by creating a custom Injector.
        Specified by:
        createInjector in class SpincastTestBase
      • 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 class SpincastTestBase
      • tweakConfigurations

        protected void tweakConfigurations(GuiceTweaker guiceTweaker)
        Since an App is used, it will probably use it own AppConfig interface for the config. Often, this interface will extends 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!

        Overrides:
        tweakConfigurations in class SpincastTestBase
      • 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() {
                 // ...
             }
         });
         
      • getExtraPlugins

        protected List<SpincastPlugin> 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 class SpincastTestBase
      • stopServer

        protected void stopServer()
      • getHttpClient

        protected HttpClient getHttpClient()
      • getRouter

        protected Router<R,W> getRouter()
      • getServer

        protected Server getServer()
      • createTestUrl

        protected String createTestUrl(String path)
        Creates an URL to the started HTTPS server.
        Parameters:
        path - the relative path to be appended to the base test URL.
      • createTestUrl

        protected String createTestUrl(String path,
                                       boolean isHttps)
        Creates an URL to the started HTTP(S) server.
        Parameters:
        path - the relative path to be appended to the base test URL.
        isHttps - if true, "https:" will be used instead of "http:".
      • createTestUrl

        protected String createTestUrl(String pathOrUrl,
                                       boolean isFullUrl,
                                       boolean isHttps)
        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 - if true, "https:" will be used instead of "http:".
      • createTestUrl

        protected String createTestUrl(String host,
                                       String path,
                                       boolean isHttps)
      • GET

        protected GetRequestBuilder GET(String path)
        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

        protected GetRequestBuilder GET(String pathOrUrl,
                                        boolean isFullUrl)
        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

        protected GetRequestBuilder GET(String pathOrUrl,
                                        boolean isFullUrl,
                                        boolean isHttps)
        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 - if true, "https:" will be used instead of "http:".
      • isDisableSllCetificateErrors

        protected boolean isDisableSllCetificateErrors()
        By default, for the tests, by disable the SSL certificate errors.
      • POST

        protected PostRequestBuilder POST(String path)
        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

        protected PostRequestBuilder POST(String pathOrUrl,
                                          boolean isFullUrl)
        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

        protected PostRequestBuilder POST(String pathOrUrl,
                                          boolean isFullUrl,
                                          boolean isHttps)
        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 - if true, "https:" will be used instead of "http:".
      • PUT

        protected PutRequestBuilder PUT(String path)
        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

        protected PutRequestBuilder PUT(String pathOrUrl,
                                        boolean isFullUrl)
        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

        protected PutRequestBuilder PUT(String pathOrUrl,
                                        boolean isFullUrl,
                                        boolean isHttps)
        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 - if true, "https:" will be used instead of "http:".
      • DELETE

        protected DeleteRequestBuilder DELETE(String path)
        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

        protected DeleteRequestBuilder DELETE(String pathOrUrl,
                                              boolean isFullUrl)
        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

        protected DeleteRequestBuilder DELETE(String pathOrUrl,
                                              boolean isFullUrl,
                                              boolean isHttps)
        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 - if true, "https:" will be used instead of "http:".
      • OPTIONS

        protected OptionsRequestBuilder OPTIONS(String path)
        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

        protected OptionsRequestBuilder OPTIONS(String pathOrUrl,
                                                boolean isFullUrl)
        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

        protected OptionsRequestBuilder OPTIONS(String pathOrUrl,
                                                boolean isFullUrl,
                                                boolean isHttps)
        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 - if true, "https:" will be used instead of "http:".
      • TRACE

        protected TraceRequestBuilder TRACE(String path)
        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

        protected TraceRequestBuilder TRACE(String pathOrUrl,
                                            boolean isFullUrl)
        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

        protected TraceRequestBuilder TRACE(String pathOrUrl,
                                            boolean isFullUrl,
                                            boolean isHttps)
        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 - if true, "https:" will be used instead of "http:".
      • CONNECT

        protected ConnectRequestBuilder CONNECT(String path)
        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

        protected ConnectRequestBuilder CONNECT(String pathOrUrl,
                                                boolean isFullUrl)
        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

        protected ConnectRequestBuilder CONNECT(String pathOrUrl,
                                                boolean isFullUrl,
                                                boolean isHttps)
        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 - if true, "https:" will be used instead of "http:".
      • PATCH

        protected PatchRequestBuilder PATCH(String path)
        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

        protected PatchRequestBuilder PATCH(String pathOrUrl,
                                            boolean isFullUrl)
        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

        protected PatchRequestBuilder PATCH(String pathOrUrl,
                                            boolean isFullUrl,
                                            boolean isHttps)
        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 - if true, "https:" will be used instead of "http:".
      • HEAD

        protected HeadRequestBuilder HEAD(String path)
        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

        protected HeadRequestBuilder HEAD(String pathOrUrl,
                                          boolean isFullUrl)
        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

        protected HeadRequestBuilder HEAD(String pathOrUrl,
                                          boolean isFullUrl,
                                          boolean isHttps)
        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 - if true, "https:" will be used instead of "http:".
      • formatDate

        protected String formatDate(Date date)
        Format a date so it can be used in a HTTP header.
      • parseDate

        protected Date parseDate(String dateHeaderValue)
        Parse a date from a HTTP header to a Date object.
      • getPreviousResponseCookies

        protected Set<Cookie> getPreviousResponseCookies()
        The 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!

      • getPreviousResponseCookie

        protected Cookie getPreviousResponseCookie(String cookieName)
      • clearPreviousResponseCookies

        protected void clearPreviousResponseCookies()
        Removes all the cookies saved from a previous response.
      • saveResponseCookies

        protected void saveResponseCookies(HttpResponse response)
        Saves the current response's cookies.

        You would then be able to resend them in a request by using getPreviousResponseCookies(). Example:

         GET("/").addCookies(getPreviousResponseCookies())...
         
      • getAppTestingConfigs

        protected abstract AppTestingConfigs 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!

Copyright © 2019. All rights reserved.





© 2015 - 2024 Weber Informatics LLC | Privacy Policy