Search in sources :

Example 6 with CSVFormatFamily

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++]));
    }
}
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 7 with CSVFormatFamily

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;
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) 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)

Example 8 with CSVFormatFamily

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++]));
    }
}
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 9 with CSVFormatFamily

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

Example 10 with CSVFormatFamily

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++]));
    }
}
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)

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