use of org.apache.cayenne.dbsync.merge.factory.DefaultMergerTokenFactory in project cayenne by apache.
the class TokensToModelExecutionTest method testCreateAndDropTable.
@Test
public void testCreateAndDropTable() throws Exception {
DbEntity entity = dbEntity().build();
DataMap dataMap = dataMap().build();
assertTrue(dataMap.getDbEntityMap().isEmpty());
assertTrue(dataMap.getObjEntityMap().isEmpty());
MergerContext context = MergerContext.builder(dataMap).dataNode(new DataNode()).build();
new DefaultMergerTokenFactory().createCreateTableToModel(entity).execute(context);
assertEquals(1, dataMap.getDbEntityMap().size());
assertEquals(1, dataMap.getObjEntities().size());
assertEquals(entity, dataMap.getDbEntity(entity.getName()));
new DefaultMergerTokenFactory().createDropTableToModel(entity).execute(context);
assertTrue(dataMap.getDbEntityMap().isEmpty());
assertTrue(dataMap.getObjEntityMap().isEmpty());
}
use of org.apache.cayenne.dbsync.merge.factory.DefaultMergerTokenFactory in project cayenne by apache.
the class DefaultDbImportActionTest method buildDbImportAction.
private DefaultDbImportAction buildDbImportAction(FileProjectSaver projectSaver, DataMapLoader mapLoader, final DbLoader dbLoader) throws Exception {
Logger log = mock(Logger.class);
when(log.isDebugEnabled()).thenReturn(true);
when(log.isInfoEnabled()).thenReturn(true);
DbAdapter dbAdapter = mock(DbAdapter.class);
DbAdapterFactory adapterFactory = mock(DbAdapterFactory.class);
when(adapterFactory.createAdapter((DataNodeDescriptor) any(), (DataSource) any())).thenReturn(dbAdapter);
DataSourceFactory dataSourceFactory = mock(DataSourceFactory.class);
DataSource mock = mock(DataSource.class);
when(dataSourceFactory.getDataSource((DataNodeDescriptor) any())).thenReturn(mock);
DataChannelMetaData metaData = mock(DataChannelMetaData.class);
MergerTokenFactoryProvider mergerTokenFactoryProvider = mock(MergerTokenFactoryProvider.class);
when(mergerTokenFactoryProvider.get((DbAdapter) any())).thenReturn(new DefaultMergerTokenFactory());
DataChannelDescriptorLoader dataChannelDescriptorLoader = mock(DataChannelDescriptorLoader.class);
return new DefaultDbImportAction(log, projectSaver, dataSourceFactory, adapterFactory, mapLoader, mergerTokenFactoryProvider, dataChannelDescriptorLoader, metaData) {
protected DbLoader createDbLoader(DbAdapter adapter, Connection connection, DbImportConfiguration config) {
return dbLoader;
}
};
}
use of org.apache.cayenne.dbsync.merge.factory.DefaultMergerTokenFactory in project cayenne by apache.
the class TokensToModelExecutionTest method testCreateAndDropColumn.
@Test
public void testCreateAndDropColumn() throws Exception {
DbAttribute attr = dbAttr("attr").build();
DbEntity entity = dbEntity().build();
DataMap dataMap = dataMap().with(entity).build();
assertEquals(1, dataMap.getDbEntityMap().size());
assertTrue(dataMap.getObjEntityMap().isEmpty());
MergerContext context = MergerContext.builder(dataMap).dataNode(new DataNode()).build();
new DefaultMergerTokenFactory().createAddColumnToModel(entity, attr).execute(context);
assertEquals(1, dataMap.getDbEntityMap().size());
assertEquals(1, entity.getAttributes().size());
assertEquals(attr, entity.getAttribute(attr.getName()));
new DefaultMergerTokenFactory().createDropColumnToModel(entity, attr).execute(context);
assertEquals(1, dataMap.getDbEntityMap().size());
assertTrue(entity.getAttributes().isEmpty());
assertTrue(dataMap.getObjEntityMap().isEmpty());
}
Aggregations