1
1
/*
2
- Copyright 2009-2014 Igor Polevoy
2
+ Copyright 2009-2015 Igor Polevoy
3
3
4
- Licensed under the Apache License, Version 2.0 (the "License");
5
- you may not use this file except in compliance with the License.
6
- You may obtain a copy of the License at
4
+ Licensed under the Apache License, Version 2.0 (the "License");
5
+ you may not use this file except in compliance with the License.
6
+ You may obtain a copy of the License at
7
7
8
- http://www.apache.org/licenses/LICENSE-2.0
8
+ http://www.apache.org/licenses/LICENSE-2.0
9
9
10
- Unless required by applicable law or agreed to in writing, software
11
- distributed under the License is distributed on an "AS IS" BASIS,
12
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
- See the License for the specific language governing permissions and
14
- limitations under the License.
10
+ Unless required by applicable law or agreed to in writing, software
11
+ distributed under the License is distributed on an "AS IS" BASIS,
12
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ See the License for the specific language governing permissions and
14
+ limitations under the License.
15
15
*/
16
-
17
-
18
16
package org .javalite .activejdbc ;
19
17
20
- import org .javalite .activejdbc .Base ;
21
- import org .javalite .activejdbc .RowListenerAdapter ;
22
18
import org .javalite .activejdbc .test .ActiveJDBCTest ;
23
19
import org .junit .Test ;
24
20
@@ -36,7 +32,7 @@ public void before() throws Exception {
36
32
}
37
33
38
34
@ Test
39
- public void testBaseFinder () {
35
+ public void testBaseFindWith () {
40
36
final List <Map > records = new ArrayList <Map >();
41
37
Base .findWith (new RowListenerAdapter () {
42
38
@ Override public void onNext (Map record ) {
@@ -48,23 +44,32 @@ public void testBaseFinder() {
48
44
}
49
45
50
46
@ Test
51
- public void testBaseFindAll () {
47
+ public void testBaseFind () {
48
+ final List <Map > records = new ArrayList <Map >();
49
+ Base .find ("select * from people order by id" , new RowListenerAdapter () {
50
+ @ Override public void onNext (Map record ) {
51
+ records .add (record );
52
+ }
53
+ });
54
+ the (records .get (0 ).get ("name" )).shouldBeEqual ("John" );
55
+ the (records .get (3 ).get ("name" )).shouldBeEqual ("Joe" );
56
+ }
52
57
58
+ @ Test
59
+ public void testBaseFindAll () {
53
60
List <Map > records = Base .findAll ("select * from people" );
54
61
a (records .size ()).shouldBeEqual (4 );
55
62
}
56
63
57
64
@ Test
58
65
public void testBaseFindAllParametrized () {
59
-
60
66
List <Map > records = Base .findAll ("select * from people where last_name = ? and name = ?" , "Smith" , "John" );
61
67
a (records .size ()).shouldBeEqual (1 );
62
68
}
63
69
64
70
@ Test
65
71
public void testExec () {
66
72
int count = Base .exec ("insert into people (NAME, LAST_NAME, DOB) values('Mic', 'Jagger', ?)" , getTimestamp (1962 , 6 , 13 ));
67
-
68
73
List <Map > results = Base .findAll ("select * from people where last_name='Jagger'" );
69
74
a (1 ).shouldBeEqual (results .size ());
70
75
a (1 ).shouldBeEqual (count );
@@ -79,18 +84,30 @@ public void testExecDelete() {
79
84
@ Test
80
85
public void testExecParametrized () {
81
86
Base .exec ("insert into people (name, last_name, dob) values(?, ?, ?)" , "John" , "Silver" , getTimestamp (1934 , 2 , 5 ));
82
-
83
87
List <Map > results = Base .findAll ("select * from people where last_name=?" , "Silver" );
84
88
a (1 ).shouldBeEqual (results .size ());
85
89
}
86
90
87
91
@ Test
88
- public void testFindParametrized (){
92
+ public void testFindWithParametrized () {
93
+ final StringBuilder sb = new StringBuilder ();
89
94
Base .findWith (new RowListenerAdapter () {
90
95
@ Override public void onNext (Map <String , Object > row ) {
91
- System .out .println (row );
96
+ sb .append (row .get ("last_name" ));
97
+ }
98
+ }, true , "select last_name from people where id > ? order by id" , 1 );
99
+ the (sb .toString ()).shouldBeEqual ("JonstonAliPesci" );
100
+ }
101
+
102
+ @ Test
103
+ public void testFindParametrized () {
104
+ final StringBuilder sb = new StringBuilder ();
105
+ Base .find ("select last_name from people where id > ? order by id" , 1 ).with (new RowListenerAdapter () {
106
+ @ Override public void onNext (Map <String , Object > row ) {
107
+ sb .append (row .get ("last_name" ));
92
108
}
93
- }, true , "select * from people where id > ? and dob > ?" , 1 , getTimestamp (1935 , 1 , 1 ));
109
+ });
110
+ the (sb .toString ()).shouldBeEqual ("JonstonAliPesci" );
94
111
}
95
112
96
113
@ Test
0 commit comments