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);
}
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());
}
}
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());
}
}
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());
}
}
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);
}
Aggregations