StorageFileDaoHelper { public StorageFileEntity getStorageFileEntity(String storageName, String filePath) throws ObjectNotFoundException, IllegalArgumentException { StorageFileEntity storageFileEntity = storageFileDao.getStorageFileByStorageNameAndFilePath(storageName, filePath); if (storageFileEntity == null) { throw new ObjectNotFoundException(String.format("Storage file \"%s\" doesn't exist in \"%s\" storage.", filePath, storageName)); } return storageFileEntity; }  List<StorageFileEntity> createStorageFileEntitiesFromStorageFiles(StorageUnitEntity storageUnitEntity, List<StorageFile> storageFiles); StorageFileEntity getStorageFileEntity(String storageName, String filePath); StorageFileEntity getStorageFileEntity(StorageUnitEntity storageUnitEntity, String filePath, BusinessObjectDataKey businessObjectDataKey);  }
@Test public void testGetStorageFileEntity() { StorageFileEntity storageFileEntity = new StorageFileEntity(); storageFileEntity.setPath(TEST_S3_KEY_PREFIX); storageFileEntity.setRowCount(ROW_COUNT); storageFileEntity.setFileSizeBytes(FILE_SIZE); String filePath = TEST_S3_KEY_PREFIX + "/" + LOCAL_FILE; when(storageFileDao.getStorageFileByStorageNameAndFilePath(STORAGE_NAME, filePath)).thenReturn(storageFileEntity); StorageFileEntity result = storageFileDaoHelper.getStorageFileEntity(STORAGE_NAME, filePath); assertThat("Result not equal to storage file entity.", result, is(storageFileEntity)); verify(storageFileDao).getStorageFileByStorageNameAndFilePath(STORAGE_NAME, filePath); verifyNoMoreInteractionsHelper(); }
@Test public void testGetStorageFileEntityWithNullStorageFileEntity() { String filePath = TEST_S3_KEY_PREFIX + "/" + LOCAL_FILE; when(storageFileDao.getStorageFileByStorageNameAndFilePath(STORAGE_NAME, filePath)).thenReturn(null); try { storageFileDaoHelper.getStorageFileEntity(STORAGE_NAME, filePath); fail(); } catch (ObjectNotFoundException objectNotFoundException) { assertThat("Exception message not equal to expected exception message.", objectNotFoundException.getMessage(), is(String.format("Storage file \"%s\" doesn't exist in \"%s\" storage.", filePath, STORAGE_NAME))); } verify(storageFileDao).getStorageFileByStorageNameAndFilePath(STORAGE_NAME, filePath); verifyNoMoreInteractionsHelper(); }
@Test public void testGetStorageFileEntityByStorageUnitEntityAndFilePath() { BusinessObjectDataKey businessObjectDataKey = new BusinessObjectDataKey(NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, FORMAT_VERSION, PARTITION_VALUE, SUBPARTITION_VALUES, DATA_VERSION); StorageUnitEntity storageUnitEntity = new StorageUnitEntity(); String filePath = TEST_S3_KEY_PREFIX + "/" + LOCAL_FILE; StorageFileEntity storageFileEntity = new StorageFileEntity(); storageFileEntity.setPath(TEST_S3_KEY_PREFIX); storageFileEntity.setRowCount(ROW_COUNT); storageFileEntity.setFileSizeBytes(FILE_SIZE); when(storageFileDao.getStorageFileByStorageUnitEntityAndFilePath(storageUnitEntity, filePath)).thenReturn(storageFileEntity); StorageFileEntity result = storageFileDaoHelper.getStorageFileEntity(storageUnitEntity, filePath, businessObjectDataKey); assertThat("Result not equal to storage file entity.", result, is(storageFileEntity)); verify(storageFileDao).getStorageFileByStorageUnitEntityAndFilePath(storageUnitEntity, filePath); verifyNoMoreInteractionsHelper(); }
@Test public void testGetStorageFileEntityByStorageUnitEntityAndFilePathWithFileOnlyPrefix() { BusinessObjectDataKey businessObjectDataKey = new BusinessObjectDataKey(NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, FORMAT_VERSION, PARTITION_VALUE, SUBPARTITION_VALUES, DATA_VERSION); StorageEntity storageEntity = new StorageEntity(); storageEntity.setName(STORAGE_NAME); StorageUnitEntity storageUnitEntity = new StorageUnitEntity(); storageUnitEntity.setStorage(storageEntity); storageUnitEntity.setDirectoryPath(TEST_S3_KEY_PREFIX); String filePath = TEST_S3_KEY_PREFIX + "/" + LOCAL_FILE; StorageFileEntity storageFileEntity = new StorageFileEntity(); storageFileEntity.setPath(TEST_S3_KEY_PREFIX); storageFileEntity.setRowCount(ROW_COUNT); storageFileEntity.setFileSizeBytes(FILE_SIZE); when(storageFileDao.getStorageFileByStorageUnitEntityAndFilePath(storageUnitEntity, filePath)).thenReturn(null); when(storageFileDao.getStorageFileByStorageUnitEntityAndFilePath(storageUnitEntity, LOCAL_FILE)).thenReturn(storageFileEntity); StorageFileEntity result = storageFileDaoHelper.getStorageFileEntity(storageUnitEntity, filePath, businessObjectDataKey); assertThat("Result not equal to storage file entity.", result, is(storageFileEntity)); verify(storageFileDao).getStorageFileByStorageUnitEntityAndFilePath(storageUnitEntity, filePath); verify(storageFileDao).getStorageFileByStorageUnitEntityAndFilePath(storageUnitEntity, LOCAL_FILE); verifyNoMoreInteractionsHelper(); }
@Test public void testGetStorageFileEntityByStorageUnitEntityAndFilePathWithNullStorageFileEntity() { BusinessObjectDataKey businessObjectDataKey = new BusinessObjectDataKey(NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, FORMAT_VERSION, PARTITION_VALUE, SUBPARTITION_VALUES, DATA_VERSION); StorageEntity storageEntity = new StorageEntity(); storageEntity.setName(STORAGE_NAME); StorageUnitEntity storageUnitEntity = new StorageUnitEntity(); storageUnitEntity.setStorage(storageEntity); storageUnitEntity.setDirectoryPath(DIRECTORY_PATH); String filePath = TEST_S3_KEY_PREFIX + "/" + LOCAL_FILE; when(storageFileDao.getStorageFileByStorageUnitEntityAndFilePath(storageUnitEntity, filePath)).thenReturn(null); try { storageFileDaoHelper.getStorageFileEntity(storageUnitEntity, filePath, businessObjectDataKey); fail(); } catch (ObjectNotFoundException objectNotFoundException) { assertThat("Exception message not equal to expected exception message.", objectNotFoundException.getMessage(), is(String .format("Storage file \"%s\" doesn't exist in \"%s\" storage. Business object data: {%s}", filePath, storageUnitEntity.getStorage().getName(), businessObjectDataHelper.businessObjectDataKeyToString(businessObjectDataKey)))); } verify(storageFileDao).getStorageFileByStorageUnitEntityAndFilePath(storageUnitEntity, filePath); verify(businessObjectDataHelper, times(2)).businessObjectDataKeyToString(businessObjectDataKey); verifyNoMoreInteractionsHelper(); }
@Test public void testGetStorageFileEntityByStorageUnitEntityAndFilePathWithNullStorageFileEntityWithBlankDirectoryPath() { BusinessObjectDataKey businessObjectDataKey = new BusinessObjectDataKey(NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, FORMAT_VERSION, PARTITION_VALUE, SUBPARTITION_VALUES, DATA_VERSION); StorageEntity storageEntity = new StorageEntity(); storageEntity.setName(STORAGE_NAME); StorageUnitEntity storageUnitEntity = new StorageUnitEntity(); storageUnitEntity.setStorage(storageEntity); String filePath = TEST_S3_KEY_PREFIX + "/" + LOCAL_FILE; when(storageFileDao.getStorageFileByStorageUnitEntityAndFilePath(storageUnitEntity, filePath)).thenReturn(null); try { storageFileDaoHelper.getStorageFileEntity(storageUnitEntity, filePath, businessObjectDataKey); fail(); } catch (ObjectNotFoundException objectNotFoundException) { assertThat("Exception message not equal to expected exception message.", objectNotFoundException.getMessage(), is(String .format("Storage file \"%s\" doesn't exist in \"%s\" storage. Business object data: {%s}", filePath, storageUnitEntity.getStorage().getName(), businessObjectDataHelper.businessObjectDataKeyToString(businessObjectDataKey)))); } verify(storageFileDao).getStorageFileByStorageUnitEntityAndFilePath(storageUnitEntity, filePath); verify(businessObjectDataHelper, times(2)).businessObjectDataKeyToString(businessObjectDataKey); verifyNoMoreInteractionsHelper(); }