Search in sources :

Example 16 with BusinessObjectDataEntity

use of org.finra.herd.model.jpa.BusinessObjectDataEntity in project herd by FINRAOS.

the class UploadDownloadHelperServiceImplTest method testPrepareForFileMoveImplOptimisticLockException.

@Test
public void testPrepareForFileMoveImplOptimisticLockException() {
    // Create an object key.
    String objectKey = UUID_VALUE;
    // Create a complete upload single parameters DTO.
    CompleteUploadSingleParamsDto completeUploadSingleParamsDto = new CompleteUploadSingleParamsDto();
    // Create a business object data status entity.
    BusinessObjectDataStatusEntity businessObjectDataStatusEntity = new BusinessObjectDataStatusEntity();
    businessObjectDataStatusEntity.setCode(BusinessObjectDataStatusEntity.UPLOADING);
    // Create a source storage entity.
    StorageEntity sourceStorageEntity = new StorageEntity();
    // Create a source business object data key.
    BusinessObjectDataKey sourceBusinessObjectDataKey = new BusinessObjectDataKey();
    sourceBusinessObjectDataKey.setBusinessObjectFormatUsage(FORMAT_USAGE_CODE);
    // Create a source business object data entity.
    BusinessObjectDataEntity sourceBusinessObjectDataEntity = new BusinessObjectDataEntity();
    sourceBusinessObjectDataEntity.setId(ID);
    sourceBusinessObjectDataEntity.setPartitionValue(objectKey);
    sourceBusinessObjectDataEntity.setStatus(businessObjectDataStatusEntity);
    // Create a list of source storage files.
    List<StorageFileEntity> sourceStorageFileEntities = new ArrayList<>();
    // Create a source storage unit.
    StorageUnitEntity sourceStorageUnitEntity = new StorageUnitEntity();
    sourceStorageUnitEntity.setBusinessObjectData(sourceBusinessObjectDataEntity);
    sourceStorageUnitEntity.setStorage(sourceStorageEntity);
    sourceStorageUnitEntity.setStorageFiles(sourceStorageFileEntities);
    // Create a source storage file entity.
    StorageFileEntity sourceStorageFileEntity = new StorageFileEntity();
    sourceStorageFileEntities.add(sourceStorageFileEntity);
    sourceStorageFileEntity.setStorageUnit(sourceStorageUnitEntity);
    sourceStorageFileEntity.setPath(S3_KEY);
    sourceStorageFileEntity.setFileSizeBytes(FILE_SIZE);
    // Create a target storage entity.
    StorageEntity targetStorageEntity = new StorageEntity();
    // Create a target business object data key.
    BusinessObjectDataKey targetBusinessObjectDataKey = new BusinessObjectDataKey();
    targetBusinessObjectDataKey.setBusinessObjectFormatUsage(FORMAT_USAGE_CODE_2);
    // Create a list of source storage files.
    List<StorageFileEntity> targetStorageFileEntities = new ArrayList<>();
    // Create a target storage unit.
    StorageUnitEntity targetStorageUnitEntity = new StorageUnitEntity();
    targetStorageUnitEntity.setStorage(targetStorageEntity);
    targetStorageUnitEntity.setStorageFiles(targetStorageFileEntities);
    // Create a source storage file entity.
    StorageFileEntity targetStorageFileEntity = new StorageFileEntity();
    targetStorageFileEntities.add(targetStorageFileEntity);
    targetStorageFileEntity.setPath(S3_KEY_2);
    // Create a target business object data entity.
    BusinessObjectDataEntity targetBusinessObjectDataEntity = new BusinessObjectDataEntity();
    targetBusinessObjectDataEntity.setId(ID_2);
    targetBusinessObjectDataEntity.setStatus(businessObjectDataStatusEntity);
    targetBusinessObjectDataEntity.setStorageUnits(Collections.singletonList(targetStorageUnitEntity));
    // Create an AWS parameters DTO.
    AwsParamsDto awsParamsDto = new AwsParamsDto(NO_AWS_ACCESS_KEY, NO_AWS_SECRET_KEY, NO_SESSION_TOKEN, HTTP_PROXY_HOST, HTTP_PROXY_PORT);
    // Mock the external calls.
    when(storageFileDaoHelper.getStorageFileEntity(StorageEntity.MANAGED_LOADING_DOCK_STORAGE, objectKey)).thenReturn(sourceStorageFileEntity);
    when(businessObjectDataHelper.getBusinessObjectDataKey(sourceBusinessObjectDataEntity)).thenReturn(sourceBusinessObjectDataKey);
    when(businessObjectDataDao.getBusinessObjectDataEntitiesByPartitionValue(objectKey)).thenReturn(Arrays.asList(sourceBusinessObjectDataEntity, targetBusinessObjectDataEntity));
    when(businessObjectDataHelper.getBusinessObjectDataKey(targetBusinessObjectDataEntity)).thenReturn(targetBusinessObjectDataKey);
    when(storageDaoHelper.getStorageEntity(StorageEntity.MANAGED_LOADING_DOCK_STORAGE)).thenReturn(sourceStorageEntity);
    when(storageHelper.getStorageBucketName(sourceStorageEntity)).thenReturn(S3_BUCKET_NAME);
    when(storageUnitDaoHelper.getStorageUnitEntity(StorageEntity.MANAGED_LOADING_DOCK_STORAGE, sourceBusinessObjectDataEntity)).thenReturn(sourceStorageUnitEntity);
    when(awsHelper.getAwsParamsDto()).thenReturn(awsParamsDto);
    when(storageHelper.getStorageBucketName(targetStorageEntity)).thenReturn(S3_BUCKET_NAME_2);
    when(storageHelper.getStorageKmsKeyId(targetStorageEntity)).thenReturn(AWS_KMS_KEY_ID);
    doThrow(new OptimisticLockException(ERROR_MESSAGE)).when(businessObjectDataDaoHelper).updateBusinessObjectDataStatus(sourceBusinessObjectDataEntity, BusinessObjectDataStatusEntity.RE_ENCRYPTING);
    when(jsonHelper.objectToJson(sourceBusinessObjectDataKey)).thenReturn(BUSINESS_OBJECT_DATA_KEY_AS_STRING);
    when(jsonHelper.objectToJson(targetBusinessObjectDataKey)).thenReturn(BUSINESS_OBJECT_DATA_KEY_AS_STRING_2);
    // Try to call the method under test.
    try {
        uploadDownloadHelperService.prepareForFileMoveImpl(objectKey, completeUploadSingleParamsDto);
    } catch (OptimisticLockException e) {
        assertEquals(String.format("Ignoring S3 notification due to an optimistic lock exception caused by duplicate S3 event notifications. " + "sourceBusinessObjectDataKey=%s targetBusinessObjectDataKey=%s", BUSINESS_OBJECT_DATA_KEY_AS_STRING, BUSINESS_OBJECT_DATA_KEY_AS_STRING_2), e.getMessage());
    }
    // Verify the external calls.
    verify(storageFileDaoHelper).getStorageFileEntity(StorageEntity.MANAGED_LOADING_DOCK_STORAGE, objectKey);
    verify(storageFileDaoHelper).getStorageFileEntity(StorageEntity.MANAGED_LOADING_DOCK_STORAGE, objectKey);
    verify(businessObjectDataHelper).getBusinessObjectDataKey(sourceBusinessObjectDataEntity);
    verify(businessObjectDataDao).getBusinessObjectDataEntitiesByPartitionValue(objectKey);
    verify(businessObjectDataHelper).getBusinessObjectDataKey(targetBusinessObjectDataEntity);
    verify(storageDaoHelper).getStorageEntity(StorageEntity.MANAGED_LOADING_DOCK_STORAGE);
    verify(storageHelper).getStorageBucketName(sourceStorageEntity);
    verify(storageUnitDaoHelper).getStorageUnitEntity(StorageEntity.MANAGED_LOADING_DOCK_STORAGE, sourceBusinessObjectDataEntity);
    verify(awsHelper, times(2)).getAwsParamsDto();
    verify(s3Dao).validateS3File(any(S3FileTransferRequestParamsDto.class), eq(FILE_SIZE));
    verify(storageHelper).getStorageBucketName(targetStorageEntity);
    verify(storageHelper).getStorageKmsKeyId(targetStorageEntity);
    verify(s3Dao).s3FileExists(any(S3FileTransferRequestParamsDto.class));
    verify(businessObjectDataDaoHelper).updateBusinessObjectDataStatus(sourceBusinessObjectDataEntity, BusinessObjectDataStatusEntity.RE_ENCRYPTING);
    verify(jsonHelper).objectToJson(sourceBusinessObjectDataKey);
    verify(jsonHelper).objectToJson(targetBusinessObjectDataKey);
    verifyNoMoreInteractionsHelper();
    // Validate the results.
    assertEquals(new CompleteUploadSingleParamsDto(sourceBusinessObjectDataKey, S3_BUCKET_NAME, S3_KEY, BusinessObjectDataStatusEntity.UPLOADING, NO_BDATA_STATUS, targetBusinessObjectDataKey, S3_BUCKET_NAME_2, S3_KEY_2, BusinessObjectDataStatusEntity.UPLOADING, NO_BDATA_STATUS, AWS_KMS_KEY_ID, awsParamsDto), completeUploadSingleParamsDto);
}
Also used : AwsParamsDto(org.finra.herd.model.dto.AwsParamsDto) S3FileTransferRequestParamsDto(org.finra.herd.model.dto.S3FileTransferRequestParamsDto) StorageUnitEntity(org.finra.herd.model.jpa.StorageUnitEntity) BusinessObjectDataStatusEntity(org.finra.herd.model.jpa.BusinessObjectDataStatusEntity) ArrayList(java.util.ArrayList) StorageEntity(org.finra.herd.model.jpa.StorageEntity) OptimisticLockException(javax.persistence.OptimisticLockException) CompleteUploadSingleParamsDto(org.finra.herd.model.dto.CompleteUploadSingleParamsDto) BusinessObjectDataKey(org.finra.herd.model.api.xml.BusinessObjectDataKey) StorageFileEntity(org.finra.herd.model.jpa.StorageFileEntity) BusinessObjectDataEntity(org.finra.herd.model.jpa.BusinessObjectDataEntity) AbstractServiceTest(org.finra.herd.service.AbstractServiceTest) Test(org.junit.Test)

