Skip to content
This repository
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

executable file 215 lines (162 sloc) 7.914 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214
<cfcomponent displayname="TestSuite" extends="Test" hint="Responsible for creating and running groups of Tests.">
<cfset cu = createObject("component","ComponentUtils") />


<cfparam name="this.testSuites" default="#getMap()#" />
<cfparam name="this.tests" default="#arrayNew(1)#" />

<!--- Generated content from method --->
<cfparam name="this.c" default="Error occurred. See stack trace." />
<cfparam name="this.dataProviderHandler" default='#createObject("component","DataproviderHandler")#' />
<cfparam name="this.MockingFramework" default="" />

<cfparam name="variables.requestScopeDebuggingEnabled" type="boolean" default="false" />

<cffunction name="TestSuite" access="public" returntype="TestSuite" hint="Constructor">
<cfreturn this />
</cffunction>

<!---
Should be of Type "Test". Since All TestCases and TestSuites
are inherited from Test, we should be able to add them here

Also, need to
--->
<cffunction name="addTest" access="remote" returntype="void" hint="Adds a single TestCase to the TestSuite.">
<cfargument name="componentName" type="string" required="yes" />
<cfargument name="method" type="string" required="yes" />
<cfargument name="componentObject" type="Any" required="no" default="" />

<cfscript>
var newStruct = {};
try{
this.tempStruct = structNew();
this.tempStruct.ComponentObject = arguments.ComponentObject;

// If the test suite exists get the method array and
// append the new method name ...
// update an existing test suite
if (this.testSuites.containsKey(arguments.componentName)) {
this.tempStruct = this.testSuites.get(arguments.componentName);

tempArray = structFind(this.tempStruct, "methods");
arrayAppend(tempArray,arguments.method);

structUpdate(this.tempStruct, "methods", tempArray);
this.testSuites.put(arguments.componentName, this.tempStruct);
} else{
//Begin a new test Suite
this.testSuite.put(arguments.componentName, this.tempStruct);

//Grab all the methods that begin with the string 'test' ...
tests = listToArray(arguments.method);

newStruct.methods = tests;

this.testSuites.put(arguments.componentName,newStruct);
}
} catch (Exception e) {
writeoutput(e.getMessage());
}
</cfscript>
</cffunction>

<!---
Maybe should be named addList
Adds a list of methods belonging to a component into a testSuite object
--->
<cffunction name="add" access="remote" returntype="void" hint="Adds a list of TestCases to the TestSuite">
<cfargument name="componentName" type="Any" required="yes" />
<cfargument name="methods" type="string" required="yes" />
<cfargument name="componentObject" type="Any" required="no" default="" />

<cfif isSimpleValue(arguments.ComponentObject)>
<cfset ComponentObject = createObject("component",arguments.ComponentName) />
</cfif>

<cfscript>
try{
//If the component already has methods, just update the method array
if ( this.testSuites.containsKey(arguments.componentName) ) {
tests = testSuites.get(arguments.componentName);

for( i = 1; i lte listLen(arguments.methods); i = i + 1 ) {
arrayAppend(tests.methods, listGetAt(arguments.methods,i));
}

return;
}

//else convert the list of methods to an array and add it to the test suite
this.tempStruct = structNew();
this.tempStruct.ComponentObject = arguments.ComponentObject;
this.tempStruct.methods = listToArray(arguments.methods);
this.testSuites.put(arguments.componentName, this.tempStruct);
} catch (any e) {
writeoutput("Error Adding Tests : " & e.getType() & " " & e.getMessage() & " " & e.getDetail());
}
</cfscript>
</cffunction>

<cffunction name="addAll" access="remote" returntype="any" output="false" hint="Adds all runnable TestCases to the TestSuite">
<cfargument name="ComponentName" type="any" required="yes" />
<cfargument name="ComponentObject" type="any" required="false" default="" />

<cfset var a_methods = "" />

<cfif isSimpleValue(arguments.ComponentObject)>
<cfset ComponentObject = createObject("component",arguments.ComponentName).TestCase() />
</cfif>
 
<cfset a_methods = ComponentObject.getRunnableMethods() />

<cfset add(arguments.ComponentName,ArrayToList(a_methods),ComponentObject) />

<cfreturn this />
</cffunction>

<cffunction name="run" returntype="any" access="remote" output="true" hint="Primary method for running TestSuites and individual tests.">
<cfargument name="results" hint="The TestResult collecting parameter." required="no" type="TestResult" default="#createObject("component","TestResult").TestResult()#" />
<cfargument name="testMethod" hint="A single test method to run." type="string" required="no" default="">

<cfset var testRunner = createObject("component", "TestSuiteRunner") />

<cfset testRunner.setMockingFramework(this.mockingFramework) />
<cfset testRunner.setDataProviderHandler(this.dataProviderHandler) />

<cfif variables.requestScopeDebuggingEnabled OR structKeyExists(url,"requestdebugenable")>
<cfset testRunner.enableRequestScopeDebugging() />
</cfif>

<cfreturn testRunner.run(this.suites(), results, testMethod)>
</cffunction>

<cffunction name="runTestRemote" access="remote" output="true">
<cfargument name="output" type="string" required="false" default="jqgrid" hint="Output format: html,xml,junitxml,jqgrid ">
<cfargument name="debug" type="boolean" required="false" default="false" hint="Flag to indicate whether or not to dump the test results to the screen.">

<cfscript>
var result = this.run();

switch(arguments.output){
case 'xml':
writeoutput(result.getXmlresults());
break;

case 'junitxml':
writeoutput(result.getJUnitXmlresults());
break;

case 'json':
writeoutput(result.getJSONResults());
break;

case 'query':
dump(result.getQueryresults());
break;

case 'text':
writeoutput( trim(result.getTextresults(name)));
break;

case 'rawhtml':
writeoutput(result.getRawHtmlresults());
break;

default:
writeoutput(result.getHtmlresults());
break;
}
</cfscript>

<cfif arguments.debug>
<p>&nbsp;</p>

<cfdump var="#result.getResults()#" label="Raw Results Dump">
</cfif>
</cffunction>

<cffunction name="suites" access="public" returntype="any">

<cfreturn this.testSuites />
</cffunction>

<cffunction name="stringValue" access="remote" returntype="string">
<cfreturn this.suites().toString() />
</cffunction>

<cffunction name="dump">
<cfargument name="o">

<cfdump var="#o#">
</cffunction>

<cffunction name="enableRequestScopeDebugging" access="public" output="false" hint="enables creation of the request.debug function">
<cfset requestScopeDebuggingEnabled = true>
</cffunction>

<cffunction name="setMockingFramework" hint="Allows a developer to set the default Mocking Framework for this test suite.">
<cfargument name="name" type="Any" required="true" hint="The name of the mocking framework to use" />

<cfset this.MockingFramework = arguments.name />
</cffunction>

<cffunction name="getMap" returntype="Any" access="private" output="false" hint="I return an instance of a java sorted map" >
<cfreturn createObject("Java","java.util.LinkedHashMap") />
</cffunction>

<cffunction name="setTestSuites" access="public" returntype="void" output="false" hint="Method used to set test suites for testing" >
<cfargument name="testSuites" type="any" required="true" />
<cfif arguments.testSuites.getClass().getName() eq "java.util.LinkedHashMap" >
<cfset this.testSuites = arguments.testSuites />
</cfif>
</cffunction>
</cfcomponent>
Something went wrong with that request. Please try again.