|
| 1 | +/* |
| 2 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 3 | + * you may not use this file except in compliance with the License. |
| 4 | + * You may obtain a copy of the License at |
| 5 | + * |
| 6 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 7 | + * |
| 8 | + * Unless required by applicable law or agreed to in writing, software |
| 9 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 10 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 11 | + * See the License for the specific language governing permissions and |
| 12 | + * limitations under the License. |
| 13 | + */ |
| 14 | +package com.facebook.presto.plugin.blackhole; |
| 15 | + |
| 16 | +import com.facebook.presto.spi.ConnectorSession; |
| 17 | +import com.facebook.presto.testing.TestingConnectorSession; |
| 18 | +import org.testng.annotations.Test; |
| 19 | + |
| 20 | +import static org.testng.Assert.assertEquals; |
| 21 | +import static org.testng.Assert.assertFalse; |
| 22 | +import static org.testng.Assert.assertTrue; |
| 23 | + |
| 24 | +public class TestBlackHoleCaseSensitivity |
| 25 | +{ |
| 26 | + private static final ConnectorSession SESSION = TestingConnectorSession.SESSION; |
| 27 | + |
| 28 | + @Test |
| 29 | + public void testBlackHoleClientConfigDefaults() |
| 30 | + { |
| 31 | + BlackHoleClientConfig config = new BlackHoleClientConfig(); |
| 32 | + assertFalse(config.isCaseSensitiveNameMatching(), |
| 33 | + "Default should be case-insensitive"); |
| 34 | + } |
| 35 | + |
| 36 | + @Test |
| 37 | + public void testBlackHoleClientConfigCaseSensitive() |
| 38 | + { |
| 39 | + BlackHoleClientConfig config = new BlackHoleClientConfig() |
| 40 | + .setCaseSensitiveNameMatching(true); |
| 41 | + |
| 42 | + assertTrue(config.isCaseSensitiveNameMatching(), |
| 43 | + "Should be case-sensitive when enabled"); |
| 44 | + } |
| 45 | + |
| 46 | + @Test |
| 47 | + public void testBlackHoleClientConfigCaseInsensitive() |
| 48 | + { |
| 49 | + BlackHoleClientConfig config = new BlackHoleClientConfig() |
| 50 | + .setCaseSensitiveNameMatching(false); |
| 51 | + |
| 52 | + assertFalse(config.isCaseSensitiveNameMatching(), |
| 53 | + "Should be case-insensitive when disabled"); |
| 54 | + } |
| 55 | + |
| 56 | + @Test |
| 57 | + public void testBlackHoleMetadataNormalizeIdentifierCaseSensitive() |
| 58 | + { |
| 59 | + BlackHoleClientConfig config = new BlackHoleClientConfig() |
| 60 | + .setCaseSensitiveNameMatching(true); |
| 61 | + BlackHoleMetadata metadata = new BlackHoleMetadata(config); |
| 62 | + |
| 63 | + // Case-sensitive: identifiers should remain unchanged |
| 64 | + assertEquals(metadata.normalizeIdentifier(SESSION, "MyTable"), "MyTable"); |
| 65 | + assertEquals(metadata.normalizeIdentifier(SESSION, "myTable"), "myTable"); |
| 66 | + assertEquals(metadata.normalizeIdentifier(SESSION, "MYTABLE"), "MYTABLE"); |
| 67 | + assertEquals(metadata.normalizeIdentifier(SESSION, "MySchema"), "MySchema"); |
| 68 | + assertEquals(metadata.normalizeIdentifier(SESSION, "Test_Table"), "Test_Table"); |
| 69 | + } |
| 70 | + |
| 71 | + @Test |
| 72 | + public void testBlackHoleMetadataNormalizeIdentifierCaseInsensitive() |
| 73 | + { |
| 74 | + BlackHoleClientConfig config = new BlackHoleClientConfig() |
| 75 | + .setCaseSensitiveNameMatching(false); |
| 76 | + BlackHoleMetadata metadata = new BlackHoleMetadata(config); |
| 77 | + |
| 78 | + // Case-insensitive: identifiers should be lowercased |
| 79 | + assertEquals(metadata.normalizeIdentifier(SESSION, "MyTable"), "mytable"); |
| 80 | + assertEquals(metadata.normalizeIdentifier(SESSION, "myTable"), "mytable"); |
| 81 | + assertEquals(metadata.normalizeIdentifier(SESSION, "MYTABLE"), "mytable"); |
| 82 | + assertEquals(metadata.normalizeIdentifier(SESSION, "MySchema"), "myschema"); |
| 83 | + assertEquals(metadata.normalizeIdentifier(SESSION, "Test_Table"), "test_table"); |
| 84 | + } |
| 85 | + |
| 86 | + @Test |
| 87 | + public void testBlackHoleMetadataDefaultBehavior() |
| 88 | + { |
| 89 | + // Default metadata should be case-insensitive |
| 90 | + BlackHoleMetadata metadata = new BlackHoleMetadata(); |
| 91 | + |
| 92 | + assertEquals(metadata.normalizeIdentifier(SESSION, "MyTable"), "mytable"); |
| 93 | + assertEquals(metadata.normalizeIdentifier(SESSION, "TestSchema"), "testschema"); |
| 94 | + assertEquals(metadata.normalizeIdentifier(SESSION, "UPPERCASE"), "uppercase"); |
| 95 | + } |
| 96 | + |
| 97 | + @Test |
| 98 | + public void testConfigIntegrationWithMetadata() |
| 99 | + { |
| 100 | + // Test that config changes are properly reflected in metadata behavior |
| 101 | + |
| 102 | + // Case-sensitive config |
| 103 | + BlackHoleClientConfig caseSensitiveConfig = new BlackHoleClientConfig() |
| 104 | + .setCaseSensitiveNameMatching(true); |
| 105 | + BlackHoleMetadata caseSensitiveMetadata = new BlackHoleMetadata(caseSensitiveConfig); |
| 106 | + |
| 107 | + // Case-insensitive config |
| 108 | + BlackHoleClientConfig caseInsensitiveConfig = new BlackHoleClientConfig() |
| 109 | + .setCaseSensitiveNameMatching(false); |
| 110 | + BlackHoleMetadata caseInsensitiveMetadata = new BlackHoleMetadata(caseInsensitiveConfig); |
| 111 | + |
| 112 | + String testIdentifier = "MyTestTable"; |
| 113 | + |
| 114 | + assertEquals(caseSensitiveMetadata.normalizeIdentifier(SESSION, testIdentifier), "MyTestTable"); |
| 115 | + assertEquals(caseInsensitiveMetadata.normalizeIdentifier(SESSION, testIdentifier), "mytesttable"); |
| 116 | + } |
| 117 | + |
| 118 | + @Test |
| 119 | + public void testMultipleConfigInstances() |
| 120 | + { |
| 121 | + // Test that multiple config instances work independently |
| 122 | + BlackHoleClientConfig config1 = new BlackHoleClientConfig().setCaseSensitiveNameMatching(true); |
| 123 | + BlackHoleClientConfig config2 = new BlackHoleClientConfig().setCaseSensitiveNameMatching(false); |
| 124 | + |
| 125 | + assertTrue(config1.isCaseSensitiveNameMatching()); |
| 126 | + assertFalse(config2.isCaseSensitiveNameMatching()); |
| 127 | + |
| 128 | + // Test that they don't interfere with each other |
| 129 | + BlackHoleMetadata metadata1 = new BlackHoleMetadata(config1); |
| 130 | + BlackHoleMetadata metadata2 = new BlackHoleMetadata(config2); |
| 131 | + |
| 132 | + assertEquals(metadata1.normalizeIdentifier(SESSION, "TestCase"), "TestCase"); |
| 133 | + assertEquals(metadata2.normalizeIdentifier(SESSION, "TestCase"), "testcase"); |
| 134 | + } |
| 135 | + |
| 136 | + @Test |
| 137 | + public void testConfigChaining() |
| 138 | + { |
| 139 | + // Test that config setter returns the config instance for chaining |
| 140 | + BlackHoleClientConfig config = new BlackHoleClientConfig() |
| 141 | + .setCaseSensitiveNameMatching(true) |
| 142 | + .setCaseSensitiveNameMatching(false) |
| 143 | + .setCaseSensitiveNameMatching(true); |
| 144 | + |
| 145 | + assertTrue(config.isCaseSensitiveNameMatching(), |
| 146 | + "Final value should be true after chaining"); |
| 147 | + } |
| 148 | +} |
0 commit comments