Search in sources :

Example 6 with DataSetMetadata

use of org.talend.dataprep.api.dataset.DataSetMetadata in project data-prep by Talend.

the class DataSetAPITest method testDataSetUpdateMetadata.

@Test
public void testDataSetUpdateMetadata() throws Exception {
    // given
    final String dataSetId = testClient.createDataset("dataset/dataset.csv", "tagada");
    // when
    final String jsonOriginalMetadata = when().get("/api/datasets/{id}/metadata", dataSetId).asString();
    final DataSetMetadata metadata = mapper.readValue(jsonOriginalMetadata, DataSetMetadata.class);
    metadata.setName("Toto");
    final String jsonMetadata = mapper.writeValueAsString(metadata);
    given().body(jsonMetadata).when().put("/api/datasets/{id}/metadata", dataSetId).asString();
    final String jsonUpdatedMetadata = when().get("/api/datasets/{id}/metadata", dataSetId).asString();
    final DataSetMetadata updatedMetadata = mapper.readValue(jsonUpdatedMetadata, DataSetMetadata.class);
    // then
    assertEquals(updatedMetadata, metadata);
}
Also used : DataSetMetadata(org.talend.dataprep.api.dataset.DataSetMetadata) UserDataSetMetadata(org.talend.dataprep.dataset.service.UserDataSetMetadata) Test(org.junit.Test)

Example 7 with DataSetMetadata

use of org.talend.dataprep.api.dataset.DataSetMetadata in project data-prep by Talend.

the class DataSetAPITest method should_list_filtered_datasets_properly.

@Test
public void should_list_filtered_datasets_properly() throws Exception {
    // create data sets
    final String dataSetId1 = testClient.createDataset("dataset/dataset.csv", "dataset1");
    final String dataSetId2 = testClient.createDataset("dataset/dataset.csv", "dataset2");
    final String dataSetId3 = testClient.createDataset("dataset/dataset.csv", "dataset3");
    testClient.createDataset("dataset/dataset.csv", "dataset4");
    // Make dataset1 more recent
    final DataSetMetadata dataSetMetadata1 = dataSetMetadataRepository.get(dataSetId1);
    dataSetMetadata1.getGovernance().setCertificationStep(DataSetGovernance.Certification.CERTIFIED);
    dataSetMetadata1.setLastModificationDate((now().getEpochSecond() + 1) * 1_000);
    dataSetMetadataRepository.save(dataSetMetadata1);
    final DataSetMetadata dataSetMetadata2 = dataSetMetadataRepository.get(dataSetId2);
    dataSetMetadataRepository.save(dataSetMetadata2);
    final DataSetMetadata dataSetMetadata3 = dataSetMetadataRepository.get(dataSetId3);
    dataSetMetadata3.getGovernance().setCertificationStep(DataSetGovernance.Certification.CERTIFIED);
    dataSetMetadataRepository.save(dataSetMetadata3);
    // add favorite
    UserData userData = new UserData(security.getUserId(), versionService.version().getVersionId());
    HashSet<String> favorites = new HashSet<>();
    favorites.add(dataSetMetadata1.getId());
    favorites.add(dataSetMetadata2.getId());
    userData.setFavoritesDatasets(favorites);
    userDataRepository.save(userData);
    // @formatter:off
    // certified, favorite and recent
    given().queryParam("favorite", "true").queryParam("certified", "true").queryParam("limit", "true").queryParam("name", "dataset").when().get("/api/datasets").then().statusCode(200).body("name", hasItem("dataset1")).body("name", hasSize(1));
    // certified, favorite and recent
    given().queryParam("favorite", "true").queryParam("certified", "true").queryParam("limit", "true").queryParam("name", "2").when().get("/api/datasets").then().statusCode(200).body("name", hasSize(0));
    // only names
    given().queryParam("name", "ATASET2").when().get("/api/datasets").then().statusCode(200).body("name", hasItem("dataset2")).body("name", hasSize(1));
    // only favorites
    given().queryParam("favorite", "true").when().get("/api/datasets").then().statusCode(200).body("name", hasItems("dataset1", "dataset2")).body("name", hasSize(2));
    // only certified
    given().queryParam("certified", "true").when().get("/api/datasets").then().statusCode(200).body("name", hasItems("dataset1", "dataset3")).body("name", hasSize(2));
    // only recent
    given().queryParam("limit", "true").when().get("/api/datasets").then().statusCode(200).body("name", hasItems("dataset2", "dataset3", "dataset4")).body("name", hasSize(3));
    // all
    when().get("/api/datasets").then().statusCode(200).body("name", hasItems("dataset1", "dataset2", "dataset3", "dataset4")).body("name", hasSize(4));
// @formatter:on
}
Also used : UserData(org.talend.dataprep.api.user.UserData) DataSetMetadata(org.talend.dataprep.api.dataset.DataSetMetadata) UserDataSetMetadata(org.talend.dataprep.dataset.service.UserDataSetMetadata) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 8 with DataSetMetadata

use of org.talend.dataprep.api.dataset.DataSetMetadata in project data-prep by Talend.

the class PreparationAPITest method testPreparationInitialMetadata.

