Adding SQL to the ddl.sql Execution for DBUNIT

63 views
Skip to first unread message

richar...@taskize.co.uk

unread,
Oct 22, 2015, 1:55:21 PM10/22/15
to Sculptor Generator
Hi - 

I am trying to figure out how to add some SQL to the DDL that is run at Unit Test time to populate Hypersonic.

We have a situation where we need to run a number of different schemas and we also have our own sequence_ ID generators. Once for each entity in each schema.

So the setup required for tests wont work out of the box.

How can we amend this behaviour?

I have noticed that the AbstractDUnitJpaTest.class has a method that looks for additional sql in the generated directories, but as its looking under generated this sql gets wiped.

    protected void buildSchema() {

    if (!buildSchemaExecuted) {

            executeScript("file:src/test/generated/resources/dbunit/ddl.sql");

            executeScript("file:src/test/generated/resources/dbunit/ddl_additional.sql");

            buildSchemaExecuted = true;

        }

    };


Help appreciated.


I have searched GIT codebase for some hints as to what I could do but nothing really jumped out at me. 


Thanks,

Richie.

Torsten Juergeleit

unread,
Oct 23, 2015, 2:04:09 PM10/23/15
to Sculptor Generator
How about overriding buildSchema() in your generated unit test class?

Or how about creating your own subclass of AbstractDUnitJpaTest which implements buildSchema() in a generic way (e.g. by requesting a list of schema files via an abstract method) and use this subclass with your unit tests?

/Torsten

Richard Walsh

unread,
Oct 25, 2015, 10:16:50 AM10/25/15
to Torsten Juergeleit, Sculptor Generator
Yes, makes sense, looking into all that now.

I think I will also write extensions to migrate all tests onto annotations rather than XML as it will help me with some of the setup required.

Now that I know how extensions work thats all actually pretty straight forward. 

--
You received this message because you are subscribed to a topic in the Google Groups "Sculptor Generator" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/sculptorgenerator/xL7UKQDg-Ws/unsubscribe.
To unsubscribe from this group and all its topics, send an email to sculptorgenera...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



Taskize Limited - Innovative solutions for Financial Services Technology.
Registered address: 33 Cannon Street, London, EC4M 5SB. Registered in England No. 7921239. This message may contain information that is privileged or confidential. If you are not the intended recipient please delete it and inform the sender immediately.

Richard Walsh

unread,
Oct 26, 2015, 7:09:28 AM10/26/15
to Torsten Juergeleit, Sculptor Generator
I am trying to override the Base Test class from AbstractDbUnitJpaTests to be my own base test class. . Here is the code that I have overridden in the extension classes. 

@ChainOverride

class PropertiesOverride extends Properties{

@Inject extension PropertiesBase propertiesBase

override String databaseJpaTestCaseClass() {

"com.taskize.repository.AbstractDbUnitJpaTests"

}

}


However the Java code generated is coming up with some issues. 

A java class called PropertiesOverride is created.

It seems to think that the following property should exist.

org.sculptor.generator.ext.PropertiesMethodIndexes.DATABASEJPATESTCASECLASS

And also that Properties should have a method called ._chained_databaseJpaTestCaseClass();

Also as its not a Tmpl class I am not sure if I should call my class PropertiesImplOverride or just PropertiesOverride. 



Torsten Juergeleit

unread,
Oct 26, 2015, 11:19:47 AM10/26/15
to Sculptor Generator
In this case it's not necessary to override this Properties method. Here the following line in sculptor-generator.properties can be used:

framework.test.AbstractDbUnitJpaTests=com.taskize.repository.AbstractDbUnitJpaTests


Your findings regarding PropertiesOverride are correct. The @ChainOverride annotation generates these artefacts.

And the class name of the extension class must use the suffix "Override". So the class name PropertiesOverride is correct.

/Torsten




On Monday, October 26, 2015 at 12:09:28 PM UTC+1, Richard Walsh wrote:
I am trying to override the Base Test class from AbstractDbUnitJpaTests to be my own base test class. . Here is the code that I have overridden in the extension classes. 

