poojanilangekar commented on code in PR #1959:
URL: https://github.com/apache/polaris/pull/1959#discussion_r2180978888


##########
polaris-core/src/test/java/org/apache/polaris/service/storage/PolarisConfigurationStoreTest.java:
##########
@@ -186,4 +185,104 @@ public void testEntityOverrides() {
     Assertions.assertEquals(
         "entity-legacy4", store.getConfiguration(testRealmContext, entity, 
cfg.apply(4)));
   }
+
+  @Test
+  public void testLegacyKeyLookup() {
+    FeatureConfiguration<String> config =
+        PolarisConfiguration.<String>builder()
+            .key("LEGACY_KEY_TEST_NEW_KEY")
+            .legacyKey("LEGACY_TEST_OLD_KEY_1")
+            .legacyKey("LEGACY_TEST_OLD_KEY_2")
+            .description("Test config with legacy keys")
+            .defaultValue("default-value")
+            .buildFeatureConfiguration();
+
+    PolarisConfigurationStore store =
+        new PolarisConfigurationStore() {
+          @SuppressWarnings("unchecked")
+          @Override
+          public <T> T getConfiguration(@Nonnull RealmContext ctx, String 
configName) {
+            Map<String, String> values = Map.of("LEGACY_TEST_OLD_KEY_1", 
"legacy-value-1");
+            return (T) values.get(configName);
+          }
+        };
+
+    String result = store.getConfiguration(testRealmContext, config);
+    Assertions.assertEquals("legacy-value-1", result);
+  }
+
+  @Test
+  public void testMainKeyTakesPrecedenceOverLegacyKeys() {
+    FeatureConfiguration<String> config =
+        PolarisConfiguration.<String>builder()
+            .key("PRECEDENCE_TEST_NEW_KEY")
+            .legacyKey("PRECEDENCE_TEST_OLD_KEY")
+            .description("Test config with legacy keys")
+            .defaultValue("default-value")
+            .buildFeatureConfiguration();
+
+    PolarisConfigurationStore store =
+        new PolarisConfigurationStore() {
+          @SuppressWarnings("unchecked")
+          @Override
+          public <T> T getConfiguration(@Nonnull RealmContext ctx, String 
configName) {
+            Map<String, String> values =
+                Map.of(
+                    "PRECEDENCE_TEST_NEW_KEY", "new-value",
+                    "PRECEDENCE_TEST_OLD_KEY", "legacy-value");
+            return (T) values.get(configName);
+          }
+        };
+
+    String result = store.getConfiguration(testRealmContext, config);
+    Assertions.assertEquals("new-value", result);
+  }
+
+  @Test
+  public void testFallbackToDefaultWhenNoKeysFound() {
+    FeatureConfiguration<String> config =
+        PolarisConfiguration.<String>builder()
+            .key("FALLBACK_TEST_NEW_KEY")
+            .legacyKey("FALLBACK_TEST_OLD_KEY")
+            .description("Test config with legacy keys")
+            .defaultValue("default-value")
+            .buildFeatureConfiguration();
+
+    PolarisConfigurationStore store =
+        new PolarisConfigurationStore() {
+          @Override
+          public <T> T getConfiguration(@Nonnull RealmContext ctx, String 
configName) {
+            return null;
+          }
+        };
+
+    String result = store.getConfiguration(testRealmContext, config);
+    Assertions.assertEquals("default-value", result);
+  }
+
+  @Test
+  public void testLegacyKeyWarningIsLogged() {

Review Comment:
   This was my mistake, I should have removed it, I was trying to get the log 
warning but couldn't capture it. I've removed it now. (The functionality is 
still tested in testLegacyKeyLookup) 



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscr...@polaris.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to