use of org.structr.core.entity.TestOne in project structr by structr.
the class BasicTest method test01CreateNode.
@Test
public void test01CreateNode() {
try {
try {
// Create node out of transaction => should give a NotInTransactionException
app.create(TestOne.class);
fail("Should have raised a NotInTransactionException");
} catch (NotInTransactionException e) {
}
try {
// Try to create node without parameters => should fail
app.create(TestOne.class);
fail("Should have raised a NotInTransactionException");
} catch (NotInTransactionException e) {
}
AbstractNode node = null;
try (final Tx tx = app.tx()) {
node = app.create(TestOne.class);
tx.success();
}
assertTrue(node != null);
assertTrue(node instanceof TestOne);
} catch (FrameworkException ex) {
logger.error("", ex);
fail("Unexpected exception");
}
}
use of org.structr.core.entity.TestOne in project structr by structr.
the class BasicTest method test06DuplicateRelationshipsOneToOne.
@Test
public void test06DuplicateRelationshipsOneToOne() {
try (final Tx tx = app.tx()) {
final TestOne test1 = app.create(TestOne.class);
final TestTwo test2 = app.create(TestTwo.class);
// test duplicate prevention
app.create(test1, test2, OneTwoOneToOne.class);
app.create(test1, test2, OneTwoOneToOne.class);
tx.success();
} catch (FrameworkException ex) {
fail("Creating duplicate relationships via app.create() should NOT throw an exception.");
}
try (final Tx tx = app.tx()) {
final TestOne test1 = app.create(TestOne.class);
final TestTwo test2 = app.create(TestTwo.class);
test1.setProperty(TestOne.testTwo, test2);
test1.setProperty(TestOne.testTwo, test2);
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 testNodeCreationWithForcedInvalidUuid.
@Test
public void testNodeCreationWithForcedInvalidUuid() {
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.id, null));
tx.success();
} catch (FrameworkException fex) {
logger.warn("", fex);
fail("Unexpected exception.");
}
try (final Tx tx = app.tx()) {
final String uuid1 = test.getProperty(GraphObject.id);
final String uuid2 = test.getUuid();
assertEquals("UUID mismatch in getProperty() and getUuid()", uuid1, uuid2);
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 test02CreateNodeWithExistingUuid.
@Test
public void test02CreateNodeWithExistingUuid() {
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);
tx.success();
}
try (final Tx tx = app.tx()) {
assertTrue(node != null);
assertTrue(node instanceof TestOne);
assertEquals(node.getUuid(), uuid);
}
} catch (FrameworkException ex) {
logger.error(ex.toString());
fail("Unexpected exception");
}
}
use of org.structr.core.entity.TestOne in project structr by structr.
the class BasicTest method testNodeCacheInvalidationInRelationshipWrapper.
@Test
public void testNodeCacheInvalidationInRelationshipWrapper() {
try (final Tx tx = app.tx()) {
final TestOne testOne = createTestNode(TestOne.class);
final TestTwo testTwo1 = createTestNode(TestTwo.class, new NodeAttribute<>(TestTwo.testOne, testOne));
final OneTwoOneToOne rel = testOne.getOutgoingRelationship(OneTwoOneToOne.class);
final TestTwo testTwo2 = rel.getTargetNode();
testTwo1.setProperty(AbstractNode.name, "test");
assertEquals("Cache invalidation failure!", "test", testTwo2.getProperty(AbstractNode.name));
tx.success();
} catch (FrameworkException fex) {
logger.warn("", fex);
fail("Unexpected exception.");
}
// fill cache with other nodes
try {
createTestNodes(TestSix.class, 1000);
} catch (FrameworkException fex) {
logger.warn("", fex);
fail("Unexpected exception.");
}
try (final Tx tx = app.tx()) {
final TestOne testOne = app.nodeQuery(TestOne.class).getFirst();
final TestTwo testTwo1 = app.nodeQuery(TestTwo.class).getFirst();
final OneTwoOneToOne rel = testOne.getOutgoingRelationship(OneTwoOneToOne.class);
final TestTwo testTwo2 = rel.getTargetNode();
testTwo1.setProperty(AbstractNode.name, "test2");
assertEquals("Cache invalidation failure!", "test2", testTwo2.getProperty(AbstractNode.name));
tx.success();
} catch (FrameworkException fex) {
logger.warn("", fex);
fail("Unexpected exception.");
}
}
Aggregations