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);
}
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);
}
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));
}
Aggregations