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 package name.angoca.zemucan.interfaze;
30
31 import name.angoca.zemucan.AbstractZemucanException;
32 import name.angoca.zemucan.ParameterNullException;
33 import name.angoca.zemucan.core.lexical.impl.ImplementationLexicalAnalyzer;
34 import name.angoca.zemucan.grammarReader.api.GrammarReaderController;
35 import name.angoca.zemucan.interfaze.model.ReturnOptions;
36 import name.angoca.zemucan.tools.Constants;
37 import name.angoca.zemucan.tools.configurator.Configurator;
38 import name.angoca.zemucan.tools.test.RandomTestRunner;
39
40 import org.junit.AfterClass;
41 import org.junit.Assert;
42 import org.junit.BeforeClass;
43 import org.junit.Test;
44 import org.junit.runner.RunWith;
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 @RunWith(RandomTestRunner.class)
82 public final class InterfaceCoreTest {
83
84
85
86
87
88
89 @BeforeClass
90 public static void setUpBeforeClass() throws AbstractZemucanException {
91 System.setProperty(Constants.ZEMUCAN_CONF_XML_PROPERTY,
92 "sa_conf-test.xml");
93 Configurator.getInstance().setProperty(
94 Constants.GRAMMAR_READER_NAME_PROPERTY,
95 Configurator.GRAMMAR_READER_NAME_VALUE);
96 Configurator.getInstance()
97 .setProperty(Constants.GRAMMAR_FILE_DESCRIPTORS_PROPERTY,
98 "grammar-test.xml");
99
100
101 ImplementationLexicalAnalyzer.getInstance();
102 }
103
104
105
106
107 @AfterClass
108 public static void tearDownAfterClass() {
109
110 ImplementationLexicalAnalyzer.destroyInstance();
111
112
113 Configurator.destroyInstance();
114 GrammarReaderController.destroyInstance();
115 System.clearProperty(Constants.ZEMUCAN_CONF_XML_PROPERTY);
116 }
117
118
119
120
121 public InterfaceCoreTest() {
122
123 }
124
125
126
127
128
129
130
131 @Test
132 public void testAnalyzeExit() throws AbstractZemucanException {
133 final String phrase = "exit";
134
135 final String phraseOut = "exit";
136
137 final String[] phrases = {};
138
139 final String[] options = {};
140
141 final ReturnOptions actual = InterfaceCore.analyzePhrase(phrase);
142
143 final ReturnOptions expected = new ReturnOptions(phraseOut, phrases,
144 options);
145
146 Assert.assertEquals("Phrases and options for 'exit'",
147 expected, actual);
148 }
149
150
151
152
153
154
155
156 @Test
157 public void testAnalyzeNull() throws AbstractZemucanException {
158 final String phrase = null;
159
160 Exception e = null;
161 try {
162 InterfaceCore.analyzePhrase(phrase);
163 } catch (final Exception exception) {
164 e = exception;
165 }
166 Assert.assertTrue("ParameterNullException",
167 e instanceof ParameterNullException);
168 }
169
170
171
172
173
174
175
176 @Test
177 public void testAnalyzePhraseComplete1() throws AbstractZemucanException {
178 final String phraseActual = "create tab";
179 final String phraseExpected = "create table";
180
181 final String[] phrases = { "tablespace" };
182 final String[] options = {};
183
184 final ReturnOptions actual = InterfaceCore.analyzePhrase(phraseActual);
185 final ReturnOptions expected = new ReturnOptions(phraseExpected,
186 phrases, options);
187
188 Assert.assertEquals("Phrases for 'create tab'", expected,
189 actual);
190 }
191
192
193
194
195
196
197
198 @Test
199 public void testAnalyzePhraseComplete2() throws AbstractZemucanException {
200 final String phraseActual = "crea";
201 final String phraseExpected = "create";
202
203 final String[] options = {};
204
205 final ReturnOptions actual = InterfaceCore.analyzePhrase(phraseActual);
206 final ReturnOptions expected = new ReturnOptions(phraseExpected,
207 new String[] {}, options);
208
209 Assert.assertEquals("Phrase for 'crea'", expected, actual);
210 }
211
212
213
214
215
216
217
218 @Test
219 public void testAnalyzePhraseOptions1() throws AbstractZemucanException {
220 final String phraseIn = "create table";
221
222 final String phraseOut = "create table";
223
224 final String[] phrases = { "tablespace" };
225
226 final String[] options = { "<tableName>" };
227
228 final ReturnOptions actual = InterfaceCore.analyzePhrase(phraseIn);
229 final ReturnOptions expected = new ReturnOptions(phraseOut, phrases,
230 options);
231
232 Assert.assertEquals("Phrases and options for 'create table'",
233 expected, actual);
234 }
235 }