use of org.structr.common.error.ErrorToken in project structr by structr.
the class ValidationTest method testLongPropertyNotNullValidation.
@Test
public void testLongPropertyNotNullValidation() {
final String keyName = "notnull";
final Class<NodeInterface> testType = createTypeWithProperty("Test", keyName, "+Long");
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("Long property not null constraint violated!");
} catch (FrameworkException fex) {
final List<ErrorToken> tokens = fex.getErrorBuffer().getErrorTokens();
final ErrorToken token = tokens.get(0);
assertEquals("Invalid long validation result", 1, tokens.size());
assertEquals("Invalid long validation result", 422, fex.getStatus());
assertEquals("Invalid long validation result", keyName, token.getProperty());
assertEquals("Invalid long validation result", "Test", token.getType());
assertEquals("Invalid long validation result", "must_not_be_empty", token.getToken());
}
}
}
use of org.structr.common.error.ErrorToken in project structr by structr.
the class ValidationTest method testInheritedStringPropertyUniqueness.
@Test
public void testInheritedStringPropertyUniqueness() {
try (final Tx tx = app.tx()) {
final SchemaNode testType = app.create(SchemaNode.class, new NodeAttribute<>(AbstractNode.name, "Test"), new NodeAttribute<>(new StringProperty("_testUnique"), "String!"));
app.create(SchemaNode.class, new NodeAttribute<>(AbstractNode.name, "TestDerived"), new NodeAttribute<>(SchemaNode.extendsClass, "org.structr.dynamic.Test"));
tx.success();
} catch (FrameworkException fex) {
fex.printStackTrace();
fail("Unexpected exception.");
}
final Class testType = StructrApp.getConfiguration().getNodeEntityClass("TestDerived");
if (testType != null) {
final PropertyKey key = StructrApp.key(testType, "testUnique");
if (key != null) {
Settings.CypherDebugLogging.setValue(true);
try (final Tx tx = app.tx()) {
// key must be unique, but can empty
app.create(testType, new NodeAttribute<>(key, "unique"));
app.create(testType, new NodeAttribute<>(key, ""));
tx.success();
} catch (FrameworkException fex) {
fex.printStackTrace();
fail("Unexpected exception.");
}
Settings.CypherDebugLogging.setValue(true);
for (int i = 0; i < 5; i++) {
try (final Tx tx = app.tx()) {
app.create(testType, new NodeAttribute<>(key, "unique"));
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", "TestDerived", token.getType());
assertEquals("Invalid uniqueness validation result", "already_taken", token.getToken());
}
}
}
}
}
use of org.structr.common.error.ErrorToken in project structr by structr.
the class ValidationTest method testLongPropertyUniquenessValidation.
// ----- long property validation tests -----
@Test
public void testLongPropertyUniquenessValidation() {
final String keyName = "unique";
final Class<NodeInterface> testType = createTypeWithProperty("Test", keyName, "Long!");
final PropertyKey key = StructrApp.key(testType, keyName);
String uuid = null;
if (key != null) {
// test failure
try (final Tx tx = app.tx()) {
uuid = app.create(testType, new NodeAttribute<>(key, 42000000000L)).getUuid();
app.create(testType, new NodeAttribute<>(key, 42000000000L));
tx.success();
fail("Long property uniqueness constraint violated!");
} catch (FrameworkException fex) {
final List<ErrorToken> tokens = fex.getErrorBuffer().getErrorTokens();
final ErrorToken token = tokens.get(0);
assertEquals("Invalid long validation result", 1, tokens.size());
assertEquals("Invalid long validation result", 422, fex.getStatus());
assertEquals("Invalid long validation result", keyName, token.getProperty());
assertEquals("Invalid long validation result", "Test", token.getType());
assertEquals("Invalid long validation result", "already_taken", token.getToken());
assertEquals("Invalid long validation result", uuid, token.getDetail());
}
}
}
use of org.structr.common.error.ErrorToken in project structr by structr.
the class ValidationTest method testSchemaNodeNameValidation.
@Test
public void testSchemaNodeNameValidation() {
try (final Tx tx = app.tx()) {
app.create(SchemaNode.class, "lowercase");
tx.success();
fail("SchemaNode name constraint violation!");
} 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 constraint violation error token", 422, fex.getStatus());
assertEquals("Invalid constraint violation error token", "name", token.getProperty());
assertEquals("Invalid constraint violation error token", "SchemaNode", token.getType());
assertEquals("Invalid constraint violation error token", "must_match", token.getToken());
}
try (final Tx tx = app.tx()) {
app.create(SchemaNode.class, "7NumberAsFirstChar");
tx.success();
fail("SchemaNode name constraint violation!");
} 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 constraint violation error token", 422, fex.getStatus());
assertEquals("Invalid constraint violation error token", "name", token.getProperty());
assertEquals("Invalid constraint violation error token", "SchemaNode", token.getType());
assertEquals("Invalid constraint violation error token", "must_match", token.getToken());
}
try (final Tx tx = app.tx()) {
app.create(SchemaNode.class, "7Number");
tx.success();
fail("SchemaNode name constraint violation!");
} 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 constraint violation error token", 422, fex.getStatus());
assertEquals("Invalid constraint violation error token", "name", token.getProperty());
assertEquals("Invalid constraint violation error token", "SchemaNode", token.getType());
assertEquals("Invalid constraint violation error token", "must_match", token.getToken());
}
try (final Tx tx = app.tx()) {
app.create(SchemaNode.class, "7Number");
tx.success();
fail("SchemaNode name constraint violation!");
} 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 constraint violation error token", 422, fex.getStatus());
assertEquals("Invalid constraint violation error token", "name", token.getProperty());
assertEquals("Invalid constraint violation error token", "SchemaNode", token.getType());
assertEquals("Invalid constraint violation error token", "must_match", token.getToken());
}
try (final Tx tx = app.tx()) {
app.create(SchemaNode.class, "Valid");
app.create(SchemaNode.class, "Valid");
tx.success();
fail("SchemaNode uniqueness constraint violation!");
} 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 constraint violation error token", 422, fex.getStatus());
assertEquals("Invalid constraint violation error token", "name", token.getProperty());
assertEquals("Invalid constraint violation error token", "SchemaNode", token.getType());
assertEquals("Invalid constraint violation error token", "already_taken", token.getToken());
}
}
use of org.structr.common.error.ErrorToken in project structr by structr.
the class ValidationTest method testStringPropertyUniquenessAgain.
@Test
public void testStringPropertyUniquenessAgain() {
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) {
final Random random = new Random();
try (final Tx tx = app.tx()) {
app.create(testType, new NodeAttribute<>(AbstractNode.name, "unique06"), new NodeAttribute<>(key, "unique00"));
app.create(testType, new NodeAttribute<>(AbstractNode.name, "unique05"), new NodeAttribute<>(key, "unique01"));
app.create(testType, new NodeAttribute<>(AbstractNode.name, "unique04"), new NodeAttribute<>(key, "unique02"));
app.create(testType, new NodeAttribute<>(AbstractNode.name, "unique03"), new NodeAttribute<>(key, "unique03"));
app.create(testType, new NodeAttribute<>(AbstractNode.name, "unique02"), new NodeAttribute<>(key, "unique04"));
app.create(testType, new NodeAttribute<>(AbstractNode.name, "unique01"), new NodeAttribute<>(key, "unique05"));
app.create(testType, new NodeAttribute<>(AbstractNode.name, "unique00"), new NodeAttribute<>(key, "unique06"));
tx.success();
} catch (FrameworkException fex) {
logger.warn("", fex);
fail("Unexpected exception.");
}
for (int i = 0; i < 5; i++) {
try (final Tx tx = app.tx()) {
app.create(testType, new NodeAttribute<>(key, "unique0" + random.nextInt(7)));
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());
}
}
}
}
}
Aggregations