Search in sources :

Example 11 with FakeElement

use of org.talend.designer.core.model.FakeElement in project tdi-studio-se by Talend.

the class ComponentsUtilsTest method testGetParameterValue.

@Test
public void testGetParameterValue() {
    //$NON-NLS-1$
    TestProperties props = (TestProperties) new TestProperties("test").init();
    //$NON-NLS-1$
    props.userId.setValue("user");
    Form form = props.getForm(Form.MAIN);
    Element fakeElement = new FakeElement(form.getName());
    INode node = createSFTestNode();
    // If it is a fake element, do not add quotes.
    Object parameterValue = ComponentsUtils.getParameterValue(fakeElement, props.userId, null);
    //$NON-NLS-1$
    assertEquals("user", parameterValue);
    // If the property value is context mode, do not add quotes.
    //$NON-NLS-1$
    props.userId.setValue("context.user");
    parameterValue = ComponentsUtils.getParameterValue(node, props.userId, null);
    //$NON-NLS-1$
    assertEquals("context.user", parameterValue);
    // If the property value is changed by user, do not add quotes.
    props.userId.setTaggedValue(UpdatesConstants.CHANGED_BY_USER, true);
    //$NON-NLS-1$
    props.userId.setValue("user");
    parameterValue = ComponentsUtils.getParameterValue(node, props.userId, null);
    //$NON-NLS-1$
    assertEquals("user", parameterValue);
    // Otherwise will add quotes.
    props.userId.setTaggedValue(UpdatesConstants.CHANGED_BY_USER, false);
    parameterValue = ComponentsUtils.getParameterValue(node, props.userId, null);
    //$NON-NLS-1$
    assertEquals("\"user\"", parameterValue);
    // If value is NULL, return "".
    props.userId.setValue(null);
    parameterValue = ComponentsUtils.getParameterValue(node, props.userId, null);
    //$NON-NLS-1$
    assertEquals("\"\"", parameterValue);
}
Also used : INode(org.talend.core.model.process.INode) Form(org.talend.daikon.properties.presentation.Form) Element(org.talend.core.model.process.Element) FakeElement(org.talend.designer.core.model.FakeElement) FakeElement(org.talend.designer.core.model.FakeElement) Test(org.junit.Test)

Example 12 with FakeElement

use of org.talend.designer.core.model.FakeElement in project tdi-studio-se by Talend.

the class ComponentsUtilsTest method testGetParametersFromForm.

@Test
public void testGetParametersFromForm() {
    //$NON-NLS-1$
    ComponentProperties props = (ComponentProperties) new TestProperties("test").init();
    Form form = props.getForm(Form.MAIN);
    /*
         * Test wizard
         */
    Element element = new FakeElement(form.getName());
    // Test readonly case
    List<ElementParameter> parameters = ComponentsUtils.getParametersFromForm(element, false, null, props, form);
    for (ElementParameter parameter : parameters) {
        assertFalse(parameter.isReadOnly());
    }
    element.setReadOnly(true);
    parameters = ComponentsUtils.getParametersFromForm(element, false, null, props, form);
    for (ElementParameter parameter : parameters) {
        assertTrue(parameter.isReadOnly());
    }
    /*
         * Test component
         */
    // Test parameter initialization case (mainly to test ComponentsUtils.getParameterValue() method).
    checkParameterInitializationStatus(true);
    checkParameterInitializationStatus(false);
}
Also used : GenericElementParameter(org.talend.designer.core.generic.model.GenericElementParameter) ElementParameter(org.talend.designer.core.model.components.ElementParameter) ComponentProperties(org.talend.components.api.properties.ComponentProperties) Form(org.talend.daikon.properties.presentation.Form) Element(org.talend.core.model.process.Element) FakeElement(org.talend.designer.core.model.FakeElement) FakeElement(org.talend.designer.core.model.FakeElement) Test(org.junit.Test)

Example 13 with FakeElement

use of org.talend.designer.core.model.FakeElement in project tdi-studio-se by Talend.

the class GenericTableUtilsTest method testSetTableValues.

