Skip to content

Commit

Permalink
Assert on expected exception's message (#160)
Browse files Browse the repository at this point in the history
  • Loading branch information
findepi authored Aug 19, 2024
1 parent 1746ff0 commit 879c32a
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import org.apache.iceberg.exceptions.UnprocessableEntityException;
import org.assertj.core.api.Assertions;
import org.jetbrains.annotations.NotNull;
import org.junit.jupiter.api.RepeatedTest;
Expand Down Expand Up @@ -94,7 +95,8 @@ public void testBadResult() {
true,
new HashSet<>(Arrays.asList("s3://bucket1/path")),
new HashSet<>(Arrays.asList("s3://bucket3/path"))))
.isInstanceOf(RuntimeException.class);
.isInstanceOf(UnprocessableEntityException.class)
.hasMessage("Failed to get subscoped credentials: extra_error_info");
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,9 @@ public void testIcebergListNamespaces() throws IOException {
@Test
public void testConfigureCatalogCaseSensitive() throws IOException {
assertThatThrownBy(() -> newSessionCatalog("TESTCONFIGURECATALOGCASESENSITIVE"))
.isInstanceOf(RESTException.class);
.isInstanceOf(RESTException.class)
.hasMessage(
"Unable to process: Unable to find warehouse TESTCONFIGURECATALOGCASESENSITIVE");
}

@Test
Expand All @@ -318,7 +320,8 @@ public void testIcebergListNamespacesNotFound() throws IOException {
SessionCatalog.SessionContext sessionContext = SessionCatalog.SessionContext.createEmpty();
assertThatThrownBy(
() -> sessionCatalog.listNamespaces(sessionContext, Namespace.of("whoops")))
.isInstanceOf(NoSuchNamespaceException.class);
.isInstanceOf(NoSuchNamespaceException.class)
.hasMessage("Namespace does not exist: whoops");
}
}

Expand All @@ -334,7 +337,8 @@ public void testIcebergListNamespacesNestedNotFound() throws IOException {
() ->
sessionCatalog.listNamespaces(
sessionContext, Namespace.of("top_level", "whoops")))
.isInstanceOf(NoSuchNamespaceException.class);
.isInstanceOf(NoSuchNamespaceException.class)
.hasMessage("Namespace does not exist: top_level.whoops");
}
}

Expand All @@ -344,7 +348,8 @@ public void testIcebergListTablesNamespaceNotFound() throws IOException {
newSessionCatalog("testIcebergListTablesNamespaceNotFound")) {
SessionCatalog.SessionContext sessionContext = SessionCatalog.SessionContext.createEmpty();
assertThatThrownBy(() -> sessionCatalog.listTables(sessionContext, Namespace.of("whoops")))
.isInstanceOf(NoSuchNamespaceException.class);
.isInstanceOf(NoSuchNamespaceException.class)
.hasMessage("Namespace does not exist: whoops");
}
}

Expand Down Expand Up @@ -394,7 +399,8 @@ public void testIcebergDropNamespaceInExternalCatalog(TestInfo testInfo) throws
assertThat(namespaces).isNotNull().hasSize(1).containsExactly(ns);
sessionCatalog.dropNamespace(sessionContext, ns);
assertThatThrownBy(() -> sessionCatalog.loadNamespaceMetadata(sessionContext, ns))
.isInstanceOf(NoSuchNamespaceException.class);
.isInstanceOf(NoSuchNamespaceException.class)
.hasMessage("Namespace does not exist: db1");
}
}

Expand All @@ -420,7 +426,8 @@ public void testIcebergCreateTablesInExternalCatalog(TestInfo testInfo) throws I
.withSortOrder(SortOrder.unsorted())
.withPartitionSpec(PartitionSpec.unpartitioned())
.create())
.isInstanceOf(BadRequestException.class);
.isInstanceOf(BadRequestException.class)
.hasMessage("Malformed request: Cannot create table on external catalogs.");
}
}

Expand Down Expand Up @@ -570,7 +577,8 @@ public void testIcebergUpdateTableInExternalCatalog(TestInfo testInfo) throws IO
new PartitionData(PartitionSpec.unpartitioned().partitionType()),
10L))
.commit())
.isInstanceOf(BadRequestException.class);
.isInstanceOf(BadRequestException.class)
.hasMessage("Malformed request: Cannot update table on external catalogs.");
}
}

Expand Down Expand Up @@ -614,7 +622,8 @@ public void testIcebergDropTableInExternalCatalog(TestInfo testInfo) throws IOEx
assertThat(table).isNotNull();
sessionCatalog.dropTable(sessionContext, tableIdentifier);
assertThatThrownBy(() -> sessionCatalog.loadTable(sessionContext, tableIdentifier))
.isInstanceOf(NoSuchTableException.class);
.isInstanceOf(NoSuchTableException.class)
.hasMessage("Table does not exist: db1.the_table");
}
}

Expand All @@ -638,7 +647,8 @@ public void testWarehouseNotSpecified() throws IOException {
emptyEnvironmentVariable,
"header." + REALM_PROPERTY_KEY,
realm)))
.isInstanceOf(BadRequestException.class);
.isInstanceOf(BadRequestException.class)
.hasMessage("Malformed request: Please specify a warehouse");
}
}
}

0 comments on commit 879c32a

Please sign in to comment.