Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 19630cf7f068edb9b98187847d2a035763c14ad8 (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
/*****************************************************************************
 * Copyright (c) 2016, 2019 Christian W. Damus and others.
 *
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License 2.0
 * which accompanies this distribution, and is available at
 * https://www.eclipse.org/legal/epl-2.0/
 *
 * SPDX-License-Identifier: EPL-2.0
 *
 * Contributors:
 *   Christian W. Damus - Initial API and implementation
 *   Ansgar Radermacher (CEA LIST) - common test model with UMLCopyTestME (context bug 541686)
 *
 *****************************************************************************/

package org.eclipse.papyrus.uml.tools.tests.tests;

import static org.hamcrest.CoreMatchers.both;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.notNullValue;
import static org.hamcrest.MatcherAssert.assertThat;

import java.util.Arrays;

import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.resource.ResourceSet;
import org.eclipse.emf.ecore.util.EcoreUtil;
import org.eclipse.papyrus.infra.core.clipboard.ICopierFactory;
import org.eclipse.papyrus.junit.utils.rules.HouseKeeper;
import org.eclipse.uml2.uml.Class;
import org.eclipse.uml2.uml.Interface;
import org.eclipse.uml2.uml.InterfaceRealization;
import org.eclipse.uml2.uml.Package;
import org.eclipse.uml2.uml.UMLPackage;
import org.eclipse.uml2.uml.util.UMLUtil;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;

/**
 * Test cases for the UML-specific tuning of the {@link EcoreUtil.Copier}
 * used by the Papyrus copy/paste infrastructure.
 */
public class UMLCopyTest {

	@Rule
	public final HouseKeeper houseKeeper = new HouseKeeper();

	private ResourceSet rset;

	private Package model;
	private Interface foo;
	private Class bar;
	private InterfaceRealization rlz;

	/**
	 * Initializes me.
	 */
	public UMLCopyTest() {
		super();
	}

	@Test
	public void copyingInterfaceRealizationDoesNotCorruptTheModel() {
		EcoreUtil.Copier copier = ICopierFactory.getInstance(rset).get();

		copier.copyAll(Arrays.asList(foo, bar));
		copier.copyReferences();

		InterfaceRealization copy = (InterfaceRealization) copier.get(rlz);

		// Verify the copy
		assertThat(copy.getImplementingClassifier(), both(notNullValue()).and(is(copier.get(bar))));
		assertThat(copy.getContract(), both(notNullValue()).and(is(copier.get(foo))));

		// Verify the non-corruption
		assertThat(copy.getClients().size(), is(1));
	}

	//
	// Nested types
	//

	@Before
	public void initFixture() {
		rset = houseKeeper.createResourceSet();

		model = UMLUtil.load(rset,
				URI.createPlatformPluginURI("org.eclipse.papyrus.uml.tools.tests/resources/uml/copy.uml", true),
				UMLPackage.Literals.PACKAGE);
		Package pkg = model.getNestedPackage("pkg");
		foo = (Interface) pkg.getOwnedType("Foo");
		bar = (Class) pkg.getOwnedType("Bar");
		rlz = bar.getInterfaceRealization(null, foo);
	}
}

Back to the top