@Test @SuppressWarnings("unchecked") public void testResourceTransactionRollback() throws IOException { File tempDir = OperatingSystemUtils.createTempDir(); File file = createTempFile(tempDir, true); ResourceTransaction transaction = resourceFactory.getTransaction(); Assert.assertNotNull(transaction); Assert.assertFalse(transaction.isStarted()); transaction.begin(); Assert.assertTrue(transaction.isStarted()); FileResource<?> fileResource = resourceFactory.create(FileResource.class, file); Assert.assertNotNull(fileResource); fileResource.setContents("Hello World"); Assert.assertTrue(fileResource.exists()); Assert.assertFalse(file.exists()); transaction.rollback(); Assert.assertFalse(fileResource.exists()); }
@After public void tearDown() { ResourceTransaction transaction = resourceFactory.getTransaction(); if (transaction.isStarted()) transaction.rollback(); }