Search in sources :

Example 31 with StorageUnit

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

the class StorageFileHelperTest method testValidateDownloadedS3Files.

@Test
public void testValidateDownloadedS3Files() throws IOException {
    File targetLocalDirectory = Paths.get(LOCAL_TEMP_PATH.toString(), TEST_S3_KEY_PREFIX).toFile();
    createLocalFiles(targetLocalDirectory.getPath(), FILE_SIZE_1_KB);
    StorageUnit storageUnit = createStorageUnit(TEST_S3_KEY_PREFIX, LOCAL_FILES, FILE_SIZE_1_KB);
    storageFileHelper.validateDownloadedS3Files(LOCAL_TEMP_PATH.toString(), TEST_S3_KEY_PREFIX, storageUnit);
}
Also used : StorageUnit(org.finra.herd.model.api.xml.StorageUnit) File(java.io.File) StorageFile(org.finra.herd.model.api.xml.StorageFile) Test(org.junit.Test) AbstractServiceTest(org.finra.herd.service.AbstractServiceTest)

Example 32 with StorageUnit

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

the class StorageFileHelperTest method testValidateDownloadedS3FilesFileSizeMismatch.

@Test
public void testValidateDownloadedS3FilesFileSizeMismatch() throws IOException {
    File targetLocalDirectory = Paths.get(LOCAL_TEMP_PATH.toString(), TEST_S3_KEY_PREFIX).toFile();
    createLocalFiles(targetLocalDirectory.getPath(), FILE_SIZE_1_KB);
    StorageUnit storageUnit = createStorageUnit(TEST_S3_KEY_PREFIX, LOCAL_FILES, FILE_SIZE_1_KB * 2);
    // Try to validate the local files, when actual file sizes do not not match to the storage unit information.
    try {
        storageFileHelper.validateDownloadedS3Files(LOCAL_TEMP_PATH.toString(), TEST_S3_KEY_PREFIX, storageUnit);
        fail("Should throw a RuntimeException when actual file sizes do not not match to the storage unit information.");
    } catch (RuntimeException e) {
        String expectedErrMsg = String.format("Size of the downloaded \"%s\" S3 file does not match the expected value (expected %d bytes, actual %d bytes).", Paths.get(LOCAL_TEMP_PATH.toString(), storageUnit.getStorageFiles().get(0).getFilePath()).toFile().getPath(), FILE_SIZE_1_KB * 2, FILE_SIZE_1_KB);
        assertEquals(expectedErrMsg, e.getMessage());
    }
}
Also used : StorageUnit(org.finra.herd.model.api.xml.StorageUnit) File(java.io.File) StorageFile(org.finra.herd.model.api.xml.StorageFile) Test(org.junit.Test) AbstractServiceTest(org.finra.herd.service.AbstractServiceTest)

Example 33 with StorageUnit

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

the class StorageFileHelperTest method testValidateStorageUnitS3FilesS3KeyPrefixMismatch.

@Test
public void testValidateStorageUnitS3FilesS3KeyPrefixMismatch() throws IOException {
    StorageUnit storageUnit = createStorageUnit("SOME_S3_KEY_PREFIX", LOCAL_FILES, FILE_SIZE_1_KB);
    // Try to validate S3 files when we have not registered S3 file.
    try {
        storageFileHelper.validateStorageUnitS3Files(storageUnit, new ArrayList<>(), TEST_S3_KEY_PREFIX);
        fail("Should throw a RuntimeException when registered S3 file does match S3 key prefix.");
    } catch (RuntimeException e) {
        String expectedErrMsg = String.format("Storage file S3 key prefix \"%s\" does not match the expected S3 key prefix \"%s\".", storageUnit.getStorageFiles().get(0).getFilePath(), TEST_S3_KEY_PREFIX);
        assertEquals(expectedErrMsg, e.getMessage());
    }
}
Also used : StorageUnit(org.finra.herd.model.api.xml.StorageUnit) Test(org.junit.Test) AbstractServiceTest(org.finra.herd.service.AbstractServiceTest)

Example 34 with StorageUnit

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

the class StorageFileHelperTest method testValidateStorageUnitS3FilesNotRegisteredS3FileFound.

@Test
public void testValidateStorageUnitS3FilesNotRegisteredS3FileFound() throws IOException {
    StorageUnit storageUnit = createStorageUnit(TEST_S3_KEY_PREFIX, new ArrayList<>(), FILE_SIZE_1_KB);
    List<String> actualS3Files = Arrays.asList(String.format("%s/%s", TEST_S3_KEY_PREFIX, LOCAL_FILES.get(0)));
    // Try to validate S3 files when we have not registered S3 file.
    try {
        storageFileHelper.validateStorageUnitS3Files(storageUnit, actualS3Files, TEST_S3_KEY_PREFIX);
        fail("Should throw a RuntimeException when S3 contains unregistered S3 file.");
    } catch (RuntimeException e) {
        String expectedErrMsg = String.format("Found S3 file \"%s\" in \"%s\" storage not registered with this business object data.", actualS3Files.get(0), storageUnit.getStorage().getName());
        assertEquals(expectedErrMsg, e.getMessage());
    }
}
Also used : StorageUnit(org.finra.herd.model.api.xml.StorageUnit) Test(org.junit.Test) AbstractServiceTest(org.finra.herd.service.AbstractServiceTest)

