@ -89,15 +89,56 @@ public class OracleTableSourceFactoryTest {
private static final String MY_SCHEMA = "mySchema" ;
private static final Properties PROPERTIES = new Properties ( ) ;
@Test
public void testRequiredProperties ( ) {
try {
Map < String , String > properties = getAllRequiredOptions ( ) ;
// validation for source
createTableSource ( properties ) ;
fail ( "exception expected" ) ;
} catch ( Throwable t ) {
assertTrue (
ExceptionUtils . findThrowableWithMessage (
t , "hostname is required when url is not configured" )
. isPresent ( ) ) ;
}
}
@Test
public void testRequiredPropertiesWithUrl ( ) {
String url = "jdbc:oracle:thin:@" + MY_LOCALHOST + ":1521" + ":" + MY_DATABASE ;
Map < String , String > properties = getAllRequiredOptions ( ) ;
properties . put ( "url" , url ) ;
// validation for source
DynamicTableSource actualSource = createTableSource ( properties ) ;
OracleTableSource expectedSource =
new OracleTableSource (
SCHEMA ,
url ,
1521 ,
null ,
MY_DATABASE ,
MY_TABLE ,
MY_SCHEMA ,
MY_USERNAME ,
MY_PASSWORD ,
PROPERTIES ,
StartupOptions . initial ( ) ) ;
assertEquals ( expectedSource , actualSource ) ;
}
@Test
public void testCommonProperties ( ) {
Map < String , String > properties = getAllOptions ( ) ;
Map < String , String > properties = getAll Required OptionsWithHost ( ) ;
// validation for source
DynamicTableSource actualSource = createTableSource ( properties ) ;
OracleTableSource expectedSource =
new OracleTableSource (
SCHEMA ,
null ,
1521 ,
MY_LOCALHOST ,
MY_DATABASE ,
@ -112,8 +153,10 @@ public class OracleTableSourceFactoryTest {
@Test
public void testOptionalProperties ( ) {
Map < String , String > options = getAll Options( ) ;
Map < String , String > options = getAll Required Options( ) ;
options . put ( "port" , "1521" ) ;
options . put ( "hostname" , MY_LOCALHOST ) ;
options . put ( "url" , "jdbc:oracle:thin:@" + MY_LOCALHOST + ":1521" + ":" + MY_DATABASE ) ;
options . put ( "debezium.snapshot.mode" , "initial" ) ;
DynamicTableSource actualSource = createTableSource ( options ) ;
@ -122,6 +165,7 @@ public class OracleTableSourceFactoryTest {
OracleTableSource expectedSource =
new OracleTableSource (
SCHEMA ,
"jdbc:oracle:thin:@" + MY_LOCALHOST + ":1521" + ":" + MY_DATABASE ,
1521 ,
MY_LOCALHOST ,
MY_DATABASE ,
@ -136,7 +180,7 @@ public class OracleTableSourceFactoryTest {
@Test
public void testStartupFromInitial ( ) {
Map < String , String > properties = getAll Options( ) ;
Map < String , String > properties = getAll Required OptionsWithHost ( ) ;
properties . put ( "scan.startup.mode" , "initial" ) ;
// validation for source
@ -144,6 +188,7 @@ public class OracleTableSourceFactoryTest {
OracleTableSource expectedSource =
new OracleTableSource (
SCHEMA ,
null ,
1521 ,
MY_LOCALHOST ,
MY_DATABASE ,
@ -158,7 +203,7 @@ public class OracleTableSourceFactoryTest {
@Test
public void testStartupFromLatestOffset ( ) {
Map < String , String > properties = getAll Options( ) ;
Map < String , String > properties = getAll Required OptionsWithHost ( ) ;
properties . put ( "scan.startup.mode" , "latest-offset" ) ;
// validation for source
@ -166,6 +211,7 @@ public class OracleTableSourceFactoryTest {
OracleTableSource expectedSource =
new OracleTableSource (
SCHEMA ,
null ,
1521 ,
MY_LOCALHOST ,
MY_DATABASE ,
@ -180,7 +226,7 @@ public class OracleTableSourceFactoryTest {
@Test
public void testMetadataColumns ( ) {
Map < String , String > properties = getAll Options( ) ;
Map < String , String > properties = getAll Required OptionsWithHost ( ) ;
// validation for source
DynamicTableSource actualSource = createTableSource ( SCHEMA_WITH_METADATA , properties ) ;
@ -192,6 +238,7 @@ public class OracleTableSourceFactoryTest {
OracleTableSource expectedSource =
new OracleTableSource (
SCHEMA_WITH_METADATA ,
null ,
1521 ,
MY_LOCALHOST ,
MY_DATABASE ,
@ -219,7 +266,7 @@ public class OracleTableSourceFactoryTest {
public void testValidation ( ) {
// validate illegal port
try {
Map < String , String > properties = getAll Options( ) ;
Map < String , String > properties = getAll Required OptionsWithHost ( ) ;
properties . put ( "port" , "123b" ) ;
createTableSource ( properties ) ;
@ -234,7 +281,7 @@ public class OracleTableSourceFactoryTest {
// validate missing required
Factory factory = new OracleTableSourceFactory ( ) ;
for ( ConfigOption < ? > requiredOption : factory . requiredOptions ( ) ) {
Map < String , String > properties = getAll Options( ) ;
Map < String , String > properties = getAll Required OptionsWithHost ( ) ;
properties . remove ( requiredOption . key ( ) ) ;
try {
@ -251,7 +298,7 @@ public class OracleTableSourceFactoryTest {
// validate unsupported option
try {
Map < String , String > properties = getAll Options( ) ;
Map < String , String > properties = getAll Required OptionsWithHost ( ) ;
properties . put ( "unknown" , "abc" ) ;
createTableSource ( properties ) ;
@ -264,7 +311,7 @@ public class OracleTableSourceFactoryTest {
// validate unsupported option
try {
Map < String , String > properties = getAll Options( ) ;
Map < String , String > properties = getAll Required OptionsWithHost ( ) ;
properties . put ( "scan.startup.mode" , "abc" ) ;
createTableSource ( properties ) ;
@ -279,10 +326,9 @@ public class OracleTableSourceFactoryTest {
}
}
private Map < String , String > getAll Options( ) {
private Map < String , String > getAll Required Options( ) {
Map < String , String > options = new HashMap < > ( ) ;
options . put ( "connector" , "oracle-cdc" ) ;
options . put ( "hostname" , MY_LOCALHOST ) ;
options . put ( "database-name" , MY_DATABASE ) ;
options . put ( "table-name" , MY_TABLE ) ;
options . put ( "username" , MY_USERNAME ) ;
@ -291,6 +337,12 @@ public class OracleTableSourceFactoryTest {
return options ;
}
private Map < String , String > getAllRequiredOptionsWithHost ( ) {
Map < String , String > options = getAllRequiredOptions ( ) ;
options . put ( "hostname" , MY_LOCALHOST ) ;
return options ;
}
private static DynamicTableSource createTableSource ( Map < String , String > options ) {
return createTableSource ( SCHEMA , options ) ;
}