package de.dhbw.humbuch.viewmodel;

import java.util.Iterator;
import java.util.List;

import javax.persistence.EntityManager;

import org.hibernate.Session;
import org.hibernate.Transaction;
import org.junit.After;
import org.junit.Before;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.google.inject.Provider;

import de.dhbw.humbuch.model.entity.TestPersistenceInitialiser;

public class BaseTest {
	private final static Logger LOG = LoggerFactory.getLogger(BaseTest.class);

	private Provider<EntityManager> emProvider;

	public void setInjected(TestPersistenceInitialiser persistenceInitialiser,
			Provider<EntityManager> emProvider) {
		this.emProvider = emProvider;
	}
	
	@Before
	public void checkInjection() {
		if (emProvider == null) {
			LOG.error("setInjected() in BaseTest might not have been called"); 
		}
	}

	@After
	public void stopPersistenceService() {
		LOG.info("deleting data in all tables");
		Session session = emProvider.get().unwrap(Session.class);
		Transaction transaction = session.beginTransaction();
		List<?> all = session.createQuery("from java.lang.Object").list();
		Iterator<?> it = all.iterator();
		while (it.hasNext()) {
			session.delete(it.next());
		}

		transaction.commit();
	}
}

@@ -340,24 +340,59 @@
 rovider;%0D%0A%0D%0A
+import de.dhbw.humbuch.model.DAO;%0D%0A
 import de.dh
@@ -446,16 +446,132 @@
 ser;%0D%0A%0D%0A
+/**%0D%0A * @author David Herrmann (davherrmann)%0D%0A * %0D%0A * Base class for Tests using persistence and %7B@link DAO%7Ds%0D%0A */%0D%0A
 public c
@@ -712,16 +712,207 @@
 vider;%0D%0A
+%09%0D%0A%09/**%0D%0A%09 * Inject necessary objects, called by child test class%0D%0A%09 * %0D%0A%09 * @param persistenceInitialiser - %7B@link TestPersistenceInitialiser%7D%0D%0A%09 * @param emProvider - %7B@link Provider%7D%0D%0A%09 */
 %0D%0A%09publi
@@ -1064,16 +1064,97 @@
 %0A%09%7D%0D%0A%09%0D%0A
+%09/**%0D%0A%09 * Log a warning if child class has not injected necessary objects%0D%0A%09 */%0D%0A
 %09@Before
@@ -1305,51 +1305,98 @@
 %0A%0D%0A%09
-@After%0D%0A%09public void stopPersistenceService
+/**%0D%0A%09 * Clear all tables after running a test%0D%0A%09 */%0D%0A%09@After%0D%0A%09public void clearAllTables
 () %7B

add javadocs