1818import static io .polaris .service .context .DefaultContextResolver .REALM_PROPERTY_KEY ;
1919import static org .assertj .core .api .Assertions .assertThat ;
2020import static org .assertj .core .api .Assertions .assertThatThrownBy ;
21- import static org .assertj .core .api .Assertions .fail ;
2221
2322import io .dropwizard .testing .ConfigOverride ;
2423import io .dropwizard .testing .ResourceHelpers ;
6564import org .apache .iceberg .exceptions .NoSuchNamespaceException ;
6665import org .apache .iceberg .exceptions .NoSuchTableException ;
6766import org .apache .iceberg .exceptions .RESTException ;
68- import org .apache .iceberg .exceptions .ServiceFailureException ;
6967import org .apache .iceberg .hadoop .HadoopFileIO ;
7068import org .apache .iceberg .io .ResolvingFileIO ;
7169import org .apache .iceberg .rest .RESTSessionCatalog ;
@@ -308,14 +306,8 @@ public void testIcebergListNamespaces() throws IOException {
308306
309307 @ Test
310308 public void testConfigureCatalogCaseSensitive () throws IOException {
311- try {
312- RESTSessionCatalog sessionCatalog = newSessionCatalog ("TESTCONFIGURECATALOGCASESENSITIVE" );
313- fail ("Expected exception connecting to catalog" );
314- } catch (ServiceFailureException e ) {
315- fail ("Unexpected service failure exception" , e );
316- } catch (RESTException e ) {
317- LoggerFactory .getLogger (getClass ()).info ("Caught expected rest exception" , e );
318- }
309+ assertThatThrownBy (() -> newSessionCatalog ("TESTCONFIGURECATALOGCASESENSITIVE" ))
310+ .isInstanceOf (RESTException .class );
319311 }
320312
321313 @ Test
@@ -400,12 +392,8 @@ public void testIcebergDropNamespaceInExternalCatalog(TestInfo testInfo) throws
400392 List <Namespace > namespaces = sessionCatalog .listNamespaces (sessionContext );
401393 assertThat (namespaces ).isNotNull ().hasSize (1 ).containsExactly (ns );
402394 sessionCatalog .dropNamespace (sessionContext , ns );
403- try {
404- sessionCatalog .loadNamespaceMetadata (sessionContext , ns );
405- Assertions .fail ("Expected exception when loading namespace after drop" );
406- } catch (NoSuchNamespaceException e ) {
407- LOGGER .info ("Received expected exception {}" , e .getMessage ());
408- }
395+ assertThatThrownBy (() -> sessionCatalog .loadNamespaceMetadata (sessionContext , ns ))
396+ .isInstanceOf (NoSuchNamespaceException .class );
409397 }
410398 }
411399
@@ -417,21 +405,21 @@ public void testIcebergCreateTablesInExternalCatalog(TestInfo testInfo) throws I
417405 SessionCatalog .SessionContext sessionContext = SessionCatalog .SessionContext .createEmpty ();
418406 Namespace ns = Namespace .of ("db1" );
419407 sessionCatalog .createNamespace (sessionContext , ns );
420- try {
421- sessionCatalog
422- . buildTable (
423- sessionContext ,
424- TableIdentifier . of ( ns , "the_table" ) ,
425- new Schema (
426- List . of ( Types . NestedField . of ( 1 , false , "theField" , Types . StringType . get ()))))
427- . withLocation ( "file:///tmp/tables" )
428- . withSortOrder ( SortOrder . unsorted ())
429- . withPartitionSpec ( PartitionSpec . unpartitioned ( ))
430- . create ();
431- Assertions . fail ( "Expected failure calling create table in external catalog" );
432- } catch ( BadRequestException e ) {
433- LOGGER . info ( "Received expected exception {}" , e . getMessage ());
434- }
408+ assertThatThrownBy (
409+ () ->
410+ sessionCatalog
411+ . buildTable (
412+ sessionContext ,
413+ TableIdentifier . of ( ns , "the_table" ),
414+ new Schema (
415+ List . of (
416+ Types . NestedField . of (
417+ 1 , false , "theField" , Types . StringType . get ())) ))
418+ . withLocation ( "file:///tmp/tables" )
419+ . withSortOrder ( SortOrder . unsorted ())
420+ . withPartitionSpec ( PartitionSpec . unpartitioned ())
421+ . create ())
422+ . isInstanceOf ( BadRequestException . class );
435423 }
436424 }
437425
@@ -571,19 +559,17 @@ public void testIcebergUpdateTableInExternalCatalog(TestInfo testInfo) throws IO
571559 sessionCatalog .registerTable (sessionContext , tableIdentifier , metadataLocation );
572560 Table table = sessionCatalog .loadTable (sessionContext , tableIdentifier );
573561 ((ResolvingFileIO ) table .io ()).setConf (new Configuration ());
574- try {
575- table
576- .newAppend ()
577- .appendFile (
578- new TestHelpers .TestDataFile (
579- location + "/path/to/file.parquet" ,
580- new PartitionData (PartitionSpec .unpartitioned ().partitionType ()),
581- 10L ))
582- .commit ();
583- Assertions .fail ("Should fail when committing an update to external catalog" );
584- } catch (BadRequestException e ) {
585- LOGGER .info ("Received expected exception {}" , e .getMessage ());
586- }
562+ assertThatThrownBy (
563+ () ->
564+ table
565+ .newAppend ()
566+ .appendFile (
567+ new TestHelpers .TestDataFile (
568+ location + "/path/to/file.parquet" ,
569+ new PartitionData (PartitionSpec .unpartitioned ().partitionType ()),
570+ 10L ))
571+ .commit ())
572+ .isInstanceOf (BadRequestException .class );
587573 }
588574 }
589575
@@ -626,12 +612,8 @@ public void testIcebergDropTableInExternalCatalog(TestInfo testInfo) throws IOEx
626612 Table table = sessionCatalog .loadTable (sessionContext , tableIdentifier );
627613 assertThat (table ).isNotNull ();
628614 sessionCatalog .dropTable (sessionContext , tableIdentifier );
629- try {
630- sessionCatalog .loadTable (sessionContext , tableIdentifier );
631- Assertions .fail ("Expected failure loading table after drop" );
632- } catch (NoSuchTableException e ) {
633- LOGGER .info ("Received expected exception {}" , e .getMessage ());
634- }
615+ assertThatThrownBy (() -> sessionCatalog .loadTable (sessionContext , tableIdentifier ))
616+ .isInstanceOf (NoSuchTableException .class );
635617 }
636618 }
637619
@@ -640,25 +622,22 @@ public void testWarehouseNotSpecified() throws IOException {
640622 try (RESTSessionCatalog sessionCatalog = new RESTSessionCatalog ()) {
641623 String emptyEnvironmentVariable = "env:__NULL_ENV_VARIABLE__" ;
642624 assertThat (EnvironmentUtil .resolveAll (Map .of ("" , emptyEnvironmentVariable )).get ("" )).isNull ();
643- sessionCatalog .initialize (
644- "snowflake" ,
645- Map .of (
646- "uri" ,
647- "http://localhost:" + EXT .getLocalPort () + "/api/catalog" ,
648- OAuth2Properties .CREDENTIAL ,
649- snowmanCredentials .clientId () + ":" + snowmanCredentials .clientSecret (),
650- OAuth2Properties .SCOPE ,
651- BasePolarisAuthenticator .PRINCIPAL_ROLE_ALL ,
652- "warehouse" ,
653- emptyEnvironmentVariable ,
654- "header." + REALM_PROPERTY_KEY ,
655- realm ));
656- fail ("Expected exception due to null warehouse" );
657- } catch (ServiceFailureException e ) {
658- fail ("Unexpected service failure exception" , e );
659- } catch (RESTException e ) {
660- LoggerFactory .getLogger (getClass ()).info ("Caught expected rest exception" , e );
661- assertThat (e ).isInstanceOf (BadRequestException .class );
625+ assertThatThrownBy (
626+ () ->
627+ sessionCatalog .initialize (
628+ "snowflake" ,
629+ Map .of (
630+ "uri" ,
631+ "http://localhost:" + EXT .getLocalPort () + "/api/catalog" ,
632+ OAuth2Properties .CREDENTIAL ,
633+ snowmanCredentials .clientId () + ":" + snowmanCredentials .clientSecret (),
634+ OAuth2Properties .SCOPE ,
635+ BasePolarisAuthenticator .PRINCIPAL_ROLE_ALL ,
636+ "warehouse" ,
637+ emptyEnvironmentVariable ,
638+ "header." + REALM_PROPERTY_KEY ,
639+ realm )))
640+ .isInstanceOf (BadRequestException .class );
662641 }
663642 }
664643}
0 commit comments