@Test public void recordingStatus() { RecordingData recordingData = mock(RecordingData.class, Mockito.RETURNS_SMART_NULLS); when(storageService.getRecordingData()).thenReturn(recordingData); when(storageService.getRecordingState()).thenReturn(RecordingState.OFF); assertThat(restfulService.getRecordingState(), hasEntry("recordingState", (Object) RecordingState.OFF)); verifyZeroInteractions(recordingData); when(storageService.getRecordingState()).thenReturn(RecordingState.ON); when(recordingData.getRecordEndDate()).thenReturn(new Date()); Map<String, Object> result = restfulService.getRecordingState(); assertThat(result, hasEntry("recordingState", (Object) RecordingState.ON)); assertThat(result, hasKey("recordingStopDate")); when(storageService.getRecordingState()).thenReturn(RecordingState.SCHEDULED); when(recordingData.getRecordStartDate()).thenReturn(new Date()); result = restfulService.getRecordingState(); assertThat(result, hasEntry("recordingState", (Object) RecordingState.SCHEDULED)); assertThat(result, hasKey("schduledStartDate")); }
@RequestMapping(method = GET, value = "state") @ResponseBody public Map<String, Object> getRecordingState() { RecordingState state = storageService.getRecordingState(); Map<String, Object> resultMap = new HashMap<>(); resultMap.put("recordingState", state); if (RecordingState.OFF != state) { RecordingData recordingData = storageService.getRecordingData(); resultMap.put("recordingStorage", recordingData.getRecordingStorage()); if (RecordingState.ON == state) { Date recordingEndDate = recordingData.getRecordEndDate(); if (null != recordingEndDate) { resultMap.put("recordingStopDate", DateFormat.getDateTimeInstance().format(recordingEndDate)); } } if (RecordingState.SCHEDULED == state) { resultMap.put("schduledStartDate", DateFormat.getDateTimeInstance().format(recordingData.getRecordStartDate())); } } return resultMap; }
StorageRestfulService { @RequestMapping(method = GET, value = "state") @ResponseBody public Map<String, Object> getRecordingState() { RecordingState state = storageService.getRecordingState(); Map<String, Object> resultMap = new HashMap<>(); resultMap.put("recordingState", state); if (RecordingState.OFF != state) { RecordingData recordingData = storageService.getRecordingData(); resultMap.put("recordingStorage", recordingData.getRecordingStorage()); if (RecordingState.ON == state) { Date recordingEndDate = recordingData.getRecordEndDate(); if (null != recordingEndDate) { resultMap.put("recordingStopDate", DateFormat.getDateTimeInstance().format(recordingEndDate)); } } if (RecordingState.SCHEDULED == state) { resultMap.put("schduledStartDate", DateFormat.getDateTimeInstance().format(recordingData.getRecordStartDate())); } } return resultMap; } }
StorageRestfulService { @RequestMapping(method = GET, value = "state") @ResponseBody public Map<String, Object> getRecordingState() { RecordingState state = storageService.getRecordingState(); Map<String, Object> resultMap = new HashMap<>(); resultMap.put("recordingState", state); if (RecordingState.OFF != state) { RecordingData recordingData = storageService.getRecordingData(); resultMap.put("recordingStorage", recordingData.getRecordingStorage()); if (RecordingState.ON == state) { Date recordingEndDate = recordingData.getRecordEndDate(); if (null != recordingEndDate) { resultMap.put("recordingStopDate", DateFormat.getDateTimeInstance().format(recordingEndDate)); } } if (RecordingState.SCHEDULED == state) { resultMap.put("schduledStartDate", DateFormat.getDateTimeInstance().format(recordingData.getRecordStartDate())); } } return resultMap; }  }
StorageRestfulService { @RequestMapping(method = GET, value = "state") @ResponseBody public Map<String, Object> getRecordingState() { RecordingState state = storageService.getRecordingState(); Map<String, Object> resultMap = new HashMap<>(); resultMap.put("recordingState", state); if (RecordingState.OFF != state) { RecordingData recordingData = storageService.getRecordingData(); resultMap.put("recordingStorage", recordingData.getRecordingStorage()); if (RecordingState.ON == state) { Date recordingEndDate = recordingData.getRecordEndDate(); if (null != recordingEndDate) { resultMap.put("recordingStopDate", DateFormat.getDateTimeInstance().format(recordingEndDate)); } } if (RecordingState.SCHEDULED == state) { resultMap.put("schduledStartDate", DateFormat.getDateTimeInstance().format(recordingData.getRecordStartDate())); } } return resultMap; }  @ExceptionHandler(Exception.class) ModelAndView handleAllException(Exception exception); @RequestMapping(method = GET, value = "") @ResponseBody List<StorageData> getAllStorages(); @RequestMapping(method = GET, value = "{id}") @ResponseBody StorageData getStorageById(@PathVariable String id); @RequestMapping(method = GET, value = "{name}/create") @ResponseBody Object createStorage(@PathVariable String name); @RequestMapping(method = GET, value = "{id}/finalize") @ResponseBody Object finalizeStorage(@PathVariable String id); @RequestMapping(method = GET, value = "{id}/delete") @ResponseBody Object deleteStorage(@PathVariable String id); @RequestMapping(method = GET, value = "state") @ResponseBody Map<String, Object> getRecordingState(); @RequestMapping(method = GET, value = "stop") @ResponseBody Object stopRecording(); @RequestMapping(method = RequestMethod.GET, value = "start") @ResponseBody Object startOrScheduleRecording(@RequestParam(value = "id", required = true) String id, @RequestParam(value = "startDelay", required = false) Long startDelay,
			@RequestParam(value = "recordingDuration", required = false) Long recordingDuration,
			@RequestParam(value = "extractInvocations", required = false, defaultValue = "true") Boolean extractInvocations,
			@RequestParam(value = "autoFinalize", required = false, defaultValue = "true") Boolean autoFinalize); @ModelAttribute void setVaryResponseHeader(HttpServletResponse response); }
