use of org.finra.herd.model.api.xml.BusinessObjectDataStorageUnitKey in project herd by FINRAOS.
the class CleanupDestroyedBusinessObjectDataServiceImplTest method testGetS3StorageUnitsToCleanup.
@Test
public void testGetS3StorageUnitsToCleanup() {
// Create a list of business object data keys.
List<BusinessObjectDataKey> businessObjectDataKeys = new ArrayList<>();
for (int i = 0; i < 7; i++) {
businessObjectDataKeys.add(new BusinessObjectDataKey(BDEF_NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, FORMAT_VERSION, Integer.toString(i), SUBPARTITION_VALUES, DATA_VERSION));
}
// Create database entities required for testing.
List<StorageUnitEntity> storageUnitEntities = Lists.newArrayList();
// Add 4 valid storage unit entries
storageUnitEntities.add(storageUnitDaoTestHelper.createStorageUnitEntity(STORAGE_NAME, StoragePlatformEntity.S3, businessObjectDataKeys.get(0), LATEST_VERSION_FLAG_SET, BusinessObjectDataStatusEntity.DELETED, StorageUnitStatusEntity.DISABLED, NO_STORAGE_DIRECTORY_PATH));
storageUnitEntities.add(storageUnitDaoTestHelper.createStorageUnitEntity(STORAGE_NAME, StoragePlatformEntity.S3, businessObjectDataKeys.get(1), LATEST_VERSION_FLAG_SET, BusinessObjectDataStatusEntity.DELETED, StorageUnitStatusEntity.DISABLED, NO_STORAGE_DIRECTORY_PATH));
storageUnitEntities.add(storageUnitDaoTestHelper.createStorageUnitEntity(STORAGE_NAME, StoragePlatformEntity.S3, businessObjectDataKeys.get(2), LATEST_VERSION_FLAG_SET, BusinessObjectDataStatusEntity.DELETED, StorageUnitStatusEntity.DISABLED, NO_STORAGE_DIRECTORY_PATH));
storageUnitEntities.add(storageUnitDaoTestHelper.createStorageUnitEntity(STORAGE_NAME_2, StoragePlatformEntity.S3, businessObjectDataKeys.get(3), LATEST_VERSION_FLAG_SET, BusinessObjectDataStatusEntity.DELETED, StorageUnitStatusEntity.DISABLED, NO_STORAGE_DIRECTORY_PATH));
// Not a valid business object data status
storageUnitEntities.add(storageUnitDaoTestHelper.createStorageUnitEntity(STORAGE_NAME, StoragePlatformEntity.S3, businessObjectDataKeys.get(4), LATEST_VERSION_FLAG_SET, BusinessObjectDataStatusEntity.ARCHIVED, StorageUnitStatusEntity.DISABLED, NO_STORAGE_DIRECTORY_PATH));
// Not a valid storage unit status
storageUnitEntities.add(storageUnitDaoTestHelper.createStorageUnitEntity(STORAGE_NAME, StoragePlatformEntity.S3, businessObjectDataKeys.get(5), LATEST_VERSION_FLAG_SET, BusinessObjectDataStatusEntity.DELETED, StorageUnitStatusEntity.ARCHIVED, NO_STORAGE_DIRECTORY_PATH));
// Not a valid storage platform
storageUnitEntities.add(storageUnitDaoTestHelper.createStorageUnitEntity(STORAGE_NAME_3, StoragePlatformEntity.TABLE_NAME, businessObjectDataKeys.get(6), LATEST_VERSION_FLAG_SET, BusinessObjectDataStatusEntity.DELETED, StorageUnitStatusEntity.DISABLED, NO_STORAGE_DIRECTORY_PATH));
// Set restore expiration time values.
Timestamp currentTime = new Timestamp(System.currentTimeMillis());
// Not a valid final destroy on date
storageUnitEntities.get(0).setFinalDestroyOn(null);
// Final destroy on date is not less than current timestamp
storageUnitEntities.get(1).setFinalDestroyOn(HerdDateUtils.addDays(currentTime, 1));
// Valid final destroy on dates
storageUnitEntities.get(2).setFinalDestroyOn(HerdDateUtils.addDays(currentTime, -1));
storageUnitEntities.get(3).setFinalDestroyOn(HerdDateUtils.addDays(currentTime, -2));
storageUnitEntities.get(4).setFinalDestroyOn(HerdDateUtils.addDays(currentTime, -2));
storageUnitEntities.get(5).setFinalDestroyOn(HerdDateUtils.addDays(currentTime, -2));
storageUnitEntities.get(6).setFinalDestroyOn(HerdDateUtils.addDays(currentTime, -2));
// Retrieve the business object data storage unit keys and validate the results. Only two entities are expected to match all select criteria.
List<BusinessObjectDataStorageUnitKey> result = cleanupDestroyedBusinessObjectDataService.getS3StorageUnitsToCleanup(MAX_RESULT);
BusinessObjectDataStorageUnitKey businessObjectDataStorageUnitKey3 = storageUnitHelper.createStorageUnitKeyFromEntity(storageUnitEntities.get(3));
BusinessObjectDataStorageUnitKey businessObjectDataStorageUnitKey2 = storageUnitHelper.createStorageUnitKeyFromEntity(storageUnitEntities.get(2));
assertEquals(Arrays.asList(businessObjectDataStorageUnitKey3, businessObjectDataStorageUnitKey2), result);
// Try to retrieve the business object data storage unit keys with max result limit set to 1. Only a single storage unit entity should get selected.
result = cleanupDestroyedBusinessObjectDataService.getS3StorageUnitsToCleanup(1);
assertEquals(Collections.singletonList(businessObjectDataStorageUnitKey3), result);
}
use of org.finra.herd.model.api.xml.BusinessObjectDataStorageUnitKey in project herd by FINRAOS.
the class BusinessObjectDataFinalizeRestoreServiceTest method testGetS3StorageUnitsToRestore.
@Test
public void testGetS3StorageUnitsToRestore() throws Exception {
// Create a list of business object data keys.
List<BusinessObjectDataKey> businessObjectDataKeys = Arrays.asList(new BusinessObjectDataKey(BDEF_NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, FORMAT_VERSION, PARTITION_VALUE, SUBPARTITION_VALUES, DATA_VERSION), new BusinessObjectDataKey(BDEF_NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, FORMAT_VERSION, PARTITION_VALUE_2, SUBPARTITION_VALUES, DATA_VERSION));
// Create database entities required for testing.
for (BusinessObjectDataKey businessObjectDataKey : businessObjectDataKeys) {
storageUnitDaoTestHelper.createStorageUnitEntity(STORAGE_NAME, businessObjectDataKey, StorageUnitStatusEntity.RESTORING);
}
// Select the RESTORING storage units.
List<BusinessObjectDataStorageUnitKey> resultStorageUnitKeys = businessObjectDataFinalizeRestoreService.getS3StorageUnitsToRestore(MAX_RESULT);
// Validate the results.
assertEquals(businessObjectDataKeys.size(), resultStorageUnitKeys.size());
for (BusinessObjectDataKey businessObjectDataKey : businessObjectDataKeys) {
assertTrue(resultStorageUnitKeys.contains(storageUnitHelper.createStorageUnitKey(businessObjectDataKey, STORAGE_NAME)));
}
// Try to select the RESTORING storage units with max result limit set to 1. Only one storage unit is expected to be returned.
assertEquals(1, businessObjectDataFinalizeRestoreService.getS3StorageUnitsToRestore(1).size());
}
use of org.finra.herd.model.api.xml.BusinessObjectDataStorageUnitKey in project herd by FINRAOS.
the class BusinessObjectDataServiceGetBusinessObjectDataTest method testGetBusinessObjectDataIncludeStorageUnitStatusHistory.
@Test
public void testGetBusinessObjectDataIncludeStorageUnitStatusHistory() {
// 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 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);
// Create a storage unit entity.
StorageUnitEntity storageUnitEntity = storageUnitDaoTestHelper.createStorageUnitEntity(STORAGE_NAME, businessObjectDataKey, StorageUnitStatusEntity.DISABLED);
// Execute a storage unit status change.
businessObjectDataStorageUnitStatusService.updateBusinessObjectDataStorageUnitStatus(businessObjectDataStorageUnitKey, new BusinessObjectDataStorageUnitStatusUpdateRequest(StorageUnitStatusEntity.ENABLED));
// Retrieve the business object data with enabled include storage unit status history flag.
BusinessObjectData resultBusinessObjectData = businessObjectDataService.getBusinessObjectData(businessObjectDataKey, PARTITION_KEY, NO_BDATA_STATUS, NO_INCLUDE_BUSINESS_OBJECT_DATA_STATUS_HISTORY, INCLUDE_STORAGE_UNIT_STATUS_HISTORY);
// Build the expected response object. The storage unit history record is expected to have system username for the createdBy auditable field.
BusinessObjectData expectedBusinessObjectData = new BusinessObjectData(storageUnitEntity.getBusinessObjectData().getId(), BDEF_NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, FORMAT_VERSION, PARTITION_KEY, PARTITION_VALUE, SUBPARTITION_VALUES, DATA_VERSION, LATEST_VERSION_FLAG_SET, BDATA_STATUS, Arrays.asList(new StorageUnit(new Storage(STORAGE_NAME, StoragePlatformEntity.S3, null), NO_STORAGE_DIRECTORY, null, StorageUnitStatusEntity.ENABLED, Arrays.asList(new StorageUnitStatusChangeEvent(StorageUnitStatusEntity.ENABLED, HerdDateUtils.getXMLGregorianCalendarValue(IterableUtils.get(storageUnitEntity.getHistoricalStatuses(), 0).getCreatedOn()), HerdDaoSecurityHelper.SYSTEM_USER)), NO_STORAGE_POLICY_TRANSITION_FAILED_ATTEMPTS, NO_RESTORE_EXPIRATION_ON)), NO_ATTRIBUTES, NO_BUSINESS_OBJECT_DATA_PARENTS, NO_BUSINESS_OBJECT_DATA_CHILDREN, NO_BUSINESS_OBJECT_DATA_STATUS_HISTORY);
// Validate the returned response object.
assertEquals(expectedBusinessObjectData, resultBusinessObjectData);
}
use of org.finra.herd.model.api.xml.BusinessObjectDataStorageUnitKey in project herd by FINRAOS.
the class BusinessObjectDataStorageUnitStatusRestControllerTest method testUpdateBusinessObjectDataStorageUnitStatus.
@Test
public void testUpdateBusinessObjectDataStorageUnitStatus() {
// Test for the business object data having all possible number of subpartition values (from 0 to MAX_SUBPARTITIONS).
for (int i = 0; i <= BusinessObjectDataEntity.MAX_SUBPARTITIONS; i++) {
// Build a list of subpartition values.
List<String> subPartitionValues = SUBPARTITION_VALUES.subList(0, i);
// 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, subPartitionValues, DATA_VERSION);
// 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, subPartitionValues, DATA_VERSION, STORAGE_NAME);
// Create a business object data storage unit status update request.
BusinessObjectDataStorageUnitStatusUpdateRequest request = new BusinessObjectDataStorageUnitStatusUpdateRequest(STORAGE_UNIT_STATUS_2);
// Create a business object data storage unit status update response.
BusinessObjectDataStorageUnitStatusUpdateResponse expectedResponse = new BusinessObjectDataStorageUnitStatusUpdateResponse(businessObjectDataStorageUnitKey, STORAGE_UNIT_STATUS_2, STORAGE_UNIT_STATUS);
// Mock the external calls.
when(businessObjectDataStorageUnitStatusService.updateBusinessObjectDataStorageUnitStatus(businessObjectDataStorageUnitKey, request)).thenReturn(expectedResponse);
when(storageUnitHelper.getBusinessObjectDataKey(businessObjectDataStorageUnitKey)).thenReturn(businessObjectDataKey);
// Call the method under test.
BusinessObjectDataStorageUnitStatusUpdateResponse result = null;
switch(i) {
case 0:
result = businessObjectDataStorageUnitStatusRestController.updateBusinessObjectDataStorageUnitStatus(BDEF_NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, FORMAT_VERSION, PARTITION_VALUE, DATA_VERSION, STORAGE_NAME, request);
break;
case 1:
result = businessObjectDataStorageUnitStatusRestController.updateBusinessObjectDataStorageUnitStatus(BDEF_NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, FORMAT_VERSION, PARTITION_VALUE, subPartitionValues.get(0), DATA_VERSION, STORAGE_NAME, request);
break;
case 2:
result = businessObjectDataStorageUnitStatusRestController.updateBusinessObjectDataStorageUnitStatus(BDEF_NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, FORMAT_VERSION, PARTITION_VALUE, subPartitionValues.get(0), subPartitionValues.get(1), DATA_VERSION, STORAGE_NAME, request);
break;
case 3:
result = businessObjectDataStorageUnitStatusRestController.updateBusinessObjectDataStorageUnitStatus(BDEF_NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, FORMAT_VERSION, PARTITION_VALUE, subPartitionValues.get(0), subPartitionValues.get(1), subPartitionValues.get(2), DATA_VERSION, STORAGE_NAME, request);
break;
case 4:
result = businessObjectDataStorageUnitStatusRestController.updateBusinessObjectDataStorageUnitStatus(BDEF_NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, FORMAT_VERSION, PARTITION_VALUE, subPartitionValues.get(0), subPartitionValues.get(1), subPartitionValues.get(2), subPartitionValues.get(3), DATA_VERSION, STORAGE_NAME, request);
break;
}
// Verify the external calls.
verify(businessObjectDataStorageUnitStatusService).updateBusinessObjectDataStorageUnitStatus(businessObjectDataStorageUnitKey, request);
verify(storageUnitHelper).getBusinessObjectDataKey(businessObjectDataStorageUnitKey);
verify(notificationEventService).processStorageUnitNotificationEventAsync(NotificationEventTypeEntity.EventTypesStorageUnit.STRGE_UNIT_STTS_CHG, businessObjectDataKey, STORAGE_NAME, STORAGE_UNIT_STATUS_2, STORAGE_UNIT_STATUS);
verifyNoMoreInteractions(businessObjectDataStorageUnitStatusService, notificationEventService, storageUnitHelper);
// Validate the results.
assertEquals(expectedResponse, result);
}
}
use of org.finra.herd.model.api.xml.BusinessObjectDataStorageUnitKey in project herd by FINRAOS.
the class UpdateBusinessObjectDataStorageUnitStatusTest method testUpdateBusinessObjectDataStorageUnitStatusMissingOptionalParametersSubPartitionValuesAsEmptyString.
@Test
public void testUpdateBusinessObjectDataStorageUnitStatusMissingOptionalParametersSubPartitionValuesAsEmptyString() throws Exception {
// 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, NO_SUBPARTITION_VALUES, DATA_VERSION, STORAGE_NAME);
// Create a storage unit entity.
storageUnitDaoTestHelper.createStorageUnitEntity(businessObjectDataStorageUnitKey, STORAGE_UNIT_STATUS);
// Create a storage unit status entity.
storageUnitStatusDaoTestHelper.createStorageUnitStatusEntity(STORAGE_UNIT_STATUS_2);
List<FieldExtension> fieldExtensionList = new ArrayList<>();
fieldExtensionList.add(buildFieldExtension("namespace", "${namespace}"));
fieldExtensionList.add(buildFieldExtension("businessObjectDefinitionName", "${businessObjectDefinitionName}"));
fieldExtensionList.add(buildFieldExtension("businessObjectFormatUsage", "${businessObjectFormatUsage}"));
fieldExtensionList.add(buildFieldExtension("businessObjectFormatFileType", "${businessObjectFormatFileType}"));
fieldExtensionList.add(buildFieldExtension("businessObjectFormatVersion", "${businessObjectFormatVersion}"));
fieldExtensionList.add(buildFieldExtension("partitionValue", "${partitionValue}"));
fieldExtensionList.add(buildFieldExtension("businessObjectDataVersion", "${businessObjectDataVersion}"));
fieldExtensionList.add(buildFieldExtension("storageName", "${storageName}"));
fieldExtensionList.add(buildFieldExtension("businessObjectDataStorageUnitStatus", "${businessObjectDataStorageUnitStatus}"));
List<Parameter> parameters = new ArrayList<>();
parameters.add(buildParameter("namespace", BDEF_NAMESPACE));
parameters.add(buildParameter("businessObjectDefinitionName", BDEF_NAME));
parameters.add(buildParameter("businessObjectFormatUsage", FORMAT_USAGE_CODE));
parameters.add(buildParameter("businessObjectFormatFileType", FORMAT_FILE_TYPE_CODE));
parameters.add(buildParameter("businessObjectFormatVersion", FORMAT_VERSION.toString()));
parameters.add(buildParameter("partitionValue", PARTITION_VALUE));
parameters.add(buildParameter("subPartitionValues", EMPTY_STRING));
parameters.add(buildParameter("businessObjectDataVersion", DATA_VERSION.toString()));
parameters.add(buildParameter("storageName", STORAGE_NAME));
parameters.add(buildParameter("businessObjectDataStorageUnitStatus", STORAGE_UNIT_STATUS_2));
// Build the expected response object.
BusinessObjectDataStorageUnitStatusUpdateResponse expectedResponse = new BusinessObjectDataStorageUnitStatusUpdateResponse(businessObjectDataStorageUnitKey, STORAGE_UNIT_STATUS_2, STORAGE_UNIT_STATUS);
// Run the activiti task and validate the returned response object.
Map<String, Object> variableValuesToValidate = new HashMap<>();
variableValuesToValidate.put(UpdateBusinessObjectDataStorageUnitStatus.VARIABLE_JSON_RESPONSE, jsonHelper.objectToJson(expectedResponse));
testActivitiServiceTaskSuccess(UpdateBusinessObjectDataStorageUnitStatus.class.getCanonicalName(), fieldExtensionList, parameters, variableValuesToValidate);
}
Aggregations