Groovy DSL Workshop

Vladimír Oraný

Test Facilitator @ Agorapulse



Domain Specific Language

A domain-specific language is a computer language specialized to a particular application domain.


Using imperative programming we need to describe how to solve problem.


Using declarative programming we need to describe what needs to be solved.

List<Session> results = []
for (Session candidate in sessions) {
    if (candidate.speaker == me) {
select * from speaker
where sp.speaker = :me


Defines own syntax with its own parser.


Uses existing general purpose programming language

select * from session
where speaker = :me

Examples - jOOQ, AUTHOR.LAST_NAME, count())

Examples - Spreadsheet Builder

PoiSpreadsheetBuilder.create(file).build {                                              
    sheet('Sample') {                                                                   
        row {                                                                           
            cell 'A'                                                                    
            cell 'B'
            cell 'C'
        row {
            cell 1
            cell 2
            cell 3

Examples - Gru

void 'upload file with message'() {
        gru.test {
            post '/moons/upload', {
                upload {                                                            
                    params message: 'Hello'                                         
                    file 'theFile', 'hello.txt', inline('Hello World'), 'text/plain'
                executes controller.&postWithMessageAndImage                        
            expect {
                json 'uploadResult.json'
static <U extends ControllerUnitTest> RequestDefinitionBuilder executes(
    RequestDefinitionBuilder self, 
    Closure method
) {
    if (!(method instanceof MethodClosure)) {
        throw new IllegalArgumentException('Closure must be method closure.')
    self.command(UrlMappingsMinion) {
        action = method as MethodClosure

Examples - UML (yUML)

[note: You can stick notes on diagrams too!{bg:skyblue}]
[Customer]<>1-orders 0..*>[Order]

Groovy DSL Workshop

Thank You

Groovy DSL Workshop

By musketyr

Groovy DSL Workshop

  • 1,204