package test; import static org.junit.jupiter.api.Assertions.assertEquals; import java.lang.reflect.Field; import java.sql.SQLException; import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.Map; import org.junit.Assert; import org.junit.Test; import bean.Author; import utils.DbUtil; public class DbUtilTest { DbUtil db = DbUtil.createDBUtil(); @Test public void testGetModel() throws Exception { Map fs = db.getModel("bean.Book"); Assert.assertEquals("price", fs.get("price")); Assert.assertEquals("update_time", fs.get("updateTime")); } @Test public void testAuthor() throws Exception { Author t = db.get(Author.class,1); // assertNotNull(t); if(t != null) { assertEquals(1, t.getId()); System.out.println(t); } List list = db.queryList(Author.class, "select * from author limit 1"); assertEquals(1, list.size()); } @Test public void testAddAuthor() throws SQLException { int ret = db.save("insert into author (name,create_time,update_time) values (?,now(),now())","lisi"); assertEquals(1, ret); } public static void main(String[] args) throws Exception { // testGetModel(); Class cls = Author.class; List fs = new ArrayList(); fs.addAll(Arrays.asList(cls.getDeclaredFields())); Class parent = cls.getSuperclass(); if (parent.getName().equalsIgnoreCase("bean.BaseModel")) { fs.addAll(Arrays.asList(parent.getDeclaredFields())); } for (Field f : fs) { System.out.println(f.getName()); } } }