?? criteriatest.java
字號(hào):
String result = null; try { result = BasePeer.createQueryString(c); } catch (TorqueException e) { fail("TorqueException thrown in BasePeer.createQueryString()"); } assertEquals(expect, result); // test the postgresql variation c = new Criteria(); Criteria.Criterion cc = c.getNewCriterion("TABLE.COLUMN", Boolean.TRUE, Criteria.EQUAL); Configuration conf = new BaseConfiguration(); conf.addProperty("driver", "org.postgresql.Driver"); try { cc.setDB(DBFactory.create("org.postgresql.Driver")); } catch (Exception e) { fail("Exception thrown in DBFactory"); } assertEquals("TABLE.COLUMN=TRUE", cc.toString()); } /** * testcase for addDate() */ public void testAddDate() { Criteria c = new Criteria(); c.addDate("TABLE.DATE_COLUMN", 2003, 0, 22); String expect = "SELECT FROM TABLE WHERE TABLE.DATE_COLUMN='20030122000000'"; String result = null; try { result = BasePeer.createQueryString(c); } catch (TorqueException e) { e.printStackTrace(); fail("TorqueException thrown in BasePeer.createQueryString()"); } assertEquals(expect, result); } /** * testcase for add(Date) */ public void testDateAdd() { Calendar cal = Calendar.getInstance(); cal.set(2003, 0, 22, 0, 0, 0); Date date = cal.getTime(); Criteria c = new Criteria(); c.add("TABLE.DATE_COLUMN", date); String expect = "SELECT FROM TABLE WHERE TABLE.DATE_COLUMN='20030122000000'"; String result = null; try { result = BasePeer.createQueryString(c); } catch (TorqueException e) { e.printStackTrace(); fail("TorqueException thrown in BasePeer.createQueryString()"); } assertEquals(expect, result); } public void testCurrentDate() { Criteria c = new Criteria() .add("TABLE.DATE_COLUMN", Criteria.CURRENT_DATE) .add("TABLE.TIME_COLUMN", Criteria.CURRENT_TIME); String expect = "SELECT FROM TABLE WHERE TABLE.TIME_COLUMN=CURRENT_TIME AND TABLE.DATE_COLUMN=CURRENT_DATE"; String result = null; try { result = BasePeer.createQueryString(c); } catch (TorqueException e) { e.printStackTrace(); fail("TorqueException thrown in BasePeer.createQueryString()"); } assertEquals(expect,result); } public void testCountAster() { Criteria c = new Criteria() .addSelectColumn("COUNT(*)") .add("TABLE.DATE_COLUMN", Criteria.CURRENT_DATE) .add("TABLE.TIME_COLUMN", Criteria.CURRENT_TIME); String expect = "SELECT COUNT(*) FROM TABLE WHERE TABLE.TIME_COLUMN=CURRENT_TIME AND TABLE.DATE_COLUMN=CURRENT_DATE"; String result = null; try { result = BasePeer.createQueryString(c); } catch (TorqueException e) { e.printStackTrace(); fail("TorqueException thrown in BasePeer.createQueryString()"); } assertEquals(expect,result); } /** * This test case has been written to try out the fix applied to resolve * TRQS73 - i.e. ensuring that Criteria.toString() does not alter any limit * or offset that may be stored in the Criteria object. This testcase * could actually pass without the fix if the database in use does not * support native limits and offsets. */ public void testCriteriaToStringOffset() { Criteria c = new Criteria() .add("TABLE.DATE_COLUMN", Criteria.CURRENT_DATE) .setOffset(3) .setLimit(5); String toStringExpect = "Criteria:: TABLE.DATE_COLUMN<=>TABLE.DATE_COLUMN=CURRENT_DATE: " + "\nCurrent Query SQL (may not be complete or applicable): " + "SELECT FROM TABLE WHERE TABLE.DATE_COLUMN=CURRENT_DATE LIMIT 3, 5"; String cString = c.toString(); //System.out.println(cString); assertEquals(toStringExpect, cString); // Note that this is intentially the same as above as the behaviour is // only observed on subsequent invocations of toString(). cString = c.toString(); //System.out.println(cString); assertEquals(toStringExpect, cString); } /** * This test case has been written to try out the fix applied to resolve * TRQS73 - i.e. ensuring that Criteria.toString() does not alter any limit * or offset that may be stored in the Criteria object. This testcase * could actually pass without the fix if the database in use does not * support native limits and offsets. */ public void testCriteriaToStringLimit() { Criteria c = new Criteria() .add("TABLE.DATE_COLUMN", Criteria.CURRENT_DATE) .setLimit(5); String toStringExpect = "Criteria:: TABLE.DATE_COLUMN<=>TABLE.DATE_COLUMN=CURRENT_DATE: " + "\nCurrent Query SQL (may not be complete or applicable): " + "SELECT FROM TABLE WHERE TABLE.DATE_COLUMN=CURRENT_DATE LIMIT 5"; String cString = c.toString(); //System.out.println(cString); assertEquals(toStringExpect, cString); // Note that this is intentially the same as above as the behaviour is // only observed on subsequent invocations of toString(). cString = c.toString(); //System.out.println(cString); assertEquals(toStringExpect, cString); } /** * This test case verifies if the Criteria.LIKE comparison type will * get replaced through Criteria.EQUAL if there are no SQL wildcards * in the given value. */ public void testLikeWithoutWildcards() { Criteria c = new Criteria(); c.add("TABLE.COLUMN", (Object) "no wildcards", Criteria.LIKE); String expect = "SELECT FROM TABLE WHERE TABLE.COLUMN = 'no wildcards'"; String result = null; try { result = BasePeer.createQueryString(c); } catch (TorqueException e) { e.printStackTrace(); fail("TorqueException thrown in BasePeer.createQueryString()"); } assertEquals(expect, result); } /** * This test case verifies if the Criteria.NOT_LIKE comparison type will * get replaced through Criteria.NOT_EQUAL if there are no SQL wildcards * in the given value. */ public void testNotLikeWithoutWildcards() { Criteria c = new Criteria(); c.add("TABLE.COLUMN", (Object) "no wildcards", Criteria.NOT_LIKE); String firstExpect = "SELECT FROM TABLE WHERE TABLE.COLUMN != 'no wildcards'"; String secondExpect = "SELECT FROM TABLE WHERE TABLE.COLUMN <> 'no wildcards'"; String result = null; try { result = BasePeer.createQueryString(c); } catch (TorqueException e) { e.printStackTrace(); fail("TorqueException thrown in BasePeer.createQueryString()"); } assertTrue(result.equals(firstExpect) || result.equals(secondExpect)); } /** * test for TRQS25 *//* public void testCriteriaAndString() { Criteria c = new Criteria() .add("TABLE.COLUMN1", "string") .and("TABLE.COLUMN2", "string", Criteria.LIKE); }*/}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -