CleanupDestroyedBusinessObjectDataServiceImpl implements CleanupDestroyedBusinessObjectDataService { @PublishNotificationMessages @Override @Transactional(propagation = Propagation.REQUIRES_NEW) public void cleanupS3StorageUnit(BusinessObjectDataStorageUnitKey businessObjectDataStorageUnitKey) { cleanupS3StorageUnitImpl(businessObjectDataStorageUnitKey); }  @PublishNotificationMessages @Override @Transactional(propagation = Propagation.REQUIRES_NEW) void cleanupS3StorageUnit(BusinessObjectDataStorageUnitKey businessObjectDataStorageUnitKey); @Override @Transactional(propagation = Propagation.NOT_SUPPORTED) List<BusinessObjectDataStorageUnitKey> getS3StorageUnitsToCleanup(int maxResult);  }
@Test public void testCleanupS3StorageUnit() { BusinessObjectDataKey businessObjectDataKey = new BusinessObjectDataKey(BDEF_NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, FORMAT_VERSION, PARTITION_VALUE, SUBPARTITION_VALUES, DATA_VERSION); BusinessObjectDataStorageUnitKey businessObjectDataStorageUnitKey = new BusinessObjectDataStorageUnitKey(BDEF_NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, FORMAT_VERSION, PARTITION_VALUE, SUBPARTITION_VALUES, DATA_VERSION, STORAGE_NAME); BusinessObjectDataEntity businessObjectDataEntity = mock(BusinessObjectDataEntity.class); when(mockBusinessObjectDataHelper.createBusinessObjectDataKeyFromStorageUnitKey(businessObjectDataStorageUnitKey)).thenReturn(businessObjectDataKey); when(mockBusinessObjectDataDaoHelper.getBusinessObjectDataEntity(businessObjectDataKey)).thenReturn(businessObjectDataEntity); when(mockBusinessObjectDataHelper.getBusinessObjectDataKey(businessObjectDataEntity)).thenReturn(businessObjectDataKey); when(businessObjectDataEntity.getLatestVersion()).thenReturn(true); when(mockBusinessObjectDataDao.getBusinessObjectDataMaxVersion(businessObjectDataKey)).thenReturn(BUSINESS_OBJECT_DATA_MAX_VERSION); when(mockBusinessObjectDataDao.getBusinessObjectDataByAltKey( new BusinessObjectDataKey(businessObjectDataKey.getNamespace(), businessObjectDataKey.getBusinessObjectDefinitionName(), businessObjectDataKey.getBusinessObjectFormatUsage(), businessObjectDataKey.getBusinessObjectFormatFileType(), businessObjectDataKey.getBusinessObjectFormatVersion(), businessObjectDataKey.getPartitionValue(), businessObjectDataKey.getSubPartitionValues(), BUSINESS_OBJECT_DATA_MAX_VERSION))).thenReturn(businessObjectDataEntity); cleanupDestroyedBusinessObjectDataService.cleanupS3StorageUnit(businessObjectDataStorageUnitKey); verify(mockBusinessObjectDataHelper).createBusinessObjectDataKeyFromStorageUnitKey(businessObjectDataStorageUnitKey); verify(mockBusinessObjectDataDaoHelper).getBusinessObjectDataEntity(businessObjectDataKey); verify(businessObjectDataEntity).getStorageUnits(); verify(mockBusinessObjectDataDao).delete(businessObjectDataEntity); verify(mockNotificationEventService) .processStorageUnitNotificationEventAsync(NotificationEventTypeEntity.EventTypesStorageUnit.STRGE_UNIT_STTS_CHG, businessObjectDataKey, STORAGE_NAME, null, StorageUnitStatusEntity.DISABLED); verify(mockNotificationEventService) .processBusinessObjectDataNotificationEventAsync(NotificationEventTypeEntity.EventTypesBdata.BUS_OBJCT_DATA_STTS_CHG, businessObjectDataKey, null, BusinessObjectDataStatusEntity.DELETED); verify(businessObjectDataEntity).getBusinessObjectDataChildren(); verify(businessObjectDataEntity).getBusinessObjectDataParents(); verify(businessObjectDataEntity).getLatestVersion(); verify(mockBusinessObjectDataDao).getBusinessObjectDataMaxVersion(businessObjectDataKey); verify(mockBusinessObjectDataDao).getBusinessObjectDataByAltKey( new BusinessObjectDataKey(businessObjectDataKey.getNamespace(), businessObjectDataKey.getBusinessObjectDefinitionName(), businessObjectDataKey.getBusinessObjectFormatUsage(), businessObjectDataKey.getBusinessObjectFormatFileType(), businessObjectDataKey.getBusinessObjectFormatVersion(), businessObjectDataKey.getPartitionValue(), businessObjectDataKey.getSubPartitionValues(), BUSINESS_OBJECT_DATA_MAX_VERSION)); verify(businessObjectDataEntity).setLatestVersion(true); verify(mockBusinessObjectDataDao).saveAndRefresh(businessObjectDataEntity); verifyNoMoreInteractions(businessObjectDataEntity); verifyNoMoreInteractionsHelper(); }
@Test public void testCleanupS3StorageUnitWithIllegalArgumentException() { BusinessObjectDataKey businessObjectDataKey = new BusinessObjectDataKey(BDEF_NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, FORMAT_VERSION, PARTITION_VALUE, SUBPARTITION_VALUES, DATA_VERSION); BusinessObjectDataStorageUnitKey businessObjectDataStorageUnitKey = new BusinessObjectDataStorageUnitKey(BDEF_NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, FORMAT_VERSION, PARTITION_VALUE, SUBPARTITION_VALUES, DATA_VERSION, STORAGE_NAME); BusinessObjectDataEntity businessObjectDataEntity = mock(BusinessObjectDataEntity.class); StoragePlatformEntity storagePlatformEntity = new StoragePlatformEntity(); storagePlatformEntity.setName(StoragePlatformEntity.S3); StorageEntity storageEntity = new StorageEntity(); storageEntity.setStoragePlatform(storagePlatformEntity); StorageUnitEntity storageUnitEntity1 = new StorageUnitEntity(); storageUnitEntity1.setStorage(storageEntity); StorageUnitEntity storageUnitEntity2 = new StorageUnitEntity(); storageUnitEntity2.setStorage(storageEntity); Collection<StorageUnitEntity> storageUnitEntities = Lists.newArrayList(); storageUnitEntities.add(storageUnitEntity1); storageUnitEntities.add(storageUnitEntity2); when(mockBusinessObjectDataHelper.createBusinessObjectDataKeyFromStorageUnitKey(businessObjectDataStorageUnitKey)).thenReturn(businessObjectDataKey); when(mockBusinessObjectDataDaoHelper.getBusinessObjectDataEntity(businessObjectDataKey)).thenReturn(businessObjectDataEntity); when(businessObjectDataEntity.getStorageUnits()).thenReturn(storageUnitEntities); when(mockBusinessObjectDataHelper.businessObjectDataKeyToString(businessObjectDataKey)) .thenReturn(businessObjectDataHelper.businessObjectDataKeyToString(businessObjectDataKey)); try { cleanupDestroyedBusinessObjectDataService.cleanupS3StorageUnit(businessObjectDataStorageUnitKey); } catch (IllegalArgumentException illegalArgumentException) { assertThat(illegalArgumentException.getMessage(), is(equalTo("Business object data has multiple (2) S3 storage units. Business object data: {" + businessObjectDataHelper.businessObjectDataKeyToString(businessObjectDataKey) + "}"))); } verify(mockBusinessObjectDataHelper).createBusinessObjectDataKeyFromStorageUnitKey(businessObjectDataStorageUnitKey); verify(mockBusinessObjectDataDaoHelper).getBusinessObjectDataEntity(businessObjectDataKey); verify(businessObjectDataEntity).getStorageUnits(); verify(mockBusinessObjectDataHelper).businessObjectDataKeyToString(businessObjectDataKey); verifyNoMoreInteractions(businessObjectDataEntity); verifyNoMoreInteractionsHelper(); }