/** * Creates a new storage with given name. * <p> * <i> Example URL: /storage/{name}/create</i> * * @param name * Name of the storage. * @return Map containing message and created storage. * @throws BusinessException * If {@link BusinessException} occurs. */ @RequestMapping(method = GET, value = "{name}/create") @ResponseBody public Object createStorage(@PathVariable String name) throws BusinessException { if (StringUtils.isEmpty(name)) { throw new BusinessException("Create a new storage via storage REST service.", StorageErrorCodeEnum.STORAGE_NAME_IS_NOT_PROVIDED); } StorageData storageData = new StorageData(); storageData.setName(name); storageData = storageService.createAndOpenStorage(storageData); Map<String, Object> resultMap = new HashMap<>(); resultMap.put("message", "Storage successfully created."); resultMap.put("storage", storageData); return resultMap; }
@Test public void createStorage() throws BusinessException { String name = "name"; restfulService.createStorage(name); ArgumentCaptor<StorageData> captor = ArgumentCaptor.forClass(StorageData.class); verify(storageService, times(1)).createAndOpenStorage(captor.capture()); assertThat(captor.getValue().getName(), is(name)); }