@Test
public void should_list_filtered_datasets_properly() throws Exception {

    // create data sets
    final String dataSetId1 = createCSVDataSet(this.getClass().getResourceAsStream("../tagada3.csv"), "dataset1");
    final String dataSetId2 = createCSVDataSet(this.getClass().getResourceAsStream("../avengers.csv"), "dataset2");
    final String dataSetId3 = createCSVDataSet(this.getClass().getResourceAsStream("../tagada.csv"), "dataset3");
    createCSVDataSet(this.getClass().getResourceAsStream("../tagada2.csv"), "dataset4");
    // Make dataset1 more recent
    final DataSetMetadata dataSetMetadata1 = dataSetMetadataRepository.get(dataSetId1);
    dataSetMetadata1.getGovernance().setCertificationStep(Certification.CERTIFIED);
    dataSetMetadata1.setLastModificationDate((now().getEpochSecond() + 1) * 1_000);
    dataSetMetadataRepository.save(dataSetMetadata1);
    final DataSetMetadata dataSetMetadata2 = dataSetMetadataRepository.get(dataSetId2);
    dataSetMetadataRepository.save(dataSetMetadata2);
    final DataSetMetadata dataSetMetadata3 = dataSetMetadataRepository.get(dataSetId3);
    dataSetMetadata3.getGovernance().setCertificationStep(Certification.CERTIFIED);
    dataSetMetadataRepository.save(dataSetMetadata3);
    UserData userData = new UserData();
    userData.setUserId(security.getUserId());
    userData.addFavoriteDataset(dataSetMetadata1.getId());
    userData.addFavoriteDataset(dataSetMetadata2.getId());
    userDataRepository.save(userData);
    // @formatter:off
    // certified, favorite and recent
    given()
            .queryParam("favorite", "true")
            .queryParam("certified", "true")
            .queryParam("limit", "true")
            .when()
            .get("/datasets")
            .then()
            .statusCode(200)
            .body("name", hasItem("dataset1"))
            .body("name", hasSize(1));
    // certified, favorite and recent
    given()
            .queryParam("favorite", "true")
            .queryParam("certified", "true")
            .queryParam("limit", "true")
            .queryParam("name", "2")
            .when()
            .get("/datasets")
            .then()
            .statusCode(200)
            .body("name", hasSize(0));
    // only names
    given()
            .queryParam("name", "ATAset2")
            .when()
            .get("/datasets")
            .then()
            .statusCode(200)
            .body("name", hasItem("dataset2"))
            .body("name", hasSize(1));
    // only favorites
    given()
            .queryParam("favorite", "true")
            .when()
            .get("/datasets")
            .then()
            .statusCode(200)
            .body("name", hasItems("dataset1", "dataset2"))
            .body("name", hasSize(2));
    // only certified
    given()
            .queryParam("certified", "true")
            .when()
            .get("/datasets")
            .then()
            .statusCode(200)
            .body("name", hasItems("dataset1", "dataset3"))
            .body("name", hasSize(2));
    // only recent
    given()
            .queryParam("limit", "true")
            .queryParam("sort", LAST_MODIFICATION_DATE.camelName())
            .when()
            .get("/datasets")
            .then()
            .statusCode(200)
            .body("name", hasItems("dataset1", "dataset3", "dataset4"))
            .body("name", hasSize(3));
    // all
    when()
            .get("/datasets")
            .then()
            .statusCode(200)
            .body("name", hasItems("dataset1", "dataset2", "dataset3", "dataset4"))
            .body("name", hasSize(4));
    // @formatter:on
}