use of org.talend.dataprep.schema.csv.CSVFormatFamily in project data-prep by Talend.
the class DataSetServiceTest method listNameSort.
@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++]));
}
}
use of org.talend.dataprep.schema.csv.CSVFormatFamily in project data-prep by Talend.
the class DataSetServiceTest method insertEmptyDataSet.
private String insertEmptyDataSet() {
String datasetId = UUID.randomUUID().toString();
DataSetMetadata dataSetMetadata = metadataBuilder.metadata().id(datasetId).formatFamilyId(new CSVFormatFamily().getBeanId()).build();
dataSetMetadata.getContent().addParameter(CSVFormatFamily.SEPARATOR_PARAMETER, ";");
dataSetMetadataRepository.save(dataSetMetadata);
contentStore.storeAsRaw(dataSetMetadata, new ByteArrayInputStream(new byte[0]));
return datasetId;
}
use of org.talend.dataprep.schema.csv.CSVFormatFamily in project data-prep by Talend.
the class DataSetServiceTest method listNameOrder.
@Test
public void listNameOrder() throws Exception {
when().get("/datasets?sort=name&order=asc").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(20).formatFamilyId(new CSVFormatFamily().getBeanId()).build();
dataSetMetadataRepository.save(metadata1);
String id2 = UUID.randomUUID().toString();
final DataSetMetadata metadata2 = metadataBuilder.metadata().id(id2).name("CCCC").author("anonymous").created(0).formatFamilyId(new CSVFormatFamily().getBeanId()).build();
dataSetMetadataRepository.save(metadata2);
String id3 = UUID.randomUUID().toString();
final DataSetMetadata metadata3 = metadataBuilder.metadata().id(id3).name("bbbb").author("anonymous").created(0).formatFamilyId(new CSVFormatFamily().getBeanId()).build();
dataSetMetadataRepository.save(metadata3);
// Ensure order by name (last character from alphabet first)
String actual = when().get("/datasets?sort=name&order=desc").asString();
Iterator<JsonNode> elements = mapper.readTree(actual).elements();
String[] expectedNames = new String[] { "CCCC", "bbbb", "AAAA" };
int i = 0;
while (elements.hasNext()) {
assertThat(elements.next().get("name").asText(), is(expectedNames[i++]));
}
// Ensure order by name (last character from alphabet first when no order value)
actual = when().get("/datasets?sort=name").asString();
elements = mapper.readTree(actual).elements();
expectedNames = new String[] { "CCCC", "bbbb", "AAAA" };
i = 0;
while (elements.hasNext()) {
assertThat(elements.next().get("name").asText(), is(expectedNames[i++]));
}
// Ensure order by name (first character from alphabet first)
actual = when().get("/datasets?sort=name&order=asc").asString();
elements = mapper.readTree(actual).elements();
expectedNames = new String[] { "AAAA", "bbbb", "CCCC" };
i = 0;
while (elements.hasNext()) {
assertThat(elements.next().get("name").asText(), is(expectedNames[i++]));
}
}
use of org.talend.dataprep.schema.csv.CSVFormatFamily in project data-prep by Talend.
the class DataSetServiceTest method list.
@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,\"author\":\"anonymous\",\"nbLinesHeader\":0,\"nbLinesFooter\":0,\"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
// $NON-NLS-1$
List<Boolean> favoritesResp = from(response).get("favorite");
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);
// $NON-NLS-1$
favoritesResp = from(when().get("/datasets").asString()).get("favorite");
assertEquals(2, favoritesResp.size());
assertTrue(favoritesResp.get(0));
assertTrue(favoritesResp.get(1));
}
use of org.talend.dataprep.schema.csv.CSVFormatFamily in project data-prep by Talend.
the class DataSetServiceTest method listDateOrder.
@Test
public void listDateOrder() throws Exception {
when().get("/datasets?sort=creationDate&order=asc").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(20).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 date (most recent first)
String actual = when().get("/datasets?sort=creationDate&order=desc").asString();
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++]));
}
// Ensure order by date (oldest first when no order value)
actual = when().get("/datasets?sort=creationDate").asString();
elements = mapper.readTree(actual).elements();
expectedNames = new String[] { "AAAA", "BBBB" };
i = 0;
while (elements.hasNext()) {
assertThat(elements.next().get("name").asText(), is(expectedNames[i++]));
}
// Ensure order by date (oldest first)
actual = when().get("/datasets?sort=creationDate&order=asc").asString();
elements = mapper.readTree(actual).elements();
expectedNames = new String[] { "BBBB", "AAAA" };
i = 0;
while (elements.hasNext()) {
assertThat(elements.next().get("name").asText(), is(expectedNames[i++]));
}
}
Aggregations