Search in sources :

Example 36 with DataSetMetadata

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

the class StatisticsAnalysisTest method should_update_dataset_nb_records.

@Test
public void should_update_dataset_nb_records() throws Exception {
    // given
    final InputStream dataset = this.getClass().getResourceAsStream("dataset.csv");
    // when
    final DataSetMetadata metadata = initializeDataSetMetadata(dataset);
    // then
    assertThat(metadata.getContent().getNbRecords(), is(4L));
}
Also used : InputStream(java.io.InputStream) DataSetMetadata(org.talend.dataprep.api.dataset.DataSetMetadata) Test(org.junit.Test) DataSetBaseTest(org.talend.dataprep.dataset.DataSetBaseTest)

Example 37 with DataSetMetadata

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

the class ContentAnalysisTest method testAnalysisWithLimit.

@Test
public void testAnalysisWithLimit() {
    final DataSetMetadata metadata = createMetadata(UUID.randomUUID().toString(), Arrays.asList("id", "first_name", "last_name", "email", "gender", "ip_address"));
    metadataBuilder.metadata().id("3548").build();
    createCsvDataSet(metadata, "100_lines.csv");
    final Long newLimit = 16L;
    final Long originalLimit = (Long) ReflectionTestUtils.getField(contentAnalysis, ContentAnalysis.class, "sizeLimit");
    ReflectionTestUtils.setField(contentAnalysis, "sizeLimit", newLimit);
    contentAnalysis.analyze(metadata.getId());
    ReflectionTestUtils.setField(contentAnalysis, "sizeLimit", originalLimit);
    final DataSetMetadata actual = dataSetMetadataRepository.get(metadata.getId());
    final Optional<Long> limit = actual.getContent().getLimit();
    assertTrue(limit.isPresent());
    assertThat(limit.get(), is(newLimit));
}
Also used : DataSetMetadata(org.talend.dataprep.api.dataset.DataSetMetadata) Test(org.junit.Test) DataSetBaseTest(org.talend.dataprep.dataset.DataSetBaseTest)

Example 38 with DataSetMetadata

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

the class ContentAnalysisTest method testAnalysisWithoutLimit.

@Test
public void testAnalysisWithoutLimit() {
    final DataSetMetadata metadata = metadataBuilder.metadata().id(UUID.randomUUID().toString()).build();
    createCsvDataSet(metadata, "5_lines.csv");
    contentAnalysis.analyze(metadata.getId());
    final DataSetMetadata actual = dataSetMetadataRepository.get(metadata.getId());
    assertFalse(actual.getContent().getLimit().isPresent());
}
Also used : DataSetMetadata(org.talend.dataprep.api.dataset.DataSetMetadata) Test(org.junit.Test) DataSetBaseTest(org.talend.dataprep.dataset.DataSetBaseTest)

Example 39 with DataSetMetadata

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

the class FormatAnalysisTest method testCSVAnalysis.

@Test
public void testCSVAnalysis() {
    String id = UUID.randomUUID().toString();
    final DataSetMetadata metadata = metadataBuilder.metadata().id(id).build();
    dataSetMetadataRepository.save(metadata);
    contentStore.storeAsRaw(metadata, DataSetServiceTest.class.getResourceAsStream("../avengers.csv"));
    formatAnalysis.analyze(id);
    final DataSetMetadata actual = dataSetMetadataRepository.get(id);
    assertThat(actual, notNullValue());
    assertThat(actual.getContent().getFormatFamilyId(), is(CSVFormatFamily.BEAN_ID));
    assertThat(actual.getContent().getMediaType(), is("text/csv"));
    assertThat(actual.getContent().getParameters().get("SEPARATOR"), is(";"));
}
Also used : DataSetServiceTest(org.talend.dataprep.dataset.service.DataSetServiceTest) DataSetMetadata(org.talend.dataprep.api.dataset.DataSetMetadata) Test(org.junit.Test) DataSetBaseTest(org.talend.dataprep.dataset.DataSetBaseTest) DataSetServiceTest(org.talend.dataprep.dataset.service.DataSetServiceTest)

Example 40 with DataSetMetadata

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

the class FormatAnalysisTest method testEncodingDetection_UTF16LE_WithoutBOM.

/**
 * see https://jira.talendforge.org/browse/TDP-2930.
 */
@Test
public void testEncodingDetection_UTF16LE_WithoutBOM() {
    String id = UUID.randomUUID().toString();
    final DataSetMetadata metadata = metadataBuilder.metadata().id(id).build();
    dataSetMetadataRepository.save(metadata);
    contentStore.storeAsRaw(metadata, DataSetServiceTest.class.getResourceAsStream("../utf16_LE_without_bom.txt"));
    formatAnalysis.analyze(id);
    final DataSetMetadata actual = dataSetMetadataRepository.get(id);
    assertThat(actual, notNullValue());
    assertThat(actual.getContent().getFormatFamilyId(), is(CSVFormatFamily.BEAN_ID));
    assertThat(actual.getContent().getMediaType(), is("text/csv"));
    assertThat(actual.getContent().getParameters().get("SEPARATOR"), is(","));
    assertThat(actual.getEncoding(), is("UTF-16LE"));
}
Also used : DataSetServiceTest(org.talend.dataprep.dataset.service.DataSetServiceTest) DataSetMetadata(org.talend.dataprep.api.dataset.DataSetMetadata) Test(org.junit.Test) DataSetBaseTest(org.talend.dataprep.dataset.DataSetBaseTest) DataSetServiceTest(org.talend.dataprep.dataset.service.DataSetServiceTest)

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