use of org.structr.core.Result in project structr by structr.
the class AccessControlTest method test05FrontendUserAccessToProtectedNode.
@Test
public void test05FrontendUserAccessToProtectedNode() {
// remove auto-generated resource access objects
clearResourceAccess();
try {
List<Principal> users = createTestNodes(Principal.class, 2);
Principal user1 = (Principal) users.get(0);
Principal user2 = (Principal) users.get(1);
PropertyMap props = new PropertyMap();
props.put(AbstractNode.visibleToPublicUsers, true);
// Create two nodes with user context, one of them is visible to public users
Class type = TestOne.class;
TestOne t1 = createTestNode(TestOne.class, props, user1);
props = new PropertyMap();
props.put(AbstractNode.visibleToAuthenticatedUsers, true);
TestOne t2 = createTestNode(TestOne.class, props, user1);
// Let another user search
SecurityContext user2Context = SecurityContext.getInstance(user2, AccessMode.Frontend);
try (final Tx tx = app.tx()) {
Result result = StructrApp.getInstance(user2Context).nodeQuery(type).getResult();
assertEquals(2, result.size());
}
} catch (FrameworkException ex) {
logger.warn("", ex);
fail("Unexpected exception");
}
}
use of org.structr.core.Result in project structr by structr.
the class AccessControlTest method test07ResultCountWithPaging.
@Test
public void test07ResultCountWithPaging() {
// remove auto-generated resource access objects
clearResourceAccess();
try {
final Class type = TestOne.class;
final List<NodeInterface> nodes = createTestNodes(type, 10);
int count = 0;
try (final Tx tx = app.tx()) {
// add names to make sorting work...
for (final NodeInterface node : nodes) {
node.setProperty(AbstractNode.name, "node0" + count++);
}
nodes.get(3).setProperty(AbstractNode.visibleToPublicUsers, true);
nodes.get(5).setProperty(AbstractNode.visibleToPublicUsers, true);
nodes.get(7).setProperty(AbstractNode.visibleToPublicUsers, true);
nodes.get(9).setProperty(AbstractNode.visibleToPublicUsers, true);
tx.success();
}
SecurityContext publicContext = SecurityContext.getInstance(null, AccessMode.Frontend);
PropertyKey sortKey = AbstractNode.name;
boolean sortDesc = false;
int pageSize = 2;
int page = 1;
try (final Tx tx = app.tx()) {
Result result = StructrApp.getInstance(publicContext).nodeQuery(type).sort(sortKey).order(sortDesc).page(page).pageSize(pageSize).getResult();
assertEquals(2, result.size());
assertEquals(4, (int) result.getRawResultCount());
assertEquals(nodes.get(3).getUuid(), result.get(0).getUuid());
assertEquals(nodes.get(5).getUuid(), result.get(1).getUuid());
}
} catch (FrameworkException ex) {
logger.warn("", ex);
fail("Unexpected exception");
}
}
use of org.structr.core.Result in project structr by structr.
the class BasicTest method test01DeleteNode.
/**
* Test successful deletion of a node.
*
* The node shouldn't be found afterwards.
* Creation and deletion are executed in two different transactions.
*/
@Test
public void test01DeleteNode() {
try {
final PropertyMap props = new PropertyMap();
final String type = "GenericNode";
final String name = "GenericNode-name";
NodeInterface node = null;
String uuid = null;
props.put(AbstractNode.type, type);
props.put(AbstractNode.name, name);
try (final Tx tx = app.tx()) {
node = app.create(GenericNode.class, props);
tx.success();
}
assertTrue(node != null);
try (final Tx tx = app.tx()) {
uuid = node.getUuid();
}
try (final Tx tx = app.tx()) {
app.delete(node);
tx.success();
}
try (final Tx tx = app.tx()) {
Result result = app.nodeQuery().uuid(uuid).getResult();
assertEquals("Node should have been deleted", 0, result.size());
} catch (FrameworkException fe) {
}
} 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 test02Paging.
/**
* Test different pages and page sizes
*/
@Test
public void test02Paging() {
try {
boolean includeDeletedAndHidden = false;
boolean publicOnly = false;
Class type = TestOne.class;
// no more than 89 to avoid sort order TestOne-10, TestOne-100 ...
int number = 89;
final int offset = 10;
final List<NodeInterface> nodes = this.createTestNodes(type, number);
Collections.shuffle(nodes, new Random(System.nanoTime()));
try (final Tx tx = app.tx()) {
int i = offset;
for (NodeInterface node : nodes) {
// System.out.println("Node ID: " + node.getNodeId());
String _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;
// test pages sizes from 0 to 10
for (int ps = 0; ps < 10; ps++) {
// test all pages
for (int p = 0; p < (number / Math.max(1, ps)) + 1; p++) {
testPaging(type, ps, p, number, offset, includeDeletedAndHidden, publicOnly, sortKey, sortDesc);
}
}
}
} 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 test08SearchByStaticMethodWithNullSearchValue01.
@Test
public void test08SearchByStaticMethodWithNullSearchValue01() {
try {
PropertyMap props = new PropertyMap();
final PropertyKey key = AbstractNode.name;
final String name = "abc";
props.put(key, name);
createTestNode(TestOne.class, props);
try (final Tx tx = app.tx()) {
Result result = app.nodeQuery(TestOne.class).andName(null).includeDeletedAndHidden().getResult();
assertTrue(result.isEmpty());
}
} catch (FrameworkException ex) {
logger.warn("", ex);
logger.error(ex.toString());
fail("Unexpected exception");
}
}
Aggregations