@@ -150,6 +150,10 @@ public void setUp() {
150150 when (projectRepository .findAllByArchivedIsFalse ())
151151 .thenReturn (Collections .singletonList (new Project ("project1" )));
152152 when (projectRepository .findById ("project1" )).thenReturn (Optional .of (new Project ("project1" )));
153+ Project archivedProject = new Project ("archivedproject" );
154+ archivedProject .setArchived (true );
155+ when (projectRepository .findById (archivedProject .getName ()))
156+ .thenReturn (Optional .of (archivedProject ));
153157
154158 Store store1 = newDummyStore ("SERVING" );
155159 Store store2 = newDummyStore ("WAREHOUSE" );
@@ -481,6 +485,55 @@ public void applyFeatureSetShouldNotCreateFeatureSetIfFieldsUnordered() {
481485 equalTo (incomingFeatureSet .getSpec ().getName ()));
482486 }
483487
488+ @ Test
489+ public void applyFeatureSetShouldCreateProjectWhenNotAlreadyExists ()
490+ throws InvalidProtocolBufferException {
491+ Field f3f1 = new Field ("f3f1" , Enum .INT64 );
492+ Field f3f2 = new Field ("f3f2" , Enum .INT64 );
493+ Field f3e1 = new Field ("f3e1" , Enum .STRING );
494+ FeatureSetProto .FeatureSet incomingFeatureSet =
495+ (new FeatureSet (
496+ "f3" ,
497+ "newproject" ,
498+ 5 ,
499+ 100L ,
500+ Arrays .asList (f3e1 ),
501+ Arrays .asList (f3f2 , f3f1 ),
502+ defaultSource ,
503+ FeatureSetStatus .STATUS_READY ))
504+ .toProto ();
505+
506+ ApplyFeatureSetResponse applyFeatureSetResponse =
507+ specService .applyFeatureSet (incomingFeatureSet );
508+ assertThat (applyFeatureSetResponse .getStatus (), equalTo (Status .CREATED ));
509+ assertThat (
510+ applyFeatureSetResponse .getFeatureSet ().getSpec ().getProject (),
511+ equalTo (incomingFeatureSet .getSpec ().getProject ()));
512+ }
513+
514+ @ Test
515+ public void applyFeatureSetShouldFailWhenProjectIsArchived ()
516+ throws InvalidProtocolBufferException {
517+ Field f3f1 = new Field ("f3f1" , Enum .INT64 );
518+ Field f3f2 = new Field ("f3f2" , Enum .INT64 );
519+ Field f3e1 = new Field ("f3e1" , Enum .STRING );
520+ FeatureSetProto .FeatureSet incomingFeatureSet =
521+ (new FeatureSet (
522+ "f3" ,
523+ "archivedproject" ,
524+ 5 ,
525+ 100L ,
526+ Arrays .asList (f3e1 ),
527+ Arrays .asList (f3f2 , f3f1 ),
528+ defaultSource ,
529+ FeatureSetStatus .STATUS_READY ))
530+ .toProto ();
531+
532+ expectedException .expect (IllegalArgumentException .class );
533+ expectedException .expectMessage ("Project is archived" );
534+ specService .applyFeatureSet (incomingFeatureSet );
535+ }
536+
484537 @ Test
485538 public void shouldUpdateStoreIfConfigChanges () throws InvalidProtocolBufferException {
486539 when (storeRepository .findById ("SERVING" )).thenReturn (Optional .of (stores .get (0 )));
0 commit comments