Arquillian Cube and data populators


#1

Hello, currently Arquillian Cube can be really interesting to be used for end to end tests, integration tests or contract tests, since you can setup your testing environment on a docker-compose file (for example databases required by the service or other services).

The important point here is that sometimes before executing a test you want to clean (or not) a database , then populate it with some known data to provide a known state, and then execute the test.

Notice that this new module should be called populator and not persistence since you can even populate data to another service too. So the idea is to provide a populator API/SPI so other technologies can hook. For example I am thinking NoSQLUnit for NoSQL databases, DBUnit (and in long term APE) for SQL and RestAssured for services.

Then the idea is that you can do in your test something like:

@PopulateTo(container="mongodb", exposedPort=8080, clean=true)
@UsingDataSet("/com/myapp/mydata.json")
@WithAuthentication(key="username", value="alex")
@WithAuthentication(key="password", value="alex")
@Test
public void executeMyTest(){}

Things to take into consideration:

  1. This only works in client mode
  2. It is not a replacement for APE/DBUnit/NoSQLUnit, it is only a populator to prepare data for tests (it does not verify anything)

In previous test, before it is executed, data defined in classpath location com/myapp/mydata.json is sent to container named mongodb using the binding port resolution of exposed port 8080 (optional parameter) suing NoSQLUnit underneath (but of course this is an implementation detail). Notice that since there is no standard way to define how authentication is managed, sometimes are login and password others a certificate, I think that from the SPI level we should provide a generic way.

I know that the test looks with so many annotations, but I really like that in this case any test reader knows exactly what is going to be tested and how.

WDYT?