Search in sources :

Example 96 with IBindingManager

use of org.whole.lang.bindings.IBindingManager in project whole by wholeplatform.

the class SQLInterpreterTest method testMapAuthorsQueryWithNestedVar.

@Test
public void testMapAuthorsQueryWithNestedVar() {
    IBindingManager bm = BindingManagerFactory.instance.createArguments();
    bm.wDefValue("connection", connection);
    bm.wDefValue("generateDropStatements", false);
    Database database = new SampleDatabase().create();
    InterpreterOperation.interpret(database, bm);
    IEntity e = DBMappingTemplateManager.instance().create("populateDB");
    InterpreterOperation.interpret(e, bm);
    IEntity map = DBMappingTemplateManager.instance().create("mapAuthorsQueryWithNestedVar");
    IEntity results = DBMappingTemplateManager.instance().create("mapAuthorsResults");
    int index = 0;
    for (IEntity result : DynamicCompilerOperation.compile(map, bm).getResultIterator()) {
        IEntity expectedResult = results.wGet(index++).wGet(0);
        assertTrue(Matcher.match(expectedResult, result));
    }
    assertEquals(1, index);
}
Also used : IEntity(org.whole.lang.model.IEntity) IBindingManager(org.whole.lang.bindings.IBindingManager) Database(org.whole.lang.rdb.model.Database) SampleDatabase(org.whole.lang.rdb.codebase.SampleDatabase) SampleDatabase(org.whole.lang.rdb.codebase.SampleDatabase) Test(org.junit.Test)

Example 97 with IBindingManager

use of org.whole.lang.bindings.IBindingManager in project whole by wholeplatform.

the class SQLInterpreterTest method testMapAuthorsQuery.

@Test
public void testMapAuthorsQuery() {
    IBindingManager bm = BindingManagerFactory.instance.createArguments();
    bm.wDefValue("connection", connection);
    bm.wDefValue("generateDropStatements", false);
    Database database = new SampleDatabase().create();
    InterpreterOperation.interpret(database, bm);
    IEntity e = DBMappingTemplateManager.instance().create("populateDB");
    InterpreterOperation.interpret(e, bm);
    IEntity map = DBMappingTemplateManager.instance().create("mapAuthorsQuery");
    IEntity results = DBMappingTemplateManager.instance().create("mapAuthorsResults");
    int index = 0;
    for (IEntity result : DynamicCompilerOperation.compile(map, bm).getResultIterator()) {
        IEntity expectedResult = results.wGet(index++).wGet(0);
        assertTrue(Matcher.match(expectedResult, result));
    }
    assertEquals(results.wSize(), index);
}
Also used : IEntity(org.whole.lang.model.IEntity) IBindingManager(org.whole.lang.bindings.IBindingManager) Database(org.whole.lang.rdb.model.Database) SampleDatabase(org.whole.lang.rdb.codebase.SampleDatabase) SampleDatabase(org.whole.lang.rdb.codebase.SampleDatabase) Test(org.junit.Test)

Example 98 with IBindingManager

use of org.whole.lang.bindings.IBindingManager in project whole by wholeplatform.

the class SQLInterpreterTest method testDataTypes.

@Test
public void testDataTypes() {
    IBindingManager bm = BindingManagerFactory.instance.createArguments();
    bm.wDefValue("connection", connection);
    bm.wDefValue("generateDropStatements", false);
    Database database = new AllTypesDatabase().create();
    InterpreterOperation.interpret(database, bm);
    IEntity e = DBMappingTemplateManager.instance().create("populateDatatypesDB");
    InterpreterOperation.interpret(e, bm);
    IEntity map = DBMappingTemplateManager.instance().create("selectDatatypesDB");
    IEntity results = DBMappingTemplateManager.instance().create("selectDatatypesDBResults");
    IEntityIterator<IEntity> resultsIterator = DynamicCompilerOperation.compile(results, bm).getResultIterator();
    for (IEntity result : DynamicCompilerOperation.compile(map, bm).getResultIterator()) {
        assertTrue(resultsIterator.hasNext());
        IEntity expectedResult = resultsIterator.next();
        assertEquals(expectedResult.wSize(), result.wSize());
        for (int i = 0; i < expectedResult.wSize(); i++) {
            IEntity expectedValue = expectedResult.wGet(i);
            IEntity actualValue = result.wGet(i);
            switch(expectedValue.wGetEntityOrd()) {
                case SQLEntityDescriptorEnum.ArrayValue_ord:
                case SQLEntityDescriptorEnum.BinaryValue_ord:
                    Object a1 = expectedValue.wGetValue();
                    Object a2 = actualValue.wGetValue();
                    assertTrue(a1.getClass().isArray());
                    assertTrue(a2.getClass().isArray());
                    int length = Array.getLength(a1);
                    assertEquals(length, Array.getLength(a2));
                    for (int j = 0; j < length; j++) assertEquals(Array.get(a1, j), Array.get(a2, j));
                    break;
                default:
                    assertTrue(Matcher.match(expectedValue, actualValue));
            }
        }
    }
    assertFalse(resultsIterator.hasNext());
}
Also used : IEntity(org.whole.lang.model.IEntity) IBindingManager(org.whole.lang.bindings.IBindingManager) Database(org.whole.lang.rdb.model.Database) SampleDatabase(org.whole.lang.rdb.codebase.SampleDatabase) Test(org.junit.Test)

