4444import org .mockito .Mockito ;
4545
4646public class SpecValidatorTest {
47+
48+ @ Rule
49+ public final ExpectedException exception = ExpectedException .none ();
4750 private FeatureInfoRepository featureInfoRepository ;
4851 private FeatureGroupInfoRepository featureGroupInfoRepository ;
4952 private EntityInfoRepository entityInfoRepository ;
5053 private StorageInfoRepository storageInfoRepository ;
5154
52- @ Rule public final ExpectedException exception = ExpectedException .none ();
53-
5455 @ Before
5556 public void setUp () {
5657 featureInfoRepository = Mockito .mock (FeatureInfoRepository .class );
@@ -369,7 +370,7 @@ public void featureSpecWithoutExistingWarehouseStoreShouldThrowIllegalArgumentEx
369370 StorageInfo redis1 = new StorageInfo ();
370371 redis1 .setId (servingStoreId );
371372 redis1 .setType ("redis" );
372- when (storageInfoRepository .findById ( servingStoreId )).thenReturn (Optional .of (redis1 ));
373+ when (storageInfoRepository .findById (servingStoreId )).thenReturn (Optional .of (redis1 ));
373374
374375 SpecValidator validator =
375376 new SpecValidator (
@@ -392,7 +393,8 @@ public void featureSpecWithoutExistingWarehouseStoreShouldThrowIllegalArgumentEx
392393 .setDataStores (dataStores )
393394 .build ();
394395 exception .expect (IllegalArgumentException .class );
395- exception .expectMessage (String .format ("Warehouse store with id %s does not exist" , warehouseStoreId ));
396+ exception .expectMessage (
397+ String .format ("Warehouse store with id %s does not exist" , warehouseStoreId ));
396398 validator .validateFeatureSpec (input );
397399 }
398400
@@ -405,7 +407,7 @@ public void featureSpecWithoutWarehouseStoreShouldBeAllowed() {
405407 StorageInfo redis1 = new StorageInfo ();
406408 redis1 .setId (servingStoreId );
407409 redis1 .setType ("redis" );
408- when (storageInfoRepository .findById ( servingStoreId )).thenReturn (Optional .of (redis1 ));
410+ when (storageInfoRepository .findById (servingStoreId )).thenReturn (Optional .of (redis1 ));
409411
410412 SpecValidator validator =
411413 new SpecValidator (
@@ -432,18 +434,21 @@ public void featureSpecWithoutWarehouseStoreShouldBeAllowed() {
432434 @ Test
433435 public void featureSpecWithUnsupportedWarehouseStoreShouldThrowIllegalArgumentException () {
434436 String servingStoreId = "REDIS1" ;
435- StorageSpec servingStoreSpec = StorageSpec .newBuilder ().setId (servingStoreId ).setType ("redis" ).build ();
437+ StorageSpec servingStoreSpec = StorageSpec .newBuilder ().setId (servingStoreId ).setType ("redis" )
438+ .build ();
436439 StorageInfo servingStoreInfo = new StorageInfo (servingStoreSpec );
437440
438441 String warehouseStoreId = "REDIS2" ;
439- StorageSpec warehouseStoreSpec = StorageSpec .newBuilder ().setId (warehouseStoreId ).setType ("redis" ).build ();
442+ StorageSpec warehouseStoreSpec = StorageSpec .newBuilder ().setId (warehouseStoreId )
443+ .setType ("redis" ).build ();
440444 StorageInfo warehouseStoreInfo = new StorageInfo (warehouseStoreSpec );
441445
442446 when (entityInfoRepository .existsById ("entity" )).thenReturn (true );
443447 when (storageInfoRepository .existsById (servingStoreId )).thenReturn (true );
444448 when (storageInfoRepository .existsById (warehouseStoreId )).thenReturn (true );
445449 when (storageInfoRepository .findById (servingStoreId )).thenReturn (Optional .of (servingStoreInfo ));
446- when (storageInfoRepository .findById (warehouseStoreId )).thenReturn (Optional .of (warehouseStoreInfo ));
450+ when (storageInfoRepository .findById (warehouseStoreId ))
451+ .thenReturn (Optional .of (warehouseStoreInfo ));
447452 SpecValidator validator =
448453 new SpecValidator (
449454 storageInfoRepository ,
@@ -488,7 +493,8 @@ public void featureSpecWithUnsupportedServingStoreShouldThrowIllegalArgumentExce
488493 when (entityInfoRepository .existsById ("entity" )).thenReturn (true );
489494 when (storageInfoRepository .existsById (servingStoreName )).thenReturn (true );
490495 when (storageInfoRepository .existsById (warehouseStorageName )).thenReturn (true );
491- when (storageInfoRepository .findById (servingStoreName )).thenReturn (Optional .of (redis1StorageInfo ));
496+ when (storageInfoRepository .findById (servingStoreName ))
497+ .thenReturn (Optional .of (redis1StorageInfo ));
492498 when (storageInfoRepository .findById (warehouseStorageName )).thenReturn (Optional .of (bqInfo ));
493499 SpecValidator validator =
494500 new SpecValidator (
@@ -778,4 +784,55 @@ public void importSpecWithUnregisteredFeaturesShouldThrowIllegalArgumentExceptio
778784 "Validation for import spec failed: Feature some_nonexistent_feature not registered" );
779785 validator .validateImportSpec (input );
780786 }
787+
788+ @ Test
789+ public void importSpecWithKafkaSourceAndCorrectOptionsShouldPassValidation () {
790+ SpecValidator validator =
791+ new SpecValidator (
792+ storageInfoRepository ,
793+ entityInfoRepository ,
794+ featureGroupInfoRepository ,
795+ featureInfoRepository );
796+ when (featureInfoRepository .existsById ("some_existing_feature" )).thenReturn (true );
797+ when (entityInfoRepository .existsById ("someEntity" )).thenReturn (true );
798+ Schema schema =
799+ Schema .newBuilder ()
800+ .addFields (Field .newBuilder ().setFeatureId ("some_existing_feature" ).build ())
801+ .build ();
802+ ImportSpec input =
803+ ImportSpec .newBuilder ()
804+ .setType ("kafka" )
805+ .putOptions ("topics" , "my-kafka-topic" )
806+ .putOptions ("server" , "localhost:54321" )
807+ .setSchema (schema )
808+ .addEntities ("someEntity" )
809+ .build ();
810+ validator .validateImportSpec (input );
811+ }
812+
813+ @ Test
814+ public void importSpecWithKafkaSourceWithoutOptionsShouldThrowIllegalArgumentException () {
815+ SpecValidator validator =
816+ new SpecValidator (
817+ storageInfoRepository ,
818+ entityInfoRepository ,
819+ featureGroupInfoRepository ,
820+ featureInfoRepository );
821+ when (featureInfoRepository .existsById ("some_existing_feature" )).thenReturn (true );
822+ when (entityInfoRepository .existsById ("someEntity" )).thenReturn (true );
823+ Schema schema =
824+ Schema .newBuilder ()
825+ .addFields (Field .newBuilder ().setFeatureId ("some_existing_feature" ).build ())
826+ .build ();
827+ ImportSpec input =
828+ ImportSpec .newBuilder ()
829+ .setType ("kafka" )
830+ .setSchema (schema )
831+ .addEntities ("someEntity" )
832+ .build ();
833+ exception .expect (IllegalArgumentException .class );
834+ exception .expectMessage (
835+ "Validation for import spec failed: Invalid options: Kafka ingestion requires either topics or servers" );
836+ validator .validateImportSpec (input );
837+ }
781838}
0 commit comments