lundi 21 novembre 2016

Testing data creating in JPA project

I have question about the creation of testing data in webapp running in Glassfish with JPA (and JSF).

I usually create class like TestDataCreator which generates some basic testing database environment. This class contains main method like:

public static void main(String[] args) {
  createSomeUsers();
  createSomeStockItems();
  putSomeItemsIntoBaskets();
  // ...
}

and each of theese methods just inserts some entities into database.

While I used to use good-old JDBC for database connection, this worked fine. But, now I am implementing app inside of Glassfish and with JPA. So, now the Glassfish is the one who performs the database connection.

So, my question is - how to (correctly) modify this class to be working again. Is some better way than creating website with button "Create database" invoking TestDataCreator's method?

Also, i prefer to store this class in src/test/java, but the "website" solution leads to put class into src/main/java. And this - correct me, if not - stinks.

Thanks in advice

Aucun commentaire:

Enregistrer un commentaire