Program: 118547
Project: 118547
Buggy source:
@Test public void testUpdateComponentSchema(){
  String TEST_TABLE_NAME="String_Node_Str";
  String TEST_COL_NAME="String_Node_Str";
  String ADDED_COL_NAME="String_Node_Str";
  String SCHEMA_PROP_NAME="String_Node_Str";
  MetadataTable table=createMetadataTable(TEST_TABLE_NAME);
  MetadataColumn testColumn=ConnectionFactory.eINSTANCE.createMetadataColumn();
  testColumn.setName(TEST_COL_NAME);
  testColumn.setLabel(testColumn.getName());
  testColumn.setDefaultValue("String_Node_Str");
  testColumn.setTalendType(JavaTypesManager.STRING.getId());
  table.getColumns().add(testColumn);
  TestProperties props=(TestProperties)new TestProperties("String_Node_Str").init();
  Schema oldSchema=SchemaBuilder.record(TEST_TABLE_NAME).fields().name(TEST_COL_NAME).type().stringType().noDefault().endRecord();
  props.schema.schema.setValue(oldSchema);
  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);
  MetadataColumn addedColumn=ConnectionFactory.eINSTANCE.createMetadataColumn();
  addedColumn.setName(ADDED_COL_NAME);
  addedColumn.setLabel(addedColumn.getName());
  addedColumn.setDefaultValue("String_Node_Str");
  addedColumn.setTalendType(JavaTypesManager.STRING.getId());
  table.getColumns().add(addedColumn);
  SchemaUtils.updateComponentSchema(table);
  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;
    }
  }
  Deserialized<ComponentProperties> fromSerialized=Properties.fromSerialized(componentPropertiesStr,ComponentProperties.class);
  ComponentProperties componentProperties=fromSerialized.properties;
  Object schemaValueStr=componentProperties.getValuedProperty(schemaPropertyName).getValue();
  Schema avroSchema=new Schema.Parser().parse((String)schemaValueStr);
  assertNotNull(avroSchema.getField(ADDED_COL_NAME));
  IMetadataTable iMetadataTable=MetadataToolHelper.convert(table);
  SchemaUtils.updateComponentSchema(props,SCHEMA_PROP_NAME,iMetadataTable);
  Map<String,String> additionalProperties=iMetadataTable.getAdditionalProperties();
  componentPropertiesStr=additionalProperties.get(IComponentConstants.COMPONENT_PROPERTIES_TAG);
  fromSerialized=Properties.fromSerialized(componentPropertiesStr,ComponentProperties.class);
  componentProperties=fromSerialized.properties;
  schemaPropertyName=additionalProperties.get(IComponentConstants.COMPONENT_SCHEMA_TAG);
  schemaValueStr=componentProperties.getValuedProperty(schemaPropertyName).getValue();
  avroSchema=new Schema.Parser().parse((String)schemaValueStr);
  assertNotNull(avroSchema.getField(TEST_COL_NAME));
  assertNotNull(avroSchema.getField(ADDED_COL_NAME));
  assertEquals(2,avroSchema.getFields().size());
}

Fixed version (ground truth):
@Test public void testUpdateComponentSchema(){
  String TEST_TABLE_NAME="String_Node_Str";
  String TEST_COL_NAME="String_Node_Str";
  String ADDED_COL_NAME="String_Node_Str";
  String SCHEMA_PROP_NAME="String_Node_Str";
  MetadataTable table=createMetadataTable(TEST_TABLE_NAME);
  MetadataColumn testColumn=ConnectionFactory.eINSTANCE.createMetadataColumn();
  testColumn.setName(TEST_COL_NAME);
  testColumn.setLabel(testColumn.getName());
  testColumn.setDefaultValue("String_Node_Str");
  testColumn.setTalendType(JavaTypesManager.STRING.getId());
  table.getColumns().add(testColumn);
  TestProperties props=(TestProperties)new TestProperties("String_Node_Str").init();
  Schema oldSchema=SchemaBuilder.record(TEST_TABLE_NAME).fields().name(TEST_COL_NAME).type().stringType().noDefault().endRecord();
  props.schema.schema.setValue(oldSchema);
  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);
  MetadataColumn addedColumn=ConnectionFactory.eINSTANCE.createMetadataColumn();
  addedColumn.setName(ADDED_COL_NAME);
  addedColumn.setLabel(addedColumn.getName());
  addedColumn.setDefaultValue("String_Node_Str");
  addedColumn.setTalendType(JavaTypesManager.STRING.getId());
  table.getColumns().add(addedColumn);
  SchemaUtils.updateComponentSchema(table);
  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);
  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());
  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());
}