72
72
import static org .assertj .core .api .InstanceOfAssertFactories .LIST ;
73
73
import static org .assertj .core .api .InstanceOfAssertFactories .MAP ;
74
74
import static org .openqa .selenium .json .Json .MAP_TYPE ;
75
- import static org .openqa .selenium .remote .http .Contents .asJson ;
76
75
import static org .openqa .selenium .remote .http .Contents .utf8String ;
77
76
import static org .openqa .selenium .remote .http .HttpMethod .GET ;
78
77
import static org .openqa .selenium .remote .http .HttpMethod .POST ;
@@ -83,8 +82,8 @@ public class GraphqlHandlerTest {
83
82
84
83
private final Secret registrationSecret = new Secret ("stilton" );
85
84
private final URI publicUri = new URI ("http://example.com/grid-o-matic" );
85
+ private final String version = "4.0.0" ;
86
86
private Distributor distributor ;
87
- private LocalNewSessionQueue localNewSessionQueue ;
88
87
private NewSessionQueuer queuer ;
89
88
private Tracer tracer ;
90
89
private EventBus events ;
@@ -107,7 +106,7 @@ public void setupGrid() {
107
106
caps = new ImmutableCapabilities ("browserName" , "cheese" );
108
107
payload = NewSessionPayload .create (caps );
109
108
110
- localNewSessionQueue = new LocalNewSessionQueue (
109
+ LocalNewSessionQueue localNewSessionQueue = new LocalNewSessionQueue (
111
110
tracer ,
112
111
events ,
113
112
Duration .ofSeconds (2 ),
@@ -130,7 +129,7 @@ public void setupGrid() {
130
129
131
130
@ Test
132
131
public void shouldBeAbleToGetGridUri () {
133
- GraphqlHandler handler = new GraphqlHandler (tracer , distributor , queuer , publicUri );
132
+ GraphqlHandler handler = new GraphqlHandler (tracer , distributor , queuer , publicUri , version );
134
133
135
134
Map <String , Object > topLevel = executeQuery (handler , "{ grid { uri } }" );
136
135
@@ -141,9 +140,22 @@ public void shouldBeAbleToGetGridUri() {
141
140
"uri" , publicUri .toString ()))));
142
141
}
143
142
143
+ @ Test
144
+ public void shouldBeAbleToGetGridVersion () {
145
+ GraphqlHandler handler = new GraphqlHandler (tracer , distributor , queuer , publicUri , version );
146
+
147
+ Map <String , Object > topLevel = executeQuery (handler , "{ grid { version } }" );
148
+
149
+ assertThat (topLevel ).isEqualTo (
150
+ singletonMap (
151
+ "data" , singletonMap (
152
+ "grid" , singletonMap (
153
+ "version" , version ))));
154
+ }
155
+
144
156
@ Test
145
157
public void shouldReturnAnEmptyListForNodesIfNoneAreRegistered () {
146
- GraphqlHandler handler = new GraphqlHandler (tracer , distributor , queuer , publicUri );
158
+ GraphqlHandler handler = new GraphqlHandler (tracer , distributor , queuer , publicUri , version );
147
159
148
160
Map <String , Object > topLevel = executeQuery (handler , "{ grid { nodes { uri } } }" );
149
161
@@ -174,7 +186,7 @@ public boolean test(Capabilities capabilities) {
174
186
distributor .add (node );
175
187
wait .until (obj -> distributor .getStatus ().hasCapacity ());
176
188
177
- GraphqlHandler handler = new GraphqlHandler (tracer , distributor , queuer , publicUri );
189
+ GraphqlHandler handler = new GraphqlHandler (tracer , distributor , queuer , publicUri , version );
178
190
Map <String , Object > topLevel = executeQuery (handler , "{ grid { nodes { uri } } }" );
179
191
180
192
assertThat (topLevel ).describedAs (topLevel .toString ()).isEqualTo (
@@ -224,7 +236,7 @@ public void shouldBeAbleToGetSessionInfo() throws URISyntaxException {
224
236
String query = String .format (
225
237
"{ session (id: \" %s\" ) { id, capabilities, startTime, uri } }" , sessionId );
226
238
227
- GraphqlHandler handler = new GraphqlHandler (tracer , distributor , queuer , publicUri );
239
+ GraphqlHandler handler = new GraphqlHandler (tracer , distributor , queuer , publicUri , version );
228
240
Map <String , Object > result = executeQuery (handler , query );
229
241
230
242
assertThat (result ).describedAs (result .toString ()).isEqualTo (
@@ -280,7 +292,7 @@ public void shouldBeAbleToGetNodeInfoForSession() throws URISyntaxException {
280
292
slot );
281
293
String query = String .format ("{ session (id: \" %s\" ) { nodeId, nodeUri } }" , sessionId );
282
294
283
- GraphqlHandler handler = new GraphqlHandler (tracer , distributor , queuer , publicUri );
295
+ GraphqlHandler handler = new GraphqlHandler (tracer , distributor , queuer , publicUri , version );
284
296
Map <String , Object > result = executeQuery (handler , query );
285
297
286
298
assertThat (result ).describedAs (result .toString ()).isEqualTo (
@@ -338,7 +350,7 @@ public void shouldBeAbleToGetSlotInfoForSession() throws URISyntaxException {
338
350
String query = String .format (
339
351
"{ session (id: \" %s\" ) { slot { id, stereotype, lastStarted } } }" , sessionId );
340
352
341
- GraphqlHandler handler = new GraphqlHandler (tracer , distributor , queuer , publicUri );
353
+ GraphqlHandler handler = new GraphqlHandler (tracer , distributor , queuer , publicUri , version );
342
354
Map <String , Object > result = executeQuery (handler , query );
343
355
344
356
assertThat (result ).describedAs (result .toString ()).isEqualTo (
@@ -381,7 +393,7 @@ public void shouldBeAbleToGetSessionDuration() throws URISyntaxException {
381
393
382
394
String query = String .format ("{ session (id: \" %s\" ) { sessionDurationMillis } }" , sessionId );
383
395
384
- GraphqlHandler handler = new GraphqlHandler (tracer , distributor , queuer , publicUri );
396
+ GraphqlHandler handler = new GraphqlHandler (tracer , distributor , queuer , publicUri , version );
385
397
Map <String , Object > result = executeQuery (handler , query );
386
398
387
399
assertThat (result )
@@ -412,7 +424,7 @@ public void shouldThrowExceptionWhenSessionNotFound() throws URISyntaxException
412
424
String randomSessionId = UUID .randomUUID ().toString ();
413
425
String query = "{ session (id: \" " + randomSessionId + "\" ) { sessionDurationMillis } }" ;
414
426
415
- GraphqlHandler handler = new GraphqlHandler (tracer , distributor , queuer , publicUri );
427
+ GraphqlHandler handler = new GraphqlHandler (tracer , distributor , queuer , publicUri , version );
416
428
Map <String , Object > result = executeQuery (handler , query );
417
429
assertThat (result )
418
430
.containsEntry ("data" , null )
@@ -441,7 +453,7 @@ public void shouldThrowExceptionWhenSessionIsEmpty() throws URISyntaxException {
441
453
442
454
String query = "{ session (id: \" \" ) { sessionDurationMillis } }" ;
443
455
444
- GraphqlHandler handler = new GraphqlHandler (tracer , distributor , queuer , publicUri );
456
+ GraphqlHandler handler = new GraphqlHandler (tracer , distributor , queuer , publicUri , version );
445
457
Map <String , Object > result = executeQuery (handler , query );
446
458
assertThat (result )
447
459
.containsEntry ("data" , null )
0 commit comments