Search in sources :

Example 56 with NodeInterface

use of org.structr.core.graph.NodeInterface in project structr by structr.

the class ValidationTest method testDoublePropertyNotNullValidation.

@Test
public void testDoublePropertyNotNullValidation() {
    final String keyName = "notnull";
    final Class<NodeInterface> testType = createTypeWithProperty("Test", keyName, "+Double");
    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("Double property not null constraint violated!");
        } catch (FrameworkException fex) {
            final List<ErrorToken> tokens = fex.getErrorBuffer().getErrorTokens();
            final ErrorToken token = tokens.get(0);
            assertEquals("Invalid double validation result", 1, tokens.size());
            assertEquals("Invalid double validation result", 422, fex.getStatus());
            assertEquals("Invalid double validation result", keyName, token.getProperty());
            assertEquals("Invalid double validation result", "Test", token.getType());
            assertEquals("Invalid double validation result", "must_not_be_empty", token.getToken());
        }
    }
}
Also used : Tx(org.structr.core.graph.Tx) FrameworkException(org.structr.common.error.FrameworkException) List(java.util.List) ErrorToken(org.structr.common.error.ErrorToken) NodeInterface(org.structr.core.graph.NodeInterface) PropertyKey(org.structr.core.property.PropertyKey) StructrTest(org.structr.common.StructrTest) Test(org.junit.Test)

Example 57 with NodeInterface

use of org.structr.core.graph.NodeInterface in project structr by structr.

the class ValidationTest method testEnumPropertyNotNullValidation.

@Test
public void testEnumPropertyNotNullValidation() {
    final String keyName = "notnull";
    final Class<NodeInterface> testType = createTypeWithProperty("Test", keyName, "+Enum(one, two, three)");
    final PropertyKey key = StructrApp.key(testType, keyName);
    // test failure
    try (final Tx tx = app.tx()) {
        app.create(testType, new NodeAttribute<>(key, null));
        tx.success();
        fail("Enum property not null 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", "must_not_be_empty", token.getToken());
    }
}
Also used : Tx(org.structr.core.graph.Tx) FrameworkException(org.structr.common.error.FrameworkException) List(java.util.List) ErrorToken(org.structr.common.error.ErrorToken) NodeInterface(org.structr.core.graph.NodeInterface) PropertyKey(org.structr.core.property.PropertyKey) StructrTest(org.structr.common.StructrTest) Test(org.junit.Test)

Example 58 with NodeInterface

use of org.structr.core.graph.NodeInterface in project structr by structr.

the class ValidationTest method testDatePropertyUniquenessValidation.

// ----- date property validation tests -----
@Test
public void testDatePropertyUniquenessValidation() {
    final String keyName = "unique";
    final Class<NodeInterface> testType = createTypeWithProperty("Test", keyName, "Date!");
    final PropertyKey key = StructrApp.key(testType, keyName);
    final Date date = new Date();
    String uuid = null;
    if (key != null) {
        // test failure
        try (final Tx tx = app.tx()) {
            uuid = app.create(testType, new NodeAttribute<>(key, date)).getUuid();
            app.create(testType, new NodeAttribute<>(key, date));
            tx.success();
            fail("Date property uniqueness 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", "already_taken", token.getToken());
            assertEquals("Invalid date validation result", uuid, token.getDetail());
        }
    }
}
Also used : Tx(org.structr.core.graph.Tx) FrameworkException(org.structr.common.error.FrameworkException) List(java.util.List) ErrorToken(org.structr.common.error.ErrorToken) NodeInterface(org.structr.core.graph.NodeInterface) PropertyKey(org.structr.core.property.PropertyKey) Date(java.util.Date) StructrTest(org.structr.common.StructrTest) Test(org.junit.Test)

Example 59 with NodeInterface

use of org.structr.core.graph.NodeInterface in project structr by structr.

the class ValidationTest method testArrayPropertyUniquenessValidation.

@Test
public void testArrayPropertyUniquenessValidation() {
    final String keyName = "stringArray";
    final Class<NodeInterface> testType = createTypeWithProperty("Test", keyName, "String[]!");
    final PropertyKey key = StructrApp.key(testType, keyName);
    String uuid1 = null;
    String uuid2 = null;
    if (key != null) {
        // test failure
        try (final Tx tx = app.tx()) {
            uuid1 = app.create(testType, new NodeAttribute<>(key, new String[] { "one", "two" })).getUuid();
            uuid2 = app.create(testType, new NodeAttribute<>(key, new String[] { "one", "two" })).getUuid();
            tx.success();
            fail("Array property validation failed!");
        } 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", keyName, token.getProperty());
            assertEquals("Invalid uniqueness validation result", "Test", token.getType());
            assertEquals("Invalid uniqueness validation result", "already_taken", token.getToken());
            assertEquals("Invalid uniqueness validation result", uuid1, token.getDetail());
        }
        removeInstances(testType);
        // test success
        try (final Tx tx = app.tx()) {
            app.create(testType, new NodeAttribute<>(key, new String[] { "one" }));
            app.create(testType, new NodeAttribute<>(key, new String[] { "one", "two" }));
            app.create(testType, new NodeAttribute<>(key, new String[] { "one", "two", "three" }));
            tx.success();
        } catch (FrameworkException fex) {
            fail("Array property validation error!");
        }
    }
}
Also used : Tx(org.structr.core.graph.Tx) FrameworkException(org.structr.common.error.FrameworkException) List(java.util.List) ErrorToken(org.structr.common.error.ErrorToken) NodeInterface(org.structr.core.graph.NodeInterface) PropertyKey(org.structr.core.property.PropertyKey) StructrTest(org.structr.common.StructrTest) Test(org.junit.Test)

Example 60 with NodeInterface

use of org.structr.core.graph.NodeInterface 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");
    }
}
Also used : FrameworkException(org.structr.common.error.FrameworkException) NodeInterface(org.structr.core.graph.NodeInterface) PropertyKey(org.structr.core.property.PropertyKey) StructrTest(org.structr.common.StructrTest) Test(org.junit.Test)

Aggregations

NodeInterface (org.structr.core.graph.NodeInterface)186 FrameworkException (org.structr.common.error.FrameworkException)120 Tx (org.structr.core.graph.Tx)116 Test (org.junit.Test)81 PropertyKey (org.structr.core.property.PropertyKey)61 LinkedList (java.util.LinkedList)36 StructrTest (org.structr.common.StructrTest)29 PropertyMap (org.structr.core.property.PropertyMap)26 TestOne (org.structr.core.entity.TestOne)24 List (java.util.List)23 GraphObject (org.structr.core.GraphObject)22 App (org.structr.core.app.App)21 StructrApp (org.structr.core.app.StructrApp)21 GenericNode (org.structr.core.entity.GenericNode)21 Before (org.junit.Before)18 Result (org.structr.core.Result)18 AbstractRelationship (org.structr.core.entity.AbstractRelationship)16 Random (java.util.Random)15 RelationshipInterface (org.structr.core.graph.RelationshipInterface)14 ErrorToken (org.structr.common.error.ErrorToken)12