51
51
52
52
import org .glassfish .jersey .internal .util .collection .MultivaluedStringMap ;
53
53
import org .glassfish .jersey .linking .InjectLink .Extension ;
54
+ import org .glassfish .jersey .linking .InjectLink .LinkQueryParam ;
54
55
import org .glassfish .jersey .linking .mapping .ResourceMappingContext ;
55
56
import org .glassfish .jersey .server .ExtendedUriInfo ;
56
57
import org .glassfish .jersey .server .model .Resource ;
@@ -123,11 +124,15 @@ public MultivaluedMap<String, String> getPathParameters(boolean decode) {
123
124
}
124
125
125
126
public MultivaluedMap <String , String > getQueryParameters () {
126
- return new MultivaluedStringMap ();
127
+ MultivaluedStringMap map = new MultivaluedStringMap ();
128
+ map .add ("q" , "somevalue" );
129
+ return map ;
127
130
}
128
131
129
132
public MultivaluedMap <String , String > getQueryParameters (boolean decode ) {
130
- return new MultivaluedStringMap ();
133
+ MultivaluedStringMap map = new MultivaluedStringMap ();
134
+ map .add ("q" , "somevalue" );
135
+ return map ;
131
136
}
132
137
133
138
public List <String > getMatchedURIs () {
@@ -361,7 +366,6 @@ public String getId2() {
361
366
362
367
@ Test
363
368
public void testConditional () {
364
- System .out .println ("EL" );
365
369
HeaderProcessor <EntityF > instance = new HeaderProcessor (EntityF .class );
366
370
EntityF testClass = new EntityF ();
367
371
List <String > headerValues = instance .getLinkHeaderValues (testClass , mockUriInfo , mockRmc );
@@ -370,4 +374,72 @@ public void testConditional() {
370
374
assertEquals ("</application/resources/1>" , headerValue );
371
375
}
372
376
377
+ @ InjectLinks ({
378
+ @ InjectLink (
379
+ value = "${entity.id1}" ,
380
+ queryParams = { @ LinkQueryParam (name = "page" , value = "${instance.page}" ),
381
+ @ LinkQueryParam (name = "page" , value = "${instance.page2}" ),
382
+ }
383
+ )
384
+ })
385
+ public static class EntityQ {
386
+
387
+ public String getId1 () {
388
+ return "1" ;
389
+ }
390
+
391
+ public String getPage () {
392
+ return "42" ;
393
+ }
394
+
395
+ public String getPage2 () {
396
+ return "43" ;
397
+ }
398
+ }
399
+
400
+ @ Test
401
+ public void testQueryParam () {
402
+ HeaderProcessor <EntityQ > instance = new HeaderProcessor (EntityQ .class );
403
+ EntityQ testClass = new EntityQ ();
404
+ List <String > headerValues = instance .getLinkHeaderValues (testClass , mockUriInfo , mockRmc );
405
+ assertEquals (1 , headerValues .size ());
406
+ String headerValue = headerValues .get (0 );
407
+ assertEquals ("</application/resources/1?page=42&page=43>" , headerValue );
408
+ }
409
+
410
+
411
+ @ InjectLinks ({
412
+ @ InjectLink (
413
+ value = "${entity.id1}" ,
414
+ copyRequestQueryParams = true ,
415
+ excludeFromRequestQueryParams = {"page" },
416
+ queryParams = {
417
+ @ LinkQueryParam (name = "page" , value = "${instance.page}" ),
418
+ }
419
+ )
420
+ })
421
+ public static class EntityR {
422
+
423
+ public String getId1 () {
424
+ return "1" ;
425
+ }
426
+
427
+ public String getPage () {
428
+ return "42" ;
429
+ }
430
+
431
+ public String getPage2 () {
432
+ return "43" ;
433
+ }
434
+ }
435
+
436
+ @ Test
437
+ public void testRequestQueryParam () {
438
+ HeaderProcessor <EntityR > instance = new HeaderProcessor (EntityR .class );
439
+ EntityR testClass = new EntityR ();
440
+ List <String > headerValues = instance .getLinkHeaderValues (testClass , mockUriInfo , mockRmc );
441
+ assertEquals (1 , headerValues .size ());
442
+ String headerValue = headerValues .get (0 );
443
+ assertEquals ("</application/resources/1?page=42&q=somevalue>" , headerValue );
444
+ }
373
445
}
0 commit comments