|
23 | 23 | import org.junit.jupiter.api.Test;
|
24 | 24 |
|
25 | 25 | public class SqlTableTest {
|
| 26 | + |
| 27 | + private static final String NAME_PROPERTY = "nameProperty"; |
| 28 | + |
| 29 | + @Test |
| 30 | + public void testFullName() { |
| 31 | + SqlTable table = new SqlTable("my_table"); |
| 32 | + assertThat(table.tableNameAtRuntime()).isEqualTo("my_table"); |
| 33 | + } |
| 34 | + |
| 35 | + @Test |
| 36 | + public void testFullNameSupplier() { |
| 37 | + |
| 38 | + System.setProperty(NAME_PROPERTY, "my_table"); |
| 39 | + SqlTable table = new SqlTable(SqlTableTest::namePropertyReader); |
| 40 | + assertThat(table.tableNameAtRuntime()).isEqualTo("my_table"); |
| 41 | + System.clearProperty(NAME_PROPERTY); |
| 42 | + } |
26 | 43 |
|
27 | 44 | @Test
|
28 | 45 | public void testSchemaSupplierEmpty() {
|
29 | 46 | SqlTable table = new SqlTable(Optional::empty, "my_table");
|
30 |
| - assertThat(table.fullyQualifiedTableName()).isEqualTo("my_table"); |
| 47 | + assertThat(table.tableNameAtRuntime()).isEqualTo("my_table"); |
31 | 48 | }
|
32 | 49 |
|
33 | 50 | @Test
|
34 | 51 | public void testSchemaSupplierWithValue() {
|
35 | 52 | SqlTable table = new SqlTable(() -> Optional.of("my_schema"), "my_table");
|
36 |
| - assertThat(table.fullyQualifiedTableName()).isEqualTo("my_schema.my_table"); |
| 53 | + assertThat(table.tableNameAtRuntime()).isEqualTo("my_schema.my_table"); |
37 | 54 | }
|
38 | 55 |
|
39 | 56 | @Test
|
40 | 57 | public void testSingletonSchemaSupplier() {
|
41 | 58 | SqlTable table = new SqlTable(MySchemaSupplier.instance(), "my_table");
|
42 |
| - assertThat(table.fullyQualifiedTableName()).isEqualTo("first_schema.my_table"); |
| 59 | + assertThat(table.tableNameAtRuntime()).isEqualTo("first_schema.my_table"); |
43 | 60 | }
|
44 | 61 |
|
45 | 62 | @Test
|
46 | 63 | public void testThatSchemaSupplierDoesDelay() {
|
47 | 64 | MySchemaSupplier schemaSupplier = new MySchemaSupplier();
|
48 | 65 | SqlTable table = new SqlTable(schemaSupplier, "my_table");
|
49 |
| - assertThat(table.fullyQualifiedTableName()).isEqualTo("first_schema.my_table"); |
| 66 | + assertThat(table.tableNameAtRuntime()).isEqualTo("first_schema.my_table"); |
50 | 67 |
|
51 | 68 | schemaSupplier.setFirst(false);
|
52 |
| - assertThat(table.fullyQualifiedTableName()).isEqualTo("second_schema.my_table"); |
| 69 | + assertThat(table.tableNameAtRuntime()).isEqualTo("second_schema.my_table"); |
53 | 70 | }
|
54 | 71 |
|
55 | 72 | @Test
|
56 | 73 | public void testCatalogAndSchemaSupplierEmpty() {
|
57 | 74 | SqlTable table = new SqlTable(Optional::empty, Optional::empty, "my_table");
|
58 |
| - assertThat(table.fullyQualifiedTableName()).isEqualTo("my_table"); |
| 75 | + assertThat(table.tableNameAtRuntime()).isEqualTo("my_table"); |
59 | 76 | }
|
60 | 77 |
|
61 | 78 | @Test
|
62 | 79 | public void testCatalogSupplierWithValue() {
|
63 | 80 | SqlTable table = new SqlTable(() -> Optional.of("my_catalog"), Optional::empty, "my_table");
|
64 |
| - assertThat(table.fullyQualifiedTableName()).isEqualTo("my_catalog..my_table"); |
| 81 | + assertThat(table.tableNameAtRuntime()).isEqualTo("my_catalog..my_table"); |
65 | 82 | }
|
66 | 83 |
|
67 | 84 | @Test
|
68 | 85 | public void testThatCatalogSupplierDoesDelay() {
|
69 | 86 | MyCatalogSupplier catalogSupplier = new MyCatalogSupplier();
|
70 | 87 | SqlTable table = new SqlTable(catalogSupplier, Optional::empty, "my_table");
|
71 |
| - assertThat(table.fullyQualifiedTableName()).isEqualTo("first_catalog..my_table"); |
| 88 | + assertThat(table.tableNameAtRuntime()).isEqualTo("first_catalog..my_table"); |
72 | 89 |
|
73 | 90 | catalogSupplier.setFirst(false);
|
74 |
| - assertThat(table.fullyQualifiedTableName()).isEqualTo("second_catalog..my_table"); |
| 91 | + assertThat(table.tableNameAtRuntime()).isEqualTo("second_catalog..my_table"); |
75 | 92 | }
|
76 | 93 |
|
77 | 94 | @Test
|
78 | 95 | public void testThatCatalogSupplierAndSchemaSupplierBothDelay() {
|
79 | 96 | MyCatalogSupplier catalogSupplier = new MyCatalogSupplier();
|
80 | 97 | MySchemaSupplier schemaSupplier = new MySchemaSupplier();
|
81 | 98 | SqlTable table = new SqlTable(catalogSupplier, schemaSupplier, "my_table");
|
82 |
| - assertThat(table.fullyQualifiedTableName()).isEqualTo("first_catalog.first_schema.my_table"); |
| 99 | + assertThat(table.tableNameAtRuntime()).isEqualTo("first_catalog.first_schema.my_table"); |
83 | 100 |
|
84 | 101 | catalogSupplier.setFirst(false);
|
85 |
| - assertThat(table.fullyQualifiedTableName()).isEqualTo("second_catalog.first_schema.my_table"); |
| 102 | + assertThat(table.tableNameAtRuntime()).isEqualTo("second_catalog.first_schema.my_table"); |
86 | 103 |
|
87 | 104 | catalogSupplier.setFirst(true);
|
88 | 105 | schemaSupplier.setFirst(false);
|
89 |
| - assertThat(table.fullyQualifiedTableName()).isEqualTo("first_catalog.second_schema.my_table"); |
| 106 | + assertThat(table.tableNameAtRuntime()).isEqualTo("first_catalog.second_schema.my_table"); |
90 | 107 |
|
91 | 108 | catalogSupplier.setFirst(false);
|
92 |
| - assertThat(table.fullyQualifiedTableName()).isEqualTo("second_catalog.second_schema.my_table"); |
| 109 | + assertThat(table.tableNameAtRuntime()).isEqualTo("second_catalog.second_schema.my_table"); |
93 | 110 |
|
94 | 111 | catalogSupplier.setEmpty(true);
|
95 |
| - assertThat(table.fullyQualifiedTableName()).isEqualTo("second_schema.my_table"); |
| 112 | + assertThat(table.tableNameAtRuntime()).isEqualTo("second_schema.my_table"); |
96 | 113 |
|
97 | 114 | schemaSupplier.setEmpty(true);
|
98 |
| - assertThat(table.fullyQualifiedTableName()).isEqualTo("my_table"); |
| 115 | + assertThat(table.tableNameAtRuntime()).isEqualTo("my_table"); |
99 | 116 |
|
100 | 117 | catalogSupplier.setEmpty(false);
|
101 |
| - assertThat(table.fullyQualifiedTableName()).isEqualTo("second_catalog..my_table"); |
| 118 | + assertThat(table.tableNameAtRuntime()).isEqualTo("second_catalog..my_table"); |
| 119 | + } |
| 120 | + |
| 121 | + private static String namePropertyReader() { |
| 122 | + return System.getProperty(NAME_PROPERTY); |
102 | 123 | }
|
103 | 124 |
|
104 | 125 | public static class MySchemaSupplier implements Supplier<Optional<String>> {
|
|
0 commit comments