use of org.whole.lang.queries.model.PathExpression in project whole by wholeplatform.
the class RewriteQueriesTest method testUpdate1.
@Test
public void testUpdate1() {
Model model = new ModelsModel().create();
ModelDeclarations declarations = model.getDeclarations();
ITemplateManager tm = RewriteQueriesTemplateManager.instance();
PathExpression query = (PathExpression) tm.create("update1");
for (IEntity entity : BehaviorUtils.compileAndLazyEvaluate(query, model)) assertTrue(Matcher.match(ModelsEntityDescriptorEnum.SimpleName, entity) || Matcher.match(ModelsEntityDescriptorEnum.DataType, entity));
assertEquals("MyModelName", model.getName().getValue());
int j = 0;
for (int i = 0; i < declarations.wSize(); i++) {
IEntity decl = declarations.wGet(i);
if (Matcher.match(ModelsEntityDescriptorEnum.DataEntity, decl)) {
if (j++ == 0) {
assertEquals("MyFirstName", ((DataEntity) decl).getName().getValue());
assertEquals("MyFirstDataType", ((DataEntity) decl).getDataType().getValue());
} else {
assertEquals("MySecondName", ((DataEntity) decl).getName().getValue());
return;
}
}
}
}
use of org.whole.lang.queries.model.PathExpression in project whole by wholeplatform.
the class SelectQueriesTest method testSelectTemplateWithNestedQuery.
@Test
public void testSelectTemplateWithNestedQuery() {
ITemplateManager tm = SelectQueriesTemplateManager.instance();
Model m = new XmlModel().create();
PathExpression pe1 = (PathExpression) tm.create("selectTemplateWithNestedQuery");
for (ClassDeclaration t : BehaviorUtils.<ClassDeclaration>compileAndLazyEvaluate(pe1, m)) {
assertEquals(JavaEntityDescriptorEnum.ClassDeclaration, t.wGetEntityDescriptor());
assertTrue(t.getBodyDeclarations().wSize() >= 2);
}
}
use of org.whole.lang.queries.model.PathExpression in project whole by wholeplatform.
the class SelectQueriesTest method testSelectTemplateFromPatternWithWhere.
@Test
public void testSelectTemplateFromPatternWithWhere() {
Model m = new XmlModel().create();
Feature feature = (Feature) ((SimpleEntity) m.getDeclarations().wGet(0)).getFeatures().wGet(0);
ITemplateManager tm = SelectQueriesTemplateManager.instance();
PathExpression pe1 = (PathExpression) tm.create("selectTemplateFromPatternWithWhere");
for (FieldDeclaration field : BehaviorUtils.<FieldDeclaration>compileAndLazyEvaluate(pe1, feature)) {
assertEquals(feature.getName().wStringValue(), field.getFragments().wGet(0).wGet(0).wStringValue());
assertEquals(StringUtils.toUpperCap(feature.getType().wStringValue()), field.getType().wStringValue());
}
}
use of org.whole.lang.queries.model.PathExpression in project whole by wholeplatform.
the class SelectQueriesTest method testSelectTemplateWithFreeVariable.
@Test
public void testSelectTemplateWithFreeVariable() {
ITemplateManager tm = SelectQueriesTemplateManager.instance();
Model m = new XmlModel().create();
PathExpression pe1 = (PathExpression) tm.create("selectTemplateWithFreeVariable");
IBindingManager bm = BindingManagerFactory.instance.createArguments();
for (ClassDeclaration t : BehaviorUtils.<ClassDeclaration>compileAndLazyEvaluate(pe1, m, bm)) {
assertEquals(JavaEntityDescriptorEnum.ClassDeclaration, t.wGetEntityDescriptor());
if (bm.wIsSet("freeVariable")) {
assertEquals(bm.wStringValue("freeVariable"), t.getName().wStringValue());
bm.wUnset("freeVariable");
} else {
assertTrue(t.getName().wIsAdapter());
bm.wDefValue("freeVariable", "MyClassName");
}
}
}
use of org.whole.lang.queries.model.PathExpression in project whole by wholeplatform.
the class SelectQueriesTest method testSelectHelperResultAs.
@Test
public void testSelectHelperResultAs() {
ITemplateManager tm = SelectQueriesTemplateManager.instance();
Model model = new XmlModel().create();
PathExpression query = (PathExpression) tm.create("selectHelperResultAs");
IBindingManager bm = BindingManagerFactory.instance.createArguments();
for (IEntity tuple : BehaviorUtils.compileAndLazyEvaluate(query, model, bm)) {
IEntity stringData = tuple.wGet(0);
SimpleEntity e = (SimpleEntity) tuple.wGet(1);
String entityName = e.getName().getValue();
String className = bm.wStringValue("className");
assertEquals(StringUtils.toUpperCap(entityName), className);
assertEquals(className, stringData.wStringValue());
}
}
Aggregations