Search in sources :

Example 1 with FakePropertyImpl

use of org.talend.core.model.repository.FakePropertyImpl in project tdi-studio-se by Talend.

the class RepositoryChangeMetadataCommandTest method testComponentSchemaUpdated.

@Test
public void testComponentSchemaUpdated() {
    IComponent component = ComponentsFactoryProvider.getInstance().get("tSalesforceInput", "DI");
    Node node = new Node(component, new Process(new FakePropertyImpl()));
    IMetadataTable table = node.getMetadataList().get(0);
    IMetadataColumn column = new MetadataColumn();
    column.setLabel("C1");
    column.setTalendType(JavaTypesManager.STRING.getId());
    table.getListColumns().add(column);
    column = new MetadataColumn();
    column.setLabel("C2");
    column.setTalendType(JavaTypesManager.STRING.getId());
    table.getListColumns().add(column);
    column = new MetadataColumn();
    column.setLabel("C3");
    column.setTalendType(JavaTypesManager.STRING.getId());
    table.getListColumns().add(column);
    IMetadataTable newTable = table.clone(true);
    newTable.getListColumns().remove(0);
    IElementParameter schemaParam = null;
    for (IElementParameter param : node.getElementParameters()) {
        if (EParameterFieldType.SCHEMA_REFERENCE.equals(param.getFieldType())) {
            schemaParam = param;
            break;
        }
    }
    assertNotNull(schemaParam);
    //$NON-NLS-1$
    String fullParamName = SCHEMA_PARAM_NAME + ":REPOSITORY_SCHEMA_TYPE";
    //$NON-NLS-1$ //$NON-NLS-2$
    String propValue = "testconnid" + " - " + newTable.getTableName();
    RepositoryChangeMetadataCommand changeMetadataCommand = new RepositoryChangeMetadataCommand(node, fullParamName, propValue, newTable, null, null);
    changeMetadataCommand.execute();
    newTable = node.getMetadataList().get(0);
    String avroSchemaStr = ((SchemaProperties) node.getComponentProperties().getProperties("module.main")).schema.getStringValue();
    assertNotNull(avroSchemaStr);
    Schema avroSchema = new Schema.Parser().parse(avroSchemaStr);
    assertEquals(2, avroSchema.getFields().size());
    //$NON-NLS-1$
    assertNull(avroSchema.getField("C1"));
    assertEquals(avroSchemaStr, schemaParam.getValue().toString());
}
Also used : IMetadataTable(org.talend.core.model.metadata.IMetadataTable) IMetadataColumn(org.talend.core.model.metadata.IMetadataColumn) MetadataColumn(org.talend.core.model.metadata.MetadataColumn) FakePropertyImpl(org.talend.core.model.repository.FakePropertyImpl) IComponent(org.talend.core.model.components.IComponent) Node(org.talend.designer.core.ui.editor.nodes.Node) Schema(org.apache.avro.Schema) IElementParameter(org.talend.core.model.process.IElementParameter) Process(org.talend.designer.core.ui.editor.process.Process) IMetadataColumn(org.talend.core.model.metadata.IMetadataColumn) Test(org.junit.Test)

Example 2 with FakePropertyImpl

use of org.talend.core.model.repository.FakePropertyImpl in project tdi-studio-se by Talend.

the class ChangeMetadataCommandTest method testComponentSchemaUpdated.

