Search in sources :

Example 16 with Storage

use of org.finra.herd.model.api.xml.Storage in project herd by FINRAOS.

the class StorageServiceTest method testCreateStorageMissingOptionalParameters.

@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);
}
Also used : Storage(org.finra.herd.model.api.xml.Storage) StorageCreateRequest(org.finra.herd.model.api.xml.StorageCreateRequest) Test(org.junit.Test)

Example 17 with Storage

use of org.finra.herd.model.api.xml.Storage in project herd by FINRAOS.

the class StorageServiceTest method testDeleteStorage.

@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()));
}
Also used : Storage(org.finra.herd.model.api.xml.Storage) StorageKey(org.finra.herd.model.api.xml.StorageKey) Test(org.junit.Test)

Example 18 with Storage

use of org.finra.herd.model.api.xml.Storage in project herd by FINRAOS.

the class StorageServiceTest method testUpdateStorageAttributesStorageHasDuplicateAttributes.

@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());
    }
}
Also used : Storage(org.finra.herd.model.api.xml.Storage) StorageAttributeEntity(org.finra.herd.model.jpa.StorageAttributeEntity) StorageAttributesUpdateRequest(org.finra.herd.model.api.xml.StorageAttributesUpdateRequest) StorageEntity(org.finra.herd.model.jpa.StorageEntity) StorageCreateRequest(org.finra.herd.model.api.xml.StorageCreateRequest) StorageKey(org.finra.herd.model.api.xml.StorageKey) Test(org.junit.Test)

Example 19 with Storage

use of org.finra.herd.model.api.xml.Storage in project herd by FINRAOS.

the class BusinessObjectDataHelperTest method getStorageUnitByStorageName.

@Test
public void getStorageUnitByStorageName() {
    // Create business object data with several test storage units.
    BusinessObjectData businessObjectData = new BusinessObjectData();
    List<String> testStorageNames = Arrays.asList("Storage_1", "storage-2", "STORAGE3");
    List<StorageUnit> storageUnits = new ArrayList<>();
    businessObjectData.setStorageUnits(storageUnits);
    for (String testStorageName : testStorageNames) {
        StorageUnit storageUnit = new StorageUnit();
        storageUnits.add(storageUnit);
        Storage storage = new Storage();
        storageUnit.setStorage(storage);
        storage.setName(testStorageName);
    }
    // Validate that we can find all storage units regardless of the storage name case.
    for (String testStorageName : testStorageNames) {
        assertEquals(testStorageName, businessObjectDataHelper.getStorageUnitByStorageName(businessObjectData, testStorageName).getStorage().getName());
        assertEquals(testStorageName, businessObjectDataHelper.getStorageUnitByStorageName(businessObjectData, testStorageName.toUpperCase()).getStorage().getName());
        assertEquals(testStorageName, businessObjectDataHelper.getStorageUnitByStorageName(businessObjectData, testStorageName.toLowerCase()).getStorage().getName());
    }
}
Also used : Storage(org.finra.herd.model.api.xml.Storage) BusinessObjectData(org.finra.herd.model.api.xml.BusinessObjectData) ArrayList(java.util.ArrayList) StorageUnit(org.finra.herd.model.api.xml.StorageUnit) Test(org.junit.Test) AbstractServiceTest(org.finra.herd.service.AbstractServiceTest)

Example 20 with Storage

use of org.finra.herd.model.api.xml.Storage in project herd by FINRAOS.

the class MockHttpClientOperationsImpl method getNewStorage.

/**
 * Gets a new storage object with the specified information.
 *
 * @param storageName the storage name.
 *
 * @return the newly created storage.
 */
private Storage getNewStorage(String storageName) {
    Storage storage = new Storage();
    storage.setName(storageName);
    storage.setStoragePlatformName(StoragePlatformEntity.S3);
    List<Attribute> attributes = new ArrayList<>();
    attributes.add(new Attribute(configurationHelper.getProperty(ConfigurationValue.S3_ATTRIBUTE_NAME_BUCKET_NAME), "testBucket"));
    /*
         * Set the KMS key attribute if the storage name contains ignore case the word "KMS" (ex. S3_MANAGED_KMS)
         */
    if (storageName.toLowerCase().contains("kms")) {
        attributes.add(new Attribute(configurationHelper.getProperty(ConfigurationValue.S3_ATTRIBUTE_NAME_KMS_KEY_ID), "testKmsKeyId"));
    }
    storage.setAttributes(attributes);
    return storage;
}
Also used : Storage(org.finra.herd.model.api.xml.Storage) Attribute(org.finra.herd.model.api.xml.Attribute) ArrayList(java.util.ArrayList)

Aggregations

Storage (org.finra.herd.model.api.xml.Storage)38 Test (org.junit.Test)29 StorageUnit (org.finra.herd.model.api.xml.StorageUnit)19 BusinessObjectData (org.finra.herd.model.api.xml.BusinessObjectData)17 Attribute (org.finra.herd.model.api.xml.Attribute)10 StorageKey (org.finra.herd.model.api.xml.StorageKey)10 ArrayList (java.util.ArrayList)6 StorageCreateRequest (org.finra.herd.model.api.xml.StorageCreateRequest)6 File (java.io.File)5 BusinessObjectDataKey (org.finra.herd.model.api.xml.BusinessObjectDataKey)4 S3KeyPrefixInformation (org.finra.herd.model.api.xml.S3KeyPrefixInformation)4 StorageAttributesUpdateRequest (org.finra.herd.model.api.xml.StorageAttributesUpdateRequest)4 StorageDirectory (org.finra.herd.model.api.xml.StorageDirectory)4 DownloaderInputManifestDto (org.finra.herd.model.dto.DownloaderInputManifestDto)4 DownloaderOutputManifestDto (org.finra.herd.model.dto.DownloaderOutputManifestDto)4 StorageUnitEntity (org.finra.herd.model.jpa.StorageUnitEntity)4 IOException (java.io.IOException)3 Path (java.nio.file.Path)3 AwsCredential (org.finra.herd.model.api.xml.AwsCredential)3 BusinessObjectDataStorageUnitKey (org.finra.herd.model.api.xml.BusinessObjectDataStorageUnitKey)3