Search in sources :

Example 56 with Tx

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

the class SchemaMethodsTest method test05InheritedSchemaMethodOnBuildinType.

@Test
public void test05InheritedSchemaMethodOnBuildinType() {
    final String builtinTypeName = "File";
    final String schemaMethodName = "testFileMethod";
    User admin = null;
    try (final Tx tx = app.tx()) {
        admin = createAdminUser();
        tx.success();
    } catch (Exception ex) {
        logger.error("", ex);
    }
    try (final Tx tx = app.tx()) {
        // Add schema method "testFileMethod" to built-in File class
        SchemaNode fileNodeDef = app.nodeQuery(SchemaNode.class).andName(builtinTypeName).getFirst();
        final PropertyMap testFileMethodProperties = new PropertyMap();
        testFileMethodProperties.put(SchemaMethod.name, schemaMethodName);
        testFileMethodProperties.put(SchemaMethod.source, "()");
        testFileMethodProperties.put(SchemaMethod.schemaNode, fileNodeDef);
        SchemaMethod testFileMethod = app.create(SchemaMethod.class, testFileMethodProperties);
        tx.success();
    } catch (Exception ex) {
        logger.error("", ex);
    }
    try (final Tx tx = app.tx()) {
        RestAssured.given().contentType("application/json; charset=UTF-8").filter(ResponseLoggingFilter.logResponseIfStatusCodeIs(200)).filter(ResponseLoggingFilter.logResponseIfStatusCodeIs(201)).filter(ResponseLoggingFilter.logResponseIfStatusCodeIs(400)).filter(ResponseLoggingFilter.logResponseIfStatusCodeIs(404)).filter(ResponseLoggingFilter.logResponseIfStatusCodeIs(422)).filter(ResponseLoggingFilter.logResponseIfStatusCodeIs(500)).headers("X-User", ADMIN_USERNAME, "X-Password", ADMIN_PASSWORD).body("{}").expect().statusCode(200).when().post("/Image/" + schemaMethodName);
        tx.success();
    } catch (FrameworkException ex) {
        logger.error(ex.toString());
        fail("Unexpected exception");
    }
}
Also used : SchemaNode(org.structr.core.entity.SchemaNode) User(org.structr.web.entity.User) PropertyMap(org.structr.core.property.PropertyMap) Tx(org.structr.core.graph.Tx) SchemaMethod(org.structr.core.entity.SchemaMethod) FrameworkException(org.structr.common.error.FrameworkException) FrameworkException(org.structr.common.error.FrameworkException) Test(org.junit.Test)

Example 57 with Tx

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

the class SchemaMethodsTest method test06InheritedSchemaMethodOnEntityOfBuiltinType.

@Test
public void test06InheritedSchemaMethodOnEntityOfBuiltinType() {
    final String builtinTypeName = "File";
    final String schemaMethodName = "testFileMethod";
    User admin = null;
    try (final Tx tx = app.tx()) {
        admin = createAdminUser();
        tx.success();
    } catch (Exception ex) {
        logger.error("", ex);
    }
    try (final Tx tx = app.tx()) {
        // Add schema method "testFileMethod" to built-in File class
        SchemaNode fileNodeDef = app.nodeQuery(SchemaNode.class).andName(builtinTypeName).getFirst();
        final PropertyMap testFileMethodProperties = new PropertyMap();
        testFileMethodProperties.put(SchemaMethod.name, schemaMethodName);
        testFileMethodProperties.put(SchemaMethod.source, "()");
        testFileMethodProperties.put(SchemaMethod.schemaNode, fileNodeDef);
        SchemaMethod testFileMethod = app.create(SchemaMethod.class, testFileMethodProperties);
        tx.success();
    } catch (Exception ex) {
        logger.error("", ex);
    }
    String id = createEntityAsAdmin("Image", "{'name': 'Test Image'}");
    try (final Tx tx = app.tx()) {
        RestAssured.given().contentType("application/json; charset=UTF-8").filter(ResponseLoggingFilter.logResponseIfStatusCodeIs(200)).filter(ResponseLoggingFilter.logResponseIfStatusCodeIs(201)).filter(ResponseLoggingFilter.logResponseIfStatusCodeIs(400)).filter(ResponseLoggingFilter.logResponseIfStatusCodeIs(404)).filter(ResponseLoggingFilter.logResponseIfStatusCodeIs(422)).filter(ResponseLoggingFilter.logResponseIfStatusCodeIs(500)).headers("X-User", ADMIN_USERNAME, "X-Password", ADMIN_PASSWORD).body("{}").expect().statusCode(200).when().post("/Image/" + id + "/" + schemaMethodName);
        tx.success();
    } catch (FrameworkException ex) {
        logger.error(ex.toString());
        fail("Unexpected exception");
    }
}
Also used : SchemaNode(org.structr.core.entity.SchemaNode) User(org.structr.web.entity.User) PropertyMap(org.structr.core.property.PropertyMap) Tx(org.structr.core.graph.Tx) SchemaMethod(org.structr.core.entity.SchemaMethod) FrameworkException(org.structr.common.error.FrameworkException) FrameworkException(org.structr.common.error.FrameworkException) Test(org.junit.Test)

Example 58 with Tx

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

the class SchemaMethodsTest method test01SchemaMethodOnBuiltinType.