@Test
public void testComponentSchemaUpdated() {
    IComponent component = ComponentsFactoryProvider.getInstance().get("tSalesforceInput", "DI");
    Node node = new Node(component, new Process(new FakePropertyImpl()));
    IMetadataTable table = node.getMetadataList().get(0);
    IMetadataColumn column = new MetadataColumn();
    column.setLabel("C1");
    column.setTalendType(JavaTypesManager.STRING.getId());
    table.getListColumns().add(column);
    column = new MetadataColumn();
    column.setLabel("C2");
    column.setTalendType(JavaTypesManager.STRING.getId());
    table.getListColumns().add(column);
    column = new MetadataColumn();
    column.setLabel("C3");
    column.setTalendType(JavaTypesManager.STRING.getId());
    table.getListColumns().add(column);
    IMetadataTable newTable = table.clone(true);
    newTable.getListColumns().remove(0);
    IElementParameter schemaParam = null;
    for (IElementParameter param : node.getElementParameters()) {
        if (EParameterFieldType.SCHEMA_REFERENCE.equals(param.getFieldType())) {
            schemaParam = param;
            break;
        }
    }
    assertNotNull(schemaParam);
    ChangeMetadataCommand changeMetadataCommand = new ChangeMetadataCommand(node, schemaParam, null, null, null, table, newTable);
    changeMetadataCommand.execute();
    String avroSchemaStr = ((SchemaProperties) node.getComponentProperties().getProperties("module.main")).schema.getStringValue();
    assertNotNull(avroSchemaStr);
    Schema avroSchema = new Schema.Parser().parse(avroSchemaStr);
    assertEquals(2, avroSchema.getFields().size());
    //$NON-NLS-1$
    assertNull(avroSchema.getField("C1"));
    assertEquals(avroSchemaStr, schemaParam.getValue().toString());
}
Also used : IMetadataTable(org.talend.core.model.metadata.IMetadataTable) IMetadataColumn(org.talend.core.model.metadata.IMetadataColumn) MetadataColumn(org.talend.core.model.metadata.MetadataColumn) FakePropertyImpl(org.talend.core.model.repository.FakePropertyImpl) IComponent(org.talend.core.model.components.IComponent) Node(org.talend.designer.core.ui.editor.nodes.Node) Schema(org.apache.avro.Schema) IElementParameter(org.talend.core.model.process.IElementParameter) Process(org.talend.designer.core.ui.editor.process.Process) IMetadataColumn(org.talend.core.model.metadata.IMetadataColumn) Test(org.junit.Test)

Example 3 with FakePropertyImpl

use of org.talend.core.model.repository.FakePropertyImpl in project tdi-studio-se by Talend.

the class NodeTest method testGetNodeConnectorsShowIf1FlowConnector.

@Test
public void testGetNodeConnectorsShowIf1FlowConnector() {
    Process process = new Process(new FakePropertyImpl());
    IComponent sourceCom = ComponentsFactoryProvider.getInstance().get("tMysqlInput", ComponentCategory.CATEGORY_4_DI.getName());
    Node node = new Node(sourceCom, process);
    // create node connector for test
    List<INodeConnector> listConnector = new ArrayList<>();
    NodeConnector connector = new NodeConnector(node);
    connector.setDefaultConnectionType(EConnectionType.FLOW_MAIN);
    connector.setName(EConnectionType.FLOW_MAIN.getName());
    connector.setMaxLinkOutput(1);
    connector.setShowIf("SHOW_FLOW_CONNECTOR == 'true'");
    listConnector.add(connector);
    node.setListConnector(listConnector);
    // create a test param with default value 'false'
    IElementParameter param = addShowIfParam(node);
    Assert.assertNull(node.getConnectorFromName(EConnectionType.FLOW_MAIN.getName()));
    Assert.assertNull(node.getConnectorFromType(EConnectionType.FLOW_MAIN));
    Assert.assertEquals(node.getConnectorsFromType(EConnectionType.FLOW_MAIN).size(), 0);
    // make connector show if to 'true'
    param.setValue(true);
    Assert.assertNotNull(node.getConnectorFromName(EConnectionType.FLOW_MAIN.getName()));
    Assert.assertNotNull(node.getConnectorFromType(EConnectionType.FLOW_MAIN));
    Assert.assertEquals(node.getConnectorsFromType(EConnectionType.FLOW_MAIN).size(), 1);
}
Also used : FakePropertyImpl(org.talend.core.model.repository.FakePropertyImpl) INodeConnector(org.talend.core.model.process.INodeConnector) NodeConnector(org.talend.designer.core.model.components.NodeConnector) IComponent(org.talend.core.model.components.IComponent) ArrayList(java.util.ArrayList) IElementParameter(org.talend.core.model.process.IElementParameter) Process(org.talend.designer.core.ui.editor.process.Process) INodeConnector(org.talend.core.model.process.INodeConnector) Test(org.junit.Test)

