Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 75e274bf3987a9ad833c97bd46ccaa7783344c19 (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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
/*******************************************************************************
 * Copyright (c) 2008 Mia-Software.
 * 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:
 *    Gabriel Barbier (Mia-Software) - initial API and implementation
 *    Fabien Giquel (Mia-Software) - Bug 339720 : MoDisco Discoverers (infra + techno) API clean
 *    Nicolas Bros (Mia-Software) - Bug 335003 - [Discoverer] : Existing Discoverers Refactoring based on new framework
 *    Nicolas Bros (Mia-Software) - Bug 378965 - Tests disabled due to EMF Compare API change
 *******************************************************************************/

package org.eclipse.modisco.kdm.uml2converter.tests;

import java.io.IOException;

import junit.framework.Assert;

import org.eclipse.emf.common.util.DiagnosticChain;
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.ecore.util.Diagnostician;
import org.eclipse.gmt.modisco.infra.common.core.internal.utils.ModelUtils;
import org.eclipse.m2m.atl.core.ATLCoreException;
import org.eclipse.modisco.common.tests.TestModelUtils;
import org.eclipse.modisco.kdm.uml2converter.internal.KdmToUmlConverter;
import org.junit.After;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;

public class KdmToUml2ConverterTest {
	// To be able to export reference model after a change in atl transformation
	private final boolean export = false;

	private final String referenceFolderPath = "/reference/"; //$NON-NLS-1$
	private final String sourceFolderPath = "/source/"; //$NON-NLS-1$
	private final String modelName = "test001"; //$NON-NLS-1$

	private final String umlModelExtension = ".uml"; //$NON-NLS-1$
	private final String kdmModelExtension = ".kdm"; //$NON-NLS-1$

	private AtlProjectFactory projectFactory;

	/**
	 * @throws java.lang.Exception
	 */
	@Before
	public void setUp() throws Exception {
		this.projectFactory = new AtlProjectFactory(this.getClass().getSimpleName());
	}

	/**
	 * @throws java.lang.Exception
	 */
	@After
	public void tearDown() throws Exception {
		if (this.projectFactory != null) {
			this.projectFactory.dispose();
		}
	}

	@Test
	@Ignore
	// @Ignore : FIXME TestModelUtils#compareModels must be rewritten for EMF Compare 2.0
	public void testKdmToUmlConverter() throws Exception {
		/*
		 * prepare the target ... we have to create an empty project into the
		 * workspace with a real uri for atl extraction.
		 */
		final String outputPath = this.projectFactory.getProject().getName() + "/BasicConversion"//$NON-NLS-1$
				+ this.umlModelExtension;
		final URI outputUri = URI.createPlatformResourceURI(outputPath, false);
		Assert.assertNotNull(outputUri);
		basicKdmToUmlConverter(outputUri);
	}

	private final void basicKdmToUmlConverter(final URI outputUri) throws Exception {
		/*
		 * first, create an empty project into the workspace, then, convert the
		 * kdm model into uml model using converter, finally, compare the result
		 * with a reference uml model.
		 */
		/*
		 * load the source model ...
		 */
		final String sourcePath = "/" + Activator.PLUGIN_ID + this.sourceFolderPath + this.modelName //$NON-NLS-1$
				+ this.kdmModelExtension;
		final URI sourceUri = URI.createPlatformPluginURI(sourcePath, true);
		/*
		 * initialize the converter ...
		 */

		Resource output = basicConvertKDMModel(sourceUri, outputUri);

		/*
		 * Because everything looks great, well we have to test model content.
		 * In details we will compare current resource with a reference (checked
		 * manually)
		 */
		final String referencePath = "/" + Activator.PLUGIN_ID + this.referenceFolderPath //$NON-NLS-1$
				+ this.modelName + this.umlModelExtension;
		final URI referenceUri = URI.createPlatformPluginURI(referencePath, true);
		Assert.assertNotNull(referenceUri);
		final Resource referenceModel = ModelUtils.loadModel(referenceUri);
		Assert.assertNotNull(referenceModel);

		// bug 327643 workaround : .uml reload from xmi rather than direct
		// atl output use
		if (output.getResourceSet() != null) {
			output.getResourceSet().getResources().remove(output);
		}
		output = ModelUtils.loadModel(output.getURI());

		Assert.assertTrue(TestModelUtils.compareModels(output, referenceModel, true));

		if (this.export) {
			output.setURI(URI.createFileURI("c:/referenceModel" + this.umlModelExtension)); //$NON-NLS-1$
			output.save(null);
		}
	}

	// TODO this tests fails
	// @Test
	// public void testValidationOfConvertedUmlModel() {
	// /*
	// * prepare the target ... we have to create an empty project into the
	// * workspace with a real uri for atl extraction.
	// */
	//		final String outputPath = projectFactory.getProject().getName() + "/ConvertedValidated" //$NON-NLS-1$
	// + this.umlModelExtension;
	// final URI outputUri = URI.createPlatformResourceURI(outputPath, false);
	// Assert.assertNotNull(outputUri);
	//
	// this.basicKdmToUmlConverter(outputUri);
	// Resource outputModel;
	// try {
	// outputModel = ModelUtils.load(outputUri);
	// Assert.assertNotNull(outputModel);
	// Diagnostician diagnostician = new Diagnostician();
	// for (EObject eObject : outputModel.getContents()) {
	// boolean result = diagnostician.validate(eObject, (DiagnosticChain) null);
	// Assert.assertTrue(result);
	// }
	// } catch (IOException e) {
	// Assert.fail(e.getMessage());
	// }
	//
	// }

	@Test
	@Ignore
	// @Ignore : FIXME TestModelUtils#compareModels must be rewritten for EMF Compare 2.0
	public void testKdmSourceToUmlConverter_bug315355() throws Exception {
		/*
		 * prepare the target ... we have to create an empty project into the
		 * workspace with a real uri for atl extraction.
		 */
		final String outputPath = this.projectFactory.getProject().getName()
				+ "/BasicKdmSourceConversion"//$NON-NLS-1$
				+ this.umlModelExtension;
		final URI outputUri = URI.createPlatformResourceURI(outputPath, false);
		Assert.assertNotNull(outputUri);
		basicKdmSourceToUmlConverter_bug315355(outputUri);
	}

	private final void basicKdmSourceToUmlConverter_bug315355(final URI outputUri) throws Exception {
		/*
		 * first, create an empty project into the workspace, then, convert the
		 * kdm model into uml model using converter, finally, compare the result
		 * with a reference uml model.
		 */
		/*
		 * load the source model ...
		 */
		final String sourcePath = "/" + Activator.PLUGIN_ID + this.sourceFolderPath + this.modelName //$NON-NLS-1$
				+ "_Source" + this.kdmModelExtension; //$NON-NLS-1$
		final URI sourceUri = URI.createPlatformPluginURI(sourcePath, true);

		Resource output = basicConvertKDMModel(sourceUri, outputUri);

		/*
		 * Because everything looks great, well we have to test model content.
		 * In details we will compare current resource with a reference (checked
		 * manually)
		 */
		final String referencePath = "/" + Activator.PLUGIN_ID + this.referenceFolderPath //$NON-NLS-1$
				+ this.modelName + "_Source" + this.umlModelExtension; //$NON-NLS-1$
		final URI referenceUri = URI.createPlatformPluginURI(referencePath, true);
		Assert.assertNotNull(referenceUri);
		final Resource referenceModel = ModelUtils.loadModel(referenceUri);
		Assert.assertNotNull(referenceModel);

		// 327643 : temporary .uml ref copy for hudson debugging
		referenceModel.setURI(output.getURI().appendFileExtension("ref.uml"));
		referenceModel.save(null);
		// end temporary

		// 327643 : temporary .uml reload from xmi for hudson strange
		// behavior
		if (output.getResourceSet() != null) {
			output.getResourceSet().getResources().remove(output);
		}
		output = ModelUtils.loadModel(output.getURI());
		// end temporary

		Assert.assertTrue(TestModelUtils.compareModels(output, referenceModel, true));

		if (this.export) {
			output.setURI(URI.createFileURI("c:/referenceModel" + this.umlModelExtension)); //$NON-NLS-1$
			output.save(null);
		}
	}

	private Resource basicConvertKDMModel(final URI sourceUri, final URI outputUri)
			throws IOException, ATLCoreException {
		Assert.assertNotNull(sourceUri);
		final Resource sourceModel = ModelUtils.loadModel(sourceUri);
		Assert.assertNotNull(sourceModel);
		/*
		 * initialize the converter ...
		 */
		final KdmToUmlConverter converter = new KdmToUmlConverter();
		Assert.assertNotNull(converter);

		Resource[] out = converter.getUML2ModelFromKDMModel(sourceModel, false);
		Assert.assertNotNull(out);
		Assert.assertEquals(1, out.length);
		Resource output = out[0];
		Assert.assertNotNull(output);

		output.setURI(outputUri);
		output.save(null);

		return output;
	}

	@Test
	public void testValidationOfConvertedSourceUmlModel() throws Exception {

		final String outputPath = this.projectFactory.getProject().getName()
				+ "/ConvertedSourceValidated" //$NON-NLS-1$
				+ this.umlModelExtension;
		final URI outputUri = URI.createPlatformResourceURI(outputPath, false);
		Assert.assertNotNull(outputUri);

		final String sourcePath = "/" + Activator.PLUGIN_ID + this.sourceFolderPath + this.modelName //$NON-NLS-1$
				+ "_Source" + this.kdmModelExtension; //$NON-NLS-1$
		final URI sourceUri = URI.createPlatformPluginURI(sourcePath, true);

		basicConvertKDMModel(sourceUri, outputUri);

		Resource outputModel;
		outputModel = ModelUtils.loadModel(outputUri);
		Assert.assertNotNull(outputModel);
		Diagnostician diagnostician = new Diagnostician();
		for (EObject eObject : outputModel.getContents()) {
			boolean result = diagnostician.validate(eObject, (DiagnosticChain) null);
			Assert.assertTrue(result);
		}
	}

	@Test
	@Ignore
	// @Ignore : FIXME TestModelUtils#compareModels must be rewritten for EMF Compare 2.0
	public void testKdmToUmlConverter_bug318638() throws Exception {
		/*
		 * prepare the target ... we have to create an empty project into the
		 * workspace with a real uri for atl extraction.
		 */
		final String outputPath = this.projectFactory.getProject().getName() + "/BasicConversion"//$NON-NLS-1$
				+ this.umlModelExtension;
		final URI outputUri = URI.createPlatformResourceURI(outputPath, false);
		Assert.assertNotNull(outputUri);

		final String modelNameForBug = "Bug_318638";
		/*
		 * load the source model ...
		 */
		final String sourcePath = "/" + Activator.PLUGIN_ID + this.sourceFolderPath //$NON-NLS-1$
				+ modelNameForBug + this.kdmModelExtension;
		final URI sourceUri = URI.createPlatformPluginURI(sourcePath, true);
		/*
		 * initialize the converter ...
		 */

		Resource output = basicConvertKDMModel(sourceUri, outputUri);

		/*
		 * Because everything looks great, well we have to test model content.
		 * In details we will compare current resource with a reference (checked
		 * manually)
		 */
		final String referencePath = "/" + Activator.PLUGIN_ID + this.referenceFolderPath //$NON-NLS-1$
				+ modelNameForBug + this.umlModelExtension;
		final URI referenceUri = URI.createPlatformPluginURI(referencePath, true);
		Assert.assertNotNull(referenceUri);
		final Resource referenceModel = ModelUtils.loadModel(referenceUri);
		Assert.assertNotNull(referenceModel);

		// bug 327643 workaround : .uml reload from xmi rather than direct
		// atl output use
		if (output.getResourceSet() != null) {
			output.getResourceSet().getResources().remove(output);
		}
		output = ModelUtils.loadModel(output.getURI());

		Assert.assertTrue(TestModelUtils.compareModels(output, referenceModel, true));

		if (this.export) {
			output.setURI(URI.createFileURI("c:/referenceModel" + this.umlModelExtension)); //$NON-NLS-1$
			output.save(null);
		}
	}
}

Back to the top