java - 在露天。如何创建临时文件进行测试?

我的想法是在测试中创建一个文件然后删除它,但是我的代码失败了

我的代码:

 @RunWith(RemoteTestRunner.class)
 @Remote(runnerClass=SpringJUnit4ClassRunner.class)
 @ContextConfiguration("classpath:alfresco/application-context.xml")
 public class FooTest {
   private static final String ADMIN_USER_NAME = "admin";

   @Autowired
   @Qualifier("NodeService")
   protected NodeService nodeService;

   @Autowired
   private FileFolderService fileFolderService;

   @Autowired
   protected Repository repositoryHelper;

   @Test
   public void testCreateTempFile() {
     AuthenticationUtil.setFullyAuthenticatedUser(ADMIN_USER_NAME);

     NodeRef root = repositoryHelper.getSharedHome();

     // create the node
     // this line throw an exception
     FileInfo fileInfo = fileFolderService.create(root,
       "foo.txt", ContentModel.PROP_CONTENT);
     ...
   }
 }

出现如下错误:

org.alfresco.error.AlfrescoRuntimeException: 07170002 Transaction must be active and synchronization is required: Thread[main,5,main] at org.alfresco.util.transaction.TransactionSupportUtil.registerSynchronizations(TransactionSupportUtil.java:188)

交易如何运作?如何激活它?

最佳答案

为了使用临时文件,alfresco 提供了一个实用类

org.alfresco.util.TempFileProvider

它具有允许您创建临时文件和目录的所有 API。

如果您经常使用临时文件,您甚至可以考虑使用这个 utility这允许您定期清除临时文件。

https://stackoverflow.com/questions/38987588/

相关文章:

cordova - Swiper.js - 禁用触摸滑动但以编程方式滑动

laravel - 如何在 Laravel 的 Eloquent 模型中覆盖 ModelNotFou

web-services - 基于操作的 URI 和基于资源的 URI 之间有什么区别?

pandas - 水平排列两个地 block

php - 匹配不同值的 RegEx BackReference

ms-access - MS Access 2013 仅显示启动表单,仅显示其他内容

r - 如何在 R 中获得 ping 响应

arrays - 通过在元素之间包含零来对向量进行上采样

python - 建立新连接失败

c#-6.0 - 有没有办法将 C# 6 的字符串插值与多行字符串一起使用?