• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

Mock data, is there an easy way?

 
Ranch Hand
Posts: 231
Android IntelliJ IDE Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I'm writing a web application using the Stripes framework which will eventually do basic CRUD actions on a MySQL database.

For the moment (I'm still in the real early stages) I'd like an easy way to get some data in the system (for read only). I was wondering if there was some solution whereby I could type up some sample data in an XML file , such as name, address, postcode etc and have this read by my DAO?

I have a DAO interface and I could write an implementation class to read from this XML file, and eventually swap out the implemtation for something in Hibernate, but I'm not sure how to go about this, or how I can find examples

My other idea was to write a class that loops through instances of my domain object and uses the setters to set properties on my domain object, eventually returning one big list, but I think that would be incredibly messy

Any suggestions?

Many thanks
 
Rancher
Posts: 600
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
James:

Because you already have a DAO interface, creating a mock object is really easy. Have the mock implement the interface, and maybe read in the XML file when you instantiate it. Have your methods return the data from the XML file that correspond to the data that will be in the database.

John.
 
James Elsey
Ranch Hand
Posts: 231
Android IntelliJ IDE Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for the info John,

I've found this article on a blog, it might be just what I need

http://www.skill-guru.com/blog/2009/10/14/hibernate-represent-entity-data-in-xml/

Thanks

 
John de Michele
Rancher
Posts: 600
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
James:

Yes, that looks promising. Good luck .

John.
 
James Elsey
Ranch Hand
Posts: 231
Android IntelliJ IDE Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I've gone through the tutorial I posted above, but it seems its more a case of returning data in XML format, rather than using XML to represent an object.

I've done a lot of searching (spent several hours last night trying to find a solution) but so far I'm not any closer.

For example, I have a domain object in my application called "person", this has "firstName" and "lastName"

Ideally I'm looking to store some static sample data in an XML file, something like :



That way, I can begin working on some pages/features of my application without having to worry about a backend database, I can slot that in later when I have a better idea of how I'm going to do that part. I just want some sample data

Can anyone please give me some pointers? Or maybe some links? I think the bulk of my problem is that I'm a bit of a newbie and not really sure on how to tackle this

Many thanks
 
John de Michele
Rancher
Posts: 600
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
James:

Why bother with XML at all? The whole point of a mock object is that it looks to the classes that access it like a real object would, but works differently. Have your mock DAO implement a private inner class (maybe called Person) that has firstName and lastName fields. Have your DAO create and maintain a List of Person objects, so you can add and return data. You can even hard code some Person objects if you need to start out with your 'table' not empty.

John.
 
I child proofed my house but they still get in. Distract them with this tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic