use of org.structr.core.entity.TestOne in project structr by structr.
the class SearchAndSortingTest method test08PagingWithHiddenOrDeletedElements.
@Test
public void test08PagingWithHiddenOrDeletedElements() {
try {
// create 10 nodes
createTestNodes(TestOne.class, 10);
} catch (FrameworkException fex) {
fail("Unexpected exception.");
}
try (final Tx tx = app.tx()) {
final List<TestOne> testOnes = app.nodeQuery(TestOne.class).getAsList();
final TestOne test1 = testOnes.get(3);
final TestOne test2 = testOnes.get(4);
final TestOne test3 = testOnes.get(7);
test1.setProperty(AbstractNode.hidden, true);
test2.setProperty(AbstractNode.deleted, true);
test3.setProperty(AbstractNode.hidden, true);
test3.setProperty(AbstractNode.deleted, true);
tx.success();
} catch (FrameworkException fex) {
fail("Unexpected exception.");
}
try (final Tx tx = app.tx()) {
final Result<TestOne> result = app.nodeQuery(TestOne.class).includeDeletedAndHidden(false).getResult();
assertEquals("Result count should not include deleted or hidden nodes", 7, (int) result.getRawResultCount());
assertEquals("Actual result size should be equal to result count", 7, (int) result.getResults().size());
tx.success();
} catch (FrameworkException fex) {
fail("Unexpected exception.");
}
}
use of org.structr.core.entity.TestOne in project structr by structr.
the class SearchAndSortingTest method test01SortByName.
@Test
public void test01SortByName() {
try {
Class type = TestOne.class;
// no more than 89 to avoid sort order TestOne-10, TestOne-100 ...
int number = 4;
final List<NodeInterface> nodes = this.createTestNodes(type, number);
final int offset = 10;
Collections.shuffle(nodes, new Random(System.nanoTime()));
try (final Tx tx = app.tx()) {
int i = offset;
String name;
for (NodeInterface node : nodes) {
// System.out.println("Node ID: " + node.getNodeId());
name = "TestOne-" + i;
i++;
node.setProperty(AbstractNode.name, name);
}
tx.success();
}
try (final Tx tx = app.tx()) {
Result result = app.nodeQuery(type).getResult();
assertEquals(number, result.size());
PropertyKey sortKey = AbstractNode.name;
boolean sortDesc = false;
int pageSize = 10;
int page = 1;
result = app.nodeQuery(type).sort(sortKey).order(sortDesc).page(page).pageSize(pageSize).getResult();
logger.info("Raw result size: {}, expected: {}", new Object[] { result.getRawResultCount(), number });
assertEquals(number, (int) result.getRawResultCount());
logger.info("Result size: {}, expected: {}", new Object[] { result.size(), Math.min(number, pageSize) });
assertEquals(Math.min(number, pageSize), result.size());
for (int j = 0; j < Math.min(result.size(), pageSize); j++) {
String expectedName = "TestOne-" + (offset + j);
String gotName = result.get(j).getProperty(AbstractNode.name);
System.out.println(expectedName + ", got: " + gotName);
assertEquals(expectedName, gotName);
}
tx.success();
}
} catch (FrameworkException ex) {
logger.error(ex.toString());
fail("Unexpected exception");
}
}
use of org.structr.core.entity.TestOne in project structr by structr.
the class SearchAndSortingTest method test01ParallelInstantiationPerformance.
@Test
public void test01ParallelInstantiationPerformance() {
try {
for (int i = 0; i < 10; i++) {
System.out.println("Creating nodes..");
createTestNodes(TestOne.class, 100);
}
} catch (FrameworkException fex) {
fail("Unexpected exception.");
}
try (final Tx tx = app.tx()) {
System.out.println("Loading nodes..");
final List<TestOne> testOnes = app.nodeQuery(TestOne.class).getAsList();
tx.success();
} catch (FrameworkException fex) {
fail("Unexpected exception.");
}
}
use of org.structr.core.entity.TestOne in project structr by structr.
the class SearchAndSortingTest method test05SeachByDefaultValue.
@Test
public void test05SeachByDefaultValue() {
try {
Class type = TestOne.class;
int number = 4;
final List<NodeInterface> nodes = this.createTestNodes(type, number);
final int offset = 10;
Collections.shuffle(nodes, new Random(System.nanoTime()));
try (final Tx tx = app.tx()) {
int i = offset;
String name;
for (NodeInterface node : nodes) {
// System.out.println("Node ID: " + node.getNodeId());
name = "TestOne-" + i;
i++;
node.setProperty(AbstractNode.name, name);
}
tx.success();
}
try (final Tx tx = app.tx()) {
Result result = app.nodeQuery(type).and(TestOne.stringWithDefault, "default value", false).getResult();
assertEquals(4, result.size());
tx.success();
}
} catch (FrameworkException ex) {
logger.error(ex.toString());
fail("Unexpected exception");
}
}
use of org.structr.core.entity.TestOne in project structr by structr.
the class SearchAndSortingTest method test02SeachByNameProperty.
@Test
public void test02SeachByNameProperty() {
try {
Class type = TestOne.class;
int number = 4;
final List<NodeInterface> nodes = this.createTestNodes(type, number);
final int offset = 10;
Collections.shuffle(nodes, new Random(System.nanoTime()));
try (final Tx tx = app.tx()) {
int i = offset;
String name;
for (NodeInterface node : nodes) {
// System.out.println("Node ID: " + node.getNodeId());
name = "TestOne-" + i;
i++;
node.setProperty(AbstractNode.name, name);
}
tx.success();
}
try (final Tx tx = app.tx()) {
Result result = app.nodeQuery(type).and(TestOne.name, "TestOne-13").getResult();
assertEquals(1, result.size());
tx.success();
}
} catch (FrameworkException ex) {
logger.error(ex.toString());
fail("Unexpected exception");
}
}
Aggregations