Advertisement
talkingtree

DataProvider.cfc

Mar 19th, 2011
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.53 KB | None | 0 0
  1. <cfcomponent>
  2.    
  3.     <cfproperty name="UITestsRoot" type="string" default="">
  4.    
  5.     <cffunction name="init" access="public" returntype="UITests.dataproviders.DataProvider" output="false">
  6.         <cfreturn this>
  7.     </cffunction>  
  8.    
  9.     <cffunction name="setUITestsRoot" access="public" returntype="void" output="false">
  10.         <cfargument name="path" type="string" required="false" default="#application.UITestsRoot#">
  11.         <cfset this.UITestsRoot = arguments.path>  
  12.     </cffunction>
  13.        
  14.     <cffunction name="getDataProvidersIndex" access="public" returntype="query" output="false">
  15.         <cfspreadsheet action="read" src="#this.UITestsRoot#\dataproviders\datafiles\DataProviders_Index.xls" excludeheaderrow="true" headerrow="1" sheet="1" query="local.dpIndex">
  16.         <cfreturn local.dpIndex>
  17.     </cffunction>
  18.  
  19.     <cffunction name="createDataProviders" access="public" returntype="struct" output="false">
  20.         <cfset local.dpIndex = getDataProvidersIndex()>
  21.         <cfset local.dataProviders = {}>
  22.         <cfset local.datafile = "">
  23.         <cfset local.dpm = createObject("component","UITests.dataproviders.DataProviderManager")>
  24.        
  25.         <cfloop from="1" to="#local.dpIndex.recordCount#" index="local.i">
  26.                        
  27.             <cfset local.datafile = "#this.UITestsRoot#\dataproviders\datafiles\#local.dpIndex.webtop[local.i]#\#local.dpIndex.filename[local.i]#">
  28.             <cfset local.datafile = replace(local.datafile,"\All\","\","one")>
  29.             <cfif not fileexists(local.datafile)>
  30.                 <cfthrow message="Data File #listlast(local.datafile,'\')# Not Found" detail="Expected to find #local.datafile#">
  31.             </cfif>
  32.            
  33.             <cfswitch expression="#dpIndex.dataSet[local.i]#">
  34.                 <cfcase value="All">
  35.                     <cfset local.dpm.setDataProvider(local.datafile,local.dpIndex.sheetName[local.i],local.dpIndex.tableName[local.i])>
  36.                     <cfset local.dataProviders['#local.dpIndex.name[local.i]#'] = local.dpm.getData()>
  37.                 </cfcase>  
  38.                 <cfcase value="Range">
  39.                     <cfset local.dpm.setDataProvider(local.datafile,local.dpIndex.sheetName[local.i],local.dpIndex.tableName[local.i])>
  40.                     <cfset local.dataProviders['#local.dpIndex.name[local.i]#'] = local.dpm.getDataByRange(local.dpIndex.startRow[local.i],local.dpIndex.endRow[local.i])>
  41.                 </cfcase>  
  42.                 <cfcase value="Row">
  43.                     <cfset local.dpm.setDataProvider(local.datafile,local.dpIndex.sheetName[local.i],local.dpIndex.tableName[local.i])>
  44.                     <cfset local.dataProviders['#local.dpIndex.name[local.i]#'] = local.dpm.getDataAtRow(local.dpIndex.startRow[local.i])>
  45.                 </cfcase>  
  46.             </cfswitch>
  47.            
  48.         </cfloop>
  49.        
  50.         <cfreturn local.dataProviders>
  51.        
  52.     </cffunction>
  53.    
  54. </cfcomponent>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement