Search in sources :

Example 1 with CSVFormatFamily

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")));
}
Also used : DataSet(org.talend.dataprep.api.dataset.DataSet) DataSetMetadata(org.talend.dataprep.api.dataset.DataSetMetadata) CSVFormatFamily(org.talend.dataprep.schema.csv.CSVFormatFamily) ServiceBaseTest(org.talend.ServiceBaseTest) Test(org.junit.Test)

Example 2 with CSVFormatFamily

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));
}
Also used : Matchers.containsString(org.hamcrest.Matchers.containsString) Matchers.isEmptyString(org.hamcrest.Matchers.isEmptyString) DataSetMetadata(org.talend.dataprep.api.dataset.DataSetMetadata) CSVFormatFamily(org.talend.dataprep.schema.csv.CSVFormatFamily) DataSetBaseTest(org.talend.dataprep.dataset.DataSetBaseTest) Test(org.junit.Test)

Example 3 with CSVFormatFamily

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++]));
    }
}
Also used : JsonNode(com.fasterxml.jackson.databind.JsonNode) Matchers.containsString(org.hamcrest.Matchers.containsString) Matchers.isEmptyString(org.hamcrest.Matchers.isEmptyString) DataSetMetadata(org.talend.dataprep.api.dataset.DataSetMetadata) CSVFormatFamily(org.talend.dataprep.schema.csv.CSVFormatFamily) DataSetBaseTest(org.talend.dataprep.dataset.DataSetBaseTest) Test(org.junit.Test)

Example 4 with CSVFormatFamily

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")));
}
Also used : ColumnMetadata(org.talend.dataprep.api.dataset.ColumnMetadata) DataSet(org.talend.dataprep.api.dataset.DataSet) DataSetContent(org.talend.dataprep.api.dataset.DataSetContent) DataSetMetadata(org.talend.dataprep.api.dataset.DataSetMetadata) CSVFormatFamily(org.talend.dataprep.schema.csv.CSVFormatFamily) LocalStoreLocation(org.talend.dataprep.api.dataset.location.LocalStoreLocation) ServiceBaseTest(org.talend.ServiceBaseTest) Test(org.junit.Test)

Example 5 with CSVFormatFamily

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);
}
Also used : DataSetMetadataBuilder(org.talend.dataprep.dataset.DataSetMetadataBuilder) UserData(org.talend.dataprep.api.user.UserData) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) Matchers.containsString(org.hamcrest.Matchers.containsString) Matchers.isEmptyString(org.hamcrest.Matchers.isEmptyString) CSVFormatFamily(org.talend.dataprep.schema.csv.CSVFormatFamily) DataSetMetadata(org.talend.dataprep.api.dataset.DataSetMetadata) HashSet(java.util.HashSet) DataSetBaseTest(org.talend.dataprep.dataset.DataSetBaseTest) Test(org.junit.Test)

Aggregations

DataSetMetadata (org.talend.dataprep.api.dataset.DataSetMetadata)11 CSVFormatFamily (org.talend.dataprep.schema.csv.CSVFormatFamily)11 Test (org.junit.Test)10 Matchers.containsString (org.hamcrest.Matchers.containsString)9 Matchers.isEmptyString (org.hamcrest.Matchers.isEmptyString)9 DataSetBaseTest (org.talend.dataprep.dataset.DataSetBaseTest)8 JsonNode (com.fasterxml.jackson.databind.JsonNode)4 ByteArrayInputStream (java.io.ByteArrayInputStream)4 HashSet (java.util.HashSet)3 UserData (org.talend.dataprep.api.user.UserData)3 InputStream (java.io.InputStream)2 ServiceBaseTest (org.talend.ServiceBaseTest)2 DataSet (org.talend.dataprep.api.dataset.DataSet)2 ColumnMetadata (org.talend.dataprep.api.dataset.ColumnMetadata)1 DataSetContent (org.talend.dataprep.api.dataset.DataSetContent)1 LocalStoreLocation (org.talend.dataprep.api.dataset.location.LocalStoreLocation)1 DataSetMetadataBuilder (org.talend.dataprep.dataset.DataSetMetadataBuilder)1