Fetching contributors…
Cannot retrieve contributors at this time
211 lines (170 sloc) 8.06 KB
<cfcomponent name="mxunit.framework.ComponentUtils" output="false" hint="Internal component not generally used outside the framework">
<cfset sep = getSeparator() />
<cffunction name="ComponentUtils" returnType="ComponentUtils" hint="Constructor"><cfreturn this /></cffunction>
<cffunction name="isFrameworkTemplate" returntype="boolean" hint="whether the passed in template is part of the mxunit framework">
<cfargument name="template" type="string" required="true" />
<!--- braindead simple.... is anything more than this necessary? --->
<cfreturn refindNoCase("mxunit(.*?)[/\\](trunk[/\\])?framework",template) />
<cffunction name="getSeparator" returntype="string" hint="Returns file.separator as seen by OS.">
<cfreturn createObject("java","java.lang.System").getProperty("file.separator") />
<cffunction name="getLineSeparator" returntype="string" hint="Returns file.separator as seen by OS.">
<cfreturn createObject("java","java.lang.System").getProperty("line.separator") />
<cffunction name="getInstallRoot" returnType="string" access="public">
var root = expandPath("/");
var mxunit = 0;
var cm = createObject("component","ConfigManager").ConfigManager();
var elements = [];
//shortcut of the usual case of a virtualhost / alias on the web root
elements = cm.getConfigElement("userConfig","installRoot");
if (arrayLen(elements) eq 0)
return getContextRoot() & "/mxunit";
return elements[1].xmlAttributes["value"];
<!--- check for the a physical directory --->
<cfdirectory action="list" directory="#root#" recurse="true" name="mxunit" filter="mxunit-config.xml">
<cfif mxunit.RecordCount eq 0>
<cfif mxunit.RecordCount eq 0>
<cfthrow message="Could not find mxunit in the web root" />
root = replaceNoCase("", root,"");
root = getDirectoryFromPath(root);
root = getContextRoot() & "/" & left(root, (Len(root) - Len("/framework/")));
return root;
<cffunction name="getComponentRoot" returnType="string" access="public">
<cfargument name="fullPath" type="string" required="false" default="" hint="Test Hook." />
// Use the mxunit-config.xml to handle install location in case of weird behavior
// or if user wants custom configuration
var cm = createObject("component","ConfigManager").ConfigManager();
var userConfig = cm.getConfigElement("userConfig","componentRoot");
var mxUnitRoot = userConfig[1].xmlAttributes["value"];
var override = userConfig[1].xmlAttributes["override"];
var i = 1;//loop index
var sep = ".";
var package = arrayNew(1); //list
var installRoot = "";
//We know THIS "should" always be in mxunt.framework.ComponentUtils
var md = getMetaData(this);
var name =;
//Inject fullPath argument for testing
if(len(arguments.fullPath)) {
name = arguments.fullPath;
//Workaround for Mac/Apache configs that do not return
//fully qualified names for getMetaData()
if(name is "ComponentUtils" OR name is "" OR name is "."){
//use the userConfig/componentRoot element value in mxunit-config.xml
//If user needs to override default install location.
// Note name is "override" is an injected test hook.
if(name is "override" OR override){
package = listToArray(name,".");
for(i; i lte arrayLen(package)-2; i = i + 1){
installRoot = installRoot & package[i] & sep;
return left(installRoot, len(installRoot)-1);
<cffunction name="dump">
<cfargument name="o" />
<cfdump var="#arguments.o#" />
<cffunction name="hasJ2EEContext">
<cfreturn getContextRootPath() is not "">
<cffunction name="getContextRootComponent">
<cfset var rootComponent = "" />
<cfset var ctx = getContextRootPath() />
<cfif hasJ2EEContext()>
<!--- This last "." worries me. Under what circumstance will this not be true? --->
<cfset rootComponent = right(ctx,len(ctx)-1) & "." />
<cfreturn rootComponent />
<cffunction name="getContextRootPath">
<cfset var ctx= "" />
<cfset ctx = getPageContext().getRequest().getContextPath() />
<cfreturn ctx />
<cffunction name="isCfc" hint="Determines whether or not the given object is a ColdFusion component; Author: Nathan Dintenfass ">
<cfargument name="objectToCheck" />
//get the meta data of the object we're inspecting
var metaData = getMetaData(arguments.objectToCheck);
//if it's an object, let's try getting the meta Data
//if it has a type, and that type is "component", then it's a component
if(structKeyExists(metaData,"type") AND metaData.type is "component"){
return true;
//if we've gotten here, it must not have been a contentObject
return false;
<cffunction name="getMockFactoryInfo" returnType="any" access="public">
<cfargument name="factoryName" required="false" default="" />
// Using the mxunit-config.xml to store the mock factory config
var cm = createObject("component","ConfigManager").ConfigManager();
var mockFactoryInfo = StructNew();
if (not Len(arguments.factoryName)) {
arguments.factoryName = cm.getConfigElementValue("mockingFramework","name");
mockFactoryInfo.factoryPath = cm.getConfigElementValue(arguments.factoryName,"factoryPath");
mockFactoryInfo.createMockMethodName = cm.getConfigElementValue(arguments.factoryName,"createMockMethodName");
mockFactoryInfo.createMockStringArgumentName = cm.getConfigElementValue(arguments.factoryName,"createMockStringArgumentName");
mockFactoryInfo.createMockObjectArgumentName = cm.getConfigElementValue(arguments.factoryName,"createMockObjectArgumentName");
mockFactoryInfo.constructorName = cm.getConfigElementValue(arguments.factoryName,"constructorName");
mockFactoryInfo.constructorArgs = cm.getConfigElementAttributeCollection(arguments.factoryName,"constructorArgs");
return mockFactoryInfo;
<cffunction name="objectIsTypeOf" output="false" access="public" returntype="boolean" hint="returns true if the object 'type' as reported by getMetadata() matches the object's type or if the object is in the inheritance tree of the type">
<cfargument name="object" required="yes" type="any" />
<cfargument name="type" required="yes" type="string" />
<cfset var md = getMetaData(object)>
<cfset var oType =>
<cfset var ancestry = buildInheritanceTree(md) />
<cfreturn listFindNoCase(ancestry, arguments.type)>
<cffunction name="buildInheritanceTree" access="public" returntype="string">
<cfargument name="metaData" type="struct" />
<cfargument name="accumulator" type="string" required="false" default=""/>
var key = "";
if( structKeyExists(arguments.metadata,"name") AND listFindNoCase(accumulator, eq 0 ){
accumulator = accumulator & & ",";
//why, oh why, is the structure different for interfaces vs. extends? For F**k's sake!
if( structKeyExists( metadata.extends, "name" ) ){
accumulator = buildInheritanceTree(metaData.extends, accumulator);
accumulator = buildInheritanceTree(metadata.extends[ structKeyList(metadata.extends) ], accumulator);
for(key in arguments.metadata.implements){
accumulator = buildInheritanceTree(metaData.implements[ key ], accumulator);
return accumulator;