use of org.structr.core.property.PropertyKey in project structr by structr.
the class ValidationTest method testDatePropertyNotNullValidation.
@Test
public void testDatePropertyNotNullValidation() {
final String keyName = "notnull";
final Class<NodeInterface> testType = createTypeWithProperty("Test", keyName, "+Date");
final PropertyKey key = StructrApp.key(testType, keyName);
if (key != null) {
// test failure
try (final Tx tx = app.tx()) {
app.create(testType, new NodeAttribute<>(key, null));
tx.success();
fail("Date property not null constraint violated!");
} catch (FrameworkException fex) {
final List<ErrorToken> tokens = fex.getErrorBuffer().getErrorTokens();
final ErrorToken token = tokens.get(0);
assertEquals("Invalid date validation result", 1, tokens.size());
assertEquals("Invalid date validation result", 422, fex.getStatus());
assertEquals("Invalid date validation result", keyName, token.getProperty());
assertEquals("Invalid date validation result", "Test", token.getType());
assertEquals("Invalid date validation result", "must_not_be_empty", token.getToken());
}
}
}
use of org.structr.core.property.PropertyKey in project structr by structr.
the class ValidationTest method testIntPropertyNotNullValidation.
@Test
public void testIntPropertyNotNullValidation() {
final String keyName = "notnull";
final Class<NodeInterface> testType = createTypeWithProperty("Test", keyName, "+Integer");
final PropertyKey key = StructrApp.key(testType, keyName);
if (key != null) {
// test failure
try (final Tx tx = app.tx()) {
app.create(testType, new NodeAttribute<>(key, null));
tx.success();
fail("Int property not null constraint violated!");
} catch (FrameworkException fex) {
final List<ErrorToken> tokens = fex.getErrorBuffer().getErrorTokens();
final ErrorToken token = tokens.get(0);
assertEquals("Invalid int validation result", 1, tokens.size());
assertEquals("Invalid int validation result", 422, fex.getStatus());
assertEquals("Invalid int validation result", keyName, token.getProperty());
assertEquals("Invalid int validation result", "Test", token.getType());
assertEquals("Invalid int validation result", "must_not_be_empty", token.getToken());
}
}
}
use of org.structr.core.property.PropertyKey in project structr by structr.
the class ValidationTest method testDoublePropertyRangeValidation4.
@Test
public void testDoublePropertyRangeValidation4() {
final Class<NodeInterface> testType = createTypeWithProperty("Test", "range1", "+Double(]0.0,0.5])");
final PropertyKey range1 = StructrApp.key(testType, "range1");
checkRangeSuccess(testType, range1, 0.00001);
checkRangeSuccess(testType, range1, 0.1);
checkRangeSuccess(testType, range1, 0.2);
checkRangeSuccess(testType, range1, 0.3);
checkRangeSuccess(testType, range1, 0.4);
checkRangeSuccess(testType, range1, 0.49999);
checkRangeSuccess(testType, range1, 0.5);
try {
checkRangeError(testType, range1, -0.0);
} catch (FrameworkException fex) {
checkException(fex, 1, 422, "Test", "range1", "must_be_in_range");
}
try {
checkRangeError(testType, range1, 0.0);
} catch (FrameworkException fex) {
checkException(fex, 1, 422, "Test", "range1", "must_be_in_range");
}
try {
checkRangeError(testType, range1, -0.00001);
} catch (FrameworkException fex) {
checkException(fex, 1, 422, "Test", "range1", "must_be_in_range");
}
try {
checkRangeError(testType, range1, 0.51);
} catch (FrameworkException fex) {
checkException(fex, 1, 422, "Test", "range1", "must_be_in_range");
}
try {
checkRangeError(testType, range1, 1.51);
} 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 testDoublePropertyRangeValidation3.
@Test
public void testDoublePropertyRangeValidation3() {
final Class<NodeInterface> testType = createTypeWithProperty("Test", "range1", "+Double([0.0,0.5[)");
final PropertyKey range1 = StructrApp.key(testType, "range1");
checkRangeSuccess(testType, range1, -0.0);
checkRangeSuccess(testType, range1, 0.0);
checkRangeSuccess(testType, range1, 0.00001);
checkRangeSuccess(testType, range1, 0.1);
checkRangeSuccess(testType, range1, 0.2);
checkRangeSuccess(testType, range1, 0.3);
checkRangeSuccess(testType, range1, 0.4);
checkRangeSuccess(testType, range1, 0.49999);
try {
checkRangeError(testType, range1, -0.00001);
} catch (FrameworkException fex) {
checkException(fex, 1, 422, "Test", "range1", "must_be_in_range");
}
try {
checkRangeError(testType, range1, 0.5);
} catch (FrameworkException fex) {
checkException(fex, 1, 422, "Test", "range1", "must_be_in_range");
}
try {
checkRangeError(testType, range1, 0.51);
} catch (FrameworkException fex) {
checkException(fex, 1, 422, "Test", "range1", "must_be_in_range");
}
try {
checkRangeError(testType, range1, 1.51);
} 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 testEmptyStringPropertyValidationWithEmptyStrings.
// ----- string property validation tests -----
@Test
public void testEmptyStringPropertyValidationWithEmptyStrings() {
try (final Tx tx = app.tx()) {
app.create(SchemaNode.class, new NodeAttribute<>(AbstractNode.name, "Test"), new NodeAttribute<>(new StringProperty("_testUnique"), "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, "testUnique");
if (key != null) {
String uuid = null;
try (final Tx tx = app.tx()) {
// for string properties, null equals the empty string
uuid = app.create(testType, new NodeAttribute<>(key, "")).getUuid();
app.create(testType, new NodeAttribute<>(key, ""));
tx.success();
fail("Uniqueness 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", "testUnique", token.getProperty());
assertEquals("Invalid uniqueness validation result", "Test", token.getType());
assertEquals("Invalid uniqueness validation result", "already_taken", token.getToken());
assertEquals("Invalid uniqueness validation result", uuid, token.getDetail());
}
}
}
}
Aggregations