Search in sources :

Example 1 with DateCalendarConverter

use of org.talend.dataprep.transformation.actions.date.DateCalendarConverter in project data-prep by Talend.

the class DateCalendarConverterTest method testCompileShouldComputeToAndFromInternalContextParameters.

@Test
public void testCompileShouldComputeToAndFromInternalContextParameters() {
    // Given
    final DateCalendarConverter calendarConverter = new DateCalendarConverter();
    final DataSetRow row = builder().with(value("toto").type(Type.STRING).name("recipe")).with(value("10/29/1996").type(Type.DATE).name("last update").statistics(getDateTestJsonAsStream("statistics_MM_dd_yyyy.json"))).with(// 
    value("tata").type(Type.STRING).name("who")).build();
    final ActionContext context = new ActionContext(new TransformationContext(), row.getRowMetadata());
    context.setActionStatus(ActionContext.ActionStatus.OK);
    final Map<String, String> parameters = new HashMap<>();
    parameters.put(ImplicitParameters.SCOPE.getKey().toLowerCase(), "column");
    parameters.put(COLUMN_ID.getKey(), "0001");
    parameters.put(FROM_CALENDAR_TYPE_PARAMETER, DateCalendarConverter.CalendarUnit.ISO.name());
    parameters.put(TO_CALENDAR_TYPE_PARAMETER, CalendarUnit.JULIAN_DAY.name());
    context.setParameters(parameters);
    // When
    calendarConverter.compile(context);
    // Then
    assertTrue(context.get(IS_FROM_CHRONOLOGY_INTERNAL_KEY));
    assertFalse(context.get(IS_TO_CHRONOLOGY_INTERNAL_KEY));
}
Also used : DateCalendarConverter(org.talend.dataprep.transformation.actions.date.DateCalendarConverter) ActionContext(org.talend.dataprep.transformation.api.action.context.ActionContext) TransformationContext(org.talend.dataprep.transformation.api.action.context.TransformationContext) DataSetRow(org.talend.dataprep.api.dataset.row.DataSetRow) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)1 DataSetRow (org.talend.dataprep.api.dataset.row.DataSetRow)1 DateCalendarConverter (org.talend.dataprep.transformation.actions.date.DateCalendarConverter)1 ActionContext (org.talend.dataprep.transformation.api.action.context.ActionContext)1 TransformationContext (org.talend.dataprep.transformation.api.action.context.TransformationContext)1