Interceptor Testing
You can test interceptors directly with no need of doing integration testing via the BaseInterceptorTest. This way you can unit test interceptors in isolation. All you need to do is the following:
1
coldbox create interceptor-test path=interceptors.Deploy points=onCreate --open
Copied!
This testing support class will create your interceptor, and decorate with mocking capabilities via MockBox and mock all the necessary companion objects around interceptors. The following are the objects that are placed in the variables scope for you to use:
    interceptor : The target interceptor to test
    mockController : A mock ColdBox controller in use by the target interceptor
    mockRequestService : A mock request service object
    mockLogger : A mock logger class in use by the target interceptor
    mockLogBox : A mock LogBox class in use by the target interceptor
    mockFlash : A mock flash scope in use by the target interceptor
All of the mock objects are essentially the dependencies of interceptor objects. You have complete control over them as they are already mocked for you.
1
/**
2
* The base interceptor test case will use the 'interceptor' annotation as the instantiation path to the interceptor
3
* and then create it, prepare it for mocking, and then place it in the variables scope as 'interceptor'. It is your
4
* responsibility to update the interceptor annotation instantiation path.
5
*/
6
component extends="coldbox.system.testing.BaseInterceptorTest" interceptor="interceptors.test"{
7
8
/*********************************** LIFE CYCLE Methods ***********************************/
9
10
function beforeAll(){
11
// interceptor configuration properties, if any
12
configProperties = {};
13
// init and configure interceptor
14
super.setup();
15
// we are now ready to test this interceptor
16
}
17
18
function afterAll(){
19
}
20
21
/*********************************** BDD SUITES ***********************************/
22
23
function run(){
24
25
describe( "interceptors.test", function(){
26
27
it( "should configure correctly", function(){
28
interceptor.configure();
29
});
30
31
32
});
33
34
}
35
36
}
Copied!
Last modified 1yr ago
Copy link