diff --git a/polaris-service/src/test/java/io/polaris/service/PolarisApplicationIntegrationTest.java b/polaris-service/src/test/java/io/polaris/service/PolarisApplicationIntegrationTest.java index 279e593b7d..1eb62ebfbf 100644 --- a/polaris-service/src/test/java/io/polaris/service/PolarisApplicationIntegrationTest.java +++ b/polaris-service/src/test/java/io/polaris/service/PolarisApplicationIntegrationTest.java @@ -18,7 +18,6 @@ import static io.polaris.service.context.DefaultContextResolver.REALM_PROPERTY_KEY; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; -import static org.assertj.core.api.Assertions.fail; import io.dropwizard.testing.ConfigOverride; import io.dropwizard.testing.ResourceHelpers; @@ -65,7 +64,6 @@ import org.apache.iceberg.exceptions.NoSuchNamespaceException; import org.apache.iceberg.exceptions.NoSuchTableException; import org.apache.iceberg.exceptions.RESTException; -import org.apache.iceberg.exceptions.ServiceFailureException; import org.apache.iceberg.hadoop.HadoopFileIO; import org.apache.iceberg.io.ResolvingFileIO; import org.apache.iceberg.rest.RESTSessionCatalog; @@ -308,14 +306,8 @@ public void testIcebergListNamespaces() throws IOException { @Test public void testConfigureCatalogCaseSensitive() throws IOException { - try { - RESTSessionCatalog sessionCatalog = newSessionCatalog("TESTCONFIGURECATALOGCASESENSITIVE"); - fail("Expected exception connecting to catalog"); - } catch (ServiceFailureException e) { - fail("Unexpected service failure exception", e); - } catch (RESTException e) { - LoggerFactory.getLogger(getClass()).info("Caught expected rest exception", e); - } + assertThatThrownBy(() -> newSessionCatalog("TESTCONFIGURECATALOGCASESENSITIVE")) + .isInstanceOf(RESTException.class); } @Test @@ -400,12 +392,8 @@ public void testIcebergDropNamespaceInExternalCatalog(TestInfo testInfo) throws List namespaces = sessionCatalog.listNamespaces(sessionContext); assertThat(namespaces).isNotNull().hasSize(1).containsExactly(ns); sessionCatalog.dropNamespace(sessionContext, ns); - try { - sessionCatalog.loadNamespaceMetadata(sessionContext, ns); - Assertions.fail("Expected exception when loading namespace after drop"); - } catch (NoSuchNamespaceException e) { - LOGGER.info("Received expected exception {}", e.getMessage()); - } + assertThatThrownBy(() -> sessionCatalog.loadNamespaceMetadata(sessionContext, ns)) + .isInstanceOf(NoSuchNamespaceException.class); } } @@ -417,21 +405,21 @@ public void testIcebergCreateTablesInExternalCatalog(TestInfo testInfo) throws I SessionCatalog.SessionContext sessionContext = SessionCatalog.SessionContext.createEmpty(); Namespace ns = Namespace.of("db1"); sessionCatalog.createNamespace(sessionContext, ns); - try { - sessionCatalog - .buildTable( - sessionContext, - TableIdentifier.of(ns, "the_table"), - new Schema( - List.of(Types.NestedField.of(1, false, "theField", Types.StringType.get())))) - .withLocation("file:///tmp/tables") - .withSortOrder(SortOrder.unsorted()) - .withPartitionSpec(PartitionSpec.unpartitioned()) - .create(); - Assertions.fail("Expected failure calling create table in external catalog"); - } catch (BadRequestException e) { - LOGGER.info("Received expected exception {}", e.getMessage()); - } + assertThatThrownBy( + () -> + sessionCatalog + .buildTable( + sessionContext, + TableIdentifier.of(ns, "the_table"), + new Schema( + List.of( + Types.NestedField.of( + 1, false, "theField", Types.StringType.get())))) + .withLocation("file:///tmp/tables") + .withSortOrder(SortOrder.unsorted()) + .withPartitionSpec(PartitionSpec.unpartitioned()) + .create()) + .isInstanceOf(BadRequestException.class); } } @@ -571,19 +559,17 @@ public void testIcebergUpdateTableInExternalCatalog(TestInfo testInfo) throws IO sessionCatalog.registerTable(sessionContext, tableIdentifier, metadataLocation); Table table = sessionCatalog.loadTable(sessionContext, tableIdentifier); ((ResolvingFileIO) table.io()).setConf(new Configuration()); - try { - table - .newAppend() - .appendFile( - new TestHelpers.TestDataFile( - location + "/path/to/file.parquet", - new PartitionData(PartitionSpec.unpartitioned().partitionType()), - 10L)) - .commit(); - Assertions.fail("Should fail when committing an update to external catalog"); - } catch (BadRequestException e) { - LOGGER.info("Received expected exception {}", e.getMessage()); - } + assertThatThrownBy( + () -> + table + .newAppend() + .appendFile( + new TestHelpers.TestDataFile( + location + "/path/to/file.parquet", + new PartitionData(PartitionSpec.unpartitioned().partitionType()), + 10L)) + .commit()) + .isInstanceOf(BadRequestException.class); } } @@ -626,12 +612,8 @@ public void testIcebergDropTableInExternalCatalog(TestInfo testInfo) throws IOEx Table table = sessionCatalog.loadTable(sessionContext, tableIdentifier); assertThat(table).isNotNull(); sessionCatalog.dropTable(sessionContext, tableIdentifier); - try { - sessionCatalog.loadTable(sessionContext, tableIdentifier); - Assertions.fail("Expected failure loading table after drop"); - } catch (NoSuchTableException e) { - LOGGER.info("Received expected exception {}", e.getMessage()); - } + assertThatThrownBy(() -> sessionCatalog.loadTable(sessionContext, tableIdentifier)) + .isInstanceOf(NoSuchTableException.class); } } @@ -640,25 +622,22 @@ public void testWarehouseNotSpecified() throws IOException { try (RESTSessionCatalog sessionCatalog = new RESTSessionCatalog()) { String emptyEnvironmentVariable = "env:__NULL_ENV_VARIABLE__"; assertThat(EnvironmentUtil.resolveAll(Map.of("", emptyEnvironmentVariable)).get("")).isNull(); - sessionCatalog.initialize( - "snowflake", - Map.of( - "uri", - "http://localhost:" + EXT.getLocalPort() + "/api/catalog", - OAuth2Properties.CREDENTIAL, - snowmanCredentials.clientId() + ":" + snowmanCredentials.clientSecret(), - OAuth2Properties.SCOPE, - BasePolarisAuthenticator.PRINCIPAL_ROLE_ALL, - "warehouse", - emptyEnvironmentVariable, - "header." + REALM_PROPERTY_KEY, - realm)); - fail("Expected exception due to null warehouse"); - } catch (ServiceFailureException e) { - fail("Unexpected service failure exception", e); - } catch (RESTException e) { - LoggerFactory.getLogger(getClass()).info("Caught expected rest exception", e); - assertThat(e).isInstanceOf(BadRequestException.class); + assertThatThrownBy( + () -> + sessionCatalog.initialize( + "snowflake", + Map.of( + "uri", + "http://localhost:" + EXT.getLocalPort() + "/api/catalog", + OAuth2Properties.CREDENTIAL, + snowmanCredentials.clientId() + ":" + snowmanCredentials.clientSecret(), + OAuth2Properties.SCOPE, + BasePolarisAuthenticator.PRINCIPAL_ROLE_ALL, + "warehouse", + emptyEnvironmentVariable, + "header." + REALM_PROPERTY_KEY, + realm))) + .isInstanceOf(BadRequestException.class); } } }