DefaultApplicationSlaManagementService implements ApplicationSlaManagementService { @Override public Observable<Void> addApplicationSLA(ApplicationSLA applicationSLA) { return storage.create(applicationSLA).doOnCompleted(() -> capacityMonitoringService.refresh().subscribe()); } @Inject  DefaultApplicationSlaManagementService(CapacityMonitoringService capacityMonitoringService,
                                                  ApplicationSlaStore storage,
                                                  ManagementSubsystemInitializer initializer); @Override Collection<ApplicationSLA> getApplicationSLAs(); @Override Collection<ApplicationSLA> getApplicationSLAsForScheduler(String schedulerName); @Override Optional<ApplicationSLA> findApplicationSLA(String applicationName); @Override ApplicationSLA getApplicationSLA(String applicationName); @Override Observable<Void> addApplicationSLA(ApplicationSLA applicationSLA); @Override Observable<Void> removeApplicationSLA(String applicationName);  }
@Test public void testAddPersistsApplicationSlaAndUpdatesCapacityRequirements() throws Exception { ApplicationSLA myApp = ApplicationSlaSample.CriticalSmall.build(); when(storage.findAll()).thenReturn(Observable.just(myApp)); when(storage.create(myApp)).thenReturn(Observable.empty()); ObservableRecorder<Void> cpmRecorder = ObservableRecorder.newRecorder(Observable.empty()); when(capacityMonitoringService.refresh()).thenReturn(cpmRecorder.getObservable()); slaManagementService.addApplicationSLA(myApp).toBlocking().firstOrDefault(null); testScheduler.triggerActions(); verify(capacityMonitoringService, times(1)).refresh(); assertThat(cpmRecorder.numberOfFinishedSubscriptions()).isEqualTo(1); }