My favorites | Sign in
Project Home Downloads Issues Source
Checkout   Browse   Changes    
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
/**
* Copyright (C) 2010 altuure <altuure [AT] gmail [DOT] com> http://www.altuure.com/projects/yagdao
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.altuure.yagdao.base;

import com.altuure.yagdao.SearchResultList;
import com.altuure.yagdao.YApply;
import com.altuure.yagdao.YLimit;
import com.altuure.yagdao.model.SimpleBean;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;

import java.util.HashSet;
import java.util.List;

import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;

/** test case for simpleBeanDAO for hibernate */
@RunWith(Parameterized.class)
public class SimpleDAOAppendTest extends HelperTest {

public SimpleDAOAppendTest(DAOTestHelper helper) {
super(helper);
}

@Test
public void append0() {
List<SimpleBean> list = (List<SimpleBean>) executePageQuery("select s from SimpleBean s where s.pbyte>=5 and s.pbyte<=7", null);
List<SimpleBean> loadAll = simpleBeanAppendDAO.append0((byte)5,(byte)7);
assertEquals(list.size(), loadAll.size());
assertEquals(new HashSet<SimpleBean>(list), new HashSet<SimpleBean>(loadAll));
}

@Test
public void append1() {
List<SimpleBean> list = (List<SimpleBean>) executePageQuery("select s.pbyte from SimpleBean s where s.pbyte>=5 and s.pbyte<=7", null);
List<SimpleBean> loadAll = simpleBeanAppendDAO.append1((byte)5,(byte)7);
assertEquals(list.size(), loadAll.size());
assertEquals(new HashSet<SimpleBean>(list), new HashSet<SimpleBean>(loadAll));
}

@Test
public void append2() {
List list = (List<SimpleBean>) executePageQuery("select s.pbyte,count(id) from SimpleBean s where s.pint>=20000 group by pbyte", null);
List loadAll = simpleBeanAppendDAO.append2(20000);
assertEquals(list.size(), loadAll.size());
for (int i = 0; i < loadAll.size(); i++) {
Object[] array1 = (Object[]) loadAll.get(i);
Object[] array2 = (Object[]) list.get(i);
assertArrayEquals(array1,array2);

}

}
@Test
public void append3() {
List list = (List) executePageQuery("select s.pbyte,count(id) from SimpleBean s where s.pint>=20000 group by pbyte having count(id)>10", null);
List loadAll = simpleBeanAppendDAO.append3(20000);
assertEquals(list.size(), loadAll.size());

for (int i = 0; i < loadAll.size(); i++) {
Object[] array1 = (Object[]) loadAll.get(i);
Object[] array2 = (Object[]) list.get(i);
assertArrayEquals(array1,array2);

}
}
@Test
public void append4_1() {
List<SimpleBean> list = (List<SimpleBean>) executePageQuery("select s from SimpleBean s where s.pstringNullable is null", null);
List<SimpleBean> loadAll = simpleBeanAppendDAO.append4_1(YApply.TRUE);
assertEquals(list.size(), loadAll.size());
assertEquals(new HashSet<SimpleBean>(list), new HashSet<SimpleBean>(loadAll));


}
@Test
public void append4() {
List<SimpleBean> list = (List<SimpleBean>) executePageQuery("select s from SimpleBean s where s.pstringNullable = ?", null,new Object[]{null});
List<SimpleBean> loadAll2 = simpleBeanAppendDAO.append4_2(null);
assertEquals(list.size(), loadAll2.size());
assertEquals(new HashSet<SimpleBean>(list), new HashSet<SimpleBean>(loadAll2));


}

@Test
public void appendPage1_a() {
Number n = (Number) executeSingleQuery("select count (*) from SimpleBean s where s.pbyte>=5 ");
List<SimpleBean> list = (List<SimpleBean>) executePageQuery("select s from SimpleBean s where s.pbyte>=5 order by s.id", new YLimit(2,100));
SearchResultList<SimpleBean> loadAll = simpleBeanAppendDAO.appendPage1((byte)5,new YLimit(2,100));
assertEquals(list.size(), loadAll.size());
assertEquals(new HashSet<SimpleBean>(list), new HashSet<SimpleBean>(loadAll));
assertEquals(loadAll.totalCount(),n.intValue());

}
@Test
public void appendPage1_b() {
Number n = (Number) executeSingleQuery("select count (*) from SimpleBean s where s.pbyte>=5 ");
List<SimpleBean> list = (List<SimpleBean>) executePageQuery("select s from SimpleBean s where s.pbyte>=5 order by s.id desc",null);
SearchResultList<SimpleBean> loadAll = simpleBeanAppendDAO.appendPage1((byte)5,null);
assertEquals(list.size(), loadAll.size());
assertEquals(new HashSet<SimpleBean>(list), new HashSet<SimpleBean>(loadAll));
assertEquals(loadAll.totalCount(),n.intValue());
assertEquals(loadAll.totalCount(),list.size());

}

}

Change log

r59 by mcakkan on Dec 9, 2010   Diff
[maven-release-plugin]  copy for tag
com.altuure.yagdao-0.3
Go to: 
Project members, sign in to write a code review

Older revisions

r55 by mcakkan on Dec 9, 2010   Diff
appaned query result set handling and
paging
r54 by mcakkan on Dec 4, 2010   Diff
acceptNull
All revisions of this file

File info

Size: 5382 bytes, 124 lines
Powered by Google Project Hosting