use of org.structr.core.property.PropertyMap 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.property.PropertyMap 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.property.PropertyMap in project structr by structr.
the class UiTest method test01AutoRenameThumbnailForImageSubclass.
@Test
public void test01AutoRenameThumbnailForImageSubclass() {
final Class testImageType = createTestImageType();
Image subclassTestImage = null;
final String initialImageName = "initial_image_name.png";
final String renamedImageName = "image_name_after_rename.png";
try (final Tx tx = app.tx()) {
subclassTestImage = (Image) ImageHelper.createFileBase64(securityContext, base64Image, testImageType);
subclassTestImage.setProperties(subclassTestImage.getSecurityContext(), new PropertyMap(Image.name, initialImageName));
assertNotNull(subclassTestImage);
assertTrue(subclassTestImage instanceof Image);
final Image tnSmall = subclassTestImage.getProperty(StructrApp.key(testImageType, "tnSmall"));
final Image tnMid = subclassTestImage.getProperty(StructrApp.key(testImageType, "tnMid"));
final Image tnCustom = subclassTestImage.getProperty(StructrApp.key(testImageType, "thumbnail"));
assertEquals("Initial small thumbnail name not as expected", ImageHelper.getThumbnailName(initialImageName, tnSmall.getWidth(), tnSmall.getHeight()), tnSmall.getProperty(StructrApp.key(Image.class, "name")));
assertEquals("Initial mid thumbnail name not as expected", ImageHelper.getThumbnailName(initialImageName, tnMid.getWidth(), tnMid.getHeight()), tnMid.getProperty(StructrApp.key(Image.class, "name")));
assertEquals("Initial custom thumbnail name not as expected", ImageHelper.getThumbnailName(initialImageName, tnCustom.getWidth(), tnCustom.getHeight()), tnCustom.getProperty(StructrApp.key(Image.class, "name")));
tx.success();
} catch (Exception ex) {
logger.error(ex.toString());
fail("Unexpected exception");
}
try (final Tx tx = app.tx()) {
subclassTestImage.setProperties(subclassTestImage.getSecurityContext(), new PropertyMap(Image.name, renamedImageName));
tx.success();
} catch (Exception ex) {
logger.error(ex.toString());
fail("Unexpected exception");
}
try (final Tx tx = app.tx()) {
final Image tnSmall = subclassTestImage.getProperty(StructrApp.key(testImageType, "tnSmall"));
final Image tnMid = subclassTestImage.getProperty(StructrApp.key(testImageType, "tnMid"));
final Image tnCustom = subclassTestImage.getProperty(StructrApp.key(testImageType, "thumbnail"));
assertEquals("Small Thumbnail name not auto-renamed as expected for image subclass", ImageHelper.getThumbnailName(renamedImageName, tnSmall.getWidth(), tnSmall.getHeight()), tnSmall.getProperty(StructrApp.key(Image.class, "name")));
assertEquals("Mid Thumbnail name not auto-renamed as expected for image subclass", ImageHelper.getThumbnailName(renamedImageName, tnMid.getWidth(), tnMid.getHeight()), tnMid.getProperty(StructrApp.key(Image.class, "name")));
assertEquals("Custom Thumbnail name not auto-renamed as expected for image subclass", ImageHelper.getThumbnailName(renamedImageName, tnCustom.getWidth(), tnCustom.getHeight()), tnCustom.getProperty(StructrApp.key(Image.class, "name")));
tx.success();
} catch (Exception ex) {
logger.error(ex.toString());
fail("Unexpected exception");
}
}
use of org.structr.core.property.PropertyMap in project structr by structr.
the class RenderDataTest method testRenderListFromRestQuery.
@Test
public void testRenderListFromRestQuery() {
String name = null;
try (final Tx tx = app.tx()) {
final Page doc = (Page) getDocument();
name = doc.getName();
final List<User> users = createTestNodes(User.class, 3);
assertEquals(3, users.size());
User user1 = users.get(0);
user1.setProperty(AbstractNode.name, "user1");
User user2 = users.get(1);
user2.setProperty(AbstractNode.name, "user2");
User user3 = users.get(2);
user3.setProperty(AbstractNode.name, "user3");
final List<File> files = createTestNodes(File.class, 6);
assertEquals(6, files.size());
File nodeA = files.get(0);
nodeA.setProperty(AbstractNode.name, "fileA");
File nodeB = files.get(1);
nodeB.setProperty(AbstractNode.name, "fileB");
File nodeC = files.get(2);
nodeC.setProperty(AbstractNode.name, "fileC");
File nodeD = files.get(3);
nodeD.setProperty(AbstractNode.name, "fileD");
File nodeE = files.get(4);
nodeE.setProperty(AbstractNode.name, "fileE");
File nodeF = files.get(5);
nodeF.setProperty(AbstractNode.name, "fileF");
// create dom tree
Element html = doc.createElement("html");
Element body = doc.createElement("body");
Element b = doc.createElement("b");
final Element p1 = doc.createElement("p");
final PropertyMap p1Properties = new PropertyMap();
p1Properties.put(StructrApp.key(DOMElement.class, "restQuery"), "users?sort=name");
p1Properties.put(StructrApp.key(DOMElement.class, "dataKey"), "user");
((DOMElement) p1).setProperties(((DOMElement) p1).getSecurityContext(), p1Properties);
Content userNameContentNode = (Content) doc.createTextNode("${user.name}");
p1.appendChild(userNameContentNode);
Element div = doc.createElement("div");
final Element p2 = doc.createElement("p");
final PropertyMap p2Properties = new PropertyMap();
p2Properties.put(StructrApp.key(DOMElement.class, "restQuery"), "files?sort=name");
p2Properties.put(StructrApp.key(DOMElement.class, "dataKey"), "file");
((DOMElement) p2).setProperties(((DOMElement) p2).getSecurityContext(), p2Properties);
Content fileNameContentNode = (Content) doc.createTextNode("${file.name}");
p2.appendChild(fileNameContentNode);
doc.appendChild(html);
html.appendChild(body);
body.appendChild(b);
body.appendChild(div);
b.appendChild(p1);
div.appendChild(p2);
makePublic(doc, html, body, div, b, p1, p2, fileNameContentNode, userNameContentNode, nodeA, nodeB, nodeC, nodeD, nodeE, nodeF, user1, user2, user3);
tx.success();
} catch (Exception ex) {
ex.printStackTrace();
fail("Unexpected exception");
}
try (final Tx tx = app.tx()) {
Document parsedDocument = Jsoup.connect(baseUri + name).timeout(100000).get();
System.out.println(parsedDocument.outerHtml());
assertEquals("user1", parsedDocument.select("html > body > b > p").get(0).ownText());
assertEquals("user2", parsedDocument.select("html > body > b > p").get(1).ownText());
assertEquals("user3", parsedDocument.select("html > body > b > p").get(2).ownText());
assertEquals("fileA", parsedDocument.select("html > body > div > p").get(0).ownText());
assertEquals("fileB", parsedDocument.select("html > body > div > p").get(1).ownText());
assertEquals("fileC", parsedDocument.select("html > body > div > p").get(2).ownText());
assertEquals("fileD", parsedDocument.select("html > body > div > p").get(3).ownText());
assertEquals("fileE", parsedDocument.select("html > body > div > p").get(4).ownText());
assertEquals("fileF", parsedDocument.select("html > body > div > p").get(5).ownText());
tx.success();
} catch (Exception ex) {
ex.printStackTrace();
fail("unexpected exception");
}
}
use of org.structr.core.property.PropertyMap in project structr by structr.
the class SearchCommand method or.
@Override
public <P> org.structr.core.app.Query<T> or(final PropertyMap attributes) {
for (final Map.Entry<PropertyKey, Object> entry : attributes.entrySet()) {
final PropertyKey key = entry.getKey();
final Object value = entry.getValue();
or(key, value);
}
return this;
}
Aggregations