use of org.structr.core.entity.TestOne in project structr by structr.
the class BasicTest method test02CreateTwoNodesWithSameUuidInSameTx.
@Test
public void test02CreateTwoNodesWithSameUuidInSameTx() {
try {
final PropertyMap props = new PropertyMap();
TestOne node = null;
final String uuid = StringUtils.replace(UUID.randomUUID().toString(), "-", "");
props.put(GraphObject.id, uuid);
try (final Tx tx = app.tx()) {
node = app.create(TestOne.class, props);
assertTrue(node != null);
assertTrue(node instanceof TestOne);
assertEquals(node.getUuid(), uuid);
node = app.create(TestOne.class, props);
tx.success();
fail("Validation failed!");
}
} catch (FrameworkException ex) {
}
}
use of org.structr.core.entity.TestOne in project structr by structr.
the class BasicTest method testCreateNodeWithAdditionalProperties.
@Test
public void testCreateNodeWithAdditionalProperties() {
TestOne test = null;
// create object with user context
try (final Tx tx = app.tx()) {
test = app.create(TestOne.class, new NodeAttribute<>(AbstractNode.name, "test"), new NodeAttribute<>(GraphObject.visibleToPublicUsers, true), new NodeAttribute<>(GraphObject.visibleToAuthenticatedUsers, true), new NodeAttribute<>(AbstractNode.deleted, true), new NodeAttribute<>(AbstractNode.hidden, true));
tx.success();
} catch (FrameworkException fex) {
logger.warn("", fex);
fail("Unexpected exception.");
}
// create object with user context
try (final Tx tx = app.tx()) {
assertEquals("Invalid create node result", "test", test.getProperty(AbstractNode.name));
assertEquals("Invalid create node result", true, test.getProperty(GraphObject.visibleToPublicUsers));
assertEquals("Invalid create node result", true, test.getProperty(GraphObject.visibleToAuthenticatedUsers));
assertEquals("Invalid create node result", true, test.getProperty(AbstractNode.deleted));
assertEquals("Invalid create node result", true, test.getProperty(AbstractNode.hidden));
tx.success();
} catch (FrameworkException fex) {
logger.warn("", fex);
fail("Unexpected exception.");
}
}
use of org.structr.core.entity.TestOne in project structr by structr.
the class BasicTest method testRelationshipEndNodeTypeRestriction.
@Test
public void testRelationshipEndNodeTypeRestriction() {
// types are filtered according to the types of their end nodes
try (final Tx tx = app.tx()) {
// create two OWNS relationships with different end node types
final TestOne testOne = app.create(TestOne.class, "testone");
final TestThree testThree = app.create(TestThree.class, "testthree");
final Principal testUser = app.create(Principal.class, "testuser");
testOne.setProperty(TestOne.testThree, testThree);
testThree.setProperty(TestThree.owner, testUser);
tx.success();
} catch (FrameworkException fex) {
logger.warn("", fex);
fail("Unexpected exception.");
}
try (final Tx tx = app.tx()) {
final List<OneThreeOneToOne> rels = app.relationshipQuery(OneThreeOneToOne.class).getAsList();
assertEquals("Relationship query returns wrong number of results", 1, rels.size());
for (final OneThreeOneToOne rel : rels) {
assertEquals("Relationship query returns wrong type", OneThreeOneToOne.class, rel.getClass());
}
tx.success();
} catch (FrameworkException fex) {
logger.warn("", fex);
fail("Unexpected exception.");
}
}
use of org.structr.core.entity.TestOne in project structr by structr.
the class BasicTest method test06DuplicateRelationshipsManyToMany.
@Test
public void test06DuplicateRelationshipsManyToMany() {
try (final Tx tx = app.tx()) {
final TestSix test1 = app.create(TestSix.class);
final TestOne test2 = app.create(TestOne.class);
// test duplicate prevention
app.create(test1, test2, SixOneManyToMany.class);
app.create(test1, test2, SixOneManyToMany.class);
fail("Creating duplicate relationships should throw an exception.");
tx.success();
} catch (FrameworkException ex) {
}
// for manyToMany only.
try (final Tx tx = app.tx()) {
final TestSix test1 = app.create(TestSix.class);
final TestOne test2 = app.create(TestOne.class);
// test duplicate prevention
final List<TestOne> list = new LinkedList<>();
list.add(test2);
list.add(test2);
test1.setProperty(TestSix.manyToManyTestOnes, list);
tx.success();
} catch (FrameworkException ex) {
fail("Creating duplicate relationships via setProperty() should NOT throw an exception.");
}
}
use of org.structr.core.entity.TestOne in project structr by structr.
the class BasicTest method test01CompareAscending.
@Test
public void test01CompareAscending() {
try {
TestOne a = createTestNode(TestOne.class);
TestOne b = createTestNode(TestOne.class);
try (final Tx tx = app.tx()) {
GraphObjectComparator comp = new GraphObjectComparator(TestOne.anInt, GraphObjectComparator.ASCENDING);
try {
comp.compare(null, null);
fail("Should have raised an NullPointerException");
} catch (NullPointerException e) {
}
try {
comp.compare(a, null);
fail("Should have raised an NullPointerException");
} catch (NullPointerException e) {
}
try {
comp.compare(null, b);
fail("Should have raised an NullPointerException");
} catch (NullPointerException e) {
}
try {
comp.compare(null, b);
fail("Should have raised an NullPointerException");
} catch (NullPointerException e) {
}
// a: null
// b: null
// a == b => 0
assertEquals(0, comp.compare(a, b));
// a: 0
// b: null
// a < b => -1
setPropertyTx(a, TestOne.anInt, 0);
assertEquals(-1, comp.compare(a, b));
// a: null
// b: 0
// a > b => 1
setPropertyTx(a, TestOne.anInt, null);
setPropertyTx(b, TestOne.anInt, 0);
assertEquals(1, comp.compare(a, b));
// a: 1
// b: 2
// a < b => -1
setPropertyTx(a, TestOne.anInt, 1);
setPropertyTx(b, TestOne.anInt, 2);
assertEquals(-1, comp.compare(a, b));
// a: 2
// b: 1
// a > b => 1
setPropertyTx(a, TestOne.anInt, 2);
setPropertyTx(b, TestOne.anInt, 1);
assertEquals(1, comp.compare(a, b));
}
} catch (FrameworkException ex) {
logger.error(ex.toString());
fail("Unexpected exception");
}
}
Aggregations