use of org.structr.core.entity.TestOne in project structr by structr.
the class SearchAndSortingTest method test07SortByIntWithNullValues.
@Test
public void test07SortByIntWithNullValues() {
try {
final List<TestOne> nodes = this.createTestNodes(TestOne.class, 10);
try (final Tx tx = app.tx()) {
int i = 0;
for (NodeInterface node : nodes) {
node.setProperty(AbstractNode.name, Long.toString(i));
if (i < 7) {
node.setProperty(TestOne.anInt, i);
}
i++;
}
tx.success();
}
try (final Tx tx = app.tx()) {
boolean sortDesc = false;
final List<TestOne> result = app.nodeQuery(TestOne.class).sort(TestOne.anInt).order(sortDesc).getAsList();
// check that the sorting is stable, i.e. the position of nodes
// with equal values (and null) is not modified by sorting
final Iterator<TestOne> nameIterator = result.iterator();
while (nameIterator.hasNext()) {
// nulls first
assertEquals("Invalid sort result with mixed values (null vs. int)", "7", nameIterator.next().getProperty(TestOne.name));
assertEquals("Invalid sort result with mixed values (null vs. int)", "8", nameIterator.next().getProperty(TestOne.name));
assertEquals("Invalid sort result with mixed values (null vs. int)", "9", nameIterator.next().getProperty(TestOne.name));
// other values after that
assertEquals("Invalid sort result with mixed values (null vs. int)", "0", nameIterator.next().getProperty(TestOne.name));
assertEquals("Invalid sort result with mixed values (null vs. int)", "1", nameIterator.next().getProperty(TestOne.name));
assertEquals("Invalid sort result with mixed values (null vs. int)", "2", nameIterator.next().getProperty(TestOne.name));
assertEquals("Invalid sort result with mixed values (null vs. int)", "3", nameIterator.next().getProperty(TestOne.name));
assertEquals("Invalid sort result with mixed values (null vs. int)", "4", nameIterator.next().getProperty(TestOne.name));
assertEquals("Invalid sort result with mixed values (null vs. int)", "5", nameIterator.next().getProperty(TestOne.name));
assertEquals("Invalid sort result with mixed values (null vs. int)", "6", nameIterator.next().getProperty(TestOne.name));
}
// check that the sorting is "nulls first" as documented
final Iterator<TestOne> intIterator = result.iterator();
while (intIterator.hasNext()) {
// nulls first
assertEquals("Invalid sort result with mixed values (null vs. int)", null, intIterator.next().getProperty(TestOne.anInt));
assertEquals("Invalid sort result with mixed values (null vs. int)", null, intIterator.next().getProperty(TestOne.anInt));
assertEquals("Invalid sort result with mixed values (null vs. int)", null, intIterator.next().getProperty(TestOne.anInt));
// other values after that
assertEquals("Invalid sort result with mixed values (null vs. int)", 0L, (long) intIterator.next().getProperty(TestOne.anInt));
assertEquals("Invalid sort result with mixed values (null vs. int)", 1L, (long) intIterator.next().getProperty(TestOne.anInt));
assertEquals("Invalid sort result with mixed values (null vs. int)", 2L, (long) intIterator.next().getProperty(TestOne.anInt));
assertEquals("Invalid sort result with mixed values (null vs. int)", 3L, (long) intIterator.next().getProperty(TestOne.anInt));
assertEquals("Invalid sort result with mixed values (null vs. int)", 4L, (long) intIterator.next().getProperty(TestOne.anInt));
assertEquals("Invalid sort result with mixed values (null vs. int)", 5L, (long) intIterator.next().getProperty(TestOne.anInt));
assertEquals("Invalid sort result with mixed values (null vs. int)", 6L, (long) intIterator.next().getProperty(TestOne.anInt));
}
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 test03SeachByNamePropertyLooseLowercase.
@Test
public void test03SeachByNamePropertyLooseLowercase() {
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", 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 test01SeachByName.
@Test
public void test01SeachByName() {
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<TestOne> result = app.nodeQuery(type).getResult();
assertEquals(4, result.size());
for (NodeInterface node : result.getResults()) {
System.out.println(node);
}
result = app.nodeQuery(type).andName("TestOne-12").getResult();
assertEquals(1, 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 test09SearchBySourceAndTargetId.
@Test
public void test09SearchBySourceAndTargetId() {
try {
final TestOne test1 = createTestNode(TestOne.class);
final List<TestSix> tests = createTestNodes(TestSix.class, 5);
try (final Tx tx = app.tx()) {
test1.setProperty(TestOne.manyToManyTestSixs, tests);
tx.success();
}
try (final Tx tx = app.tx()) {
final List<SixOneManyToMany> result1 = app.relationshipQuery(SixOneManyToMany.class).and(SixOneManyToMany.sourceId, tests.get(0).getUuid()).getAsList();
assertEquals("Invalid sourceId query result", 1, result1.size());
tx.success();
}
try (final Tx tx = app.tx()) {
final List<SixOneManyToMany> result1 = app.relationshipQuery(SixOneManyToMany.class).and(SixOneManyToMany.targetId, test1.getUuid()).getAsList();
assertEquals("Invalid targetId query result", 5, result1.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 test06InexactSearchWithHyphen.
@Test
public void test06InexactSearchWithHyphen() {
final Map<String, Integer> testResults = new LinkedHashMap<>();
testResults.put("ABCDE12345", 1);
testResults.put("ABCDE#1234", 1);
testResults.put("ABCDE+2345", 1);
testResults.put("ABCDE-2345", 1);
testResults.put("ABCDE!2345", 1);
testResults.put("ABCDE(2345", 1);
testResults.put("ABCDE)2345", 1);
testResults.put("ABCDE:2345", 1);
testResults.put("ABCDE^2345", 1);
testResults.put("ABCDE[2345", 1);
testResults.put("ABCDE]2345", 1);
testResults.put("ABCDE\"2345", 1);
testResults.put("ABCDE{2345", 1);
testResults.put("ABCDE}2345", 1);
testResults.put("ABCDE~2345", 1);
testResults.put("ABCDE*2345", 1);
testResults.put("ABCDE?2345", 1);
testResults.put("ABCDE|2345", 1);
testResults.put("ABCDE&2345", 1);
testResults.put("ABCDE;2345", 1);
testResults.put("ABCDE/2345", 1);
try {
try (final Tx tx = app.tx()) {
for (final String source : testResults.keySet()) {
app.create(TestOne.class, source);
}
tx.success();
}
try (final Tx tx = app.tx()) {
for (final String source : testResults.keySet()) {
final String query = source.substring(0, 6);
final int count = testResults.get(source);
final List<TestOne> result = app.nodeQuery(TestOne.class).and(AbstractNode.name, query, false).getAsList();
assertEquals("Unexpected query result for special char query " + query, count, result.size());
}
tx.success();
}
} catch (FrameworkException ex) {
logger.error(ex.toString());
fail("Unexpected exception");
}
}
Aggregations