easyb plugable functionality

Posted by Ken Brooks Sun, 23 Dec 2007 20:36:00 GMT

if you aren’t familiar with easyb (http://easyb.org), then do yourself a favor and pay that site a visit to learn the basics of this great bdd framework for java.

one of the strengths of easyb is its domain specific language that allows us to write behaviors and stories that act as executable documentation. we also have a way to allow you as a user to extend that by writing plugins.

here are the steps to do so:

  • implement Plugable on our plugin classes (optional)
  • create the following file META-INF/services/org.disco.easyb.core.delegates.Plugable
  • package it all up into a jar and make it available on the classpath

lets start with our class, write any java/groovy class that exposes a public method and (for readability) implement the org.disco.easyb.core.delegates.Plugable interface.

now, create a file named org.disco.easyb.core.delegates.Plugable and when you package everything into the plugin jar put that file into the META-INF/services directory. the contents of the file need only be a list of classes (fully qualified) that optionally implement the Plugable interface and expose public functionality you wish to mixin to easyb.

package your classes and the property file into a jar file (outside the scope of this article) and make sure that jar file is available on the classpath when easyb stories are run

three steps, thats it? seem too simple! thats what easby is all about.

So whats happening under the covers? when easyb encounters a method call in the story that it can’t resolve it then goes thru the list of classes found in the META-INF/services/org.disco.easyb.core.delegates.Plugable file. Each class is then inspected to see if it contains a method that can handle our call. If it finds one then everything is golden and the call is made, if not then a MethodMissing exception is thrown.

If you wish to see an example of this completely implemented then checkout the easyb source and look in the plug-ins dir for easyb-dbunit. This mixes in dbunit functionality into easyb.

Tags  | no comments

Comments

(leave url/email »)

   Comment Markup Help Preview comment