package net.sf;
import java.util.HashMap;
import java.util.List;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContextType;
import javax.persistence.spi.PersistenceUnitTransactionType;
import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;
import net.sf.domainbeans.DefaultDomainBeans;
import net.sf.domainbeans.DomainBeans;
import net.sf.domainbeans.FactoryBuilder;
import org.hibernate.SessionFactory;
import org.hibernate.dialect.HSQLDialect;
import org.hibernate.ejb.EntityManagerImpl;
/**
* Unit test for simple App.
*/
public class AppTest extends TestCase {
FactoryBuilder factoryBuilder;
SessionFactory sessionFactory;
@Override
protected void setUp() throws Exception {
factoryBuilder = new FactoryBuilder();
factoryBuilder.setAutoUpdateTable();
factoryBuilder.setDriverClass(org.hsqldb.jdbcDriver.class);
factoryBuilder.setConnectionUrl("jdbc:hsqldb:.");
factoryBuilder.setUserName("sa");
factoryBuilder.setPassword("");
factoryBuilder.setShowSql();
factoryBuilder.setDialect(HSQLDialect.class);
factoryBuilder.addAnnotatedClass(User.class);
sessionFactory = factoryBuilder.getSessionFactory();
}
/**
* @return the suite of tests being tested
*/
public static Test suite() {
return new TestSuite(AppTest.class);
}
/**
* Rigourous Test :-)
*/
public void testApp() {
EntityManager entityManager = new EntityManagerImpl(sessionFactory,PersistenceContextType.TRANSACTION,PersistenceUnitTransactionType.RESOURCE_LOCAL,true,null,new HashMap<String, String>());
DomainBeans domainbeans = new DefaultDomainBeans(entityManager);
User user = new User(); //domainbeans.bind(new User());
user.setDb(domainbeans);
user.setUserName("arif");
user.setPassword("rachim");
System.out.println("We are saving");
user.save("testing saving password");
user = new User();
user.setDb(domainbeans);
user.loadBasedOnName("arif");
System.out.println(user.getPassword());
// User userTwo = domainbeans.bind(new User());
// userTwo.setUserName("jojo");
// userTwo.setPassword("rachim");
// userTwo.save("rachim");
//
// List<User> users = domainbeans.bind(new User()).findByPassword("rachim");
// System.out.println("We got user "+users);
// for (User usr : users) {
// System.out.println(usr.getUserName()+" "+usr.getPassword());
// }
//
// User userThree = domainbeans.bind(new User());
// userThree.setUserName("jojo");
// userThree.load();
// System.out.println(userThree.getPassword());
}
}