Search in sources :

Example 1 with DataSourceConfig

use of org.apache.cayenne.tools.model.DataSourceConfig in project cayenne by apache.

the class DbGenerateTask method dataSource.

public DataSourceConfig dataSource(Closure closure) {
    dataSource = new DataSourceConfig();
    getProject().configure(dataSource, closure);
    return dataSource;
}
Also used : DataSourceConfig(org.apache.cayenne.tools.model.DataSourceConfig)

Example 2 with DataSourceConfig

use of org.apache.cayenne.tools.model.DataSourceConfig in project cayenne by apache.

the class DbImportTaskTest method testFullConfigCreation.

@Test
public void testFullConfigCreation() {
    File mockFile = mock(File.class);
    // configure task
    task.setMap(mockFile);
    task.setAdapter("org.apache.cayenne.test.adapter");
    task.dataSource(new Closure<DataSourceConfig>(task, task) {

        DataSourceConfig doCall(DataSourceConfig dataSourceConfig) {
            assertNotNull(dataSourceConfig);
            dataSourceConfig.setUrl("test://url");
            dataSourceConfig.setDriver("org.apache.cayenne.test.driver");
            dataSourceConfig.setUsername("username");
            dataSourceConfig.setPassword("password");
            return dataSourceConfig;
        }
    });
    task.dbImport(new Closure<DataSourceConfig>(task, task) {

        DbImportConfig doCall(DbImportConfig config) {
            assertNotNull(config);
            config.setDefaultPackage("com.example.package");
            config.setMeaningfulPkTables("pk_tables");
            config.setNamingStrategy("com.example.naming");
            config.setSkipPrimaryKeyLoading(true);
            config.setSkipRelationshipsLoading(true);
            config.setStripFromTableNames("strip");
            config.tableTypes("view", "alias");
            config.setForceDataMapCatalog(true);
            config.setForceDataMapSchema(true);
            config.setUseJava7Types(true);
            config.setUsePrimitives(false);
            return config;
        }
    });
    // Testing this:
    DbImportConfiguration dbImportConfiguration = task.createConfig();
    // Check that all values in end configuration is properly set
    assertEquals("org.apache.cayenne.test.adapter", dbImportConfiguration.getAdapter());
    assertEquals("test://url", dbImportConfiguration.getUrl());
    assertEquals("org.apache.cayenne.test.driver", dbImportConfiguration.getDriver());
    assertEquals("username", dbImportConfiguration.getUsername());
    assertEquals("password", dbImportConfiguration.getPassword());
    assertEquals("com.example.package", dbImportConfiguration.getDefaultPackage());
    assertEquals("pk_tables", dbImportConfiguration.getMeaningfulPkTables());
    assertEquals("com.example.naming", dbImportConfiguration.getNamingStrategy());
    assertTrue(dbImportConfiguration.getDbLoaderConfig().isSkipPrimaryKeyLoading());
    assertTrue(dbImportConfiguration.getDbLoaderConfig().isSkipRelationshipsLoading());
    assertEquals("strip", dbImportConfiguration.getStripFromTableNames());
    assertEquals("password", dbImportConfiguration.getPassword());
    assertArrayEquals(new String[] { "view", "alias" }, dbImportConfiguration.getDbLoaderConfig().getTableTypes());
    assertTrue(dbImportConfiguration.isForceDataMapCatalog());
    assertTrue(dbImportConfiguration.isForceDataMapSchema());
    assertTrue(dbImportConfiguration.isUseJava7Types());
    assertFalse(dbImportConfiguration.isUsePrimitives());
}
Also used : DbImportConfig(org.apache.cayenne.tools.model.DbImportConfig) DbImportConfiguration(org.apache.cayenne.dbsync.reverse.dbimport.DbImportConfiguration) DataSourceConfig(org.apache.cayenne.tools.model.DataSourceConfig) File(java.io.File) Test(org.junit.Test)

Aggregations

DataSourceConfig (org.apache.cayenne.tools.model.DataSourceConfig)2 File (java.io.File)1 DbImportConfiguration (org.apache.cayenne.dbsync.reverse.dbimport.DbImportConfiguration)1 DbImportConfig (org.apache.cayenne.tools.model.DbImportConfig)1 Test (org.junit.Test)1