Search in sources :

Example 11 with Parameter

use of org.talend.dataprep.parameters.Parameter in project data-prep by Talend.

the class ParameterTest method shouldSerializeToJsonWithoutEmptyConfiguration.

@Test
public void shouldSerializeToJsonWithoutEmptyConfiguration() throws IOException {
    // given
    Parameter expected = Parameter.parameter(Locale.US).setName("column_id").setType(ParameterType.STRING).setDefaultValue("0001").setImplicit(true).setCanBeBlank(false).setReadonly(true).build(this);
    // when
    StringWriter out = new StringWriter();
    mapper.writer().writeValue(out, expected);
    // then
    assertThat(out.toString(), sameJSONAs(IOUtils.toString(this.getClass().getResourceAsStream("textParameter.json"), UTF_8)));
}
Also used : StringWriter(java.io.StringWriter) Parameter(org.talend.dataprep.parameters.Parameter) Test(org.junit.Test)

Example 12 with Parameter

use of org.talend.dataprep.parameters.Parameter in project data-prep by Talend.

the class CSVFormatTest method csv.

@Test
public void csv() {
    // when
    final ExportFormatMessage exportFormatMessage = beanConversionService.convert(format, ExportFormatMessage.class);
    // then
    assertEquals("text/csv", exportFormatMessage.getMimeType());
    assertEquals("CSV", exportFormatMessage.getId());
    assertEquals("Local CSV file", exportFormatMessage.getName());
    assertEquals(true, exportFormatMessage.isNeedParameters());
    assertEquals(false, exportFormatMessage.isDefaultExport());
    assertEquals(true, exportFormatMessage.isEnabled());
    assertEquals("", exportFormatMessage.getDisableReason());
    assertEquals("Export to CSV", exportFormatMessage.getTitle());
    List<Parameter> parameters = exportFormatMessage.getParameters();
    assertNotNull(parameters);
    assertEquals(6, parameters.size());
}
Also used : ExportFormatMessage(org.talend.dataprep.format.export.ExportFormatMessage) Parameter(org.talend.dataprep.parameters.Parameter) Test(org.junit.Test)

Example 13 with Parameter

use of org.talend.dataprep.parameters.Parameter in project data-prep by Talend.

the class RenameTest method testAdapt.

@Test
public void testAdapt() throws Exception {
    assertThat(action.adapt((ColumnMetadata) null), is(action));
    ColumnMetadata column = column().name("myColumn").id(0).type(Type.STRING).build();
    assertThat(action.adapt(column), not(is(action)));
    boolean hasMetExpectedParameter = false;
    for (Parameter parameter : action.adapt(column).getParameters(Locale.US)) {
        if (Rename.NEW_COLUMN_NAME_PARAMETER_NAME.equals(parameter.getName())) {
            assertThat(parameter.getDefault(), is(column.getName()));
            hasMetExpectedParameter = true;
        }
    }
    assertThat(hasMetExpectedParameter, is(true));
}
Also used : ColumnMetadata(org.talend.dataprep.api.dataset.ColumnMetadata) Parameter(org.talend.dataprep.parameters.Parameter) Test(org.junit.Test) AbstractMetadataBaseTest(org.talend.dataprep.transformation.actions.AbstractMetadataBaseTest)

Example 14 with Parameter

use of org.talend.dataprep.parameters.Parameter in project data-prep by Talend.

the class AbstractMetadataBaseTest method forbidCreateColumn_alwaysDisabled.

private void forbidCreateColumn_alwaysDisabled() {
    // test that 'create_new_column' parameter is not present:
    final List<Parameter> parameters = action.getParameters(Locale.getDefault());
    for (Parameter parameter : parameters) {
        if (parameter.getName().equals(CREATE_NEW_COLUMN)) {
            fail("'Create new column' found, while it should not");
        }
    }
    // test that this action will not create a new column:
    assertFalse(ActionsUtils.doesCreateNewColumn(Collections.<String, String>emptyMap(), false));
}
Also used : Parameter(org.talend.dataprep.parameters.Parameter)

Example 15 with Parameter

use of org.talend.dataprep.parameters.Parameter in project data-prep by Talend.

the class AbstractMetadataBaseTest method allowCreateColumn_enabledByDefault.

private void allowCreateColumn_enabledByDefault() {
    // test that 'create_new_column' parameter is present and set to 'true' by default:
    final List<Parameter> parameters = action.getParameters(Locale.getDefault());
    boolean found = false;
    for (Parameter parameter : parameters) {
        if (parameter.getName().equals(CREATE_NEW_COLUMN)) {
            found = true;
            assertEquals("Create new column", parameter.getLabel());
            assertTrue(Boolean.parseBoolean(parameter.getDefault()));
        }
    }
    if (!found) {
        fail("'Create new column' not found");
    }
}
Also used : Parameter(org.talend.dataprep.parameters.Parameter)

Aggregations

Parameter (org.talend.dataprep.parameters.Parameter)25 Test (org.junit.Test)10 SelectParameter (org.talend.dataprep.parameters.SelectParameter)7 SelectParameter.selectParameter (org.talend.dataprep.parameters.SelectParameter.selectParameter)7 AbstractMetadataBaseTest (org.talend.dataprep.transformation.actions.AbstractMetadataBaseTest)5 ActionDefinition (org.talend.dataprep.api.action.ActionDefinition)2 ColumnMetadata (org.talend.dataprep.api.dataset.ColumnMetadata)2 ExportFormatMessage (org.talend.dataprep.format.export.ExportFormatMessage)2 SelectParameterBuilder (org.talend.dataprep.parameters.SelectParameter.SelectParameterBuilder)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 StringWriter (java.io.StringWriter)1 java.util (java.util)1 List (java.util.List)1 Predicate (java.util.function.Predicate)1 Collectors (java.util.stream.Collectors)1 Collectors.toSet (java.util.stream.Collectors.toSet)1 DataSetMetadata (org.talend.dataprep.api.dataset.DataSetMetadata)1 RowMetadata (org.talend.dataprep.api.dataset.RowMetadata)1 Action (org.talend.dataprep.api.preparation.Action)1 ParameterType (org.talend.dataprep.parameters.ParameterType)1