Interceptor Test and 'Log' property

Hello Guys,

I have written a test case for an interceptor which extends the BaseInterceptorTest, however, the base interceptor test doesn’t seem to properly mock the ‘log’ property of an interceptor.

So when inside my interceptor doing something like this:

// The user is not logged in so we couldn’t collect their current account.

// Log that we managed to add this user account into the event.

log.info(“We did not load a user account into the event, because (#e#)”);

I get an exception saying that the property ‘log’ is not defined, however, in reality, this is perfectly acceptable code which works when run in the app.

In my mind this is a bug in the BaseInterceptorTest, what do you think? Should this property be mocked?

Robert

can you post your test. We have tons of tests on the core to test interceptors this way with logging and it works. I just tested it also, so there might be something amiss.

Luis F. Majano
President
Ortus Solutions, Corp
www.ortussolutions.com

ColdBox Platform: http://www.coldbox.org
Linked In: http://www.linkedin.com/pub/3/731/483
Blog: http://www.luismajano.com
IECFUG Manager: http://www.iecfug.com

Social: twitter.com/lmajano facebook.com/lmajano

Hi Luis,

Sure. Here is the code in my test case:

component extends=‘coldbox.system.testing.BaseInterceptorTest’ interceptor=‘modules.saas.interceptors.security’ {

public void function setUp() {
// Call the super setup method to setup the app.
super.setup();

// Create the security service that we’re going to test.
securityService = getMockBox().createMock(“modules.saas.model.security.securityService”);

// Mock the get model method in the interceptor to return the security service.
Interceptor.$(“getModel”, securityService);

// Mock the required logging behaviour.
// TODO: I don’t like having to mock this, it SHOULD be part of the ColdBox core, speak to Luis about it.
Interceptor.$property(propertyname=‘log’, mock=mockLogger);
MockLogger.$(“info”);
}

public void function testRememberMeSuccess() {
// Mock the return structure for the security service.
local.return = {
issuccess = true,
message = ‘We remembered this user some user.’
};

// Mock that the security service will a sucessful result struct.
securityService.$(‘rememberMeLogin’, local.return);

// Clear the properties for the mock event.
mockRequestContext.clearCollection();

// Call the interceptor with the mock event.
Interceptor.sessionStart(mockRequestContext, ‘’);
}

public void function testRememberMeFailed() {
// Mock the return structure for the security service.
local.return = {
issuccess = false,
message = ‘The user doesnt appear to have a remember me cookie.’
};

// Mock that the security service will a sucessful result struct.
securityService.$(‘rememberMeLogin’, local.return);

// Clear the properties for the mock event.
mockRequestContext.clearCollection();

// Call the interceptor with the mock event.
Interceptor.sessionStart(mockRequestContext, ‘’);
}

}

And here is the code it’s testing.

component extends=“coldbox.system.interceptors.Security” {

public void function configure () {

// Configure the super class.
super.configure();
}

public void function SessionStart() {
// Ask the security service to try and login any remember me cookies.
local.remember_me_login_result = getModel(‘security.SecurityService’).rememberMeLogin();

// Check to see if the login passed or not.
if (local.remember_me_login_result.issuccess) {
// We logged the user in as they’d asked us to remember them.
// Put a log note about this as it’s an invisible action.
log.info(“User Remembered: #local.remember_me_login_result.message#”);
} else {
// We didn’t remember who the user was or log them in automaticaly.
// Put a log note about this as it’s an invisible action.
log.info(“User Not Remembered: #local.remember_me_login_result.message#”);
}
}

}

This, as it stands works just fine, but notice how I have to explicitly mock the ‘log’ property and ‘info’ methods in my setup?

Robert

Logbox is mocked, can you share how you define the variable log?

Regards,

Andrew Scott

http://www.andyscott.id.au/

Logbox is mocked, can you share how you define the variable log?

Regards,

Andrew Scott

http://www.andyscott.id.au/

You will see that the base interceptor test also mocks the get logger
call that ocurrs once the interceptor is inited. That is when the log
is mocked. S the interceptor must ini

Hi Luis,

Thanks for the feedback. I’m still struggling with this though. I’m now initing the interceptor like so:

public void function setUp() {

// Call the super setup method to setup the app.

super.setup();

// Create the security service that we’re going to test.

securityService = getMockBox().createMock(“modules.saas.model.security.securityService”);

// Mock the get model method in the interceptor to return the security service.

Interceptor.$(“getModel”, securityService);

// Init the interceptor.

Interceptor.init(mockController, {});

// Mock the account that we’ll use.

mockAccount = getMockBox().createMock(“modules.saas.model.account.account”);

}

However, I’m now getting an error which looks as if the mock logger isn’t quite right:

component [coldbox.system.logging.Logger] has no function with name [INFO]

Am I missing something?

Thanks for your help mate.

Robert