use of org.structr.common.error.FrameworkException in project structr by structr.
the class PerformanceTest method testPerformanceOfNodeDeletion.
@Test
public void testPerformanceOfNodeDeletion() {
final App app = StructrApp.getInstance(setup());
final List<TestOne> nodes = new LinkedList<>();
final int number = 1000;
try {
try (final Tx tx = app.tx()) {
nodes.addAll(createNodes(app, TestOne.class, number));
tx.success();
}
} catch (FrameworkException ex) {
logger.error(ex.toString());
fail("Unexpected exception");
}
// start measuring
final long t0 = System.currentTimeMillis();
try {
final BulkDeleteCommand cmd = app.command(BulkDeleteCommand.class);
try (final Tx tx = app.tx()) {
final Iterator<GraphObject> iterator = (Iterator) nodes.iterator();
cmd.bulkDelete(iterator);
tx.success();
}
} catch (FrameworkException ex) {
logger.error(ex.toString());
fail("Unexpected exception");
}
final long t1 = System.currentTimeMillis();
DecimalFormat decimalFormat = new DecimalFormat("0.000000000", DecimalFormatSymbols.getInstance(Locale.ENGLISH));
Double time = (t1 - t0) / 1000.0;
Double rate = number / ((t1 - t0) / 1000.0);
logger.info("Deleted {} nodes in {} seconds ({} per s)", number, decimalFormat.format(time), decimalFormat.format(rate));
assertTrue("Deletion rate of nodes too low, expected > 100, was " + rate, rate > 50);
}
use of org.structr.common.error.FrameworkException in project structr by structr.
the class PropertyTest method testCustomProperty.
@Test
public void testCustomProperty() {
// schema setup
try (final Tx tx = app.tx()) {
final JsonSchema schema = StructrSchema.createFromDatabase(app, Arrays.asList("Image"));
final Gson gson = new GsonBuilder().create();
final Map<String, Object> str = (Map<String, Object>) gson.fromJson(schema.toString(), Map.class);
final Map<String, Object> def = (Map<String, Object>) str.get("definitions");
final Map<String, Object> img = (Map<String, Object>) def.get("Image");
final Map<String, Object> pro = (Map<String, Object>) img.get("properties");
final Map<String, Object> tn = (Map<String, Object>) pro.get("tnMid");
assertEquals("Export of custom property should contain format string.", "300, 300, false", tn.get("format"));
tx.success();
} catch (FrameworkException | URISyntaxException t) {
t.printStackTrace();
fail("Unexpected exception");
}
}
use of org.structr.common.error.FrameworkException in project structr by structr.
the class DirectFileImportTest method testDirectFileImportWithExistingFileCopyOverwrite.
@Test
public void testDirectFileImportWithExistingFileCopyOverwrite() {
try (final Tx tx = app.tx()) {
FileHelper.createFile(securityContext, "initial content".getBytes("utf-8"), "text/plain", File.class, "test.txt");
tx.success();
} catch (FrameworkException | IOException fex) {
fex.printStackTrace();
fail("Unexpected exception.");
}
Path testDir = null;
Path importPath = null;
try {
testDir = Files.createTempDirectory(Paths.get(basePath), "directFileImportTestFileCopyOverwrite");
importPath = testDir.resolve(Paths.get("test.txt"));
createTestFile(importPath, "test file content 1");
} catch (IOException ioex) {
fail("Unable to create test files.");
}
try (final Tx tx = app.tx()) {
app.command(DirectFileImportCommand.class).execute(setupParameters(importPath.toString(), "/", "COPY", "OVERWRITE", false));
tx.success();
} catch (FrameworkException ex) {
ex.printStackTrace();
fail("Unexpected exception.");
}
// verify successful file import
try (final Tx tx = app.tx()) {
final List<File> files = app.nodeQuery(File.class).getAsList();
// import mode SKIP => no change, no additional file
assertEquals("Only one file should exist after import", 1, files.size());
final File file = files.get(0);
assertNotNull("Test file should have been created by import", file);
assertEquals("Test file name should be test.txt", "test.txt", file.getName());
assertNull("Test file should NOT have a parent folder", file.getParent());
assertEquals("Test file content does not match source", "test file content 1", getContent(file));
tx.success();
} catch (FrameworkException ex) {
ex.printStackTrace();
fail("Unexpected exception.");
}
// verify source file exists after import
assertTrue("Source file should not be deleted after import", importPath.toFile().exists());
}
use of org.structr.common.error.FrameworkException in project structr by structr.
the class DirectFileImportTest method testDirectFileImportWithAbsoluteDirectory.
@Test
public void testDirectFileImportWithAbsoluteDirectory() {
final PropertyKey<String> pathKey = StructrApp.key(File.class, "path");
Path testDir = null;
String importPath = null;
try {
testDir = Files.createTempDirectory(Paths.get(basePath), "directFileImportTestAbsoluteDirectory");
createTestFile(testDir.resolve(Paths.get("test1.txt")), "test file content 1");
createTestFile(testDir.resolve(Paths.get("test2.txt")), "test file content 2");
createTestFile(testDir.resolve(Paths.get("test3.txt")), "test file content 3");
importPath = testDir.toString();
} catch (IOException ioex) {
fail("Unable to create test files.");
}
// do import
final Map<String, Object> attributes = new LinkedHashMap<>();
attributes.put("source", importPath);
try (final Tx tx = app.tx()) {
app.command(DirectFileImportCommand.class).execute(attributes);
tx.success();
} catch (FrameworkException ex) {
ex.printStackTrace();
fail("Unexpected exception.");
}
// verify successful file import
try (final Tx tx = app.tx()) {
assertNotNull("Folder should have been created by import", app.nodeQuery(Folder.class).and(pathKey, "/" + testDir.getFileName().toString()).getFirst());
final File file1 = app.nodeQuery(File.class).and(pathKey, "/" + testDir.getFileName().toString() + "/test1.txt").getFirst();
final File file2 = app.nodeQuery(File.class).and(pathKey, "/" + testDir.getFileName().toString() + "/test2.txt").getFirst();
final File file3 = app.nodeQuery(File.class).and(pathKey, "/" + testDir.getFileName().toString() + "/test3.txt").getFirst();
assertNotNull("Test file should have been created by import", file1);
assertNotNull("Test file should have been created by import", file2);
assertNotNull("Test file should have been created by import", file3);
assertEquals("Imported test file content does not match source", "test file content 1", getContent(file1));
assertEquals("Imported test file content does not match source", "test file content 2", getContent(file2));
assertEquals("Imported test file content does not match source", "test file content 3", getContent(file3));
tx.success();
} catch (FrameworkException ex) {
ex.printStackTrace();
fail("Unexpected exception.");
}
}
use of org.structr.common.error.FrameworkException in project structr by structr.
the class DirectFileImportTest method testDirectFileImportWithRelativeDirectory.
@Test
public void testDirectFileImportWithRelativeDirectory() {
final PropertyKey<String> pathKey = StructrApp.key(File.class, "path");
final String dirName = "directFileImportTestRelativeDirectory";
final Path base = Paths.get(basePath);
Path testDir = null;
try {
testDir = Files.createDirectory(base.resolve(dirName));
createTestFile(testDir.resolve(Paths.get("test1.txt")), "test file content 1");
createTestFile(testDir.resolve(Paths.get("test2.txt")), "test file content 2");
createTestFile(testDir.resolve(Paths.get("test3.txt")), "test file content 3");
} catch (IOException ioex) {
fail("Unable to create test files.");
}
// do import
try (final Tx tx = app.tx()) {
app.command(DirectFileImportCommand.class).execute(setupParameters(dirName, "/", "COPY", "OVERWRITE", false));
tx.success();
} catch (FrameworkException ex) {
ex.printStackTrace();
fail("Unexpected exception.");
}
// verify successful file import
try (final Tx tx = app.tx()) {
assertNotNull("Folder should have been created by import", app.nodeQuery(Folder.class).and(pathKey, "/" + testDir.getFileName().toString()).getFirst());
final File file1 = app.nodeQuery(File.class).and(pathKey, "/" + testDir.getFileName().toString() + "/test1.txt").getFirst();
final File file2 = app.nodeQuery(File.class).and(pathKey, "/" + testDir.getFileName().toString() + "/test2.txt").getFirst();
final File file3 = app.nodeQuery(File.class).and(pathKey, "/" + testDir.getFileName().toString() + "/test3.txt").getFirst();
assertNotNull("Test file should have been created by import", file1);
assertNotNull("Test file should have been created by import", file2);
assertNotNull("Test file should have been created by import", file3);
assertEquals("Imported test file content does not match source", "test file content 1", getContent(file1));
assertEquals("Imported test file content does not match source", "test file content 2", getContent(file2));
assertEquals("Imported test file content does not match source", "test file content 3", getContent(file3));
tx.success();
} catch (FrameworkException ex) {
ex.printStackTrace();
fail("Unexpected exception.");
}
}
Aggregations