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


##########
nessie/src/test/java/org/apache/iceberg/nessie/TestNessieTable.java:
##########
@@ -356,6 +361,107 @@ public void testListTables() {
     Assertions.assertThat(catalog.tableExists(TABLE_IDENTIFIER)).isTrue();
   }
 
+  private void testRegister(TableIdentifier identifier, List<String> 
metadataVersionFiles) {
+    Assertions.assertThat(catalog.dropTable(identifier, false)).isFalse();
+    Assertions.assertThat(catalog.registerTable(
+            identifier,
+            "file:" + metadataVersionFiles.get(0))).isNotNull();
+    Table newTable = catalog.loadTable(identifier);
+    Assertions.assertThat(newTable).isNotNull();
+    TableOperations ops = ((HasTableOperations) newTable).operations();
+    String metadataLocation = ((NessieTableOperations) 
ops).currentMetadataLocation();
+    Assertions.assertThat("file:" + 
metadataVersionFiles.get(0)).isEqualTo(metadataLocation);
+    Assertions.assertThat(catalog.tableExists(identifier)).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);
+  }
+
+  @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
+    Assertions.assertThatThrownBy(
+            () -> catalog.registerTable(
+                    TableIdentifier.of(DB_NAME, "`" + TABLE_NAME + 
"`@default"),
+                    "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"),
+                            "file:" + metadataVersionFiles.get(0)))
+            .isInstanceOf(IllegalArgumentException.class)
+            .hasMessage("You can only mutate tables when using a branch 
without a hash or timestamp.");
+    // Case 4: non-null metadata path with null metadata location
+    Assertions.assertThat(catalog.dropTable(TABLE_IDENTIFIER, false)).isTrue();
+    Assertions.assertThatThrownBy(
+            () -> catalog.registerTable(TABLE_IDENTIFIER, "file:" + 
metadataVersionFiles.get(0) + "invalidName"))
+        .isInstanceOf(NotFoundException.class);
+  }
+
+  @Test
+  public void testRegisterTableWithDefaultBranch() {
+    List<String> metadataVersionFiles = metadataVersionFiles(TABLE_NAME);
+    Assertions.assertThat(1).isEqualTo(metadataVersionFiles.size());
+    Assertions.assertThat(catalog.dropTable(TABLE_IDENTIFIER)).isTrue();
+    Assertions.assertThat(catalog.registerTable(TABLE_IDENTIFIER, "file:" + 
metadataVersionFiles.get(0))).isNotNull();

Review Comment:
   please rebase on #5033 



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