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/lexical/impl/ImplementationLexicalAnalyzerTest.java $:
28   */
29  package name.angoca.zemucan.core.lexical.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.grammarReader.api.GrammarReaderController;
37  import name.angoca.zemucan.interfaze.model.ReturnOptions;
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   * This is the set of test for the lexical analyzer. The inputs are phrases that
50   * represents the user's command, they are received like strings and this class
51   * tests its conversion to Tokens and analyze the results.
52   * <p>
53   * <b>Control Version</b>
54   * <p>
55   * <ul>
56   * <li>0.0.1 Class creation.</li>
57   * <li>0.1.0</li>
58   * <li>0.2.0</li>
59   * <li>0.2.1 Recommendations from PMD.</li>
60   * <li>0.2.2 Organized.</li>
61   * <li>0.2.3 Setup class.</li>
62   * <li>0.3.0 jUnit 4 annotations.</li>
63   * <li>0.4.0 Invalid graph exception.</li>
64   * <li>0.4.1 Set up method.</li>
65   * <li>0.4.2 Destroy instance.</li>
66   * <li>0.4.3 final and comments.</li>
67   * <li>0.4.4 Reset system variable.</li>
68   * <li>1.0.0 Moved to version 1.</li>
69   * <li>1.1.0 Exception hierarchy changed.</li>
70   * <li>1.2.0 New excception</li>
71   * <li>1.3.0 Throws</li>
72   * <li>1.4.0 Space after phrase</li>
73   * <li>1.5.0 Null phrase and grammar controller</li>
74   * <li>1.6.0 Param null tests</li>
75   * <li>1.6.1 Method renamed</li>
76   * <li>1.7.0 Token is reserved and tests modification.</li>
77   * <li>1.7.1 Method change in analyzer.</li>
78   * <li>1.7.2 Changed after the 9 cases.</li>
79   * <li>1.7.3 Destroy instances in after class method.</li>
80   * </ul>
81   *
82   * @author Andres Gomez Casanova <a
83   *         href="mailto:a n g o c a at y a h o o dot c o m" >(AngocA)</a>
84   * @version 1.7.3 2010-09-25
85   */
86  @RunWith(RandomTestRunner.class)
87  public final class ImplementationLexicalAnalyzerTest {
88      /**
89       * The ')' word.
90       */
91      private static final String CLOSE_PARENTHESIS = ")"; //$NON-NLS-1$
92  
93      /**
94       * The '&lt;colName&gt;' word.
95       */
96      private static final String COL_NAME = "<colName>"; //$NON-NLS-1$
97  
98      /**
99       * The 'create' word.
100      */
101     private static final String CREATE = "create"; //$NON-NLS-1$
102 
103     /**
104      * The 'create tab' words.
105      */
106     private static final String CREATE_TAB = "create tab";
107     /**
108      * The ' ' word.
109      */
110     private static final String SPACE = " "; //$NON-NLS-1$
111 
112     /**
113      * Load the graph.
114      *
115      * @throws AbstractZemucanException
116      *             Never
117      */
118     @BeforeClass
119     public static void setUpBeforeClass() throws AbstractZemucanException {
120         System.setProperty(Constants.ZEMUCAN_CONF_XML_PROPERTY,
121                 "sa_conf-test.xml"); //$NON-NLS-1$
122         Configurator.getInstance().setProperty(
123                 Constants.GRAMMAR_READER_NAME_PROPERTY,
124                 Configurator.GRAMMAR_READER_NAME_VALUE);
125         Configurator.getInstance()
126                 .setProperty(Constants.GRAMMAR_FILE_DESCRIPTORS_PROPERTY,
127                         "grammar-test.xml"); //$NON-NLS-1$
128 
129         // Creates the Lexical analyzer instance.
130         ImplementationLexicalAnalyzer.getInstance();
131     }
132 
133     /**
134      * Clears the configuration file name property at the end of the test.
135      */
136     @AfterClass
137     public static void tearDownAfterClass() {
138         // Destroy any existent instance.
139         ImplementationLexicalAnalyzer.destroyInstance();
140         GrammarReaderController.destroyInstance();
141         // Recreates the configurator instance.
142         Configurator.destroyInstance();
143         System.clearProperty(Constants.ZEMUCAN_CONF_XML_PROPERTY);
144     }
145 
146     /**
147      * Default constructor.
148      */
149     public ImplementationLexicalAnalyzerTest() {
150         // Nothing.
151     }
152 
153     /**
154      * Test of the options for the 'create table t1 (c1 int, c2 char(10'
155      * command.
156      *
157      * @throws AbstractZemucanException
158      *             Never.
159      */
160     @Test
161     public void testCloseFirstParenthesis() throws AbstractZemucanException {
162         final String cmdIn = "create table t1 (c1 int, c2 char(10"; //$NON-NLS-1$
163 
164         final String cmdOut = "create table t1 (c1 int, c2 char(10 )"; //$NON-NLS-1$
165 
166         final ReturnOptions actual = ImplementationLexicalAnalyzer
167                 .getInstance().analyzePhrase(cmdIn);
168 
169         final ReturnOptions expected = new ReturnOptions(cmdOut,
170                 new String[] {}, new String[] {});
171 
172         Assert.assertEquals("object for 'create table t1 (c1 int, c2 char(10'", //$NON-NLS-1$
173                 expected, actual);
174     }
175 
176     /**
177      * Test of the options for the 'create table t2(c1 int' command.
178      *
179      * @throws AbstractZemucanException
180      *             Never.
181      */
182     @Test
183     public void testComma() throws AbstractZemucanException {
184         final String cmdIn = "create table t2(c1 int"; //$NON-NLS-1$
185 
186         final String cmdOut = "create table t2(c1 int "; //$NON-NLS-1$
187 
188         final String option1 = ","; //$NON-NLS-1$
189         final String option2 = ImplementationLexicalAnalyzerTest.CLOSE_PARENTHESIS;
190 
191         final ReturnOptions actual = ImplementationLexicalAnalyzer
192                 .getInstance().analyzePhrase(cmdIn);
193 
194         final ReturnOptions expected = new ReturnOptions(cmdOut,
195                 new String[] {}, new String[] { option1, option2 });
196 
197         Assert.assertEquals("object for 'create table t2(c1 int'", //$NON-NLS-1$
198                 expected, actual);
199     }
200 
201     /**
202      * Tests the token conversion.
203      *
204      * @throws AbstractZemucanException
205      *             Never.
206      */
207     @Test
208     public void testConvertionCrea() throws AbstractZemucanException {
209         final String phraseIn = "crea"; //$NON-NLS-1$
210 
211         final String phraseOut = ImplementationLexicalAnalyzerTest.CREATE;
212 
213         final String token1 = "crea"; //$NON-NLS-1$
214         final List<Token> tokens = new ArrayList<Token>();
215         tokens.add(new Token(token1, true));
216 
217         final String actual = ImplementationLexicalAnalyzer.getInstance()
218                 .replaceLastToken(phraseIn, tokens,
219                         ImplementationLexicalAnalyzerTest.CREATE);
220 
221         final String expected = phraseOut;
222 
223         Assert.assertEquals("conversion for 'crea'", expected, actual); //$NON-NLS-1$
224     }
225 
226     /**
227      * Tests the token conversion 'create tab' -> 'create tab'.
228      *
229      * @throws AbstractZemucanException
230      *             Never.
231      */
232     @Test
233     public void testConvertionCreateTab() throws AbstractZemucanException {
234         final String phraseIn = ImplementationLexicalAnalyzerTest.CREATE_TAB;
235 
236         final String phraseOut = ImplementationLexicalAnalyzerTest.CREATE_TAB;
237 
238         final String token1 = ImplementationLexicalAnalyzerTest.CREATE;
239         final String token2 = "tab"; //$NON-NLS-1$
240         final List<Token> tokens = new ArrayList<Token>();
241         tokens.add(new Token(token1, true));
242         tokens.add(new Token(token2, true));
243 
244         final String actual = ImplementationLexicalAnalyzer.getInstance()
245                 .replaceLastToken(phraseIn, tokens, "tab");
246 
247         final String expected = phraseOut;
248 
249         Assert.assertEquals("conversion for 'create tab'", expected, //$NON-NLS-1$
250                 actual);
251     }
252 
253     /**
254      * Test to complete the phrase crea (phrase).
255      *
256      * @throws AbstractZemucanException
257      *             Never.
258      */
259     @Test
260     public void testCreaPhrase1() throws AbstractZemucanException {
261         final String cmdIn = "crea"; //$NON-NLS-1$
262 
263         final String cmdOut = ImplementationLexicalAnalyzerTest.CREATE;
264 
265         final ReturnOptions ret = ImplementationLexicalAnalyzer.getInstance()
266                 .analyzePhrase(cmdIn);
267         final String actual = ret.getPhrase();
268 
269         final String expected = cmdOut;
270 
271         Assert.assertEquals("complete for 'crea'", expected, actual); //$NON-NLS-1$
272     }
273 
274     /**
275      * Test to complete the phrase crea (options).
276      *
277      * @throws AbstractZemucanException
278      *             Never.
279      */
280     @Test
281     public void testCreaPhrase2() throws AbstractZemucanException {
282         final String cmdIn = "crea"; //$NON-NLS-1$
283 
284         final ReturnOptions ret = ImplementationLexicalAnalyzer.getInstance()
285                 .analyzePhrase(cmdIn);
286         final int actual = ret.getOptions().length;
287 
288         final int expected = new String[] {}.length;
289 
290         Assert.assertEquals("options for 'crea'", expected, actual); //$NON-NLS-1$
291     }
292 
293     /**
294      * Test that the phrase 'crea' does not have several phrases.
295      *
296      * @throws AbstractZemucanException
297      *             Never.
298      */
299     @Test
300     public void testCreaPhrase3() throws AbstractZemucanException {
301         final String cmdIn = "crea"; //$NON-NLS-1$
302 
303         final ReturnOptions ret = ImplementationLexicalAnalyzer.getInstance()
304                 .analyzePhrase(cmdIn);
305         final int actual = ret.getPhrases().length;
306 
307         final int expected = new String[] {}.length;
308 
309         Assert.assertEquals("phrases for 'crea'", expected, actual); //$NON-NLS-1$
310     }
311 
312     /**
313      * Test to complete the phrase 'crea' (object).
314      *
315      * @throws AbstractZemucanException
316      *             Never.
317      */
318     @Test
319     public void testCreaPhrase4() throws AbstractZemucanException {
320         final String cmdIn = "crea"; //$NON-NLS-1$
321 
322         final String cmdOut = ImplementationLexicalAnalyzerTest.CREATE;
323 
324         final ReturnOptions actual = ImplementationLexicalAnalyzer
325                 .getInstance().analyzePhrase(cmdIn);
326 
327         final ReturnOptions expected = new ReturnOptions(cmdOut,
328                 new String[] {}, new String[] {});
329 
330         Assert.assertEquals("object for 'crea'", expected, actual); //$NON-NLS-1$
331     }
332 
333     /**
334      * Test of the options for the 'create' command. There is only one option.
335      *
336      * @throws AbstractZemucanException
337      *             Never.
338      */
339     @Test
340     public void testCreateCommand() throws AbstractZemucanException {
341         final String cmdIn = ImplementationLexicalAnalyzerTest.CREATE;
342 
343         final String cmdOut = ImplementationLexicalAnalyzerTest.CREATE
344                 + " table";
345 
346         final String opt1 = "table"; //$NON-NLS-1$
347         final String opt2 = "tablespace"; //$NON-NLS-1$
348 
349         final ReturnOptions actual = ImplementationLexicalAnalyzer
350                 .getInstance().analyzePhrase(cmdIn);
351 
352         final ReturnOptions expected = new ReturnOptions(cmdOut,
353                 new String[] {}, new String[] { opt1, opt2 });
354 
355         Assert.assertEquals("object for 'create'", expected, actual); //$NON-NLS-1$
356     }
357 
358     /**
359      * Test the token completion tab -> table.
360      *
361      * @throws AbstractZemucanException
362      *             Never.
363      */
364     @Test
365     public void testCreateTab() throws AbstractZemucanException {
366         final String cmdIn = ImplementationLexicalAnalyzerTest.CREATE_TAB;
367 
368         final String cmdOut = "create table"; //$NON-NLS-1$
369 
370         final String opt1 = "tablespace"; //$NON-NLS-1$
371 
372         final ReturnOptions actual = ImplementationLexicalAnalyzer
373                 .getInstance().analyzePhrase(cmdIn);
374 
375         final ReturnOptions expected = new ReturnOptions(cmdOut,
376                 new String[] { opt1 }, new String[] {});
377 
378         Assert.assertEquals("object for 'create tab'", expected, actual); //$NON-NLS-1$
379     }
380 
381     /**
382      * Test of the options for the 'create table' command. Test options.
383      *
384      * @throws AbstractZemucanException
385      *             Never.
386      */
387     @Test
388     public void testCreateTableCommand1() throws AbstractZemucanException {
389         final String cmdIn = "create table"; //$NON-NLS-1$
390 
391         final String opt1 = "<tableName>"; //$NON-NLS-1$
392 
393         final ReturnOptions ret = ImplementationLexicalAnalyzer.getInstance()
394                 .analyzePhrase(cmdIn);
395         final String[] actual = ret.getOptions();
396 
397         final String[] expected = new String[] { opt1 };
398 
399         Assert.assertEquals("options for 'create table'", //$NON-NLS-1$
400                 expected.length, actual.length);
401     }
402 
403     /**
404      * Test of the options for the 'create table' command. Test phrases.
405      *
406      * @throws AbstractZemucanException
407      *             Never.
408      */
409     @Test
410     public void testCreateTableCommand2() throws AbstractZemucanException {
411         final String cmdIn = "create table"; //$NON-NLS-1$
412 
413         final String phrase1 = "tablespace"; //$NON-NLS-1$
414 
415         final ReturnOptions ret = ImplementationLexicalAnalyzer.getInstance()
416                 .analyzePhrase(cmdIn);
417         final String[] actual = ret.getPhrases();
418 
419         final String[] expected = new String[] { phrase1 };
420 
421         Assert.assertEquals("phrases for 'create table'", //$NON-NLS-1$
422                 expected.length, actual.length);
423     }
424 
425     /**
426      * Test of the options for the 'create table' command. Phrase empty.
427      *
428      * @throws AbstractZemucanException
429      *             Never.
430      */
431     @Test
432     public void testCreateTableCommand3() throws AbstractZemucanException {
433         final String cmdIn = "create table"; //$NON-NLS-1$
434 
435         final String cmdOut = "create table"; //$NON-NLS-1$
436 
437         final ReturnOptions ret = ImplementationLexicalAnalyzer.getInstance()
438                 .analyzePhrase(cmdIn);
439         final String actual = ret.getPhrase();
440 
441         final String expected = cmdOut;
442 
443         Assert.assertEquals("complete for 'create table'", expected, //$NON-NLS-1$
444                 actual);
445     }
446 
447     /**
448      * Test of the options for the 'create table' command.
449      *
450      * @throws AbstractZemucanException
451      *             Never.
452      */
453     @Test
454     public void testCreateTableCommand4() throws AbstractZemucanException {
455         final String cmdIn = "create table"; //$NON-NLS-1$
456 
457         final String cmdOut = "create table"; //$NON-NLS-1$
458 
459         final String phrase1 = "tablespace"; //$NON-NLS-1$
460 
461         final String opt1 = "<tableName>"; //$NON-NLS-1$
462 
463         final ReturnOptions actual = ImplementationLexicalAnalyzer
464                 .getInstance().analyzePhrase(cmdIn);
465 
466         final ReturnOptions expected = new ReturnOptions(cmdOut,
467                 new String[] { phrase1 }, new String[] { opt1 });
468 
469         Assert.assertEquals("object for 'create table'", expected, //$NON-NLS-1$
470                 actual);
471     }
472 
473     /**
474      * Test of the options for the 'create table ' command.
475      *
476      * @throws AbstractZemucanException
477      *             Never.
478      */
479     @Test
480     public void testCreateTableCommand4WithSpace()
481             throws AbstractZemucanException {
482         final String cmdIn = "create table "; //$NON-NLS-1$
483 
484         final String cmdOut = "create table "; //$NON-NLS-1$
485 
486         final String opt1 = "<tableName>"; //$NON-NLS-1$
487 
488         final ReturnOptions actual = ImplementationLexicalAnalyzer
489                 .getInstance().analyzePhrase(cmdIn);
490 
491         final ReturnOptions expected = new ReturnOptions(cmdOut,
492                 new String[] {}, new String[] { opt1 });
493 
494         Assert.assertEquals("object for 'create table '", expected, //$NON-NLS-1$
495                 actual);
496     }
497 
498     /**
499      * Test of the options for the 'create table &lt;tableName&gt;' command.
500      *
501      * @throws AbstractZemucanException
502      *             Never.
503      */
504     @Test
505     public void testCreateTableTableNameCommand()
506             throws AbstractZemucanException {
507         final String cmdIn = "create table t1"; //$NON-NLS-1$
508 
509         final String cmdOut = "create table t1 ("; //$NON-NLS-1$
510 
511         final ReturnOptions actual = ImplementationLexicalAnalyzer
512                 .getInstance().analyzePhrase(cmdIn);
513 
514         final ReturnOptions expected = new ReturnOptions(cmdOut,
515                 new String[] {}, new String[] {});
516 
517         Assert.assertEquals("object for 'create table t1'", expected, //$NON-NLS-1$
518                 actual);
519     }
520 
521     /**
522      * Test of the options for the 'create table &lt;tableName&gt;(' command.
523      * Without space between tableName and command.
524      *
525      * @throws AbstractZemucanException
526      *             Never.
527      */
528     @Test
529     public void testCTtnParenthesis() throws AbstractZemucanException {
530         final String cmdIn = "create table t2("; //$NON-NLS-1$
531         final String cmdOut = "create table t2( "; //$NON-NLS-1$
532         final String opt1 = ImplementationLexicalAnalyzerTest.COL_NAME;
533 
534         final ReturnOptions actual = ImplementationLexicalAnalyzer
535                 .getInstance().analyzePhrase(cmdIn);
536 
537         final ReturnOptions expected = new ReturnOptions(cmdOut,
538                 new String[] {}, new String[] { opt1 });
539 
540         Assert.assertEquals("object for 'create table t2('", expected, //$NON-NLS-1$
541                 actual);
542     }
543 
544     /**
545      * Test of the options for the 'create table &lt;tableName&gt; (' command.
546      * With space between tableName and command.
547      *
548      * @throws AbstractZemucanException
549      *             Never.
550      */
551     @Test
552     public void testCTtnSpaceParenthesis() throws AbstractZemucanException {
553         final String cmdIn = "create table t2 ("; //$NON-NLS-1$
554 
555         final String cmdOut = "create table t2 ( "; //$NON-NLS-1$
556 
557         final String opt1 = ImplementationLexicalAnalyzerTest.COL_NAME;
558 
559         final ReturnOptions actual = ImplementationLexicalAnalyzer
560                 .getInstance().analyzePhrase(cmdIn);
561 
562         final ReturnOptions expected = new ReturnOptions(cmdOut,
563                 new String[] {}, new String[] { opt1 });
564 
565         Assert.assertEquals("object for 'create table t2 ('", expected, //$NON-NLS-1$
566                 actual);
567     }
568 
569     /**
570      * Test of the options for the 'create table &lt;tableName&gt; ( ' command.
571      * With space between tableName and command.
572      *
573      * @throws AbstractZemucanException
574      *             Never.
575      */
576     @Test
577     public void testCTtnSpaceParenthesisWithSpace()
578             throws AbstractZemucanException {
579         final String cmdIn = "create table t2 ( "; //$NON-NLS-1$
580 
581         final String cmdOut = "create table t2 ( "; //$NON-NLS-1$
582 
583         final String opt1 = ImplementationLexicalAnalyzerTest.COL_NAME;
584 
585         final ReturnOptions actual = ImplementationLexicalAnalyzer
586                 .getInstance().analyzePhrase(cmdIn);
587 
588         final ReturnOptions expected = new ReturnOptions(cmdOut,
589                 new String[] {}, new String[] { opt1 });
590 
591         Assert.assertEquals("object for 'create table t2 ('", expected, //$NON-NLS-1$
592                 actual);
593     }
594 
595     /**
596      * Test of the options for the 'create table t2(c1' command.
597      *
598      * @throws AbstractZemucanException
599      *             Never.
600      */
601     @Test
602     public void testDataType() throws AbstractZemucanException {
603         final String cmdIn = "create table t2(c1"; //$NON-NLS-1$
604 
605         final String cmdOut = "create table t2(c1 "; //$NON-NLS-1$
606 
607         final String option1 = "int"; //$NON-NLS-1$
608         final String option2 = "char"; //$NON-NLS-1$
609 
610         final ReturnOptions actual = ImplementationLexicalAnalyzer
611                 .getInstance().analyzePhrase(cmdIn);
612 
613         final ReturnOptions expected = new ReturnOptions(cmdOut,
614                 new String[] {}, new String[] { option1, option2 });
615 
616         Assert.assertEquals("object for 'create table t2(c1'", expected, //$NON-NLS-1$
617                 actual);
618     }
619 
620     /**
621      * The string with two spaces returns a string empty.
622      *
623      * @throws AbstractZemucanException
624      *             Never.
625      */
626     @Test
627     public void testDoubleSpace() throws AbstractZemucanException {
628         final String cmdIn = ImplementationLexicalAnalyzerTest.SPACE
629                 + ImplementationLexicalAnalyzerTest.SPACE;
630 
631         final String cmdOut = ""; //$NON-NLS-1$
632 
633         final ReturnOptions ret = ImplementationLexicalAnalyzer.getInstance()
634                 .analyzePhrase(cmdIn);
635         final String actual = ret.getPhrase();
636 
637         final String expected = cmdOut;
638 
639         Assert.assertEquals("Empty phrase for an space", expected, //$NON-NLS-1$
640                 actual);
641     }
642 
643     /**
644      * Empty string as a command gives also a completed phrase empty.
645      *
646      * @throws AbstractZemucanException
647      *             Never
648      */
649     @Test
650     public void testEmptyString1() throws AbstractZemucanException {
651         final String cmdIn = ""; //$NON-NLS-1$
652 
653         final String cmdOut = ""; //$NON-NLS-1$
654 
655         final ReturnOptions ret = ImplementationLexicalAnalyzer.getInstance()
656                 .analyzePhrase(cmdIn);
657         final String actual = ret.getPhrase();
658 
659         final String expected = cmdOut;
660 
661         Assert.assertEquals("Return Empty phrase", expected, actual); //$NON-NLS-1$
662     }
663 
664     /**
665      * Empty string as a command gives a set of options different to zero. At
666      * least, the grammar has to have one option.
667      * <p>
668      * If the grammar was not defined is it possible to return zero options,
669      * however this is not a normal case.
670      *
671      * @throws AbstractZemucanException
672      *             Never.
673      */
674     @Test
675     public void testEmptyString2() throws AbstractZemucanException {
676         final String cmdIn = ""; //$NON-NLS-1$
677 
678         final ReturnOptions actual = ImplementationLexicalAnalyzer
679                 .getInstance().analyzePhrase(cmdIn);
680 
681         final boolean condition = 0 < actual.getOptions().length;
682 
683         Assert.assertTrue("Zero options for an empty phrase", //$NON-NLS-1$
684                 condition);
685     }
686 
687     /**
688      * An empty string does not have several way of phrases.
689      *
690      * @throws AbstractZemucanException
691      *             Never.
692      */
693     @Test
694     public void testEmptyString3() throws AbstractZemucanException {
695         final String cmdIn = ""; //$NON-NLS-1$
696 
697         final ReturnOptions actual = ImplementationLexicalAnalyzer
698                 .getInstance().analyzePhrase(cmdIn);
699 
700         Assert.assertEquals("Zero phrases for an empty phrase", 0, //$NON-NLS-1$
701                 actual.getPhrases().length);
702     }
703 
704     /**
705      * Invalid, no options.
706      *
707      * @throws AbstractZemucanException
708      *             Never.
709      */
710     @Test
711     public void testInvalidCommand1() throws AbstractZemucanException {
712         final String cmdIn = "create table t1 (c1 int char)"; //$NON-NLS-1$
713 
714         final String cmdOut = "create table t1 (c1 int char)"; //$NON-NLS-1$
715 
716         final ReturnOptions actual = ImplementationLexicalAnalyzer
717                 .getInstance().analyzePhrase(cmdIn);
718 
719         final ReturnOptions expected = new ReturnOptions(cmdOut,
720                 new String[] {}, new String[] {});
721 
722         Assert.assertEquals("object for 'create table t1 (c1 int char)'", //$NON-NLS-1$
723                 expected, actual);
724     }
725 
726     /**
727      * Invalid, no options.
728      *
729      * @throws AbstractZemucanException
730      *             Never.
731      */
732     @Test
733     public void testInvalidCommand2() throws AbstractZemucanException {
734         final String cmdIn = "Andres Gomez Casanova"; //$NON-NLS-1$
735 
736         final String cmdOut = "Andres Gomez Casanova"; //$NON-NLS-1$
737 
738         final ReturnOptions actual = ImplementationLexicalAnalyzer
739                 .getInstance().analyzePhrase(cmdIn);
740 
741         final ReturnOptions expected = new ReturnOptions(cmdOut,
742                 new String[] {}, new String[] {});
743 
744         Assert.assertEquals("object for 'Andres Gomez Casanova'", //$NON-NLS-1$
745                 expected, actual);
746     }
747 
748     /**
749      * Tries to add a null answer.
750      *
751      * @throws AbstractZemucanException
752      *             Never.
753      */
754     @Test(expected = AssertionError.class)
755     public void testNullAnswerReplacetoken()
756             throws AbstractZemucanException {
757         ImplementationLexicalAnalyzer.getInstance().replaceLastToken("", //$NON-NLS-1$
758                 new ArrayList<Token>(), null);
759     }
760 
761     /**
762      * Tests that a phrase cannot be null.
763      *
764      * @throws AbstractZemucanException
765      *             Never.
766      */
767     @Test(expected = AssertionError.class)
768     public void testNullPhrase() throws AbstractZemucanException {
769         ImplementationLexicalAnalyzer.getInstance().analyzePhrase(null);
770     }
771 
772     /**
773      * Tries to add a null phrase.
774      *
775      * @throws AbstractZemucanException
776      *             Never.
777      */
778     @Test(expected = AssertionError.class)
779     public void testNullPhraseReplacetoken()
780             throws AbstractZemucanException {
781         ImplementationLexicalAnalyzer.getInstance().replaceLastToken(null,
782                 new ArrayList<Token>(), "");
783     }
784 
785     /**
786      * Tries to add a null in the list of tokens.
787      *
788      * @throws AbstractZemucanException
789      *             Never.
790      */
791     @Test(expected = AssertionError.class)
792     public void testNullTokenInTokensReplacetoken()
793             throws AbstractZemucanException {
794         final List<Token> tokens = new ArrayList<Token>();
795         tokens.add(null);
796         ImplementationLexicalAnalyzer.getInstance().replaceLastToken("", //$NON-NLS-1$
797                 tokens, "");
798     }
799 
800     /**
801      * Tries to add a null list of tokens.
802      *
803      * @throws AbstractZemucanException
804      *             Never.
805      */
806     @Test(expected = AssertionError.class)
807     public void testNullTokensReplacetoken()
808             throws AbstractZemucanException {
809         ImplementationLexicalAnalyzer.getInstance().replaceLastToken("", //$NON-NLS-1$
810                 null, "");
811     }
812 
813     /**
814      * Test of the options for the 'create table t1 (c1 int, c2 char(' command.
815      *
816      * @throws AbstractZemucanException
817      *             Never.
818      */
819     @Test
820     public void testPrecision() throws AbstractZemucanException {
821         final String cmdIn = "create table t1 (c1 int, c2 char("; //$NON-NLS-1$
822 
823         final String cmdOut = "create table t1 (c1 int, c2 char( "; //$NON-NLS-1$
824 
825         final String option1 = "<charTypeValue>"; //$NON-NLS-1$
826 
827         final ReturnOptions actual = ImplementationLexicalAnalyzer
828                 .getInstance().analyzePhrase(cmdIn);
829 
830         final ReturnOptions expected = new ReturnOptions(cmdOut,
831                 new String[] {}, new String[] { option1 });
832 
833         Assert.assertEquals("object for 'create table t1 (c1 int, c2 char('", //$NON-NLS-1$
834                 expected, actual);
835     }
836 
837     /**
838      * Test of the options for the 'create table t2(c1 int,' command.
839      *
840      * @throws AbstractZemucanException
841      *             Never.
842      */
843     @Test
844     public void testSecondColumn() throws AbstractZemucanException {
845         final String cmdIn = "create table t2(c1 int,"; //$NON-NLS-1$
846 
847         final String cmdOut = "create table t2(c1 int, "; //$NON-NLS-1$
848 
849         final String option = ImplementationLexicalAnalyzerTest.COL_NAME;
850 
851         final ReturnOptions actual = ImplementationLexicalAnalyzer
852                 .getInstance().analyzePhrase(cmdIn);
853 
854         final ReturnOptions expected = new ReturnOptions(cmdOut,
855                 new String[] {}, new String[] { option });
856 
857         Assert.assertEquals("object for create table t2(c1 int,'", //$NON-NLS-1$
858                 expected, actual);
859     }
860 
861     /**
862      * Test of the options for the 'create table t1 (c1 int, c2 char(10)'
863      * command.
864      *
865      * @throws AbstractZemucanException
866      *             Never.
867      */
868     @Test
869     public void testSeveralOptionsAfterColumn()
870             throws AbstractZemucanException {
871         final String cmdIn = "create table t1 (c1 int, c2 char(10)"; //$NON-NLS-1$
872 
873         final String cmdOut = "create table t1 (c1 int, c2 char(10) "; //$NON-NLS-1$
874 
875         final String option1 = ","; //$NON-NLS-1$
876         final String option2 = ImplementationLexicalAnalyzerTest.CLOSE_PARENTHESIS;
877 
878         final ReturnOptions actual = ImplementationLexicalAnalyzer
879                 .getInstance().analyzePhrase(cmdIn);
880 
881         final ReturnOptions expected = new ReturnOptions(cmdOut,
882                 new String[] {}, new String[] { option1, option2 });
883 
884         Assert.assertEquals(
885                 "object for 'create table t1 (c1 int, c2 char(10)'", //$NON-NLS-1$
886                 expected, actual);
887     }
888 
889     /**
890      * The string with just one space returns a string empty.
891      *
892      * @throws AbstractZemucanException
893      *             Never.
894      */
895     @Test
896     public void testSpace1() throws AbstractZemucanException {
897         final String cmdIn = ImplementationLexicalAnalyzerTest.SPACE;
898 
899         final String cmdOut = ""; //$NON-NLS-1$
900 
901         final ReturnOptions ret = ImplementationLexicalAnalyzer.getInstance()
902                 .analyzePhrase(cmdIn);
903         final String actual = ret.getPhrase();
904 
905         final String expected = cmdOut;
906 
907         Assert.assertEquals("Empty phrase for an space", expected, //$NON-NLS-1$
908                 actual);
909     }
910 
911     /**
912      * The string with just one space returns a string with one space also.
913      *
914      * @throws AbstractZemucanException
915      *             Never.
916      */
917     @Test
918     public void testSpace2() throws AbstractZemucanException {
919         final String cmdIn = ImplementationLexicalAnalyzerTest.SPACE;
920 
921         final ReturnOptions actual = ImplementationLexicalAnalyzer
922                 .getInstance().analyzePhrase(cmdIn);
923 
924         final boolean condition = 0 < actual.getOptions().length;
925 
926         Assert.assertTrue("Several options for a space", //$NON-NLS-1$
927                 condition);
928     }
929 
930     /**
931      * An space does not have several ways of phrases.
932      *
933      * @throws AbstractZemucanException
934      *             Never.
935      */
936     @Test
937     public void testSpace3() throws AbstractZemucanException {
938         final String cmdIn = ImplementationLexicalAnalyzerTest.SPACE;
939 
940         final ReturnOptions actual = ImplementationLexicalAnalyzer
941                 .getInstance().analyzePhrase(cmdIn);
942 
943         Assert.assertEquals("Zero phrases for a space", 0, //$NON-NLS-1$
944                 actual.getPhrases().length);
945     }
946 
947     /**
948      * Test of the options for the 'create table t1 (c1 int)' command.
949      *
950      * @throws AbstractZemucanException
951      *             Never.
952      */
953     @Test
954     public void testValidCommand1() throws AbstractZemucanException {
955         final String cmdIn = "create table t1 (c1 int)"; //$NON-NLS-1$
956 
957         final String cmdOut = "create table t1 (c1 int)"; //$NON-NLS-1$
958 
959         final ReturnOptions actual = ImplementationLexicalAnalyzer
960                 .getInstance().analyzePhrase(cmdIn);
961 
962         final ReturnOptions expected = new ReturnOptions(cmdOut,
963                 new String[] {}, new String[] {});
964 
965         Assert.assertEquals("object for 'create table t1 (c1 int)'", //$NON-NLS-1$
966                 expected, actual);
967     }
968 
969     /**
970      * Test of the options for the 'create table t1 (c1 int, c2 char(10))'
971      * command.
972      *
973      * @throws AbstractZemucanException
974      *             Never.
975      */
976     @Test
977     public void testValidCommand2() throws AbstractZemucanException {
978         final String cmdIn = "create table t1 (c1 int, c2 char(10))"; //$NON-NLS-1$
979 
980         final String cmdOut = "create table t1 (c1 int, c2 char(10))"; //$NON-NLS-1$
981 
982         final ReturnOptions actual = ImplementationLexicalAnalyzer
983                 .getInstance().analyzePhrase(cmdIn);
984 
985         final ReturnOptions expected = new ReturnOptions(cmdOut,
986                 new String[] {}, new String[] {});
987 
988         Assert.assertEquals(
989                 "object for 'create table t1 (c1 int, c2 char(10))'", //$NON-NLS-1$
990                 expected, actual);
991     }
992 }