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