@Test
public void test01SchemaMethodOnBuiltinType() {
    final String builtinTypeName = "File";
    final String schemaMethodName = "testFileMethod";
    try (final Tx tx = app.tx()) {
        // Add schema method "testFileMethod" to built-in File class
        SchemaNode fileNodeDef = app.nodeQuery(SchemaNode.class).andName(builtinTypeName).getFirst();
        final PropertyMap testFileMethodProperties = new PropertyMap();
        testFileMethodProperties.put(SchemaMethod.name, schemaMethodName);
        testFileMethodProperties.put(SchemaMethod.source, "()");
        testFileMethodProperties.put(SchemaMethod.schemaNode, fileNodeDef);
        SchemaMethod testFileMethod = app.create(SchemaMethod.class, testFileMethodProperties);
        tx.success();
    } catch (Exception ex) {
        logger.error("", ex);
    }
    User admin = null;
    try (final Tx tx = app.tx()) {
        admin = createAdminUser();
        tx.success();
    } catch (Exception ex) {
        logger.error("", ex);
    }
    try (final Tx tx = app.tx()) {
        RestAssured.given().contentType("application/json; charset=UTF-8").filter(ResponseLoggingFilter.logResponseIfStatusCodeIs(200)).filter(ResponseLoggingFilter.logResponseIfStatusCodeIs(201)).filter(ResponseLoggingFilter.logResponseIfStatusCodeIs(400)).filter(ResponseLoggingFilter.logResponseIfStatusCodeIs(404)).filter(ResponseLoggingFilter.logResponseIfStatusCodeIs(422)).filter(ResponseLoggingFilter.logResponseIfStatusCodeIs(500)).headers("X-User", ADMIN_USERNAME, "X-Password", ADMIN_PASSWORD).body("{}").expect().statusCode(200).when().post(builtinTypeName + "/" + schemaMethodName);
        tx.success();
    } catch (FrameworkException ex) {
        logger.error(ex.toString());
        fail("Unexpected exception");
    }
}
Also used : SchemaNode(org.structr.core.entity.SchemaNode) PropertyMap(org.structr.core.property.PropertyMap) User(org.structr.web.entity.User) Tx(org.structr.core.graph.Tx) SchemaMethod(org.structr.core.entity.SchemaMethod) FrameworkException(org.structr.common.error.FrameworkException) FrameworkException(org.structr.common.error.FrameworkException) Test(org.junit.Test)

Example 59 with Tx

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

the class SimpleTest method test001EMailAddressConstraint.

@Test
public void test001EMailAddressConstraint() {
    final PropertyKey<String> eMail = StructrApp.key(User.class, "eMail");
    try (final Tx tx = app.tx()) {
        app.create(User.class, new NodeAttribute(User.name, "TestUser1"), new NodeAttribute(eMail, "user@structr.test"));
        app.create(User.class, new NodeAttribute(User.name, "TestUser2"), new NodeAttribute(eMail, "user@structr.test"));
        tx.success();
        fail("Expected exception to be thrown.");
    } catch (FrameworkException fex) {
        assertEquals("Invalid error code", 422, fex.getStatus());
    }
    check();
    try (final Tx tx = app.tx()) {
        app.create(User.class, new NodeAttribute(User.name, "TestUser1"), new NodeAttribute(eMail, "user@structr.test"));
        app.create(User.class, new NodeAttribute(User.name, "TestUser2"), new NodeAttribute(eMail, "User@Structr.test"));
        tx.success();
        fail("Expected exception to be thrown.");
    } catch (FrameworkException fex) {
        assertEquals("Invalid error code", 422, fex.getStatus());
    }
    check();
}
Also used : NodeAttribute(org.structr.core.graph.NodeAttribute) Tx(org.structr.core.graph.Tx) FrameworkException(org.structr.common.error.FrameworkException) Test(org.junit.Test) StructrUiTest(org.structr.web.StructrUiTest)

Example 60 with Tx

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

the class SimpleTest method testIncreasePageVersion.

@Test
public void testIncreasePageVersion() {
    Page page = null;
    try (final Tx tx = app.tx()) {
        page = Page.createSimplePage(securityContext, "test");
        tx.success();
    } catch (FrameworkException fex) {
        fail("Unepxected exception.");
    }
    try (final Tx tx = app.tx()) {
        assertEquals("Page version is not increased on modification", 0, page.getVersion());
        final Element div = page.createElement("div");
        // add new element
        page.getElementsByTagName("div").item(0).appendChild(div);
        tx.success();
    } catch (FrameworkException fex) {
        fail("Unepxected exception.");
    }
    try (final Tx tx = app.tx()) {
        assertEquals("Page version is not increased on modification", 3, page.getVersion());
        tx.success();
    } catch (FrameworkException fex) {
        fail("Unepxected exception.");
    }
}
Also used : Tx(org.structr.core.graph.Tx) FrameworkException(org.structr.common.error.FrameworkException) DOMElement(org.structr.web.entity.dom.DOMElement) Element(org.w3c.dom.Element) Page(org.structr.web.entity.dom.Page) Test(org.junit.Test) StructrUiTest(org.structr.web.StructrUiTest)

Aggregations

Tx (org.structr.core.graph.Tx)892 FrameworkException (org.structr.common.error.FrameworkException)684 Test (org.junit.Test)461 App (org.structr.core.app.App)201 StructrApp (org.structr.core.app.StructrApp)201 StructrUiTest (org.structr.web.StructrUiTest)139 NodeInterface (org.structr.core.graph.NodeInterface)117 StructrTest (org.structr.common.StructrTest)108 IOException (java.io.IOException)105 PropertyMap (org.structr.core.property.PropertyMap)102 LinkedList (java.util.LinkedList)99 TestOne (org.structr.core.entity.TestOne)98 File (org.structr.web.entity.File)83 Page (org.structr.web.entity.dom.Page)71 Principal (org.structr.core.entity.Principal)65 Folder (org.structr.web.entity.Folder)65 PropertyKey (org.structr.core.property.PropertyKey)62 NodeAttribute (org.structr.core.graph.NodeAttribute)57 SchemaNode (org.structr.core.entity.SchemaNode)45 AbstractFile (org.structr.web.entity.AbstractFile)44