Search in sources :

Example 21 with GenericConnection

use of org.talend.repository.generic.model.genericMetadata.GenericConnection in project tdi-studio-se by Talend.

the class RepositoryUpdateTest method testRepositoryResetParams.

@Test
public void testRepositoryResetParams() 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\"");
        IElementParameter param = node.getElementParameter("connection.userPassword.userId");
        assertTrue(param.isRepositoryValueUsed());
        assertNotNull(param.getRepositoryValue());
        Form form = node.getComponentProperties().getForm(Form.MAIN);
        List<ElementParameter> parameters = new ArrayList<>();
        parameters = ComponentsUtils.getParametersFromForm(node, false, EComponentCategory.BASIC, node.getComponentProperties(), form);
        node.setElementParameters(parameters);
        param = node.getElementParameter("connection.userPassword.userId");
        assertTrue(param.isRepositoryValueUsed());
        assertNotNull(param.getRepositoryValue());
    } finally {
        IRepositoryViewObject object = ProxyRepositoryFactory.getInstance().getLastVersion(id);
        if (object != null) {
            ProxyRepositoryFactory.getInstance().deleteObjectPhysical(object);
        }
    }
}
Also used : IElementParameter(org.talend.core.model.process.IElementParameter) ElementParameter(org.talend.designer.core.model.components.ElementParameter) FakePropertyImpl(org.talend.core.model.repository.FakePropertyImpl) Form(org.talend.daikon.properties.presentation.Form) IComponent(org.talend.core.model.components.IComponent) Node(org.talend.designer.core.ui.editor.nodes.Node) INode(org.talend.core.model.process.INode) ArrayList(java.util.ArrayList) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) IElementParameter(org.talend.core.model.process.IElementParameter) Process(org.talend.designer.core.ui.editor.process.Process) GenericConnection(org.talend.repository.generic.model.genericMetadata.GenericConnection) Test(org.junit.Test)

Example 22 with GenericConnection

use of org.talend.repository.generic.model.genericMetadata.GenericConnection in project tdi-studio-se by Talend.

the class GenericConnectionUtilTest method createTestItem.

private GenericConnectionItem createTestItem(String label, String serializedProps) {
    GenericConnection connection = GenericMetadataFactory.eINSTANCE.createGenericConnection();
    connection.setCompProperties(serializedProps);
    Property connectionProperty = PropertiesFactory.eINSTANCE.createProperty();
    //$NON-NLS-1$
    connectionProperty.setId("testId");
    connectionProperty.setLabel(label);
    connectionProperty.setVersion(VersionUtils.DEFAULT_VERSION);
    //$NON-NLS-1$
    connectionProperty.setStatusCode("");
    GenericConnectionItem connectionItem = GenericMetadataFactory.eINSTANCE.createGenericConnectionItem();
    connectionItem.setProperty(connectionProperty);
    connectionItem.setConnection(connection);
    return connectionItem;
}
Also used : GenericConnection(org.talend.repository.generic.model.genericMetadata.GenericConnection) GenericConnectionItem(org.talend.repository.generic.model.genericMetadata.GenericConnectionItem) Property(org.talend.core.model.properties.Property)

Example 23 with GenericConnection

use of org.talend.repository.generic.model.genericMetadata.GenericConnection in project tdi-studio-se by Talend.

the class GenericConnectionUtilTest method testSynNamePropertyWithItem.

@Test
public void testSynNamePropertyWithItem() {
    //$NON-NLS-1$
    String namePropertyValue = "test";
    //$NON-NLS-1$
    TestProperties props = (TestProperties) new TestProperties("test").init();
    props.name.setValue(namePropertyValue);
    String serializedProps = props.toSerialized();
    GenericConnectionItem testItem = createTestItem(namePropertyValue, serializedProps);
    GenericConnection testConn = (GenericConnection) testItem.getConnection();
    boolean itemChanged = GenericConnectionUtil.synNamePropertyWithItem(testItem);
    assertFalse(itemChanged);
    ComponentProperties componentProperties = ComponentsUtils.getComponentPropertiesFromSerialized(serializedProps, testConn);
    assertEquals(namePropertyValue, componentProperties.getValuedProperty(IGenericConstants.NAME_PROPERTY).getValue());
    //$NON-NLS-1$
    String newPropertyValue = "test1";
    testItem.getProperty().setLabel(newPropertyValue);
    itemChanged = GenericConnectionUtil.synNamePropertyWithItem(testItem);
    assertTrue(itemChanged);
    componentProperties = ComponentsUtils.getComponentPropertiesFromSerialized(testConn.getCompProperties(), testConn);
    assertEquals(newPropertyValue, componentProperties.getValuedProperty(IGenericConstants.NAME_PROPERTY).getValue());
}
Also used : ComponentProperties(org.talend.components.api.properties.ComponentProperties) GenericConnection(org.talend.repository.generic.model.genericMetadata.GenericConnection) GenericConnectionItem(org.talend.repository.generic.model.genericMetadata.GenericConnectionItem) Test(org.junit.Test)

Example 24 with GenericConnection

use of org.talend.repository.generic.model.genericMetadata.GenericConnection in project tdi-studio-se by Talend.

the class GenericContextUtilTest method testExportAndRevertContextForComponentProperties.

