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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
/**
* 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.jpa.JpaDAOTestHelper;
import com.altuure.yagdao.model.SimpleBean;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runners.Parameterized.Parameters;

import java.util.*;

import static org.junit.Assert.assertEquals;

/** test case for simpleBeanDAO for hibernate */
public class SimpleDAOCriteriaNewTest extends HelperTest {

private static final Integer PINT_MEDIUM = 20000;

public SimpleDAOCriteriaNewTest(DAOTestHelper helper) {
super(helper);

}
@Test
public void criteriaQuery0() {
byte arg1 = 100;
List<SimpleBean> list = (List<SimpleBean>) executePageQuery("from SimpleBean s where s.pbyte=:arg1", null,
map("arg1", arg1));

List<SimpleBean> loadAll = simpleBeanNewDAO.criteria0(arg1);
assertEquals(list.size(), loadAll.size());
assertEquals(new HashSet<SimpleBean>(list), new HashSet<SimpleBean>(loadAll));
}
@Test
public void criteriaQuery1() {
int arg1 = 20000;
List<SimpleBean> list = (List<SimpleBean>) executePageQuery("from SimpleBean s where s.pint>=:arg1", null,
map("arg1", arg1));

List<SimpleBean> loadAll = simpleBeanNewDAO.criteria1(arg1);
assertEquals(list.size(), loadAll.size());
assertEquals(new HashSet<SimpleBean>(list), new HashSet<SimpleBean>(loadAll));
}
@Test
public void criteria1CheckApplied() {
int arg1 = 20000;
List<SimpleBean> list = (List<SimpleBean>) executePageQuery("from SimpleBean s where s.pint>=:arg1", null,
map("arg1", arg1));

List<SimpleBean> loadAll = simpleBeanNewDAO.criteria1CheckApplied(true);
assertEquals(list.size(), loadAll.size());
assertEquals(new HashSet<SimpleBean>(list), new HashSet<SimpleBean>(loadAll));
}
@Test
public void criteriaWhereOr() {
int arg1 = 20000;
List<SimpleBean> list = (List<SimpleBean>) executePageQuery("from SimpleBean s where pint>=50000 or pint<=30000", null);

List<SimpleBean> loadAll = simpleBeanNewDAO.criteriaWhereOr();
assertEquals(list.size(), loadAll.size());
assertEquals(new HashSet<SimpleBean>(list), new HashSet<SimpleBean>(loadAll));
}
@Test
public void criteriaWhereAnd() {
int arg1 = 20000;
List<SimpleBean> list = (List<SimpleBean>) executePageQuery("from SimpleBean s where pint>=20000 and pint<=50000", null);

List<SimpleBean> loadAll = simpleBeanNewDAO.criteriaWhereAnd();
assertEquals(list.size(), loadAll.size());
assertEquals(new HashSet<SimpleBean>(list), new HashSet<SimpleBean>(loadAll));
}
@Test
public void criteriaQuery2() {
int arg1 = 20000;
int arg2 = 50000;
List<SimpleBean> list = (List<SimpleBean>) executePageQuery("from SimpleBean s where s.pint>=:arg1 and s.pint<=:arg2", null,
map("arg1", arg1,"arg2",arg2));


List<SimpleBean> loadAll = simpleBeanNewDAO.criteria2(arg1,arg2);
assertEquals(list.size(), loadAll.size());
assertEquals(new HashSet<SimpleBean>(list), new HashSet<SimpleBean>(loadAll));
}
@Test
public void criteriaQuery3() {

List<SimpleBean> list = (List<SimpleBean>) executePageQuery("from SimpleBean s where s.pstring is null", null);


List<SimpleBean> loadAll = simpleBeanNewDAO.criteria3(true);
assertEquals(list.size(), loadAll.size());
assertEquals(new HashSet<SimpleBean>(list), new HashSet<SimpleBean>(loadAll));
}
@Test
public void criteria2CheckApplied() {
int arg1 = 20000;
int arg2 = 50000;
List<SimpleBean> list = (List<SimpleBean>) executePageQuery("from SimpleBean s where s.pint>=:arg1 and s.pint<=:arg2", null,
map("arg1", arg1,"arg2",arg2));

List<SimpleBean> loadAll = simpleBeanNewDAO.criteria2CheckApplied(true,true);
assertEquals(list.size(), loadAll.size());
assertEquals(new HashSet<SimpleBean>(list), new HashSet<SimpleBean>(loadAll));

// partial applicaed parameters
list = (List<SimpleBean>) executePageQuery("from SimpleBean s where s.pint>=:arg1 ", null,

map("arg1", arg1));

loadAll = simpleBeanNewDAO.criteria2CheckApplied(true,false);
assertEquals(list.size(), loadAll.size());
assertEquals(new HashSet<SimpleBean>(list), new HashSet<SimpleBean>(loadAll));
}

@Test
public void criteriaGroup1() {

List<Object[]> list = (List<Object[]>) executePageQuery("select count(id),pbyte from SimpleBean s group by pbyte", null);

List<Object[]> loadAll = simpleBeanNewDAO.criteriaGroup1();
assertEquals(list.size(), loadAll.size());
// assertEquals(new HashSet<Object[]>(list), new HashSet<Object[]>(loadAll));
HashMap map1 = new HashMap();
HashMap map2 = new HashMap();
for (int i = 0; i < list.size(); i++) {
Object[] array1 = list.get(i);
Object[] array2 = loadAll.get(i);
Assert.assertArrayEquals(array1,array2);
}

// partial applicaed parameters

}
@Test
public void criteriaGroup2() {

List<Object[]> list = (List<Object[]>) executePageQuery("select count(id),month(pdate) from SimpleBean s group by month(pdate)", null);

List<Object[]> loadAll = simpleBeanNewDAO.criteriaGroup2();
assertEquals(list.size(), loadAll.size());
// assertEquals(new HashSet<Object[]>(list), new HashSet<Object[]>(loadAll));
HashMap map1 = new HashMap();
HashMap map2 = new HashMap();
for (int i = 0; i < list.size(); i++) {
Object[] array1 = list.get(i);
Object[] array2 = loadAll.get(i);
Assert.assertArrayEquals(array1,array2);
}

// partial applicaed parameters

}
@Test
public void criteriaGroupHaving() {

List<Object[]> list = (List<Object[]>) executePageQuery("select count(id),pbyte,sum(pint) from SimpleBean s group by pbyte having count(id)>9", null);

List<Object[]> loadAll = simpleBeanNewDAO.criteriaGroupHaving();
assertEquals(list.size(), loadAll.size());
// assertEquals(new HashSet<Object[]>(list), new HashSet<Object[]>(loadAll));
HashMap map1 = new HashMap();
HashMap map2 = new HashMap();
for (int i = 0; i < list.size(); i++) {
Object[] array1 = list.get(i);
Object[] array2 = loadAll.get(i);
Assert.assertArrayEquals(array1,array2);
}

// partial applicaed parameters

}
@Test
public void criteriaDateFunctions() {

List<Object[]> list = (List<Object[]>) executePageQuery("select id,year(pdate),month(pdate),day(pdate),hour(pdate),minute(pdate),second(pdate),current_time(),current_timestamp(),current_date()" +
" from SimpleBean s where s.id=2", null);

List<Object[]> loadAll = simpleBeanNewDAO.criteriaDateFunctions();
assertEquals(list.size(), loadAll.size());
// assertEquals(new HashSet<Object[]>(list), new HashSet<Object[]>(loadAll));
HashMap map1 = new HashMap();
HashMap map2 = new HashMap();
for (int i = 0; i < list.size(); i++) {
Object[] array1 = list.get(i);
Object[] array2 = loadAll.get(i);
//ignore time and seconds
array1[6]=array1[7]=array1[8]=array1[9]=
array2[6]=array2[7]=array2[8]=array2[9]=null;
Assert.assertArrayEquals(array1,array2);
}

// partial applicaed parameters

}


@Parameters
public static Collection<Object[]> data() {


return Arrays.asList(new Object[][] {

{ JpaDAOTestHelper.getInstance() }});

}
}

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

r48 by mcakkan on Dec 4, 2010   Diff
optimize imports
r44 by mcakkan on Dec 1, 2010   Diff
jpa release ready
r43 by mcakkan on Nov 30, 2010   Diff
jpa final , almost
All revisions of this file

File info

Size: 8975 bytes, 220 lines
Powered by Google Project Hosting