@Test
public void list() throws Exception {

    when().get("/datasets").then().statusCode(OK.value()).body(equalTo("[]"));
    // Adds 1 data set to store
    String id1 = UUID.randomUUID().toString();
    final DataSetMetadata metadata = metadataBuilder
            .metadata()
            .id(id1)
            .name("name1")
            .author("anonymous")
            .created(0)
            .formatFamilyId(new CSVFormatFamily().getBeanId())
            .build();
    metadata.getContent().addParameter(CSVFormatFamily.SEPARATOR_PARAMETER, ";");
    dataSetMetadataRepository.save(metadata);
    String expected =
            "[{\"id\":\"" + id1 + "\",\"name\":\"name1\",\"records\":0,\"ownerId\":\"anonymous\",\"created\":0}]";
    InputStream content = when().get("/datasets").asInputStream();
    String contentAsString = IOUtils.toString(content, UTF_8);
    assertThat(contentAsString, sameJSONAs(expected).allowingExtraUnexpectedFields().allowingAnyArrayOrdering());
    // Adds a new data set to store
    String id2 = UUID.randomUUID().toString();
    DataSetMetadata metadata2 = metadataBuilder
            .metadata()
            .id(id2)
            .name("name2")
            .author("anonymous")
            .created(0)
            .formatFamilyId(new CSVFormatFamily().getBeanId())
            .build();
    metadata2.getContent().addParameter(CSVFormatFamily.SEPARATOR_PARAMETER, ";");
    dataSetMetadataRepository.save(metadata2);
    when().get("/datasets").then().statusCode(OK.value());
    String response = when().get("/datasets").asString();
    List<String> ids = from(response).get("id");
    assertThat(ids, hasItems(id1, id2));
    // check favorites
    List<Boolean> favoritesResp = from(response).get("favorite"); //$NON-NLS-1$
    assertEquals(2, favoritesResp.size());
    assertFalse(favoritesResp.get(0));
    assertFalse(favoritesResp.get(1));
    // add favorite
    UserData userData = new UserData(security.getUserId(), versionService.version().getVersionId());
    HashSet<String> favorites = new HashSet<>();
    favorites.add(id1);
    favorites.add(id2);
    userData.setFavoritesDatasets(favorites);
    userDataRepository.save(userData);
    favoritesResp = from(when().get("/datasets").asString()).get("favorite"); //$NON-NLS-1$
    assertEquals(2, favoritesResp.size());
    assertTrue(favoritesResp.get(0));
    assertTrue(favoritesResp.get(1));
}