/
EmfParsleyDslSmokeTest.xtend
155 lines (134 loc) · 3.25 KB
/
EmfParsleyDslSmokeTest.xtend
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
/*******************************************************************************
* Copyright (c) 2013 RCP Vision (http://www.rcp-vision.com) 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:
* Lorenzo Bettini - initial API and implementation
*******************************************************************************/
package org.eclipse.emf.parsley.dsl.tests
import com.google.inject.Inject
import org.apache.log4j.ConsoleAppender
import org.apache.log4j.Level
import org.apache.log4j.Logger
import org.apache.log4j.spi.LoggingEvent
import org.eclipse.emf.parsley.dsl.model.Model
import org.eclipse.xtext.junit4.InjectWith
import org.eclipse.xtext.junit4.XtextRunner
import org.eclipse.xtext.junit4.util.ParseHelper
import org.eclipse.xtext.junit4.validation.ValidationTestHelper
import org.eclipse.xtext.xbase.jvmmodel.JvmModelAssociator
import org.junit.After
import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith
import static org.junit.Assert.*
@RunWith(XtextRunner)
@InjectWith(EmfParsleyDslInjectorProvider)
class EmfParsleyDslSmokeTest {
@Inject extension ParseHelper<Model>
@Inject extension ValidationTestHelper
private final static Logger LOG = Logger.getLogger(JvmModelAssociator);
/**
* JvmModelAssociator does not throw exceptions but logs possible
* errors; we use this class to record possible error events
*/
static class LogListener extends ConsoleAppender {
val public events = newArrayList()
override doAppend(LoggingEvent event) {
if (event.getLevel == Level.ERROR) {
events += event
}
}
}
var LogListener logListener
@Before
def void createAppender() {
logListener = new LogListener => [
LOG.addAppender(it)
]
}
@After
def void removeAppender() {
LOG.removeAppender(logListener)
}
@Test
def void testModuleWithNoName() {
'''
module
'''.assertNoException
}
@Test
def void testExtendsWithoutType() {
'''
module my.empty extends
'''.assertNoException
}
@Test
def void testTypeBindingWithNoType() {
'''
module my.empty {
bindings {
type
}
}
'''.assertNoException
}
@Test
def void testProviderBindingWithNoType() {
'''
module my.empty {
bindings {
provide
}
}
'''.assertNoException
}
@Test
def void testValueBindingWithNoType() {
'''
module my.empty {
bindings {
value
}
}
'''.assertNoException
}
@Test
def void testValueBindingWithUnknownType() {
'''
module my.empty {
bindings {
value Foo TableColumnWeights
}
}
'''.assertNoException
}
@Test
def void testResourceManagerInitializeWithNoBody() {
'''
module my.empty {
resourceManager {
initializeResource
}
}
'''.assertNoException
}
@Test
def void testResourceManagerSaveWithNoBody() {
'''
module my.empty {
resourceManager {
saveSave
}
}
'''.assertNoException
}
def private assertNoException(CharSequence s) {
s.parse.validate
// there must be no error in the log either
assertTrue("Some error was reported in the LOG", logListener.events.empty)
}
}