@ChainOverride

class PropertiesOverride extends Properties{

@Inject extension PropertiesBase propertiesBase

override String databaseJpaTestCaseClass() {

"com.taskize.repository.AbstractDbUnitJpaTests"

}

}


However the Java code generated is coming up with some issues. 

A java class called PropertiesOverride is created.

It seems to think that the following property should exist.

org.sculptor.generator.ext.PropertiesMethodIndexes.DATABASEJPATESTCASECLASS

And also that Properties should have a method called ._chained_databaseJpaTestCaseClass();

Also as its not a Tmpl class I am not sure if I should call my class PropertiesImplOverride or just PropertiesOverride. 



On 25 October 2015 at 14:16, Richard Walsh wrote:
Yes, makes sense, looking into all that now.

I think I will also write extensions to migrate all tests onto annotations rather than XML as it will help me with some of the setup required.

Now that I know how extensions work thats all actually pretty straight forward. 

On 23 October 2015 at 19:04, Torsten Juergeleit wrote:
How about overriding buildSchema() in your generated unit test class?

Or how about creating your own subclass of AbstractDUnitJpaTest which implements buildSchema() in a generic way (e.g. by requesting a list of schema files via an abstract method) and use this subclass with your unit tests?

/Torsten


On Thursday, October 22, 2015 at 7:55:21 PM UTC+2, richard.walsh wrote:
Hi - 

I am trying to figure out how to add some SQL to the DDL that is run at Unit Test time to populate Hypersonic.

We have a situation where we need to run a number of different schemas and we also have our own sequence_ ID generators. Once for each entity in each schema.

So the setup required for tests wont work out of the box.

How can we amend this behaviour?

I have noticed that the AbstractDUnitJpaTest.class has a method that looks for additional sql in the generated directories, but as its looking under generated this sql gets wiped.

    protected void buildSchema() {

    if (!buildSchemaExecuted) {

            executeScript("file:src/test/generated/resources/dbunit/ddl.sql");

            executeScript("file:src/test/generated/resources/dbunit/ddl_additional.sql");

            buildSchemaExecuted = true;

        }

    };


Help appreciated.


I have searched GIT codebase for some hints as to what I could do but nothing really jumped out at me. 


Thanks,

Richie.



Richard Walsh

unread,
Oct 26, 2015, 2:00:38 PM10/26/15
to Torsten Juergeleit, Sculptor Generator
Is that really all I have to do.

Having  set framework.test.AbstractDbUnitJpaTests=com.taskize.repository.AbstractDbUnitJpaTests in sculptor.generator.properties the Test Classes are still pointing to the scultpor class of the same name!

--
You received this message because you are subscribed to a topic in the Google Groups "Sculptor Generator" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/sculptorgenerator/xL7UKQDg-Ws/unsubscribe.
To unsubscribe from this group and all its topics, send an email to sculptorgenera...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Torsten Juergeleit

unread,
Oct 26, 2015, 6:37:37 PM10/26/15
to Sculptor Generator
Is that really all I have to do.

Sure.

Having  set framework.test.AbstractDbUnitJpaTests=com.taskize.repository.AbstractDbUnitJpaTests in sculptor.generator.properties the Test Classes are still pointing to the scultpor class of the same name!

The service test classes are only generated if not present. So please delete them and regenerate.

/Torsten


On Monday, October 26, 2015 at 7:00:38 PM UTC+1, Richard Walsh wrote:
Is that really all I have to do.

Having  set framework.test.AbstractDbUnitJpaTests=com.taskize.repository.AbstractDbUnitJpaTests in sculptor.generator.properties the Test Classes are still pointing to the scultpor class of the same name!

Richard Walsh

unread,
Oct 27, 2015, 6:50:25 AM10/27/15
to Torsten Juergeleit, Sculptor Generator
Ah ok. Forgot that. Thanks. 

--
You received this message because you are subscribed to a topic in the Google Groups "Sculptor Generator" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/sculptorgenerator/xL7UKQDg-Ws/unsubscribe.
To unsubscribe from this group and all its topics, send an email to sculptorgenera...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages