comment

Introducing Metro - A Transfer ORM Service Factory and More...

2008 December 07
No Comments
Metro is a library of components to support rapid development of applications that use ColdSpring and Transfer ORM.

read more...

Working With Transfer ORM - Transfer Transaction Advice

2008 November 28
No Comments

Maintaining referential integrity in your database is a good thing. Any decent RDBMS will include ACID (Atomicity, Consistency, Isolation, Durability) transaction support for ensuring consistency and recoverability of your database. With the Transfer ORM Transaction object, one can apply transactions easily to a Service or Gateway. Here's how one can use it to wrap all "save" and "delete" methods for a Service.

read more...

A Simple onMissingTemplate Example

2008 November 24
No Comments

For the migration to Mango Blog, I wanted to preserve my previous RSS feed location (/rss.cfm). The new location is feeds/rss.cfm. With the availability of onMissingTemplate event handler for ColdFusion 8, making sure my RSS didn't break was a snap. Here's the snippet of code I added to Application.cfc.

<cffunction name="onMissingTemplate" returntype="void">
   <cfargument name="thePage" type="string" required="true">
   <cfif arguments.thePage is "/blog/rss.cfm">
      <cflocation url="/blog/feeds/rss.cfm" addtoken="false" />
   </cfif>
</cffunction>

Not the most elegant solution I've ever developed, but it keeps the RSS feed alive until I decide how I want to manage it the future...

Transient Creation Performance - ColdSpring and TransientFactory

2008 November 11
No Comments
In my last post, I demonstrated the generic factory I use to create Transient objects in my Coldfusion apps. Jaime Metcher asked in a comment whether the Transient Factory is faster than CS when instantiating transient objects. I had no hard data to answer Jaime's question, so I took the opportunity to set up jMeter on my new dev machine and run through some load tests to find out.

read more...

A Coldfusion Transient Factory Example

2008 November 07
No Comments
When learning how to apply object oriented principles to ColdFusion development, one will assuredly encounter the subject of design patterns. Singleton, Factory, Strategy and Bridge are just some of the patterns that describe solutions to common problems in programming. For this example, I'll demonstrate a variation on the Factory Pattern for transient objects. What is a factory? At it's simplest, a factory encapsulates the creation of objects to provide a consistent api for clients. What is a transient object? A typical OO ColdFusion application will incorporate a combination of Singletons (one instance per application - often instantiated at application startup) and Transients (a per request object that is not maintained in a persistent scope).

read more...

Java For Mac OS X 10.5 Update 2 - ColdFusion 8 Gotcha

2008 October 28
No Comments
If you're a Mac person and haven't already installed ColdFusion 8 on 10.5 (Leopard), be aware that updating Java will cause the ColdFusion 8 (64-bit OS X) installer to fail. The problem appears to be that the Java version "1.5.0_16" is unrecognized by the installer as a supported 64-bit version of Java. Note that CF8 will run on Java version 1.5.0_16 for Mac, but it will not install to it.

ColdSpring Reloaded

2008 September 12
No Comments
Coldspring was the first Coldfusion-based "framework" that I integrated into my application development process. I can't claim to be an expert, but today I'll step up and try evangelism. Based on the popular Java Spring framework, Coldspring provides a solid foundation for applications with features like dependecy injection, aspect-oriented programing, remote proxy generation and more. If you already use ColdSpring, or want to learn how to use it, I highly recommend the new Quickstart Guide and Examples written by ColdSpring guru Brian Kotek. In addition to a new look and documentation update, version 1.2 is now final! Get ye to the Springery...

For the Love of Chocolate, Style Your Optgroup!

2008 September 10
No Comments
If you haven't tried out the cfUniForm tag library by Matt Quackenbush, I highly recommend it. Version 2.3 includes some nice updates proposed by Bob Silverberg, including the addition of optgroup to select lists. I don't like the default italic style for an optgroup label, so when I use it, I add a simple css selector to make them a little more visually appealing. For example: optgroup {
   font-weight: bold;
   font-style:normal;
}
Don't let default optgroup styles drag you down. Make them great with a little CSS.

My Approach to Test Driven Development Part 3 - Testing Against a Database

2008 September 08
No Comments
Confidently unit testing code that relies on a database is troublesome. There are many different approaches and many opinions on the matter. I've previously written about using transactions to safely rollback the database after every test. This worked well for me at the time, but there are pitfalls in using that approach. Recently, I've done some more research on the subject and even attempted, without success, to integrate DBUnit into my database reliant unit tests. After some trial and error, I landed on the following approach that is a culmination of a few ideas I'd previously heard of, but never tried. The goal of this approach is to:
  1. Run tests against a known data set.
  2. Reset the entire database prior to each test.
The example code that follows requires a test database, test database user and a test datasource targeting the test database.

read more...

My Approach to Test Driven Development Part 2 - MXUnit, Coldspring and ColdMock