@Test
public void testSetTableValues() {
    IElement elem = new FakeElement("test");
    IElementParameter tableParam = new ElementParameter(elem);
    tableParam.setName("myTable");
    IElementParameter column1 = new ElementParameter(elem);
    column1.setName("column1");
    column1.setFieldType(EParameterFieldType.TEXT);
    IElementParameter column2 = new ElementParameter(elem);
    column2.setName("column2");
    column2.setFieldType(EParameterFieldType.CHECK);
    IElementParameter column3 = new ElementParameter(elem);
    column3.setName("column3");
    column3.setFieldType(EParameterFieldType.CLOSED_LIST);
    List<String> values = new ArrayList<>();
    values.add("Value1");
    values.add("Value2");
    values.add("Value3");
    column3.setListItemsValue(values.toArray());
    List<String> codeNames = new ArrayList<>();
    codeNames.add("column1");
    codeNames.add("column2");
    codeNames.add("column3");
    tableParam.setListItemsDisplayCodeName(codeNames.toArray(new String[0]));
    List<IElementParameter> childParams = new ArrayList<>();
    childParams.add(column1);
    childParams.add(column2);
    childParams.add(column3);
    tableParam.setListItemsValue(childParams.toArray());
    List<Map<String, Object>> table = new ArrayList<Map<String, Object>>();
    Map<String, Object> line = new HashMap<String, Object>();
    line.put("column1", "Text1");
    line.put("column2", Boolean.TRUE);
    line.put("column3", "Value1");
    table.add(line);
    line = new HashMap<String, Object>();
    line.put("column1", "Text2");
    line.put("column2", Boolean.FALSE);
    line.put("column3", 2);
    table.add(line);
    MyTestTable tableProperties = new MyTestTable("tableProp");
    GenericTableUtils.setTableValues(tableProperties, table, tableParam);
    // call 2 times, to ensure the number of line is not added at each calls
    GenericTableUtils.setTableValues(tableProperties, table, tableParam);
    assertEquals(2, ((List) tableProperties.column1.getValue()).size());
    assertEquals(2, ((List) tableProperties.column2.getValue()).size());
    assertEquals(2, ((List) tableProperties.column3.getValue()).size());
    assertEquals("Text1", ((List) tableProperties.column1.getValue()).get(0));
    assertEquals("Text2", ((List) tableProperties.column1.getValue()).get(1));
    assertEquals("true", ((List) tableProperties.column2.getValue()).get(0));
    assertEquals("false", ((List) tableProperties.column2.getValue()).get(1));
    assertEquals("Value1", ((List) tableProperties.column3.getValue()).get(0));
    assertEquals("Value3", ((List) tableProperties.column3.getValue()).get(1));
}
Also used : IElement(org.talend.core.model.process.IElement) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) FakeElement(org.talend.designer.core.model.FakeElement) IElementParameter(org.talend.core.model.process.IElementParameter) ElementParameter(org.talend.designer.core.model.components.ElementParameter) IElementParameter(org.talend.core.model.process.IElementParameter) HashMap(java.util.HashMap) Map(java.util.Map) Test(org.junit.Test)

Aggregations

FakeElement (org.talend.designer.core.model.FakeElement)13 ArrayList (java.util.ArrayList)5 Test (org.junit.Test)5 ElementParameter (org.talend.designer.core.model.components.ElementParameter)5 FormAttachment (org.eclipse.swt.layout.FormAttachment)4 FormData (org.eclipse.swt.layout.FormData)4 ComponentProperties (org.talend.components.api.properties.ComponentProperties)4 Element (org.talend.core.model.process.Element)4 Form (org.talend.daikon.properties.presentation.Form)4 GenericElementParameter (org.talend.designer.core.generic.model.GenericElementParameter)4 DecoratedField (org.eclipse.jface.fieldassist.DecoratedField)3 FieldDecoration (org.eclipse.jface.fieldassist.FieldDecoration)3 Point (org.eclipse.swt.graphics.Point)3 Composite (org.eclipse.swt.widgets.Composite)3 Control (org.eclipse.swt.widgets.Control)3 IElement (org.talend.core.model.process.IElement)3 IElementParameter (org.talend.core.model.process.IElementParameter)3 INode (org.talend.core.model.process.INode)3 NamedThing (org.talend.daikon.NamedThing)3 Node (org.talend.designer.core.ui.editor.nodes.Node)3