@@ -2623,11 +2623,11 @@ public void parseServerSideListener_invalidTrafficDirection() throws ResourceInv
26232623 .setName ("listener1" )
26242624 .setTrafficDirection (TrafficDirection .OUTBOUND )
26252625 .build ();
2626- assertThrows (ResourceInvalidException .class );
2626+ ResourceInvalidException e = assertThrows (ResourceInvalidException .class ,
2627+ () -> XdsListenerResource .parseServerSideListener (
2628+ listener , null , filterRegistry , null , getXdsResourceTypeArgs (true )));
26272629 assertThat (e ).hasMessageThat ()
26282630 .isEqualTo ("Listener listener1 with invalid traffic direction: OUTBOUND" );
2629- XdsListenerResource .parseServerSideListener (
2630- listener , null , filterRegistry , null , getXdsResourceTypeArgs (true ));
26312631 }
26322632
26332633 @ Test
@@ -2680,11 +2680,10 @@ public void parseServerSideListener_emptyAddress() throws ResourceInvalidExcepti
26802680 .setSocketAddress (
26812681 SocketAddress .newBuilder ()))
26822682 .build ();
2683- thrown .expect (ResourceInvalidException .class );
2684- thrown .expectMessage ("Invalid address: Empty address is not allowed." );
2685-
2686- XdsListenerResource .parseServerSideListener (
2687- listener ,null , filterRegistry , null , getXdsResourceTypeArgs (true ));
2683+ ResourceInvalidException e = assertThrows (ResourceInvalidException .class ,
2684+ () -> XdsListenerResource .parseServerSideListener (
2685+ listener , null , filterRegistry , null , getXdsResourceTypeArgs (true )));
2686+ assertThat (e ).hasMessageThat ().isEqualTo ("Invalid address: Empty address is not allowed." );
26882687 }
26892688
26902689 @ Test
@@ -2698,11 +2697,10 @@ public void parseServerSideListener_namedPort() throws ResourceInvalidException
26982697 SocketAddress .newBuilder ()
26992698 .setAddress ("172.14.14.5" ).setNamedPort ("" )))
27002699 .build ();
2701- thrown .expect (ResourceInvalidException .class );
2702- thrown .expectMessage ("NAMED_PORT is not supported in gRPC." );
2703-
2704- XdsListenerResource .parseServerSideListener (
2705- listener ,null , filterRegistry , null , getXdsResourceTypeArgs (true ));
2700+ ResourceInvalidException e = assertThrows (ResourceInvalidException .class ,
2701+ () -> XdsListenerResource .parseServerSideListener (
2702+ listener , null , filterRegistry , null , getXdsResourceTypeArgs (true )));
2703+ assertThat (e ).hasMessageThat ().isEqualTo ("NAMED_PORT is not supported in gRPC." );
27062704 }
27072705
27082706 @ Test
@@ -3062,11 +3060,11 @@ public void validateCommonTlsContext_validationContextCertificateProvider()
30623060 .setValidationContextCertificateProvider (
30633061 CommonTlsContext .CertificateProvider .getDefaultInstance ())
30643062 .build ();
3065- assertThrows (ResourceInvalidException .class );
3063+ ResourceInvalidException e = assertThrows (ResourceInvalidException .class , () ->
3064+ XdsClusterResource .validateCommonTlsContext (commonTlsContext , null , false ));
30663065 assertThat (e ).hasMessageThat ()
30673066 .isEqualTo (
30683067 "common-tls-context with validation_context_certificate_provider is not supported" );
3069- XdsClusterResource .validateCommonTlsContext (commonTlsContext , null , false );
30703068 }
30713069
30723070 @ Test
@@ -3077,24 +3075,23 @@ public void validateCommonTlsContext_validationContextCertificateProviderInstanc
30773075 .setValidationContextCertificateProviderInstance (
30783076 CommonTlsContext .CertificateProviderInstance .getDefaultInstance ())
30793077 .build ();
3080- assertThrows (ResourceInvalidException .class );
3078+ ResourceInvalidException e = assertThrows (ResourceInvalidException .class , () ->
3079+ XdsClusterResource .validateCommonTlsContext (commonTlsContext , null , false ));
30813080 assertThat (e ).hasMessageThat ()
30823081 .isEqualTo (
30833082 "common-tls-context with validation_context_certificate_provider_instance is not "
30843083 + "supported" );
3085- XdsClusterResource .validateCommonTlsContext (commonTlsContext , null , false );
30863084 }
30873085
30883086 @ Test
30893087 public void validateCommonTlsContext_tlsCertificateProviderInstance_isRequiredForServer ()
30903088 throws ResourceInvalidException {
30913089 CommonTlsContext commonTlsContext = CommonTlsContext .newBuilder ()
30923090 .build ();
3093- assertThrows (ResourceInvalidException .class );
3094- assertThat ( e ). hasMessageThat ()
3095- .isEqualTo (
3091+ ResourceInvalidException e = assertThrows (ResourceInvalidException .class ,
3092+ () -> XdsClusterResource . validateCommonTlsContext ( commonTlsContext , null , true ));
3093+ assertThat ( e ). hasMessageThat () .isEqualTo (
30963094 "tls_certificate_provider_instance is required in downstream-tls-context" );
3097- XdsClusterResource .validateCommonTlsContext (commonTlsContext , null , true );
30983095 }
30993096
31003097 @ Test
@@ -3126,12 +3123,11 @@ public void validateCommonTlsContext_tlsCertificateProviderInstance_absentInBoot
31263123 .setTlsCertificateProviderInstance (
31273124 CertificateProviderPluginInstance .newBuilder ().setInstanceName ("bad-name" ))
31283125 .build ();
3129- assertThrows (ResourceInvalidException .class );
3130- assertThat (e ).hasMessageThat ()
3131- .isEqualTo (
3126+ ResourceInvalidException e = assertThrows (ResourceInvalidException .class ,
3127+ () -> XdsClusterResource .validateCommonTlsContext (commonTlsContext ,
3128+ ImmutableSet .of ("name1" , "name2" ), true ));
3129+ assertThat (e ).hasMessageThat ().isEqualTo (
31323130 "CertificateProvider instance name 'bad-name' not defined in the bootstrap file." );
3133- XdsClusterResource
3134- .validateCommonTlsContext (commonTlsContext , ImmutableSet .of ("name1" , "name2" ), true );
31353131 }
31363132
31373133 @ Test
@@ -3239,12 +3235,11 @@ public void validateCommonTlsContext_validationContextProviderInstance_absentInB
32393235 .setCaCertificateProviderInstance (CertificateProviderPluginInstance .newBuilder ()
32403236 .setInstanceName ("bad-name" ))))
32413237 .build ();
3242- assertThrows (ResourceInvalidException .class );
3243- assertThat (e ).hasMessageThat ()
3244- .isEqualTo (
3238+ ResourceInvalidException e = assertThrows (ResourceInvalidException .class ,
3239+ () -> XdsClusterResource .validateCommonTlsContext (commonTlsContext ,
3240+ ImmutableSet .of ("name1" , "name2" ), false ));
3241+ assertThat (e ).hasMessageThat ().isEqualTo (
32453242 "ca_certificate_provider_instance name 'bad-name' not defined in the bootstrap file." );
3246- XdsClusterResource
3247- .validateCommonTlsContext (commonTlsContext , ImmutableSet .of ("name1" , "name2" ), false );
32483243 }
32493244
32503245
@@ -3253,9 +3248,9 @@ public void validateCommonTlsContext_tlsCertificatesCount() throws ResourceInval
32533248 CommonTlsContext commonTlsContext = CommonTlsContext .newBuilder ()
32543249 .addTlsCertificates (TlsCertificate .getDefaultInstance ())
32553250 .build ();
3256- assertThrows (ResourceInvalidException .class );
3251+ ResourceInvalidException e = assertThrows (ResourceInvalidException .class ,
3252+ () -> XdsClusterResource .validateCommonTlsContext (commonTlsContext , null , false ));
32573253 assertThat (e ).hasMessageThat ().isEqualTo ("tls_certificate_provider_instance is unset" );
3258- XdsClusterResource .validateCommonTlsContext (commonTlsContext , null , false );
32593254 }
32603255
32613256 @ Test
@@ -3264,10 +3259,10 @@ public void validateCommonTlsContext_tlsCertificateSdsSecretConfigsCount()
32643259 CommonTlsContext commonTlsContext = CommonTlsContext .newBuilder ()
32653260 .addTlsCertificateSdsSecretConfigs (SdsSecretConfig .getDefaultInstance ())
32663261 .build ();
3267- assertThrows (ResourceInvalidException .class );
3262+ ResourceInvalidException e = assertThrows (ResourceInvalidException .class ,
3263+ () -> XdsClusterResource .validateCommonTlsContext (commonTlsContext , null , false ));
32683264 assertThat (e ).hasMessageThat ().isEqualTo (
32693265 "tls_certificate_provider_instance is unset" );
3270- XdsClusterResource .validateCommonTlsContext (commonTlsContext , null , false );
32713266 }
32723267
32733268 @ Test
@@ -3278,21 +3273,21 @@ public void validateCommonTlsContext_tlsCertificateCertificateProvider()
32783273 .setTlsCertificateCertificateProvider (
32793274 CommonTlsContext .CertificateProvider .getDefaultInstance ())
32803275 .build ();
3281- assertThrows (ResourceInvalidException .class );
3276+ ResourceInvalidException e = assertThrows (ResourceInvalidException .class , () ->
3277+ XdsClusterResource .validateCommonTlsContext (commonTlsContext , null , false ));
32823278 assertThat (e ).hasMessageThat ().isEqualTo (
32833279 "tls_certificate_provider_instance is unset" );
3284- XdsClusterResource .validateCommonTlsContext (commonTlsContext , null , false );
32853280 }
32863281
32873282 @ Test
32883283 public void validateCommonTlsContext_combinedValidationContext_isRequiredForClient ()
32893284 throws ResourceInvalidException {
32903285 CommonTlsContext commonTlsContext = CommonTlsContext .newBuilder ()
32913286 .build ();
3292- assertThrows (ResourceInvalidException .class );
3287+ ResourceInvalidException e = assertThrows (ResourceInvalidException .class , () ->
3288+ XdsClusterResource .validateCommonTlsContext (commonTlsContext , null , false ));
32933289 assertThat (e ).hasMessageThat ().isEqualTo ("ca_certificate_provider_instance or system_root_certs is required "
32943290 + "in upstream-tls-context" );
3295- XdsClusterResource .validateCommonTlsContext (commonTlsContext , null , false );
32963291 }
32973292
32983293 @ Test
@@ -3302,11 +3297,11 @@ public void validateCommonTlsContext_combinedValidationContextWithoutCertProvide
33023297 .setCombinedValidationContext (
33033298 CommonTlsContext .CombinedCertificateValidationContext .getDefaultInstance ())
33043299 .build ();
3305- assertThrows (ResourceInvalidException .class );
3300+ ResourceInvalidException e = assertThrows (ResourceInvalidException .class , () ->
3301+ XdsClusterResource .validateCommonTlsContext (commonTlsContext , null , false ));
33063302 assertThat (e ).hasMessageThat ().isEqualTo (
33073303 "ca_certificate_provider_instance or system_root_certs is required in "
33083304 + "upstream-tls-context" );
3309- XdsClusterResource .validateCommonTlsContext (commonTlsContext , null , false );
33103305 }
33113306
33123307 @ Test
@@ -3324,9 +3319,9 @@ public void validateCommonTlsContext_combinedValContextWithDefaultValContextForS
33243319 .setTlsCertificateProviderInstance (
33253320 CertificateProviderPluginInstance .getDefaultInstance ())
33263321 .build ();
3327- assertThrows (ResourceInvalidException .class );
3322+ ResourceInvalidException e = assertThrows (ResourceInvalidException .class , () ->
3323+ XdsClusterResource .validateCommonTlsContext (commonTlsContext , ImmutableSet .of ("" ), true ));
33283324 assertThat (e ).hasMessageThat ().isEqualTo ("match_subject_alt_names only allowed in upstream_tls_context" );
3329- XdsClusterResource .validateCommonTlsContext (commonTlsContext , ImmutableSet .of ("" ), true );
33303325 }
33313326
33323327 @ Test
@@ -3341,10 +3336,10 @@ public void validateCommonTlsContext_combinedValContextWithDefaultValContextVeri
33413336 .addVerifyCertificateSpki ("foo" )))
33423337 .setTlsCertificateProviderInstance (CertificateProviderPluginInstance .getDefaultInstance ())
33433338 .build ();
3344- assertThrows (ResourceInvalidException .class );
3339+ ResourceInvalidException e = assertThrows (ResourceInvalidException .class , () ->
3340+ XdsClusterResource .validateCommonTlsContext (commonTlsContext , ImmutableSet .of ("" ), false ));
33453341 assertThat (e ).hasMessageThat ().isEqualTo ("verify_certificate_spki in default_validation_context is not "
33463342 + "supported" );
3347- XdsClusterResource .validateCommonTlsContext (commonTlsContext , ImmutableSet .of ("" ), false );
33483343 }
33493344
33503345 @ Test
@@ -3359,10 +3354,10 @@ public void validateCommonTlsContext_combinedValContextWithDefaultValContextVeri
33593354 .addVerifyCertificateHash ("foo" )))
33603355 .setTlsCertificateProviderInstance (CertificateProviderPluginInstance .getDefaultInstance ())
33613356 .build ();
3362- assertThrows (ResourceInvalidException .class );
3357+ ResourceInvalidException e = assertThrows (ResourceInvalidException .class , () ->
3358+ XdsClusterResource .validateCommonTlsContext (commonTlsContext , ImmutableSet .of ("" ), false ));
33633359 assertThat (e ).hasMessageThat ().isEqualTo ("verify_certificate_hash in default_validation_context is not "
33643360 + "supported" );
3365- XdsClusterResource .validateCommonTlsContext (commonTlsContext , ImmutableSet .of ("" ), false );
33663361 }
33673362
33683363 @ Test
@@ -3378,11 +3373,11 @@ public void validateCommonTlsContext_combinedValContextDfltValContextRequireSign
33783373 .setTlsCertificateProviderInstance (
33793374 CertificateProviderPluginInstance .getDefaultInstance ())
33803375 .build ();
3381- assertThrows (ResourceInvalidException .class );
3376+ ResourceInvalidException e = assertThrows (ResourceInvalidException .class , () ->
3377+ XdsClusterResource .validateCommonTlsContext (commonTlsContext , ImmutableSet .of ("" ), false ));
33823378 assertThat (e ).hasMessageThat ().isEqualTo (
33833379 "require_signed_certificate_timestamp in default_validation_context is not "
33843380 + "supported" );
3385- XdsClusterResource .validateCommonTlsContext (commonTlsContext , ImmutableSet .of ("" ), false );
33863381 }
33873382
33883383 @ Test
@@ -3397,9 +3392,9 @@ public void validateCommonTlsContext_combinedValidationContextWithDefaultValidat
33973392 .setCrl (DataSource .getDefaultInstance ())))
33983393 .setTlsCertificateProviderInstance (CertificateProviderPluginInstance .getDefaultInstance ())
33993394 .build ();
3400- assertThrows (ResourceInvalidException .class );
3395+ ResourceInvalidException e = assertThrows (ResourceInvalidException .class , () ->
3396+ XdsClusterResource .validateCommonTlsContext (commonTlsContext , ImmutableSet .of ("" ), false ));
34013397 assertThat (e ).hasMessageThat ().isEqualTo ("crl in default_validation_context is not supported" );
3402- XdsClusterResource .validateCommonTlsContext (commonTlsContext , ImmutableSet .of ("" ), false );
34033398 }
34043399
34053400 @ Test
@@ -3414,18 +3409,18 @@ public void validateCommonTlsContext_combinedValContextWithDfltValContextCustomV
34143409 .setCustomValidatorConfig (TypedExtensionConfig .getDefaultInstance ())))
34153410 .setTlsCertificateProviderInstance (CertificateProviderPluginInstance .getDefaultInstance ())
34163411 .build ();
3417- assertThrows (ResourceInvalidException .class );
3412+ ResourceInvalidException e = assertThrows (ResourceInvalidException .class , () ->
3413+ XdsClusterResource .validateCommonTlsContext (commonTlsContext , ImmutableSet .of ("" ), false ));
34183414 assertThat (e ).hasMessageThat ().isEqualTo ("custom_validator_config in default_validation_context is not "
34193415 + "supported" );
3420- XdsClusterResource .validateCommonTlsContext (commonTlsContext , ImmutableSet .of ("" ), false );
34213416 }
34223417
34233418 @ Test
34243419 public void validateDownstreamTlsContext_noCommonTlsContext () throws ResourceInvalidException {
34253420 DownstreamTlsContext downstreamTlsContext = DownstreamTlsContext .getDefaultInstance ();
3426- assertThrows (ResourceInvalidException .class );
3421+ ResourceInvalidException e = assertThrows (ResourceInvalidException .class , () ->
3422+ XdsListenerResource .validateDownstreamTlsContext (downstreamTlsContext , null ));
34273423 assertThat (e ).hasMessageThat ().isEqualTo ("common-tls-context is required in downstream-tls-context" );
3428- XdsListenerResource .validateDownstreamTlsContext (downstreamTlsContext , null );
34293424 }
34303425
34313426 @ Test
@@ -3442,9 +3437,10 @@ public void validateDownstreamTlsContext_hasRequireSni() throws ResourceInvalidE
34423437 .setCommonTlsContext (commonTlsContext )
34433438 .setRequireSni (BoolValue .of (true ))
34443439 .build ();
3445- assertThrows (ResourceInvalidException .class );
3440+ ResourceInvalidException e = assertThrows (ResourceInvalidException .class , () ->
3441+ XdsListenerResource .validateDownstreamTlsContext (downstreamTlsContext ,
3442+ ImmutableSet .of ("" )));
34463443 assertThat (e ).hasMessageThat ().isEqualTo ("downstream-tls-context with require-sni is not supported" );
3447- XdsListenerResource .validateDownstreamTlsContext (downstreamTlsContext , ImmutableSet .of ("" ));
34483444 }
34493445
34503446 @ Test
@@ -3461,10 +3457,11 @@ public void validateDownstreamTlsContext_hasOcspStaplePolicy() throws ResourceIn
34613457 .setCommonTlsContext (commonTlsContext )
34623458 .setOcspStaplePolicy (DownstreamTlsContext .OcspStaplePolicy .STRICT_STAPLING )
34633459 .build ();
3464- assertThrows (ResourceInvalidException .class );
3460+ ResourceInvalidException e = assertThrows (ResourceInvalidException .class , () ->
3461+ XdsListenerResource .validateDownstreamTlsContext (downstreamTlsContext ,
3462+ ImmutableSet .of ("" )));
34653463 assertThat (e ).hasMessageThat ().isEqualTo (
34663464 "downstream-tls-context with ocsp_staple_policy value STRICT_STAPLING is not supported" );
3467- XdsListenerResource .validateDownstreamTlsContext (downstreamTlsContext , ImmutableSet .of ("" ));
34683465 }
34693466
34703467 @ Test
0 commit comments