use of org.finra.herd.model.jpa.RetentionTypeEntity in project herd by FINRAOS.
the class BusinessObjectDataInitiateDestroyHelperServiceImplTest method testValidateBusinessObjectDataInvalidPrimaryPartitionValue.
@Test
public void testValidateBusinessObjectDataInvalidPrimaryPartitionValue() {
// Create a version-less business object format key.
BusinessObjectFormatKey businessObjectFormatKey = new BusinessObjectFormatKey(BDEF_NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, NO_FORMAT_VERSION);
// 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, NO_SUBPARTITION_VALUES, DATA_VERSION);
// Create a retention type entity.
RetentionTypeEntity retentionTypeEntity = new RetentionTypeEntity();
retentionTypeEntity.setCode(RetentionTypeEntity.PARTITION_VALUE);
// Create a business object format entity.
BusinessObjectFormatEntity businessObjectFormatEntity = new BusinessObjectFormatEntity();
businessObjectFormatEntity.setLatestVersion(true);
businessObjectFormatEntity.setRetentionType(retentionTypeEntity);
businessObjectFormatEntity.setRetentionPeriodInDays(RETENTION_PERIOD_DAYS);
// Create a business object data entity.
BusinessObjectDataEntity businessObjectDataEntity = new BusinessObjectDataEntity();
businessObjectDataEntity.setBusinessObjectFormat(businessObjectFormatEntity);
businessObjectDataEntity.setPartitionValue(PARTITION_VALUE);
// Mock the external calls.
when(businessObjectDataHelper.getDateFromString(PARTITION_VALUE)).thenReturn(null);
when(businessObjectDataHelper.businessObjectDataKeyToString(businessObjectDataKey)).thenReturn(BUSINESS_OBJECT_DATA_KEY_AS_STRING);
// Try to call the method under test.
try {
businessObjectDataInitiateDestroyHelperServiceImpl.validateBusinessObjectData(businessObjectDataEntity, businessObjectDataKey);
fail();
} catch (IllegalArgumentException e) {
assertEquals(String.format("Primary partition value \"%s\" cannot get converted to a valid date. Business object data: {%s}", PARTITION_VALUE, BUSINESS_OBJECT_DATA_KEY_AS_STRING), e.getMessage());
}
// Verify the external calls.
verify(businessObjectDataHelper).getDateFromString(PARTITION_VALUE);
verify(businessObjectDataHelper).businessObjectDataKeyToString(businessObjectDataKey);
verifyNoMoreInteractionsHelper();
}
use of org.finra.herd.model.jpa.RetentionTypeEntity in project herd by FINRAOS.
the class RetentionTypeDaoTestHelper method createRetentionTypeEntity.
/**
* Create the retention type entity
* @param code retention type
* @return retention type entity
*/
public RetentionTypeEntity createRetentionTypeEntity(String code) {
RetentionTypeEntity retentionTypeEntity = new RetentionTypeEntity();
retentionTypeEntity.setCode(code);
return retentionTypeDao.saveAndRefresh(retentionTypeEntity);
}
use of org.finra.herd.model.jpa.RetentionTypeEntity in project herd by FINRAOS.
the class RetentionTypeDaoTest method testGetRetentionTypeByCode.
@Test
public void testGetRetentionTypeByCode() {
RetentionTypeEntity existingRetentionType = retentionTypeDao.getRetentionTypeByCode(RetentionTypeEntity.PARTITION_VALUE);
if (existingRetentionType == null) {
retentionTypeDaoTestHelper.createRetentionTypeEntity(RetentionTypeEntity.PARTITION_VALUE);
}
// Create database entities required for testing.
List<RetentionTypeEntity> retentionTypeEntityList = Arrays.asList(existingRetentionType, retentionTypeDaoTestHelper.createRetentionTypeEntity("REGISTRATION_DATE"));
// Retrieve the relative retention type entities and validate the results.
assertEquals(retentionTypeEntityList.get(0), retentionTypeDao.getRetentionTypeByCode(RetentionTypeEntity.PARTITION_VALUE));
assertEquals(retentionTypeEntityList.get(1), retentionTypeDao.getRetentionTypeByCode("REGISTRATION_DATE"));
// Test case insensitivity for the retention type.
assertEquals(retentionTypeEntityList.get(0), retentionTypeDao.getRetentionTypeByCode(RetentionTypeEntity.PARTITION_VALUE.toLowerCase()));
assertEquals(retentionTypeEntityList.get(0), retentionTypeDao.getRetentionTypeByCode(RetentionTypeEntity.PARTITION_VALUE.toUpperCase()));
// Confirm negative results when using non-existing retention type.
assertNull(retentionTypeDao.getRetentionTypeByCode("I_DO_NOT_EXIST"));
}
use of org.finra.herd.model.jpa.RetentionTypeEntity in project herd by FINRAOS.
the class BusinessObjectDataDaoTest method testBusinessObjectDataSearchWithRetentionExpirationFilterMultipleFormats.
@Test
public void testBusinessObjectDataSearchWithRetentionExpirationFilterMultipleFormats() {
int retentionPeriod = 180;
java.util.Date date = DateUtils.addDays(new java.util.Date(), -1 * retentionPeriod);
String partitionValueDate = DateFormatUtils.format(date, AbstractHerdDao.DEFAULT_SINGLE_DAY_DATE_MASK);
BusinessObjectDataEntity businessObjectDataEntity = businessObjectDataDaoTestHelper.createBusinessObjectDataEntity(NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, FORMAT_VERSION, partitionValueDate, null, DATA_VERSION, true, "VALID");
BusinessObjectDataEntity businessObjectDataEntity2 = businessObjectDataDaoTestHelper.createBusinessObjectDataEntity(NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE_2, FORMAT_FILE_TYPE_CODE, FORMAT_VERSION, partitionValueDate, null, DATA_VERSION, true, "INVALID");
BusinessObjectDataEntity businessObjectDataEntity3 = businessObjectDataDaoTestHelper.createBusinessObjectDataEntity(NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE_3, FORMAT_FILE_TYPE_CODE, FORMAT_VERSION, partitionValueDate, null, DATA_VERSION, true, "INVALID");
BusinessObjectDataEntity businessObjectDataEntity4 = businessObjectDataDaoTestHelper.createBusinessObjectDataEntity(NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE_3, FORMAT_FILE_TYPE_CODE_2, FORMAT_VERSION, partitionValueDate, null, DATA_VERSION, true, "INVALID");
businessObjectDataDaoTestHelper.createBusinessObjectDataEntity(NAMESPACE_2, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, FORMAT_VERSION, partitionValueDate, null, DATA_VERSION, true, "INVALID");
RetentionTypeEntity existingRetentionType = retentionTypeDao.getRetentionTypeByCode(RetentionTypeEntity.PARTITION_VALUE);
if (existingRetentionType == null) {
retentionTypeDaoTestHelper.createRetentionTypeEntity(RetentionTypeEntity.PARTITION_VALUE);
}
businessObjectDataEntity.getBusinessObjectFormat().setRetentionType(existingRetentionType);
businessObjectDataEntity.getBusinessObjectFormat().setRetentionPeriodInDays(retentionPeriod - 1);
businessObjectDataEntity2.getBusinessObjectFormat().setRetentionType(existingRetentionType);
businessObjectDataEntity2.getBusinessObjectFormat().setRetentionPeriodInDays(retentionPeriod - 1);
businessObjectDataEntity3.getBusinessObjectFormat().setRetentionType(existingRetentionType);
businessObjectDataEntity3.getBusinessObjectFormat().setRetentionPeriodInDays(null);
RetentionTypeEntity notFoundRetentionTypeEntity = retentionTypeDaoTestHelper.createRetentionTypeEntity(RetentionTypeEntity.PARTITION_VALUE + "NOTFOUND");
businessObjectDataEntity4.getBusinessObjectFormat().setRetentionType(notFoundRetentionTypeEntity);
businessObjectDataEntity4.getBusinessObjectFormat().setRetentionPeriodInDays(retentionPeriod);
BusinessObjectDataSearchKey businessObjectDataSearchKey = new BusinessObjectDataSearchKey();
businessObjectDataSearchKey.setNamespace(NAMESPACE);
businessObjectDataSearchKey.setBusinessObjectDefinitionName(BDEF_NAME);
businessObjectDataSearchKey.setFilterOnRetentionExpiration(true);
List<BusinessObjectData> result = businessObjectDataDao.searchBusinessObjectData(businessObjectDataSearchKey, DEFAULT_PAGE_NUMBER, DEFAULT_PAGE_SIZE);
assertEquals(2, result.size());
}
use of org.finra.herd.model.jpa.RetentionTypeEntity in project herd by FINRAOS.
the class BusinessObjectDataDaoTest method testBusinessObjectDataSearchWithRetentionExpirationFilter.
@Test
public void testBusinessObjectDataSearchWithRetentionExpirationFilter() {
int retentionPeriod = 180;
java.util.Date date = DateUtils.addDays(new java.util.Date(), -1 * retentionPeriod);
String partitionValueDate = DateFormatUtils.format(date, AbstractHerdDao.DEFAULT_SINGLE_DAY_DATE_MASK);
businessObjectDataDaoTestHelper.createBusinessObjectDataEntity(NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, FORMAT_VERSION, partitionValueDate, null, DATA_VERSION, true, "VALID");
BusinessObjectDataEntity businessObjectDataEntity2 = businessObjectDataDaoTestHelper.createBusinessObjectDataEntity(NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, FORMAT_VERSION_2, partitionValueDate, null, DATA_VERSION, true, "INVALID");
businessObjectDataDaoTestHelper.createBusinessObjectDataEntity(NAMESPACE_2, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, FORMAT_VERSION, partitionValueDate, null, DATA_VERSION, true, "INVALID");
RetentionTypeEntity existingRetentionType = retentionTypeDao.getRetentionTypeByCode(RetentionTypeEntity.PARTITION_VALUE);
if (existingRetentionType == null) {
retentionTypeDaoTestHelper.createRetentionTypeEntity(RetentionTypeEntity.PARTITION_VALUE);
}
businessObjectDataEntity2.getBusinessObjectFormat().setRetentionType(existingRetentionType);
businessObjectDataEntity2.getBusinessObjectFormat().setRetentionPeriodInDays(retentionPeriod - 1);
BusinessObjectDataSearchKey businessObjectDataSearchKey = new BusinessObjectDataSearchKey();
businessObjectDataSearchKey.setNamespace(NAMESPACE);
businessObjectDataSearchKey.setBusinessObjectDefinitionName(BDEF_NAME);
businessObjectDataSearchKey.setBusinessObjectFormatUsage(FORMAT_USAGE_CODE);
businessObjectDataSearchKey.setBusinessObjectFormatFileType(FORMAT_FILE_TYPE_CODE);
businessObjectDataSearchKey.setFilterOnRetentionExpiration(true);
List<BusinessObjectData> result = businessObjectDataDao.searchBusinessObjectData(businessObjectDataSearchKey, DEFAULT_PAGE_NUMBER, DEFAULT_PAGE_SIZE);
assertEquals(2, result.size());
}
Aggregations