Example 4 with FakePropertyImpl

use of org.talend.core.model.repository.FakePropertyImpl in project tdi-studio-se by Talend.

the class NodeTest method testGetNodeConnectorsShowIf2FlowConnector.

@Test
public void testGetNodeConnectorsShowIf2FlowConnector() {
    Process process = new Process(new FakePropertyImpl());
    IComponent sourceCom = ComponentsFactoryProvider.getInstance().get("tMysqlInput", ComponentCategory.CATEGORY_4_DI.getName());
    Node node = new Node(sourceCom, process);
    // create node connector for test
    List<INodeConnector> listConnector = new ArrayList<>();
    NodeConnector connector1 = new NodeConnector(node);
    connector1.setDefaultConnectionType(EConnectionType.FLOW_MAIN);
    connector1.setName(EConnectionType.FLOW_MAIN.getName());
    connector1.setMaxLinkOutput(1);
    listConnector.add(connector1);
    connector1.setShowIf("SHOW_FLOW_CONNECTOR == 'true'");
    NodeConnector connector2 = new NodeConnector(node);
    connector2.setDefaultConnectionType(EConnectionType.FLOW_MAIN);
    connector2.setName(EConnectionType.FLOW_MAIN.getName());
    connector2.setMaxLinkInput(-1);
    connector2.setMaxLinkOutput(-1);
    connector2.setShowIf("SHOW_FLOW_CONNECTOR == 'false'");
    listConnector.add(connector2);
    node.setListConnector(listConnector);
    // create a test param with default value 'false'
    IElementParameter param = addShowIfParam(node);
    Assert.assertTrue(node.getConnectorFromName(EConnectionType.FLOW_MAIN.getName()) == connector2);
    Assert.assertTrue(node.getConnectorFromType(EConnectionType.FLOW_MAIN) == connector2);
    Assert.assertEquals(node.getConnectorsFromType(EConnectionType.FLOW_MAIN).size(), 1);
    // make connector show if to 'true'
    param.setValue(true);
    Assert.assertTrue(node.getConnectorFromName(EConnectionType.FLOW_MAIN.getName()) == connector1);
    Assert.assertTrue(node.getConnectorFromType(EConnectionType.FLOW_MAIN) == connector1);
    Assert.assertEquals(node.getConnectorsFromType(EConnectionType.FLOW_MAIN).size(), 1);
    // connector with same name should have the same current input/output
    connector1.setCurLinkNbInput(10);
    connector1.setCurLinkNbOutput(100);
    Assert.assertEquals(connector1.getCurLinkNbInput(), 10);
    Assert.assertEquals(connector1.getCurLinkNbOutput(), 100);
    Assert.assertEquals(connector2.getCurLinkNbInput(), 10);
    Assert.assertEquals(connector2.getCurLinkNbOutput(), 100);
}
Also used : FakePropertyImpl(org.talend.core.model.repository.FakePropertyImpl) INodeConnector(org.talend.core.model.process.INodeConnector) NodeConnector(org.talend.designer.core.model.components.NodeConnector) IComponent(org.talend.core.model.components.IComponent) ArrayList(java.util.ArrayList) IElementParameter(org.talend.core.model.process.IElementParameter) Process(org.talend.designer.core.ui.editor.process.Process) INodeConnector(org.talend.core.model.process.INodeConnector) Test(org.junit.Test)

Example 5 with FakePropertyImpl

use of org.talend.core.model.repository.FakePropertyImpl in project tdi-studio-se by Talend.

the class RepositoryUpdateTest method testRepositoryChange.

