Search in sources :

Example 1 with RetentionTypeEntity

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();
}
Also used : BusinessObjectFormatKey(org.finra.herd.model.api.xml.BusinessObjectFormatKey) BusinessObjectDataEntity(org.finra.herd.model.jpa.BusinessObjectDataEntity) BusinessObjectDataKey(org.finra.herd.model.api.xml.BusinessObjectDataKey) BusinessObjectFormatEntity(org.finra.herd.model.jpa.BusinessObjectFormatEntity) RetentionTypeEntity(org.finra.herd.model.jpa.RetentionTypeEntity) AbstractServiceTest(org.finra.herd.service.AbstractServiceTest) Test(org.junit.Test)

Example 2 with RetentionTypeEntity

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);
}
Also used : RetentionTypeEntity(org.finra.herd.model.jpa.RetentionTypeEntity)

Example 3 with 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"));
}
Also used : RetentionTypeEntity(org.finra.herd.model.jpa.RetentionTypeEntity) Test(org.junit.Test)

Example 4 with RetentionTypeEntity

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());
}
Also used : BusinessObjectData(org.finra.herd.model.api.xml.BusinessObjectData) BusinessObjectDataSearchKey(org.finra.herd.model.api.xml.BusinessObjectDataSearchKey) BusinessObjectDataEntity(org.finra.herd.model.jpa.BusinessObjectDataEntity) RetentionTypeEntity(org.finra.herd.model.jpa.RetentionTypeEntity) Test(org.junit.Test)

Example 5 with RetentionTypeEntity

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());
}
Also used : BusinessObjectData(org.finra.herd.model.api.xml.BusinessObjectData) BusinessObjectDataSearchKey(org.finra.herd.model.api.xml.BusinessObjectDataSearchKey) BusinessObjectDataEntity(org.finra.herd.model.jpa.BusinessObjectDataEntity) RetentionTypeEntity(org.finra.herd.model.jpa.RetentionTypeEntity) Test(org.junit.Test)

Aggregations

RetentionTypeEntity (org.finra.herd.model.jpa.RetentionTypeEntity)11 Test (org.junit.Test)8 BusinessObjectDataEntity (org.finra.herd.model.jpa.BusinessObjectDataEntity)7 BusinessObjectFormatEntity (org.finra.herd.model.jpa.BusinessObjectFormatEntity)6 BusinessObjectDataKey (org.finra.herd.model.api.xml.BusinessObjectDataKey)5 BusinessObjectFormatKey (org.finra.herd.model.api.xml.BusinessObjectFormatKey)5 AbstractServiceTest (org.finra.herd.service.AbstractServiceTest)5 Timestamp (java.sql.Timestamp)2 Calendar (java.util.Calendar)2 Date (java.util.Date)2 BusinessObjectData (org.finra.herd.model.api.xml.BusinessObjectData)2 BusinessObjectDataSearchKey (org.finra.herd.model.api.xml.BusinessObjectDataSearchKey)2 CriteriaBuilder (javax.persistence.criteria.CriteriaBuilder)1 Predicate (javax.persistence.criteria.Predicate)1 NamespacePermission (org.finra.herd.model.annotation.NamespacePermission)1 StorageFile (org.finra.herd.model.api.xml.StorageFile)1 BusinessObjectDataDestroyDto (org.finra.herd.model.dto.BusinessObjectDataDestroyDto)1 BusinessObjectDataStatusEntity (org.finra.herd.model.jpa.BusinessObjectDataStatusEntity)1 StorageEntity (org.finra.herd.model.jpa.StorageEntity)1 StorageFileEntity (org.finra.herd.model.jpa.StorageFileEntity)1