This is a simple test I threw together to make sure our fairly complex ModelGlue.xml config file doesn’t end up getting two events named with the same name. While this shouldn’t happen it did and so I needed a test to make sure it didn’t happen again.

<cffunction name="testConfigFileForDuplicateEventNodeNames" access="public"
<cfset var local = structNew() />

<cfset local.filepath = ExpandPath('\lb2\config\ModelGlue.xml') />

<cfset local.xml = XmlParse(local.filePath) />

<cfset = local.xml.modelglue["event-handlers"].XmlChildren
<cfset local.usedKeys = structnew() />

<cfloop from="1" to="#ArrayLen(" index="local.i">
<cfset local.node =[local.i] />
<cfif StructKeyExists(local.usedKeys, local.node)>
<cfset fail("the node " & local.node & " is defined more than once in
ModelGlue.xml") />
<cfset local.usedKeys["#local.node#"] = "" />


This is obviously an incredibly simple test and it doesn’t collate problems, it just fails on the first one. Nor will it tell you where in your ModelGlue.xml file to find the problem; but it works for a simple peace of mind test. Hope it helps someone else!

Finally I mention mxUnit but obviously you can easily update this to work with the unit test framework of your choice. I just happen to choose mxUnit.