nastra commented on code in PR #7004:
URL: https://github.com/apache/iceberg/pull/7004#discussion_r1127693987


##########
snowflake/src/integration/java/org/apache/iceberg/snowflake/NamespaceTests.java:
##########
@@ -0,0 +1,290 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.iceberg.snowflake;
+
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import org.apache.iceberg.catalog.Namespace;
+import org.apache.iceberg.exceptions.NoSuchNamespaceException;
+import org.assertj.core.api.Assertions;
+import org.junit.Test;
+
+public class NamespaceTests extends SnowTestBase {
+
+  @Test
+  public void testListNamespacesAtRootLevel() throws SQLException, 
InterruptedException {
+    List<Namespace> namespaces = 
snowflakeCatalog.listNamespaces(Namespace.empty());
+    int dbCount =
+        clientPool.run(
+            conn -> {
+              int databaseCount = 0;
+              ResultSet rs = conn.createStatement().executeQuery("show 
databases");
+              while (rs.next()) {
+                databaseCount++;
+              }
+              return databaseCount;
+            });
+    Assertions.assertThat(namespaces.stream().count()).isEqualTo(dbCount);
+  }
+
+  @Test
+  public void testListNamespacesAtDatabaseLevel() throws SQLException, 
InterruptedException {
+    String schema1 = "Schema_1";
+    String schema2 = "Schema_2";
+    String dbName = 
TestConfigurations.getInstance().getDatabase().toUpperCase();
+    try {
+      clientPool.run(conn -> conn.createStatement().execute("use " + dbName));
+      createOrReplaceSchema(schema1);
+      createOrReplaceSchema(schema2);
+      List<Namespace> namespaces = 
snowflakeCatalog.listNamespaces(Namespace.of(dbName));
+      Assertions.assertThat(namespaces)
+          .containsExactlyInAnyOrderElementsOf(
+              new ArrayList<Namespace>(

Review Comment:
   I believe the additional `new ArrayList<Namespace>(..)` is not required



##########
snowflake/src/integration/java/org/apache/iceberg/snowflake/NamespaceTests.java:
##########
@@ -0,0 +1,290 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.iceberg.snowflake;
+
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import org.apache.iceberg.catalog.Namespace;
+import org.apache.iceberg.exceptions.NoSuchNamespaceException;
+import org.assertj.core.api.Assertions;
+import org.junit.Test;
+
+public class NamespaceTests extends SnowTestBase {
+
+  @Test
+  public void testListNamespacesAtRootLevel() throws SQLException, 
InterruptedException {
+    List<Namespace> namespaces = 
snowflakeCatalog.listNamespaces(Namespace.empty());
+    int dbCount =
+        clientPool.run(
+            conn -> {
+              int databaseCount = 0;
+              ResultSet rs = conn.createStatement().executeQuery("show 
databases");
+              while (rs.next()) {
+                databaseCount++;
+              }
+              return databaseCount;
+            });
+    Assertions.assertThat(namespaces.stream().count()).isEqualTo(dbCount);
+  }
+
+  @Test
+  public void testListNamespacesAtDatabaseLevel() throws SQLException, 
InterruptedException {
+    String schema1 = "Schema_1";
+    String schema2 = "Schema_2";
+    String dbName = 
TestConfigurations.getInstance().getDatabase().toUpperCase();
+    try {
+      clientPool.run(conn -> conn.createStatement().execute("use " + dbName));
+      createOrReplaceSchema(schema1);
+      createOrReplaceSchema(schema2);
+      List<Namespace> namespaces = 
snowflakeCatalog.listNamespaces(Namespace.of(dbName));
+      Assertions.assertThat(namespaces)
+          .containsExactlyInAnyOrderElementsOf(
+              new ArrayList<Namespace>(
+                  Arrays.asList(
+                      Namespace.of(dbName, schema1.toUpperCase()),
+                      Namespace.of(dbName, schema2.toUpperCase()),
+                      Namespace.of(dbName, "PUBLIC"),
+                      Namespace.of(dbName, "INFORMATION_SCHEMA"))));
+    } finally {
+      dropSchemaIfExists(schema1);
+      dropSchemaIfExists(schema2);
+    }
+  }
+
+  @Test
+  public void testListNamespacesAtSchemaLevelIsNotAllowed()
+      throws SQLException, InterruptedException {
+    String schema1 = "Schema_1";
+    String dbName = 
TestConfigurations.getInstance().getDatabase().toUpperCase();
+    try {
+      clientPool.run(conn -> conn.createStatement().execute("use " + dbName));
+      createOrReplaceSchema(schema1);
+      Assertions.assertThatException()
+          .isThrownBy(
+              () -> {
+                snowflakeCatalog.listNamespaces(Namespace.of(dbName, schema1));
+              })
+          .isInstanceOf(IllegalArgumentException.class);
+    } finally {
+      dropSchemaIfExists(schema1);
+    }
+  }
+
+  @Test
+  public void testLoadNonExistingRootLevelNamespace() {
+    String nonExistingDb = "IDontExist";
+    Assertions.assertThatThrownBy(
+            () -> {
+              
snowflakeCatalog.loadNamespaceMetadata(Namespace.of(nonExistingDb));
+            })
+        .isInstanceOf(NoSuchNamespaceException.class);
+  }
+
+  @Test
+  public void testLoadNonExistingDBLevelNamespace() {
+    String nonExistingSchema = "IDontExist";
+    String db = TestConfigurations.getInstance().getDatabase();
+    Assertions.assertThatThrownBy(
+            () -> {
+              snowflakeCatalog.loadNamespaceMetadata(Namespace.of(db, 
nonExistingSchema));
+            })
+        .isInstanceOf(NoSuchNamespaceException.class);
+  }
+
+  @Test
+  public void testLoadNamespaceThatExceedMaxSupportedHierarchy() {
+    String nonExistingSchema = "IDontExist";
+    String db = TestConfigurations.getInstance().getDatabase();
+    Assertions.assertThatThrownBy(
+            () -> {
+              snowflakeCatalog.loadNamespaceMetadata(
+                  Namespace.of(db, nonExistingSchema, "UnSupportedLevel"));
+            })
+        .isInstanceOf(IllegalArgumentException.class);
+  }
+
+  @Test
+  public void testLoadNamespaceWithUnquotedIdentifier() throws SQLException, 
InterruptedException {
+    String schema1 = "Schema123";
+    String dbName = TestConfigurations.getInstance().getDatabase();
+    try {
+      Assertions.assertThatNoException()
+          .isThrownBy(
+              () -> {
+                clientPool.run(conn -> conn.createStatement().execute("use " + 
dbName));
+                createOrReplaceSchema(schema1);
+                snowflakeCatalog.loadNamespaceMetadata(Namespace.of(dbName, 
schema1));

Review Comment:
   rather than using `Assertions.assertThatNoException()` it would be better to 
assert that the correct metadata is returned



##########
snowflake/src/integration/java/org/apache/iceberg/snowflake/SnowTestBase.java:
##########
@@ -0,0 +1,110 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.iceberg.snowflake;
+
+import java.sql.PreparedStatement;
+import java.sql.SQLException;
+import org.apache.iceberg.jdbc.JdbcClientPool;
+import org.apache.iceberg.relocated.com.google.common.base.Preconditions;
+import org.junit.BeforeClass;
+import org.junit.jupiter.api.AfterAll;
+
+@SuppressWarnings("VisibilityModifier")
+class SnowTestBase {
+
+  static SnowflakeCatalog snowflakeCatalog;
+
+  static JdbcClientPool clientPool;
+
+  protected SnowTestBase() {}
+
+  @BeforeClass
+  public static void beforeAll() {
+    snowflakeCatalog = new SnowflakeCatalog();
+    TestConfigurations configs = TestConfigurations.getInstance();

Review Comment:
   Why not just expose the respective fields (db, user, uri) in `SnowTestBase` 
for subclasses rather than introducing `TestConfigurations`?



##########
snowflake/src/integration/java/org/apache/iceberg/snowflake/NamespaceTests.java:
##########
@@ -0,0 +1,290 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.iceberg.snowflake;
+
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import org.apache.iceberg.catalog.Namespace;
+import org.apache.iceberg.exceptions.NoSuchNamespaceException;
+import org.assertj.core.api.Assertions;
+import org.junit.Test;
+
+public class NamespaceTests extends SnowTestBase {
+
+  @Test
+  public void testListNamespacesAtRootLevel() throws SQLException, 
InterruptedException {
+    List<Namespace> namespaces = 
snowflakeCatalog.listNamespaces(Namespace.empty());
+    int dbCount =
+        clientPool.run(
+            conn -> {
+              int databaseCount = 0;
+              ResultSet rs = conn.createStatement().executeQuery("show 
databases");
+              while (rs.next()) {
+                databaseCount++;
+              }
+              return databaseCount;
+            });
+    Assertions.assertThat(namespaces.stream().count()).isEqualTo(dbCount);
+  }
+
+  @Test
+  public void testListNamespacesAtDatabaseLevel() throws SQLException, 
InterruptedException {
+    String schema1 = "Schema_1";
+    String schema2 = "Schema_2";
+    String dbName = 
TestConfigurations.getInstance().getDatabase().toUpperCase();
+    try {
+      clientPool.run(conn -> conn.createStatement().execute("use " + dbName));
+      createOrReplaceSchema(schema1);
+      createOrReplaceSchema(schema2);
+      List<Namespace> namespaces = 
snowflakeCatalog.listNamespaces(Namespace.of(dbName));
+      Assertions.assertThat(namespaces)
+          .containsExactlyInAnyOrderElementsOf(
+              new ArrayList<Namespace>(
+                  Arrays.asList(
+                      Namespace.of(dbName, schema1.toUpperCase()),
+                      Namespace.of(dbName, schema2.toUpperCase()),
+                      Namespace.of(dbName, "PUBLIC"),
+                      Namespace.of(dbName, "INFORMATION_SCHEMA"))));
+    } finally {
+      dropSchemaIfExists(schema1);
+      dropSchemaIfExists(schema2);
+    }
+  }
+
+  @Test
+  public void testListNamespacesAtSchemaLevelIsNotAllowed()
+      throws SQLException, InterruptedException {
+    String schema1 = "Schema_1";
+    String dbName = 
TestConfigurations.getInstance().getDatabase().toUpperCase();
+    try {
+      clientPool.run(conn -> conn.createStatement().execute("use " + dbName));
+      createOrReplaceSchema(schema1);
+      Assertions.assertThatException()
+          .isThrownBy(
+              () -> {
+                snowflakeCatalog.listNamespaces(Namespace.of(dbName, schema1));
+              })
+          .isInstanceOf(IllegalArgumentException.class);
+    } finally {
+      dropSchemaIfExists(schema1);
+    }
+  }
+
+  @Test
+  public void testLoadNonExistingRootLevelNamespace() {
+    String nonExistingDb = "IDontExist";
+    Assertions.assertThatThrownBy(
+            () -> {
+              
snowflakeCatalog.loadNamespaceMetadata(Namespace.of(nonExistingDb));
+            })
+        .isInstanceOf(NoSuchNamespaceException.class);
+  }
+
+  @Test
+  public void testLoadNonExistingDBLevelNamespace() {
+    String nonExistingSchema = "IDontExist";
+    String db = TestConfigurations.getInstance().getDatabase();
+    Assertions.assertThatThrownBy(
+            () -> {
+              snowflakeCatalog.loadNamespaceMetadata(Namespace.of(db, 
nonExistingSchema));
+            })
+        .isInstanceOf(NoSuchNamespaceException.class);
+  }
+
+  @Test
+  public void testLoadNamespaceThatExceedMaxSupportedHierarchy() {
+    String nonExistingSchema = "IDontExist";
+    String db = TestConfigurations.getInstance().getDatabase();
+    Assertions.assertThatThrownBy(
+            () -> {
+              snowflakeCatalog.loadNamespaceMetadata(
+                  Namespace.of(db, nonExistingSchema, "UnSupportedLevel"));
+            })
+        .isInstanceOf(IllegalArgumentException.class);
+  }
+
+  @Test
+  public void testLoadNamespaceWithUnquotedIdentifier() throws SQLException, 
InterruptedException {
+    String schema1 = "Schema123";
+    String dbName = TestConfigurations.getInstance().getDatabase();
+    try {
+      Assertions.assertThatNoException()
+          .isThrownBy(
+              () -> {
+                clientPool.run(conn -> conn.createStatement().execute("use " + 
dbName));
+                createOrReplaceSchema(schema1);
+                snowflakeCatalog.loadNamespaceMetadata(Namespace.of(dbName, 
schema1));
+              });
+    } finally {
+      dropSchemaIfExists(schema1);
+    }
+  }
+
+  @Test
+  public void testLoadNamespaceWithUnquotedIdentifierIsCaseInsensitive()
+      throws SQLException, InterruptedException {
+    String schema1 = "Schema123";
+    String dbName = TestConfigurations.getInstance().getDatabase();
+    try {
+      Assertions.assertThatNoException()
+          .isThrownBy(
+              () -> {
+                clientPool.run(conn -> conn.createStatement().execute("use " + 
dbName));
+                createOrReplaceSchema(schema1);
+                snowflakeCatalog.loadNamespaceMetadata(Namespace.of(dbName, 
schema1));
+                snowflakeCatalog.loadNamespaceMetadata(Namespace.of(dbName, 
schema1.toUpperCase()));
+                snowflakeCatalog.loadNamespaceMetadata(Namespace.of(dbName, 
"schEmA123"));
+              });
+    } finally {
+      dropSchemaIfExists(schema1);
+    }
+  }
+
+  @Test
+  public void 
testLoadNamespaceWithUnquotedIdentifierWithLeadingUnderscoreAndDollarCharacters()
+      throws SQLException, InterruptedException {
+    String schema1 = "_Schema$_123";
+    String dbName = TestConfigurations.getInstance().getDatabase();
+    try {
+      Assertions.assertThatNoException()

Review Comment:
   reading through all the test methods around this, I think it would make 
sense to use [JUnit5 + parameterized 
tests](https://junit.org/junit5/docs/current/user-guide/#writing-tests-parameterized-tests)
 because the tests mainly differ in the schema name



##########
snowflake/src/integration/java/org/apache/iceberg/snowflake/NamespaceTests.java:
##########
@@ -0,0 +1,290 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.iceberg.snowflake;
+
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import org.apache.iceberg.catalog.Namespace;
+import org.apache.iceberg.exceptions.NoSuchNamespaceException;
+import org.assertj.core.api.Assertions;
+import org.junit.Test;

Review Comment:
   as mentioned on `SnowTestBase` it would be better to switch to Junit5 tests 
for new stuff



##########
snowflake/src/integration/java/org/apache/iceberg/snowflake/NamespaceTests.java:
##########
@@ -0,0 +1,290 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.iceberg.snowflake;
+
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import org.apache.iceberg.catalog.Namespace;
+import org.apache.iceberg.exceptions.NoSuchNamespaceException;
+import org.assertj.core.api.Assertions;
+import org.junit.Test;
+
+public class NamespaceTests extends SnowTestBase {
+
+  @Test
+  public void testListNamespacesAtRootLevel() throws SQLException, 
InterruptedException {
+    List<Namespace> namespaces = 
snowflakeCatalog.listNamespaces(Namespace.empty());
+    int dbCount =
+        clientPool.run(
+            conn -> {
+              int databaseCount = 0;
+              ResultSet rs = conn.createStatement().executeQuery("show 
databases");
+              while (rs.next()) {
+                databaseCount++;
+              }
+              return databaseCount;
+            });
+    Assertions.assertThat(namespaces.stream().count()).isEqualTo(dbCount);
+  }
+
+  @Test
+  public void testListNamespacesAtDatabaseLevel() throws SQLException, 
InterruptedException {
+    String schema1 = "Schema_1";
+    String schema2 = "Schema_2";
+    String dbName = 
TestConfigurations.getInstance().getDatabase().toUpperCase();
+    try {
+      clientPool.run(conn -> conn.createStatement().execute("use " + dbName));
+      createOrReplaceSchema(schema1);
+      createOrReplaceSchema(schema2);
+      List<Namespace> namespaces = 
snowflakeCatalog.listNamespaces(Namespace.of(dbName));
+      Assertions.assertThat(namespaces)
+          .containsExactlyInAnyOrderElementsOf(
+              new ArrayList<Namespace>(
+                  Arrays.asList(
+                      Namespace.of(dbName, schema1.toUpperCase()),
+                      Namespace.of(dbName, schema2.toUpperCase()),
+                      Namespace.of(dbName, "PUBLIC"),
+                      Namespace.of(dbName, "INFORMATION_SCHEMA"))));
+    } finally {
+      dropSchemaIfExists(schema1);
+      dropSchemaIfExists(schema2);
+    }
+  }
+
+  @Test
+  public void testListNamespacesAtSchemaLevelIsNotAllowed()
+      throws SQLException, InterruptedException {
+    String schema1 = "Schema_1";
+    String dbName = 
TestConfigurations.getInstance().getDatabase().toUpperCase();
+    try {
+      clientPool.run(conn -> conn.createStatement().execute("use " + dbName));
+      createOrReplaceSchema(schema1);
+      Assertions.assertThatException()
+          .isThrownBy(
+              () -> {
+                snowflakeCatalog.listNamespaces(Namespace.of(dbName, schema1));
+              })
+          .isInstanceOf(IllegalArgumentException.class);
+    } finally {
+      dropSchemaIfExists(schema1);
+    }
+  }
+
+  @Test
+  public void testLoadNonExistingRootLevelNamespace() {
+    String nonExistingDb = "IDontExist";
+    Assertions.assertThatThrownBy(
+            () -> {
+              
snowflakeCatalog.loadNamespaceMetadata(Namespace.of(nonExistingDb));
+            })
+        .isInstanceOf(NoSuchNamespaceException.class);
+  }
+
+  @Test
+  public void testLoadNonExistingDBLevelNamespace() {
+    String nonExistingSchema = "IDontExist";
+    String db = TestConfigurations.getInstance().getDatabase();
+    Assertions.assertThatThrownBy(
+            () -> {
+              snowflakeCatalog.loadNamespaceMetadata(Namespace.of(db, 
nonExistingSchema));
+            })
+        .isInstanceOf(NoSuchNamespaceException.class);
+  }
+
+  @Test
+  public void testLoadNamespaceThatExceedMaxSupportedHierarchy() {
+    String nonExistingSchema = "IDontExist";
+    String db = TestConfigurations.getInstance().getDatabase();
+    Assertions.assertThatThrownBy(
+            () -> {
+              snowflakeCatalog.loadNamespaceMetadata(
+                  Namespace.of(db, nonExistingSchema, "UnSupportedLevel"));
+            })
+        .isInstanceOf(IllegalArgumentException.class);
+  }
+
+  @Test
+  public void testLoadNamespaceWithUnquotedIdentifier() throws SQLException, 
InterruptedException {
+    String schema1 = "Schema123";
+    String dbName = TestConfigurations.getInstance().getDatabase();
+    try {
+      Assertions.assertThatNoException()
+          .isThrownBy(
+              () -> {
+                clientPool.run(conn -> conn.createStatement().execute("use " + 
dbName));
+                createOrReplaceSchema(schema1);
+                snowflakeCatalog.loadNamespaceMetadata(Namespace.of(dbName, 
schema1));
+              });
+    } finally {
+      dropSchemaIfExists(schema1);
+    }
+  }
+
+  @Test
+  public void testLoadNamespaceWithUnquotedIdentifierIsCaseInsensitive()
+      throws SQLException, InterruptedException {
+    String schema1 = "Schema123";
+    String dbName = TestConfigurations.getInstance().getDatabase();
+    try {
+      Assertions.assertThatNoException()
+          .isThrownBy(
+              () -> {
+                clientPool.run(conn -> conn.createStatement().execute("use " + 
dbName));
+                createOrReplaceSchema(schema1);
+                snowflakeCatalog.loadNamespaceMetadata(Namespace.of(dbName, 
schema1));
+                snowflakeCatalog.loadNamespaceMetadata(Namespace.of(dbName, 
schema1.toUpperCase()));
+                snowflakeCatalog.loadNamespaceMetadata(Namespace.of(dbName, 
"schEmA123"));
+              });
+    } finally {
+      dropSchemaIfExists(schema1);
+    }
+  }
+
+  @Test
+  public void 
testLoadNamespaceWithUnquotedIdentifierWithLeadingUnderscoreAndDollarCharacters()
+      throws SQLException, InterruptedException {
+    String schema1 = "_Schema$_123";
+    String dbName = TestConfigurations.getInstance().getDatabase();
+    try {
+      Assertions.assertThatNoException()

Review Comment:
   same as above



##########
snowflake/src/integration/java/org/apache/iceberg/snowflake/NamespaceTests.java:
##########
@@ -0,0 +1,290 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.iceberg.snowflake;
+
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import org.apache.iceberg.catalog.Namespace;
+import org.apache.iceberg.exceptions.NoSuchNamespaceException;
+import org.assertj.core.api.Assertions;
+import org.junit.Test;
+
+public class NamespaceTests extends SnowTestBase {
+
+  @Test
+  public void testListNamespacesAtRootLevel() throws SQLException, 
InterruptedException {
+    List<Namespace> namespaces = 
snowflakeCatalog.listNamespaces(Namespace.empty());
+    int dbCount =
+        clientPool.run(
+            conn -> {
+              int databaseCount = 0;
+              ResultSet rs = conn.createStatement().executeQuery("show 
databases");
+              while (rs.next()) {
+                databaseCount++;
+              }
+              return databaseCount;
+            });
+    Assertions.assertThat(namespaces.stream().count()).isEqualTo(dbCount);
+  }
+
+  @Test
+  public void testListNamespacesAtDatabaseLevel() throws SQLException, 
InterruptedException {
+    String schema1 = "Schema_1";
+    String schema2 = "Schema_2";
+    String dbName = 
TestConfigurations.getInstance().getDatabase().toUpperCase();
+    try {
+      clientPool.run(conn -> conn.createStatement().execute("use " + dbName));
+      createOrReplaceSchema(schema1);
+      createOrReplaceSchema(schema2);
+      List<Namespace> namespaces = 
snowflakeCatalog.listNamespaces(Namespace.of(dbName));
+      Assertions.assertThat(namespaces)
+          .containsExactlyInAnyOrderElementsOf(
+              new ArrayList<Namespace>(
+                  Arrays.asList(
+                      Namespace.of(dbName, schema1.toUpperCase()),
+                      Namespace.of(dbName, schema2.toUpperCase()),
+                      Namespace.of(dbName, "PUBLIC"),
+                      Namespace.of(dbName, "INFORMATION_SCHEMA"))));
+    } finally {
+      dropSchemaIfExists(schema1);
+      dropSchemaIfExists(schema2);
+    }
+  }
+
+  @Test
+  public void testListNamespacesAtSchemaLevelIsNotAllowed()
+      throws SQLException, InterruptedException {
+    String schema1 = "Schema_1";
+    String dbName = 
TestConfigurations.getInstance().getDatabase().toUpperCase();
+    try {
+      clientPool.run(conn -> conn.createStatement().execute("use " + dbName));
+      createOrReplaceSchema(schema1);
+      Assertions.assertThatException()
+          .isThrownBy(
+              () -> {
+                snowflakeCatalog.listNamespaces(Namespace.of(dbName, schema1));
+              })
+          .isInstanceOf(IllegalArgumentException.class);

Review Comment:
   all of these checks that verify a certain type of exception is thrown should 
have a check for the error message: `hasMessage(...)`



##########
snowflake/src/integration/java/org/apache/iceberg/snowflake/NamespaceTests.java:
##########
@@ -0,0 +1,290 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.iceberg.snowflake;
+
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import org.apache.iceberg.catalog.Namespace;
+import org.apache.iceberg.exceptions.NoSuchNamespaceException;
+import org.assertj.core.api.Assertions;
+import org.junit.Test;
+
+public class NamespaceTests extends SnowTestBase {
+
+  @Test
+  public void testListNamespacesAtRootLevel() throws SQLException, 
InterruptedException {
+    List<Namespace> namespaces = 
snowflakeCatalog.listNamespaces(Namespace.empty());
+    int dbCount =
+        clientPool.run(
+            conn -> {
+              int databaseCount = 0;
+              ResultSet rs = conn.createStatement().executeQuery("show 
databases");
+              while (rs.next()) {
+                databaseCount++;
+              }
+              return databaseCount;
+            });
+    Assertions.assertThat(namespaces.stream().count()).isEqualTo(dbCount);
+  }
+
+  @Test
+  public void testListNamespacesAtDatabaseLevel() throws SQLException, 
InterruptedException {
+    String schema1 = "Schema_1";
+    String schema2 = "Schema_2";
+    String dbName = 
TestConfigurations.getInstance().getDatabase().toUpperCase();
+    try {
+      clientPool.run(conn -> conn.createStatement().execute("use " + dbName));
+      createOrReplaceSchema(schema1);
+      createOrReplaceSchema(schema2);
+      List<Namespace> namespaces = 
snowflakeCatalog.listNamespaces(Namespace.of(dbName));
+      Assertions.assertThat(namespaces)
+          .containsExactlyInAnyOrderElementsOf(
+              new ArrayList<Namespace>(
+                  Arrays.asList(
+                      Namespace.of(dbName, schema1.toUpperCase()),
+                      Namespace.of(dbName, schema2.toUpperCase()),
+                      Namespace.of(dbName, "PUBLIC"),
+                      Namespace.of(dbName, "INFORMATION_SCHEMA"))));
+    } finally {
+      dropSchemaIfExists(schema1);
+      dropSchemaIfExists(schema2);
+    }
+  }
+
+  @Test
+  public void testListNamespacesAtSchemaLevelIsNotAllowed()
+      throws SQLException, InterruptedException {
+    String schema1 = "Schema_1";
+    String dbName = 
TestConfigurations.getInstance().getDatabase().toUpperCase();
+    try {
+      clientPool.run(conn -> conn.createStatement().execute("use " + dbName));
+      createOrReplaceSchema(schema1);
+      Assertions.assertThatException()
+          .isThrownBy(
+              () -> {
+                snowflakeCatalog.listNamespaces(Namespace.of(dbName, schema1));
+              })
+          .isInstanceOf(IllegalArgumentException.class);
+    } finally {
+      dropSchemaIfExists(schema1);
+    }
+  }
+
+  @Test
+  public void testLoadNonExistingRootLevelNamespace() {
+    String nonExistingDb = "IDontExist";
+    Assertions.assertThatThrownBy(
+            () -> {
+              
snowflakeCatalog.loadNamespaceMetadata(Namespace.of(nonExistingDb));
+            })
+        .isInstanceOf(NoSuchNamespaceException.class);
+  }
+
+  @Test
+  public void testLoadNonExistingDBLevelNamespace() {
+    String nonExistingSchema = "IDontExist";
+    String db = TestConfigurations.getInstance().getDatabase();
+    Assertions.assertThatThrownBy(
+            () -> {
+              snowflakeCatalog.loadNamespaceMetadata(Namespace.of(db, 
nonExistingSchema));
+            })
+        .isInstanceOf(NoSuchNamespaceException.class);
+  }
+
+  @Test
+  public void testLoadNamespaceThatExceedMaxSupportedHierarchy() {
+    String nonExistingSchema = "IDontExist";
+    String db = TestConfigurations.getInstance().getDatabase();
+    Assertions.assertThatThrownBy(
+            () -> {
+              snowflakeCatalog.loadNamespaceMetadata(
+                  Namespace.of(db, nonExistingSchema, "UnSupportedLevel"));
+            })
+        .isInstanceOf(IllegalArgumentException.class);
+  }
+
+  @Test
+  public void testLoadNamespaceWithUnquotedIdentifier() throws SQLException, 
InterruptedException {
+    String schema1 = "Schema123";
+    String dbName = TestConfigurations.getInstance().getDatabase();
+    try {
+      Assertions.assertThatNoException()
+          .isThrownBy(
+              () -> {
+                clientPool.run(conn -> conn.createStatement().execute("use " + 
dbName));
+                createOrReplaceSchema(schema1);
+                snowflakeCatalog.loadNamespaceMetadata(Namespace.of(dbName, 
schema1));
+              });
+    } finally {
+      dropSchemaIfExists(schema1);
+    }
+  }
+
+  @Test
+  public void testLoadNamespaceWithUnquotedIdentifierIsCaseInsensitive()
+      throws SQLException, InterruptedException {
+    String schema1 = "Schema123";
+    String dbName = TestConfigurations.getInstance().getDatabase();
+    try {
+      Assertions.assertThatNoException()

Review Comment:
   same as above, it's better to verify that the correct namespace metadata is 
returned



##########
snowflake/src/integration/java/org/apache/iceberg/snowflake/NamespaceTests.java:
##########
@@ -0,0 +1,290 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.iceberg.snowflake;
+
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import org.apache.iceberg.catalog.Namespace;
+import org.apache.iceberg.exceptions.NoSuchNamespaceException;
+import org.assertj.core.api.Assertions;
+import org.junit.Test;
+
+public class NamespaceTests extends SnowTestBase {
+
+  @Test
+  public void testListNamespacesAtRootLevel() throws SQLException, 
InterruptedException {
+    List<Namespace> namespaces = 
snowflakeCatalog.listNamespaces(Namespace.empty());
+    int dbCount =
+        clientPool.run(
+            conn -> {
+              int databaseCount = 0;
+              ResultSet rs = conn.createStatement().executeQuery("show 
databases");
+              while (rs.next()) {
+                databaseCount++;
+              }
+              return databaseCount;
+            });
+    Assertions.assertThat(namespaces.stream().count()).isEqualTo(dbCount);
+  }
+
+  @Test
+  public void testListNamespacesAtDatabaseLevel() throws SQLException, 
InterruptedException {
+    String schema1 = "Schema_1";
+    String schema2 = "Schema_2";
+    String dbName = 
TestConfigurations.getInstance().getDatabase().toUpperCase();
+    try {
+      clientPool.run(conn -> conn.createStatement().execute("use " + dbName));
+      createOrReplaceSchema(schema1);
+      createOrReplaceSchema(schema2);
+      List<Namespace> namespaces = 
snowflakeCatalog.listNamespaces(Namespace.of(dbName));
+      Assertions.assertThat(namespaces)
+          .containsExactlyInAnyOrderElementsOf(
+              new ArrayList<Namespace>(
+                  Arrays.asList(
+                      Namespace.of(dbName, schema1.toUpperCase()),
+                      Namespace.of(dbName, schema2.toUpperCase()),
+                      Namespace.of(dbName, "PUBLIC"),
+                      Namespace.of(dbName, "INFORMATION_SCHEMA"))));
+    } finally {
+      dropSchemaIfExists(schema1);
+      dropSchemaIfExists(schema2);
+    }
+  }
+
+  @Test
+  public void testListNamespacesAtSchemaLevelIsNotAllowed()
+      throws SQLException, InterruptedException {
+    String schema1 = "Schema_1";
+    String dbName = 
TestConfigurations.getInstance().getDatabase().toUpperCase();
+    try {
+      clientPool.run(conn -> conn.createStatement().execute("use " + dbName));
+      createOrReplaceSchema(schema1);
+      Assertions.assertThatException()
+          .isThrownBy(
+              () -> {
+                snowflakeCatalog.listNamespaces(Namespace.of(dbName, schema1));
+              })
+          .isInstanceOf(IllegalArgumentException.class);
+    } finally {
+      dropSchemaIfExists(schema1);
+    }
+  }
+
+  @Test
+  public void testLoadNonExistingRootLevelNamespace() {
+    String nonExistingDb = "IDontExist";
+    Assertions.assertThatThrownBy(
+            () -> {
+              
snowflakeCatalog.loadNamespaceMetadata(Namespace.of(nonExistingDb));
+            })
+        .isInstanceOf(NoSuchNamespaceException.class);
+  }
+
+  @Test
+  public void testLoadNonExistingDBLevelNamespace() {
+    String nonExistingSchema = "IDontExist";
+    String db = TestConfigurations.getInstance().getDatabase();
+    Assertions.assertThatThrownBy(
+            () -> {
+              snowflakeCatalog.loadNamespaceMetadata(Namespace.of(db, 
nonExistingSchema));
+            })
+        .isInstanceOf(NoSuchNamespaceException.class);
+  }
+
+  @Test
+  public void testLoadNamespaceThatExceedMaxSupportedHierarchy() {
+    String nonExistingSchema = "IDontExist";
+    String db = TestConfigurations.getInstance().getDatabase();
+    Assertions.assertThatThrownBy(
+            () -> {
+              snowflakeCatalog.loadNamespaceMetadata(
+                  Namespace.of(db, nonExistingSchema, "UnSupportedLevel"));
+            })
+        .isInstanceOf(IllegalArgumentException.class);
+  }
+
+  @Test
+  public void testLoadNamespaceWithUnquotedIdentifier() throws SQLException, 
InterruptedException {
+    String schema1 = "Schema123";
+    String dbName = TestConfigurations.getInstance().getDatabase();
+    try {
+      Assertions.assertThatNoException()
+          .isThrownBy(
+              () -> {
+                clientPool.run(conn -> conn.createStatement().execute("use " + 
dbName));
+                createOrReplaceSchema(schema1);
+                snowflakeCatalog.loadNamespaceMetadata(Namespace.of(dbName, 
schema1));
+              });
+    } finally {
+      dropSchemaIfExists(schema1);
+    }
+  }
+
+  @Test
+  public void testLoadNamespaceWithUnquotedIdentifierIsCaseInsensitive()
+      throws SQLException, InterruptedException {
+    String schema1 = "Schema123";
+    String dbName = TestConfigurations.getInstance().getDatabase();
+    try {
+      Assertions.assertThatNoException()
+          .isThrownBy(
+              () -> {
+                clientPool.run(conn -> conn.createStatement().execute("use " + 
dbName));
+                createOrReplaceSchema(schema1);
+                snowflakeCatalog.loadNamespaceMetadata(Namespace.of(dbName, 
schema1));
+                snowflakeCatalog.loadNamespaceMetadata(Namespace.of(dbName, 
schema1.toUpperCase()));
+                snowflakeCatalog.loadNamespaceMetadata(Namespace.of(dbName, 
"schEmA123"));
+              });
+    } finally {
+      dropSchemaIfExists(schema1);
+    }
+  }
+
+  @Test
+  public void 
testLoadNamespaceWithUnquotedIdentifierWithLeadingUnderscoreAndDollarCharacters()
+      throws SQLException, InterruptedException {
+    String schema1 = "_Schema$_123";
+    String dbName = TestConfigurations.getInstance().getDatabase();
+    try {
+      Assertions.assertThatNoException()
+          .isThrownBy(
+              () -> {
+                clientPool.run(conn -> conn.createStatement().execute("use " + 
dbName));
+                createOrReplaceSchema(schema1);
+                snowflakeCatalog.loadNamespaceMetadata(Namespace.of(dbName, 
schema1));
+              });
+    } finally {
+      dropSchemaIfExists(schema1);
+    }
+  }
+
+  @Test
+  public void testLoadNamespaceWithQuotedIdentifierIsCaseSensitive()
+      throws SQLException, InterruptedException {
+    String schema1 = "\"Schema123\"";
+    String dbName = TestConfigurations.getInstance().getDatabase();
+    try {
+      Assertions.assertThatThrownBy(
+              () -> {
+                clientPool.run(conn -> conn.createStatement().execute("use " + 
dbName));
+                createOrReplaceSchema(schema1);
+                snowflakeCatalog.loadNamespaceMetadata(Namespace.of(dbName, 
schema1.toUpperCase()));
+              })
+          .isInstanceOf(NoSuchNamespaceException.class);
+    } finally {
+      dropSchemaIfExists(schema1);
+    }
+  }
+
+  @Test
+  public void testLoadNamespaceWithQuotedIdentifier() throws SQLException, 
InterruptedException {
+    String schema1 = "\"Schema123\"";
+    String dbName = TestConfigurations.getInstance().getDatabase();
+    try {
+      Assertions.assertThatNoException()
+          .isThrownBy(
+              () -> {
+                clientPool.run(conn -> conn.createStatement().execute("use " + 
dbName));
+                createOrReplaceSchema(schema1);
+                snowflakeCatalog.loadNamespaceMetadata(Namespace.of(dbName, 
schema1));
+              });
+    } finally {
+      dropSchemaIfExists(schema1);
+    }
+  }
+
+  @Test
+  public void testLoadNamespaceWithQuotedIdentifierWithSpecialCharacters()
+      throws SQLException, InterruptedException {
+    String schema1 = "\"H@!!.0-w*r()^'\"";
+    String dbName = TestConfigurations.getInstance().getDatabase();
+    try {
+      Assertions.assertThatNoException()
+          .isThrownBy(
+              () -> {
+                clientPool.run(conn -> conn.createStatement().execute("use " + 
dbName));
+                createOrReplaceSchema(schema1);
+                snowflakeCatalog.loadNamespaceMetadata(Namespace.of(dbName, 
schema1));
+              });
+    } finally {
+      dropSchemaIfExists(schema1);
+    }
+  }
+
+  @Test
+  public void testDropNamespaceNotSupported() throws SQLException, 
InterruptedException {
+    String schema1 = "Schema123";
+    String dbName = TestConfigurations.getInstance().getDatabase();
+    try {
+      Assertions.assertThatException()
+          .isThrownBy(
+              () -> {
+                clientPool.run(conn -> conn.createStatement().execute("use " + 
dbName));
+                createOrReplaceSchema(schema1);
+                snowflakeCatalog.dropNamespace(Namespace.of(dbName, schema1));
+              })
+          .isInstanceOf(UnsupportedOperationException.class);
+    } finally {
+      dropSchemaIfExists(schema1);
+    }
+  }
+
+  @Test
+  public void testSetPropertiesNotSupported() throws SQLException, 
InterruptedException {
+    String schema1 = "Schema123";
+    String dbName = TestConfigurations.getInstance().getDatabase();
+    try {
+      Assertions.assertThatException()
+          .isThrownBy(
+              () -> {
+                clientPool.run(conn -> conn.createStatement().execute("use " + 
dbName));
+                createOrReplaceSchema(schema1);
+                snowflakeCatalog.setProperties(
+                    Namespace.of(dbName, schema1), new HashMap<String, 
String>());
+              })
+          .isInstanceOf(UnsupportedOperationException.class);
+    } finally {
+      dropSchemaIfExists(schema1);
+    }
+  }
+
+  @Test
+  public void testRemovePropertiesNotSupported() throws SQLException, 
InterruptedException {
+    String schema1 = "Schema123";
+    String dbName = TestConfigurations.getInstance().getDatabase();
+    try {
+      Assertions.assertThatException()
+          .isThrownBy(

Review Comment:
   `.isThrownBy(..)` should only contain the line of code that actually throws 
the exception. Same for all the other test methods in this class



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]


Reply via email to