/** * Returns all storages. * <p> * <i> Example URL: /storage</i> * * @return List of all storages. */ @RequestMapping(method = GET, value = "") @ResponseBody public List<StorageData> getAllStorages() { List<StorageData> storages = storageService.getExistingStorages(); return storages; }
/** * Returns storage by ID. * <p> * <i> Example URL: /storage/{id}</i> * * @param id * ID bounded from path. * @return One storage or <code>null</code> if the storage with given ID does not exists. */ @RequestMapping(method = GET, value = "{id}") @ResponseBody public StorageData getStorageById(@PathVariable String id) { List<StorageData> storages = storageService.getExistingStorages(); for (StorageData storageData : storages) { if (Objects.equals(id, storageData.getId())) { return storageData; } } return null; }
@Test public void getStorageById() { String id = "id"; when(storageData.getId()).thenReturn(id); when(storageService.getExistingStorages()).thenReturn(Collections.singletonList(storageData)); assertThat(restfulService.getStorageById(id), is(storageData)); when(storageData.getId()).thenReturn(""); assertThat(restfulService.getStorageById(id), is(nullValue())); }
@SuppressWarnings("deprecation") @Test public void startRecording() throws BusinessException { String id = "id"; StorageData storageData = new StorageData(); storageData.setId(id); when(storageService.getExistingStorages()).thenReturn(Collections.singletonList(storageData)); restfulService.startOrScheduleRecording(id, 10L, 20L, true, true); ArgumentCaptor<RecordingProperties> propertiesCaptor = ArgumentCaptor.forClass(RecordingProperties.class); verify(storageService, times(1)).startOrScheduleRecording(eq(storageData), propertiesCaptor.capture()); assertThat(propertiesCaptor.getValue().getStartDelay(), is(10L)); assertThat(propertiesCaptor.getValue().getRecordDuration(), is(20L)); assertThat(propertiesCaptor.getValue().isAutoFinalize(), is(true)); assertThat(propertiesCaptor.getValue().getRecordingDataProcessors(), hasItem(is(InvocationExtractorDataProcessor.class))); restfulService.startOrScheduleRecording(id, 10L, 20L, false, false); verify(storageService, times(2)).startOrScheduleRecording(eq(storageData), propertiesCaptor.capture()); assertThat(propertiesCaptor.getValue().isAutoFinalize(), is(false)); assertThat(propertiesCaptor.getValue().getRecordingDataProcessors(), not(hasItem(is(InvocationExtractorDataProcessor.class)))); } }