17
17
package org .neo4j .driver .internal ;
18
18
19
19
import static org .junit .jupiter .api .Assertions .assertEquals ;
20
+ import static org .junit .jupiter .api .Assertions .assertNull ;
20
21
import static org .junit .jupiter .api .Assertions .assertThrows ;
21
22
import static org .mockito .ArgumentMatchers .any ;
22
23
import static org .mockito .ArgumentMatchers .eq ;
35
36
import org .junit .jupiter .params .provider .MethodSource ;
36
37
import org .mockito .ArgumentCaptor ;
37
38
import org .neo4j .driver .AccessMode ;
39
+ import org .neo4j .driver .AuthTokens ;
38
40
import org .neo4j .driver .BookmarkManager ;
39
41
import org .neo4j .driver .Driver ;
40
42
import org .neo4j .driver .ExecutableQuery ;
43
45
import org .neo4j .driver .Record ;
44
46
import org .neo4j .driver .Result ;
45
47
import org .neo4j .driver .RoutingControl ;
48
+ import org .neo4j .driver .Session ;
46
49
import org .neo4j .driver .SessionConfig ;
47
50
import org .neo4j .driver .TransactionCallback ;
48
51
import org .neo4j .driver .TransactionConfig ;
@@ -55,27 +58,27 @@ class InternalExecutableQueryTest {
55
58
void shouldNotAcceptNullDriverOnInstantiation () {
56
59
assertThrows (
57
60
NullPointerException .class ,
58
- () -> new InternalExecutableQuery (null , new Query ("string" ), QueryConfig .defaultConfig ()));
61
+ () -> new InternalExecutableQuery (null , new Query ("string" ), QueryConfig .defaultConfig (), null ));
59
62
}
60
63
61
64
@ Test
62
65
void shouldNotAcceptNullQueryOnInstantiation () {
63
66
assertThrows (
64
67
NullPointerException .class ,
65
- () -> new InternalExecutableQuery (mock (Driver .class ), null , QueryConfig .defaultConfig ()));
68
+ () -> new InternalExecutableQuery (mock (Driver .class ), null , QueryConfig .defaultConfig (), null ));
66
69
}
67
70
68
71
@ Test
69
72
void shouldNotAcceptNullConfigOnInstantiation () {
70
73
assertThrows (
71
74
NullPointerException .class ,
72
- () -> new InternalExecutableQuery (mock (Driver .class ), new Query ("string" ), null ));
75
+ () -> new InternalExecutableQuery (mock (Driver .class ), new Query ("string" ), null , null ));
73
76
}
74
77
75
78
@ Test
76
79
void shouldNotAcceptNullParameters () {
77
80
var executableQuery =
78
- new InternalExecutableQuery (mock (Driver .class ), new Query ("string" ), QueryConfig .defaultConfig ());
81
+ new InternalExecutableQuery (mock (Driver .class ), new Query ("string" ), QueryConfig .defaultConfig (), null );
79
82
assertThrows (NullPointerException .class , () -> executableQuery .withParameters (null ));
80
83
}
81
84
@@ -84,7 +87,7 @@ void shouldUpdateParameters() {
84
87
// GIVEN
85
88
var query = new Query ("string" );
86
89
var params = Map .<String , Object >of ("$param" , "value" );
87
- var executableQuery = new InternalExecutableQuery (mock (Driver .class ), query , QueryConfig .defaultConfig ());
90
+ var executableQuery = new InternalExecutableQuery (mock (Driver .class ), query , QueryConfig .defaultConfig (), null );
88
91
89
92
// WHEN
90
93
executableQuery = (InternalExecutableQuery ) executableQuery .withParameters (params );
@@ -96,15 +99,15 @@ void shouldUpdateParameters() {
96
99
@ Test
97
100
void shouldNotAcceptNullConfig () {
98
101
var executableQuery =
99
- new InternalExecutableQuery (mock (Driver .class ), new Query ("string" ), QueryConfig .defaultConfig ());
102
+ new InternalExecutableQuery (mock (Driver .class ), new Query ("string" ), QueryConfig .defaultConfig (), null );
100
103
assertThrows (NullPointerException .class , () -> executableQuery .withConfig (null ));
101
104
}
102
105
103
106
@ Test
104
107
void shouldUpdateConfig () {
105
108
// GIVEN
106
109
var query = new Query ("string" );
107
- var executableQuery = new InternalExecutableQuery (mock (Driver .class ), query , QueryConfig .defaultConfig ());
110
+ var executableQuery = new InternalExecutableQuery (mock (Driver .class ), query , QueryConfig .defaultConfig (), null );
108
111
var config = QueryConfig .builder ().withDatabase ("database" ).build ();
109
112
110
113
// WHEN
@@ -127,7 +130,8 @@ void shouldExecuteAndReturnResult(RoutingControl routingControl) {
127
130
var bookmarkManager = mock (BookmarkManager .class );
128
131
given (driver .executableQueryBookmarkManager ()).willReturn (bookmarkManager );
129
132
var session = mock (InternalSession .class );
130
- given (driver .session (any (SessionConfig .class ))).willReturn (session );
133
+ given (driver .session (eq (Session .class ), any (SessionConfig .class ), eq (null )))
134
+ .willReturn (session );
131
135
var txContext = mock (TransactionContext .class );
132
136
var accessMode = routingControl .equals (RoutingControl .WRITE ) ? AccessMode .WRITE : AccessMode .READ ;
133
137
given (session .execute (
@@ -169,14 +173,14 @@ var record = mock(Record.class);
169
173
var expectedExecuteResult = "1" ;
170
174
given (finisherWithSummary .finish (any (List .class ), any (String .class ), any (ResultSummary .class )))
171
175
.willReturn (expectedExecuteResult );
172
- var executableQuery = new InternalExecutableQuery (driver , query , config ).withParameters (params );
176
+ var executableQuery = new InternalExecutableQuery (driver , query , config , null ).withParameters (params );
173
177
174
178
// WHEN
175
179
var executeResult = executableQuery .execute (recordCollector , finisherWithSummary );
176
180
177
181
// THEN
178
182
var sessionConfigCapture = ArgumentCaptor .forClass (SessionConfig .class );
179
- then (driver ).should ().session (sessionConfigCapture .capture ());
183
+ then (driver ).should ().session (eq ( Session . class ), sessionConfigCapture .capture (), eq ( null ));
180
184
var sessionConfig = sessionConfigCapture .getValue ();
181
185
@ SuppressWarnings ("OptionalGetWithoutIsPresent" )
182
186
var expectedSessionConfig = SessionConfig .builder ()
@@ -205,4 +209,25 @@ var record = mock(Record.class);
205
209
then (finisherWithSummary ).should ().finish (keys , collectorResult , summary );
206
210
assertEquals (expectedExecuteResult , executeResult );
207
211
}
212
+
213
+ @ Test
214
+ void shouldAllowNullAuthToken () {
215
+ var executableQuery =
216
+ new InternalExecutableQuery (mock (Driver .class ), new Query ("string" ), QueryConfig .defaultConfig (), null );
217
+
218
+ executableQuery .withAuthToken (null );
219
+
220
+ assertNull (executableQuery .authToken ());
221
+ }
222
+
223
+ @ Test
224
+ void shouldUpdateAuthToken () {
225
+ var executableQuery =
226
+ new InternalExecutableQuery (mock (Driver .class ), new Query ("string" ), QueryConfig .defaultConfig (), null );
227
+ var authToken = AuthTokens .basic ("user" , "password" );
228
+
229
+ executableQuery = (InternalExecutableQuery ) executableQuery .withAuthToken (authToken );
230
+
231
+ assertEquals (authToken , executableQuery .authToken ());
232
+ }
208
233
}
0 commit comments