/** * Create and persist database entities required for the initiate a restore request testing. * * @param businessObjectDataKey the business object data key * * @return the business object data entity */ public BusinessObjectDataEntity createDatabaseEntitiesForInitiateRestoreTesting(BusinessObjectDataKey businessObjectDataKey) { return createDatabaseEntitiesForInitiateRestoreTesting(businessObjectDataKey, AbstractServiceTest.STORAGE_NAME, AbstractServiceTest.S3_BUCKET_NAME, StorageUnitStatusEntity.ARCHIVED, AbstractServiceTest.LOCAL_FILES); }
@Test public void testPrepareToInitiateRestoreUpperCaseParameters() { // 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 database entities required for testing. businessObjectDataServiceTestHelper.createDatabaseEntitiesForInitiateRestoreTesting(businessObjectDataKey); // Execute a before step for the initiate a business object data restore request // using upper case input parameters (except for case-sensitive partition values). BusinessObjectDataRestoreDto storagePolicyTransitionParamsDto = businessObjectDataInitiateRestoreHelperService.prepareToInitiateRestore( new BusinessObjectDataKey(BDEF_NAMESPACE.toUpperCase(), BDEF_NAME.toUpperCase(), FORMAT_USAGE_CODE.toUpperCase(), FORMAT_FILE_TYPE_CODE.toUpperCase(), FORMAT_VERSION, PARTITION_VALUE, NO_SUBPARTITION_VALUES, DATA_VERSION), EXPIRATION_IN_DAYS); // Validate the returned object. assertEquals(businessObjectDataKey, storagePolicyTransitionParamsDto.getBusinessObjectDataKey()); } }
@Test public void testPrepareToInitiateRestoreLowerCaseParameters() { // 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 database entities required for testing. businessObjectDataServiceTestHelper.createDatabaseEntitiesForInitiateRestoreTesting(businessObjectDataKey); // Execute a before step for the initiate a business object data restore request // using lower case input parameters (except for case-sensitive partition values). BusinessObjectDataRestoreDto storagePolicyTransitionParamsDto = businessObjectDataInitiateRestoreHelperService.prepareToInitiateRestore( new BusinessObjectDataKey(BDEF_NAMESPACE.toLowerCase(), BDEF_NAME.toLowerCase(), FORMAT_USAGE_CODE.toLowerCase(), FORMAT_FILE_TYPE_CODE.toLowerCase(), FORMAT_VERSION, PARTITION_VALUE, NO_SUBPARTITION_VALUES, DATA_VERSION), EXPIRATION_IN_DAYS); // Validate the returned object. assertEquals(businessObjectDataKey, storagePolicyTransitionParamsDto.getBusinessObjectDataKey()); }
@Test public void testPrepareToInitiateRestoreStorageUnitAlreadyRestoring() throws Exception { // 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 database entities required for testing with a storage unit already being restored. businessObjectDataServiceTestHelper .createDatabaseEntitiesForInitiateRestoreTesting(businessObjectDataKey, STORAGE_NAME, S3_BUCKET_NAME, StorageUnitStatusEntity.RESTORING, LOCAL_FILES); // Try to execute a before step for the initiate a business object data restore request when storage unit is already being restored. try { businessObjectDataInitiateRestoreHelperService.prepareToInitiateRestore(businessObjectDataKey, EXPIRATION_IN_DAYS); fail(); } catch (IllegalArgumentException e) { assertEquals(String.format("Business object data is already being restored in \"%s\" S3 storage. Business object data: {%s}", STORAGE_NAME, businessObjectDataServiceTestHelper.getExpectedBusinessObjectDataKeyAsString(businessObjectDataKey)), e.getMessage()); } }
@Test public void testPrepareToInitiateRestoreStorageHasNoS3BucketName() throws Exception { // 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 database entities required for testing with the storage not having S3 bucket name configured. businessObjectDataServiceTestHelper .createDatabaseEntitiesForInitiateRestoreTesting(businessObjectDataKey, STORAGE_NAME, NO_S3_BUCKET_NAME, StorageUnitStatusEntity.ARCHIVED, LOCAL_FILES); // Try to execute a before step for the initiate a business object data restore request // when the storage does not have an S3 bucket name configured. try { businessObjectDataInitiateRestoreHelperService.prepareToInitiateRestore(businessObjectDataKey, EXPIRATION_IN_DAYS); fail(); } catch (IllegalStateException e) { assertEquals(String.format("Attribute \"%s\" for \"%s\" storage must be configured.", configurationHelper.getProperty(ConfigurationValue.S3_ATTRIBUTE_NAME_BUCKET_NAME), STORAGE_NAME), e.getMessage()); } }
@Test public void testPrepareToInitiateRestore() throws Exception { // 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 database entities required for testing. BusinessObjectDataEntity businessObjectDataEntity = businessObjectDataServiceTestHelper.createDatabaseEntitiesForInitiateRestoreTesting(businessObjectDataKey); // Get the current time and compute the expected timestamp value. Timestamp currentTime = new Timestamp(System.currentTimeMillis()); Timestamp expectedTimestamp = HerdDateUtils.addDays(currentTime, EXPIRATION_IN_DAYS); // Execute a before step for the initiate a business object data restore request. BusinessObjectDataRestoreDto storagePolicyTransitionParamsDto = businessObjectDataInitiateRestoreHelperService.prepareToInitiateRestore(businessObjectDataKey, EXPIRATION_IN_DAYS); // Validate the returned object. assertEquals(businessObjectDataKey, storagePolicyTransitionParamsDto.getBusinessObjectDataKey()); // Validate that restore expiration time is set correctly on the storage unit. StorageUnitEntity storageUnitEntity = storageUnitDaoHelper.getStorageUnitEntity(STORAGE_NAME, businessObjectDataEntity); assertNotNull(storageUnitEntity.getRestoreExpirationOn()); Long differenceInMilliseconds = storageUnitEntity.getRestoreExpirationOn().getTime() - expectedTimestamp.getTime(); assertTrue(Math.abs(differenceInMilliseconds) < 1000); }
@Test public void testPrepareToInitiateRestoreStorageUnitHasNoStorageFiles() throws Exception { // 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 database entities required for testing. BusinessObjectDataEntity businessObjectDataEntity = businessObjectDataServiceTestHelper .createDatabaseEntitiesForInitiateRestoreTesting(businessObjectDataKey, STORAGE_NAME, S3_BUCKET_NAME, StorageUnitStatusEntity.ARCHIVED, LOCAL_FILES); // Get the storage unit entity. StorageUnitEntity storageUnitEntity = storageUnitDaoHelper.getStorageUnitEntity(STORAGE_NAME, businessObjectDataEntity); // Remove storage files from the storage unit. storageUnitEntity.getStorageFiles().clear(); // Try to execute a before step for the initiate a business object data restore request when storage unit has no storage files. try { businessObjectDataInitiateRestoreHelperService.prepareToInitiateRestore(businessObjectDataKey, EXPIRATION_IN_DAYS); fail(); } catch (IllegalArgumentException e) { assertEquals(String.format("Business object data has no storage files registered in \"%s\" storage. Business object data: {%s}", STORAGE_NAME, businessObjectDataServiceTestHelper.getExpectedBusinessObjectDataKeyAsString(businessObjectDataKey)), e.getMessage()); } }
@Test public void testPrepareToInitiateRestoreMissingOptionalParameters() throws Exception { // Create a business object data key without sub-partition values. 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 database entities required for testing. BusinessObjectDataEntity businessObjectDataEntity = businessObjectDataServiceTestHelper.createDatabaseEntitiesForInitiateRestoreTesting(businessObjectDataKey); // Execute a before step for the initiate a business object data restore request for business object data without sub-partition values. BusinessObjectDataRestoreDto storagePolicyTransitionParamsDto = businessObjectDataInitiateRestoreHelperService.prepareToInitiateRestore(businessObjectDataKey, NO_EXPIRATION_IN_DAYS); // Validate the returned object. assertEquals(businessObjectDataKey, storagePolicyTransitionParamsDto.getBusinessObjectDataKey()); // Validate that restore expiration time is set correctly on the storage unit. StorageUnitEntity storageUnitEntity = storageUnitDaoHelper.getStorageUnitEntity(STORAGE_NAME, businessObjectDataEntity); assertNotNull(storageUnitEntity.getRestoreExpirationOn()); Long differenceInDays = TimeUnit.DAYS.convert(storageUnitEntity.getRestoreExpirationOn().getTime() - storageUnitEntity.getCreatedOn().getTime(), TimeUnit.MILLISECONDS); assertTrue((Integer) ConfigurationValue.BDATA_RESTORE_EXPIRATION_IN_DAYS_DEFAULT.getDefaultValue() - differenceInDays <= 1); }
.createDatabaseEntitiesForInitiateRestoreTesting(businessObjectDataKey, AbstractServiceTest.STORAGE_NAME, AbstractServiceTest.S3_BUCKET_NAME, StorageUnitStatusEntity.ARCHIVED, Collections.singletonList(LOCAL_FILE));
businessObjectDataServiceTestHelper.createDatabaseEntitiesForInitiateRestoreTesting(businessObjectDataKey);
@Test public void testPrepareToInitiateRestoreTrimParameters() { // 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 database entities required for testing. businessObjectDataServiceTestHelper.createDatabaseEntitiesForInitiateRestoreTesting(businessObjectDataKey); // Execute a before step for the initiate a business object data restore request using input parameters with leading and trailing empty spaces. BusinessObjectDataRestoreDto storagePolicyTransitionParamsDto = businessObjectDataInitiateRestoreHelperService.prepareToInitiateRestore( new BusinessObjectDataKey(addWhitespace(BDEF_NAMESPACE), addWhitespace(BDEF_NAME), addWhitespace(FORMAT_USAGE_CODE), addWhitespace(FORMAT_FILE_TYPE_CODE), FORMAT_VERSION, addWhitespace(PARTITION_VALUE), NO_SUBPARTITION_VALUES, DATA_VERSION), EXPIRATION_IN_DAYS); // Validate the returned object. assertEquals(businessObjectDataKey, storagePolicyTransitionParamsDto.getBusinessObjectDataKey()); }
businessObjectDataServiceTestHelper.createDatabaseEntitiesForInitiateRestoreTesting(businessObjectDataKey);