Skip to content

Commit e57aa91

Browse files
author
Adam Tuttle
committed
#73 finished Hoth & BLHQ integration examples & tests
1 parent d36c62b commit e57aa91

File tree

10 files changed

+108
-10
lines changed

10 files changed

+108
-10
lines changed

bonus/ILogAdapter.cfc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
<cffunction name="init" hint="I accept a configuration structure to setup and return myself">
44
<cfargument name="config" />
5+
<cfargument name="tracker" />
56
</cffunction>
67
<cffunction name="log" hint="I log or otherwise notify you of an exception">
78
<cfargument name="exception" />

bonus/LogToBugLogHQ.cfc

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,31 @@
22

33
<cffunction name="init">
44
<cfargument name="config" />
5+
<cfargument name="tracker" default="#createObject("component", "bugLog.client.bugLogService")#" />
6+
7+
<cfset variables.blhq = arguments.tracker />
8+
<cfset variables.blhq.init(
9+
argumentCollection=arguments.config
10+
) />
11+
12+
<cfparam name="arguments.config.message" default="Exception trapped in API" />
13+
<cfset variables.message = arguments.config.message />
14+
515
<cfreturn this />
616
</cffunction>
717

818
<cffunction name="log">
919
<cfargument name="exception" />
10-
<!--- TODO --->
20+
21+
<cfset var msg = '' />
22+
23+
<cfif structKeyExists(exception, "message")>
24+
<cfset msg = exception.message />
25+
<cfelse>
26+
<cfset msg = variables.message />
27+
</cfif>
28+
29+
<cfset variables.blhq.notifyService(msg, arguments.exception) />
1130
</cffunction>
1231

1332
</cfcomponent>

bonus/LogToEmail.cfc

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,19 @@
22

33
<cffunction name="init">
44
<cfargument name="config" />
5-
<cfset structAppend( variables, arguments.config, true ) /><!--- copy settings into adapter instance data --->
5+
<cfargument name="tracker" hint="unused" default="" />
6+
7+
<!--- copy settings into adapter instance data --->
8+
<cfset structAppend( variables, arguments.config, true ) />
9+
610
<cfreturn this />
711
</cffunction>
812

913
<cffunction name="log">
1014
<cfargument name="exception" />
1115
<!---
12-
TODO: this adapter does not currently support authentication-required email, supplying a specific server, etc.
13-
That would be a great and relatively easy thing for a 3rd party contributor to add! :)
16+
TODO: This adapter does not currently support authentication-required email, supplying a specific server, etc.
17+
That would be a great and relatively easy thing for you to contribute back! :)
1418
--->
1519
<cfmail
1620
from="#variables.emailFrom#"

bonus/LogToHoth.cfc

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22

33
<cffunction name="init">
44
<cfargument name="config" />
5-
<cfset variables.hothtracker = createObject("component", "Hoth.HothTracker").init(
5+
<cfargument name="tracker" default="#createObject("component", "Hoth.HothTracker")#" />
6+
<cfset variables.hothtracker = arguments.tracker />
7+
<cfset variables.hothtracker.init(
68
createObject("component", arguments.config)
79
) />
810
<cfreturn this />

examples/api/Application.cfc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
variables.framework.reloadKey = "reload";
99
variables.framework.reloadPassword = "true";
1010
variables.framework.defaultRepresentationClass = "taffy.core.genericRepresentation";
11+
variables.framework.returnExceptionsAsJson = true;
1112

1213
// do your onApplicationStart stuff here
1314
function applicationStartEvent(){}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<cfcomponent extends="taffy.core.api">
2+
<cfscript>
3+
4+
this.name = hash(getCurrentTemplatePath());
5+
6+
variables.framework = {};
7+
8+
variables.framework.defaultExceptionLogAdapter = "taffy.bonus.LogToBugLogHQ";
9+
10+
variables.framework.exceptionLogAdapterConfig = StructNew();
11+
variables.framework.exceptionLogAdapterConfig.bugLogListener = "bugLog.listeners.bugLogListenerWS";
12+
variables.framework.exceptionLogAdapterConfig.bugEmailRecipients = "[email protected]";
13+
variables.framework.exceptionLogAdapterConfig.bugEmailSender = "[email protected]";
14+
variables.framework.exceptionLogAdapterConfig.hostname = "Taffy_DEV_Examples";
15+
variables.framework.exceptionLogAdapterConfig.apikey = "";
16+
17+
</cfscript>
18+
</cfcomponent>

examples/api_BugLogHQ/index.cfm

Whitespace-only changes.
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<cfcomponent extends="taffy.core.resource" taffy_uri="/foo">
2+
3+
<cffunction name="get" access="public" output="false">
4+
<cfthrow message="this is the message" detail="this is the detail" />
5+
</cffunction>
6+
7+
</cfcomponent>

examples/api_Hoth/Application.cfc

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,9 @@
22
<cfscript>
33
this.name = hash(getCurrentTemplatePath());
44

5-
variables.framework = {
6-
returnExceptionsAsJson = true
7-
,defaultExceptionLogAdapter = "taffy.bonus.LogToHoth"
8-
,exceptionLogAdapterConfig = "taffy.examples.api_hoth.resources.HothConfig"
9-
};
5+
variables.framework = {};
6+
variables.framework.defaultExceptionLogAdapter = "taffy.bonus.LogToHoth";
7+
variables.framework.exceptionLogAdapterConfig = "taffy.examples.api_hoth.resources.HothConfig";
108

119
</cfscript>
1210
</cfcomponent>

tests/tests/TestLoggers.cfc

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
<cfcomponent extends="base">
2+
<cfscript>
3+
4+
function test_hoth(){
5+
var mockHoth = mock();
6+
var hothAdapter = '';
7+
var fakeError = {};
8+
9+
//setup the behaviors we're expecting the adapter to run
10+
mockHoth.track('{struct}');
11+
12+
//create hoth adapter to test
13+
hothAdapter = createObject("component", "taffy.bonus.LogToHoth").init(
14+
"taffy.examples.api_hoth.resources.HothConfig",
15+
mockHoth
16+
);
17+
18+
//fake error
19+
fakeError.message = "This is a test error";
20+
fakeError.detail = "Rubber Baby Buggy Bumper";
21+
hothAdapter.log(fakeError);
22+
23+
mockHoth.verify().track('{struct}');
24+
}
25+
26+
function test_BugLogHQ(){
27+
var mockBLHQ = mock();
28+
var blhqAdapter = '';
29+
var blhqSettings = {};
30+
var fakeError = {};
31+
32+
mockBLHQ.notifyService('{string}', '{struct}');
33+
34+
blhqAdapter = createObject("component", "taffy.bonus.LogToBugLogHQ").init(
35+
blhqSettings,
36+
mockBLHQ
37+
);
38+
39+
//fake error
40+
fakeError.message = "This is a test error";
41+
fakeError.detail = "Rubber Baby Buggy Bumper";
42+
blhqAdapter.log(fakeError);
43+
44+
mockBLHQ.verify().notifyService('{string}', '{struct}');
45+
}
46+
47+
</cfscript>
48+
</cfcomponent>

0 commit comments

Comments
 (0)