1
2
3
4 package org.melati.poem.test;
5
6 import org.melati.poem.CachedCount;
7 import org.melati.poem.Table;
8 import org.melati.poem.User;
9
10
11
12
13
14 public class CachedCountTest extends PoemTestCase {
15
16 public CachedCountTest(String name) {
17 super(name);
18 }
19
20 protected void setUp()
21 throws Exception {
22 super.setUp();
23 }
24
25 protected void tearDown()
26 throws Exception {
27 super.tearDown();
28 }
29
30
31
32
33 public void testCachedCountTableStringTableArray() {
34
35 int queries = getDb().getQueryCount();
36 CachedCount cc = new CachedCount(getDb().getUserTable(),
37 getDb().getUserTable().troidColumn().fullQuotedName() + " = 0", null);
38 int queries2 = getDb().getQueryCount();
39 assertEquals(queries, queries2);
40 assertEquals(1, cc.count());
41 int queries3 = getDb().getQueryCount();
42 assertEquals(queries2 + 1, queries3);
43 assertEquals(1, cc.count());
44 int queries4 = getDb().getQueryCount();
45 assertEquals(queries3, queries4);
46 }
47
48
49
50
51 public void testCachedCountPersistentBooleanBoolean() {
52 int queries = getDb().getQueryCount();
53 User u = (User)getDb().getUserTable().newPersistent();
54 u.setName("guest");
55 CachedCount cc = new CachedCount(u,false,true);
56 int queries2 = getDb().getQueryCount();
57 assertEquals(queries, queries2);
58 assertEquals(1, cc.count());
59 int queries3 = getDb().getQueryCount();
60 assertEquals(queries2 + 1, queries3);
61 assertEquals(1, cc.count());
62 int queries4 = getDb().getQueryCount();
63 assertEquals(queries3, queries4);
64 }
65
66
67
68
69 public void testCachedCountTableString() {
70 int queries = getDb().getQueryCount();
71 CachedCount cc = new CachedCount(getDb().getUserTable(),
72 getDb().getUserTable().troidColumn().fullQuotedName() + " = 0");
73 int queries2 = getDb().getQueryCount();
74 assertEquals(queries, queries2);
75 assertEquals(1, cc.count());
76 int queries3 = getDb().getQueryCount();
77 assertEquals(queries2 + 1, queries3);
78 assertEquals(1, cc.count());
79 int queries4 = getDb().getQueryCount();
80 assertEquals(queries3, queries4);
81
82 }
83
84
85
86
87 public void testCount() {
88 int queries = getDb().getQueryCount();
89 CachedCount cc = new CachedCount(getDb().getUserTable(), null, null);
90 int queries2 = getDb().getQueryCount();
91 assertEquals(queries, queries2);
92 assertEquals(2, cc.count());
93 int queries3 = getDb().getQueryCount();
94 assertEquals(queries2 + 1, queries3);
95 assertEquals(2, cc.count());
96 int queries4 = getDb().getQueryCount();
97 assertEquals(queries3, queries4);
98 }
99
100 }