/** * Creates a new storage. * * @param storageCreateRequest the information needed to create the storage * * @return the created storage information */ @RequestMapping(value = STORAGE_URI_PREFIX, method = RequestMethod.POST, consumes = {"application/xml", "application/json"}) @Secured(SecurityFunctions.FN_STORAGES_POST) Storage createStorage(@RequestBody StorageCreateRequest storageCreateRequest) { return storageService.createStorage(storageCreateRequest); }
/** * Deletes an existing storage by name. * * @param storageName the storage name * * @return the storage information of the storage that got deleted */ @RequestMapping(value = STORAGE_URI_PREFIX + "/{storageName}", method = RequestMethod.DELETE) @Secured(SecurityFunctions.FN_STORAGES_DELETE) Storage deleteStorage(@PathVariable("storageName") String storageName) { return storageService.deleteStorage(new StorageKey(storageName)); }
/** * Gets a list of storage keys for all storage defined in the system. * * @return the list of storage keys */ @RequestMapping(value = STORAGE_URI_PREFIX, method = RequestMethod.GET) @Secured(SecurityFunctions.FN_STORAGES_ALL_GET) StorageKeys getStorages() { return storageService.getAllStorage(); }
@Test public void testUpdateStorageAttributesRemoveAllAttributes() { // Create and persist a valid storage. StorageCreateRequest request = getNewStorageCreateRequest(); Storage storage = storageService.createStorage(request); // Update attributes for the storage. Storage result = storageService.updateStorageAttributes(new StorageKey(storage.getName()), new StorageAttributesUpdateRequest(NO_ATTRIBUTES)); // Validate the results. assertEquals(new Storage(storage.getName(), storage.getStoragePlatformName(), NO_ATTRIBUTES), result); }
@Test public void testGetStorage() { // Create and persist a valid storage. Storage storage = storageService.createStorage(getNewStorageCreateRequest()); // Retrieve the storage by its name. Storage result = storageService.getStorage(new StorageKey(storage.getName())); // Validate the results. assertEquals(storage, result); }
@Test public void testDeleteStorage() { // Create and persist a valid storage. Storage storage = storageService.createStorage(getNewStorageCreateRequest()); // Delete the storage. Storage result = storageService.deleteStorage(new StorageKey(storage.getName())); assertEquals(storage, result); // Retrieve the storage by its name and verify that it doesn't exist. assertNull(storageDao.getStorageByName(storage.getName())); }
@Test public void testUpdateStorage() { // Create a storage. Storage storage = storageService.createStorage(getNewStorageCreateRequest()); // Update the storage. // TODO: Update various attributes of the storage update request in the future when there is something to update. Storage result = storageService.updateStorage(new StorageKey(storage.getName()), new StorageUpdateRequest()); // Validate the results. // TODO: Add asserts to ensure fields that were update indeed got updated. assertEquals(new Storage(storage.getName(), storage.getStoragePlatformName(), storage.getAttributes()), result); }
/** * Gets an existing storage by name. * * @param storageName the storage name * * @return the storage information */ @RequestMapping(value = STORAGE_URI_PREFIX + "/{storageName}", method = RequestMethod.GET) @Secured(SecurityFunctions.FN_STORAGES_GET) Storage getStorage(@PathVariable("storageName") String storageName) { return storageService.getStorage(new StorageKey(storageName)); }
/** * Updates an existing storage. * * @param storageName the name of the storage to update * @param storageUpdateRequest the information needed to update the storage * * @return the updated storage information */ @RequestMapping(value = STORAGE_URI_PREFIX + "/{storageName}", method = RequestMethod.PUT, consumes = {"application/xml", "application/json"}) @Secured(SecurityFunctions.FN_STORAGES_PUT) Storage updateStorage(@PathVariable("storageName") String storageName, @RequestBody StorageUpdateRequest storageUpdateRequest) { return storageService.updateStorage(new StorageKey(storageName), storageUpdateRequest); }
/** * Updates an existing storage attributes by storage name. * <p> * This endpoint replaces the entire list of attributes on the Storage with the contents of the request. Observe this example: * <ol> * <li>Three attributes present on the Storage.</li> * <li>This endpoint is called with a single attribute in the request with an updated value.</li> * <li>After this operation the Storage will have only one attribute – which is probably not the desired outcome.</li> * <li>Instead, supply all existing attributes and provide updated values and additional attributes as needed. * The only case when an existing attribute should be left out is to remove the attribute.</li> * </ol> * </p> * * @param storageName the name of the storage * @param storageAttributesUpdateRequest the information needed to update storage attributes * * @return the updated storage information */ @RequestMapping(value = "/storageAttributes/storages/{storageName}", method = RequestMethod.PUT, consumes = {"application/xml", "application/json"}) @Secured(SecurityFunctions.FN_STORAGE_ATTRIBUTES_PUT) Storage updateStorageAttributes(@PathVariable("storageName") String storageName, @RequestBody StorageAttributesUpdateRequest storageAttributesUpdateRequest) { return storageService.updateStorageAttributes(new StorageKey(storageName), storageAttributesUpdateRequest); } }
@Test public void testUpdateStorageAttributes() { // Create and persist a valid storage. StorageCreateRequest request = getNewStorageCreateRequest(); Storage storage = storageService.createStorage(request); // Update attributes for the storage. Storage result = storageService.updateStorageAttributes(new StorageKey(storage.getName()), new StorageAttributesUpdateRequest(businessObjectDefinitionServiceTestHelper.getNewAttributes2())); // Validate the results. assertEquals(new Storage(storage.getName(), storage.getStoragePlatformName(), businessObjectDefinitionServiceTestHelper.getNewAttributes2()), result); }
/** * Gets an existing storage by name. * * @param storageName the storage name * * @return the storage information */ @RequestMapping(value = STORAGE_URI_PREFIX + "/{storageName}", method = RequestMethod.GET) @Secured(SecurityFunctions.FN_STORAGES_GET) Storage getStorage(@PathVariable("storageName") String storageName) { return storageService.getStorage(new StorageKey(storageName)); }
/** * Updates an existing storage. * * @param storageName the name of the storage to update * @param storageUpdateRequest the information needed to update the storage * * @return the updated storage information */ @RequestMapping(value = STORAGE_URI_PREFIX + "/{storageName}", method = RequestMethod.PUT, consumes = {"application/xml", "application/json"}) @Secured(SecurityFunctions.FN_STORAGES_PUT) Storage updateStorage(@PathVariable("storageName") String storageName, @RequestBody StorageUpdateRequest storageUpdateRequest) { return storageService.updateStorage(new StorageKey(storageName), storageUpdateRequest); }
/** * Updates an existing storage attributes by storage name. * <p> * This endpoint replaces the entire list of attributes on the Storage with the contents of the request. Observe this example: * <ol> * <li>Three attributes present on the Storage.</li> * <li>This endpoint is called with a single attribute in the request with an updated value.</li> * <li>After this operation the Storage will have only one attribute – which is probably not the desired outcome.</li> * <li>Instead, supply all existing attributes and provide updated values and additional attributes as needed. * The only case when an existing attribute should be left out is to remove the attribute.</li> * </ol> * </p> * * @param storageName the name of the storage * @param storageAttributesUpdateRequest the information needed to update storage attributes * * @return the updated storage information */ @RequestMapping(value = "/storageAttributes/storages/{storageName}", method = RequestMethod.PUT, consumes = {"application/xml", "application/json"}) @Secured(SecurityFunctions.FN_STORAGE_ATTRIBUTES_PUT) Storage updateStorageAttributes(@PathVariable("storageName") String storageName, @RequestBody StorageAttributesUpdateRequest storageAttributesUpdateRequest) { return storageService.updateStorageAttributes(new StorageKey(storageName), storageAttributesUpdateRequest); } }
@Test public void testUpdateStorageAttributesStorageHasDuplicateAttributes() { // Create and persist a valid storage. StorageCreateRequest request = getNewStorageCreateRequest(); Storage storage = storageService.createStorage(request); // Add a duplicate attribute to the storage. StorageEntity storageEntity = storageDao.getStorageByName(storage.getName()); StorageAttributeEntity storageAttributeEntity = new StorageAttributeEntity(); storageAttributeEntity.setStorage(storageEntity); storageAttributeEntity.setName(request.getAttributes().get(0).getName().toUpperCase()); storageEntity.getAttributes().add(storageAttributeEntity); storageDao.saveAndRefresh(storageEntity); // Try to update attributes for the storage. try { storageService.updateStorageAttributes(new StorageKey(storage.getName()), new StorageAttributesUpdateRequest(businessObjectDefinitionServiceTestHelper.getNewAttributes2())); } catch (IllegalStateException e) { assertEquals(String.format("Found duplicate attribute with name \"%s\" for \"%s\" storage.", request.getAttributes().get(0).getName().toLowerCase(), storage.getName()), e.getMessage()); } }
/** * Creates a new storage. * * @param storageCreateRequest the information needed to create the storage * * @return the created storage information */ @RequestMapping(value = STORAGE_URI_PREFIX, method = RequestMethod.POST, consumes = {"application/xml", "application/json"}) @Secured(SecurityFunctions.FN_STORAGES_POST) Storage createStorage(@RequestBody StorageCreateRequest storageCreateRequest) { return storageService.createStorage(storageCreateRequest); }
/** * Deletes an existing storage by name. * * @param storageName the storage name * * @return the storage information of the storage that got deleted */ @RequestMapping(value = STORAGE_URI_PREFIX + "/{storageName}", method = RequestMethod.DELETE) @Secured(SecurityFunctions.FN_STORAGES_DELETE) Storage deleteStorage(@PathVariable("storageName") String storageName) { return storageService.deleteStorage(new StorageKey(storageName)); }
/** * Gets a list of storage keys for all storage defined in the system. * * @return the list of storage keys */ @RequestMapping(value = STORAGE_URI_PREFIX, method = RequestMethod.GET) @Secured(SecurityFunctions.FN_STORAGES_ALL_GET) StorageKeys getStorages() { return storageService.getAllStorage(); }
@Test public void testGetStorage() { // Create a storage key. StorageKey storageKey = new StorageKey(STORAGE_NAME); // Create a storage. Storage storage = new Storage(STORAGE_NAME, STORAGE_PLATFORM_CODE, NO_ATTRIBUTES); // Mock the external calls. when(storageService.getStorage(storageKey)).thenReturn(storage); // Call the method under test. Storage result = storageRestController.getStorage(STORAGE_NAME); // Verify the external calls. verify(storageService).getStorage(storageKey); verifyNoMoreInteractions(storageService); // Validate the returned object. assertEquals(storage, result); }
@Test public void testUpdateStorage() { // Create a storage key. StorageKey storageKey = new StorageKey(STORAGE_NAME); // Create a storage update request. StorageUpdateRequest storageUpdateRequest = new StorageUpdateRequest(); // Create a storage. Storage storage = new Storage(STORAGE_NAME, STORAGE_PLATFORM_CODE, NO_ATTRIBUTES); // Mock the external calls. when(storageService.updateStorage(storageKey, storageUpdateRequest)).thenReturn(storage); // Call the method under test. Storage result = storageRestController.updateStorage(STORAGE_NAME, storageUpdateRequest); // Verify the external calls. verify(storageService).updateStorage(storageKey, storageUpdateRequest); verifyNoMoreInteractions(storageService); // Validate the returned object. assertEquals(storage, result); }