dimas-b commented on code in PR #2170:
URL: https://github.com/apache/polaris/pull/2170#discussion_r2226994742


##########
service/common/src/test/java/org/apache/polaris/service/admin/PolarisAdminServiceTest.java:
##########
@@ -0,0 +1,411 @@
+/*
+ * 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.service.admin;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+import jakarta.ws.rs.core.SecurityContext;
+import java.lang.reflect.Method;
+import java.util.List;
+import org.apache.iceberg.catalog.Namespace;
+import org.apache.iceberg.exceptions.NotFoundException;
+import org.apache.polaris.core.PolarisCallContext;
+import org.apache.polaris.core.PolarisDiagnostics;
+import org.apache.polaris.core.auth.AuthenticatedPolarisPrincipal;
+import org.apache.polaris.core.auth.PolarisAuthorizer;
+import org.apache.polaris.core.context.CallContext;
+import org.apache.polaris.core.entity.PolarisEntity;
+import org.apache.polaris.core.entity.PolarisEntityType;
+import org.apache.polaris.core.entity.PolarisPrivilege;
+import org.apache.polaris.core.persistence.PolarisEntityManager;
+import org.apache.polaris.core.persistence.PolarisMetaStoreManager;
+import org.apache.polaris.core.persistence.PolarisResolvedPathWrapper;
+import org.apache.polaris.core.persistence.dao.entity.PrivilegeResult;
+import org.apache.polaris.core.persistence.resolver.PolarisResolutionManifest;
+import org.apache.polaris.core.persistence.resolver.ResolverStatus;
+import org.apache.polaris.core.secrets.UserSecretsManager;
+import org.apache.polaris.service.config.ReservedProperties;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+
+public class PolarisAdminServiceTest {
+
+  @Mock private CallContext callContext;
+  @Mock private PolarisCallContext polarisCallContext;
+  @Mock private PolarisDiagnostics polarisDiagnostics;
+  @Mock private PolarisEntityManager entityManager;
+  @Mock private PolarisMetaStoreManager metaStoreManager;
+  @Mock private UserSecretsManager userSecretsManager;
+  @Mock private SecurityContext securityContext;
+  @Mock private PolarisAuthorizer authorizer;
+  @Mock private ReservedProperties reservedProperties;
+  @Mock private AuthenticatedPolarisPrincipal authenticatedPrincipal;
+  @Mock private PolarisResolutionManifest resolutionManifest;
+  @Mock private PolarisResolvedPathWrapper resolvedPathWrapper;
+
+  private PolarisAdminService adminService;
+  private Method isNamespaceFullyResolvedMethod;
+
+  @BeforeEach
+  void setUp() throws Exception {
+    MockitoAnnotations.openMocks(this);
+    
when(securityContext.getUserPrincipal()).thenReturn(authenticatedPrincipal);
+    when(callContext.getPolarisCallContext()).thenReturn(polarisCallContext);
+    when(polarisCallContext.getDiagServices()).thenReturn(polarisDiagnostics);
+
+    adminService =
+        new PolarisAdminService(
+            callContext,
+            entityManager,
+            metaStoreManager,
+            userSecretsManager,
+            securityContext,
+            authorizer,
+            reservedProperties);
+
+    isNamespaceFullyResolvedMethod =
+        PolarisAdminService.class.getDeclaredMethod(
+            "isNamespaceFullyResolved",
+            PolarisResolvedPathWrapper.class,
+            String.class,
+            Namespace.class);
+    isNamespaceFullyResolvedMethod.setAccessible(true);
+  }
+
+  @Test
+  void testIsNamespaceFullyResolved_NullWrapper() throws Exception {
+    boolean result =
+        (boolean)
+            isNamespaceFullyResolvedMethod.invoke(
+                adminService, null, "test-catalog", Namespace.of("ns1"));
+
+    assertThat(result).isFalse();

Review Comment:
   nit: Why not inline `result`? The expression is already multi-line 
:thinking: 



##########
service/common/src/main/java/org/apache/polaris/service/admin/PolarisAdminService.java:
##########
@@ -1672,6 +1672,42 @@ public boolean revokePrivilegeOnCatalogFromRole(
         .isSuccess();
   }
 
+  /**
+   * Checks if a namespace is fully resolved.
+   *
+   * @param resolvedPathWrapper the resolved path wrapper from resolution
+   * @param catalogName the name of the catalog
+   * @param namespace the namespace we're trying to resolve
+   * @return true if the namespace is considered fully resolved for the given 
catalog type
+   */
+  private boolean isNamespaceFullyResolved(
+      @Nullable PolarisResolvedPathWrapper resolvedPathWrapper,
+      @Nonnull String catalogName,
+      @Nonnull Namespace namespace) {
+    if (resolvedPathWrapper == null) {
+      return false;
+    }
+
+    List<PolarisEntity> fullPath = resolvedPathWrapper.getRawFullPath();
+    int expectedPathLength = 1 + namespace.levels().length;
+    if (fullPath.size() < expectedPathLength) {

Review Comment:
   why not `==`?



##########
service/common/src/test/java/org/apache/polaris/service/admin/PolarisAdminServiceTest.java:
##########
@@ -0,0 +1,411 @@
+/*
+ * 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.service.admin;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+import jakarta.ws.rs.core.SecurityContext;
+import java.lang.reflect.Method;
+import java.util.List;
+import org.apache.iceberg.catalog.Namespace;
+import org.apache.iceberg.exceptions.NotFoundException;
+import org.apache.polaris.core.PolarisCallContext;
+import org.apache.polaris.core.PolarisDiagnostics;
+import org.apache.polaris.core.auth.AuthenticatedPolarisPrincipal;
+import org.apache.polaris.core.auth.PolarisAuthorizer;
+import org.apache.polaris.core.context.CallContext;
+import org.apache.polaris.core.entity.PolarisEntity;
+import org.apache.polaris.core.entity.PolarisEntityType;
+import org.apache.polaris.core.entity.PolarisPrivilege;
+import org.apache.polaris.core.persistence.PolarisEntityManager;
+import org.apache.polaris.core.persistence.PolarisMetaStoreManager;
+import org.apache.polaris.core.persistence.PolarisResolvedPathWrapper;
+import org.apache.polaris.core.persistence.dao.entity.PrivilegeResult;
+import org.apache.polaris.core.persistence.resolver.PolarisResolutionManifest;
+import org.apache.polaris.core.persistence.resolver.ResolverStatus;
+import org.apache.polaris.core.secrets.UserSecretsManager;
+import org.apache.polaris.service.config.ReservedProperties;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+
+public class PolarisAdminServiceTest {
+
+  @Mock private CallContext callContext;
+  @Mock private PolarisCallContext polarisCallContext;
+  @Mock private PolarisDiagnostics polarisDiagnostics;
+  @Mock private PolarisEntityManager entityManager;
+  @Mock private PolarisMetaStoreManager metaStoreManager;
+  @Mock private UserSecretsManager userSecretsManager;
+  @Mock private SecurityContext securityContext;
+  @Mock private PolarisAuthorizer authorizer;
+  @Mock private ReservedProperties reservedProperties;
+  @Mock private AuthenticatedPolarisPrincipal authenticatedPrincipal;
+  @Mock private PolarisResolutionManifest resolutionManifest;
+  @Mock private PolarisResolvedPathWrapper resolvedPathWrapper;
+
+  private PolarisAdminService adminService;
+  private Method isNamespaceFullyResolvedMethod;
+
+  @BeforeEach
+  void setUp() throws Exception {
+    MockitoAnnotations.openMocks(this);
+    
when(securityContext.getUserPrincipal()).thenReturn(authenticatedPrincipal);
+    when(callContext.getPolarisCallContext()).thenReturn(polarisCallContext);
+    when(polarisCallContext.getDiagServices()).thenReturn(polarisDiagnostics);
+
+    adminService =
+        new PolarisAdminService(
+            callContext,
+            entityManager,
+            metaStoreManager,
+            userSecretsManager,
+            securityContext,
+            authorizer,
+            reservedProperties);
+
+    isNamespaceFullyResolvedMethod =
+        PolarisAdminService.class.getDeclaredMethod(
+            "isNamespaceFullyResolved",
+            PolarisResolvedPathWrapper.class,
+            String.class,
+            Namespace.class);
+    isNamespaceFullyResolvedMethod.setAccessible(true);
+  }
+
+  @Test
+  void testIsNamespaceFullyResolved_NullWrapper() throws Exception {
+    boolean result =
+        (boolean)
+            isNamespaceFullyResolvedMethod.invoke(
+                adminService, null, "test-catalog", Namespace.of("ns1"));
+
+    assertThat(result).isFalse();
+  }
+
+  @Test
+  void testIsNamespaceFullyResolved_InsufficientPathLength() throws Exception {
+    String catalogName = "test-catalog";
+    Namespace namespace = Namespace.of("ns1", "ns2");
+
+    PolarisEntity catalogEntity = createEntity(catalogName, 
PolarisEntityType.CATALOG);
+    List<PolarisEntity> shortPath = List.of(catalogEntity);
+
+    when(resolvedPathWrapper.getRawFullPath()).thenReturn(shortPath);
+
+    boolean result =
+        (boolean)
+            isNamespaceFullyResolvedMethod.invoke(
+                adminService, resolvedPathWrapper, catalogName, namespace);

Review Comment:
   This pattern is repeated... Maybe add a help method in this test class?



##########
service/common/src/main/java/org/apache/polaris/service/admin/PolarisAdminService.java:
##########
@@ -1672,6 +1672,42 @@ public boolean revokePrivilegeOnCatalogFromRole(
         .isSuccess();
   }
 
+  /**
+   * Checks if a namespace is fully resolved.
+   *
+   * @param resolvedPathWrapper the resolved path wrapper from resolution
+   * @param catalogName the name of the catalog
+   * @param namespace the namespace we're trying to resolve
+   * @return true if the namespace is considered fully resolved for the given 
catalog type
+   */
+  private boolean isNamespaceFullyResolved(

Review Comment:
   Why keep it as a private instance method? It does not use any state from 
`this`... It could be a package-private `static` method in a utility 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: issues-unsubscr...@polaris.apache.org

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

Reply via email to