60
60
import javax .ws .rs .PathParam ;
61
61
import javax .ws .rs .Produces ;
62
62
import javax .ws .rs .QueryParam ;
63
+ import javax .ws .rs .RuntimeType ;
63
64
import javax .ws .rs .container .AsyncResponse ;
64
65
import javax .ws .rs .container .ContainerRequestContext ;
65
66
import javax .ws .rs .container .ContainerRequestFilter ;
66
67
import javax .ws .rs .container .Suspended ;
68
+ import javax .ws .rs .core .Configuration ;
67
69
68
70
import javax .inject .Singleton ;
69
71
70
72
import org .glassfish .jersey .Severity ;
71
73
import org .glassfish .jersey .internal .Errors ;
74
+ import org .glassfish .jersey .internal .inject .AbstractBinder ;
75
+ import org .glassfish .jersey .internal .inject .InjectionManager ;
72
76
import org .glassfish .jersey .internal .util .Producer ;
77
+ import org .glassfish .jersey .model .internal .CommonConfig ;
78
+ import org .glassfish .jersey .model .internal .ComponentBag ;
73
79
import org .glassfish .jersey .server .ApplicationHandler ;
74
80
import org .glassfish .jersey .server .ContainerRequest ;
75
81
import org .glassfish .jersey .server .ContainerResponse ;
96
102
* @author Jakub Podlesak (jakub.podlesak at oracle.com)
97
103
*/
98
104
public class ValidatorTest {
99
- private static final Logger LOGGER = Logger .getLogger (ValidatorTest .class .getName ());
100
105
106
+ private static final Logger LOGGER = Logger .getLogger (ValidatorTest .class .getName ());
101
107
102
108
@ Path ("rootNonAmbigCtors" )
103
109
public static class TestRootResourceNonAmbigCtors {
@@ -123,7 +129,7 @@ public void testRootResourceNonAmbigConstructors() throws Exception {
123
129
LOGGER .info ("No issue should be reported if more public ctors exists with the same number of params, "
124
130
+ "but another just one is presented with more params at a root resource:" );
125
131
Resource resource = Resource .builder (TestRootResourceNonAmbigCtors .class ).build ();
126
- ComponentModelValidator validator = new ComponentModelValidator (InjectionManagerFactory . createInjectionManager ());
132
+ ComponentModelValidator validator = new ComponentModelValidator (createInjectionManager ());
127
133
validator .validate (resource );
128
134
assertTrue (validator .getIssueList ().isEmpty ());
129
135
}
@@ -324,7 +330,8 @@ public List<ResourceModelIssue> call() {
324
330
}
325
331
326
332
ResourceModel model = new ResourceModel .Builder (resources , false ).build ();
327
- ComponentModelValidator validator = new ComponentModelValidator (InjectionManagerFactory .createInjectionManager ());
333
+ InjectionManager injectionManager = createInjectionManager ();
334
+ ComponentModelValidator validator = new ComponentModelValidator (injectionManager );
328
335
validator .validate (model );
329
336
return ModelErrors .getErrorsAsResourceModelIssues ();
330
337
}
@@ -446,7 +453,7 @@ public void srLocator() {
446
453
public void testSRLReturningVoid () throws Exception {
447
454
LOGGER .info ("An issue should be reported if a sub-resource locator returns void:" );
448
455
Resource resource = Resource .builder (TestSRLReturningVoid .class ).build ();
449
- ComponentModelValidator validator = new ComponentModelValidator (InjectionManagerFactory . createInjectionManager ());
456
+ ComponentModelValidator validator = new ComponentModelValidator (createInjectionManager ());
450
457
validator .validate (resource );
451
458
assertTrue (validator .fatalIssuesFound ());
452
459
}
@@ -522,7 +529,7 @@ public void testMultipleHttpMethodDesignatorsRM() throws Exception {
522
529
LOGGER .info ("An issue should be reported if more than one HTTP method designator exist on a resource "
523
530
+ "method:" );
524
531
Resource resource = Resource .builder (TestMultipleHttpMethodDesignatorsRM .class ).build ();
525
- ComponentModelValidator validator = new ComponentModelValidator (InjectionManagerFactory . createInjectionManager ());
532
+ ComponentModelValidator validator = new ComponentModelValidator (createInjectionManager ());
526
533
validator .validate (resource );
527
534
assertTrue (validator .fatalIssuesFound ());
528
535
}
@@ -543,7 +550,7 @@ public void testMultipleHttpMethodDesignatorsSRM() throws Exception {
543
550
LOGGER .info ("An issue should be reported if more than one HTTP method designator exist on a sub-resource "
544
551
+ "method:" );
545
552
Resource resource = Resource .builder (TestMultipleHttpMethodDesignatorsSRM .class ).build ();
546
- ComponentModelValidator validator = new ComponentModelValidator (InjectionManagerFactory . createInjectionManager ());
553
+ ComponentModelValidator validator = new ComponentModelValidator (createInjectionManager ());
547
554
validator .validate (resource );
548
555
assertTrue (validator .fatalIssuesFound ());
549
556
}
@@ -561,7 +568,7 @@ public String locator(String s) {
561
568
public void testEntityParamOnSRL () throws Exception {
562
569
LOGGER .info ("An issue should be reported if an entity parameter exists on a sub-resource locator:" );
563
570
Resource resource = Resource .builder (TestEntityParamOnSRL .class ).build ();
564
- ComponentModelValidator validator = new ComponentModelValidator (InjectionManagerFactory . createInjectionManager ());
571
+ ComponentModelValidator validator = new ComponentModelValidator (createInjectionManager ());
565
572
validator .validate (resource );
566
573
assertTrue (validator .fatalIssuesFound ());
567
574
}
@@ -640,7 +647,7 @@ public void testAmbiguousParams() throws Exception {
640
647
@ Override
641
648
public void run () {
642
649
Resource resource = Resource .builder (TestAmbiguousParams .class ).build ();
643
- ComponentModelValidator validator = new ComponentModelValidator (InjectionManagerFactory . createInjectionManager ());
650
+ ComponentModelValidator validator = new ComponentModelValidator (createInjectionManager ());
644
651
validator .validate (resource );
645
652
646
653
assertTrue (!validator .fatalIssuesFound ());
@@ -664,7 +671,7 @@ public String get() {
664
671
public void testEmptyPathSegment () throws Exception {
665
672
LOGGER .info ("A warning should be reported if @Path with \" /\" or empty string value is seen" );
666
673
Resource resource = Resource .builder (TestEmptyPathSegment .class ).build ();
667
- ComponentModelValidator validator = new ComponentModelValidator (InjectionManagerFactory . createInjectionManager ());
674
+ ComponentModelValidator validator = new ComponentModelValidator (createInjectionManager ());
668
675
validator .validate (resource );
669
676
670
677
assertTrue (!validator .fatalIssuesFound ());
@@ -707,7 +714,7 @@ public void testTypeVariableResource() throws Exception {
707
714
@ Override
708
715
public void run () {
709
716
Resource resource = Resource .builder (TypeVariableResource .class ).build ();
710
- ComponentModelValidator validator = new ComponentModelValidator (InjectionManagerFactory . createInjectionManager ());
717
+ ComponentModelValidator validator = new ComponentModelValidator (createInjectionManager ());
711
718
validator .validate (resource );
712
719
713
720
assertTrue (!validator .fatalIssuesFound ());
@@ -752,7 +759,7 @@ public static class ConcreteParameterizedTypeResource extends ParameterizedTypeR
752
759
public void testParameterizedTypeResource () throws Exception {
753
760
LOGGER .info ("" );
754
761
Resource resource = Resource .builder (ConcreteParameterizedTypeResource .class ).build ();
755
- ComponentModelValidator validator = new ComponentModelValidator (InjectionManagerFactory . createInjectionManager ());
762
+ ComponentModelValidator validator = new ComponentModelValidator (createInjectionManager ());
756
763
validator .validate (resource );
757
764
758
765
assertTrue (!validator .fatalIssuesFound ());
@@ -789,7 +796,7 @@ public static class ConcreteGenericArrayResource extends GenericArrayResource<St
789
796
public void testGenericArrayResource () throws Exception {
790
797
LOGGER .info ("" );
791
798
Resource resource = Resource .builder (ConcreteGenericArrayResource .class ).build ();
792
- ComponentModelValidator validator = new ComponentModelValidator (InjectionManagerFactory . createInjectionManager ());
799
+ ComponentModelValidator validator = new ComponentModelValidator (createInjectionManager ());
793
800
validator .validate (resource );
794
801
795
802
assertTrue (!validator .fatalIssuesFound ());
@@ -854,7 +861,7 @@ public String moreNonAnnotatedParameters(@HeaderParam("something") String header
854
861
@ Test
855
862
public void testNotAnnotatedParameters () throws Exception {
856
863
Resource resource = Resource .builder (AmbiguousParameterResource .class ).build ();
857
- ComponentModelValidator validator = new ComponentModelValidator (InjectionManagerFactory . createInjectionManager ());
864
+ ComponentModelValidator validator = new ComponentModelValidator (createInjectionManager ());
858
865
validator .validate (resource );
859
866
860
867
final List <ResourceModelIssue > errorMessages = validator .getIssueList ();
@@ -1161,4 +1168,15 @@ public void testDisableFailOnErrors() throws ExecutionException, InterruptedExce
1161
1168
assertEquals (200 , response .getStatus ());
1162
1169
assertEquals ("PASSED" , response .getEntity ());
1163
1170
}
1171
+
1172
+ private InjectionManager createInjectionManager () {
1173
+ InjectionManager injectionManager = InjectionManagerFactory .createInjectionManager ();
1174
+ injectionManager .register (new AbstractBinder () {
1175
+ @ Override
1176
+ protected void configure () {
1177
+ bind (new CommonConfig (RuntimeType .SERVER , ComponentBag .EXCLUDE_EMPTY )).to (Configuration .class );
1178
+ }
1179
+ });
1180
+ return injectionManager ;
1181
+ }
1164
1182
}
0 commit comments