Example 17 with BusinessObjectDataEntity

use of org.finra.herd.model.jpa.BusinessObjectDataEntity in project herd by FINRAOS.

the class ExpireRestoredBusinessObjectDataHelperServiceImplTest method testCompleteStorageUnitExpiration.

@Test
public void testCompleteStorageUnitExpiration() {
    // 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 DTO for business object data restore parameters.
    BusinessObjectDataRestoreDto businessObjectDataRestoreDto = new BusinessObjectDataRestoreDto(businessObjectDataKey, STORAGE_NAME, S3_ENDPOINT, S3_BUCKET_NAME, S3_KEY_PREFIX, NO_STORAGE_UNIT_STATUS, NO_STORAGE_UNIT_STATUS, Arrays.asList(new StorageFile(S3_KEY, FILE_SIZE, ROW_COUNT)), NO_EXCEPTION);
    // Create a business object data entity.
    BusinessObjectDataEntity businessObjectDataEntity = new BusinessObjectDataEntity();
    // Create a new storage unit status entity.
    StorageUnitStatusEntity newStorageUnitStatusEntity = new StorageUnitStatusEntity();
    newStorageUnitStatusEntity.setCode(StorageUnitStatusEntity.ARCHIVED);
    // Create an old storage unit status entity.
    StorageUnitStatusEntity oldStorageUnitStatusEntity = new StorageUnitStatusEntity();
    oldStorageUnitStatusEntity.setCode(StorageUnitStatusEntity.EXPIRING);
    // Create a storage unit entity.
    StorageUnitEntity storageUnitEntity = new StorageUnitEntity();
    storageUnitEntity.setStatus(oldStorageUnitStatusEntity);
    // Mock the external calls.
    when(businessObjectDataDaoHelper.getBusinessObjectDataEntity(businessObjectDataKey)).thenReturn(businessObjectDataEntity);
    when(storageUnitDaoHelper.getStorageUnitEntity(STORAGE_NAME, businessObjectDataEntity)).thenReturn(storageUnitEntity);
    doAnswer(new Answer<Void>() {

        public Void answer(InvocationOnMock invocation) {
            // Get the storage unit entity.
            StorageUnitEntity storageUnitEntity = (StorageUnitEntity) invocation.getArguments()[0];
            // Update the storage unit status.
            storageUnitEntity.setStatus(newStorageUnitStatusEntity);
            return null;
        }
    }).when(storageUnitDaoHelper).updateStorageUnitStatus(storageUnitEntity, StorageUnitStatusEntity.ARCHIVED, StorageUnitStatusEntity.ARCHIVED);
    // Call the method under test.
    expireRestoredBusinessObjectDataHelperServiceImpl.completeStorageUnitExpiration(businessObjectDataRestoreDto);
    // Verify the external calls.
    verify(businessObjectDataDaoHelper).getBusinessObjectDataEntity(businessObjectDataKey);
    verify(storageUnitDaoHelper).getStorageUnitEntity(STORAGE_NAME, businessObjectDataEntity);
    verify(storageUnitDaoHelper).updateStorageUnitStatus(storageUnitEntity, StorageUnitStatusEntity.ARCHIVED, StorageUnitStatusEntity.ARCHIVED);
    verifyNoMoreInteractionsHelper();
    // Validate the results.
    assertEquals(StorageUnitStatusEntity.ARCHIVED, businessObjectDataRestoreDto.getNewStorageUnitStatus());
    assertEquals(StorageUnitStatusEntity.EXPIRING, businessObjectDataRestoreDto.getOldStorageUnitStatus());
}
Also used : StorageUnitEntity(org.finra.herd.model.jpa.StorageUnitEntity) InvocationOnMock(org.mockito.invocation.InvocationOnMock) StorageFile(org.finra.herd.model.api.xml.StorageFile) StorageUnitStatusEntity(org.finra.herd.model.jpa.StorageUnitStatusEntity) BusinessObjectDataEntity(org.finra.herd.model.jpa.BusinessObjectDataEntity) BusinessObjectDataKey(org.finra.herd.model.api.xml.BusinessObjectDataKey) BusinessObjectDataRestoreDto(org.finra.herd.model.dto.BusinessObjectDataRestoreDto) AbstractServiceTest(org.finra.herd.service.AbstractServiceTest) Test(org.junit.Test)

