Search in sources :

Example 31 with ElementParameter

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);
}
Also used : INode(org.talend.core.model.process.INode) ElementParameter(org.talend.designer.core.model.components.ElementParameter) TdTable(org.talend.cwm.relational.TdTable) TdColumn(org.talend.cwm.relational.TdColumn) Method(java.lang.reflect.Method) Test(org.junit.Test)

Example 32 with ElementParameter

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());
}
Also used : INode(org.talend.core.model.process.INode) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) IElementParameter(org.talend.core.model.process.IElementParameter) ElementParameter(org.talend.designer.core.model.components.ElementParameter) DummyComponent(org.talend.designer.core.model.components.DummyComponent) DataNode(org.talend.designer.core.model.process.DataNode) IElementParameter(org.talend.core.model.process.IElementParameter) HashMap(java.util.HashMap) Map(java.util.Map) ModuleNeeded(org.talend.core.model.general.ModuleNeeded) Test(org.junit.Test)

Example 33 with ElementParameter

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;
}
Also used : IElementParameter(org.talend.core.model.process.IElementParameter) ElementParameter(org.talend.designer.core.model.components.ElementParameter) IElementParameter(org.talend.core.model.process.IElementParameter)

Example 34 with ElementParameter

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("\""));
                        }
                    }
                }
            }
        }
    }
}
Also used : GenericElementParameter(org.talend.designer.core.generic.model.GenericElementParameter) ElementParameter(org.talend.designer.core.model.components.ElementParameter) GenericElementParameter(org.talend.designer.core.generic.model.GenericElementParameter) StringProperty(org.talend.daikon.properties.property.StringProperty) Property(org.talend.daikon.properties.property.Property)

Example 35 with ElementParameter

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));
}
Also used : ElementParameter(org.talend.designer.core.model.components.ElementParameter) IElementParameter(org.talend.core.model.process.IElementParameter) ArrayList(java.util.ArrayList) IElementParameter(org.talend.core.model.process.IElementParameter)

Aggregations

ElementParameter (org.talend.designer.core.model.components.ElementParameter)72 IElementParameter (org.talend.core.model.process.IElementParameter)62 ArrayList (java.util.ArrayList)44 List (java.util.List)26 INode (org.talend.core.model.process.INode)20 Map (java.util.Map)19 HashMap (java.util.HashMap)15 Node (org.talend.designer.core.ui.editor.nodes.Node)12 IPreferenceStore (org.eclipse.jface.preference.IPreferenceStore)11 GenericElementParameter (org.talend.designer.core.generic.model.GenericElementParameter)10 Test (org.junit.Test)9 IComponent (org.talend.core.model.components.IComponent)8 ComponentProperties (org.talend.components.api.properties.ComponentProperties)7 IMetadataTable (org.talend.core.model.metadata.IMetadataTable)7 IConnection (org.talend.core.model.process.IConnection)7 Form (org.talend.daikon.properties.presentation.Form)6 ModuleNeeded (org.talend.core.model.general.ModuleNeeded)5 IMetadataColumn (org.talend.core.model.metadata.IMetadataColumn)5 INodeConnector (org.talend.core.model.process.INodeConnector)5 IProcess (org.talend.core.model.process.IProcess)4