dimas-b commented on code in PR #2170: URL: https://github.com/apache/polaris/pull/2170#discussion_r2227058158
########## polaris-core/src/test/java/org/apache/polaris/core/persistence/PolarisResolvedPathWrapperTest.java: ########## @@ -0,0 +1,145 @@ +/* + * 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.polaris.core.persistence; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; + +import java.util.List; +import org.apache.iceberg.catalog.Namespace; +import org.apache.polaris.core.entity.PolarisEntity; +import org.apache.polaris.core.entity.PolarisEntityType; +import org.junit.jupiter.api.Test; + +public class PolarisResolvedPathWrapperTest { + + @Test + void testIsFullyResolvedNamespace_NullResolvedPath() { + PolarisResolvedPathWrapper wrapper = new PolarisResolvedPathWrapper(null); + + boolean result = wrapper.isFullyResolvedNamespace("test-catalog", Namespace.of("ns1")); + + assertThat(result).isFalse(); + } + + @Test + void testIsFullyResolvedNamespace_InsufficientPathLength() { + String catalogName = "test-catalog"; + Namespace namespace = Namespace.of("ns1", "ns2"); + + PolarisEntity catalogEntity = createEntity(catalogName, PolarisEntityType.CATALOG); + List<ResolvedPolarisEntity> shortPath = List.of(createResolvedEntity(catalogEntity)); + PolarisResolvedPathWrapper wrapper = new PolarisResolvedPathWrapper(shortPath); + + assertFalse(wrapper.isFullyResolvedNamespace(catalogName, namespace)); + } + + @Test + void testIsFullyResolvedNamespace_WrongCatalogName() { + String catalogName = "test-catalog"; + String wrongCatalogName = "wrong-catalog"; + Namespace namespace = Namespace.of("ns1"); + + PolarisEntity wrongCatalogEntity = createEntity(wrongCatalogName, PolarisEntityType.CATALOG); + PolarisEntity namespaceEntity = createEntity("ns1", PolarisEntityType.NAMESPACE); + List<ResolvedPolarisEntity> path = + List.of(createResolvedEntity(wrongCatalogEntity), createResolvedEntity(namespaceEntity)); + PolarisResolvedPathWrapper wrapper = new PolarisResolvedPathWrapper(path); + + assertFalse(wrapper.isFullyResolvedNamespace(catalogName, namespace)); + } + + @Test + void testIsFullyResolvedNamespace_WrongNamespaceNames() { + String catalogName = "test-catalog"; + Namespace namespace = Namespace.of("ns1", "ns2"); + + PolarisEntity catalogEntity = createEntity(catalogName, PolarisEntityType.CATALOG); + PolarisEntity namespace1Entity = createEntity("ns1", PolarisEntityType.NAMESPACE); + PolarisEntity namespace2WrongEntity = createEntity("wrong-ns2", PolarisEntityType.NAMESPACE); + List<ResolvedPolarisEntity> path = + List.of( + createResolvedEntity(catalogEntity), + createResolvedEntity(namespace1Entity), + createResolvedEntity(namespace2WrongEntity)); + PolarisResolvedPathWrapper wrapper = new PolarisResolvedPathWrapper(path); + + assertFalse(wrapper.isFullyResolvedNamespace(catalogName, namespace)); + } + + @Test + void testIsFullyResolvedNamespace_CorrectPath() { + String catalogName = "test-catalog"; + Namespace namespace = Namespace.of("ns1", "ns2"); + + PolarisEntity catalogEntity = createEntity(catalogName, PolarisEntityType.CATALOG); + PolarisEntity namespace1Entity = createEntity("ns1", PolarisEntityType.NAMESPACE); + PolarisEntity namespace2Entity = createEntity("ns2", PolarisEntityType.NAMESPACE); + List<ResolvedPolarisEntity> path = + List.of( + createResolvedEntity(catalogEntity), + createResolvedEntity(namespace1Entity), + createResolvedEntity(namespace2Entity)); + PolarisResolvedPathWrapper wrapper = new PolarisResolvedPathWrapper(path); + + assertTrue(wrapper.isFullyResolvedNamespace(catalogName, namespace)); + } + + @Test + void testIsFullyResolvedNamespace_WrongEntityType() { + String catalogName = "test-catalog"; + Namespace namespace = Namespace.of("ns1"); + + PolarisEntity catalogEntity = createEntity(catalogName, PolarisEntityType.CATALOG); + PolarisEntity wrongTypeEntity = createEntity("ns1", PolarisEntityType.TABLE_LIKE); Review Comment: For completeness this test should probably also have some NS level with the right type and some with another type. -- 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