Example 18 with BusinessObjectDataEntity

use of org.finra.herd.model.jpa.BusinessObjectDataEntity in project herd by FINRAOS.

the class ExpireRestoredBusinessObjectDataHelperServiceImplTest method testPrepareToExpireStorageUnit.

@Test
public void testPrepareToExpireStorageUnit() {
    // 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 unit key.
    BusinessObjectDataStorageUnitKey storageUnitKey = 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 entity.
    StorageEntity storageEntity = new StorageEntity();
    storageEntity.setName(STORAGE_NAME);
    // Create a business object format entity.
    BusinessObjectFormatEntity businessObjectFormatEntity = new BusinessObjectFormatEntity();
    // Create a business object data entity.
    BusinessObjectDataEntity businessObjectDataEntity = new BusinessObjectDataEntity();
    businessObjectDataEntity.setBusinessObjectFormat(businessObjectFormatEntity);
    // Create a new storage unit status entity.
    StorageUnitStatusEntity newStorageUnitStatusEntity = new StorageUnitStatusEntity();
    newStorageUnitStatusEntity.setCode(StorageUnitStatusEntity.EXPIRING);
    // Create an old storage unit status entity.
    StorageUnitStatusEntity oldStorageUnitStatusEntity = new StorageUnitStatusEntity();
    oldStorageUnitStatusEntity.setCode(StorageUnitStatusEntity.RESTORED);
    // Create a list of storage file entities.
    List<StorageFileEntity> storageFileEntities = Arrays.asList(new StorageFileEntity());
    // Create a storage unit entity.
    StorageUnitEntity storageUnitEntity = new StorageUnitEntity();
    storageUnitEntity.setStorage(storageEntity);
    storageUnitEntity.setBusinessObjectData(businessObjectDataEntity);
    storageUnitEntity.setStatus(oldStorageUnitStatusEntity);
    storageUnitEntity.setStorageFiles(storageFileEntities);
    // Create a list of storage files.
    List<StorageFile> storageFiles = Arrays.asList(new StorageFile(S3_KEY, FILE_SIZE, ROW_COUNT));
    // Mock the external calls.
    when(businessObjectDataHelper.createBusinessObjectDataKeyFromStorageUnitKey(storageUnitKey)).thenReturn(businessObjectDataKey);
    when(businessObjectDataDaoHelper.getBusinessObjectDataEntity(businessObjectDataKey)).thenReturn(businessObjectDataEntity);
    when(storageUnitDaoHelper.getStorageUnitEntity(STORAGE_NAME, businessObjectDataEntity)).thenReturn(storageUnitEntity);
    when(configurationHelper.getProperty(ConfigurationValue.S3_ATTRIBUTE_NAME_BUCKET_NAME)).thenReturn(S3_ATTRIBUTE_NAME_BUCKET_NAME);
    when(storageHelper.getStorageAttributeValueByName(S3_ATTRIBUTE_NAME_BUCKET_NAME, storageEntity, true)).thenReturn(S3_BUCKET_NAME);
    when(s3KeyPrefixHelper.buildS3KeyPrefix(storageEntity, businessObjectFormatEntity, businessObjectDataKey)).thenReturn(S3_KEY_PREFIX);
    when(storageFileHelper.getAndValidateStorageFiles(storageUnitEntity, S3_KEY_PREFIX, STORAGE_NAME, businessObjectDataKey)).thenReturn(storageFiles);
    doAnswer(new Answer<Void>() {

        public Void answer(InvocationOnMock invocation) {
            // Get the storage unit entity.
            StorageUnitEntity storageUnitEntity = (StorageUnitEntity) invocation.getArguments()[0];
            // Update the storage unit status.
            storageUnitEntity.setStatus(newStorageUnitStatusEntity);
            return null;
        }
    }).when(storageUnitDaoHelper).updateStorageUnitStatus(storageUnitEntity, StorageUnitStatusEntity.EXPIRING, StorageUnitStatusEntity.EXPIRING);
    when(configurationHelper.getProperty(ConfigurationValue.S3_ENDPOINT)).thenReturn(S3_ENDPOINT);
    // Call the method under test.
    BusinessObjectDataRestoreDto result = expireRestoredBusinessObjectDataHelperServiceImpl.prepareToExpireStorageUnit(storageUnitKey);
    // Verify the external calls.
    verify(businessObjectDataHelper).createBusinessObjectDataKeyFromStorageUnitKey(storageUnitKey);
    verify(businessObjectDataDaoHelper).getBusinessObjectDataEntity(businessObjectDataKey);
    verify(storageUnitDaoHelper).getStorageUnitEntity(STORAGE_NAME, businessObjectDataEntity);
    verify(configurationHelper).getProperty(ConfigurationValue.S3_ATTRIBUTE_NAME_BUCKET_NAME);
    verify(storageHelper).getStorageAttributeValueByName(S3_ATTRIBUTE_NAME_BUCKET_NAME, storageEntity, true);
    verify(s3KeyPrefixHelper).buildS3KeyPrefix(storageEntity, businessObjectFormatEntity, businessObjectDataKey);
    verify(storageFileHelper).getAndValidateStorageFiles(storageUnitEntity, S3_KEY_PREFIX, STORAGE_NAME, businessObjectDataKey);
    verify(storageFileDaoHelper).validateStorageFilesCount(STORAGE_NAME, businessObjectDataKey, S3_KEY_PREFIX, storageFiles.size());
    verify(storageUnitDaoHelper).updateStorageUnitStatus(storageUnitEntity, StorageUnitStatusEntity.EXPIRING, StorageUnitStatusEntity.EXPIRING);
    verify(configurationHelper).getProperty(ConfigurationValue.S3_ENDPOINT);
    verifyNoMoreInteractionsHelper();
    // Validate the result.
    assertEquals(new BusinessObjectDataRestoreDto(businessObjectDataKey, STORAGE_NAME, S3_ENDPOINT, S3_BUCKET_NAME, S3_KEY_PREFIX, StorageUnitStatusEntity.EXPIRING, StorageUnitStatusEntity.RESTORED, storageFiles, NO_EXCEPTION), result);
}
Also used : StorageUnitEntity(org.finra.herd.model.jpa.StorageUnitEntity) StorageEntity(org.finra.herd.model.jpa.StorageEntity) BusinessObjectDataKey(org.finra.herd.model.api.xml.BusinessObjectDataKey) BusinessObjectFormatEntity(org.finra.herd.model.jpa.BusinessObjectFormatEntity) BusinessObjectDataStorageUnitKey(org.finra.herd.model.api.xml.BusinessObjectDataStorageUnitKey) StorageFileEntity(org.finra.herd.model.jpa.StorageFileEntity) InvocationOnMock(org.mockito.invocation.InvocationOnMock) StorageUnitStatusEntity(org.finra.herd.model.jpa.StorageUnitStatusEntity) StorageFile(org.finra.herd.model.api.xml.StorageFile) BusinessObjectDataEntity(org.finra.herd.model.jpa.BusinessObjectDataEntity) BusinessObjectDataRestoreDto(org.finra.herd.model.dto.BusinessObjectDataRestoreDto) AbstractServiceTest(org.finra.herd.service.AbstractServiceTest) Test(org.junit.Test)

