Skip to content
Rodionov Aleksandr edited this page May 28, 2018 · 5 revisions

Conceptually JFixtures is a translator - it translates(or compiles) fixtures(yaml) files into a SQL file. Roughly it has fixtures folder as input, SQL file as output and a few options, like, which SQL dialect to take to translate to. There are two ways in using JFixtures: as a java library and as a command line tool.

JFixtures as a java library

Include it from Maven Central to your project and all is set.

com.github.vkorobkov.jfixtures.JFixtures class is an entry point of JFixtures API:

import com.github.vkorobkov.jfixtures.JFixtures;

JFixtures.sql99("/home/user/fixtures-folder").toFile("home/user/test-data.sql");

This example compiles fixtures from /home/user/fixtures-folder to home/user/test-data.sql using SQL-99 dialect.

More examples are below:

Compile fixtures to a string

import com.github.vkorobkov.jfixtures.JFixtures;

String testSql = JFixtures.sql99("/home/user/fixtures-folder").asString();

Compile fixtures to SQL file with MySql dialect:

import com.github.vkorobkov.jfixtures.JFixtures;

JFixtures.mysql("/home/user/fixtures-folder").toFile("home/user/test-data.sql");

Compile fixtures to SQL file with Microsoft SQL dialect:

import com.github.vkorobkov.jfixtures.JFixtures;

JFixtures.microsoftSql("/home/user/fixtures-folder").toFile("home/user/test-data.sql");

Compile fixtures to XML

There is also JFixtures.xml method which allows to save the result into either XML file or just into a string with XML content.

This is a demo project to show how JFixtures works on practice:

https://github.com/rodionovsasha/CommentService

JFixtures as a command line tool

JFixtures is also distributed as a self packaged runnable jar which could be used as command line utility. This is a separate project, please, check it out on GitHub