Search in sources :

Example 1 with Database

use of org.whole.lang.rdb.model.Database in project whole by wholeplatform.

the class DBSchemaTemplateFactoryTest method testRDBUtils.

@Category(KnownFailingTests.class)
@Test
public void testRDBUtils() throws Exception {
    IBindingManager bm = BindingManagerFactory.instance.createArguments();
    bm.wDefValue("connection", connection);
    bm.wDefValue("generateDropStatements", false);
    Database database = new SampleDatabase().create();
    InterpreterOperation.interpret(database, bm);
    DBSchemaTemplateFactory dbSchemaTemplateFactory = new DBSchemaTemplateFactory(connection, "DBNAME", null);
    Database generatedDatabase = dbSchemaTemplateFactory.create();
    HashMap<EntityDescriptor<?>, Comparator<IEntity>> comparatorsMap = new HashMap<EntityDescriptor<?>, Comparator<IEntity>>();
    comparatorsMap.put(RDBEntityDescriptorEnum.Tables, new OrderedMatcher.SimpleFeatureComparator(RDBFeatureDescriptorEnum.name));
    Assert.assertTrue(OrderedMatcher.match(database, generatedDatabase, comparatorsMap));
    Assert.fail();
}
Also used : EntityDescriptor(org.whole.lang.reflect.EntityDescriptor) HashMap(java.util.HashMap) IEntity(org.whole.lang.model.IEntity) IBindingManager(org.whole.lang.bindings.IBindingManager) Database(org.whole.lang.rdb.model.Database) Comparator(java.util.Comparator) Category(org.junit.experimental.categories.Category) Test(org.junit.Test)

Example 2 with Database

use of org.whole.lang.rdb.model.Database 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 3 with Database

use of org.whole.lang.rdb.model.Database 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 4 with Database

use of org.whole.lang.rdb.model.Database 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 5 with Database

use of org.whole.lang.rdb.model.Database 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)

Aggregations

Database (org.whole.lang.rdb.model.Database)9 IEntity (org.whole.lang.model.IEntity)8 Test (org.junit.Test)7 IBindingManager (org.whole.lang.bindings.IBindingManager)7 SampleDatabase (org.whole.lang.rdb.codebase.SampleDatabase)5 Comparator (java.util.Comparator)2 HashMap (java.util.HashMap)2 EntityDescriptor (org.whole.lang.reflect.EntityDescriptor)2 Connection (java.sql.Connection)1 ArrayList (java.util.ArrayList)1 Category (org.junit.experimental.categories.Category)1 DBSchemaTemplateFactory (org.whole.lang.rdb.codebase.DBSchemaTemplateFactory)1