janbols / spock-dbunit Goto Github PK
View Code? Open in Web Editor NEWDbunit extension for spock avoiding a separate xml file
Dbunit extension for spock avoiding a separate xml file
Content is called for all cases.
How specify it for each case?
@DbUnit def content = {
CATEGORY(CATEGORY_ID: 1L, CATEGORY_NAME: "N", CATEGORY_IMAGE:"I")
}
Is there a plan to add @ExpectedDataset feature?
I have legacy test codebase , which working fine in MySql.
Now when I tried that code base with MSSQL, it required me to pass schema in each class which is cumbersome. Like
@DbUnit(schema = 'dbo', configure={
.....
})
Is this possible to use schema from Connection class, in DbUnitInterceptor like this:
void interceptFeatureMethod(IMethodInvocation invocation) throws Throwable {
....
def schema = dbUnitAnnotation.schema()
if(schema == '' || schema == null){
dataSource.getConnection().getSchema();
}
tester = new DataSourceDatabaseTester(dataSource, schema ) {
...
}
I'm trying to use @dbunit at field level, and @SingleExecution at method level.
Issue: @dbunit should be execute first and then @SingleExecution should be execute
For @SingleExecution - interceptIterationExecution() contain logic which every time first executed
For @dbunit - interceptFeatureMethod() contain logic which executed after @SingleExecution interceptIterationExecution method execute.
Currently they are executing in below order:
But I want to execute above annotation in following order:
My code is as below:
@dbunit(configure={ IDatabaseTester it ->
it.setUpOperation = InsertIdentityOperation.REFRESH
it.tearDownOperation = InsertIdentityOperation.NONE
})
def content = {
table1(col1:value1, col2:value2)
}
@SingleExecution('getColumnWiseMap')
def "test data table with single execution"(){
.....
}
def getColumnWiseMap(){
return ....;
}
When using an Oracle Database the following warning spams the log file:
WARN org.dbunit.dataset.AbstractTableMetaData - Potential problem found: The configured data type factory 'class org.dbunit.dataset.datatype.DefaultDataTypeFactory' might cause problems with the current database 'Oracle' (e.g. some datatypes may not be supported properly). In rare cases you might see this message because the list of supported database products is incomplete (list=[derby]). If so please request a java-class update via the forums.If you are using your own IDataTypeFactory extending DefaultDataTypeFactory, ensure that you override getValidDbProducts() to specify the supported database products.
It would be awesome when you could set the used database somehow
It would be nice to have the possibility to annotate a feature with @dbunit.
It would allow e.g. that only one feature uses dbunit or that several feature could have their individual dbunit instruction set.
I have one of my table without primary key, So I want to set IColumnFilter as per given example in
So I have add below @dbunit annoation to one of my feature:
@dbunit(configure={ IDatabaseTester it ->
it.getConnection().getConfig().setProperty(
DatabaseConfig.PROPERTY_PRIMARY_KEY_FILTER,
new MyPrimaryKeyFilter(null))
it.setUpOperation = DatabaseOperation.REFRESH
it.tearDownOperation = DatabaseOperation.NONE
}, content = {
tableWitoutPK(no_key1:value1, no_key2:value2)
})
def "add value to table without pk"(){
.........
}
class MyPrimaryKeyFilter implements IColumnFilter{
.........
}
But it's failing with exception: org.dbunit.dataset.NoPrimaryKeyException: tableWitoutPK
When I have debug, found that while configuring IDatabaseTester in DbUnitInterceptor it's throwing exception "Failed to instantiate tester configurer in @dbunit".
I don't know this feature is present in current DbUnit extension or not.
I have below code in my spec file:
@dbunit(configure={ IDatabaseTester it ->
it.setUpOperation = InsertIdentityOperation.REFRESH
it.tearDownOperation = InsertIdentityOperation.DELETE
})
def content = {
abc(id:123, name:'test')
}
This working finr in MySql, but when I try to run for MSSQL it gives org.dbunit.dataset.NoSuchTableException : abc error.
I have verified the 'abc' table is already there in MSSSQL database.
While debugging I have found that connection.getSchema() return "".
So how I can pass schema 'dbo' to @dbunit extension?
I don't want to pass in every class @dbunit(schema='dbo', configure......) like this.
Instead is it possible to get schema from field like we get datasource.
My project requires mocking data in multiple schemas (databases), so I am trying to us DbUnit's qualified table name feature. However, I am having problems with this so I am wondering if it has been tested before.
I am able to enable the feature with the configure closure:
@DbUnit(configure = {
it.connection.config.setProperty(DatabaseConfig.FEATURE_QUALIFIED_TABLE_NAMES, true)
})
def content = {
'FOO.BAR'(id: 1)
}
But inserting fails with an unknown table:
org.dbunit.dataset.NoSuchTableException: FOO.BAR
I have verified the tables exist with a simple SELECT *
query.
Disregard this part below; this issue was related to jooq and are not present using groovy sql.
Hi!
I initialized the value in the ip field of the DB table as below, but it does not contain the value.
@DbUnit(configure = { IDatabaseTester it ->
it.setUpOperation = DatabaseOperation.CLEAN_INSERT
})
def content = {
User(name: 'test1', ip: '1.2.3.4')
User(name: 'test2', ip: '127.0.0.1')
}
What should I do?
Please confirm.
Your help is very much appreciated!
Hi,
first, let me say thank you for this cool lib.
I tried to create different child entities of the same parent with annotations, but could not set non-common arguments.
So in my case, there is a User parent class, an EndUser and a ManagerUser children. I tried to make one EndUser and two ManagerUser instances. The latter would need some attributes filled which are not present in the first. So I am adding the attributes for the ManagerUser, but not for the EndUser. This way the attribute value is not set in the DB (it is null). If I only want to create ManagerUser instances I can add the attribute if I add to all of the created ones.
Is this a bug or am I doing something wrongly?
Your help is very much appreciated!
I have legacy db in which there are some tables without Primary key and some with PK, I know that for table with PK i can use DatabaseOperation.INSERT and tables without PK I can use DatabaseOperation.REFRESH, but for this I need to write 2 def conten{...}, but it's not allow to write, so what should I do?
In spec file how can I handle this scenario?
Hi Jan,
I need to set the schema of an oracle database.
There is the posibility to do it with the configure closure like this
@DbUnit(configure = { IDatabaseTester dbTester -> dbTester.setSchema(config.getString("schema")) })
but this approach is deprecated in dbunit
since 2.4.3 Should not be used anymore. Every concrete IDatabaseTester implementation that needs a schema has the possibility to set it somehow in the constructor
Would it be possible that the annotation gets an extra field to specify a schema?
It would be nice, if we could use the "column sensing" feature of DBUnit.
With this defining rows with null values wouldn't be so awkward.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.