use of org.structr.core.entity.SchemaMethod in project structr by structr.
the class DeploymentTest method test33SchemaMethods.
@Test
public void test33SchemaMethods() {
// setup
try (final Tx tx = app.tx()) {
app.create(SchemaMethod.class, new NodeAttribute<>(SchemaMethod.name, "method1"), new NodeAttribute<>(SchemaMethod.comment, "comment1"), new NodeAttribute<>(SchemaMethod.source, "source1"), new NodeAttribute<>(SchemaMethod.virtualFileName, "virtualFileName1"), new NodeAttribute<>(SchemaMethod.visibleToPublicUsers, true), new NodeAttribute<>(SchemaMethod.visibleToAuthenticatedUsers, false));
app.create(SchemaMethod.class, new NodeAttribute<>(SchemaMethod.name, "method2"), new NodeAttribute<>(SchemaMethod.comment, "comment2"), new NodeAttribute<>(SchemaMethod.source, "source2"), new NodeAttribute<>(SchemaMethod.virtualFileName, "virtualFileName2"), new NodeAttribute<>(SchemaMethod.visibleToPublicUsers, false), new NodeAttribute<>(SchemaMethod.visibleToAuthenticatedUsers, true));
tx.success();
} catch (FrameworkException fex) {
logger.warn("", fex);
fail("Unexpected exception.");
}
// test
doImportExportRoundtrip(true);
// check
try (final Tx tx = app.tx()) {
final SchemaMethod method1 = app.nodeQuery(SchemaMethod.class).and(SchemaMethod.name, "method1").getFirst();
final SchemaMethod method2 = app.nodeQuery(SchemaMethod.class).and(SchemaMethod.name, "method2").getFirst();
Assert.assertNotNull("Invalid deployment result", method1);
Assert.assertNotNull("Invalid deployment result", method2);
Assert.assertEquals("Invalid SchemaMethod deployment result", "method1", method1.getProperty(SchemaMethod.name));
Assert.assertEquals("Invalid SchemaMethod deployment result", "comment1", method1.getProperty(SchemaMethod.comment));
Assert.assertEquals("Invalid SchemaMethod deployment result", "source1", method1.getProperty(SchemaMethod.source));
Assert.assertEquals("Invalid SchemaMethod deployment result", "virtualFileName1", method1.getProperty(SchemaMethod.virtualFileName));
Assert.assertEquals("Invalid SchemaMethod deployment result", true, method1.getProperty(SchemaMethod.visibleToPublicUsers));
Assert.assertEquals("Invalid SchemaMethod deployment result", false, method1.getProperty(SchemaMethod.visibleToAuthenticatedUsers));
Assert.assertEquals("Invalid SchemaMethod deployment result", "method2", method2.getProperty(SchemaMethod.name));
Assert.assertEquals("Invalid SchemaMethod deployment result", "comment2", method2.getProperty(SchemaMethod.comment));
Assert.assertEquals("Invalid SchemaMethod deployment result", "source2", method2.getProperty(SchemaMethod.source));
Assert.assertEquals("Invalid SchemaMethod deployment result", "virtualFileName2", method2.getProperty(SchemaMethod.virtualFileName));
Assert.assertEquals("Invalid SchemaMethod deployment result", false, method2.getProperty(SchemaMethod.visibleToPublicUsers));
Assert.assertEquals("Invalid SchemaMethod deployment result", true, method2.getProperty(SchemaMethod.visibleToAuthenticatedUsers));
tx.success();
} catch (FrameworkException fex) {
fail("Unexpected exception.");
}
}
use of org.structr.core.entity.SchemaMethod 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");
}
}
use of org.structr.core.entity.SchemaMethod 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");
}
}
use of org.structr.core.entity.SchemaMethod 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");
}
}
use of org.structr.core.entity.SchemaMethod in project structr by structr.
the class StructrSchemaMethodPath method move.
@Override
public void move(final Path target, final CopyOption... options) throws IOException {
if (target instanceof StructrSchemaMethodPath) {
final App app = StructrApp.getInstance(fs.getSecurityContext());
final StructrSchemaMethodPath other = (StructrSchemaMethodPath) target;
final AbstractSchemaNode otherNode = other.getSchemaNode();
final SchemaMethod method = getSchemaMethodNode();
final String targetName = target.getFileName().toString();
try (final Tx tx = app.tx()) {
if (otherNode.getUuid().equals(schemaNode.getUuid())) {
// move from node to same node
method.setProperty(SchemaMethod.name, normalizeFileNameForJavaIdentifier(targetName));
method.setProperty(SchemaMethod.virtualFileName, targetName);
}
tx.success();
} catch (FrameworkException fex) {
logger.warn("", fex);
}
}
}
Aggregations