@Test
public void testRepositoryChange() throws PersistenceException {
    //$NON-NLS-1$
    String id = "testId";
    try {
        //$NON-NLS-1$ //$NON-NLS-2$
        IComponent component = ComponentsFactoryProvider.getInstance().get("tSalesforceInput", "DI");
        Node node = new Node(component, new Process(new FakePropertyImpl()));
        GenericConnection connection = (GenericConnection) createBasicConnection(id).getConnection();
        setupPropertiesWithoutProxy(id);
        updateNode(id, node, connection);
        //$NON-NLS-1$  //$NON-NLS-2$
        testRepositoryValue(node, "connection.userPassword.userId", "\"myUser\"");
        //$NON-NLS-1$  //$NON-NLS-2$
        testRepositoryValue(node, "connection.userPassword.password", "\"myPassword\"");
        //$NON-NLS-1$
        testRepositoryValue(node, "connection.proxy.useProxy", Boolean.FALSE);
        //$NON-NLS-1$  //$NON-NLS-2$
        testRepositoryValue(node, "connection.proxy.host", "\"\"");
        //$NON-NLS-1$
        testRepositoryValue(node, "connection.proxy.port", null);
        //$NON-NLS-1$  //$NON-NLS-2$
        testRepositoryValue(node, "connection.proxy.userPassword.userId", "\"\"");
        //$NON-NLS-1$  //$NON-NLS-2$
        testRepositoryValue(node, "connection.proxy.userPassword.password", "\"\"");
        setupPropertiesWithProxy(id);
        updateNode(id, node, connection);
        //$NON-NLS-1$  //$NON-NLS-2$
        testRepositoryValue(node, "connection.userPassword.userId", "\"myUser\"");
        //$NON-NLS-1$  //$NON-NLS-2$
        testRepositoryValue(node, "connection.userPassword.password", "\"myPassword\"");
        //$NON-NLS-1$
        testRepositoryValue(node, "connection.proxy.useProxy", Boolean.TRUE);
        //$NON-NLS-1$  //$NON-NLS-2$
        testRepositoryValue(node, "connection.proxy.host", "\"host\"");
        //$NON-NLS-1$
        testRepositoryValue(node, "connection.proxy.port", 1234);
        //$NON-NLS-1$  //$NON-NLS-2$
        testRepositoryValue(node, "connection.proxy.userPassword.userId", "\"proxyUser\"");
        //$NON-NLS-1$  //$NON-NLS-2$
        testRepositoryValue(node, "connection.proxy.userPassword.password", "\"proxyPassword\"");
    } finally {
        IRepositoryViewObject object = ProxyRepositoryFactory.getInstance().getLastVersion(id);
        if (object != null) {
            ProxyRepositoryFactory.getInstance().deleteObjectPhysical(object);
        }
    }
}
Also used : FakePropertyImpl(org.talend.core.model.repository.FakePropertyImpl) IComponent(org.talend.core.model.components.IComponent) Node(org.talend.designer.core.ui.editor.nodes.Node) INode(org.talend.core.model.process.INode) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) Process(org.talend.designer.core.ui.editor.process.Process) GenericConnection(org.talend.repository.generic.model.genericMetadata.GenericConnection) Test(org.junit.Test)

Aggregations

FakePropertyImpl (org.talend.core.model.repository.FakePropertyImpl)18 IComponent (org.talend.core.model.components.IComponent)15 Process (org.talend.designer.core.ui.editor.process.Process)15 Test (org.junit.Test)13 Node (org.talend.designer.core.ui.editor.nodes.Node)12 ArrayList (java.util.ArrayList)8 IElementParameter (org.talend.core.model.process.IElementParameter)8 INode (org.talend.core.model.process.INode)8 IRepositoryViewObject (org.talend.core.model.repository.IRepositoryViewObject)5 Schema (org.apache.avro.Schema)3 IMetadataTable (org.talend.core.model.metadata.IMetadataTable)3 INodeConnector (org.talend.core.model.process.INodeConnector)3 GenericConnection (org.talend.repository.generic.model.genericMetadata.GenericConnection)3 File (java.io.File)2 IOException (java.io.IOException)2 List (java.util.List)2 IProject (org.eclipse.core.resources.IProject)2 IPath (org.eclipse.core.runtime.IPath)2 Path (org.eclipse.core.runtime.Path)2 Before (org.junit.Before)2