/** * 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); }
/** * 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); }
@Test public void testCreateStorage() { // Create a storage create request. StorageCreateRequest storageCreateRequest = new StorageCreateRequest(STORAGE_NAME, STORAGE_PLATFORM_CODE, NO_ATTRIBUTES); // Create a storage. Storage storage = new Storage(STORAGE_NAME, STORAGE_PLATFORM_CODE, NO_ATTRIBUTES); // Mock the external calls. when(storageService.createStorage(storageCreateRequest)).thenReturn(storage); // Call the method under test. Storage result = storageRestController.createStorage(storageCreateRequest); // Verify the external calls. verify(storageService).createStorage(storageCreateRequest); verifyNoMoreInteractions(storageService); // Validate the returned object. assertEquals(storage, result); }
@Test public void testCreateStorageStorageAlreadyExists() { // Create and persist a valid storage. StorageCreateRequest storageCreateRequest = getNewStorageCreateRequest(); storageService.createStorage(storageCreateRequest); // Try creating that storage again which is invalid since it already exists. try { storageService.createStorage(storageCreateRequest); fail(); } catch (AlreadyExistsException e) { assertEquals(String.format("Storage with name \"%s\" already exists.", storageCreateRequest.getName()), e.getMessage()); } }
@Test public void testCreateStorageMissingRequiredParameters() { // Try to create a storage without specifying a storage name. try { storageService.createStorage(new StorageCreateRequest(BLANK_TEXT, STORAGE_PLATFORM_CODE, NO_ATTRIBUTES)); fail(); } catch (IllegalArgumentException e) { assertEquals("A storage name must be specified.", e.getMessage()); } }
@Test public void testCreateStorageInvalidParameters() { // Try to create a storage instance when storage platform name contains a forward slash character. try { storageService.createStorage(new StorageCreateRequest(STORAGE_NAME, addSlash(STORAGE_PLATFORM_CODE), NO_ATTRIBUTES)); fail("Should throw an IllegalArgumentException when storage platform name contains a forward slash character."); } catch (IllegalArgumentException e) { assertEquals("Storage platform name can not contain a forward slash character.", e.getMessage()); } // Try to create a storage instance when storage name contains a forward slash character. try { storageService.createStorage(new StorageCreateRequest(addSlash(DATA_PROVIDER_NAME), STORAGE_PLATFORM_CODE, NO_ATTRIBUTES)); fail("Should throw an IllegalArgumentException when storage name contains a forward slash character."); } catch (IllegalArgumentException e) { assertEquals("Storage name can not contain a forward slash character.", e.getMessage()); } }
@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 testCreateStorage() { // Create and persist a valid storage. StorageCreateRequest request = getNewStorageCreateRequest(); Storage result = storageService.createStorage(request); // Validate the results. assertEquals(new Storage(request.getName(), request.getStoragePlatformName(), request.getAttributes()), result); }
@Test public void testCreateStorageMissingOptionalParameters() { // Create and persist a valid storage without specifying optional parameters. StorageCreateRequest request = getNewStorageCreateRequest(); request.setAttributes(null); Storage result = storageService.createStorage(request); // Validate the results. assertEquals(new Storage(request.getName(), request.getStoragePlatformName(), NO_ATTRIBUTES), result); }
@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()); } }
@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 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 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); }
@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); }