ajantha-bhat commented on code in PR #5037:
URL: https://github.com/apache/iceberg/pull/5037#discussion_r916513979


##########
nessie/src/test/java/org/apache/iceberg/nessie/TestNessieTable.java:
##########
@@ -385,6 +388,83 @@ public void testDropTable() throws IOException {
     verifyCommitMetadata();
   }
 
+  private void testRegister(TableIdentifier identifier, String 
metadataVersionFiles) {
+    Assertions.assertThat(catalog.registerTable(identifier, "file:" + 
metadataVersionFiles)).isNotNull();
+    Table newTable = catalog.loadTable(identifier);
+    Assertions.assertThat(newTable).isNotNull();
+    TableOperations ops = ((HasTableOperations) newTable).operations();
+    String metadataLocation = ((NessieTableOperations) 
ops).currentMetadataLocation();
+    Assertions.assertThat("file:" + 
metadataVersionFiles).isEqualTo(metadataLocation);
+    Assertions.assertThat(catalog.dropTable(identifier, false)).isTrue();
+  }
+
+  @Test
+  public void testRegisterTableWithGivenBranch() {
+    List<String> metadataVersionFiles = metadataVersionFiles(TABLE_NAME);
+    Assertions.assertThat(1).isEqualTo(metadataVersionFiles.size());
+    ImmutableTableReference tableReference =
+        
ImmutableTableReference.builder().reference("main").name(TABLE_NAME).build();
+    TableIdentifier identifier = TableIdentifier.of(DB_NAME, 
tableReference.toString());
+    testRegister(identifier, metadataVersionFiles.get(0));
+  }
+
+  @Test
+  public void testRegisterTableNegativeScenarios() throws 
NessieConflictException, NessieNotFoundException {
+    List<String> metadataVersionFiles = metadataVersionFiles(TABLE_NAME);
+    Assertions.assertThat(1).isEqualTo(metadataVersionFiles.size());
+    // Case 1: Branch does not exist
+    ImmutableTableReference tableReference =
+        
ImmutableTableReference.builder().reference("default").name(TABLE_NAME).build();
+    TableIdentifier identifier = TableIdentifier.of(DB_NAME, 
tableReference.toString());
+    Assertions.assertThatThrownBy(
+        () -> catalog.registerTable(
+            identifier, "file:" + metadataVersionFiles.get(0)))
+        .isInstanceOf(IllegalArgumentException.class)
+        .hasMessage("Nessie ref 'default' does not exist");
+    // Case 2: Table Already Exists
+    Assertions.assertThatThrownBy(() -> 
catalog.registerTable(TABLE_IDENTIFIER, "file:" + metadataVersionFiles.get(0)))
+        .isInstanceOf(AlreadyExistsException.class)
+        .hasMessage("Table already exists: db.tbl");
+    // Case 3: Registering using a tag
+    api.createReference().sourceRefName(BRANCH).reference(Tag.of("tag_1", 
catalog.currentHash())).create();
+    Assertions.assertThatThrownBy(
+        () -> catalog.registerTable(
+            TableIdentifier.of(DB_NAME, "`" + TABLE_NAME + "`@tag_1"),

Review Comment:
   nit: can use `TableReference` here for tag also. 



-- 
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