use of org.finra.herd.model.api.xml.BusinessObjectData in project herd by FINRAOS.
the class BusinessObjectDataDaoTest method testBusinessObjectDataSearchWithPartitionValueFilters.
@Test
public void testBusinessObjectDataSearchWithPartitionValueFilters() {
BusinessObjectDataEntity businessObjectDataEntity = createBusinessObjectEntityForPartitionValueFilterTest();
String namespace = businessObjectDataEntity.getBusinessObjectFormat().getBusinessObjectDefinition().getNamespace().getCode();
String bDefName = businessObjectDataEntity.getBusinessObjectFormat().getBusinessObjectDefinition().getName();
String usage = businessObjectDataEntity.getBusinessObjectFormat().getUsage();
String fileTypeCode = businessObjectDataEntity.getBusinessObjectFormat().getFileType().getCode();
int formatVersion = businessObjectDataEntity.getBusinessObjectFormat().getBusinessObjectFormatVersion();
BusinessObjectDataSearchKey businessObjectDataSearchKey = new BusinessObjectDataSearchKey();
List<PartitionValueFilter> partitionValueFilters = new ArrayList<>();
PartitionValueFilter partitionValueFilter = new PartitionValueFilter();
partitionValueFilters.add(partitionValueFilter);
partitionValueFilter.setPartitionKey(PARTITION_KEY);
List<String> values = new ArrayList<>();
values.add(PARTITION_VALUE);
partitionValueFilter.setPartitionValues(values);
for (int i = 1; i < 5; i++) {
PartitionValueFilter partitionValueFilter2 = new PartitionValueFilter();
partitionValueFilters.add(partitionValueFilter2);
partitionValueFilter2.setPartitionKey(PARTITION_KEY + i);
List<String> values2 = new ArrayList<>();
// add the expected sub partition value
values2.add(SUBPARTITION_VALUES.get(i - 1));
// add some noise, it should be ignored as the query is doing in
values2.add("NOISE");
partitionValueFilter2.setPartitionValues(values2);
}
businessObjectDataSearchKey.setPartitionValueFilters(partitionValueFilters);
businessObjectDataSearchKey.setNamespace(namespace);
businessObjectDataSearchKey.setBusinessObjectDefinitionName(bDefName);
businessObjectDataSearchKey.setBusinessObjectFormatUsage(usage);
businessObjectDataSearchKey.setBusinessObjectFormatFileType(fileTypeCode);
businessObjectDataSearchKey.setBusinessObjectFormatVersion(formatVersion);
List<BusinessObjectData> result = businessObjectDataDao.searchBusinessObjectData(businessObjectDataSearchKey, DEFAULT_PAGE_NUMBER, DEFAULT_PAGE_SIZE);
assertEquals(1, result.size());
for (BusinessObjectData data : result) {
assertEquals(NAMESPACE, data.getNamespace());
assertEquals(BDEF_NAME, data.getBusinessObjectDefinitionName());
assertEquals(FORMAT_USAGE_CODE, data.getBusinessObjectFormatUsage());
assertEquals(FORMAT_FILE_TYPE_CODE, data.getBusinessObjectFormatFileType());
assertTrue(FORMAT_VERSION == data.getBusinessObjectFormatVersion());
}
}
use of org.finra.herd.model.api.xml.BusinessObjectData in project herd by FINRAOS.
the class BusinessObjectDataInvalidateUnregisteredHelperTest method testInvalidateUnregisteredBusinessObjectDataS31Herd0.
/**
* Test case where S3 has 1 object, and herd has no object registered. Expects one new registration in INVALID status.
*/
@Test
public void testInvalidateUnregisteredBusinessObjectDataS31Herd0() throws Exception {
BusinessObjectDataInvalidateUnregisteredRequest request = new BusinessObjectDataInvalidateUnregisteredRequest(NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, FORMAT_VERSION, PARTITION_VALUE, NO_SUBPARTITION_VALUES, StorageEntity.MANAGED_STORAGE);
// Given a business object format
// Given an object in S3
BusinessObjectFormatEntity businessObjectFormatEntity;
try {
businessObjectFormatEntity = businessObjectFormatServiceTestHelper.createBusinessObjectFormat(request);
businessObjectDataServiceTestHelper.createS3Object(businessObjectFormatEntity, request, 0);
} catch (Exception e) {
throw new IllegalArgumentException("Test failed during setup. Most likely setup or developer error.", e);
}
// Call API
BusinessObjectDataInvalidateUnregisteredResponse actualResponse = businessObjectDataInvalidateUnregisteredHelper.invalidateUnregisteredBusinessObjectData(request);
// Make assertions
Assert.assertNotNull("response business object datas is null", actualResponse.getRegisteredBusinessObjectDataList());
Assert.assertEquals("response business object datas size", 1, actualResponse.getRegisteredBusinessObjectDataList().size());
{
BusinessObjectData businessObjectData = actualResponse.getRegisteredBusinessObjectDataList().get(0);
Assert.assertEquals("response business object data[0] version", 0, businessObjectData.getVersion());
Assert.assertEquals("response business object data[0] status", BusinessObjectDataInvalidateUnregisteredHelper.UNREGISTERED_STATUS, businessObjectData.getStatus());
Assert.assertNotNull("response business object data[0] storage units is null", businessObjectData.getStorageUnits());
Assert.assertEquals("response business object data[0] storage units size", 1, businessObjectData.getStorageUnits().size());
{
String expectedS3KeyPrefix = s3KeyPrefixHelper.buildS3KeyPrefix(S3_KEY_PREFIX_VELOCITY_TEMPLATE, businessObjectFormatEntity, businessObjectDataHelper.createBusinessObjectDataKey(businessObjectData), STORAGE_NAME);
StorageUnit storageUnit = businessObjectData.getStorageUnits().get(0);
Assert.assertNotNull("response business object data[0] storage unit[0] storage directory is null", storageUnit.getStorageDirectory());
Assert.assertEquals("response business object data[0] storage unit[0] storage directory path", expectedS3KeyPrefix, storageUnit.getStorageDirectory().getDirectoryPath());
}
}
}
use of org.finra.herd.model.api.xml.BusinessObjectData in project herd by FINRAOS.
the class BusinessObjectDataRetryStoragePolicyTransitionHelperTest method testRetryStoragePolicyTransitionMissingOptionalParameters.
@Test
public void testRetryStoragePolicyTransitionMissingOptionalParameters() {
// Create a business object data key without sub-partition values.
BusinessObjectDataKey businessObjectDataKey = new BusinessObjectDataKey(BDEF_NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, FORMAT_VERSION, PARTITION_VALUE, NO_SUBPARTITION_VALUES, DATA_VERSION);
// Create a storage policy key.
StoragePolicyKey storagePolicyKey = new StoragePolicyKey(STORAGE_POLICY_NAMESPACE_CD, STORAGE_POLICY_NAME);
// Create database entities required for testing.
BusinessObjectDataEntity businessObjectDataEntity = businessObjectDataServiceTestHelper.createDatabaseEntitiesForRetryStoragePolicyTransitionTesting(businessObjectDataKey, storagePolicyKey);
// Retry a storage policy transition.
BusinessObjectData businessObjectData = businessObjectDataRetryStoragePolicyTransitionHelper.retryStoragePolicyTransition(businessObjectDataKey, new BusinessObjectDataRetryStoragePolicyTransitionRequest(storagePolicyKey));
// Validate the returned object.
businessObjectDataServiceTestHelper.validateBusinessObjectData(businessObjectDataEntity.getId(), businessObjectDataKey, LATEST_VERSION_FLAG_SET, BDATA_STATUS, businessObjectData);
}
use of org.finra.herd.model.api.xml.BusinessObjectData in project herd by FINRAOS.
the class BusinessObjectDataRetryStoragePolicyTransitionHelperTest method testRetryStoragePolicyTransitionTrimParameters.
@Test
public void testRetryStoragePolicyTransitionTrimParameters() {
// Create a business object data key.
BusinessObjectDataKey businessObjectDataKey = new BusinessObjectDataKey(BDEF_NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, FORMAT_VERSION, PARTITION_VALUE, SUBPARTITION_VALUES, DATA_VERSION);
// Create a storage policy key.
StoragePolicyKey storagePolicyKey = new StoragePolicyKey(STORAGE_POLICY_NAMESPACE_CD, STORAGE_POLICY_NAME);
// Create database entities required for testing.
BusinessObjectDataEntity businessObjectDataEntity = businessObjectDataServiceTestHelper.createDatabaseEntitiesForRetryStoragePolicyTransitionTesting(businessObjectDataKey, storagePolicyKey);
// Retry a storage policy transition using input parameters with leading and trailing empty spaces.
BusinessObjectData businessObjectData = businessObjectDataRetryStoragePolicyTransitionHelper.retryStoragePolicyTransition(new BusinessObjectDataKey(addWhitespace(BDEF_NAMESPACE), addWhitespace(BDEF_NAME), addWhitespace(FORMAT_USAGE_CODE), addWhitespace(FORMAT_FILE_TYPE_CODE), FORMAT_VERSION, addWhitespace(PARTITION_VALUE), addWhitespace(SUBPARTITION_VALUES), DATA_VERSION), new BusinessObjectDataRetryStoragePolicyTransitionRequest(new StoragePolicyKey(addWhitespace(STORAGE_POLICY_NAMESPACE_CD), addWhitespace(STORAGE_POLICY_NAME))));
// Validate the returned object.
businessObjectDataServiceTestHelper.validateBusinessObjectData(businessObjectDataEntity.getId(), businessObjectDataKey, LATEST_VERSION_FLAG_SET, BDATA_STATUS, businessObjectData);
}
use of org.finra.herd.model.api.xml.BusinessObjectData 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());
}
}
Aggregations