Example 19 with BusinessObjectDataEntity

use of org.finra.herd.model.jpa.BusinessObjectDataEntity in project herd by FINRAOS.

the class StoragePolicySelectorServiceImplTest method testCompleteStoragePolicyTransitionImpl.

@Test
public void testCompleteStoragePolicyTransitionImpl() {
    // Create a current timestamp.
    Timestamp currentTimestamp = new Timestamp(LONG_VALUE);
    // Set a number of maximum results.
    Integer maxResults = 10;
    // Create configuration values required for testing.
    Integer updatedOnThresholdInDays = 90;
    Integer storagePolicyTransitionMaxAllowedAttempts = 3;
    // Create an empty mapping of matched business object data entities.
    Map<BusinessObjectDataEntity, StoragePolicyEntity> noMatchingBusinessObjectDataEntities = new HashMap<>();
    // Create an empty list of storage policy selections.
    List<StoragePolicySelection> storagePolicySelections = new ArrayList<>();
    // Mock the external calls.
    when(herdDao.getCurrentTimestamp()).thenReturn(currentTimestamp);
    when(herdStringHelper.getConfigurationValueAsInteger(ConfigurationValue.STORAGE_POLICY_PROCESSOR_BDATA_UPDATED_ON_THRESHOLD_DAYS)).thenReturn(updatedOnThresholdInDays);
    when(businessObjectDataDao.getBusinessObjectDataEntitiesMatchingStoragePolicies(StoragePolicySelectorServiceImpl.STORAGE_POLICY_PRIORITY_LEVELS.get(0), StoragePolicySelectorServiceImpl.SUPPORTED_BUSINESS_OBJECT_DATA_STATUSES, storagePolicyTransitionMaxAllowedAttempts, 0, maxResults)).thenReturn(noMatchingBusinessObjectDataEntities);
    when(businessObjectDataDao.getBusinessObjectDataEntitiesMatchingStoragePolicies(StoragePolicySelectorServiceImpl.STORAGE_POLICY_PRIORITY_LEVELS.get(1), StoragePolicySelectorServiceImpl.SUPPORTED_BUSINESS_OBJECT_DATA_STATUSES, storagePolicyTransitionMaxAllowedAttempts, 0, maxResults)).thenReturn(noMatchingBusinessObjectDataEntities);
    when(businessObjectDataDao.getBusinessObjectDataEntitiesMatchingStoragePolicies(StoragePolicySelectorServiceImpl.STORAGE_POLICY_PRIORITY_LEVELS.get(2), StoragePolicySelectorServiceImpl.SUPPORTED_BUSINESS_OBJECT_DATA_STATUSES, storagePolicyTransitionMaxAllowedAttempts, 0, maxResults)).thenReturn(noMatchingBusinessObjectDataEntities);
    when(businessObjectDataDao.getBusinessObjectDataEntitiesMatchingStoragePolicies(StoragePolicySelectorServiceImpl.STORAGE_POLICY_PRIORITY_LEVELS.get(3), StoragePolicySelectorServiceImpl.SUPPORTED_BUSINESS_OBJECT_DATA_STATUSES, storagePolicyTransitionMaxAllowedAttempts, 0, maxResults)).thenReturn(noMatchingBusinessObjectDataEntities);
    when(herdStringHelper.getConfigurationValueAsInteger(ConfigurationValue.STORAGE_POLICY_TRANSITION_MAX_ALLOWED_ATTEMPTS)).thenReturn(storagePolicyTransitionMaxAllowedAttempts);
    // Call the method under test.
    List<StoragePolicySelection> result = storagePolicySelectorServiceImpl.execute(AWS_SQS_QUEUE_NAME, maxResults);
    // Verify the external calls.
    verify(herdDao).getCurrentTimestamp();
    verify(herdStringHelper).getConfigurationValueAsInteger(ConfigurationValue.STORAGE_POLICY_PROCESSOR_BDATA_UPDATED_ON_THRESHOLD_DAYS);
    verify(herdStringHelper).getConfigurationValueAsInteger(ConfigurationValue.STORAGE_POLICY_TRANSITION_MAX_ALLOWED_ATTEMPTS);
    verify(businessObjectDataDao).getBusinessObjectDataEntitiesMatchingStoragePolicies(StoragePolicySelectorServiceImpl.STORAGE_POLICY_PRIORITY_LEVELS.get(0), StoragePolicySelectorServiceImpl.SUPPORTED_BUSINESS_OBJECT_DATA_STATUSES, storagePolicyTransitionMaxAllowedAttempts, 0, maxResults);
    verify(businessObjectDataDao).getBusinessObjectDataEntitiesMatchingStoragePolicies(StoragePolicySelectorServiceImpl.STORAGE_POLICY_PRIORITY_LEVELS.get(1), StoragePolicySelectorServiceImpl.SUPPORTED_BUSINESS_OBJECT_DATA_STATUSES, storagePolicyTransitionMaxAllowedAttempts, 0, maxResults);
    verify(businessObjectDataDao).getBusinessObjectDataEntitiesMatchingStoragePolicies(StoragePolicySelectorServiceImpl.STORAGE_POLICY_PRIORITY_LEVELS.get(2), StoragePolicySelectorServiceImpl.SUPPORTED_BUSINESS_OBJECT_DATA_STATUSES, storagePolicyTransitionMaxAllowedAttempts, 0, maxResults);
    verify(businessObjectDataDao).getBusinessObjectDataEntitiesMatchingStoragePolicies(StoragePolicySelectorServiceImpl.STORAGE_POLICY_PRIORITY_LEVELS.get(3), StoragePolicySelectorServiceImpl.SUPPORTED_BUSINESS_OBJECT_DATA_STATUSES, storagePolicyTransitionMaxAllowedAttempts, 0, maxResults);
    verifyNoMoreInteractionsHelper();
    // Validate the results.
    assertEquals(storagePolicySelections, result);
}
Also used : HashMap(java.util.HashMap) StoragePolicyEntity(org.finra.herd.model.jpa.StoragePolicyEntity) ArrayList(java.util.ArrayList) BusinessObjectDataEntity(org.finra.herd.model.jpa.BusinessObjectDataEntity) StoragePolicySelection(org.finra.herd.model.dto.StoragePolicySelection) Timestamp(java.sql.Timestamp) AbstractServiceTest(org.finra.herd.service.AbstractServiceTest) Test(org.junit.Test)

