@Test
public void listNameSort() throws Exception {

    when().get("/datasets?sort=name").then().statusCode(OK.value()).body(equalTo("[]"));
    // Adds 2 data set metadata to store
    String id1 = UUID.randomUUID().toString();
    final DataSetMetadata metadata1 = metadataBuilder
            .metadata()
            .id(id1)
            .name("AAAA")
            .author("anonymous")
            .created(0)
            .formatFamilyId(new CSVFormatFamily().getBeanId())
            .build();
    dataSetMetadataRepository.save(metadata1);
    String id2 = UUID.randomUUID().toString();
    final DataSetMetadata metadata2 = metadataBuilder
            .metadata()
            .id(id2)
            .name("BBBB")
            .author("anonymous")
            .created(0)
            .formatFamilyId(new CSVFormatFamily().getBeanId())
            .build();
    dataSetMetadataRepository.save(metadata2);
    // Ensure order by name (most recent first)
    String actual = when().get("/datasets?sort=name").asString();
    final Iterator<JsonNode> elements = mapper.readTree(actual).elements();
    String[] expectedNames = new String[] { "BBBB", "AAAA" };
    int i = 0;
    while (elements.hasNext()) {
        assertThat(elements.next().get("name").asText(), is(expectedNames[i++]));
    }
}