blob: 2cbb93a086dd4326d1d73e7b6623c25c26a29142 (
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
|
/*****************************************************************************
* Copyright (c) 2014 CEA LIST.
*
*
* 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:
* Ed Seidewitz (MDS) - Initial implementation
*
*****************************************************************************/
package org.eclipse.papyrus.uml.alf.tests.generator
import java.io.File
import java.io.FileWriter
import java.io.IOException
import java.io.PrintWriter
import org.eclipse.emf.common.util.BasicDiagnostic
import org.eclipse.papyrus.uml.alf.MappingError
import org.eclipse.papyrus.uml.alf.tests.ParserTest
import org.eclipse.xtext.junit4.XtextRunner
import org.junit.BeforeClass
import org.junit.Ignore
import org.junit.Test
import org.junit.runner.RunWith
import static org.junit.Assert.*
@RunWith(XtextRunner)
class GenerationTest extends ParserTest {
static final public String ALF_DIRECTORY = System.getProperty("user.dir") + "/Alf"
static final public String UML_DIRECTORY = System.getProperty("user.dir") + "/UML"
static protected AlfGenerator generator;
static protected String umlDirectory;
@BeforeClass
static def void setUp() {
generator = new AlfGenerator()
umlDirectory = System.getProperty("uml.directory", UML_DIRECTORY)
}
@Test
@Ignore("Doesn't run on Maven - Bug 464026")
def void testGeneration() {
var failures = 0;
System.out.println("[GenerationTest] Directory " + umlDirectory + ":")
val directory = new File(umlDirectory)
for (file : directory.listFiles()) {
val name = file.name;
val l = name.length
if (name.substring(l - 4, l).equals(".uml")) {
System.out.println(name)
val resource = generator.getResource(file.path)
try {
val text = generator.generate(resource.getContents())
val output = new PrintWriter(new FileWriter(
ALF_DIRECTORY + "/" + name.substring(0, l - 4) + ".alf"
));
output.print(text);
output.close
} catch (MappingError e) {
val diagnostic = e.diagnostic
if (diagnostic != null) {
val status = BasicDiagnostic.toIStatus(diagnostic)
System.out.println(" " + status)
} else {
System.out.println(e.getMessage());
}
failures = failures + 1
} catch (IOException e) {
e.printStackTrace()
}
catch (Exception e) {
e.printStackTrace()
failures = failures + 1
}
resource.unload()
}
}
System.out.println()
assertEquals(0, failures)
}
}
|