2424import io .grpc .NameResolver ;
2525import io .grpc .NameResolver .ServiceConfigParser ;
2626import io .grpc .SynchronizationContext ;
27+ import io .grpc .Uri ;
2728import io .grpc .internal .DnsNameResolverProvider ;
2829import io .grpc .internal .GrpcUtil ;
2930import java .net .URI ;
31+ import java .util .Arrays ;
3032import org .junit .Test ;
3133import org .junit .runner .RunWith ;
32- import org .junit .runners .JUnit4 ;
34+ import org .junit .runners .Parameterized ;
35+ import org .junit .runners .Parameterized .Parameter ;
36+ import org .junit .runners .Parameterized .Parameters ;
3337
3438/** Unit tests for {@link SecretGrpclbNameResolverProvider}. */
35- @ RunWith (JUnit4 .class )
39+ @ RunWith (Parameterized .class )
3640public class SecretGrpclbNameResolverProviderTest {
3741
3842 private final SynchronizationContext syncContext = new SynchronizationContext (
@@ -53,6 +57,13 @@ public void uncaughtException(Thread t, Throwable e) {
5357 private SecretGrpclbNameResolverProvider .Provider provider =
5458 new SecretGrpclbNameResolverProvider .Provider ();
5559
60+ @ Parameters (name = "enableRfc3986UrisParam={0}" )
61+ public static Iterable <Object []> data () {
62+ return Arrays .asList (new Object [][] {{true }, {false }});
63+ }
64+
65+ @ Parameter public boolean enableRfc3986UrisParam ;
66+
5667 @ Test
5768 public void isAvailable () {
5869 assertThat (provider .isAvailable ()).isTrue ();
@@ -66,43 +77,49 @@ public void priority_shouldBeHigherThanDefaultDnsNameResolver() {
6677 }
6778
6879 @ Test
69- public void newNameResolver () {
70- assertThat (provider . newNameResolver (URI . create ( "dns:///localhost:443" ) , args ))
80+ public void newNameResolverReturnsCorrectType () {
81+ assertThat (newNameResolver ("dns:///localhost:443" , args ))
7182 .isInstanceOf (GrpclbNameResolver .class );
72- assertThat (provider . newNameResolver (URI . create ( "notdns:///localhost:443" ) , args )).isNull ();
83+ assertThat (newNameResolver ("notdns:///localhost:443" , args )).isNull ();
7384 }
7485
7586 @ Test
7687 public void invalidDnsName () throws Exception {
77- testInvalidUri (URI . create ( "dns:/%5Binvalid%5D" ) );
88+ testInvalidUri ("dns:/%5Binvalid%5D" );
7889 }
7990
8091 @ Test
8192 public void validIpv6 () throws Exception {
82- testValidUri (URI . create ( "dns:/%5B::1%5D" ) );
93+ testValidUri ("dns:/%5B::1%5D" );
8394 }
8495
8596 @ Test
8697 public void validDnsNameWithoutPort () throws Exception {
87- testValidUri (URI . create ( "dns:/foo.googleapis.com" ) );
98+ testValidUri ("dns:/foo.googleapis.com" );
8899 }
89100
90101 @ Test
91102 public void validDnsNameWithPort () throws Exception {
92- testValidUri (URI . create ( "dns:/foo.googleapis.com:456" ) );
103+ testValidUri ("dns:/foo.googleapis.com:456" );
93104 }
94105
95- private void testInvalidUri (URI uri ) {
106+ private void testInvalidUri (String uri ) {
96107 try {
97- provider . newNameResolver (uri , args );
108+ newNameResolver (uri , args );
98109 fail ("Should have failed" );
99110 } catch (IllegalArgumentException e ) {
100111 // expected
101112 }
102113 }
103114
104- private void testValidUri (URI uri ) {
105- GrpclbNameResolver resolver = provider . newNameResolver (uri , args );
115+ private void testValidUri (String uri ) {
116+ NameResolver resolver = newNameResolver (uri , args );
106117 assertThat (resolver ).isNotNull ();
107118 }
119+
120+ private NameResolver newNameResolver (String uriString , NameResolver .Args args ) {
121+ return enableRfc3986UrisParam
122+ ? provider .newNameResolver (Uri .create (uriString ), args )
123+ : provider .newNameResolver (URI .create (uriString ), args );
124+ }
108125}
0 commit comments