use of org.structr.core.Result 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.Result in project structr by structr.
the class SearchAndSortingTest method test12SearchByEmptyLongField.
@Test
public void test12SearchByEmptyLongField() {
try {
PropertyMap props = new PropertyMap();
AbstractNode node = createTestNode(TestOne.class, props);
try (final Tx tx = app.tx()) {
Result result = app.nodeQuery(TestOne.class).and(TestOne.aLong, null).includeDeletedAndHidden().getResult();
assertTrue(result.size() == 1);
assertTrue(result.get(0).equals(node));
}
} catch (FrameworkException ex) {
logger.warn("", ex);
logger.error(ex.toString());
fail("Unexpected exception");
}
}
use of org.structr.core.Result in project structr by structr.
the class SearchAndSortingTest method test07SearchByStaticMethod01.
@Test
public void test07SearchByStaticMethod01() {
try {
PropertyMap props = new PropertyMap();
final PropertyKey key = AbstractNode.name;
final String name = "89w3hkl sdfghsdkljth";
props.put(key, name);
final AbstractNode node = createTestNode(TestOne.class, props);
try (final Tx tx = app.tx()) {
Result result = app.nodeQuery(TestOne.class).andName(name).includeDeletedAndHidden().getResult();
assertTrue(result.size() == 1);
assertTrue(result.get(0).equals(node));
}
} catch (FrameworkException ex) {
logger.warn("", ex);
logger.error(ex.toString());
fail("Unexpected exception");
}
}
use of org.structr.core.Result in project structr by structr.
the class SearchAndSortingTest method test04SortByDateDesc.
@Test
public void test04SortByDateDesc() {
try {
Class type = TestOne.class;
int number = 131;
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) {
name = Integer.toString(i);
i++;
node.setProperty(AbstractNode.name, name);
// slow down execution speed to make sure distinct changes fall in different milliseconds
try {
Thread.sleep(2);
} catch (Throwable t) {
}
}
tx.success();
}
try (final Tx tx = app.tx()) {
Result result = app.nodeQuery(type).getResult();
assertEquals(number, result.size());
PropertyKey sortKey = AbstractNode.lastModifiedDate;
boolean sortDesc = true;
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 });
assertTrue(result.getRawResultCount() == number);
logger.info("Result size: {}, expected: {}", new Object[] { result.size(), pageSize });
assertTrue(result.size() == Math.min(number, pageSize));
for (int j = 0; j < pageSize; j++) {
int expectedNumber = number + offset - 1 - j;
String gotName = result.get(j).getProperty(AbstractNode.name);
System.out.println(expectedNumber + ", got: " + gotName);
assertEquals(Integer.toString(expectedNumber), gotName);
}
tx.success();
}
} catch (FrameworkException ex) {
logger.error(ex.toString());
fail("Unexpected exception");
}
}
use of org.structr.core.Result in project structr by structr.
the class SearchAndSortingTest method test04SearchByLocation.
@Test
public void test04SearchByLocation() {
try {
final PropertyMap props = new PropertyMap();
final PropertyKey lat = TestSeven.latitude;
final PropertyKey lon = TestSeven.longitude;
final Class type = TestSeven.class;
props.put(lat, 50.12284d);
props.put(lon, 8.73923d);
props.put(AbstractNode.name, "TestSeven-0");
NodeInterface node = createTestNode(type, props);
try (final Tx tx = app.tx()) {
Result result = app.nodeQuery(type).location("Hanauer Landstraße", "200", "60314", "Frankfurt", "Germany", 10.0).includeDeletedAndHidden().getResult();
assertEquals(1, result.size());
assertTrue(result.get(0).equals(node));
}
} catch (FrameworkException ex) {
logger.warn("", ex);
logger.error(ex.toString());
fail("Unexpected exception");
}
}
Aggregations