Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorcbrun2013-03-18 07:37:58 -0400
committercbrun2013-03-18 07:37:58 -0400
commit0e5138aaf013f713b261699b137883265896d39d (patch)
treefdf0aeeaee0e13eb2ec33105f06c5087db42c69a /plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/diff
parentba189483c4ef16ae3fb86d92db0b265d685792c9 (diff)
downloadorg.eclipse.emf.compare-0e5138aaf013f713b261699b137883265896d39d.tar.gz
org.eclipse.emf.compare-0e5138aaf013f713b261699b137883265896d39d.tar.xz
org.eclipse.emf.compare-0e5138aaf013f713b261699b137883265896d39d.zip
Fix chocolate commit
Diffstat (limited to 'plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/diff')
-rw-r--r--plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/diff/ChangeModelBridge.java114
-rw-r--r--plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/diff/ChangeModelBridgeTests.java131
2 files changed, 0 insertions, 245 deletions
diff --git a/plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/diff/ChangeModelBridge.java b/plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/diff/ChangeModelBridge.java
deleted file mode 100644
index 86fc8727c..000000000
--- a/plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/diff/ChangeModelBridge.java
+++ /dev/null
@@ -1,114 +0,0 @@
-package org.eclipse.emf.compare.tests.diff;
-
-import com.google.common.collect.Lists;
-
-import java.util.List;
-
-import org.eclipse.emf.common.notify.Notification;
-import org.eclipse.emf.common.notify.Notifier;
-import org.eclipse.emf.common.notify.impl.NotificationImpl;
-import org.eclipse.emf.compare.DifferenceKind;
-import org.eclipse.emf.compare.DifferenceSource;
-import org.eclipse.emf.compare.Match;
-import org.eclipse.emf.compare.diff.IDiffProcessor;
-import org.eclipse.emf.ecore.EAttribute;
-import org.eclipse.emf.ecore.EObject;
-import org.eclipse.emf.ecore.EReference;
-import org.eclipse.emf.ecore.EStructuralFeature;
-import org.eclipse.emf.ecore.change.ChangeDescription;
-import org.eclipse.emf.ecore.change.ChangeFactory;
-import org.eclipse.emf.ecore.change.util.ChangeRecorder;
-
-public class ChangeModelBridge implements IDiffProcessor {
-
- private ChangeRecorder recordedChanges;
-
- public ChangeModelBridge() {
- recordedChanges = new ChangeRecorder() {
-
- @Override
- protected void addAdapter(Notifier notifier) {
- /*
- * we should not install ourself on the changed objects.
- */
- }
-
- };
- recordedChanges.beginRecording(ChangeFactory.eINSTANCE.createChangeDescription(), Lists
- .newArrayList());
-
- }
-
- public void referenceChange(final Match match, final EReference reference, EObject value,
- DifferenceKind kind, DifferenceSource source) {
- someChange(match, reference, value, kind);
- }
-
- protected void someChange(final Match match, final EStructuralFeature feature, Object value,
- DifferenceKind kind) {
- int eventType = 0;
- Object oldValue = null;
- Object newValue = null;
- Object notifier = match.getLeft();
- int position = Notification.NO_INDEX;
- switch (kind) {
- case ADD:
- eventType = Notification.ADD;
- newValue = value;
- position = ((List)match.getLeft().eGet(feature)).indexOf(value);
- break;
- case CHANGE:
- if (match.getRight() == null) {
- eventType = Notification.UNSET;
- newValue = value;
- oldValue = match.getLeft().eGet(feature);
- } else {
- eventType = Notification.SET;
- newValue = value;
- oldValue = match.getRight().eGet(feature);
- }
- break;
- case DELETE:
- eventType = Notification.REMOVE;
- oldValue = value;
- break;
- case MOVE:
- eventType = Notification.MOVE;
- newValue = ((List)match.getLeft().eGet(feature)).indexOf(value);
- oldValue = ((List)match.getRight().eGet(feature)).indexOf(value);
- break;
- default:
- break;
- }
- Notification notification = new NotificationImpl(eventType, oldValue, newValue, position) {
-
- @Override
- public Object getNotifier() {
- return match.getLeft();
- }
-
- @Override
- public Object getFeature() {
- return feature;
- }
-
- @Override
- public int getFeatureID(Class<?> expectedClass) {
- return feature.getFeatureID();
- }
- };
-
- recordedChanges.notifyChanged(notification);
- }
-
- public void attributeChange(Match match, EAttribute attribute, Object value, DifferenceKind kind,
- DifferenceSource source) {
- someChange(match, attribute, value, kind);
-
- }
-
- public ChangeDescription getChanges() {
- return recordedChanges.summarize();
-
- }
-}
diff --git a/plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/diff/ChangeModelBridgeTests.java b/plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/diff/ChangeModelBridgeTests.java
deleted file mode 100644
index 11c189515..000000000
--- a/plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/diff/ChangeModelBridgeTests.java
+++ /dev/null
@@ -1,131 +0,0 @@
-package org.eclipse.emf.compare.tests.diff;
-
-import static org.junit.Assert.assertEquals;
-
-import com.google.common.collect.Lists;
-import com.google.common.collect.Maps;
-
-import java.io.IOException;
-import java.io.StringWriter;
-import java.util.Map;
-
-import org.eclipse.emf.common.util.URI;
-import org.eclipse.emf.compare.Comparison;
-import org.eclipse.emf.compare.EMFCompareConfiguration;
-import org.eclipse.emf.compare.EMFCompareMessages;
-import org.eclipse.emf.compare.diff.DefaultDiffEngine;
-import org.eclipse.emf.compare.diff.IDiffEngine;
-import org.eclipse.emf.compare.match.DefaultMatchEngine;
-import org.eclipse.emf.compare.match.IMatchEngine;
-import org.eclipse.emf.compare.scope.DefaultComparisonScope;
-import org.eclipse.emf.ecore.EClassifier;
-import org.eclipse.emf.ecore.EObject;
-import org.eclipse.emf.ecore.EPackage;
-import org.eclipse.emf.ecore.EcoreFactory;
-import org.eclipse.emf.ecore.EcorePackage;
-import org.eclipse.emf.ecore.change.ChangeDescription;
-import org.eclipse.emf.ecore.change.util.ChangeRecorder;
-import org.eclipse.emf.ecore.resource.Resource;
-import org.eclipse.emf.ecore.util.EcoreUtil;
-import org.eclipse.emf.ecore.xmi.XMLResource;
-import org.eclipse.emf.ecore.xmi.impl.XMIResourceImpl;
-import org.junit.Before;
-import org.junit.Test;
-
-public class ChangeModelBridgeTests {
-
- ChangeModelBridge bridge;
-
- EObject v1;
-
- EObject v2;
-
- ChangeRecorder recorder;
-
- @Before
- public void setUp() {
- bridge = new ChangeModelBridge();
- v1 = EcoreUtil.copy(EcorePackage.eINSTANCE);
- new XMIResourceImpl(URI.createURI("http://ecore.ecore")).getContents().add(v1);
- v2 = EcoreUtil.copy(EcorePackage.eINSTANCE);
- new XMIResourceImpl(URI.createURI("http://ecore.ecore")).getContents().add(v2);
- recorder = new ChangeRecorder();
- recorder.setRecordingTransientFeatures(false);
- recorder.beginRecording(Lists.newArrayList(v2));
- }
-
- private String serialize(EObject root) throws IOException {
- if (root == null) {
- throw new NullPointerException(EMFCompareMessages.getString("ModelUtils.NullSaveRoot")); //$NON-NLS-1$
- }
-
- // Copies the root to avoid modifying it
- final EObject copyRoot = EcoreUtil.copy(root);
- attachResource(URI.createFileURI("resource.xml"), copyRoot); //$NON-NLS-1$
- final StringWriter writer = new StringWriter();
- final Map<String, String> options = Maps.newHashMap();
- options.put(XMLResource.OPTION_ENCODING, "utf-8");
- // Should not throw ClassCast since uri calls for an xml resource
- ((XMLResource)copyRoot.eResource()).save(writer, options);
- final String result = writer.toString();
- writer.flush();
- return result;
- }
-
- public static Resource attachResource(URI resourceURI, EObject root) {
- if (root == null) {
- throw new NullPointerException(EMFCompareMessages.getString("ModelUtils.NullRoot")); //$NON-NLS-1$
- }
-
- final Resource newResource = new XMIResourceImpl(resourceURI);
- newResource.getContents().add(root);
- return newResource;
- }
-
- @Test
- public void rename() throws Exception {
- ((EPackage)v2).setName("new name");
- assertEMFCompareFindTheDifferences();
- }
-
- @Test
- public void reorder() throws Exception {
- ((EPackage)v2).getEClassifiers().move(3, 4);
- assertEMFCompareFindTheDifferences();
- }
-
- @Test
- public void remove() throws Exception {
- EcoreUtil.remove(((EPackage)v2).getEClassifiers().get(0));
- assertEMFCompareFindTheDifferences();
- }
-
- @Test
- public void delete() throws Exception {
- EcoreUtil.delete(((EPackage)v2).getEClassifiers().get(0));
- assertEMFCompareFindTheDifferences();
- }
-
- @Test
- public void addNew() throws Exception {
- EClassifier newClas = EcoreFactory.eINSTANCE.createEClass();
- newClas.setName("Added class");
- ((EPackage)v2).getEClassifiers().add(newClas);
- assertEMFCompareFindTheDifferences();
- }
-
- protected void assertEMFCompareFindTheDifferences() throws IOException {
- final IMatchEngine matchEngine = new DefaultMatchEngine();
- Comparison comparison = matchEngine.match(new DefaultComparisonScope(v1, v2, null),
- EMFCompareConfiguration.builder().build());
-
- // TODO allow extension of the default diff engine
- final IDiffEngine diffEngine = new DefaultDiffEngine(bridge);
- diffEngine.diff(comparison);
-
- ChangeDescription inferedChanges = bridge.getChanges();
- ChangeDescription capturedChanges = recorder.summarize();
- capturedChanges.applyAndReverse();
- assertEquals(serialize(capturedChanges), serialize(inferedChanges));
- }
-}

Back to the top