2008 August 28
No Comments
Like the title says, this post will include code samples for setting up an MXUnit test case using ColdSpring and ColdMock. The goal of any test case are to isolate the component under test as much as possible. I find ColdMock to be a simple and powerful tool for achieving test isolation. For this example, I created a test case for my ConfigFactory which I mentioned in a previous post. TheConfigFactory component has a constructor dependency on the Environment Config component developed by Rolando Lopez which makes this a good case for mocking. Here's a snapshot of the files used in this sample test setup, A common convention for test cases is to add the suffix "Test" to match the test case to the component being tested. I have my own convention for setting up tests withColdSpring bean definitions which I keep in a similarly named xml file. All test cases extend the BaseTestCase which contains a couple of methods to simplify test configuration with ColdSpring. The full code of the of the BaseTestCase follows. <cfcomponent displayname="tests.BaseTestCase" extends="mxunit.framework.TestCase" output="false">

<cfset variables.beansXML = "">

<cffunction name="setBeanFactory" access="private" output="false" returntype="void">
<cfargument name="beansXML" type="string" required="true">
<cfargument name="params" type="struct" required="false" default="#structnew()#">
<cfscript>

if ((not structkeyExists(request,"beanFactory")) or (comparenocase(variables.beansXML,arguments.beansXML) neq 0))
{
variables.beansXML = arguments.beansXML;
request.beanFactory = createObject("component" ,"coldspring.beans.DefaultXmlBeanFactory").init(StructNew(),arguments.params);
request.beanFactory.loadBeans(variables.beansXML);
}
</cfscript>
</cffunction>

<cffunction name="getBeanFactory" access="private" output="false" returntype="any">
<cfreturn request.beanFactory>
</cffunction>

</cfcomponent>
In the past I kept my ColdSpring reference in variables scope, but I found that when testing components based that rely on Transfer ORM, I can shave the time of tests considerably when I have multiple tests in the same test case. Whether you run the MXUnit HttpAntRunner, the eclipse plugin or a manually configured test suite within a browser they all run as a single request, so as you define more tests it helps to speed things up. Here's what the ConfigFactoryTest.xml looks like. <beans>
<bean id="mockFactory" class="tests.MockFactory" singleton="true" />

<bean id="EnvironmentConfig" factory-bean="MockFactory" factory-method="createMock">
<constructor-arg name="objectToMock">
<value>model.Environment</value>
</constructor-arg>
</bean>

<bean id="ConfigFactory" class="model.ConfigFactory">
<constructor-arg name="hostName">
<value>${hostName}</value>
</constructor-arg>
<constructor-arg name="environmentConfig">
<ref bean="EnvironmentConfig" />
</constructor-arg>
</bean>

</beans>
You can see how easy it is to mock the dependency using the ColdMock MockFactory. Below is the full code for my ConfigFacotry test case. The important thing to note is that the component display name is used to resolve the path to the ColdSpring bean definitions used in the test suite. <cfcomponent displayname="tests.ConfigFactoryTest" extends="tests.BaseTestCase">

<cffunction name="setUp" access="public" returntype="void">
<cfset var beanDefFileLocation = expandPath('/' & Replace(GetMetadata(this).displayname,'.','/','all') & '.xml')>
<cfset var params = Structnew()>
<cfset params.hostName = "www.somedomain.com">
<cfset setBeanFactory(beanDefFileLocation,params)>
</cffunction>

<!--- Begin Specific Test Cases --->

<cffunction name="testGetSetting" access="public" returntype="void">
<cfscript>
var configFactory = "";
var env = getBeanFactory().getBean("EnvironmentConfig");
var settings = structNew();
settings["MyString"] = "my string";
env.mockMethod('getEnvironmentByUrl').returns(settings);
configFactory = getBeanFactory().getBean("ConfigFactory");
assertTrue(configFactory.getSetting("MyString") eq settings["MyString"]);
</cfscript>
</cffunction>

<cffunction name="testGetAllSettings" access="public" returntype="void">
<cfscript>
var configFactory = "";
var env = getBeanFactory().getBean("EnvironmentConfig");
var settings = structNew();
settings["MyString"] = "my string";
env.mockMethod('getEnvironmentByUrl').returns(settings);
configFactory = getBeanFactory().getBean("ConfigFactory");
assertTrue(StructCount(configFactory.getAllSettings()) eq 1);
</cfscript>
</cffunction>

<cffunction name="testOnMissingMethod" access="public" returntype="void">
<cfscript>
var configFactory = "";
var env = getBeanFactory().getBean("EnvironmentConfig");
var settings = structNew();
settings["MyString"] = "my string";
env.mockMethod('getEnvironmentByUrl').returns(settings);
configFactory = getBeanFactory().getBean("ConfigFactory");
assertTrue(configFactory.getMyString() eq settings["MyString"]);
</cfscript>
</cffunction>

<!--- End Specific Test Cases --->

</cfcomponent>
Most of my tests aren't this involved. Since my ConfigFactory has a constructor dependency on EnvironmentConfig, I pull it out of ColdSpring first, mock the getEnvironmentByUrl method to return a known structure before requesting the ConfigFactory. Truly powerful stuff! I have attached a zip file of this sample test bed as an enclosure for folks to try out.