use of org.talend.core.model.process.IElementParameter in project tdi-studio-se by Talend.
the class ElementParameterTest method main.
/**
* DOC nrousseau Comment method "main".
*
* @param args
*/
public static void main(String[] args) {
List<IElementParameter> listParams = new ArrayList<IElementParameter>();
ElementParameter param = new ElementParameter(null);
//$NON-NLS-1$
param.setName("VAR1");
//$NON-NLS-1$
param.setValue("value1");
//$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$
param.setListItemsDisplayCodeName(new String[] { "VALUE1", "VALUE2", "VALUE3", "VALUE4", "VALUE5", "VALUE5_6" });
//$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$
param.setListItemsValue(new String[] { "value1", "value2", "value3", "value4", "value5", "value5;value6" });
listParams.add(param);
param = new ElementParameter(null);
//$NON-NLS-1$
param.setName("VAR2");
//$NON-NLS-1$
param.setValue("value2");
//$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$
param.setListItemsDisplayCodeName(new String[] { "VALUE1", "VALUE2", "VALUE3", "VALUE4", "VALUE5", "VALUE5_6" });
//$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$
param.setListItemsValue(new String[] { "value1", "value2", "value3", "value4", "value5", "value5;value6" });
listParams.add(param);
param = new ElementParameter(null);
//$NON-NLS-1$
param.setName("VAR3");
//$NON-NLS-1$
param.setValue("value3");
//$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$
param.setListItemsDisplayCodeName(new String[] { "VALUE1", "VALUE2", "VALUE3", "VALUE4", "VALUE5", "VALUE5_6" });
//$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$
param.setListItemsValue(new String[] { "value1", "value2", "value3", "value4", "value5", "value5;value6" });
listParams.add(param);
param = new ElementParameter(null);
//$NON-NLS-1$
param.setName("VAR4");
//$NON-NLS-1$
param.setValue("value4");
//$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$
param.setListItemsDisplayCodeName(new String[] { "VALUE1", "VALUE2", "VALUE3", "VALUE4", "VALUE5", "VALUE5_6" });
//$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$
param.setListItemsValue(new String[] { "value1", "value2", "value3", "value4", "value5", "value5;value6" });
listParams.add(param);
param = new ElementParameter(null);
//$NON-NLS-1$
param.setName("VAR5");
//$NON-NLS-1$
param.setValue("value5;value6");
//$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$
param.setListItemsDisplayCodeName(new String[] { "VALUE1", "VALUE2", "VALUE3", "VALUE4", "VALUE5", "VALUE5_6" });
//$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$
param.setListItemsValue(new String[] { "value1", "value2", "value3", "value4", "value5", "value5;value6" });
listParams.add(param);
param = new ElementParameter(null);
//$NON-NLS-1$
param.setName("VAR6");
param.setValue(new Boolean(true));
listParams.add(param);
param = new ElementParameter(null);
//$NON-NLS-1$
param.setName("VAR7");
//$NON-NLS-1$
param.setValue("value1");
//$NON-NLS-1$ //$NON-NLS-2$
param.setListItemsDisplayCodeName(new String[] { "POSTGRESQL", "ORACLE" });
//$NON-NLS-1$ //$NON-NLS-2$
param.setListItemsValue(new String[] { "value1", "value2" });
listParams.add(param);
ElementParameter paramToTest = new ElementParameter(null);
//$NON-NLS-1$
paramToTest.setName("VAR_TEST");
Assert.assertTrue(testParam(//$NON-NLS-1$
"((VAR1 == 'VALUE1' and VAR2 == 'VALUE2') or (VAR3 != 'VALUE3')) or (VAR4 == 'VALUE4')", //$NON-NLS-1$
paramToTest, listParams));
Assert.assertTrue(testParam(//$NON-NLS-1$
"((VAR1 == 'VALUE1' AND VAR2 == 'VALUE2') OR (VAR3 != 'VALUE3')) OR (VAR4 == 'VALUE4')", //$NON-NLS-1$
paramToTest, listParams));
Assert.assertTrue(testParam(//$NON-NLS-1$
"(VAR4 == 'VALUE4') or ((VAR1 == 'VALUE1' and VAR2 == 'VALUE2') or VAR3 != 'VALUE3')", //$NON-NLS-1$
paramToTest, listParams));
Assert.assertTrue(testParam(//$NON-NLS-1$
"((VAR1 == 'VALUE1' and VAR2 == 'VALUE2') and (VAR3 != 'VALUE3' or VAR4 == 'VALUE4'))", //$NON-NLS-1$
paramToTest, listParams));
Assert.assertFalse(testParam(//$NON-NLS-1$
"VAR4 != 'VALUE4' and (VAR2 == 'VALUE2' or VAR1 == 'VALUE1')", //$NON-NLS-1$
paramToTest, listParams));
//$NON-NLS-1$
Assert.assertTrue(testParam("(VAR5 == 'VALUE5_6') and (VAR6 == 'true')", paramToTest, listParams));
//$NON-NLS-1$
Assert.assertTrue(testParam("VAR6 == 'true'", paramToTest, listParams));
//$NON-NLS-1$
Assert.assertTrue(testParam("(VAR7 == 'POSTGRESQL') or (VAR7 == 'ORACLE')", paramToTest, listParams));
}
use of org.talend.core.model.process.IElementParameter in project tdi-studio-se by Talend.
the class GenericTableUtilsTest method testGetTableValues.
@Test
public void testGetTableValues() {
MyTestTable tableProperties = new MyTestTable("tableProp");
List<String> columnValues = new ArrayList<String>();
columnValues.add("Text1");
columnValues.add("Text2");
tableProperties.column1.setValue(columnValues);
columnValues = new ArrayList<String>();
columnValues.add("true");
columnValues.add("false");
tableProperties.column2.setValue(columnValues);
columnValues = new ArrayList<String>();
columnValues.add("Value1");
columnValues.add("Value3");
tableProperties.column3.setValue(columnValues);
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 = GenericTableUtils.getTableValues(tableProperties, tableParam);
assertEquals(2, table.size());
Map<String, Object> line1 = table.get(0);
Map<String, Object> line2 = table.get(1);
assertEquals("Text1", line1.get("column1"));
assertEquals(Boolean.TRUE, line1.get("column2"));
assertEquals("Value1", line1.get("column3"));
assertEquals("Text2", line2.get("column1"));
assertEquals(Boolean.FALSE, line2.get("column2"));
assertEquals("Value3", line2.get("column3"));
}
use of org.talend.core.model.process.IElementParameter in project tdi-studio-se by Talend.
the class ComponentTest method testGetElementParameterValueFromComponentProperties.
@Test
public void testGetElementParameterValueFromComponentProperties() {
//$NON-NLS-1$ //$NON-NLS-2$
IComponent sfComponent = ComponentsFactoryProvider.getInstance().get("tSalesforceInput", "DI");
INode node = new Node(sfComponent, new Process(new FakePropertyImpl()));
ComponentProperties props = node.getComponentProperties();
Form form = props.getForm(Form.MAIN);
IElementParameter param = new GenericElementParameter(node, node.getComponentProperties(), form, form.getWidget("condition"), //$NON-NLS-1$
null);
Object obj = component.getElementParameterValueFromComponentProperties(node, param);
Assert.assertNotNull(obj);
}
use of org.talend.core.model.process.IElementParameter in project tdi-studio-se by Talend.
the class ExpressionTest method testEvaluateDistrib_link.
@Test
public void testEvaluateDistrib_link() {
List<IElementParameter> params = new ArrayList<>();
ElementParameter param1 = createMockParameter("PARA1", true, null);
params.add(param1);
ElementParameter paramNode = mock(ElementParameter.class);
INode testElement = mock(INode.class);
when(paramNode.getName()).thenReturn("PARANODE");
TextElementParameter testParam = mock(TextElementParameter.class);
when(paramNode.getElement()).thenReturn(testElement);
when(paramNode.getElement().getElementName()).thenReturn("testComponent");
when(testElement.getElementParametersWithChildrens()).thenReturn((List) Arrays.asList(testParam));
when(testParam.getVariableName()).thenReturn("__CONNECTION__");
when(testParam.getValue()).thenReturn("relatedNode");
INode relatedNode = mock(INode.class);
when(relatedNode.getUniqueName()).thenReturn("relatedNode");
when(relatedNode.getElementParameters()).thenReturn((List) params);
IProcess process = mock(IProcess.class);
when(process.getGeneratingNodes()).thenReturn((List) Arrays.asList(relatedNode));
when(testElement.getProcess()).thenReturn(process);
params.add(paramNode);
ElementParameter distrib = createMockParameter("DISTRIBUTION", "CUSTOM");
params.add(distrib);
ElementParameter version = createMockParameter("HIVE_VERSION", "testVersion");
params.add(version);
ElementParameter invaliddistrib = createMockParameter("INVALDDISTRIB", "INVALID");
params.add(invaliddistrib);
assertTrue(Expression.evaluateDistrib("DISTRIB[#LINK@NODE.CONNECTION.DISTRIBUTION, #LINK@NODE.CONNECTION.HIVE_VERSION].doSupportUseDatanodeHostname[]", params, paramNode));
assertFalse(Expression.evaluateDistrib("!DISTRIB[#LINK@NODE.CONNECTION.DISTRIBUTION, #LINK@NODE.CONNECTION.HIVE_VERSION].doSupportUseDatanodeHostname[]", params, paramNode));
}
use of org.talend.core.model.process.IElementParameter in project tdi-studio-se by Talend.
the class ExpressionTest method testIsShowFunctionClosedListItem.
@Test
public void testIsShowFunctionClosedListItem() {
List<IElementParameter> parameters = spy(new ArrayList<IElementParameter>());
ElementParameter param1 = createMockParameter("PARA1.VALUE1", true, null);
ElementParameter param2 = createMockParameter("PARA1.VALUE2", false, null);
ElementParameter param3 = createMockParameter("PARA2", false, "isShow[PARA1.VALUE1]");
ElementParameter param4 = createMockParameter("PARA3", false, "isShow[PARA1.VALUE2]");
updateParameters(parameters, param1, param2, param3, param4);
assertTrue(Expression.evaluate("isShow[PARA1.VALUE1]", parameters, param3));
assertFalse(Expression.evaluate("isShow[PARA1.VALUE2]", parameters, param4));
}
Aggregations