@Test
public void testExportAndRevertContextForComponentProperties() {
    //$NON-NLS-1$
    String prefix = "testConn";
    GenericConnection connection = GenericMetadataFactory.eINSTANCE.createGenericConnection();
    //$NON-NLS-1$
    TestProperties props = (TestProperties) new TestProperties("test").init();
    //$NON-NLS-1$
    props.userId.setValue("1");
    //$NON-NLS-1$
    TestNestedProperties nestedProps = (TestNestedProperties) props.getProperty("nestedProps");
    //$NON-NLS-1$
    nestedProps.userName.setValue("testUserName");
    //$NON-NLS-1$
    nestedProps.userPassword.setValue("testUserPassword");
    connection.setCompProperties(props.toSerialized());
    Set<IConnParamName> contextParams = new HashSet<>();
    //$NON-NLS-1$
    contextParams.add(createConnParamName("userId"));
    //$NON-NLS-1$
    contextParams.add(createConnParamName("nestedProps.userName"));
    //$NON-NLS-1$
    contextParams.add(createConnParamName("nestedProps.userPassword"));
    // Test export context
    GenericContextUtil.setPropertiesForContextMode(prefix, connection, contextParams);
    TestProperties deserProps = getPropertiesFromConnection(connection);
    //$NON-NLS-1$
    assertEquals("context.testConn_userId", deserProps.userId.getValue());
    //$NON-NLS-1$
    assertEquals("context.testConn_nestedProps_userName", deserProps.nestedProps.userName.getValue());
    //$NON-NLS-1$
    assertEquals("context.testConn_nestedProps_userPassword", deserProps.nestedProps.userPassword.getValue());
    assertEquals(deserProps.userId.getTaggedValue(IGenericConstants.IS_CONTEXT_MODE), true);
    assertEquals(deserProps.nestedProps.userName.getTaggedValue(IGenericConstants.IS_CONTEXT_MODE), true);
    assertEquals(deserProps.nestedProps.userPassword.getTaggedValue(IGenericConstants.IS_CONTEXT_MODE), true);
    // Test revert context
    ContextType contextType = TalendFileFactoryImpl.eINSTANCE.createContextType();
    //$NON-NLS-1$ //$NON-NLS-2$
    contextType.getContextParameter().add(createContextParameterType("testConn_userId", "1"));
    //$NON-NLS-1$ //$NON-NLS-2$
    contextType.getContextParameter().add(createContextParameterType("testConn_nestedProps_userName", "testUserName"));
    //$NON-NLS-1$ //$NON-NLS-2$
    contextType.getContextParameter().add(createContextParameterType("testConn_nestedProps_userPassword", "testUserPassword"));
    GenericContextUtil.revertPropertiesForContextMode(connection, contextType);
    deserProps = getPropertiesFromConnection(connection);
    //$NON-NLS-1$
    assertEquals("1", deserProps.userId.getValue());
    //$NON-NLS-1$
    assertEquals("testUserName", deserProps.nestedProps.userName.getValue());
    //$NON-NLS-1$
    assertEquals("testUserPassword", deserProps.nestedProps.userPassword.getValue());
    assertEquals(deserProps.userId.getTaggedValue(IGenericConstants.IS_CONTEXT_MODE), false);
    assertEquals(deserProps.nestedProps.userName.getTaggedValue(IGenericConstants.IS_CONTEXT_MODE), false);
    assertEquals(deserProps.nestedProps.userPassword.getTaggedValue(IGenericConstants.IS_CONTEXT_MODE), false);
}
Also used : ContextType(org.talend.designer.core.model.utils.emf.talendfile.ContextType) IConnParamName(org.talend.metadata.managment.ui.model.IConnParamName) GenericConnection(org.talend.repository.generic.model.genericMetadata.GenericConnection) HashSet(java.util.HashSet) Test(org.junit.Test)

Aggregations

GenericConnection (org.talend.repository.generic.model.genericMetadata.GenericConnection)24 ComponentProperties (org.talend.components.api.properties.ComponentProperties)11 GenericConnectionItem (org.talend.repository.generic.model.genericMetadata.GenericConnectionItem)10 IRepositoryViewObject (org.talend.core.model.repository.IRepositoryViewObject)6 ArrayList (java.util.ArrayList)5 Test (org.junit.Test)5 ConnectionItem (org.talend.core.model.properties.ConnectionItem)5 IComponent (org.talend.core.model.components.IComponent)4 Connection (org.talend.core.model.metadata.builder.connection.Connection)4 IConnParamName (org.talend.metadata.managment.ui.model.IConnParamName)4 Path (org.eclipse.core.runtime.Path)3 ComponentService (org.talend.components.api.service.ComponentService)3 ComponentWizard (org.talend.components.api.wizard.ComponentWizard)3 MetadataTable (org.talend.core.model.metadata.builder.connection.MetadataTable)3 INode (org.talend.core.model.process.INode)3 Property (org.talend.core.model.properties.Property)3 FakePropertyImpl (org.talend.core.model.repository.FakePropertyImpl)3 Node (org.talend.designer.core.ui.editor.nodes.Node)3 Process (org.talend.designer.core.ui.editor.process.Process)3 GenericConnParamName (org.talend.metadata.managment.ui.utils.GenericConnParamName)3