1
1
/*
2
- * Copyright 2002-2016 the original author or authors.
2
+ * Copyright 2002-2017 the original author or authors.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
20
20
import static org .junit .Assert .fail ;
21
21
import static org .mockito .Mockito .mock ;
22
22
23
- import javax .sql .DataSource ;
24
-
25
23
import org .junit .Assert ;
26
24
import org .junit .Test ;
27
25
28
26
import org .springframework .beans .factory .BeanFactory ;
29
27
import org .springframework .jdbc .core .JdbcOperations ;
28
+ import org .springframework .jdbc .datasource .embedded .EmbeddedDatabase ;
30
29
import org .springframework .jdbc .datasource .embedded .EmbeddedDatabaseBuilder ;
31
30
32
31
/**
33
32
*
34
33
* @author Gunnar Hillert
35
34
* @author Gary Russell
35
+ * @author Artem Bilan
36
+ *
36
37
* @since 2.1
37
38
*
38
39
*/
39
40
public class JdbcOutboundGatewayTests {
40
41
41
42
@ Test
42
43
public void testSetMaxRowsPerPollWithoutSelectQuery () {
43
-
44
-
45
- DataSource dataSource = new EmbeddedDatabaseBuilder ().build ();
44
+ EmbeddedDatabase dataSource = new EmbeddedDatabaseBuilder ().build ();
46
45
47
46
JdbcOutboundGateway jdbcOutboundGateway = new JdbcOutboundGateway (dataSource , "update something" );
48
47
@@ -51,18 +50,17 @@ public void testSetMaxRowsPerPollWithoutSelectQuery() {
51
50
jdbcOutboundGateway .setBeanFactory (mock (BeanFactory .class ));
52
51
jdbcOutboundGateway .afterPropertiesSet ();
53
52
53
+ fail ("Expected an IllegalArgumentException to be thrown." );
54
54
}
55
55
catch (IllegalArgumentException e ) {
56
56
assertEquals ("If you want to set 'maxRowsPerPoll', then you must provide a 'selectQuery'." , e .getMessage ());
57
- return ;
58
57
}
59
58
60
- fail ("Expected an IllegalArgumentException to be thrown." );
61
-
59
+ dataSource .shutdown ();
62
60
}
63
61
64
62
@ Test
65
- public void testConstructorWithNulljdbcOperations () {
63
+ public void testConstructorWithNullJdbcOperations () {
66
64
67
65
JdbcOperations jdbcOperations = null ;
68
66
@@ -79,44 +77,39 @@ public void testConstructorWithNulljdbcOperations() {
79
77
80
78
@ Test
81
79
public void testConstructorWithEmptyAndNullQueries () {
82
-
83
- final DataSource dataSource = new EmbeddedDatabaseBuilder ().build ();
80
+ EmbeddedDatabase dataSource = new EmbeddedDatabaseBuilder ().build ();
84
81
85
82
final String selectQuery = " " ;
86
83
final String updateQuery = null ;
87
84
88
85
try {
89
86
new JdbcOutboundGateway (dataSource , updateQuery , selectQuery );
87
+
88
+ fail ("Expected an IllegalArgumentException to be thrown." );
90
89
}
91
90
catch (IllegalArgumentException e ) {
92
91
Assert .assertEquals ("The 'updateQuery' and the 'selectQuery' must not both be null or empty." , e .getMessage ());
93
- return ;
94
92
}
95
93
96
- fail ( "Expected an IllegalArgumentException to be thrown." );
94
+ dataSource . shutdown ( );
97
95
}
98
96
99
- /**
100
- * Test method for
101
- * {@link org.springframework.integration.jdbc.JdbcOutboundGateway#setMaxRowsPerPoll(Integer)}.
102
- */
103
97
@ Test
104
98
public void testSetMaxRowsPerPoll () {
105
-
106
-
107
- DataSource dataSource = new EmbeddedDatabaseBuilder ().build ();
99
+ EmbeddedDatabase dataSource = new EmbeddedDatabaseBuilder ().build ();
108
100
109
101
JdbcOutboundGateway jdbcOutboundGateway = new JdbcOutboundGateway (dataSource , "select * from DOES_NOT_EXIST" );
110
102
111
103
try {
112
104
jdbcOutboundGateway .setMaxRowsPerPoll (null );
105
+
106
+ fail ("Expected an IllegalArgumentException to be thrown." );
113
107
}
114
108
catch (IllegalArgumentException e ) {
115
109
assertEquals ("MaxRowsPerPoll must not be null." , e .getMessage ());
116
- return ;
117
110
}
118
111
119
- fail ("Expected an IllegalArgumentException to be thrown." );
120
-
112
+ dataSource .shutdown ();
121
113
}
114
+
122
115
}
0 commit comments