use of org.talend.core.model.metadata.IMetadataTable 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());
}
use of org.talend.core.model.metadata.IMetadataTable in project tdi-studio-se by Talend.
the class ConnectionCreateCommandTest method executeSimpleInputToSimpleOutput3.
/**
* simple input to simple output with no metadata and without schema auto propagate.
*/
private ConnectionCreateCommand executeSimpleInputToSimpleOutput3() {
IProcess2 process = getFakeProcess();
Node simpleInputNode = NodeTestCreator.createSimpleInputNode(process);
// simple tests only since it's simply using the class ConnectionManager which already have JUnits.
List<Object> args = new ArrayList<Object>();
args.add(simpleInputNode.getUniqueName());
//$NON-NLS-1$
args.add("connectionName");
simpleInputNode.getMetadataList().clear();
IMetadataTable table = createSimpleMetadata1();
table.setTableName(simpleInputNode.getUniqueName());
table.setLabel(simpleInputNode.getUniqueName());
//$NON-NLS-1$
table.setAttachedConnector("FLOW");
simpleInputNode.getMetadataList().add(table);
// set null, the command should take the schema from the component directly
args.add(null);
//$NON-NLS-1$
ConnectionCreateCommand ccc = new ConnectionCreateCommand(simpleInputNode, "FLOW", args);
ConnectionCreateCommand.setCreatingConnection(true);
Node simpleOutputNode = NodeTestCreator.createSimpleOutputNodeNoPropagate(process);
ccc.setTarget(simpleOutputNode);
ccc.execute();
assertEquals(simpleInputNode.getOutgoingConnections().size(), 1);
assertEquals(simpleOutputNode.getIncomingConnections().size(), 1);
assertEquals(simpleOutputNode.getMetadataList().size(), 1);
IMetadataTable outputMetadata = simpleOutputNode.getMetadataList().get(0);
// no propagation
assertEquals(outputMetadata.getListColumns().size(), 0);
IConnection connection = simpleInputNode.getOutgoingConnections().get(0);
assertEquals(simpleOutputNode.getIncomingConnections().get(0), connection);
assertEquals(connection.getSource(), simpleInputNode);
assertEquals(connection.getTarget(), simpleOutputNode);
assertEquals(connection.getMetaName(), simpleInputNode.getUniqueName());
//$NON-NLS-1$
assertEquals(connection.getConnectorName(), "FLOW");
//$NON-NLS-1$
INodeConnector inputConnector = simpleInputNode.getConnectorFromName("FLOW");
//$NON-NLS-1$
INodeConnector outputConnector = simpleOutputNode.getConnectorFromName("FLOW");
assertEquals(inputConnector.getCurLinkNbOutput(), 1);
assertEquals(outputConnector.getCurLinkNbInput(), 1);
return ccc;
}
use of org.talend.core.model.metadata.IMetadataTable in project tdi-studio-se by Talend.
the class ConnectionCreateActionTest method createSimpleMetadata.
private IMetadataTable createSimpleMetadata() {
IMetadataTable table = new org.talend.core.model.metadata.MetadataTable();
IMetadataColumn column1 = new MetadataColumn();
//$NON-NLS-1$
column1.setLabel("C1");
//$NON-NLS-1$
column1.setTalendType("id_String");
table.getListColumns().add(column1);
IMetadataColumn column2 = new MetadataColumn();
//$NON-NLS-1$
column2.setLabel("C2");
//$NON-NLS-1$
column2.setTalendType("id_String");
table.getListColumns().add(column2);
IMetadataColumn column3 = new MetadataColumn();
//$NON-NLS-1$
column3.setLabel("C3");
//$NON-NLS-1$
column3.setTalendType("id_Integer");
table.getListColumns().add(column3);
return table;
}
use of org.talend.core.model.metadata.IMetadataTable in project tdi-studio-se by Talend.
the class ConnectionCreateActionTest method testRun2.
private void testRun2() {
EConnectionType ct = EConnectionType.FLOW_MAIN;
String text = "Main";
String tableName = text;
IMetadataTable meta = node.getMetadataTable("JOBS");
String connectionName = meta.getTableName();
assertEquals(connectionName, "JOBS");
}
use of org.talend.core.model.metadata.IMetadataTable in project tdi-studio-se by Talend.
the class SchemaUtilsTest method testUpdateComponentSchema.
@Test
public void testUpdateComponentSchema() {
//$NON-NLS-1$
String TEST_TABLE_NAME = "testTable";
//$NON-NLS-1$
String TEST_COL_NAME = "userId";
//$NON-NLS-1$
String ADDED_COL_NAME = "added";
//$NON-NLS-1$
String SCHEMA_PROP_NAME = "schema.schema";
// Create the test MetadataTable.
MetadataTable table = createMetadataTable(TEST_TABLE_NAME);
MetadataColumn testColumn = ConnectionFactory.eINSTANCE.createMetadataColumn();
testColumn.setName(TEST_COL_NAME);
testColumn.setLabel(testColumn.getName());
//$NON-NLS-1$
testColumn.setDefaultValue("1");
testColumn.setTalendType(JavaTypesManager.STRING.getId());
table.getColumns().add(testColumn);
// Create one component properties which has one schema property.
//$NON-NLS-1$
TestProperties props = (TestProperties) new TestProperties("test").init();
Schema oldSchema = SchemaBuilder.record(TEST_TABLE_NAME).fields().name(TEST_COL_NAME).type().stringType().noDefault().endRecord();
props.schema.schema.setValue(oldSchema);
// Set the component properties and schema property name into MetadataTable.
TaggedValue serializedPropsTV = CoreFactory.eINSTANCE.createTaggedValue();
serializedPropsTV.setTag(IComponentConstants.COMPONENT_PROPERTIES_TAG);
serializedPropsTV.setValue(props.toSerialized());
table.getTaggedValue().add(serializedPropsTV);
TaggedValue schemaPropertyTV = CoreFactory.eINSTANCE.createTaggedValue();
schemaPropertyTV.setTag(IComponentConstants.COMPONENT_SCHEMA_TAG);
schemaPropertyTV.setValue(SCHEMA_PROP_NAME);
table.getTaggedValue().add(schemaPropertyTV);
// Add another MetadataColumn into MetadataTable.
MetadataColumn addedColumn = ConnectionFactory.eINSTANCE.createMetadataColumn();
addedColumn.setName(ADDED_COL_NAME);
addedColumn.setLabel(addedColumn.getName());
//$NON-NLS-1$
addedColumn.setDefaultValue("x");
addedColumn.setTalendType(JavaTypesManager.STRING.getId());
table.getColumns().add(addedColumn);
// Invoke updateComponentSchema() method.
SchemaUtils.updateComponentSchema(table, null);
// Check if the schema object is updated correctly.
String componentPropertiesStr = null;
String schemaPropertyName = null;
EList<TaggedValue> taggedValues = table.getTaggedValue();
for (TaggedValue taggedValue : taggedValues) {
String tag = taggedValue.getTag();
String tagValue = taggedValue.getValue();
if (IComponentConstants.COMPONENT_PROPERTIES_TAG.equals(tag)) {
componentPropertiesStr = tagValue;
} else if (IComponentConstants.COMPONENT_SCHEMA_TAG.equals(tag)) {
schemaPropertyName = tagValue;
}
}
ComponentProperties componentProperties = ComponentsUtils.getComponentPropertiesFromSerialized(componentPropertiesStr, null);
Object schemaValue = componentProperties.getValuedProperty(schemaPropertyName).getValue();
Schema avroSchema = getAvroSchema(schemaValue);
props.schema.schema.setValue(avroSchema);
assertNotNull(avroSchema.getField(TEST_COL_NAME));
assertNotNull(avroSchema.getField(ADDED_COL_NAME));
assertEquals(2, avroSchema.getFields().size());
// Test method updateComponentSchema(ComponentProperties componentProperties, String schemaPropertyName,
// IMetadataTable metadataTable)
IMetadataTable iMetadataTable = MetadataToolHelper.convert(table);
iMetadataTable.getListColumns().remove(1);
SchemaUtils.updateComponentSchema(props, SCHEMA_PROP_NAME, iMetadataTable);
schemaValue = props.getValuedProperty(schemaPropertyName).getValue();
avroSchema = getAvroSchema(schemaValue);
assertNotNull(avroSchema.getField(TEST_COL_NAME));
assertNull(avroSchema.getField(ADDED_COL_NAME));
assertEquals(1, avroSchema.getFields().size());
}
Aggregations