Skip to content

Support ${SQL.FILE:...} DSL to allow loading database queries from external SQL files #736

@authorjapps

Description

@authorjapps

Overview

Currently, Zerocode provides several convenient DSL tokens like ${JSON.FILE:...}, ${XML.FILE:...}, and ${GQL.FILE:...} to externalize large request payloads into separate files. This keeps the main scenario JSON/YAML files clean and readable.

However, when performing database testing (e.g., against Postgres, MySQL, Sybase or Oracle), complex SQL queries often have to be hardcoded as strings within the request body of a step. This can make the scenario file bulky and difficult to read(maintain), especially for long INSERT scripts or complex JOIN queries.

We should introduce a ${SQL.FILE:<path_to_file>} DSL token to allow users to store their SQL queries in .sql files and inject them into the request body dynamically at runtime, mirroring the behavior of GQL.FILE.

Example usage:

{
    "name": "execute_complex_query",
    "url": "org.jsmart.zerocode.zerocodejavaexec.DbSqlExecutor",
    "operation": "execute",
    "request": "${SQL.FILE:test_data/queries/fetch_user_details.sql}",
    "assertions": {
        "id": 101
    }
}

Acceptance Criteria (ACs)

  • AC1: Support the ${SQL.FILE:path/to/query.sql} token within the request section of a Zerocode step.

  • AC2: The framework must resolve the file path relative to the src/test/resources folder (consistent with other .FILE DSLs).

  • AC3: The content of the .sql file should be loaded as a plain string and injected into the step execution context before the DB executor is called.

Relevant Examples

You can refer to the existing implementation of ${XML.FILE:...} in the project's integration tests to see how similar tokens are handled.

Metadata

Metadata

Assignees

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions