Skip to main content
summaryrefslogtreecommitdiffstats
blob: 4b60f3f845926d30a390a3d269b4ea94a61015ee (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
/*******************************************************************************
 * Copyright (c) 2010 Technical University of Denmark.
 * All rights reserved. This program and the accompanying materials 
 * are made available under the terms of the Eclipse Public License v1.0 
 * which accompanies this distribution, and is available at 
 * http://www.eclipse.org/legal/epl-v10.html 
 * 
 * Contributors:
 *    Patrick Koenemann, DTU Informatics - initial API and implementation
 *******************************************************************************/
package org.eclipse.emf.compare.mpatch.test.junit;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;

import org.eclipse.emf.compare.mpatch.MPatchModel;
import org.eclipse.emf.compare.mpatch.apply.generic.util.InternalReferencesTransformation;
import org.eclipse.emf.compare.mpatch.apply.generic.util.MPatchDependencyTransformation;
import org.eclipse.emf.compare.mpatch.common.util.ExtensionManager;
import org.eclipse.emf.compare.mpatch.common.util.MPatchConstants;
import org.eclipse.emf.compare.mpatch.extension.IModelDescriptorCreator;
import org.eclipse.emf.compare.mpatch.extension.ISymbolicReferenceCreator;
import org.eclipse.emf.compare.mpatch.extension.MPatchApplicationResult;
import org.eclipse.emf.compare.mpatch.extension.ResolvedSymbolicReferences;
import org.eclipse.emf.compare.mpatch.test.util.CompareTestHelper;
import org.eclipse.emf.compare.mpatch.test.util.TestConstants;
import org.eclipse.emf.compare.mpatch.transform.util.GeneralizeTransformation;
import org.eclipse.emf.compare.mpatch.transform.util.GroupingTransformation;
import org.eclipse.emf.ecore.EPackage;
import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
import org.junit.Test;

/**
 * Testing the library example:
 * <ol>
 * <li> Compare library.ecore and library_karl.ecore with EMF Compare
 * <li> Create MPatch (condition-based only)
 * <li> Perform all available transformations
 * <li> Apply all changes to library_eve.ecore
 * </ol>
 * 
 * @author Patrick Koenemann (pk@imm.dtu.dk)
 */
public class LibraryExampleTest {

	/**
	 * Test description: {@link LibraryExampleTest}
	 */
	@Test
	public void testLibraryExample() {
		// get creators
		final ISymbolicReferenceCreator symrefCreator = ExtensionManager.getAllSymbolicReferenceCreators().get(
				"Condition-based");
		final IModelDescriptorCreator descriptorCreator = ExtensionManager.getAllModelDescriptorCreators().get(
				"Default");
		final String info = "symrefCreator: " + symrefCreator.getLabel() + ", descriptorCreator: "
				+ descriptorCreator.getLabel();

		// create mpatch
		final MPatchModel mpatch = CompareTestHelper.getMPatchFromUris(TestConstants.LIBRARY_URI2,
				TestConstants.LIBRARY_URI1, symrefCreator, descriptorCreator);

		doTransformations(mpatch);

		// resolve references to other model
		final EPackage applyModel = (EPackage) CompareTestHelper.loadModel(TestConstants.LIBRARY_URI3,
				new ResourceSetImpl()).get(0);
		final ResolvedSymbolicReferences resolvedReferences = CompareTestHelper.resolveReferences(mpatch, applyModel, info);

		// apply differences
		final MPatchApplicationResult result = TestConstants.DIFF_APPLIER.applyMPatch(resolvedReferences, true);

		// check application status
		assertTrue("Some changes failed to apply: " + result.failed, result.failed.isEmpty());
		assertTrue("Cross reference restoring failed for: " + result.crossReferences, result.crossReferences.isEmpty());
		assertEquals("Application result was not successful!", MPatchApplicationResult.ApplicationStatus.SUCCESSFUL,
				result.status);
	}

	private void doTransformations(MPatchModel mpatch) {
		final int groups = GroupingTransformation.group(mpatch);
		assertNull(MPatchConstants.MPATCH_SHORT_NAME + " is not valid!", CompareTestHelper.validateMPatch(mpatch));
		assertEquals("Groups were not created correctly!", 2, groups);
		final int deps = MPatchDependencyTransformation.calculateDependencies(mpatch);
		assertNull(MPatchConstants.MPATCH_SHORT_NAME + " is not valid!", CompareTestHelper.validateMPatch(mpatch));
		assertEquals("Dependencies were not calculated correctly!", 4, deps);
		final int refs = InternalReferencesTransformation.createInternalReferences(mpatch);
		assertNull(MPatchConstants.MPATCH_SHORT_NAME + " is not valid!", CompareTestHelper.validateMPatch(mpatch));
		assertEquals("Internal references were not created correctly!", 6, refs);
		final int card = GeneralizeTransformation.unboundSymbolicReferences(mpatch);
		assertNull(MPatchConstants.MPATCH_SHORT_NAME + " is not valid!", CompareTestHelper.validateMPatch(mpatch));
		assertEquals("Cardinality weakening was not performed correctly!", 16, card);
		final int str = GeneralizeTransformation.expandScope(mpatch);
		assertNull(MPatchConstants.MPATCH_SHORT_NAME + " is not valid!", CompareTestHelper.validateMPatch(mpatch));
		assertTrue("String weakening was not performed correctly!", str >= 12);
	}
}

Back to the top