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);
}
}
}
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;
}
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());
}
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);
}
Aggregations