Commit 12cdc4e7 authored by npedot's avatar npedot
Browse files

refacts test dir and adds liquibase sqlize create column

parent 3b27baf3
package unibz.cs.semint.kprime.adapter.service
import liquibase.database.core.H2Database
import liquibase.sqlgenerator.SqlGenerator
import liquibase.sqlgenerator.SqlGeneratorChain
import liquibase.sqlgenerator.core.AddColumnGenerator
import liquibase.statement.NotNullConstraint
import liquibase.statement.SqlStatement
import liquibase.statement.core.AddColumnStatement
import unibz.cs.semint.kprime.domain.dml.ChangeSet
import unibz.cs.semint.kprime.domain.dml.CreateColumn
import unibz.cs.semint.kprime.usecase.service.SQLizeServiceI
import java.util.*
class MockSqlGeneratorChain: SqlGeneratorChain<SqlStatement>(TreeSet<SqlGenerator<SqlStatement>>()) { }
class LiquibaseSQLizeAdapter: SQLizeServiceI {
override fun sqlize(change: ChangeSet): List<String> {
return change.createColumn.flatMap { sqlizeAddColumn(it) }
}
fun sqlizeAddColumn(createColumns: CreateColumn): List<String> {
val statements = createColumns.columns.map {
AddColumnStatement(
createColumns.catalog,
createColumns.schema,
it.dbtable,
it.dbname,
it.dbtype,
null,
NotNullConstraint()
)
}
val addStatements = AddColumnStatement(statements)
val generateSql = AddColumnGenerator().generateSql(
addStatements,
H2Database(),
MockSqlGeneratorChain())
return generateSql.map { it.toSql() }
}
}
\ No newline at end of file
package unibz.cs.semint.kprime.usecase.catalog
class VerticalTransformer {
import unibz.cs.semint.kprime.domain.Applicability
import unibz.cs.semint.kprime.domain.Transformation
import unibz.cs.semint.kprime.domain.TransformationStrategy
import unibz.cs.semint.kprime.domain.ddl.Database
import unibz.cs.semint.kprime.domain.dml.ChangeSet
import unibz.cs.semint.kprime.usecase.TransformerUseCase
class VerticalTransformer : TransformerUseCase {
override fun decompose(db: Database, params: Map<String, Any>): Transformation {
TODO("Not yet implemented")
val change = ChangeSet()
return Transformation(change,db,"NOT TRANSFORMED")
}
override fun compose(db: Database, params: Map<String, Any>): Transformation {
TODO("Not yet implemented")
}
override fun decomposeApplicable(db: Database, transformationStrategy: TransformationStrategy, params: Map<String, Any>): Applicability {
TODO("Not yet implemented")
}
override fun composeApplicable(db: Database, transformationStrategy: TransformationStrategy, params: Map<String, Any>): Applicability {
TODO("Not yet implemented")
}
}
\ No newline at end of file
package unibz.cs.semint.kprime.usecase.service
import unibz.cs.semint.kprime.domain.dml.ChangeSet
interface SQLizeServiceI {
fun sqlize(change: ChangeSet): List<String>
}
\ No newline at end of file
package unibz.cs.semint.kprime.adapter
import org.junit.Test
import unibz.cs.semint.kprime.adapter.service.LiquibaseSQLizeAdapter
import unibz.cs.semint.kprime.domain.ddl.Column
import unibz.cs.semint.kprime.domain.dml.ChangeSet
import unibz.cs.semint.kprime.domain.dml.CreateColumn
import kotlin.test.assertEquals
class LiquibaseSQLizeAdapterTest {
@Test
fun test_add_column_change() {
// given
val change = ChangeSet()
val createColumn = CreateColumn()
createColumn.catalog = "cat1"
createColumn.schema = "schema1"
val col1 = Column("colName","colId")
col1.dbname = "colDbName"
col1.dbtype = "colDbType"
col1.dbtable = "tableDbName"
createColumn.columns.add(col1)
change.createColumn.add(createColumn)
// when
val sqlize = LiquibaseSQLizeAdapter().sqlize(change)
// then
val sqlizeresult = sqlize.joinToString(System.lineSeparator())
assertEquals("""
ALTER TABLE schema1.tableDbName ADD colDbName COLDBTYPE NOT NULL
""".trimIndent(),sqlizeresult)
}
}
\ No newline at end of file
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment