Search in sources :

Example 26 with ErrorToken

use of org.structr.common.error.ErrorToken in project structr by structr.

the class ValidationTest method testGlobalUniqueness.

@Test
public void testGlobalUniqueness() {
    try (final Tx tx = app.tx()) {
        app.create(SchemaNode.class, new NodeAttribute<>(AbstractNode.name, "Test"));
        tx.success();
    } catch (FrameworkException fex) {
        fail("Unexpected exception.");
    }
    final Class testType = StructrApp.getConfiguration().getNodeEntityClass("Test");
    if (testType != null) {
        String uuid = null;
        try (final Tx tx = app.tx()) {
            uuid = app.create(testType, new NodeAttribute<>(GraphObject.id, "00000000000000000000000000000000")).getUuid();
            tx.success();
        } catch (FrameworkException fex) {
            fail("Unexpected exception.");
        }
        for (int i = 0; i < 5; i++) {
            try (final Tx tx = app.tx()) {
                app.create(testType, new NodeAttribute<>(GraphObject.id, "00000000000000000000000000000000"));
                tx.success();
                fail("UUID uniqueness constraint violated!");
            } catch (FrameworkException fex) {
                final ErrorToken token = fex.getErrorBuffer().getErrorTokens().get(0);
                assertEquals("Invalid UUID uniqueness validation result", 422, fex.getStatus());
                assertEquals("Invalid UUID uniqueness validation result", "id", token.getProperty());
                assertEquals("Invalid UUID uniqueness validation result", "Test", token.getType());
                assertEquals("Invalid UUID uniqueness validation result", "already_taken", token.getToken());
                assertEquals("Invalid UUID uniqueness validation result", uuid, token.getDetail());
            }
        }
    }
}
Also used : Tx(org.structr.core.graph.Tx) FrameworkException(org.structr.common.error.FrameworkException) ErrorToken(org.structr.common.error.ErrorToken) StructrTest(org.structr.common.StructrTest) Test(org.junit.Test)

Aggregations

ErrorToken (org.structr.common.error.ErrorToken)26 Test (org.junit.Test)25 FrameworkException (org.structr.common.error.FrameworkException)25 Tx (org.structr.core.graph.Tx)25 StructrTest (org.structr.common.StructrTest)24 List (java.util.List)21 PropertyKey (org.structr.core.property.PropertyKey)20 NodeInterface (org.structr.core.graph.NodeInterface)12 StringProperty (org.structr.core.property.StringProperty)6 Date (java.util.Date)1 Random (java.util.Random)1 GraphObject (org.structr.core.GraphObject)1 App (org.structr.core.app.App)1 StructrApp (org.structr.core.app.StructrApp)1 Principal (org.structr.core.entity.Principal)1 SchemaNode (org.structr.core.entity.SchemaNode)1 EnumProperty (org.structr.core.property.EnumProperty)1