coldbox.system.testing

Class BaseTestCase

lucee.Component
    extended by testbox.system.BaseSpec
      extended by testbox.system.compat.framework.TestCase
        extended by coldbox.system.testing.BaseTestCase
Direct Known Subclasses:
BaseHandlerTest , BaseInterceptorTest , BaseModelTest

Copyright Since 2005 ColdBox Framework by Luis Majano and Ortus Solutions, Corp www.ortussolutions.com --- Base testing component to intergrate TestBox with ColdBox

Class Attributes:
  • synchronized : false
  •  
  • accessors : true
  •  
  • persistent : false
  •  
    Property Summary
    type property default serializable required
    any appMapping
          The application mapping this test links to.

    • access = public
    • returntype = any
    true false
    any coldboxAppKey
          The application key for the ColdBox applicatin this test links to.

    • access = public
    • returntype = any
    true false
    any configMapping
          The configuration location this test links to.

    • access = public
    • returntype = any
    true false
    any controller
          The ColdBox controller this test links to.

    • access = public
    • returntype = any
    true false
    Method Summary
    any afterAll()
         BDD: The main teardown for ColdBox enabled applications after all tests execute.
    any afterTests()
         xUnit: The main teardown for ColdBox enabled applications after all tests execute.
    any announce(any state, [struct data='[runtime expression]'], [boolean async='false'], [boolean asyncAll='false'], [boolean asyncAllJoin='true'], [any asyncPriority='NORMAL'], [numeric asyncJoinTimeout='0'])
         Announce an interception.
    any announceInterception(any state, [struct interceptData='[runtime expression]'], [boolean async='false'], [boolean asyncAll='false'], [boolean asyncAllJoin='true'], [any asyncPriority='NORMAL'], [numeric asyncJoinTimeout='0'])
    any beforeAll()
         BDD: The main setup method for running ColdBox Integration enabled tests.
    any beforeTests()
         The main setup method for running ColdBox Integration enabled tests.
    any delete([string route=''], [struct params='[runtime expression]'], [struct headers='[runtime expression]'], [boolean renderResults='true'], [boolean withExceptionHandling='false'])
         Shortcut method to making a DELETE request through the framework.
    any execute([string event=''], [string route=''], [string queryString=''], [boolean private='false'], [boolean prePostExempt='false'], [struct eventArguments='[runtime expression]'], [boolean renderResults='false'], [boolean withExceptionHandling='false'])
         Executes a framework lifecycle by executing an event.
    private struct explodeRoute(string route)
         Separate a route into two parts: the base route, and a query string collection.
    any get([string route=''], [struct params='[runtime expression]'], [struct headers='[runtime expression]'], [boolean renderResults='true'], [boolean withExceptionHandling='false'])
         Shortcut method to making a GET request through the framework.
    string getAppMapping()
    any getCache(any cacheName='default')
         Get the CacheBox reference from the running application.
    any getCacheBox()
         Get the CacheBox reference from the running application.
    string getColdboxAppKey()
    string getConfigMapping()
    string getController()
    any getFlashScope()
         Get the RequestContext reference from the running application.
    any getHandlerResults()
         Get the results from a handler execution if any.
    any getInstance([any name], [struct initArguments='[runtime expression]'], [any dsl])
         Get a instance object from WireBox.
    any getInterceptor(any interceptorName)
         Get an interceptor reference.
    any getLogBox()
         Get the LogBox reference from the running application.
    any getMockController()
         I will return a mock controller object.
    any getMockModel(any name, [boolean clearMethods='false'])
         ColdBox must be loaded for this to work.
    any getMockRequestContext([boolean clearMethods='false'], [any decorator])
         Builds an empty functioning request context mocked with methods via MockBox.
    any getModel()
    any getNativeStatusCode()
         Get the status code set in the CFML engine.
    private any getPageContextResponse()
         Helper method to deal with ACF2016's overload of the page context response, come on Adobe, get your act together!.
    any getRenderData()
         Get the render data struct for a ColdBox integration test.
    any getRenderedContent()
         Get the rendered content from a ColdBox integration test.
    any getRequestContext()
         Get the RequestContext reference from the running application.
    any getStatusCode()
         Get the status code for a ColdBox integration test.
    any getUtil()
         Get the ColdBox global utility class.
    any getWireBox()
         Get the WireBox reference from the running application.
    any metadataInspection()
         Inspect test case for annotations.
    private struct parseQueryString(string queryString)
         Parses a query string into a struct.
    any patch([string route=''], [struct params='[runtime expression]'], [struct headers='[runtime expression]'], [boolean renderResults='true'], [boolean withExceptionHandling='false'])
         Shortcut method to making a PATCH request through the framework.
    any post([string route=''], [struct params='[runtime expression]'], [struct headers='[runtime expression]'], [boolean renderResults='true'], [boolean withExceptionHandling='false'])
         Shortcut method to making a POST request through the framework.
    private string processException(any controller, any exception)
         Process an exception and returns a rendered bug report.
    any put([string route=''], [struct params='[runtime expression]'], [struct headers='[runtime expression]'], [boolean renderResults='true'], [boolean withExceptionHandling='false'])
         Shortcut method to making a PUT request through the framework.
    any request([string route=''], [struct params='[runtime expression]'], [struct headers='[runtime expression]'], [string method='GET'], [boolean renderResults='true'], [boolean withExceptionHandling='false'])
         Shortcut method to making a request through the framework.
    any reset([boolean clearMethods='false'], [any decorator])
         Reset the persistence of the unit test coldbox app, basically removes the controller from application scope.
    any setAppMapping(any appMapping)
    any setColdboxAppKey(any coldboxAppKey)
    any setConfigMapping(any configMapping)
    any setController(any controller)
    any setup()
         This executes before any test method for integration tests.
    any setupRequest(any event)
         Setup an initial request capture.
     
    Methods inherited from class testbox.system.compat.framework.TestCase
    addAssertDecorator, assert, assertArrayEquals, assertEquals, assertEqualsCase, assertEqualsWithTolerance, assertFalse, assertIsArray, assertIsDefined, assertIsEmpty, assertIsEmptyArray, assertIsEmptyQuery, assertIsEmptyStruct, assertIsExactTypeOf, assertIsQuery, assertIsStruct, assertIsTypeOf, assertIsXMLDoc, assertNotEquals, assertNotSame, assertQueryEquals, assertSame, assertStructEquals, assertTrue, debug, expectException, fail, getMockFactory, init, injectMethod, injectProperty, mock, runTestRemote, setMockingFramework, teardown
     
    Methods inherited from class testbox.system.BaseSpec
    addAssertions, addMatchers, afterEach, aroundEach, aroundStub, beforeEach, clearDebugBuffer, closureStub, console, createEmptyMock, createMock, createStub, describe, expect, expectAll, expectedException, fdescribe, feature, ffeature, fgiven, fit, fscenario, fstory, fthen, fwhen, generateAroundEachClosuresStack, getDebugBuffer, getMockBox, getProperty, given, hasExpectedException, isExpectedException, it, makePublic, mockData, prepareMock, print, println, querySim, runAfterEachClosures, runAroundEachClosures, runBeforeEachClosures, runRemote, runSpec, runTestMethod, scenario, story, then, when, xdescribe, xfeature, xgiven, xit, xscenario, xstory, xthen, xwhen
     
    Methods inherited from class lucee.Component
    None

    Property Detail

    appMapping

    property any appMapping

    The application mapping this test links to

    Attributes:
    access - public
    required - false
    returntype - any
    serializable - true

    coldboxAppKey

    property any coldboxAppKey

    The application key for the ColdBox applicatin this test links to

    Attributes:
    access - public
    required - false
    returntype - any
    serializable - true

    configMapping

    property any configMapping

    The configuration location this test links to

    Attributes:
    access - public
    required - false
    returntype - any
    serializable - true

    controller

    property any controller

    The ColdBox controller this test links to

    Attributes:
    access - public
    required - false
    returntype - any
    serializable - true

    Method Detail

    afterAll

    public any afterAll()

    BDD: The main teardown for ColdBox enabled applications after all tests execute


    afterTests

    public any afterTests()

    xUnit: The main teardown for ColdBox enabled applications after all tests execute

    Overrides:
    afterTests in class testbox.system.compat.framework.TestCase

    announce

    public any announce(any state, [struct data='[runtime expression]'], [boolean async='false'], [boolean asyncAll='false'], [boolean asyncAllJoin='true'], [any asyncPriority='NORMAL'], [numeric asyncJoinTimeout='0'])

    Announce an interception

    Parameters:
    state - The interception state to announce
    data - A data structure used to pass intercepted information.
    async - If true, the entire interception chain will be ran in a separate thread.
    asyncAll - If true, each interceptor in the interception chain will be ran in a separate thread and then joined together at the end.
    asyncAllJoin - If true, each interceptor in the interception chain will be ran in a separate thread and joined together at the end by default. If you set this flag to false then there will be no joining and waiting for the threads to finalize.
    asyncPriority - The thread priority to be used. Either LOW, NORMAL or HIGH. The default value is NORMAL
    asyncJoinTimeout - The timeout in milliseconds for the join thread to wait for interceptor threads to finish. By default there is no timeout.
    Returns:
    struct of thread information or void

    announceInterception Deprecated

    public any announceInterception(any state, [struct interceptData='[runtime expression]'], [boolean async='false'], [boolean asyncAll='false'], [boolean asyncAllJoin='true'], [any asyncPriority='NORMAL'], [numeric asyncJoinTimeout='0'])

    Deprecated:
    Please use `announce()` instead
    Parameters:
    state
    interceptData
    async
    asyncAll
    asyncAllJoin
    asyncPriority
    asyncJoinTimeout

    beforeAll

    public any beforeAll()

    BDD: The main setup method for running ColdBox Integration enabled tests


    beforeTests

    public any beforeTests()

    The main setup method for running ColdBox Integration enabled tests

    Overrides:
    beforeTests in class testbox.system.compat.framework.TestCase

    delete

    public any delete([string route=''], [struct params='[runtime expression]'], [struct headers='[runtime expression]'], [boolean renderResults='true'], [boolean withExceptionHandling='false'])

    Shortcut method to making a DELETE request through the framework.

    Parameters:
    route - The route to execute.
    params - Params to pass to the `rc` scope.
    headers - Custom headers to pass as from the request
    renderResults - If true, then it will try to do the normal rendering procedures and store the rendered content in the RC as cbox_rendered_content
    withExceptionHandling - If true, then ColdBox will process any errors through the exception handling framework instead of just throwing the error. Default: false.

    execute

    public any execute([string event=''], [string route=''], [string queryString=''], [boolean private='false'], [boolean prePostExempt='false'], [struct eventArguments='[runtime expression]'], [boolean renderResults='false'], [boolean withExceptionHandling='false'])

    Executes a framework lifecycle by executing an event. This method returns a request context object that is decorated and can be used for assertions. (e.g. '/login' which may route to 'sessions.new') calling event handler method. rendering procedures and store the rendered content in the RC as cbox_rendered_content. through the exception handling framework instead of just throwing the error. Default: false.

    Parameters:
    event - The event to execute (e.g. 'main.index')
    route - The route to execute
    queryString
    private - Call a private event or not.
    prePostExempt - If true, pre/post handlers will not be fired.
    eventArguments - A collection of arguments to passthrough to the
    renderResults - If true, then it will try to do the normal
    withExceptionHandling - If true, then ColdBox will process any errors
    Returns:
    coldbox.system.context.RequestContext

    explodeRoute

    private struct explodeRoute(string route)

    Separate a route into two parts: the base route, and a query string collection

    Parameters:
    route - a string containing the route with an optional query string (e.g. '/posts?recent=true')
    Returns:
    a struct containing the base route and a struct of query string parameters

    get

    public any get([string route=''], [struct params='[runtime expression]'], [struct headers='[runtime expression]'], [boolean renderResults='true'], [boolean withExceptionHandling='false'])

    Shortcut method to making a GET request through the framework.

    Parameters:
    route - The route to execute.
    params - Params to pass to the `rc` scope.
    headers - Custom headers to pass as from the request
    renderResults - If true, then it will try to do the normal rendering procedures and store the rendered content in the RC as cbox_rendered_content
    withExceptionHandling - If true, then ColdBox will process any errors through the exception handling framework instead of just throwing the error. Default: false.

    getAppMapping

    public string getAppMapping()


    getCache

    public any getCache(any cacheName='default')

    Get the CacheBox reference from the running application

    Parameters:
    cacheName - The cache name to retrieve or returns the 'default' cache by default.
    Returns:
    coldbox.system.cache.providers.ICacheProvider

    getCacheBox

    public any getCacheBox()

    Get the CacheBox reference from the running application

    Returns:
    coldbox.system.cache.CacheFactory

    getColdboxAppKey

    public string getColdboxAppKey()


    getConfigMapping

    public string getConfigMapping()


    getController

    public string getController()


    getFlashScope

    public any getFlashScope()

    Get the RequestContext reference from the running application

    Returns:
    coldbox.system.web.Flash.AbstractFlashScope

    getHandlerResults

    public any getHandlerResults()

    Get the results from a handler execution if any

    Returns:
    The handler results or an empty string

    getInstance

    public any getInstance([any name], [struct initArguments='[runtime expression]'], [any dsl])

    Get a instance object from WireBox

    Parameters:
    name - The mapping name or CFC path to retrieve
    initArguments - The constructor structure of arguments to passthrough when initializing the instance
    dsl - The DSL string to use to retrieve an instance

    getInterceptor

    public any getInterceptor(any interceptorName)

    Get an interceptor reference

    Parameters:
    interceptorName - The name of the interceptor to retrieve
    Returns:
    Interceptor

    getLogBox

    public any getLogBox()

    Get the LogBox reference from the running application

    Returns:
    coldbox.system.logging.LogBox

    getMockController

    public any getMockController()

    I will return a mock controller object

    Returns:
    coldbox.system.testing.mock.web.MockController

    getMockModel

    public any getMockModel(any name, [boolean clearMethods='false'])

    ColdBox must be loaded for this to work. Get a mock model object by convention. You can optional clear all the methods on the model object if you wanted to. The object is created but not initiated, that would be your job.

    Parameters:
    name - The name of the model to mock and return back
    clearMethods - Clear methods on the object

    getMockRequestContext

    public any getMockRequestContext([boolean clearMethods='false'], [any decorator])

    Builds an empty functioning request context mocked with methods via MockBox. You can also optionally wipe all methods on it

    Parameters:
    clearMethods - Clear methods on the object
    decorator - The class path to the decorator to build into the mock request context
    Returns:
    coldbox.system.web.context.RequestContext

    getModel Deprecated

    public any getModel()

    Deprecated:
    true

    getNativeStatusCode

    public any getNativeStatusCode()

    Get the status code set in the CFML engine.

    Returns:
    The CFML status code.

    getPageContextResponse

    private any getPageContextResponse()

    Helper method to deal with ACF2016's overload of the page context response, come on Adobe, get your act together!


    getRenderData

    public any getRenderData()

    Get the render data struct for a ColdBox integration test

    Returns:
    cbox_render_data or an empty struct

    getRenderedContent

    public any getRenderedContent()

    Get the rendered content from a ColdBox integration test

    Returns:
    cbox_rendered_content or an empty string

    getRequestContext

    public any getRequestContext()

    Get the RequestContext reference from the running application

    Returns:
    coldbox.system.web.context.RequestContext

    getStatusCode

    public any getStatusCode()

    Get the status code for a ColdBox integration test

    Returns:
    cbox_statusCode or 200

    getUtil

    public any getUtil()

    Get the ColdBox global utility class

    Returns:
    coldbox.system.core.util.Util

    getWireBox

    public any getWireBox()

    Get the WireBox reference from the running application

    Returns:
    coldbox.system.ioc.Injector

    metadataInspection

    public any metadataInspection()

    Inspect test case for annotations

    Returns:
    BaseTestCase

    parseQueryString

    private struct parseQueryString(string queryString)

    Parses a query string into a struct

    Parameters:
    queryString - a query string from a URI
    Returns:
    a struct of query string parameters

    patch

    public any patch([string route=''], [struct params='[runtime expression]'], [struct headers='[runtime expression]'], [boolean renderResults='true'], [boolean withExceptionHandling='false'])

    Shortcut method to making a PATCH request through the framework.

    Parameters:
    route - The route to execute.
    params - Params to pass to the `rc` scope.
    headers - Custom headers to pass as from the request
    renderResults - If true, then it will try to do the normal rendering procedures and store the rendered content in the RC as cbox_rendered_content
    withExceptionHandling - If true, then ColdBox will process any errors through the exception handling framework instead of just throwing the error. Default: false.

    post

    public any post([string route=''], [struct params='[runtime expression]'], [struct headers='[runtime expression]'], [boolean renderResults='true'], [boolean withExceptionHandling='false'])

    Shortcut method to making a POST request through the framework.

    Parameters:
    route - The route to execute.
    params - Params to pass to the `rc` scope.
    headers - Custom headers to pass as from the request
    renderResults - If true, then it will try to do the normal rendering procedures and store the rendered content in the RC as cbox_rendered_content
    withExceptionHandling - If true, then ColdBox will process any errors through the exception handling framework instead of just throwing the error. Default: false.

    processException

    private string processException(any controller, any exception)

    Process an exception and returns a rendered bug report

    Parameters:
    controller - The ColdBox Controller
    exception - The ColdFusion exception

    put

    public any put([string route=''], [struct params='[runtime expression]'], [struct headers='[runtime expression]'], [boolean renderResults='true'], [boolean withExceptionHandling='false'])

    Shortcut method to making a PUT request through the framework.

    Parameters:
    route - The route to execute.
    params - Params to pass to the `rc` scope.
    headers - Custom headers to pass as from the request
    renderResults - If true, then it will try to do the normal rendering procedures and store the rendered content in the RC as cbox_rendered_content
    withExceptionHandling - If true, then ColdBox will process any errors through the exception handling framework instead of just throwing the error. Default: false.

    request

    public any request([string route=''], [struct params='[runtime expression]'], [struct headers='[runtime expression]'], [string method='GET'], [boolean renderResults='true'], [boolean withExceptionHandling='false'])

    Shortcut method to making a request through the framework.

    Parameters:
    route - The route to execute.
    params - Params to pass to the `rc` scope.
    headers - Custom headers to pass as from the request
    method - The method type to execute. Defaults to GET.
    renderResults - If true, then it will try to do the normal rendering procedures and store the rendered content in the RC as cbox_rendered_content
    withExceptionHandling - If true, then ColdBox will process any errors through the exception handling framework instead of just throwing the error. Default: false.

    reset

    public any reset([boolean clearMethods='false'], [any decorator])

    Reset the persistence of the unit test coldbox app, basically removes the controller from application scope

    Parameters:
    clearMethods
    decorator
    Returns:
    BaseTestCase

    setAppMapping

    public any setAppMapping(any appMapping)

    Parameters:
    appMapping

    setColdboxAppKey

    public any setColdboxAppKey(any coldboxAppKey)

    Parameters:
    coldboxAppKey

    setConfigMapping

    public any setConfigMapping(any configMapping)

    Parameters:
    configMapping

    setController

    public any setController(any controller)

    Parameters:
    controller

    setup

    public any setup()

    This executes before any test method for integration tests

    Overrides:
    setup in class testbox.system.compat.framework.TestCase

    setupRequest

    public any setupRequest(any event)

    Setup an initial request capture. I basically look at the FORM/URL scopes and create the request collection out of them.

    Parameters:
    event - The event to setup the request context with, simulates the URL/FORM.event
    Returns:
    BaseTestCase