*/
public class FilesTest extends StructrTest {
public void testCreateFolder() {
Folder folder1 = null;
try (final Tx tx = app.tx()) {
folder1 = FileHelper.createFolderPath(SecurityContext.getSuperUserInstance(), "/folder1");
tx.success();
} catch (FrameworkException ex) {
Logger.getLogger(FilesTest.class.getName()).log(Level.SEVERE, null, ex);
}
try (final Tx tx = app.tx()) {
File file1 = (File) app.create(File.class, "file1");
assertNotNull(file1);
assertEquals(FileHelper.getFolderPath(file1), "/file1");
file1.setProperty(File.parent, folder1);
assertEquals(FileHelper.getFolderPath(file1), "/folder1/file1");
tx.success();
} catch (FrameworkException ex) {
Logger.getLogger(FilesTest.class.getName()).log(Level.SEVERE, null, ex);
}
try (final Tx tx = app.tx()) {
Image image1 = (Image) app.create(Image.class, "image1");
assertNotNull(image1);
assertEquals(FileHelper.getFolderPath(image1), "/image1");
image1.setProperty(File.parent, folder1);
assertEquals(FileHelper.getFolderPath(image1), "/folder1/image1");
tx.success();
} catch (FrameworkException ex) {
Logger.getLogger(FilesTest.class.getName()).log(Level.SEVERE, null, ex);
}
try (final Tx tx = app.tx()) {
assertEquals(2, folder1.getProperty(Folder.files).size());
assertEquals(1, folder1.getProperty(Folder.images).size());
} catch (FrameworkException ex) {
Logger.getLogger(FilesTest.class.getName()).log(Level.SEVERE, null, ex);
}
}