package mytest;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import javax.jdo.PersistenceManager;
import javax.jdo.PersistenceManagerFactory;
import javax.jdo.Query;
import junit.framework.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import com.locatead.proto.dao.CellDAO;
import com.locatead.proto.model.Cell;
import com.locatead.proto.util.datastore.RdbmsPMF;
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations={"classpath:applicationContext.xml"})
public class PmfTest {
private final Logger logger = LoggerFactory.getLogger(PmfTest.class);
@Autowired
private CellDAO dao;
@Test
public void myTest() {
if (dao == null) {
System.out.println("null");
}
}
// @Test
// public void pmfTest() {
// PersistenceManager pm = null;
// try {
// PersistenceManagerFactory pmf = JDOHelper.getPersistenceManagerFactory();
// pm = pmf.getPersistenceManager();
// }
// finally {
// pm.close();
// }
// Assert.assertEquals(true, true);
// }
@Test
public void CellDBTest() {
Cell c = new Cell("", 0, 0, new Date(), new Date(), new Date(), "Sean Reuben", "LBSNIC Inc.");
Cell d = null;
PersistenceManager pm = null;
try {
PersistenceManagerFactory pmf = RdbmsPMF.get();
pm = pmf.getPersistenceManager();
//pm.makePersistent(c);
logger.info("query is ready");
Query q = pm.newQuery(Cell.class, "x==ix && y==iy");
q.declareParameters("int ix, int iy");
logger.info("query before execute");
@SuppressWarnings("unchecked")
List<Cell> lst = (List<Cell>) q.execute(new Integer(0), new Integer(0));
logger.info("successfully executed a Cell object");
d = lst.get(0);
}
finally {
pm.close();
}
logger.info(d.getX() + ", " + d.getY());
logger.info(d.getOwner());
Assert.assertEquals(c.getOwner(), d.getOwner());
}
}
|