views:

44

answers:

3

I'm writing a Java web app in my free time to learn more about development. I'm using the Stripes framework and eventually intend to use hibernate and MySQL

For the moment, whilst creating the pages and general layout, how can I mock up some data easily? For example I don't want to be messing around with a backend database at this stage, is there a solution where I could have some sample data in an XML file?

+1  A: 

I use DAO interfaces, so that I can implement both a real DAO and a test DAO. For example, this is the interface:

public interface PersonDAO {
   public List<Person> findAll();
}

Then I'll have 2 implementations of this interface:

public class PersonHibernateDAO implements PersonDAO {
   public List<Person> findAll() {
      // use Hibernate to find and return all the Person objects
   }
}

public class PersonTestDAO implements PersonDAO {
   public List<Person> findAll() {
      List<Person> testData = new ArrayList<Person>();
      testData.add(new Person("Bob");
      testData.add(new Person("Steve");
      return testData;
   }
}

The controller itself uses a PersonDAO, and you can supply either the Hibernate implementation (when in production or testing against the database), or the Test implementation (when unit testing or playing around before the database is set up).

Kaleb Brasee
A: 

You might want to take a look at creating DataTables or using data tables with JTable. Basically you would just mock up the structure of a database table, create a number of rows of data and then use that to bind to your data bound controls.

Creating data table in java

A Simple Interactive JTable Tutorial

Have fun and hope this helps some.

Chris
A: 

You could use XStream to read XML into your Java objects. You can even use JSON instead of XML, which might be less verbose and quicker for the purposes of your tests.

Frederic Daoud