View Javadoc

1   /*
2    * Zemucan: A Syntax Assistant for DB2
3    * Copyright (C) 2009, 2010 Andres Gomez Casanova
4    *
5    * This file is part of Zemucan.
6    *
7    * Zemucan is free software: you can redistribute it and/or modify
8    * it under the terms of the GNU Lesser General Public License as published by
9    * the Free Software Foundation; either version 3 of the License, or
10   * (at your option) any later version.
11   *
12   * Zemucan is distributed in the hope that it will be useful,
13   * but WITHOUT ANY WARRANTY; without even the implied warranty of
14   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15   * GNU Lesser General Public License for more details.
16   *
17   * You should have received a copy of the GNU Lesser General Public License
18   * along with this library; if not, see <http://www.gnu.org/licenses/>.
19   *
20   * Contact:
21   * a n g o c a  at  y a h o o  dot  c o m
22   * Cra. 45 No 61 - 31, Bogota, Colombia.
23   *
24   * Author:   $LastChangedBy: angoca $:
25   * Date:     $LastChangedDate: 2011-03-06 22:39:08 -0500 (dom, 06 mar 2011) $:
26   * Revision: $LastChangedRevision: 1916 $:
27   * URL:      $HeadURL: https://zemucan.svn.sourceforge.net/svnroot/zemucan/branches/zemucan_v1/source-code/analyzers/src/test/java/name/angoca/zemucan/core/syntactic/impl/ImplementationSyntacticAnalyzerTest.java $:
28   */
29  package name.angoca.zemucan.core.syntactic.impl;
30  
31  import java.util.ArrayList;
32  import java.util.List;
33  
34  import name.angoca.zemucan.AbstractZemucanException;
35  import name.angoca.zemucan.core.lexical.model.Token;
36  import name.angoca.zemucan.core.syntactic.model.GraphAnswer;
37  import name.angoca.zemucan.grammarReader.api.GrammarReaderController;
38  import name.angoca.zemucan.tools.Constants;
39  import name.angoca.zemucan.tools.configurator.Configurator;
40  import name.angoca.zemucan.tools.test.RandomTestRunner;
41  
42  import org.junit.AfterClass;
43  import org.junit.Assert;
44  import org.junit.BeforeClass;
45  import org.junit.Test;
46  import org.junit.runner.RunWith;
47  
48  /**
49   * Set of test of the implementation of the syntax analyzer.
50   * <p>
51   * <b>Control Version</b>
52   * <p>
53   * <ul>
54   * <li>0.0.1 Class creation.</li>
55   * <li>0.1.0</li>
56   * <li>0.2.0</li>
57   * <li>0.2.1 ArrayList -> List.</li>
58   * <li>0.2.2 Organized.</li>
59   * <li>0.3.0 jUnit 4 annotations.</li>
60   * <li>0.3.1 Help Token.</li>
61   * <li>0.3.2 Destroy instance.</li>
62   * <li>0.3.3 final.</li>
63   * <li>0.3.4 Reset system property.</li>
64   * <li>1.0.0 Moved to version 1.</li>
65   * <li>1.1.0 Exception hierarchy changed.</li>
66   * <li>1.2.0 throws.</li>
67   * <li>1.3.0 Space after phrase.</li>
68   * <li>1.3.1 Grammar controller.</li>
69   * <li>1.4.0 Param null tests.</li>
70   * <li>1.4.1 Method renamed.</li>
71   * <li>1.4.2 Token is reserved.</li>
72   * <li>1.4.3 About and license tokens.</li>
73   * <li>1.4.4 Destroy instance in the after class method.</li>
74   * </ul>
75   *
76   * @author Andres Gomez Casanova <a
77   *         href="mailto:a n g o c a at y a h o o dot c o m">(AngocA)</a>
78   * @version 1.4.4 2010-09-25
79   */
80  @RunWith(RandomTestRunner.class)
81  public final class ImplementationSyntacticAnalyzerTest {
82  
83      /**
84       * The 'about' word.
85       */
86      private static final String ABOUT = "about"; //$NON-NLS-1$
87  
88      /**
89       * The 'c1' word.
90       */
91      private static final String C1 = "c1"; //$NON-NLS-1$
92  
93      /**
94       * The ')' word.
95       */
96      private static final String CLOSE_PARENTHESIS = ")"; //$NON-NLS-1$
97      /**
98       * The '&lt;colName&gt;' word.
99       */
100     private static final String COL_NAME = "<colName>"; //$NON-NLS-1$
101     /**
102      * The 'create' word.
103      */
104     private static final String CREATE = "create"; //$NON-NLS-1$
105     /**
106      * The '?' word.
107      */
108     private static final String HELP = "?"; //$NON-NLS-1$
109     /**
110      * The 'in2' word.
111      */
112     private static final String INT = "int"; //$NON-NLS-1$
113     /**
114      * The 'license' word.
115      */
116     private static final String LICENSE = "license"; //$NON-NLS-1$
117     /**
118      * The '(' word.
119      */
120     private static final String OPEN_PARENTHESIS = "("; //$NON-NLS-1$
121     /**
122      * The 't1' word.
123      */
124     private static final String T1 = "t1"; //$NON-NLS-1$
125     /**
126      * The 'table' word.
127      */
128     private static final String TABLE = "table"; //$NON-NLS-1$
129     /**
130      * The '&lt;tableName&gt;' word.
131      */
132     private static final String TABLE_NAME = "<tableName>"; //$NON-NLS-1$
133     /**
134      * The 'tablespace' word.
135      */
136     private static final String TABLESPACE = "tablespace"; //$NON-NLS-1$
137     /**
138      * The 'toto' word.
139      */
140     private static final String TOTO = "toto"; //$NON-NLS-1$
141 
142     /**
143      * Reads the graph just once for all tests.
144      *
145      * @throws AbstractZemucanException
146      *             Never.
147      */
148     @BeforeClass
149     public static void setUpBeforeClass() throws AbstractZemucanException {
150         System.setProperty(Constants.ZEMUCAN_CONF_XML_PROPERTY,
151                 "sa_conf-test.xml"); //$NON-NLS-1$
152         Configurator.getInstance().setProperty(
153                 Constants.GRAMMAR_READER_NAME_PROPERTY,
154                 Configurator.GRAMMAR_READER_NAME_VALUE);
155         Configurator.getInstance()
156                 .setProperty(Constants.GRAMMAR_FILE_DESCRIPTORS_PROPERTY,
157                         "grammar-test.xml"); //$NON-NLS-1$
158 
159         // Recreates the syntax analyzer instance.
160         ImplementationSyntacticAnalyzer.destroyInstance();
161         ImplementationSyntacticAnalyzer.getInstance();
162     }
163 
164     /**
165      * Clears the configuration file name property at the end of the test.
166      */
167     @AfterClass
168     public static void tearDownAfterClass() {
169         ImplementationSyntacticAnalyzer.destroyInstance();
170         GrammarReaderController.destroyInstance();
171         Configurator.destroyInstance();
172         System.clearProperty(Constants.ZEMUCAN_CONF_XML_PROPERTY);
173     }
174 
175     /**
176      * Default constructor.
177      */
178     public ImplementationSyntacticAnalyzerTest() {
179         // Nothing.
180     }
181 
182     /**
183      * Test the possible options of an empty command.
184      *
185      * @throws AbstractZemucanException
186      *             Never
187      */
188     @Test
189     public void testGetOptions0() throws AbstractZemucanException {
190         // There is nothing as token in.
191 
192         final String option1 = ImplementationSyntacticAnalyzerTest.CREATE;
193         final String option2 = ImplementationSyntacticAnalyzerTest.ABOUT;
194         final String option3 = ImplementationSyntacticAnalyzerTest.HELP;
195         final String option4 = ImplementationSyntacticAnalyzerTest.LICENSE;
196 
197         final List<Token> phraseIn = new ArrayList<Token>();
198         final boolean endsWithSpace = false;
199 
200         final GraphAnswer actual = ImplementationSyntacticAnalyzer
201                 .getInstance().analyzeTokens(phraseIn, endsWithSpace);
202 
203         final List<Token> phraseOut = new ArrayList<Token>();
204         final List<Token> options = new ArrayList<Token>();
205         options.add(new Token(option1, true));
206         options.add(new Token(option2, true));
207         options.add(new Token(option3, true));
208         options.add(new Token(option4, true));
209         final GraphAnswer expected = new GraphAnswer(phraseOut, options);
210 
211         Assert.assertEquals("Empty command.", expected, actual); //$NON-NLS-1$
212     }
213 
214     /**
215      * Test the possible options of an empty command (Only options).
216      *
217      * @throws AbstractZemucanException
218      *             Never
219      */
220     @Test
221     public void testGetOptions0options() throws AbstractZemucanException {
222         // There is nothing as token in.
223 
224         final String option1 = ImplementationSyntacticAnalyzerTest.CREATE;
225         final String option2 = ImplementationSyntacticAnalyzerTest.ABOUT;
226         final String option3 = ImplementationSyntacticAnalyzerTest.HELP;
227         final String option4 = ImplementationSyntacticAnalyzerTest.LICENSE;
228 
229         final List<Token> phraseIn = new ArrayList<Token>();
230         final boolean endsWithSpace = false;
231         final GraphAnswer graph = ImplementationSyntacticAnalyzer.getInstance()
232                 .analyzeTokens(phraseIn, endsWithSpace);
233         final List<Token> actual = graph.getOptions();
234 
235         final List<Token> expected = new ArrayList<Token>();
236         expected.add(new Token(option2, true));
237         expected.add(new Token(option3, true));
238         expected.add(new Token(option4, true));
239         expected.add(new Token(option1, true));
240 
241         Assert.assertEquals("Options for an empty command", expected, //$NON-NLS-1$
242                 actual);
243     }
244 
245     /**
246      * Test the possible options of an empty command (Only phrase).
247      *
248      * @throws AbstractZemucanException
249      *             Never
250      */
251     @Test
252     public void testGetOptions0phrase() throws AbstractZemucanException {
253         // There is nothing as token in.
254 
255         final List<Token> phraseIn = new ArrayList<Token>();
256         final boolean endsWithSpace = false;
257         final GraphAnswer graph = ImplementationSyntacticAnalyzer.getInstance()
258                 .analyzeTokens(phraseIn, endsWithSpace);
259         final List<Token> actual = graph.getPhrases();
260 
261         final List<Token> expected = new ArrayList<Token>();
262 
263         Assert.assertEquals("Phrases for an empty command", expected, //$NON-NLS-1$
264                 actual);
265     }
266 
267     /**
268      * Test the possible options of a 'create' command.
269      *
270      * @throws AbstractZemucanException
271      *             Never
272      */
273     @Test
274     public void testGetOptions1() throws AbstractZemucanException {
275         final String tokenIn1 = ImplementationSyntacticAnalyzerTest.CREATE;
276 
277         final String option1 = ImplementationSyntacticAnalyzerTest.TABLE;
278         final String option2 = ImplementationSyntacticAnalyzerTest.TABLESPACE;
279 
280         final List<Token> phraseIn = new ArrayList<Token>();
281         phraseIn.add(new Token(tokenIn1, true));
282         final boolean endsWithSpace = false;
283         final GraphAnswer actual = ImplementationSyntacticAnalyzer
284                 .getInstance().analyzeTokens(phraseIn, endsWithSpace);
285 
286         final List<Token> phraseOut = new ArrayList<Token>();
287         final List<Token> options = new ArrayList<Token>();
288         options.add(new Token(option1, true));
289         options.add(new Token(option2, true));
290         final GraphAnswer expected = new GraphAnswer(phraseOut, options);
291 
292         Assert.assertEquals("'create' command", expected, actual); //$NON-NLS-1$
293     }
294 
295     /**
296      * Test the possible options of a 'create' command (Only options).
297      *
298      * @throws AbstractZemucanException
299      *             Never
300      */
301     @Test
302     public void testGetOptions1options() throws AbstractZemucanException {
303         final String tokenIn1 = ImplementationSyntacticAnalyzerTest.CREATE;
304 
305         final String option1 = ImplementationSyntacticAnalyzerTest.TABLE;
306         final String option2 = ImplementationSyntacticAnalyzerTest.TABLESPACE;
307 
308         final List<Token> phraseIn = new ArrayList<Token>();
309         phraseIn.add(new Token(tokenIn1, true));
310         final boolean endsWithSpace = false;
311         final GraphAnswer graph = ImplementationSyntacticAnalyzer.getInstance()
312                 .analyzeTokens(phraseIn, endsWithSpace);
313 
314         final List<Token> actual = graph.getOptions();
315         final List<Token> expected = new ArrayList<Token>();
316         expected.add(new Token(option1, true));
317         expected.add(new Token(option2, true));
318 
319         Assert.assertEquals("Options for 'create' command", expected, //$NON-NLS-1$
320                 actual);
321     }
322 
323     /**
324      * Test the possible options of a 'create' command (Only phrase).
325      *
326      * @throws AbstractZemucanException
327      *             Never
328      */
329     @Test
330     public void testGetOptions1phrase() throws AbstractZemucanException {
331         final String tokenIn1 = ImplementationSyntacticAnalyzerTest.CREATE;
332 
333         final List<Token> phraseIn = new ArrayList<Token>();
334         phraseIn.add(new Token(tokenIn1, true));
335         final boolean endsWithSpace = false;
336         final GraphAnswer graph = ImplementationSyntacticAnalyzer.getInstance()
337                 .analyzeTokens(phraseIn, endsWithSpace);
338         final List<Token> actual = graph.getPhrases();
339 
340         final List<Token> expected = new ArrayList<Token>();
341 
342         Assert.assertEquals("Phrases for 'create' command", expected, //$NON-NLS-1$
343                 actual);
344     }
345 
346     /**
347      * Test the possible options of a 'create ' command.
348      *
349      * @throws AbstractZemucanException
350      *             Never
351      */
352     @Test
353     public void testGetOptions1WithSpace() throws AbstractZemucanException {
354         final String tokenIn1 = ImplementationSyntacticAnalyzerTest.CREATE;
355 
356         final String option1 = ImplementationSyntacticAnalyzerTest.TABLE;
357         final String option2 = ImplementationSyntacticAnalyzerTest.TABLESPACE;
358 
359         final List<Token> phraseIn = new ArrayList<Token>();
360         phraseIn.add(new Token(tokenIn1, true));
361         final boolean endsWithSpace = true;
362         final GraphAnswer actual = ImplementationSyntacticAnalyzer
363                 .getInstance().analyzeTokens(phraseIn, endsWithSpace);
364 
365         final List<Token> phraseOut = new ArrayList<Token>();
366         final List<Token> options = new ArrayList<Token>();
367         options.add(new Token(option1, true));
368         options.add(new Token(option2, true));
369         final GraphAnswer expected = new GraphAnswer(phraseOut, options);
370 
371         Assert.assertEquals("'create ' command", expected, actual); //$NON-NLS-1$
372     }
373 
374     /**
375      * Test the possible options of a 'create table' command.
376      *
377      * @throws AbstractZemucanException
378      *             Never
379      */
380     @Test
381     public void testGetOptions2() throws AbstractZemucanException {
382         final String tokenIn1 = ImplementationSyntacticAnalyzerTest.CREATE;
383         final String tokenIn2 = ImplementationSyntacticAnalyzerTest.TABLE;
384 
385         final String tokenOut1 = ImplementationSyntacticAnalyzerTest.TABLESPACE;
386 
387         final String option1 = ImplementationSyntacticAnalyzerTest.TABLE_NAME;
388 
389         final List<Token> phraseIn = new ArrayList<Token>();
390         phraseIn.add(new Token(tokenIn1, true));
391         phraseIn.add(new Token(tokenIn2, true));
392         final boolean endsWithSpace = false;
393         final GraphAnswer actual = ImplementationSyntacticAnalyzer
394                 .getInstance().analyzeTokens(phraseIn, endsWithSpace);
395 
396         final List<Token> phraseOut = new ArrayList<Token>();
397         phraseOut.add(new Token(tokenOut1, true));
398         final List<Token> options = new ArrayList<Token>();
399         options.add(new Token(option1, true));
400         final GraphAnswer expected = new GraphAnswer(phraseOut, options);
401 
402         Assert.assertEquals("'create table' command", expected, actual); //$NON-NLS-1$
403     }
404 
405     /**
406      * Test the possible options of a 'create table' command (Only options).
407      *
408      * @throws AbstractZemucanException
409      *             Never
410      */
411     @Test
412     public void testGetOptions2options() throws AbstractZemucanException {
413         final String tokenIn1 = ImplementationSyntacticAnalyzerTest.CREATE;
414         final String tokenIn2 = ImplementationSyntacticAnalyzerTest.TABLE;
415 
416         final String option1 = ImplementationSyntacticAnalyzerTest.TABLE_NAME;
417 
418         final List<Token> phraseIn = new ArrayList<Token>();
419         phraseIn.add(new Token(tokenIn1, true));
420         phraseIn.add(new Token(tokenIn2, true));
421         final boolean endsWithSpace = false;
422         final GraphAnswer graph = ImplementationSyntacticAnalyzer.getInstance()
423                 .analyzeTokens(phraseIn, endsWithSpace);
424         final List<Token> actual = graph.getOptions();
425 
426         final List<Token> expected = new ArrayList<Token>();
427         expected.add(new Token(option1, true));
428 
429         Assert.assertEquals("Options for 'create table' command", //$NON-NLS-1$
430                 expected, actual);
431     }
432 
433     /**
434      * Test the possible options of a 'create table' command (Only phrase).
435      *
436      * @throws AbstractZemucanException
437      *             Never
438      */
439     @Test
440     public void testGetOptions2phrase() throws AbstractZemucanException {
441         final String tokenIn1 = ImplementationSyntacticAnalyzerTest.CREATE;
442         final String tokenIn2 = ImplementationSyntacticAnalyzerTest.TABLE;
443 
444         final String tokenOut1 = ImplementationSyntacticAnalyzerTest.TABLESPACE;
445 
446         final List<Token> phraseIn = new ArrayList<Token>();
447         phraseIn.add(new Token(tokenIn1, true));
448         phraseIn.add(new Token(tokenIn2, true));
449         final boolean endsWithSpace = false;
450         final GraphAnswer graph = ImplementationSyntacticAnalyzer.getInstance()
451                 .analyzeTokens(phraseIn, endsWithSpace);
452         final List<Token> actual = graph.getPhrases();
453 
454         final List<Token> expected = new ArrayList<Token>();
455         expected.add(new Token(tokenOut1, true));
456 
457         Assert.assertEquals("Phrases for 'create table' command", //$NON-NLS-1$
458                 expected, actual);
459     }
460 
461     /**
462      * Test the possible options of a 'create table ' command.
463      *
464      * @throws AbstractZemucanException
465      *             Never
466      */
467     @Test
468     public void testGetOptions2WithSpace() throws AbstractZemucanException {
469         final String tokenIn1 = ImplementationSyntacticAnalyzerTest.CREATE;
470         final String tokenIn2 = ImplementationSyntacticAnalyzerTest.TABLE;
471 
472         final String option1 = ImplementationSyntacticAnalyzerTest.TABLE_NAME;
473 
474         final List<Token> phraseIn = new ArrayList<Token>();
475         phraseIn.add(new Token(tokenIn1, true));
476         phraseIn.add(new Token(tokenIn2, true));
477         final boolean endsWithSpace = true;
478         final GraphAnswer actual = ImplementationSyntacticAnalyzer
479                 .getInstance().analyzeTokens(phraseIn, endsWithSpace);
480 
481         final List<Token> phraseOut = new ArrayList<Token>();
482         final List<Token> options = new ArrayList<Token>();
483         options.add(new Token(option1, true));
484         final GraphAnswer expected = new GraphAnswer(phraseOut, options);
485 
486         Assert.assertEquals("'create table ' command", expected, actual); //$NON-NLS-1$
487     }
488 
489     /**
490      * Test the possible options of a 'create table t1' command.
491      *
492      * @throws AbstractZemucanException
493      *             Never
494      */
495     @Test
496     public void testGetOptions3() throws AbstractZemucanException {
497         final String tokenIn1 = ImplementationSyntacticAnalyzerTest.CREATE;
498         final String tokenIn2 = ImplementationSyntacticAnalyzerTest.TABLE;
499         final String tokenIn3 = ImplementationSyntacticAnalyzerTest.T1;
500 
501         final String option1 = ImplementationSyntacticAnalyzerTest.OPEN_PARENTHESIS;
502 
503         final List<Token> phraseIn = new ArrayList<Token>();
504         phraseIn.add(new Token(tokenIn1, true));
505         phraseIn.add(new Token(tokenIn2, true));
506         phraseIn.add(new Token(tokenIn3, true));
507         final boolean endsWithSpace = false;
508         final GraphAnswer actual = ImplementationSyntacticAnalyzer
509                 .getInstance().analyzeTokens(phraseIn, endsWithSpace);
510 
511         final List<Token> phraseOut = new ArrayList<Token>();
512         final List<Token> options = new ArrayList<Token>();
513         options.add(new Token(option1, true));
514         final GraphAnswer expected = new GraphAnswer(phraseOut, options);
515 
516         Assert.assertEquals("'create table t1' command", expected, //$NON-NLS-1$
517                 actual);
518     }
519 
520     /**
521      * Test the possible options of a 'create table t1' command (Only options).
522      *
523      * @throws AbstractZemucanException
524      *             Never
525      */
526     @Test
527     public void testGetOptions3options() throws AbstractZemucanException {
528         final String tokenIn1 = ImplementationSyntacticAnalyzerTest.CREATE;
529         final String tokenIn2 = ImplementationSyntacticAnalyzerTest.TABLE;
530         final String tokenIn3 = ImplementationSyntacticAnalyzerTest.T1;
531 
532         final String option1 = ImplementationSyntacticAnalyzerTest.OPEN_PARENTHESIS;
533 
534         final List<Token> phraseIn = new ArrayList<Token>();
535         phraseIn.add(new Token(tokenIn1, true));
536         phraseIn.add(new Token(tokenIn2, true));
537         phraseIn.add(new Token(tokenIn3, true));
538         final boolean endsWithSpace = false;
539         final GraphAnswer graph = ImplementationSyntacticAnalyzer.getInstance()
540                 .analyzeTokens(phraseIn, endsWithSpace);
541         final List<Token> actual = graph.getOptions();
542 
543         final List<Token> expected = new ArrayList<Token>();
544         expected.add(new Token(option1, true));
545 
546         Assert.assertEquals("Options for 'create table t1' command", //$NON-NLS-1$
547                 expected, actual);
548     }
549 
550     /**
551      * Test the possible options of a 'create table t1' command (Only phrase).
552      *
553      * @throws AbstractZemucanException
554      *             Never
555      */
556     @Test
557     public void testGetOptions3phrase() throws AbstractZemucanException {
558         final String tokenIn1 = ImplementationSyntacticAnalyzerTest.CREATE;
559         final String tokenIn2 = ImplementationSyntacticAnalyzerTest.TABLE;
560         final String tokenIn3 = ImplementationSyntacticAnalyzerTest.T1;
561 
562         final List<Token> phraseIn = new ArrayList<Token>();
563         phraseIn.add(new Token(tokenIn1, true));
564         phraseIn.add(new Token(tokenIn2, true));
565         phraseIn.add(new Token(tokenIn3, true));
566         final boolean endsWithSpace = false;
567         final GraphAnswer graph = ImplementationSyntacticAnalyzer.getInstance()
568                 .analyzeTokens(phraseIn, endsWithSpace);
569         final List<Token> actual = graph.getPhrases();
570 
571         final List<Token> expected = new ArrayList<Token>();
572 
573         Assert.assertEquals("Phrase for 'create table t1' command", //$NON-NLS-1$
574                 expected, actual);
575     }
576 
577     /**
578      * Test the possible options of a 'create table t1 (' command.
579      *
580      * @throws AbstractZemucanException
581      *             Never
582      */
583     @Test
584     public void testGetOptions4() throws AbstractZemucanException {
585         final String tokenIn1 = ImplementationSyntacticAnalyzerTest.CREATE;
586         final String tokenIn2 = ImplementationSyntacticAnalyzerTest.TABLE;
587         final String tokenIn3 = ImplementationSyntacticAnalyzerTest.T1;
588         final String tokenIn4 = ImplementationSyntacticAnalyzerTest.OPEN_PARENTHESIS;
589 
590         final String option1 = ImplementationSyntacticAnalyzerTest.COL_NAME;
591 
592         final List<Token> phraseIn = new ArrayList<Token>();
593         phraseIn.add(new Token(tokenIn1, true));
594         phraseIn.add(new Token(tokenIn2, true));
595         phraseIn.add(new Token(tokenIn3, true));
596         phraseIn.add(new Token(tokenIn4, true));
597         final boolean endsWithSpace = false;
598         final GraphAnswer actual = ImplementationSyntacticAnalyzer
599                 .getInstance().analyzeTokens(phraseIn, endsWithSpace);
600 
601         final List<Token> phraseOut = new ArrayList<Token>();
602         final List<Token> options = new ArrayList<Token>();
603         options.add(new Token(option1, true));
604         final GraphAnswer expected = new GraphAnswer(phraseOut, options);
605 
606         Assert.assertEquals("Phrases for 'create table t1' command", //$NON-NLS-1$
607                 expected, actual);
608     }
609 
610     /**
611      * Test the possible options of a 'create table t1 (' command (Only
612      * options).
613      *
614      * @throws AbstractZemucanException
615      *             Never
616      */
617     @Test
618     public void testGetOptions4options() throws AbstractZemucanException {
619         final String tokenIn1 = ImplementationSyntacticAnalyzerTest.CREATE;
620         final String tokenIn2 = ImplementationSyntacticAnalyzerTest.TABLE;
621         final String tokenIn3 = ImplementationSyntacticAnalyzerTest.T1;
622         final String tokenIn4 = ImplementationSyntacticAnalyzerTest.OPEN_PARENTHESIS;
623 
624         final String option1 = ImplementationSyntacticAnalyzerTest.COL_NAME;
625 
626         final List<Token> phraseIn = new ArrayList<Token>();
627         phraseIn.add(new Token(tokenIn1, true));
628         phraseIn.add(new Token(tokenIn2, true));
629         phraseIn.add(new Token(tokenIn3, true));
630         phraseIn.add(new Token(tokenIn4, true));
631         final boolean endsWithSpace = false;
632         final GraphAnswer graph = ImplementationSyntacticAnalyzer.getInstance()
633                 .analyzeTokens(phraseIn, endsWithSpace);
634         final List<Token> actual = graph.getOptions();
635 
636         final List<Token> expected = new ArrayList<Token>();
637         expected.add(new Token(option1, true));
638 
639         Assert.assertEquals("Options for 'create table t1 (' command", //$NON-NLS-1$
640                 expected, actual);
641     }
642 
643     /**
644      * Test the possible options of a 'create table t1 (' command (Only phrase).
645      *
646      * @throws AbstractZemucanException
647      *             Never
648      */
649     @Test
650     public void testGetOptions4phrase() throws AbstractZemucanException {
651         final String tokenIn1 = ImplementationSyntacticAnalyzerTest.CREATE;
652         final String tokenIn2 = ImplementationSyntacticAnalyzerTest.TABLE;
653         final String tokenIn3 = ImplementationSyntacticAnalyzerTest.T1;
654         final String tokenIn4 = ImplementationSyntacticAnalyzerTest.OPEN_PARENTHESIS;
655 
656         final List<Token> phraseIn = new ArrayList<Token>();
657         phraseIn.add(new Token(tokenIn1, true));
658         phraseIn.add(new Token(tokenIn2, true));
659         phraseIn.add(new Token(tokenIn3, true));
660         phraseIn.add(new Token(tokenIn4, true));
661         final boolean endsWithSpace = false;
662         final GraphAnswer graph = ImplementationSyntacticAnalyzer.getInstance()
663                 .analyzeTokens(phraseIn, endsWithSpace);
664         final List<Token> actual = graph.getPhrases();
665 
666         final List<Token> expected = new ArrayList<Token>();
667 
668         Assert.assertEquals("Phrase for 'create table t1 (' command", //$NON-NLS-1$
669                 expected, actual);
670     }
671 
672     /**
673      * Test the possible options of a 'create table t1 (c1 int)' command. This
674      * is a complete command.
675      *
676      * @throws AbstractZemucanException
677      *             Never
678      */
679     @Test
680     public void testGetOptions5() throws AbstractZemucanException {
681         final String tokenIn1 = ImplementationSyntacticAnalyzerTest.CREATE;
682         final String tokenIn2 = ImplementationSyntacticAnalyzerTest.TABLE;
683         final String tokenIn3 = ImplementationSyntacticAnalyzerTest.T1;
684         final String tokenIn4 = ImplementationSyntacticAnalyzerTest.OPEN_PARENTHESIS;
685         final String tokenIn5 = ImplementationSyntacticAnalyzerTest.C1;
686         final String tokenIn6 = ImplementationSyntacticAnalyzerTest.INT;
687         final String tokenIn7 = ImplementationSyntacticAnalyzerTest.CLOSE_PARENTHESIS;
688 
689         final List<Token> phraseIn = new ArrayList<Token>();
690         phraseIn.add(new Token(tokenIn1, true));
691         phraseIn.add(new Token(tokenIn2, true));
692         phraseIn.add(new Token(tokenIn3, true));
693         phraseIn.add(new Token(tokenIn4, true));
694         phraseIn.add(new Token(tokenIn5, true));
695         phraseIn.add(new Token(tokenIn6, true));
696         phraseIn.add(new Token(tokenIn7, true));
697         final boolean endsWithSpace = false;
698         final GraphAnswer actual = ImplementationSyntacticAnalyzer
699                 .getInstance().analyzeTokens(phraseIn, endsWithSpace);
700 
701         final List<Token> phraseOut = new ArrayList<Token>();
702         final List<Token> options = new ArrayList<Token>();
703         final GraphAnswer expected = new GraphAnswer(phraseOut, options);
704 
705         Assert.assertEquals("'create table t1 (c1 int)' command", //$NON-NLS-1$
706                 expected, actual);
707     }
708 
709     /**
710      * Test the possible options of a 'create table t1 (c1 int) in ts1' command.
711      *
712      * @throws AbstractZemucanException
713      *             Never
714      */
715     @Test
716     public void testGetOptions6() throws AbstractZemucanException {
717         final String tokenIn1 = ImplementationSyntacticAnalyzerTest.CREATE;
718         final String tokenIn2 = ImplementationSyntacticAnalyzerTest.TABLE;
719         final String tokenIn3 = ImplementationSyntacticAnalyzerTest.T1;
720         final String tokenIn4 = ImplementationSyntacticAnalyzerTest.OPEN_PARENTHESIS;
721         final String tokenIn5 = ImplementationSyntacticAnalyzerTest.C1;
722         final String tokenIn6 = ImplementationSyntacticAnalyzerTest.INT;
723         final String tokenIn7 = ImplementationSyntacticAnalyzerTest.CLOSE_PARENTHESIS;
724         final String tokenIn8 = "in"; //$NON-NLS-1$
725         final String tokenIn9 = "ts1"; //$NON-NLS-1$
726 
727         final List<Token> phraseIn = new ArrayList<Token>();
728         // Bogus warning in the next lines, but it's a test case :)
729         phraseIn.add(new Token(tokenIn1, true));
730         phraseIn.add(new Token(tokenIn2, true));
731         phraseIn.add(new Token(tokenIn3, true));
732         phraseIn.add(new Token(tokenIn4, true));
733         phraseIn.add(new Token(tokenIn5, true));
734         phraseIn.add(new Token(tokenIn6, true));
735         phraseIn.add(new Token(tokenIn7, true));
736         phraseIn.add(new Token(tokenIn8, true));
737         phraseIn.add(new Token(tokenIn9, true));
738         final boolean endsWithSpace = false;
739         final GraphAnswer actual = ImplementationSyntacticAnalyzer
740                 .getInstance().analyzeTokens(phraseIn, endsWithSpace);
741 
742         final List<Token> phraseOut = new ArrayList<Token>();
743         final List<Token> options = new ArrayList<Token>();
744         final GraphAnswer expected = new GraphAnswer(phraseOut, options);
745 
746         Assert.assertEquals("'create table t1 (c1 int) in ts1' command", //$NON-NLS-1$
747                 expected, actual);
748     }
749 
750     /**
751      * Test the possible options of a 'create table t1 (c1 int) in' command.
752      *
753      * @throws AbstractZemucanException
754      *             Never
755      */
756     @Test
757     public void testGetOptions7() throws AbstractZemucanException {
758         final String tokenIn1 = ImplementationSyntacticAnalyzerTest.CREATE;
759         final String tokenIn2 = ImplementationSyntacticAnalyzerTest.TABLE;
760         final String tokenIn3 = ImplementationSyntacticAnalyzerTest.T1;
761         final String tokenIn4 = ImplementationSyntacticAnalyzerTest.OPEN_PARENTHESIS;
762         final String tokenIn5 = ImplementationSyntacticAnalyzerTest.C1;
763         final String tokenIn6 = ImplementationSyntacticAnalyzerTest.INT;
764         final String tokenIn7 = ImplementationSyntacticAnalyzerTest.CLOSE_PARENTHESIS;
765         final String tokenIn8 = "in"; //$NON-NLS-1$
766 
767         final List<Token> phraseIn = new ArrayList<Token>();
768         // Bogus warning in the next lines, but it's a test case :)
769         phraseIn.add(new Token(tokenIn1, true));
770         phraseIn.add(new Token(tokenIn2, true));
771         phraseIn.add(new Token(tokenIn3, true));
772         phraseIn.add(new Token(tokenIn4, true));
773         phraseIn.add(new Token(tokenIn5, true));
774         phraseIn.add(new Token(tokenIn6, true));
775         phraseIn.add(new Token(tokenIn7, true));
776         phraseIn.add(new Token(tokenIn8, true));
777         final boolean endsWithSpace = false;
778         final GraphAnswer actual = ImplementationSyntacticAnalyzer
779                 .getInstance().analyzeTokens(phraseIn, endsWithSpace);
780 
781         final List<Token> phraseOut = new ArrayList<Token>();
782         final List<Token> options = new ArrayList<Token>();
783         final GraphAnswer expected = new GraphAnswer(phraseOut, options);
784 
785         Assert.assertEquals("'create table t1 (c1 int) in' command", //$NON-NLS-1$
786                 expected, actual);
787     }
788 
789     /**
790      * Test the possible options of a 'create tab' command.
791      *
792      * @throws AbstractZemucanException
793      *             Never
794      */
795     @Test
796     public void testGetOptions8() throws AbstractZemucanException {
797         final String tokenIn1 = ImplementationSyntacticAnalyzerTest.CREATE;
798         final String tokenIn2 = "tab"; //$NON-NLS-1$
799 
800         final String tokenOut1 = ImplementationSyntacticAnalyzerTest.TABLE;
801         final String tokenOut2 = ImplementationSyntacticAnalyzerTest.TABLESPACE;
802 
803         final List<Token> phraseIn = new ArrayList<Token>();
804         phraseIn.add(new Token(tokenIn1, true));
805         phraseIn.add(new Token(tokenIn2, true));
806         final boolean endsWithSpace = false;
807         final GraphAnswer actual = ImplementationSyntacticAnalyzer
808                 .getInstance().analyzeTokens(phraseIn, endsWithSpace);
809 
810         final List<Token> phraseOut = new ArrayList<Token>();
811         phraseOut.add(new Token(tokenOut1, true));
812         phraseOut.add(new Token(tokenOut2, true));
813         final List<Token> options = new ArrayList<Token>();
814         final GraphAnswer expected = new GraphAnswer(phraseOut, options);
815 
816         Assert.assertEquals("'create tab' command", expected, actual); //$NON-NLS-1$
817     }
818 
819     /**
820      * This is a test of an invalid initial token.
821      *
822      * @throws AbstractZemucanException
823      *             Never
824      */
825     @Test
826     public void testInvalidFirstToken() throws AbstractZemucanException {
827         final String tokenIn1 = ImplementationSyntacticAnalyzerTest.TOTO;
828 
829         final List<Token> phraseIn = new ArrayList<Token>();
830         phraseIn.add(new Token(tokenIn1, true));
831         final boolean endsWithSpace = false;
832         final GraphAnswer actual = ImplementationSyntacticAnalyzer
833                 .getInstance().analyzeTokens(phraseIn, endsWithSpace);
834 
835         final List<Token> phraseOut = new ArrayList<Token>();
836         final List<Token> options = new ArrayList<Token>();
837         final GraphAnswer expected = new GraphAnswer(phraseOut, options);
838 
839         Assert.assertEquals("'toto' phrase", expected, actual); //$NON-NLS-1$
840     }
841 
842     /**
843      * This is a test of an invalid token.
844      *
845      * @throws AbstractZemucanException
846      *             Never
847      */
848     @Test
849     public void testInvalidSecondToken() throws AbstractZemucanException {
850         final String tokenIn1 = ImplementationSyntacticAnalyzerTest.CREATE;
851         final String tokenIn2 = ImplementationSyntacticAnalyzerTest.TOTO;
852 
853         final List<Token> phraseIn = new ArrayList<Token>();
854         phraseIn.add(new Token(tokenIn1, true));
855         phraseIn.add(new Token(tokenIn2, true));
856         final boolean endsWithSpace = false;
857         final GraphAnswer actual = ImplementationSyntacticAnalyzer
858                 .getInstance().analyzeTokens(phraseIn, endsWithSpace);
859 
860         final List<Token> phraseOut = new ArrayList<Token>();
861         final List<Token> options = new ArrayList<Token>();
862         final GraphAnswer expected = new GraphAnswer(phraseOut, options);
863 
864         Assert.assertEquals("'create toto' phrase", expected, actual); //$NON-NLS-1$
865     }
866 
867     /**
868      * Tests that the get option method cannot receive a null parameter.
869      *
870      * @throws AbstractZemucanException
871      *             Never.
872      */
873     @Test(expected = AssertionError.class)
874     public void testNullGetOption() throws AbstractZemucanException {
875         ImplementationSyntacticAnalyzer.getInstance()
876                 .analyzeTokens(null, false);
877     }
878 
879     /**
880      * Tests that the get option method cannot receive a null token.
881      *
882      * @throws AbstractZemucanException
883      *             Never.
884      */
885     @Test(expected = AssertionError.class)
886     public void testNullTokenGetOption() throws AbstractZemucanException {
887         final List<Token> phraseIn = new ArrayList<Token>();
888         phraseIn.add(null);
889 
890         ImplementationSyntacticAnalyzer.getInstance().analyzeTokens(phraseIn,
891                 false);
892     }
893 }