Bug 559017 - Unsettable object attributes with default value do not get
migrated correctly

Unsettable object attributes which have a default value are not
correctly migrated if they are null.
The fix is to set the (new) null values, too in the object instance
during migration if the unsettable flag is set.

Change-Id: I80fbd7fadc0b05597b09bffb32af9ddb8bfe6d84
Signed-off-by: rsieger <ralf.sieger@ids.de>
diff --git a/plugins/org.eclipse.emf.edapt.migration/generated-src/org/eclipse/emf/edapt/spi/migration/impl/InstanceImpl.java b/plugins/org.eclipse.emf.edapt.migration/generated-src/org/eclipse/emf/edapt/spi/migration/impl/InstanceImpl.java
index 13919f6..e14c789 100644
--- a/plugins/org.eclipse.emf.edapt.migration/generated-src/org/eclipse/emf/edapt/spi/migration/impl/InstanceImpl.java
+++ b/plugins/org.eclipse.emf.edapt.migration/generated-src/org/eclipse/emf/edapt/spi/migration/impl/InstanceImpl.java
@@ -217,8 +217,7 @@
 			if (msgs != null) {
 				msgs.dispatch();
 			}
-		}
-		else if (eNotificationRequired()) {
+		} else if (eNotificationRequired()) {
 			eNotify(new ENotificationImpl(this, Notification.SET, MigrationPackage.INSTANCE__TYPE, newType, newType));
 		}
 	}
@@ -381,7 +380,7 @@
 				if (isSet(feature) && oldValue != null) {
 					this.remove(feature, oldValue);
 				}
-				if (newValue != null) {
+				if (newValue != null || feature.isUnsettable()) {
 					this.add(feature, newValue);
 				}
 			}