Example 35 with StorageUnit

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

the class StorageUnitHelperTest method testCreateStorageUnitsFromEntities.

@Test
public void testCreateStorageUnitsFromEntities() {
    // Create a business object data storage unit key.
    BusinessObjectDataStorageUnitKey businessObjectDataStorageUnitKey = new BusinessObjectDataStorageUnitKey(BDEF_NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, FORMAT_VERSION, PARTITION_VALUE, SUBPARTITION_VALUES, DATA_VERSION, STORAGE_NAME);
    Timestamp restoredExpirationOn = new Timestamp(new Date().getTime());
    // Create a storage unit entity.
    StorageUnitEntity storageUnitEntity = storageUnitDaoTestHelper.createStorageUnitEntity(businessObjectDataStorageUnitKey, STORAGE_UNIT_STATUS);
    storageUnitEntity.setDirectoryPath(STORAGE_DIRECTORY_PATH);
    storageUnitEntity.setStoragePolicyTransitionFailedAttempts(STORAGE_POLICY_TRANSITION_FAILED_ATTEMPTS);
    storageUnitEntity.setRestoreExpirationOn(restoredExpirationOn);
    // Call the method under test.
    List<StorageUnit> result = storageUnitHelper.createStorageUnitsFromEntities(Arrays.asList(storageUnitEntity), NO_INCLUDE_STORAGE_UNIT_STATUS_HISTORY);
    // Verify the external calls.
    verifyNoMoreInteractionsHelper();
    // Validate the results.
    assertEquals(Arrays.asList(new StorageUnit(new Storage(STORAGE_NAME, StoragePlatformEntity.S3, null), new StorageDirectory(STORAGE_DIRECTORY_PATH), null, STORAGE_UNIT_STATUS, NO_STORAGE_UNIT_STATUS_HISTORY, STORAGE_POLICY_TRANSITION_FAILED_ATTEMPTS, HerdDateUtils.getXMLGregorianCalendarValue(restoredExpirationOn))), result);
}
Also used : BusinessObjectDataStorageUnitKey(org.finra.herd.model.api.xml.BusinessObjectDataStorageUnitKey) Storage(org.finra.herd.model.api.xml.Storage) StorageUnitEntity(org.finra.herd.model.jpa.StorageUnitEntity) StorageUnit(org.finra.herd.model.api.xml.StorageUnit) StorageDirectory(org.finra.herd.model.api.xml.StorageDirectory) Timestamp(java.sql.Timestamp) Date(java.util.Date) AbstractServiceTest(org.finra.herd.service.AbstractServiceTest) Test(org.junit.Test)

Aggregations

StorageUnit (org.finra.herd.model.api.xml.StorageUnit)37 Test (org.junit.Test)29 BusinessObjectData (org.finra.herd.model.api.xml.BusinessObjectData)23 Storage (org.finra.herd.model.api.xml.Storage)19 AbstractServiceTest (org.finra.herd.service.AbstractServiceTest)15 StorageFile (org.finra.herd.model.api.xml.StorageFile)10 File (java.io.File)9 ArrayList (java.util.ArrayList)9 Attribute (org.finra.herd.model.api.xml.Attribute)9 StorageDirectory (org.finra.herd.model.api.xml.StorageDirectory)5 ObjectNotFoundException (org.finra.herd.model.ObjectNotFoundException)4 BusinessObjectDataInvalidateUnregisteredRequest (org.finra.herd.model.api.xml.BusinessObjectDataInvalidateUnregisteredRequest)4 BusinessObjectDataInvalidateUnregisteredResponse (org.finra.herd.model.api.xml.BusinessObjectDataInvalidateUnregisteredResponse)4 S3KeyPrefixInformation (org.finra.herd.model.api.xml.S3KeyPrefixInformation)4 DownloaderInputManifestDto (org.finra.herd.model.dto.DownloaderInputManifestDto)4 DownloaderOutputManifestDto (org.finra.herd.model.dto.DownloaderOutputManifestDto)4 BusinessObjectFormatEntity (org.finra.herd.model.jpa.BusinessObjectFormatEntity)4 StorageUnitEntity (org.finra.herd.model.jpa.StorageUnitEntity)4 Path (java.nio.file.Path)3 BusinessObjectDataCreateRequest (org.finra.herd.model.api.xml.BusinessObjectDataCreateRequest)3