use of org.structr.core.entity.TestEleven in project structr by structr.
the class MaintenanceTest method testSyncCommandInheritance.
@Test
public void testSyncCommandInheritance() {
try {
// create test nodes
final List<TestEleven> testNodes = createTestNodes(TestEleven.class, 10);
final String tenantIdentifier = app.getDatabaseService().getTenantIdentifier();
int labelCount = 7;
// one additional label
if (tenantIdentifier != null) {
labelCount += 1;
}
try (final Tx tx = app.tx()) {
for (final TestEleven node : testNodes) {
Iterable<Label> labels = node.getNode().getLabels();
assertEquals(labelCount, Iterables.count(labels));
for (final Label label : labels) {
System.out.print(label.name() + " ");
}
System.out.println();
final Set<String> names = Iterables.toSet(labels).stream().map(Label::name).collect(Collectors.toSet());
assertEquals("Number of labels must be 7", labelCount, names.size());
assertTrue("Set of labels must contain AbstractNode", names.contains("AbstractNode"));
assertTrue("Set of labels must contain NodeInterface", names.contains("NodeInterface"));
assertTrue("Set of labels must contain AccessControllable", names.contains("AccessControllable"));
assertTrue("Set of labels must contain CMISInfo", names.contains("CMISInfo"));
assertTrue("Set of labels must contain CMISItemInfo", names.contains("CMISItemInfo"));
assertTrue("Set of labels must contain TestOne", names.contains("TestOne"));
assertTrue("Set of labels must contain TestEleven", names.contains("TestEleven"));
if (tenantIdentifier != null) {
assertTrue("Set of labels must contain custom tenant identifier if set", names.contains(tenantIdentifier));
}
}
tx.success();
}
// test export
app.command(SyncCommand.class).execute(toMap("mode", "export", "file", EXPORT_FILENAME));
final Path exportFile = Paths.get(EXPORT_FILENAME);
assertTrue("Export file doesn't exist!", Files.exists(exportFile));
// stop existing and start new database
stopSystem();
startSystem();
// test import
app.command(SyncCommand.class).execute(toMap("mode", "import", "file", EXPORT_FILENAME));
final DatabaseService db = app.getDatabaseService();
try (final Tx tx = app.tx()) {
final Result<TestEleven> result = app.nodeQuery(TestEleven.class).getResult();
assertEquals(10, result.size());
for (final TestEleven node : result.getResults()) {
Iterable<Label> labels = node.getNode().getLabels();
final Set<Label> set = new HashSet<>(Iterables.toList(labels));
assertEquals(labelCount, set.size());
assertTrue("First label has to be AbstractNode", set.contains(db.forName(Label.class, "AbstractNode")));
assertTrue("Second label has to be NodeInterface", set.contains(db.forName(Label.class, "NodeInterface")));
assertTrue("Third label has to be AccessControllable", set.contains(db.forName(Label.class, "AccessControllable")));
assertTrue("Fourth label has to be CMISInfo", set.contains(db.forName(Label.class, "CMISInfo")));
assertTrue("Firth label has to be CMISItemInfo", set.contains(db.forName(Label.class, "CMISItemInfo")));
assertTrue("Sixth label has to be TestEleven", set.contains(db.forName(Label.class, "TestEleven")));
assertTrue("Seventh label has to be TestOne", set.contains(db.forName(Label.class, "TestOne")));
if (tenantIdentifier != null) {
assertTrue("Set of labels must contain custom tenant identifier if set", set.contains(db.forName(Label.class, tenantIdentifier)));
}
}
tx.success();
}
// clean-up after test
Files.delete(exportFile);
} catch (Exception ex) {
ex.printStackTrace();
logger.warn("", ex);
fail("Unexpected exception.");
}
}
Aggregations