Ninja-Squad / DbSetup

An API for populating a database in unit tests
http://dbsetup.ninja-squad.com/
212 stars 34 forks source link

Fix/41 repeating values #42

Closed jnizet closed 9 years ago

jnizet commented 9 years ago

This allows repeating the same row several times. It's useful to populate the database with a large amount of values, using value generators. We could already do that with a simple for loop, but the syntax is prettier:

Insert.into("tag")
      .withGeneratedValue("id", ValueGenerators.sequence().startingAt(1L))
      .withGeneratedValue("name", ValueGenerators.stringSequence("tag-").startingAt(1L))
      .columns("description")
      .repeatingValues("fake description").times(1000)
      .build();

Note that we can also pass a Map instead of a vararg for the values. Also note that name/value rows built with a row builder can also be repeated:

Insert.into("tag")
      .withGeneratedValue("id", ValueGenerators.sequence().startingAt(1L))
      .withGeneratedValue("name", ValueGenerators.stringSequence("tag-").startingAt(1L))
      .row()
          .column("description", "fake description")
          .times(1000)
      .build();
clacote commented 9 years ago

The new API repeatingValues() is not documented as exemple in Insert javadoc.

clacote commented 9 years ago

Besides my (uneducated) comments: :+1:!