use of org.finra.herd.service.helper.BusinessObjectDataKeyComparator in project herd by FINRAOS.
the class BusinessObjectDataServiceGetBusinessObjectDataTest method testGetBusinessObjectDataUsingCreateRequest.
@Test
public void testGetBusinessObjectDataUsingCreateRequest() {
BusinessObjectDataCreateRequest request = businessObjectDataServiceTestHelper.getNewBusinessObjectDataCreateRequest();
StorageUnitCreateRequest storageUnit = request.getStorageUnits().get(0);
// Create the business object data.
businessObjectDataService.createBusinessObjectData(request);
// Retrieve the business object data.
BusinessObjectData businessObjectData = businessObjectDataService.getBusinessObjectData(new BusinessObjectDataKey(request.getNamespace(), request.getBusinessObjectDefinitionName(), request.getBusinessObjectFormatUsage(), request.getBusinessObjectFormatFileType(), request.getBusinessObjectFormatVersion(), request.getPartitionValue(), request.getSubPartitionValues(), INITIAL_DATA_VERSION), request.getPartitionKey(), NO_BDATA_STATUS, NO_INCLUDE_BUSINESS_OBJECT_DATA_STATUS_HISTORY, NO_INCLUDE_STORAGE_UNIT_STATUS_HISTORY);
// Verify the results.
assertNotNull(businessObjectData);
assertNotNull(businessObjectData.getId());
assertTrue(businessObjectData.getBusinessObjectDefinitionName().equals(request.getBusinessObjectDefinitionName()));
assertTrue(businessObjectData.getBusinessObjectFormatUsage().equals(request.getBusinessObjectFormatUsage()));
assertTrue(businessObjectData.getBusinessObjectFormatFileType().equals(request.getBusinessObjectFormatFileType()));
assertTrue(businessObjectData.getBusinessObjectFormatVersion() == request.getBusinessObjectFormatVersion());
assertTrue(businessObjectData.getPartitionValue().equals(request.getPartitionValue()));
assertTrue(businessObjectData.getSubPartitionValues().equals(request.getSubPartitionValues()));
assertTrue(businessObjectData.getVersion() == INITIAL_DATA_VERSION);
assertTrue(businessObjectData.isLatestVersion());
List<StorageUnit> storageUnits = businessObjectData.getStorageUnits();
assertTrue(storageUnits.size() == 1);
StorageUnit resultStorageUnit = storageUnits.get(0);
assertTrue(resultStorageUnit.getStorage().getName().equals(storageUnit.getStorageName()));
// Check if result storage directory path matches to the directory path from the request.
assertEquals(storageUnit.getStorageDirectory(), resultStorageUnit.getStorageDirectory());
// Check if result list of storage files matches to the list from the create request.
businessObjectDataServiceTestHelper.validateStorageFiles(resultStorageUnit.getStorageFiles(), storageUnit.getStorageFiles());
// Check if result list of attributes matches to the list from the create request.
businessObjectDefinitionServiceTestHelper.validateAttributes(request.getAttributes(), businessObjectData.getAttributes());
// Validate the parents.
assertTrue(businessObjectData.getBusinessObjectDataParents().size() == 2);
Collections.sort(request.getBusinessObjectDataParents(), new BusinessObjectDataKeyComparator());
assertEquals(request.getBusinessObjectDataParents(), businessObjectData.getBusinessObjectDataParents());
// Ensure no children exist since the entity is new.
assertTrue(businessObjectData.getBusinessObjectDataChildren().size() == 0);
// Get one of the parents.
BusinessObjectDataKey businessObjectDataParentKey = request.getBusinessObjectDataParents().get(0);
// Retrieve the business object data for the parent.
BusinessObjectData businessObjectDataParent = businessObjectDataService.getBusinessObjectData(new BusinessObjectDataKey(businessObjectDataParentKey.getNamespace(), businessObjectDataParentKey.getBusinessObjectDefinitionName(), businessObjectDataParentKey.getBusinessObjectFormatUsage(), businessObjectDataParentKey.getBusinessObjectFormatFileType(), businessObjectDataParentKey.getBusinessObjectFormatVersion(), businessObjectDataParentKey.getPartitionValue(), businessObjectDataParentKey.getSubPartitionValues(), businessObjectDataParentKey.getBusinessObjectDataVersion()), request.getPartitionKey(), NO_BDATA_STATUS, NO_INCLUDE_BUSINESS_OBJECT_DATA_STATUS_HISTORY, NO_INCLUDE_STORAGE_UNIT_STATUS_HISTORY);
// Ensure that the parent contains a single child record and that it is equal to our original business object data we created.
assertTrue(businessObjectDataParent.getBusinessObjectDataChildren().size() == 1);
assertEquals(businessObjectDataHelper.createBusinessObjectDataKey(businessObjectData), businessObjectDataParent.getBusinessObjectDataChildren().get(0));
}
Aggregations