Introduction

Light Fixture is a Java component which helps you model test scenario data using a simple text descriptor. You describe your beans and Light Fixture will instantiate the beans and optionally persist them to a database at the same time. In essence it allows you to create lightweight test fixtures.

Usage

Fixture Data

Your fixture data is modelled as a set of POJOs (Plain Old Java Objects) with property values spelled out within a fixture data file. Example:

				import com.myco.bean.User
				import com.myco.bean.Company

				Company acme {
					id: 42
					name: Acme Widgets Inc.
				}

				User bob {
					id: 1
					firstName: Bob
					lastName: Smith Jones
					company: ${acme}
				}
			
Note the use of a variable reference in bob's company property.

Your Test

You may then use the Fixture API to instantiate the contents of a fixture file within your test (or anywhere else for that matter):

				public void testSomething() {
					Fixture fix = new Fixture();
					InputStream str = getClass().getResourceAsStream("scenario1.fix");
					fix.create(str);
					Company cbean = (Company) fix.get("acme");
				}
				public void testPersist() {
					Fixture fix = new Fixture(new HibernatePersister(getSession()));
					InputStream str = getClass().getResourceAsStream("scenario1.fix");
					fix.create(str);
					Company cbean = getSession().load(Company.class, new Integer(42));
				}
			
Note the use of a Hibernate Session in the second test to persist the fixture data into a database. The Fixture does no transaction, connection or session management itself - it is the responsibility of the caller to commit() and/or close(). Light Fixture currently ships with support for Hiberate 2.x and Hibernate 3.x. If you develop a persister for another technology, please send it to me and I'll add it!

Installation

The Light Fixture core is only 30k and has minimal dependencies. You may download the individual jars:

If you are using maven, you can integrate Light Fixture into your project quite easily by adding the following to your project.xml:

				
				<dependency>
					<id>ognl</id>
					<version>2.6.7</version>
				</dependency>
				<dependency>
					<id>commons-logging</id>
					<version>1.0.4</version>
				</dependency>
				<dependency>
					<id>lightfixture</id>
					<version>1.0</version>
				</dependency>
				
			

Documentation

The Light Fixture javadoc is available.