Example 20 with BusinessObjectDataEntity

use of org.finra.herd.model.jpa.BusinessObjectDataEntity in project herd by FINRAOS.

the class BaseJpaDaoImplTest method testGetPredicateForInClauseOneChunk.

@Test
public void testGetPredicateForInClauseOneChunk() {
    // Create the JPA builder, query, and entity root.
    CriteriaBuilder builder = entityManager.getCriteriaBuilder();
    CriteriaQuery<BusinessObjectDataEntity> criteria = builder.createQuery(BusinessObjectDataEntity.class);
    Root<BusinessObjectDataEntity> businessObjectDataEntity = criteria.from(BusinessObjectDataEntity.class);
    // Get the predicate for the "in" clause with 1000 values.
    Predicate predicate = baseJpaDaoImpl.getPredicateForInClause(builder, businessObjectDataEntity.get(BusinessObjectDataEntity_.partitionValue), getPartitionValueList(1000));
    // We expect to get back an "in" predicate with a single chunk of 1000 partition values.
    assertTrue(predicate instanceof InPredicate);
    assertEquals(1000, ((InPredicate) predicate).getValues().size());
}
Also used : CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) BusinessObjectDataEntity(org.finra.herd.model.jpa.BusinessObjectDataEntity) InPredicate(org.hibernate.query.criteria.internal.predicate.InPredicate) InPredicate(org.hibernate.query.criteria.internal.predicate.InPredicate) Predicate(javax.persistence.criteria.Predicate) Test(org.junit.Test) AbstractDaoTest(org.finra.herd.dao.AbstractDaoTest)