diff --git a/tests/org.eclipse.emf.edapt.tests/data/unsettableObject/migrated_model.xmi b/tests/org.eclipse.emf.edapt.tests/data/unsettableObject/migrated_model.xmi
new file mode 100644
index 0000000..2efb079
--- /dev/null
+++ b/tests/org.eclipse.emf.edapt.tests/data/unsettableObject/migrated_model.xmi
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<unsettableObject:Container xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:unsettableObject="http://unsettableObject/2" xsi:schemaLocation="http://unsettableObject/1 unsettableObject.ecore">
+  <children>
+  	<unsettableAttribute xsi:nil="true"/>
+  </children>
+  <children unsettableAttribute="2"/>
+</unsettableObject:Container>
diff --git a/tests/org.eclipse.emf.edapt.tests/data/unsettableObject/original_model.xmi b/tests/org.eclipse.emf.edapt.tests/data/unsettableObject/original_model.xmi
new file mode 100644
index 0000000..69a0486
--- /dev/null
+++ b/tests/org.eclipse.emf.edapt.tests/data/unsettableObject/original_model.xmi
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<unsettableObject:Container xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:unsettableObject="http://unsettableObject/1" xsi:schemaLocation="http://unsettableObject/1 unsettableObject.ecore">
+  <children>
+  	<unsettableAttribute xsi:nil="true"/>
+  </children>
+  <children unsettableAttribute="2"/>
+</unsettableObject:Container>
diff --git a/tests/org.eclipse.emf.edapt.tests/data/unsettableObject/original_model_migrated.xmi b/tests/org.eclipse.emf.edapt.tests/data/unsettableObject/original_model_migrated.xmi
new file mode 100644
index 0000000..93fb8b7
--- /dev/null
+++ b/tests/org.eclipse.emf.edapt.tests/data/unsettableObject/original_model_migrated.xmi
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<unsettableObject:Container xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:unsettableObject="http://unsettableObject/2" xmi:id="__yAnQDXtEeqTGpiS7VQV7w">
+  <children xmi:id="__yAnQTXtEeqTGpiS7VQV7w">
+    <unsettableAttribute xsi:nil="true"/>
+  </children>
+  <children xmi:id="__yAnQjXtEeqTGpiS7VQV7w" unsettableAttribute="2"/>
+</unsettableObject:Container>
diff --git a/tests/org.eclipse.emf.edapt.tests/data/unsettableObject/unsettableObject.ecore b/tests/org.eclipse.emf.edapt.tests/data/unsettableObject/unsettableObject.ecore
new file mode 100644
index 0000000..59f9ada
--- /dev/null
+++ b/tests/org.eclipse.emf.edapt.tests/data/unsettableObject/unsettableObject.ecore
@@ -0,0 +1,13 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ecore:EPackage xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+    xmlns:ecore="http://www.eclipse.org/emf/2002/Ecore" name="unsettableObject" nsURI="http://unsettableObject/2" nsPrefix="unsettableObject">
+  <eClassifiers xsi:type="ecore:EClass" name="Container">
+    <eStructuralFeatures xsi:type="ecore:EReference" name="children" upperBound="-1"
+        eType="#//Child" containment="true"/>
+  </eClassifiers>
+  <eClassifiers xsi:type="ecore:EClass" name="Child">
+    <eStructuralFeatures xsi:type="ecore:EAttribute" name="unsettableAttribute" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EIntegerObject"
+        defaultValueLiteral="1" unsettable="true"/>
+  </eClassifiers>
+  <eClassifiers xsi:type="ecore:EClass" name="Foo"/>
+</ecore:EPackage>
diff --git a/tests/org.eclipse.emf.edapt.tests/data/unsettableObject/unsettableObject.history b/tests/org.eclipse.emf.edapt.tests/data/unsettableObject/unsettableObject.history
new file mode 100644
index 0000000..ba06e31
--- /dev/null
+++ b/tests/org.eclipse.emf.edapt.tests/data/unsettableObject/unsettableObject.history
@@ -0,0 +1,96 @@
+<?xml version="1.0" encoding="ASCII"?>
+<history:History xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:history="http://www.eclipse.org/emf/edapt/history/0.3" xmi:id="_I3fdwDK8Eeq__Mv5n169VA">
+  <releases xmi:id="_I3fdwTK8Eeq__Mv5n169VA" date="2020-01-09T09:43:50.648+0100">
+    <changes xsi:type="history:CompositeChange" xmi:id="_I3fdwjK8Eeq__Mv5n169VA">
+      <changes xsi:type="history:Create" xmi:id="_I3fdwzK8Eeq__Mv5n169VA">
+        <element href="unsettableObject.ecore#/"/>
+        <changes xsi:type="history:Set" xmi:id="_I3fdxDK8Eeq__Mv5n169VA" featureName="name" dataValue="unsettableObject">
+          <element href="unsettableObject.ecore#/"/>
+        </changes>
+        <changes xsi:type="history:Set" xmi:id="_I3fdxTK8Eeq__Mv5n169VA" featureName="nsURI" dataValue="http://unsettableObject/1">
+          <element href="unsettableObject.ecore#/"/>
+        </changes>
+        <changes xsi:type="history:Set" xmi:id="_I3fdxjK8Eeq__Mv5n169VA" featureName="nsPrefix" dataValue="unsettableObject">
+          <element href="unsettableObject.ecore#/"/>
+        </changes>
+      </changes>
+      <changes xsi:type="history:Create" xmi:id="_I3fdxzK8Eeq__Mv5n169VA" referenceName="eClassifiers">
+        <target href="unsettableObject.ecore#/"/>
+        <element href="unsettableObject.ecore#//Container"/>
+        <changes xsi:type="history:Set" xmi:id="_I3fdyDK8Eeq__Mv5n169VA" featureName="name" dataValue="Container">
+          <element href="unsettableObject.ecore#//Container"/>
+        </changes>
+      </changes>
+      <changes xsi:type="history:Create" xmi:id="_I3fdyTK8Eeq__Mv5n169VA" referenceName="eClassifiers">
+        <target href="unsettableObject.ecore#/"/>
+        <element href="unsettableObject.ecore#//Child"/>
+        <changes xsi:type="history:Set" xmi:id="_I3fdyjK8Eeq__Mv5n169VA" featureName="name" dataValue="Child">
+          <element href="unsettableObject.ecore#//Child"/>
+        </changes>
+      </changes>
+      <changes xsi:type="history:Create" xmi:id="_I3fdyzK8Eeq__Mv5n169VA" referenceName="eStructuralFeatures">
+        <target href="unsettableObject.ecore#//Container"/>
+        <element href="unsettableObject.ecore#//Container/children"/>
+        <changes xsi:type="history:Set" xmi:id="_I3fdzDK8Eeq__Mv5n169VA" featureName="name" dataValue="children">
+          <element href="unsettableObject.ecore#//Container/children"/>
+        </changes>
+        <changes xsi:type="history:Set" xmi:id="_I3fdzTK8Eeq__Mv5n169VA" featureName="upperBound" dataValue="-1" oldDataValue="1">
+          <element href="unsettableObject.ecore#//Container/children"/>
+        </changes>
+        <changes xsi:type="history:Set" xmi:id="_I3fdzjK8Eeq__Mv5n169VA" featureName="containment" dataValue="true" oldDataValue="false">
+          <element href="unsettableObject.ecore#//Container/children"/>
+        </changes>
+        <changes xsi:type="history:Set" xmi:id="_I3fdzzK8Eeq__Mv5n169VA" featureName="eType">
+          <element href="unsettableObject.ecore#//Container/children"/>
+          <referenceValue href="unsettableObject.ecore#//Child"/>
+        </changes>
+      </changes>
+      <changes xsi:type="history:Create" xmi:id="_I3fd0DK8Eeq__Mv5n169VA" referenceName="eStructuralFeatures">
+        <target href="unsettableObject.ecore#//Child"/>
+        <element href="unsettableObject.ecore#//Child/unsettableAttribute"/>
+        <changes xsi:type="history:Set" xmi:id="_I3fd0TK8Eeq__Mv5n169VA" featureName="name" dataValue="unsettableAttribute">
+          <element href="unsettableObject.ecore#//Child/unsettableAttribute"/>
+        </changes>
+        <changes xsi:type="history:Set" xmi:id="_I3fd0jK8Eeq__Mv5n169VA" featureName="defaultValueLiteral" dataValue="1">
+          <element href="unsettableObject.ecore#//Child/unsettableAttribute"/>
+        </changes>
+        <changes xsi:type="history:Set" xmi:id="_I3fd0zK8Eeq__Mv5n169VA" featureName="unsettable" dataValue="true" oldDataValue="false">
+          <element href="unsettableObject.ecore#//Child/unsettableAttribute"/>
+        </changes>
+        <changes xsi:type="history:Set" xmi:id="_I3fd1DK8Eeq__Mv5n169VA" featureName="eType">
+          <element href="unsettableObject.ecore#//Child/unsettableAttribute"/>
+          <referenceValue href="http://www.eclipse.org/emf/2002/Ecore#//EIntegerObject"/>
+        </changes>
+      </changes>
+    </changes>
+  </releases>
+  <releases xmi:id="_KLYHgDK8Eeq__Mv5n169VA" date="2020-01-09T09:45:41.189+0100">
+    <changes xsi:type="history:OperationChange" xmi:id="_ZUDW0DK8Eeq__Mv5n169VA">
+      <changes xsi:type="history:Create" xmi:id="_ZUDW0TK8Eeq__Mv5n169VA" referenceName="eClassifiers">
+        <target href="unsettableObject.ecore#/"/>
+        <element href="unsettableObject.ecore#//Foo"/>
+        <changes xsi:type="history:Set" xmi:id="_ZUDW0jK8Eeq__Mv5n169VA" featureName="name" dataValue="Foo">
+          <element href="unsettableObject.ecore#//Foo"/>
+        </changes>
+      </changes>
+      <operation xmi:id="_ZUDW0zK8Eeq__Mv5n169VA" name="newClass">
+        <parameters xmi:id="_ZUDW1DK8Eeq__Mv5n169VA" name="ePackage">
+          <referenceValue xmi:id="_ZUDW1TK8Eeq__Mv5n169VA">
+            <element href="unsettableObject.ecore#/"/>
+          </referenceValue>
+        </parameters>
+        <parameters xmi:id="_ZUDW1jK8Eeq__Mv5n169VA" name="name">
+          <dataValue>Foo</dataValue>
+        </parameters>
+        <parameters xmi:id="_ZUDW1zK8Eeq__Mv5n169VA" name="superClasses"/>
+        <parameters xmi:id="_ZUDW2DK8Eeq__Mv5n169VA" name="abstr">
+          <dataValue>false</dataValue>
+        </parameters>
+      </operation>
+    </changes>
+    <changes xsi:type="history:Set" xmi:id="_apk_UDK8Eeq__Mv5n169VA" featureName="nsURI" dataValue="http://unsettableObject/2" oldDataValue="http://unsettableObject/1">
+      <element href="unsettableObject.ecore#/"/>
+    </changes>
+  </releases>
+  <releases xmi:id="_apk_UTK8Eeq__Mv5n169VA"/>
+</history:History>
diff --git a/tests/org.eclipse.emf.edapt.tests/data/unsettableObject/unsettableObject.test b/tests/org.eclipse.emf.edapt.tests/data/unsettableObject/unsettableObject.test
new file mode 100644
index 0000000..cf51bd8
--- /dev/null
+++ b/tests/org.eclipse.emf.edapt.tests/data/unsettableObject/unsettableObject.test
@@ -0,0 +1,4 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<test:TestSuiteDefinition xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:test="http://www.eclipse.org/emf/edapt/migration/test/0.3" name="UnsettableObject attributes test" history="unsettableObject.history">
+  <cases name="UnsettableObject Model" model="original_model.xmi" expectedModel="migrated_model.xmi"/>
+</test:TestSuiteDefinition>