StorageRestfulService { @RequestMapping(method = GET, value = "state") @ResponseBody public Map<String, Object> getRecordingState() { RecordingState state = storageService.getRecordingState(); Map<String, Object> resultMap = new HashMap<>(); resultMap.put("recordingState", state); if (RecordingState.OFF != state) { RecordingData recordingData = storageService.getRecordingData(); resultMap.put("recordingStorage", recordingData.getRecordingStorage()); if (RecordingState.ON == state) { Date recordingEndDate = recordingData.getRecordEndDate(); if (null != recordingEndDate) { resultMap.put("recordingStopDate", DateFormat.getDateTimeInstance().format(recordingEndDate)); } } if (RecordingState.SCHEDULED == state) { resultMap.put("schduledStartDate", DateFormat.getDateTimeInstance().format(recordingData.getRecordStartDate())); } } return resultMap; }  @ExceptionHandler(Exception.class) ModelAndView handleAllException(Exception exception); @RequestMapping(method = GET, value = "") @ResponseBody List<StorageData> getAllStorages(); @RequestMapping(method = GET, value = "{id}") @ResponseBody StorageData getStorageById(@PathVariable String id); @RequestMapping(method = GET, value = "{name}/create") @ResponseBody Object createStorage(@PathVariable String name); @RequestMapping(method = GET, value = "{id}/finalize") @ResponseBody Object finalizeStorage(@PathVariable String id); @RequestMapping(method = GET, value = "{id}/delete") @ResponseBody Object deleteStorage(@PathVariable String id); @RequestMapping(method = GET, value = "state") @ResponseBody Map<String, Object> getRecordingState(); @RequestMapping(method = GET, value = "stop") @ResponseBody Object stopRecording(); @RequestMapping(method = RequestMethod.GET, value = "start") @ResponseBody Object startOrScheduleRecording(@RequestParam(value = "id", required = true) String id, @RequestParam(value = "startDelay", required = false) Long startDelay,
			@RequestParam(value = "recordingDuration", required = false) Long recordingDuration,
			@RequestParam(value = "extractInvocations", required = false, defaultValue = "true") Boolean extractInvocations,
			@RequestParam(value = "autoFinalize", required = false, defaultValue = "true") Boolean autoFinalize); @ModelAttribute void setVaryResponseHeader(HttpServletResponse response);  }