Aggregations

BusinessObjectDataEntity (org.finra.herd.model.jpa.BusinessObjectDataEntity)278 Test (org.junit.Test)184 BusinessObjectDataKey (org.finra.herd.model.api.xml.BusinessObjectDataKey)138 StorageUnitEntity (org.finra.herd.model.jpa.StorageUnitEntity)105 ArrayList (java.util.ArrayList)70 StorageEntity (org.finra.herd.model.jpa.StorageEntity)67 AbstractServiceTest (org.finra.herd.service.AbstractServiceTest)63 BusinessObjectData (org.finra.herd.model.api.xml.BusinessObjectData)57 BusinessObjectFormatEntity (org.finra.herd.model.jpa.BusinessObjectFormatEntity)54 StorageUnitStatusEntity (org.finra.herd.model.jpa.StorageUnitStatusEntity)31 Attribute (org.finra.herd.model.api.xml.Attribute)28 NotificationMessageDefinition (org.finra.herd.model.api.xml.NotificationMessageDefinition)27 NotificationMessageDefinitions (org.finra.herd.model.api.xml.NotificationMessageDefinitions)27 ConfigurationEntity (org.finra.herd.model.jpa.ConfigurationEntity)27 BusinessObjectDataStatusEntity (org.finra.herd.model.jpa.BusinessObjectDataStatusEntity)25 Predicate (javax.persistence.criteria.Predicate)24 NotificationMessage (org.finra.herd.model.dto.NotificationMessage)24 BusinessObjectDataAttributeEntity (org.finra.herd.model.jpa.BusinessObjectDataAttributeEntity)23 StoragePolicyKey (org.finra.herd.model.api.xml.StoragePolicyKey)21 CriteriaBuilder (javax.persistence.criteria.CriteriaBuilder)19