Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: f24b05e7ae6dda0522587ca3cda8468af16b61e8 (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
/*******************************************************************************
 * Copyright (c) 2014, 2015 CEA LIST, 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 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
 *   Christian W. Damus - bug 464647
 *     
 ******************************************************************************/
package org.eclipse.papyrus.tests.framework.gmfgenuml2utp;


import java.util.Collection;
import java.util.Collections;
import java.util.List;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.ecore.resource.ResourceSet;
import org.eclipse.emf.mwe.core.WorkflowContext;
import org.eclipse.emf.mwe.core.issues.Issues;
import org.eclipse.emf.mwe.core.monitor.ProgressMonitor;
import org.eclipse.emf.mwe.utils.AbstractEMFWorkflowComponent;
import org.eclipse.papyrus.tests.framework.exceptions.TestExceptions;
import org.eclipse.papyrus.tests.framework.gmfgen2uml.GMFGen2UMLComponent;
import org.eclipse.uml2.uml.Model;
import org.eclipse.uml2.uml.Profile;
import org.eclipse.uml2.uml.UMLPackage;
import org.eclipse.uml2.uml.resource.UMLResource;
import org.eclipse.xtext.xbase.lib.Functions.Function3;

import com.google.common.collect.ImmutableList;
import com.google.common.collect.Iterables;
import com.google.inject.Guice;
import com.google.inject.Injector;

/**
 * A workflow component that configures and runs a transformation of the UML representation of a
 * GMFGen model to a UML-UTP model describing the tests to be generated for that diagram.
 * 
 * @see GMFGen2UMLComponent
 */
public class GMFGen2UTPComponent extends AbstractEMFWorkflowComponent {

	private Log log = LogFactory.getLog(getClass());

	private String metamodelSlot;

	private String frameworkBaseSlot;

	private String utpSlot;

	private String outputSlot;

	private Function3<Model, Model, Profile, GMFGen2UTPModule> utpModule;

	public GMFGen2UTPComponent() {
		super();
	}

	public String getMetamodelSlot() {
		return metamodelSlot;
	}

	public void setMetamodelSlot(String metamodelSlot) {
		this.metamodelSlot = metamodelSlot;
	}

	public String getFrameworkBaseSlot() {
		return frameworkBaseSlot;
	}

	public void setFrameworkBaseSlot(String frameworkBaseSlot) {
		this.frameworkBaseSlot = frameworkBaseSlot;
	}

	public String getUtpSlot() {
		return utpSlot;
	}

	public void setUtpSlot(String utpSlot) {
		this.utpSlot = utpSlot;
	}

	public String getOutputSlot() {
		return outputSlot;
	}

	public void setOutputSlot(String outputSlot) {
		this.outputSlot = outputSlot;
	}

	public Function3<Model, Model, Profile, GMFGen2UTPModule> getUtpModule() {
		return utpModule;
	}

	public void setUtpModule(Function3<Model, Model, Profile, GMFGen2UTPModule> utpModule) {
		this.utpModule = utpModule;
	}

	protected GMFGen2UTPModule createGMFGen2UTPModule(WorkflowContext ctx, Collection<TestExceptions> testExceptions) {
		TestExceptionManager excmgr = new TestExceptionManager(testExceptions);

		GMFGen2UTPModule result = getUtpModule().apply(
				(Model) ctx.get(getMetamodelSlot()),
				(Model) ctx.get(getFrameworkBaseSlot()),
				(Profile) ctx.get(getUtpSlot()));
		result.setTestExceptionManager(excmgr);

		return result;
	}

	@Override
	protected void invokeInternal(WorkflowContext ctx, ProgressMonitor monitor,
			Issues issues) {

		log.info("Transforming GMFGen UML model to UTP test model ...");
		Object modelSlotContent = ctx.get(getModelSlot());
		Model model = null;
		Collection<TestExceptions> testExceptions = Collections.emptyList();
		if (modelSlotContent instanceof Model) {
			model = (Model) modelSlotContent;
		} else if (modelSlotContent instanceof List) {
			List<?> slotContentList = (List<?>) modelSlotContent;
			model = Iterables.getFirst(Iterables.filter(slotContentList, Model.class), null);
			testExceptions = ImmutableList.copyOf(Iterables.filter(slotContentList, TestExceptions.class));
		}
		if ((model == null) || !(model instanceof Model)) {
			log.error("The input model for the transformation was not loaded!");
			return;
		}

		GMFGen2UTPModule module = createGMFGen2UTPModule(ctx, testExceptions);
		module.initEditPartDefaults(model, new TransformationUtilities());
		Injector injector = Guice.createInjector(module);

		CanonicalTests transformation = injector.getInstance(CanonicalTests.class);

		// Need a resource set context for working with static profiles
		ResourceSet rset = getResourceSet();
		rset.getResourceFactoryRegistry().getContentTypeToFactoryMap().put(UMLPackage.eCONTENT_TYPE, UMLResource.Factory.INSTANCE);
		Resource resource = rset.createResource(URI.createURI("tmp:uml"), UMLPackage.eCONTENT_TYPE);

		Model uml = transformation.toUTPModel(model, resource);
		ctx.set(getOutputSlot(), uml);
		log.info("The transformation successfully created Model " + uml.getLabel());
	}

}

Back to the top