@Test
public void testPreparationInitialMetadata() throws Exception {
    // given
    final String preparationName = "testPreparationContentGet";
    final String preparationId = testClient.createPreparationFromFile("dataset/dataset.csv", preparationName, home.getId());
    // when
    final DataSetMetadata actual = testClient.getPrepMetadata(preparationId);
    // then
    assertNotNull(actual);
    final List<ColumnMetadata> columns = actual.getRowMetadata().getColumns();
    assertEquals(6, columns.size());
    final List<String> expectedColumns = Arrays.asList("id", "firstname", "lastname", "age", "date-of-birth", "alive");
    for (ColumnMetadata column : columns) {
        assertTrue(expectedColumns.contains(column.getName()));
    }
}
Also used : ColumnMetadata(org.talend.dataprep.api.dataset.ColumnMetadata) DataSetMetadata(org.talend.dataprep.api.dataset.DataSetMetadata) Test(org.junit.Test)

Example 9 with DataSetMetadata

use of org.talend.dataprep.api.dataset.DataSetMetadata in project data-prep by Talend.

the class APIPreparationConversionsTest method shouldEnrichPreparationWithDataset.

@Test
public void shouldEnrichPreparationWithDataset() {
    // given
    DataSetMetadata metadata = getDataSetMetadata("super dataset", 1001L);
    setupHystrixCommand(DataSetGetMetadata.class, metadata);
    final PreparationMessage preparation = getPreparationMessage(metadata.getId());
    Folder folder = getFolder("F-753854");
    setupHystrixCommand(LocatePreparation.class, folder);
    // when
    final EnrichedPreparation actual = conversionService.convert(preparation, EnrichedPreparation.class);
    // then
    assertEquals(metadata.getId(), actual.getSummary().getDataSetId());
    assertEquals(metadata.getName(), actual.getSummary().getDataSetName());
    assertEquals(metadata.getContent().getNbRecords(), actual.getSummary().getDataSetNbRow());
    final List<String> expectedSteps = preparation.getSteps().stream().map(Step::getId).collect(Collectors.toList());
    final List<String> actualSteps = actual.getSteps();
    assertNotNull(actualSteps);
    assertEquals(expectedSteps.size(), expectedSteps.size());
    expectedSteps.forEach(s -> assertTrue(actualSteps.contains(s)));
    assertEquals(folder, actual.getFolder());
}
Also used : EnrichedPreparation(org.talend.dataprep.api.service.api.EnrichedPreparation) PreparationMessage(org.talend.dataprep.api.preparation.PreparationMessage) Folder(org.talend.dataprep.api.folder.Folder) DataSetMetadata(org.talend.dataprep.api.dataset.DataSetMetadata) Test(org.junit.Test)

Example 10 with DataSetMetadata

use of org.talend.dataprep.api.dataset.DataSetMetadata in project data-prep by Talend.

the class PipelineTest method testPipeline.

@Test
public void testPipeline() throws Exception {
    // given
    final Pipeline pipeline = new Pipeline(NodeBuilder.source().to(output).build());
    final RowMetadata rowMetadata = new RowMetadata();
    final DataSetRow row1 = new DataSetRow(rowMetadata);
    final DataSetRow row2 = new DataSetRow(rowMetadata);
    final List<DataSetRow> records = new ArrayList<>();
    records.add(row1);
    records.add(row2);
    final DataSet dataSet = new DataSet();
    final DataSetMetadata metadata = new DataSetMetadata();
    metadata.setRowMetadata(rowMetadata);
    dataSet.setMetadata(metadata);
    dataSet.setRecords(records.stream());
    // when
    pipeline.execute(dataSet);
    // then
    assertThat(output.getCount(), is(2));
    assertThat(output.getRow(), is(row2));
    assertThat(output.getMetadata(), is(rowMetadata));
    assertThat(output.getSignal(), is(END_OF_STREAM));
}
Also used : DataSet(org.talend.dataprep.api.dataset.DataSet) ArrayList(java.util.ArrayList) RowMetadata(org.talend.dataprep.api.dataset.RowMetadata) DataSetRow(org.talend.dataprep.api.dataset.row.DataSetRow) DataSetMetadata(org.talend.dataprep.api.dataset.DataSetMetadata) Test(org.junit.Test)

Aggregations

DataSetMetadata (org.talend.dataprep.api.dataset.DataSetMetadata)192 Test (org.junit.Test)126 DataSetBaseTest (org.talend.dataprep.dataset.DataSetBaseTest)63 ColumnMetadata (org.talend.dataprep.api.dataset.ColumnMetadata)48 InputStream (java.io.InputStream)45 Matchers.containsString (org.hamcrest.Matchers.containsString)28 Matchers.isEmptyString (org.hamcrest.Matchers.isEmptyString)28 TDPException (org.talend.dataprep.exception.TDPException)26 RowMetadata (org.talend.dataprep.api.dataset.RowMetadata)20 DataSetServiceTest (org.talend.dataprep.dataset.service.DataSetServiceTest)20 ApiOperation (io.swagger.annotations.ApiOperation)18 DataSet (org.talend.dataprep.api.dataset.DataSet)18 Type (org.talend.dataprep.api.type.Type)17 Timed (org.talend.dataprep.metrics.Timed)17 DistributedLock (org.talend.dataprep.lock.DistributedLock)16 Autowired (org.springframework.beans.factory.annotation.Autowired)14 DataSetRow (org.talend.dataprep.api.dataset.row.DataSetRow)14 IOException (java.io.IOException)13 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)13 ArrayList (java.util.ArrayList)12