use of org.structr.core.property.PropertyKey in project structr by structr.
the class ValidationTest method testLongPropertyRangeValidation5.
@Test
public void testLongPropertyRangeValidation5() {
final Class<NodeInterface> testType = createTypeWithProperty("Test", "range1", "+Long(]0,5[)");
final PropertyKey range1 = StructrApp.key(testType, "range1");
checkRangeSuccess(testType, range1, 1);
checkRangeSuccess(testType, range1, 2);
checkRangeSuccess(testType, range1, 3);
checkRangeSuccess(testType, range1, 4);
try {
checkRangeError(testType, range1, 0);
} catch (FrameworkException fex) {
checkException(fex, 1, 422, "Test", "range1", "must_be_in_range");
}
try {
checkRangeError(testType, range1, 5);
} catch (FrameworkException fex) {
checkException(fex, 1, 422, "Test", "range1", "must_be_in_range");
}
try {
checkRangeError(testType, range1, 6);
} catch (FrameworkException fex) {
checkException(fex, 1, 422, "Test", "range1", "must_be_in_range");
}
}
use of org.structr.core.property.PropertyKey in project structr by structr.
the class ValidationTest method testConcurrentValidationOnDynamicProperty.
@Test
public void testConcurrentValidationOnDynamicProperty() {
final int count = 100;
try (final Tx tx = app.tx()) {
app.create(SchemaNode.class, new NodeAttribute(SchemaNode.name, "Item"), new NodeAttribute(new StringProperty("_testXYZ"), "+String!"));
tx.success();
} catch (FrameworkException fex) {
logger.warn("", fex);
fail("Unexpected exception.");
}
final Class type = StructrApp.getConfiguration().getNodeEntityClass("Item");
assertNotNull(type);
final PropertyKey testXYZ = StructrApp.key(type, "testXYZ");
assertNotNull(testXYZ);
final Runnable tester = new Runnable() {
@Override
public void run() {
for (int i = 0; i < count; i++) {
// testing must be done in an isolated transaction
try (final Tx tx = app.tx()) {
app.create(type, new NodeAttribute(testXYZ, "Item" + i));
tx.success();
} catch (FrameworkException fex) {
}
}
}
};
// submit three test instances
final ExecutorService executor = Executors.newCachedThreadPool();
final Future f1 = executor.submit(tester);
final Future f2 = executor.submit(tester);
final Future f3 = executor.submit(tester);
try {
f1.get();
f2.get();
f3.get();
} catch (Throwable ex) {
}
List<GraphObject> result = null;
try (final Tx tx = app.tx()) {
result = app.nodeQuery(type).getAsList();
tx.success();
} catch (FrameworkException fex) {
logger.warn("", fex);
fail("Unexpected exception.");
}
// verify that only count entities have been created.
assertEquals("Invalid concurrent validation result", count, result.size());
executor.shutdownNow();
}
use of org.structr.core.property.PropertyKey in project structr by structr.
the class ValidationTest method testEnumPropertyUniquenessValidation.
// ----- enum property validation tests -----
@Test
public void testEnumPropertyUniquenessValidation() {
final String keyName = "unique";
final Class<NodeInterface> testType = createTypeWithProperty("Test", keyName, "Enum(one, two, three)!");
final PropertyKey key = StructrApp.key(testType, keyName);
String uuid = null;
if (key != null) {
// test failure
try (final Tx tx = app.tx()) {
final Object value = ((EnumProperty) key).getEnumType().getEnumConstants()[0];
uuid = app.create(testType, new NodeAttribute<>(key, value)).getUuid();
app.create(testType, new NodeAttribute<>(key, value));
tx.success();
fail("Enum property uniqueness constraint violated!");
} catch (FrameworkException fex) {
final List<ErrorToken> tokens = fex.getErrorBuffer().getErrorTokens();
final ErrorToken token = tokens.get(0);
assertEquals("Invalid enum validation result", 1, tokens.size());
assertEquals("Invalid enum validation result", 422, fex.getStatus());
assertEquals("Invalid enum validation result", keyName, token.getProperty());
assertEquals("Invalid enum validation result", "Test", token.getType());
assertEquals("Invalid enum validation result", "already_taken", token.getToken());
assertEquals("Invalid enum validation result", uuid, token.getDetail());
}
}
}
use of org.structr.core.property.PropertyKey in project structr by structr.
the class ValidationTest method testStringPropertyNotNull.
@Test
public void testStringPropertyNotNull() {
try (final Tx tx = app.tx()) {
app.create(SchemaNode.class, new NodeAttribute<>(AbstractNode.name, "Test"), new NodeAttribute<>(new StringProperty("_nonempty"), "+String"));
tx.success();
} catch (FrameworkException fex) {
logger.warn("", fex);
fail("Unexpected exception.");
}
final Class testType = StructrApp.getConfiguration().getNodeEntityClass("Test");
if (testType != null) {
final PropertyKey key = StructrApp.key(testType, "nonempty");
if (key != null) {
try (final Tx tx = app.tx()) {
app.create(testType, new NodeAttribute<>(key, null));
tx.success();
fail("Not empty constraint violated!");
} catch (FrameworkException fex) {
final List<ErrorToken> tokens = fex.getErrorBuffer().getErrorTokens();
final ErrorToken token = tokens.get(0);
assertEquals("Invalid uniqueness validation result", 1, tokens.size());
assertEquals("Invalid uniqueness validation result", 422, fex.getStatus());
assertEquals("Invalid uniqueness validation result", "nonempty", token.getProperty());
assertEquals("Invalid uniqueness validation result", "Test", token.getType());
assertEquals("Invalid uniqueness validation result", "must_not_be_empty", token.getToken());
}
}
}
}
use of org.structr.core.property.PropertyKey in project structr by structr.
the class ValidationTest method testBooleanPropertyNotNullValidation.
// ----- boolean property validation tests -----
@Test
public void testBooleanPropertyNotNullValidation() {
final String keyName = "notNull";
final Class<NodeInterface> testType = createTypeWithProperty("Test", keyName, "+Boolean");
final PropertyKey key = StructrApp.key(testType, keyName);
if (key != null) {
// test failure
try (final Tx tx = app.tx()) {
/* Boolean properties are special. A boolean property will
* _always_ have a value, i.e. "null" equals "false" and
* will be returned as false.
*
* => a boolean property value can never be null!
*/
app.create(testType, new NodeAttribute<>(key, null));
app.create(testType, new NodeAttribute<>(key, true));
app.create(testType, new NodeAttribute<>(key, false));
tx.success();
} catch (FrameworkException fex) {
fail("Unexpected array property validation exception.");
}
}
}
Aggregations