Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: e62293e97c78a19a93f0e58678199ab85a12d7a9 (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
/*******************************************************************************
 * 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.m2t.xtend.templates

import java.util.ArrayList
import java.util.List
import org.eclipse.uml2.uml.Class
import org.eclipse.uml2.uml.Model
import org.eclipse.uml2.uml.Package
import javax.inject.Inject

/**
 * The main entry-point rule for the model-to-text transformation that generates the test code
 * from a UML-UTP model describing the diagram test cases.
 */
class PapyrusDiagramCanonicalTests {
    @Inject extension TemplateQueries
    @Inject extension CodegenContext
    
    @Inject AllPackageTestsTemplate allPackageTests
    @Inject AppearanceTestTemplate appearanceTests
    @Inject DirectEditTestTemplate directEditTests
    @Inject DeleteTestTemplate deleteTests
    @Inject DropTestTemplate dropTests
    @Inject TestChildLabelNodeTemplate childLabelNodeTests
    @Inject TestLinkTemplate linkTests
    @Inject TestNodeTemplate nodeTests
    @Inject SynchronizationTestTemplate synchronizationTests
	
	def generate(Model model) {
		var List<String> suiteClasses = new ArrayList<String>
		for (Package subpackage : model.ownedElements.filter(Package)){
			val allTestClasses = subpackage.allOwnedElements.filter(Class)
				.filter[getAppliedStereotype("utp::TestContext") != null]
				.filter[!ownedAttributes.empty]
				.filter[hasTestCases]
				
		    if (!allTestClasses.empty) {
                for (Class clazz : allTestClasses) {

                    // Invoke the proper template for the class
                    val superClass = clazz.generals.head as Class

                    createFile(clazz) [
                        switch superClass.name {
                            case "AbstractCreateNodeFromPaletteTest": nodeTests.generate(clazz)
                            case "AbstractCreateLinkFromPaletteTest": linkTests.generate(clazz)
                            case "AbstractCreateChildLabelNodeFromPaletteTest": childLabelNodeTests.generate(clazz)
                            case "AbstractCreateLinkOwnedBySourceFromPaletteTest": linkTests.generate(clazz)
                            case "AbstractAppearanceNodeTest": appearanceTests.generate(clazz)
                            case "AbstractDropNodeTest": dropTests.generate(clazz)
                            case "AbstractDeleteNodeTest": deleteTests.generate(clazz)
                            case "AbstractEditableNodeTest": directEditTests.generate(clazz)
                            case "AbstractSynchronizationTest",
                            case "AbstractCSSSynchronizationTest" : synchronizationTests.generate(clazz)
                            default: throw new RuntimeException("Type of test not recognized: " + superClass.name)
                        }
                    ]
                }
                var className = generatePackageTestSuiteClass(subpackage, allTestClasses)
                suiteClasses.add(className);
            }
		}
		generateAllTestSuiteClass(model, suiteClasses)
	}
	
	def generateAllTestSuiteClass(Package model, List<String> testSuiteNames) {
	    val className = "AllGenTests"
		createClass(model, className) [
            allPackageTests.generate(className, model.name, testSuiteNames);
        ]
	}
	
	def generatePackageTestSuiteClass(Package package_, Iterable<Class> allTestClasses) {
	    val packageName = package_.name
		val className = "All" + packageName.substring(packageName.lastIndexOf('.') + 1).toFirstUpper + "Tests"
		createClass(package_, className) [
            allPackageTests.generate(className, packageName, allTestClasses.toList.map[name]);
        ]
        
        packageName + '.' + className
	}
}

Back to the top