|
@@ -13,10 +13,7 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.test.context.ContextConfiguration;
|
|
|
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
|
|
|
|
|
-import java.util.ArrayList;
|
|
|
-import java.util.Date;
|
|
|
-import java.util.List;
|
|
|
-import java.util.Map;
|
|
|
+import java.util.*;
|
|
|
|
|
|
/**
|
|
|
* 基于拓展的测试用例
|
|
@@ -26,8 +23,7 @@ import java.util.Map;
|
|
|
* @email liukx@elab-plus.com
|
|
|
**/
|
|
|
@RunWith(SpringJUnit4ClassRunner.class) //使用junit4进行测试
|
|
|
-@ContextConfiguration
|
|
|
- ({"classpath:applicationContext-datasource.xml",})
|
|
|
+@ContextConfiguration({"classpath:applicationContext-datasource.xml",})
|
|
|
public class BasicBaseDaoCase {
|
|
|
|
|
|
@Autowired
|
|
@@ -36,64 +32,63 @@ public class BasicBaseDaoCase {
|
|
|
@Autowired
|
|
|
private BasicBaseDao basicBaseDao;
|
|
|
|
|
|
-// @Autowired
|
|
|
-// private IHelloDao helloDao;
|
|
|
+ // @Autowired
|
|
|
+ // private IHelloDao helloDao;
|
|
|
|
|
|
-// @Test
|
|
|
-// public void executeQueryforListMap() {
|
|
|
-// Map<String, String> map = new HashMap<>();
|
|
|
-// map.put("status", "1");
|
|
|
-// List<Map<String, Object>> maps = basicBaseDao.executeQueryForListMap("com.db.service.dao.ITestDao.selectByExample", map);
|
|
|
-// System.out.println(maps.size());
|
|
|
-// }
|
|
|
-//
|
|
|
-// @Test
|
|
|
-// public void executeQueryList() {
|
|
|
-// TTest test = new TTest();
|
|
|
-// test.setStatus("1");
|
|
|
-// List<TTest> tTests = basicBaseDao.executeQueryList("com.db.service.dao.ITestDao.selectByExample", test, TTest.class);
|
|
|
-// System.out.println(tTests.size());
|
|
|
-// }
|
|
|
-//
|
|
|
-// @Test
|
|
|
-// public void executeQueryBigDataList() {
|
|
|
-// TTest test = new TTest();
|
|
|
-// test.setStatus("1");
|
|
|
-// List<TTest> tTests = basicBaseDao.executeQueryBigDataList("com.db.service.dao.ITestDao.selectByExample", test, TTest.class);
|
|
|
-// System.out.println(tTests.size());
|
|
|
-// }
|
|
|
-//
|
|
|
-//
|
|
|
-// @Test
|
|
|
-// public void executeInsert() {
|
|
|
-// TTest test = new TTest();
|
|
|
-// test.setStatus("1");
|
|
|
-// test.setUsername("某某某xx");
|
|
|
-// int i = basicBaseDao.insert("test.insert", test);
|
|
|
-// System.out.println(i);
|
|
|
-// }
|
|
|
-//
|
|
|
-// @Test
|
|
|
-// public void executeUpdate() {
|
|
|
-// TTest test = new TTest();
|
|
|
-// test.setId(1);
|
|
|
-// test.setStatus("1");
|
|
|
-// test.setUsername("某某某xx");
|
|
|
-// int i = basicBaseDao.executeUpdate("test.updateByPrimaryKey", test);
|
|
|
-// System.out.println(i);
|
|
|
-// }
|
|
|
+ // @Test
|
|
|
+ // public void executeQueryforListMap() {
|
|
|
+ // Map<String, String> map = new HashMap<>();
|
|
|
+ // map.put("status", "1");
|
|
|
+ // List<Map<String, Object>> maps = basicBaseDao.executeQueryForListMap("com.db.service.dao.ITestDao.selectByExample", map);
|
|
|
+ // System.out.println(maps.size());
|
|
|
+ // }
|
|
|
+ //
|
|
|
+ // @Test
|
|
|
+ // public void executeQueryList() {
|
|
|
+ // TTest test = new TTest();
|
|
|
+ // test.setStatus("1");
|
|
|
+ // List<TTest> tTests = basicBaseDao.executeQueryList("com.db.service.dao.ITestDao.selectByExample", test, TTest.class);
|
|
|
+ // System.out.println(tTests.size());
|
|
|
+ // }
|
|
|
+ //
|
|
|
+ // @Test
|
|
|
+ // public void executeQueryBigDataList() {
|
|
|
+ // TTest test = new TTest();
|
|
|
+ // test.setStatus("1");
|
|
|
+ // List<TTest> tTests = basicBaseDao.executeQueryBigDataList("com.db.service.dao.ITestDao.selectByExample", test, TTest.class);
|
|
|
+ // System.out.println(tTests.size());
|
|
|
+ // }
|
|
|
+ //
|
|
|
+ //
|
|
|
+ // @Test
|
|
|
+ // public void executeInsert() {
|
|
|
+ // TTest test = new TTest();
|
|
|
+ // test.setStatus("1");
|
|
|
+ // test.setUsername("某某某xx");
|
|
|
+ // int i = basicBaseDao.insert("test.insert", test);
|
|
|
+ // System.out.println(i);
|
|
|
+ // }
|
|
|
+ //
|
|
|
+ // @Test
|
|
|
+ // public void executeUpdate() {
|
|
|
+ // TTest test = new TTest();
|
|
|
+ // test.setId(1);
|
|
|
+ // test.setStatus("1");
|
|
|
+ // test.setUsername("某某某xx");
|
|
|
+ // int i = basicBaseDao.executeUpdate("test.updateByPrimaryKey", test);
|
|
|
+ // System.out.println(i);
|
|
|
+ // }
|
|
|
|
|
|
@Test
|
|
|
public void executeQueryList() throws Exception {
|
|
|
-// String sql = configurableFactory.getSqlConfigurableFactory().getSql("test.selectByObjectToCount");
|
|
|
- String sql = "select count(1) from test.t_test where id =:id and love_name =:loveName and created " +
|
|
|
- "=:created and sex =:sex and name =:name and id =:id and time =:time and username =:username and status =:status and test_id =:testId";
|
|
|
+ // String sql = configurableFactory.getSqlConfigurableFactory().getSql("test.selectByObjectToCount");
|
|
|
+ String sql = "select count(1) from test.t_test where id =:id and love_name =:loveName and created "
|
|
|
+ + "=:created and sex =:sex and name =:name and id =:id and time =:time and username =:username and status =:status and test_id =:testId";
|
|
|
TTest test = new TTest();
|
|
|
test.setStatus("1");
|
|
|
- Long integer = basicBaseDao.executeQueryCount(sql,
|
|
|
- test, null, Long.class);
|
|
|
-// Long integer1 = basicBaseDao.getJdbcTemplate().queryForObject("select count(1) from test.t_test where 1=1 and status =?",
|
|
|
-// new Object[]{1}, Long.class);
|
|
|
+ Long integer = basicBaseDao.executeQueryCount(sql, test, null, Long.class);
|
|
|
+ // Long integer1 = basicBaseDao.getJdbcTemplate().queryForObject("select count(1) from test.t_test where 1=1 and status =?",
|
|
|
+ // new Object[]{1}, Long.class);
|
|
|
System.out.println(integer);
|
|
|
}
|
|
|
|
|
@@ -109,12 +104,12 @@ public class BasicBaseDaoCase {
|
|
|
test.setTime(new Date());
|
|
|
test.setCreated(new Date());
|
|
|
test.setName("batchTest_name_" + i);
|
|
|
-// test.setLoveName("aaaaa");
|
|
|
+ // test.setLoveName("aaaaa");
|
|
|
list.add(test);
|
|
|
}
|
|
|
- String sql = "insert into t_test (username, name, sex, status, created, time, test_id, love_name) values " +
|
|
|
- "(:username, :name, :sex, :status, :created, :time, :test_id, :love_name)";
|
|
|
-// String sql = "insert into t_test (username, name, sex, status, created, time, test_id, love_name) values (?, ?, ?, ?, ?, ?, ?, ?)";
|
|
|
+ String sql = "insert into t_test (username, name, sex, status, created, time, test_id, love_name) values "
|
|
|
+ + "(:username, :name, :sex, :status, :created, :time, :test_id, :love_name)";
|
|
|
+ // String sql = "insert into t_test (username, name, sex, status, created, time, test_id, love_name) values (?, ?, ?, ?, ?, ?, ?, ?)";
|
|
|
basicBaseDao.batchOperation(SqlCommandType.INSERT, sql, list);
|
|
|
System.out.println("=========");
|
|
|
}
|
|
@@ -129,35 +124,44 @@ public class BasicBaseDaoCase {
|
|
|
list.add(test);
|
|
|
}
|
|
|
String sql = "update t_test set time = :time where id = :id";
|
|
|
-// String sql = "insert into t_test (username, name, sex, status, created, time, test_id, love_name) values (?, ?, ?, ?, ?, ?, ?, ?)";
|
|
|
+ // String sql = "insert into t_test (username, name, sex, status, created, time, test_id, love_name) values (?, ?, ?, ?, ?, ?, ?, ?)";
|
|
|
basicBaseDao.batchOperation(SqlCommandType.UPDATE, sql, list);
|
|
|
}
|
|
|
|
|
|
@Test
|
|
|
public void testSql() throws Exception {
|
|
|
- String json = "{\"houseId\":10151,\"writeType\":1,\"keyword1\":\"%%\",\"keyword2\n" +
|
|
|
- "\":\"%%\"}";
|
|
|
+ String json = "{\"houseId\":10151,\"writeType\":1,\"keyword1\":\"%%\",\"keyword2\n" + "\":\"%%\"}";
|
|
|
Map map = JSON.parseObject(json, Map.class);
|
|
|
- String sql = "select distinct a.id,a.name,a.mobile,a.sex,a.head,a.online_status,a.video_online_status,\n" +
|
|
|
- " a.wxno,a.im_adviser,a.video_adviser,a.agent,a.honor,d.id organize_id,\n" +
|
|
|
- " d.name organize_name,b.user_id worker_id,b.follow_service,b.toker_service,\n" +
|
|
|
- " b.writer,b.write_time,b.write_type,b.status,b.recommend,a.photo,a.email from worker_account a\n" +
|
|
|
- " left join organize_user_rlat b on b.user_id = a.id\n" +
|
|
|
- " left join organize d on d.id = b.organize_id\n" +
|
|
|
- " left join t_dm_organize_house_rlat f on f.organize_id = d.id and f.house_id = b.house_id\n" +
|
|
|
- " where d.status = 1 and f.status = 1 and b.house_id = :houseId and b.write_type = :writeType\n" +
|
|
|
- " and b.organize_id = :organizeId and (a.name like :keyword1 or a.mobile like :keyword2)\n" +
|
|
|
- " order by ifnull(b.updated,b.created) desc";
|
|
|
- String okSql = "select distinct a.id,a.name,a.mobile,a.sex,a.head,a.online_status,a.video_online_status,\n" +
|
|
|
- " a.wxno,a.im_adviser,a.video_adviser,a.agent,a.honor,d.id organize_id,\n" +
|
|
|
- " d.name organize_name,b.user_id worker_id,b.follow_service,b.toker_service,\n" +
|
|
|
- " b.writer,b.write_time,b.write_type,b.status,b.recommend,a.photo,a.email from worker_account a\n" +
|
|
|
- " left join organize_user_rlat b on b.user_id = a.id\n" +
|
|
|
- " left join organize d on d.id = b.organize_id\n" +
|
|
|
- " left join t_dm_organize_house_rlat f on f.organize_id = d.id and f.house_id = b.house_id\n" +
|
|
|
- " where d.status = 1 and f.status = 1 and b.house_id = ? and b.write_type = ? and (a.name like ? )\n" +
|
|
|
- " order by ifnull(b.updated,b.created) desc";
|
|
|
- JdbcParamsModel model = basicBaseDao.commonParseSql(sql, map);
|
|
|
+ String sql = "select distinct a.id,a.name,a.mobile,a.sex,a.head,a.online_status,a.video_online_status,\n"
|
|
|
+ + " a.wxno,a.im_adviser,a.video_adviser,a.agent,a.honor,d.id organize_id,\n"
|
|
|
+ + " d.name organize_name,b.user_id worker_id,b.follow_service,b.toker_service,\n"
|
|
|
+ + " b.writer,b.write_time,b.write_type,b.status,b.recommend,a.photo,a.email from worker_account a\n"
|
|
|
+ + " left join organize_user_rlat b on b.user_id = a.id\n"
|
|
|
+ + " left join organize d on d.id = b.organize_id\n"
|
|
|
+ + " left join t_dm_organize_house_rlat f on f.organize_id = d.id and f.house_id = b.house_id\n"
|
|
|
+ + " where d.status = 1 and f.status = 1 and b.house_id = :houseId and b.write_type = :writeType\n"
|
|
|
+ + " and b.organize_id = :organizeId and (a.name like :keyword1 or a.mobile like :keyword2)\n"
|
|
|
+ + " order by ifnull(b.updated,b.created) desc";
|
|
|
+ String okSql = "select distinct a.id,a.name,a.mobile,a.sex,a.head,a.online_status,a.video_online_status,\n"
|
|
|
+ + " a.wxno,a.im_adviser,a.video_adviser,a.agent,a.honor,d.id organize_id,\n"
|
|
|
+ + " d.name organize_name,b.user_id worker_id,b.follow_service,b.toker_service,\n"
|
|
|
+ + " b.writer,b.write_time,b.write_type,b.status,b.recommend,a.photo,a.email from worker_account a\n"
|
|
|
+ + " left join organize_user_rlat b on b.user_id = a.id\n"
|
|
|
+ + " left join organize d on d.id = b.organize_id\n"
|
|
|
+ + " left join t_dm_organize_house_rlat f on f.organize_id = d.id and f.house_id = b.house_id\n"
|
|
|
+ + " where d.status = 1 and f.status = 1 and b.house_id = ? and b.write_type = ? and (a.name like ? )\n"
|
|
|
+ + " order by ifnull(b.updated,b.created) desc";
|
|
|
+
|
|
|
+ String sql3 = "SELECT\n" + " *\n" + " FROM t_plate\n" + " WHERE `status`=:status AND\n"
|
|
|
+ + " MBRWITHIN (\n" + " GeomFromText(:requestCentre),\n" + " t_plate.geo_polygons)";
|
|
|
+
|
|
|
+ Map<String, Object> reqData = new HashMap<>();
|
|
|
+ List<String> fromText = new ArrayList<>();
|
|
|
+ fromText.add("A");
|
|
|
+ fromText.add("B");
|
|
|
+ reqData.put("requestCentre", fromText);
|
|
|
+ reqData.put("status",1);
|
|
|
+ JdbcParamsModel model = basicBaseDao.commonParseSql(sql3, reqData);
|
|
|
Assert.assertTrue(model.getSql().equals(okSql));
|
|
|
}
|
|
|
}
|