Search in sources :

Example 1 with CREATE_NEW_COLUMN

use of org.talend.dataprep.transformation.actions.common.ActionsUtils.CREATE_NEW_COLUMN in project data-prep by Talend.

the class ChangeDatePatternTest method should_set_new_pattern_as_most_used_one_newcolumn.

@Test
public void should_set_new_pattern_as_most_used_one_newcolumn() throws Exception {
    // given
    final DataSetRow row = // 
    builder().with(// 
    value("toto").type(Type.STRING).name("recipe")).with(// 
    value("04/25/1999").type(Type.DATE).name("recipe").statistics(getDateTestJsonAsStream("statistics_MM_dd_yyyy.json"))).with(// 
    value("tata").type(Type.STRING).name("last update")).build();
    parameters.put(CREATE_NEW_COLUMN, "true");
    // when
    ActionTestWorkbench.test(row, actionRegistry, factory.create(action, parameters));
    // then
    final List<PatternFrequency> patternFrequencies = // 
    row.getRowMetadata().getById(// 
    "0003").getStatistics().getPatternFrequencies();
    String newPattern = parameters.get("new_pattern");
    final Optional<PatternFrequency> newPatternSet = // 
    patternFrequencies.stream().filter(// 
    p -> StringUtils.equals(newPattern, p.getPattern())).findFirst();
    assertTrue(newPatternSet.isPresent());
    assertEquals(newPatternSet.get().getOccurrences(), 48);
}
Also used : CoreMatchers.is(org.hamcrest.CoreMatchers.is) ImplicitParameters(org.talend.dataprep.transformation.actions.common.ImplicitParameters) StringUtils(org.apache.commons.lang.StringUtils) Arrays(java.util.Arrays) CREATE_NEW_COLUMN(org.talend.dataprep.transformation.actions.common.ActionsUtils.CREATE_NEW_COLUMN) HashMap(java.util.HashMap) ValueBuilder.value(org.talend.dataprep.transformation.actions.AbstractMetadataBaseTest.ValueBuilder.value) ActionMetadataTestUtils.getRow(org.talend.dataprep.transformation.actions.ActionMetadataTestUtils.getRow) ActionMetadataTestUtils.getColumn(org.talend.dataprep.transformation.actions.ActionMetadataTestUtils.getColumn) Assert.assertThat(org.junit.Assert.assertThat) ActionTestWorkbench(org.talend.dataprep.transformation.api.action.ActionTestWorkbench) ActionCategory(org.talend.dataprep.transformation.actions.category.ActionCategory) Locale(java.util.Locale) Map(java.util.Map) DataSetRow(org.talend.dataprep.api.dataset.row.DataSetRow) PatternFrequency(org.talend.dataprep.api.dataset.statistics.PatternFrequency) Before(org.junit.Before) TalendRuntimeException(org.talend.daikon.exception.TalendRuntimeException) ActionMetadataTestUtils(org.talend.dataprep.transformation.actions.ActionMetadataTestUtils) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) IOException(java.io.IOException) ValuesBuilder.builder(org.talend.dataprep.transformation.actions.AbstractMetadataBaseTest.ValuesBuilder.builder) Type(org.talend.dataprep.api.type.Type) List(java.util.List) Builder.column(org.talend.dataprep.api.dataset.ColumnMetadata.Builder.column) Assert.assertFalse(org.junit.Assert.assertFalse) Optional(java.util.Optional) ActionMetadataTestUtils.setStatistics(org.talend.dataprep.transformation.actions.ActionMetadataTestUtils.setStatistics) ActionDefinition(org.talend.dataprep.api.action.ActionDefinition) SelectParameter(org.talend.dataprep.parameters.SelectParameter) Collections(java.util.Collections) Assert.assertEquals(org.junit.Assert.assertEquals) ColumnMetadata(org.talend.dataprep.api.dataset.ColumnMetadata) PatternFrequency(org.talend.dataprep.api.dataset.statistics.PatternFrequency) DataSetRow(org.talend.dataprep.api.dataset.row.DataSetRow) Test(org.junit.Test)

Aggregations

IOException (java.io.IOException)1 Arrays (java.util.Arrays)1 Collections (java.util.Collections)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Locale (java.util.Locale)1 Map (java.util.Map)1 Optional (java.util.Optional)1 StringUtils (org.apache.commons.lang.StringUtils)1 CoreMatchers.is (org.hamcrest.CoreMatchers.is)1 Assert.assertEquals (org.junit.Assert.assertEquals)1 Assert.assertFalse (org.junit.Assert.assertFalse)1 Assert.assertThat (org.junit.Assert.assertThat)1 Assert.assertTrue (org.junit.Assert.assertTrue)1 Before (org.junit.Before)1 Test (org.junit.Test)1 TalendRuntimeException (org.talend.daikon.exception.TalendRuntimeException)1 ActionDefinition (org.talend.dataprep.api.action.ActionDefinition)1 ColumnMetadata (org.talend.dataprep.api.dataset.ColumnMetadata)1 Builder.column (org.talend.dataprep.api.dataset.ColumnMetadata.Builder.column)1