use of org.talend.dataprep.schema.csv.CSVFormatFamily in project data-prep by Talend.
the class DataSetJSONTest method testRoundTrip.
@Test
public void testRoundTrip() throws Exception {
DataSet dataSet = from(DataSetJSONTest.class.getResourceAsStream("test3.json"));
final DataSetMetadata metadata = dataSet.getMetadata();
metadata.getContent().addParameter(CSVFormatFamily.SEPARATOR_PARAMETER, ",");
metadata.getContent().setFormatFamilyId(new CSVFormatFamily().getBeanId());
assertNotNull(metadata);
StringWriter writer = new StringWriter();
to(dataSet, writer);
assertThat(writer.toString(), sameJSONAsFile(DataSetJSONTest.class.getResourceAsStream("test3.json")));
}
use of org.talend.dataprep.schema.csv.CSVFormatFamily in project data-prep by Talend.
the class DataSetServiceTest method delete.
@Test
public void delete() throws Exception {
String expectedId = UUID.randomUUID().toString();
DataSetMetadata dataSetMetadata = metadataBuilder.metadata().id(expectedId).formatFamilyId(new CSVFormatFamily().getBeanId()).build();
dataSetMetadata.getContent().addParameter(CSVFormatFamily.SEPARATOR_PARAMETER, ";");
dataSetMetadataRepository.save(dataSetMetadata);
List<String> ids = from(when().get("/datasets").asString()).get("");
assertThat(ids.size(), is(1));
int before = dataSetMetadataRepository.size();
when().delete("/datasets/{id}", expectedId).then().statusCode(OK.value());
int after = dataSetMetadataRepository.size();
logger.debug("delete before {} after {}", before, after);
assertThat(before - after, is(1));
}
use of org.talend.dataprep.schema.csv.CSVFormatFamily in project data-prep by Talend.
the class DataSetServiceTest method listDateSort.
@Test
public void listDateSort() throws Exception {
when().get("/datasets?sort=creationDate").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").asString();
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++]));
}
}
use of org.talend.dataprep.schema.csv.CSVFormatFamily in project data-prep by Talend.
the class DataSetJSONTest method testWrite1.
@Test
public void testWrite1() throws Exception {
final ColumnMetadata.Builder columnBuilder = //
ColumnMetadata.Builder.column().id(//
5).name(//
"column1").type(//
Type.STRING).empty(//
0).invalid(//
10).valid(50);
DataSetMetadata metadata = metadataBuilder.metadata().id("1234").name("name").author("author").created(0).row(columnBuilder).build();
final DataSetContent content = metadata.getContent();
content.addParameter(CSVFormatFamily.SEPARATOR_PARAMETER, ",");
content.setFormatFamilyId(new CSVFormatFamily().getBeanId());
content.setMediaType("text/csv");
metadata.getLifecycle().qualityAnalyzed(true);
metadata.getLifecycle().schemaAnalyzed(true);
LocalStoreLocation location = new LocalStoreLocation();
metadata.setLocation(location);
StringWriter writer = new StringWriter();
DataSet dataSet = new DataSet();
dataSet.setMetadata(metadata);
to(dataSet, writer);
assertThat(writer.toString(), sameJSONAsFile(DataSetJSONTest.class.getResourceAsStream("test2.json")));
}
use of org.talend.dataprep.schema.csv.CSVFormatFamily in project data-prep by Talend.
the class DataSetServiceTest method getMetadata.
@Test
public void getMetadata() throws Exception {
DataSetMetadataBuilder builder = metadataBuilder.metadata().id("1234");
builder.row(//
ColumnMetadata.Builder.column().id(//
1234).name(//
"id").empty(//
0).invalid(//
0).valid(//
0).type(//
Type.STRING)).created(//
0).name(//
"name").author(//
"author").footerSize(//
0).headerSize(//
1).qualityAnalyzed(//
true).schemaAnalyzed(//
true).formatFamilyId(//
new CSVFormatFamily().getBeanId()).mediaType("text/csv");
DataSetMetadata metadata = builder.build();
metadata.getContent().addParameter(CSVFormatFamily.SEPARATOR_PARAMETER, ";");
dataSetMetadataRepository.save(metadata);
String contentAsString = when().get("/datasets/{id}/metadata", "1234").asString();
InputStream expected = this.getClass().getResourceAsStream("../metadata1.json");
assertThat(contentAsString, sameJSONAsFile(expected));
Boolean isFavorites = from(contentAsString).get("metadata.favorite");
assertFalse(isFavorites);
// add favorite
UserData userData = new UserData(security.getUserId(), versionService.version().getVersionId());
HashSet<String> favorites = new HashSet<>();
favorites.add("1234");
userData.setFavoritesDatasets(favorites);
userDataRepository.save(userData);
contentAsString = when().get("/datasets/{id}/metadata", "1234").asString();
isFavorites = from(contentAsString).get("metadata.favorite");
assertTrue(isFavorites);
}
Aggregations