1616import org .junit .runners .Parameterized ;
1717import org .junit .runners .Parameterized .Parameters ;
1818
19+ import java .util .function .BiConsumer ;
20+
21+ import static java .util .Locale .ENGLISH ;
1922import static org .hamcrest .CoreMatchers .instanceOf ;
2023import static org .hamcrest .CoreMatchers .is ;
2124import static org .hamcrest .MatcherAssert .assertThat ;
22- import static org .junit .Assert .fail ;
25+ import static org .junit .Assert .* ;
2326
2427@ RunWith (Parameterized .class )
2528public class InvalidOracleConnectionUriParsingTest {
2629
2730 @ Parameters (name = "{0}: {1}" )
28- public static Object [][] data () {
31+ public static Object [][] testData () {
2932 Object [][] params = {
30- {"null uri" , null },
31- {"uri with invalid scheme" , "postgresql://user@?host=localhost&port=1234" },
32- {"uri with no separated user/password" , "oracle:thin:scott@myhost:1521:orcl" },
33- {"uri with no separated user/password" , "oracle:thin:scott@myhost:1521:orcl" },
34- {"uri without password" , "oracle:thin:scott/@myhost:1521:orcl" },
35- {"uri without user" , "oracle:thin:/tiger@myhost:1521:orcl" },
36- {"uri with multiple user/password splitters" , "oracle:thin:scott/tiger/dragon@myhost:1521:orcl" },
37- {"uri without net location" , "oracle:thin:scott/tiger" },
38- {"uri without SID after host" , "oracle:thin:scott/tiger@myhost" },
39- {"uri without SID after port" , "oracle:thin:scott/tiger@myhost:1521" },
40- {"uri with empty SID" , "oracle:thin:scott/tiger@myhost:1521:" },
41- {"uri with invalid content after host" , "oracle:thin:@[::1]sss:1521:orcl" },
42- {"uri with invalid IPv6 address" , "oracle:thin:@[:1521:orcl" },
43- {"uri with empty host" , "oracle:thin:@:1521:orcl" },
44- {"uri with empty IPv6 address" , "oracle:thin:@[]:1521:orcl" },
45- {"uri with empty port" , "oracle:thin:@myhost::orcl" },
46- {"uri with invalid port" , "oracle:thin:@myhost:7654645:orcl" },
47- {"uri with multiple hosts and ports" , "oracle:thin:scott/tiger@myhost1:1521,myhost2:1521:orcl" },
48- {"uri with multiple hosts" , "oracle:thin:scott/tiger@myhost1,myhost2:1521:orcl" },
49- {"uri with empty props" , "oracle:thin:scott/tiger@myhost:1521:orcl?" },
50- {"uri with empty service name" , "oracle:thin:scott/tiger@myhost:1521/" },
51- {"uri with empty server mode" , "oracle:thin:scott/tiger@myhost:1521/orcl:?prop=val" },
52- {"uri with invalid server mode" , "oracle:thin:scott/tiger@myhost:1521/orcl:foo" },
53- {"uri with service name but empty instance name" , "oracle:thin:scott/tiger@myhost:1521/orcl/" },
54- {"uri with service name and server mode but empty instance name" , "oracle:thin:scott/tiger@myhost:1521/orcl:shared/" },
55- {"uri with empty prop" , "oracle:thin:scott/tiger@myhost:1521:orcl?&prop2" },
56- {"uri with prop having no value" , "oracle:thin:scott/tiger@myhost:1521:orcl?prop1&prop2=val2" },
33+ testData ("null uri" , null ),
34+ testData ("uri with invalid scheme" , "postgresql://user@?host=localhost&port=1234" ),
35+ testData ("uri with no separated user/password" , "oracle:thin:scott@myhost:1521:orcl" ),
36+ testData ("uri with no separated user/password" , "oracle:thin:scott@myhost:1521:orcl" ),
37+ testData ("uri without password" , "oracle:thin:scott/@myhost:1521:orcl" ),
38+ testData ("uri without user" , "oracle:thin:/tiger@myhost:1521:orcl" ),
39+ testData ("uri with multiple user/password splitters" , "oracle:thin:scott/tiger/dragon@myhost:1521:orcl" ),
40+ testData ("uri without net location" , "oracle:thin:scott/tiger" ),
41+ testData ("uri without SID after host" , "oracle:thin:scott/tiger@myhost" ),
42+ testData ("uri without SID after port" , "oracle:thin:scott/tiger@myhost:1521" ),
43+ testData ("uri with empty SID" , "oracle:thin:scott/tiger@myhost:1521:" ),
44+ testData ("uri with invalid content after host" , "oracle:thin:@[::1]sss:1521:orcl" ),
45+ testData ("uri with invalid IPv6 address" , "oracle:thin:@[:1521:orcl" ),
46+ testData ("uri with empty host" , "oracle:thin:@:1521:orcl" ),
47+ testData ("uri with empty IPv6 address" , "oracle:thin:@[]:1521:orcl" ),
48+ testData ("uri with empty port" , "oracle:thin:@myhost::orcl" ),
49+ testData ("uri with invalid port" , "oracle:thin:@myhost:7654645:orcl" ),
50+ testData ("uri with multiple hosts and ports" , "oracle:thin:scott/tiger@myhost1:1521,myhost2:1521:orcl" ),
51+ testData ("uri with multiple hosts" , "oracle:thin:scott/tiger@myhost1,myhost2:1521:orcl" ),
52+ testData ("uri with empty props" , "oracle:thin:scott/tiger@myhost:1521:orcl?" ),
53+ testData ("uri with empty service name" , "oracle:thin:scott/tiger@myhost:1521/" ),
54+ testData ("uri with empty server mode" , "oracle:thin:scott/tiger@myhost:1521/orcl:?prop=val" ),
55+ testData ("uri with invalid server mode" , "oracle:thin:scott/tiger@myhost:1521/orcl:foo" ),
56+ testData ("uri with service name but empty instance name" , "oracle:thin:scott/tiger@myhost:1521/orcl/" ),
57+ testData ("uri with service name and server mode but empty instance name" , "oracle:thin:scott/tiger@myhost:1521/orcl:shared/" ),
58+ testData ("uri with empty prop" , "oracle:thin:scott/tiger@myhost:1521:orcl?&prop2" ),
59+ testData ("uri with prop having no value" , "oracle:thin:scott/tiger@myhost:1521:orcl?prop1&prop2=val2" ),
60+ testData (
61+ "uri with ldap syntax" , "oracle:thin:@ldap://ldap.acme.com:7777/sales,cn=OracleContext,dc=com" ,
62+ (s , e ) -> {
63+ assertNotNull (e .getCause ());
64+ assertTrue (e .getCause ().getMessage ().toLowerCase (ENGLISH ).contains ("ldap" ));
65+ }),
66+ testData ("uri with Oracle Net connection descriptor" , "oracle:thin:@(DESCRIPTION=\n " +
67+ " (LOAD_BALANCE=on)\n " +
68+ "(ADDRESS_LIST=\n " +
69+ " (ADDRESS=(PROTOCOL=TCP)(HOST=host1) (PORT=1521))\n " +
70+ " (ADDRESS=(PROTOCOL=TCP)(HOST=host2)(PORT=1521)))\n " +
71+ " (CONNECT_DATA=(SERVICE_NAME=service_name)))" ,
72+ (s , e ) -> {
73+ assertNotNull (e .getCause ());
74+ assertTrue (e .getCause ().getMessage ().toLowerCase (ENGLISH ).contains ("tns url" ));
75+ }),
5776 };
5877 return params ;
5978 }
6079
80+ private static Object [] testData (String testName , String uri ) {
81+ return testData (testName , uri , null );
82+ }
83+
84+ private static Object [] testData (String testName , String uri , BiConsumer <String , Exception > assertions ) {
85+ return new Object []{testName , uri , assertions };
86+ }
87+
6188 private final String connectionUri ;
89+ private final BiConsumer <String , Exception > assertions ;
6290
63- public InvalidOracleConnectionUriParsingTest (@ SuppressWarnings ("unused" ) String name , String connectionUri ) {
91+ public InvalidOracleConnectionUriParsingTest (@ SuppressWarnings ("unused" ) String name , String connectionUri , BiConsumer < String , Exception > assertions ) {
6492 this .connectionUri = connectionUri ;
93+ this .assertions = assertions ;
6594 }
6695
6796 @ Test
@@ -75,6 +104,9 @@ public void shouldFailToParseInvalidUri() {
75104 } else {
76105 assertThat (e , is (instanceOf (IllegalArgumentException .class )));
77106 }
107+ if (assertions != null ) {
108+ assertions .accept (connectionUri , e );
109+ }
78110 }
79111 }
80112}
0 commit comments