Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: f01e24771ab9253850ced888ec7ed73ac2a63d54 (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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
/*****************************************************************************
 * Copyright (c) 2013, 2017 CEA LIST and others.
 *
 * 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:
 *   CEA LIST - Initial API and implementation
 *   Eike Stepper (CEA) - bug 466520
 *****************************************************************************/
package org.eclipse.papyrus.cdo.internal.core.importer.tests;

import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;

import java.util.Set;

import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.core.runtime.Path;
import org.eclipse.emf.common.util.Diagnostic;
import org.eclipse.emf.common.util.URI;
import org.eclipse.papyrus.cdo.core.importer.IModelImportMapping;
import org.eclipse.papyrus.cdo.core.importer.IModelTransferConfiguration;
import org.eclipse.papyrus.cdo.core.importer.IModelTransferNode;
import org.eclipse.papyrus.cdo.core.importer.IModelTransferOperation;
import org.eclipse.papyrus.cdo.core.importer.ModelTransferMappingListenerAdapter;
import org.eclipse.papyrus.cdo.core.tests.AbstractPapyrusCDOTest;
import org.eclipse.papyrus.cdo.core.tests.TestProject;
import org.junit.After;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;

import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Sets;

/**
 * This is the ManyToOneModelImportMappingTest type. Enjoy.
 */
public class ManyToOneModelImportMappingTest extends AbstractPapyrusCDOTest {

	private IModelTransferConfiguration config;

	private IModelImportMapping fixture;

	@Rule
	public TestProject hasDependencies = new TestProject("has_dependencies");

	@Rule
	public TestProject hasDependents = new TestProject("has_dependents");

	public ManyToOneModelImportMappingTest() {
		super();
	}

	@Test
	public void testDefaultMappings() {
		URI uri1 = hasDependencies.getResourceURI("model.di");
		URI uri2 = hasDependents.getResourceURI("Datatypes.di");

		config.addModelToTransfer(uri1);
		config.addModelToTransfer(uri2);

		assertThat(fixture.getMapping(getNode(uri1)), is((IPath) new Path("/has_dependencies/model.di")));
		assertThat(fixture.getMapping(getNode(uri2)), is((IPath) new Path("/has_dependencies/model.di")));
	}

	@Test
	public void testMappings() {
		URI uri1 = hasDependencies.getResourceURI("model.di");
		URI uri2 = hasDependents.getResourceURI("Datatypes.di");

		config.addModelToTransfer(uri1);
		config.addModelToTransfer(uri2);

		class Test extends ModelTransferMappingListenerAdapter {

			Set<IModelTransferNode> notified = Sets.newHashSet();

			@Override
			public void modelTransferMappingChanged(IModelTransferNode node) {
				notified.add(node);
			}
		}
		Test test = new Test();
		fixture.addModelTransferMappingListener(test);

		IPath path = new Path("/myfolder/MyModel.di");
		fixture.mapTo(getNode(uri1), path);

		assertThat(test.notified, is((Set<IModelTransferNode>) ImmutableSet.of(getNode(uri1), getNode(uri2))));

		assertThat(fixture.getMapping(getNode(uri1)), is(path));
		assertThat(fixture.getMapping(getNode(uri2)), is(path));
	}

	//
	// Test framework
	//

	@Before
	public void createTestFixture() {
		config = IModelTransferConfiguration.Factory.IMPORT.create(new IModelTransferOperation.Context() {

			public Diagnostic run(IModelTransferOperation operation) {
				operation.run(new NullProgressMonitor());
				return Diagnostic.OK_INSTANCE;
			}
		}, null);

		fixture = IModelImportMapping.Factory.MANY_TO_ONE.create(config);
		fixture.setCheckout(getCheckout());
	}

	@After
	public void disposeTestFixture() {
		fixture = null;

		config.dispose();
		config = null;
	}

	IModelTransferNode getNode(URI uri) {
		IModelTransferNode result = null;

		for (IModelTransferNode next : config.getModelsToTransfer()) {
			if (next.getPrimaryResourceURI().equals(uri)) {
				result = next;
				break;
			}
		}

		return result;
	}
}

Back to the top