Search in sources :

Example 6 with SelectParameter

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

the class SelectParameterTest method shouldCreateConstantItem.

@Test
public void shouldCreateConstantItem() {
    // when
    final SelectParameter params = SelectParameter.selectParameter(Locale.US).constant("key", "a constant key").build(this);
    // then
    assertThat(params.getItems().get(0).getValue(), is("key"));
    assertThat(params.getItems().get(0).getLabel(), is("a constant key"));
}
Also used : SelectParameter(org.talend.dataprep.parameters.SelectParameter) Test(org.junit.Test)

Example 7 with SelectParameter

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

the class TestI18nKeysForActionsTest method assertParameter.

private void assertParameter(Parameter param) {
    String parameterName = param.getName();
    assertNotNull(parameterName);
    assertNotEquals("", parameterName);
    String parameterLabel = param.getLabel();
    assertNotNull(parameterLabel);
    assertNotEquals("", parameterLabel);
    String parameterDescription = param.getDescription();
    assertNotNull(parameterDescription);
    assertNotEquals("", parameterDescription);
    LOGGER.trace("  - " + parameterName + " | " + parameterLabel + " | " + parameterDescription);
    if (param instanceof SelectParameter) {
        List<Item> values = ((SelectParameter) param).getItems();
        for (Item value : values) {
            assertItem(value);
        }
    }
}
Also used : Item(org.talend.dataprep.parameters.Item) SelectParameter(org.talend.dataprep.parameters.SelectParameter)

Example 8 with SelectParameter

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

the class SelectParameterTest method shouldSerializeToJsonWithItemsInConfiguration.

@Test
public void shouldSerializeToJsonWithItemsInConfiguration() throws IOException {
    // given
    SelectParameter expected = SelectParameter.selectParameter(// 
    Locale.US).name(// 
    "column_id").defaultValue(// 
    "").implicit(// 
    false).canBeBlank(// 
    false).item(// 
    "first value").item(// 
    "2").item("your choice", Parameter.parameter(Locale.US).setName("limit").setType(ParameterType.INTEGER).setDefaultValue(StringUtils.EMPTY).setCanBeBlank(false).build(// 
    this)).build(this);
    // when
    StringWriter out = new StringWriter();
    mapper.writer().writeValue(out, expected);
    // then
    assertThat(out.toString(), sameJSONAs(IOUtils.toString(this.getClass().getResourceAsStream("selectParameter.json"), UTF_8)));
}
Also used : StringWriter(java.io.StringWriter) SelectParameter(org.talend.dataprep.parameters.SelectParameter) Test(org.junit.Test)

Example 9 with SelectParameter

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

the class RemoveRepeatedCharsTest method testGetParameters.

@Test
public void testGetParameters() throws Exception {
    final List<Parameter> parameters = action.getParameters(Locale.US);
    assertEquals(6, parameters.size());
    final SelectParameter parameter4 = (SelectParameter) parameters.get(5);
    assertEquals(2, parameter4.getItems().size());
    assertEquals("Whitespace", parameter4.getItems().get(0).getLabel());
    assertEquals("Other", parameter4.getItems().get(1).getLabel());
}
Also used : SelectParameter(org.talend.dataprep.parameters.SelectParameter) Parameter(org.talend.dataprep.parameters.Parameter) SelectParameter(org.talend.dataprep.parameters.SelectParameter) Test(org.junit.Test) AbstractMetadataBaseTest(org.talend.dataprep.transformation.actions.AbstractMetadataBaseTest)

Aggregations

SelectParameter (org.talend.dataprep.parameters.SelectParameter)9 Test (org.junit.Test)7 Parameter (org.talend.dataprep.parameters.Parameter)5 AbstractMetadataBaseTest (org.talend.dataprep.transformation.actions.AbstractMetadataBaseTest)3 StringWriter (java.io.StringWriter)1 Item (org.talend.dataprep.parameters.Item)1