@Test
public void testUpdateBusinessObjectDataParents()
{

    // Create a business object data key for the first parent.
    BusinessObjectDataKey businessObjectDataParentOneKey =
        new BusinessObjectDataKey(NAMESPACE_2, BDEF_NAME_2, FORMAT_USAGE_CODE_2, FORMAT_FILE_TYPE_CODE_2, FORMAT_VERSION, PARTITION_VALUE_2,
            SUBPARTITION_VALUES_2, DATA_VERSION);
    // Create a business object data key for the second parent.
    BusinessObjectDataKey businessObjectDataParentTwoKey =
        new BusinessObjectDataKey(NAMESPACE_3, BDEF_NAME_3, FORMAT_USAGE_CODE_3, FORMAT_FILE_TYPE_CODE_3, FORMAT_VERSION, PARTITION_VALUE_3,
            SUBPARTITION_VALUES_3, DATA_VERSION);
    // Create a business object data key for the child.
    BusinessObjectDataKey businessObjectDataChildKey =
        new BusinessObjectDataKey(NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, FORMAT_VERSION, PARTITION_VALUE, SUBPARTITION_VALUES,
            DATA_VERSION);
    // Create first business object data parent.
    BusinessObjectDataEntity businessObjectDataParentOneEntity =
        businessObjectDataDaoTestHelper.createBusinessObjectDataEntity(businessObjectDataParentOneKey, LATEST_VERSION_FLAG_SET, BDATA_STATUS);
    // Create second business object data parent.
    BusinessObjectDataEntity businessObjectDataParentTwoEntity =
        businessObjectDataDaoTestHelper.createBusinessObjectDataEntity(businessObjectDataParentTwoKey, LATEST_VERSION_FLAG_SET, BDATA_STATUS);
    // Create child business object data entity having a pre-registration status.
    BusinessObjectDataEntity businessObjectDataChildEntity = businessObjectDataDaoTestHelper
        .createBusinessObjectDataEntity(businessObjectDataChildKey, LATEST_VERSION_FLAG_SET, BusinessObjectDataStatusEntity.UPLOADING);
    // Associate child and first parent business object data entities.
    businessObjectDataParentOneEntity.getBusinessObjectDataChildren().add(businessObjectDataChildEntity);
    businessObjectDataChildEntity.getBusinessObjectDataParents().add(businessObjectDataParentOneEntity);
    // Create a business object data parents update request.
    BusinessObjectDataParentsUpdateRequest businessObjectDataParentsUpdateRequest =
        new BusinessObjectDataParentsUpdateRequest(Collections.singletonList(businessObjectDataParentTwoKey));
    // Create a business object data.
    BusinessObjectData businessObjectData = new BusinessObjectData();
    businessObjectData.setId(ID);
    // Mock the external calls.
    when(businessObjectDataDaoHelper.getBusinessObjectDataEntity(businessObjectDataChildKey)).thenReturn(businessObjectDataChildEntity);
    when(businessObjectDataDaoHelper.getBusinessObjectDataEntity(businessObjectDataParentTwoKey)).thenReturn(businessObjectDataParentTwoEntity);
    when(businessObjectDataDao.saveAndRefresh(businessObjectDataChildEntity)).thenReturn(businessObjectDataChildEntity);
    when(businessObjectDataHelper.createBusinessObjectDataFromEntity(businessObjectDataChildEntity)).thenReturn(businessObjectData);
    // Call the method under test.
    BusinessObjectData result =
        businessObjectDataServiceImpl.updateBusinessObjectDataParents(businessObjectDataChildKey, businessObjectDataParentsUpdateRequest);
    // Verify the external calls.
    verify(businessObjectDataHelper).validateBusinessObjectDataKey(businessObjectDataChildKey, true, true);
    verify(businessObjectDataDaoHelper).validateBusinessObjectDataKeys(businessObjectDataParentsUpdateRequest.getBusinessObjectDataParents());
    verify(businessObjectDataDaoHelper).getBusinessObjectDataEntity(businessObjectDataChildKey);
    verify(businessObjectDataDaoHelper).getBusinessObjectDataEntity(businessObjectDataParentTwoKey);
    verify(businessObjectDataDao).saveAndRefresh(businessObjectDataChildEntity);
    verify(businessObjectDataHelper).createBusinessObjectDataFromEntity(businessObjectDataChildEntity);
    verifyNoMoreInteractionsHelper();
    // Validate the results.
    assertEquals(businessObjectData, result);
    // Validate the list of parents on the business object data entity.
    assertEquals(1, CollectionUtils.size(businessObjectDataChildEntity.getBusinessObjectDataParents()));
    assertEquals(businessObjectDataParentTwoEntity, businessObjectDataChildEntity.getBusinessObjectDataParents().get(0));
}