Example 99 with IBindingManager

use of org.whole.lang.bindings.IBindingManager in project whole by wholeplatform.

the class SQLInterpreterTest method testMapAuthorsQuery3.

@Test
public void testMapAuthorsQuery3() {
    IBindingManager bm = BindingManagerFactory.instance.createArguments();
    bm.wDefValue("connection", connection);
    bm.wDefValue("generateDropStatements", false);
    Database database = new SampleDatabase().create();
    InterpreterOperation.interpret(database, bm);
    IEntity e = DBMappingTemplateManager.instance().create("populateDB");
    InterpreterOperation.interpret(e, bm);
    IEntity map = DBMappingTemplateManager.instance().create("mapAuthorsQuery3");
    IEntity results = DBMappingTemplateManager.instance().create("mapAuthorsResults");
    int index = 0;
    for (IEntity result : DynamicCompilerOperation.compile(map, bm).getResultIterator()) {
        IEntity expectedResult = results.wGet(index++).wGet(0);
        assertTrue(Matcher.match(expectedResult, result));
    }
    assertEquals(results.wSize(), index);
}
Also used : IEntity(org.whole.lang.model.IEntity) IBindingManager(org.whole.lang.bindings.IBindingManager) Database(org.whole.lang.rdb.model.Database) SampleDatabase(org.whole.lang.rdb.codebase.SampleDatabase) SampleDatabase(org.whole.lang.rdb.codebase.SampleDatabase) Test(org.junit.Test)

Example 100 with IBindingManager

use of org.whole.lang.bindings.IBindingManager in project whole by wholeplatform.

the class XsiModelTemplateTest method testXsiModelTemplate.

@Category({ KnownFailingTests.class, SlowTests.class })
@Test
public void testXsiModelTemplate() throws Exception {
    fail();
    IBindingManager bm = BindingManagerFactory.instance.createBindingManager();
    bm.wDefValue("folderLocation", new File("test/org/whole/lang/xsd/templates").getAbsolutePath());
    bm.wDefValue("packageName", "");
    XsdDeployStrategies.setDeployStrategy(bm, XsdDeployStrategies.ALL);
    String fileName = "S202SCTDIRPFRAA0001.C.xml";
    IEntity xsiModel = XsiPersistenceKit.instance().readModel(new StreamPersistenceProvider(getInputStream(fileName), null, bm));
    CommonsEntityFactory.instance.createRootFragment(xsiModel.wGetAdapter(CommonsEntityDescriptorEnum.Any));
    IEntity xmlModel = XmlSourcePersistenceKit.instance().readModel(new StreamPersistenceProvider(getInputStream(fileName), null, bm));
    CommonsEntityFactory.instance.createRootFragment(xmlModel.wGetAdapter(CommonsEntityDescriptorEnum.Any));
    ModelBuilderOperation mop = new ModelBuilderOperation();
    XmlNormalizerBuilderOperation xnbo = new XmlNormalizerBuilderOperation(mop);
    XsiModelTemplate xsiModelTemplate = new XsiModelTemplate(xsiModel);
    xsiModelTemplate.apply(xnbo);
    IEntity xmlModelFromXsiModel = mop.wGetResult();
    Assert.assertTrue(Matcher.match(xmlModelFromXsiModel, xmlModel));
}
Also used : ModelBuilderOperation(org.whole.lang.builders.ModelBuilderOperation) IEntity(org.whole.lang.model.IEntity) XmlNormalizerBuilderOperation(org.whole.lang.xml.codebase.XmlNormalizerBuilderOperation) IBindingManager(org.whole.lang.bindings.IBindingManager) StreamPersistenceProvider(org.whole.lang.codebase.StreamPersistenceProvider) File(java.io.File) Category(org.junit.experimental.categories.Category) Test(org.junit.Test)

Aggregations

IBindingManager (org.whole.lang.bindings.IBindingManager)223 IEntity (org.whole.lang.model.IEntity)141 Test (org.junit.Test)91 PathExpression (org.whole.lang.queries.model.PathExpression)49 ITemplateManager (org.whole.lang.templates.ITemplateManager)40 Grammar (org.whole.lang.grammars.model.Grammar)28 TestXmlGrammar (org.whole.lang.grammars.util.TestXmlGrammar)27 ESelectionService (org.eclipse.e4.ui.workbench.modeling.ESelectionService)17 Model (org.whole.lang.models.model.Model)15 Production (org.whole.lang.grammars.model.Production)14 IEntityPartViewer (org.whole.lang.ui.viewers.IEntityPartViewer)14 File (java.io.File)12 QueriesGrammar (org.whole.lang.grammars.codebase.QueriesGrammar)12 XmlModel (org.whole.lang.models.codebase.XmlModel)11 SimpleEntity (org.whole.lang.models.model.SimpleEntity)10 VisitException (org.whole.lang.visitors.VisitException)9 IBindingScope (org.whole.lang.bindings.IBindingScope)6 ModelBuilderOperation (org.whole.lang.builders.ModelBuilderOperation)6 HashMap (java.util.HashMap)5 IFile (org.eclipse.core.resources.IFile)5