@Test
public void compatibleDatasetsListDateSort() throws Exception {

    String dataSetId = createCSVDataSet(this.getClass().getResourceAsStream(TAGADA_CSV), "ds-13");
    String dataSetId2 = createCSVDataSet(this.getClass().getResourceAsStream(TAGADA_CSV), "ds-12");
    String dataSetId3 = createCSVDataSet(this.getClass().getResourceAsStream(TAGADA_CSV), "ds-11");
    DataSetMetadata metadata1 = dataSetMetadataRepository.get(dataSetId);
    metadata1.setName("CCCC");
    dataSetMetadataRepository.save(metadata1);
    DataSetMetadata metadata2 = dataSetMetadataRepository.get(dataSetId2);
    metadata2.setName("BBBB");
    dataSetMetadataRepository.save(metadata2);
    DataSetMetadata metadata3 = dataSetMetadataRepository.get(dataSetId3);
    metadata3.setName("AAAA");
    dataSetMetadataRepository.save(metadata3);
    // when
    final String actual = expect()
            .statusCode(200)
            .log()
            .ifValidationFails()
            .get("/datasets/{id}/compatibledatasets?sort=creationDate", dataSetId)
            .asString();
    // Ensure order by name (most recent first)
    final Iterator<JsonNode> elements = mapper.readTree(actual).elements();
    String[] expectedNames = new String[] { "AAAA", "BBBB" };
    int i = 0;
    while (elements.hasNext()) {
        assertThat(elements.next().get("name").asText(), is(expectedNames[i++]));
    }
}