use of org.talend.designer.core.model.components.ElementParameter in project tdi-studio-se by Talend.
the class QueryGuessCommandTest method generateNewTeradataQuery.
@Test
public void generateNewTeradataQuery() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, PersistenceException {
connection = ConnectionFactory.eINSTANCE.createConnection();
node = Mockito.mock(INode.class);
connection.setContextMode(true);
TdTable table = RelationalFactory.eINSTANCE.createTdTable();
table.setName("tableName");
table.setLabel("tableLabel");
TdColumn column1 = RelationalFactory.eINSTANCE.createTdColumn();
column1.setName("id");
TdColumn column2 = RelationalFactory.eINSTANCE.createTdColumn();
column2.setName("name");
table.getColumns().add(column1);
table.getColumns().add(column2);
metadataTable = ConvertionHelper.convert(table);
ElementParameter parameter = new ElementParameter(node);
parameter.setName("DBTABLE");
parameter.setValue(table.getName());
Mockito.when(node.getPropertyValue(EParameterName.PROPERTY_TYPE.getName())).thenReturn("REPOSITORY");
Mockito.when(node.getElementParameterFromField(EParameterFieldType.DBTABLE)).thenReturn(parameter);
// test case 1
String schema = "myschema";
String dbType = EDatabaseTypeName.TERADATA.getDisplayName();
String expectedQuery = "\"SELECT myschema.tableName.\\\"id\\\", myschema.tableName.name FROM myschema.tableName\"";
QueryGuessCommand command = new QueryGuessCommand(node, metadataTable, schema, dbType, connection);
Method method = command.getClass().getDeclaredMethod("generateNewQuery");
method.setAccessible(true);
String queryString = (String) method.invoke(command);
Assert.assertEquals(expectedQuery, queryString);
}
use of org.talend.designer.core.model.components.ElementParameter in project tdi-studio-se by Talend.
the class JavaProcessUtilTest method testFindMoreLibraries.
@Test
public void testFindMoreLibraries() {
// ensure the CAMEL is not added as jar dependency
DummyComponent comp = mock(DummyComponent.class);
when(comp.getType()).thenReturn(ComponentCategory.CATEGORY_4_CAMEL.getName());
//$NON-NLS-1$
INode node = new DataNode(comp, "");
IElementParameter param = new ElementParameter(node);
param.setName("HOTLIBS");
List<Map<String, Object>> table = new ArrayList<Map<String, Object>>();
Map<String, Object> line = new HashMap<String, Object>();
line.put("LIBPATH", "CAMEL");
table.add(line);
param.setValue(table);
List<ModuleNeeded> modulesNeeded = new ArrayList<ModuleNeeded>();
JavaProcessUtil.findMoreLibraries(null, modulesNeeded, param);
assertTrue(modulesNeeded.isEmpty());
table = new ArrayList<Map<String, Object>>();
line = new HashMap<String, Object>();
line.put("LIBPATH", "\"camel.jar\"");
table.add(line);
param.setValue(table);
modulesNeeded = new ArrayList<ModuleNeeded>();
JavaProcessUtil.findMoreLibraries(null, modulesNeeded, param);
assertEquals(1, modulesNeeded.size());
assertEquals("camel.jar", modulesNeeded.get(0).getModuleName());
}
use of org.talend.designer.core.model.components.ElementParameter in project tdi-studio-se by Talend.
the class NodeTest method addShowIfParam.
private IElementParameter addShowIfParam(Node node) {
IElementParameter param = new ElementParameter(node);
param.setName("SHOW_FLOW_CONNECTOR");
param.setCategory(EComponentCategory.TECHNICAL);
param.setFieldType(EParameterFieldType.CHECK);
param.setDisplayName("show flow connector");
param.setNumRow(99);
param.setShow(false);
param.setValue(false);
node.addElementParameter(param);
return param;
}
use of org.talend.designer.core.model.components.ElementParameter in project tdi-studio-se by Talend.
the class ComponentsUtilsTest method checkParameterInitializationStatus.
private void checkParameterInitializationStatus(List<ElementParameter> parameters, boolean isInitializing) {
for (ElementParameter parameter : parameters) {
if (parameter instanceof GenericElementParameter) {
GenericElementParameter genericElementParameter = (GenericElementParameter) parameter;
Property property = genericElementParameter.getProperty();
if (property != null) {
if (GenericTypeUtils.isStringType(property)) {
String propertyValue = (String) property.getValue();
String parameterValue = (String) parameter.getValue();
// If value is empty (from default value or input) add double quotes.
if (StringUtils.isEmpty(propertyValue)) {
//$NON-NLS-1$
assertTrue("\"\"".equals(parameterValue));
} else {
// Else value is not empty.
if (isInitializing) {
// If isInitializing is true value will be surrounded with quotes if not exist.
//$NON-NLS-1$ //$NON-NLS-2$
assertTrue(parameterValue.startsWith("\"") && parameterValue.endsWith("\""));
} else if (!propertyValue.startsWith("\"") || !propertyValue.endsWith("\"")) {
//$NON-NLS-1$ //$NON-NLS-2$
// Else shouldn't add quotes to the value.
//$NON-NLS-1$ //$NON-NLS-2$
assertFalse(parameterValue.startsWith("\"") && parameterValue.endsWith("\""));
}
}
}
}
}
}
}
use of org.talend.designer.core.model.components.ElementParameter 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));
}
Aggregations