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/ImplementationLexicalAnalyzerRealGrammarTest.java $:
28   */
29  package name.angoca.zemucan.core.lexical.impl;
30  
31  import name.angoca.zemucan.AbstractZemucanException;
32  import name.angoca.zemucan.grammarReader.api.GrammarReaderController;
33  import name.angoca.zemucan.interfaze.model.ReturnOptions;
34  import name.angoca.zemucan.tools.Constants;
35  import name.angoca.zemucan.tools.configurator.Configurator;
36  import name.angoca.zemucan.tools.test.RandomTestRunner;
37  
38  import org.junit.AfterClass;
39  import org.junit.Assert;
40  import org.junit.BeforeClass;
41  import org.junit.Test;
42  import org.junit.runner.RunWith;
43  
44  /**
45   * This is the set of test for the lexical analyzer. The inputs are phrases that
46   * represents the user's command, they are received like strings and this class
47   * tests its conversion to Tokens and analyze the results.
48   * <p>
49   * <b>Control Version</b>
50   * <p>
51   * <ul>
52   * <li>1.0.0 Class creation.</li>
53   * <li>1.1.0 More tests and TO-DOs.</li>
54   * <li>1.2.0 Same tests as in jLine.</li>
55   * <li>1.3.0 9 cases that describe all possible ways.</li>
56   * <li>1.3.1 Before and after junit methods</li>
57   * </ul>
58   *
59   * @author Andres Gomez Casanova <a
60   *         href="mailto:a n g o c a at y a h o o dot c o m" >(AngocA)</a>
61   * @version 1.3.1 2010-09-25
62   */
63  @RunWith(RandomTestRunner.class)
64  public final class ImplementationLexicalAnalyzerRealGrammarTest {
65  
66      /**
67       * Load the graph.
68       *
69       * @throws AbstractZemucanException
70       *             Never
71       */
72      @BeforeClass
73      public static void setUpBeforeClass() throws AbstractZemucanException {
74          System.setProperty(Constants.ZEMUCAN_CONF_XML_PROPERTY,
75                  "sa_conf-test-realGrammar.xml"); //$NON-NLS-1$
76          Configurator.getInstance().setProperty(
77                  Constants.GRAMMAR_READER_NAME_PROPERTY,
78                  Configurator.GRAMMAR_READER_NAME_VALUE);
79  
80          // Creates the Lexical analyzer instance.
81          ImplementationLexicalAnalyzer.getInstance();
82      }
83  
84      /**
85       * Clears the configuration file name property at the end of the test.
86       */
87      @AfterClass
88      public static void tearDownAfterClass() {
89          // Destroy any existent instance.
90          ImplementationLexicalAnalyzer.destroyInstance();
91  
92          // Recreates the configurator instance.
93          Configurator.destroyInstance();
94          GrammarReaderController.destroyInstance();
95          System.clearProperty(Constants.ZEMUCAN_CONF_XML_PROPERTY);
96      }
97  
98      /**
99       * Default constructor.
100      */
101     public ImplementationLexicalAnalyzerRealGrammarTest() {
102         // Nothing.
103     }
104 
105     /**
106      * Tests the command ''
107      *
108      * @throws AbstractZemucanException
109      *             Never.
110      */
111     @Test
112     public void test1() throws AbstractZemucanException {
113         final String cmdIn = ""; //$NON-NLS-1$
114 
115         final ReturnOptions ret = ImplementationLexicalAnalyzer.getInstance()
116                 .analyzePhrase(cmdIn);
117 
118         final String actual = ret.getPhrase();
119 
120         final String expected = "";
121 
122         final int actualOptionsSize = ret.getOptions().length;
123         final int actualPhrasesSize = ret.getPhrases().length;
124         Assert.assertEquals("phrase '" + cmdIn + "'", expected, actual);
125         // ?, about, license, db2, db2ilist, db2auto, db2fm, db2fmcu
126         Assert.assertEquals("options '" + cmdIn + "'", 8, actualOptionsSize);
127         // EMPTY
128         Assert.assertEquals("phrases '" + cmdIn + "'", 0, actualPhrasesSize);
129     }
130 
131     /**
132      * Tests the command 'db2 create'
133      *
134      * @throws AbstractZemucanException
135      *             Never.
136      */
137     @Test
138     public void test10() throws AbstractZemucanException {
139         final String cmdIn = "db2 create"; //$NON-NLS-1$
140 
141         final ReturnOptions ret = ImplementationLexicalAnalyzer.getInstance()
142                 .analyzePhrase(cmdIn);
143 
144         final String actual = ret.getPhrase();
145 
146         final String expected = "db2 create table";
147 
148         Assert.assertEquals("phrase: '" + cmdIn + "'", expected, actual);
149         // table, tablespace
150         Assert.assertTrue("options: '" + cmdIn + "'",
151                 ret.getOptions().length == 2);
152         Assert.assertTrue("phrases: '" + cmdIn + "'",
153                 ret.getPhrases().length == 0);
154     }
155 
156     /**
157      * Tests the command ' db2 create'
158      *
159      * @throws AbstractZemucanException
160      *             Never.
161      */
162     @Test
163     public void test10a() throws AbstractZemucanException {
164         final String cmdIn = "  db2   create"; //$NON-NLS-1$
165 
166         final ReturnOptions ret = ImplementationLexicalAnalyzer.getInstance()
167                 .analyzePhrase(cmdIn);
168 
169         final String actual = ret.getPhrase();
170 
171         final String expected = "db2   create table";
172 
173         Assert.assertEquals("phrase: '" + cmdIn + "'", expected, actual);
174         // table, tablespace
175         Assert.assertTrue("options: '" + cmdIn + "'",
176                 ret.getOptions().length == 2);
177         Assert.assertTrue("phrases: '" + cmdIn + "'",
178                 ret.getPhrases().length == 0);
179     }
180 
181     /**
182      * Tests the command 'db2 create '
183      *
184      * @throws AbstractZemucanException
185      *             Never.
186      */
187     @Test
188     public void test11() throws AbstractZemucanException {
189         final String cmdIn = "db2 create "; //$NON-NLS-1$
190 
191         final ReturnOptions ret = ImplementationLexicalAnalyzer.getInstance()
192                 .analyzePhrase(cmdIn);
193 
194         final String actual = ret.getPhrase();
195 
196         final String expected = "db2 create table";
197 
198         final int actualOptionsSize = ret.getOptions().length;
199         final int actualPhrasesSize = ret.getPhrases().length;
200         Assert.assertEquals("phrase: '" + cmdIn + "'", expected, actual);
201         // <tableName>
202         Assert.assertEquals("options: '" + cmdIn + "'", 2, actualOptionsSize);
203         // tablespace
204         Assert.assertEquals("phrases: '" + cmdIn + "'", 0, actualPhrasesSize);
205     }
206 
207     /**
208      * Tests the command 'db2 create t'
209      *
210      * @throws AbstractZemucanException
211      *             Never.
212      */
213     @Test
214     public void test12() throws AbstractZemucanException {
215         final String cmdIn = "db2 create t"; //$NON-NLS-1$
216 
217         final ReturnOptions ret = ImplementationLexicalAnalyzer.getInstance()
218                 .analyzePhrase(cmdIn);
219 
220         final String actual = ret.getPhrase();
221 
222         final String expected = "db2 create table";
223 
224         Assert.assertEquals("phrase: '" + cmdIn + "'", expected, actual);
225         Assert.assertTrue("options: '" + cmdIn + "'",
226                 ret.getOptions().length == 0);
227         Assert.assertTrue("phrases: '" + cmdIn + "'",
228                 ret.getPhrases().length == 2);
229     }
230 
231     /**
232      * Tests the command 'db2 create tables'
233      *
234      * @throws AbstractZemucanException
235      *             Never.
236      */
237     @Test
238     public void test13() throws AbstractZemucanException {
239         final String cmdIn = "db2 create tables"; //$NON-NLS-1$
240 
241         final ReturnOptions ret = ImplementationLexicalAnalyzer.getInstance()
242                 .analyzePhrase(cmdIn);
243 
244         final String actual = ret.getPhrase();
245 
246         final String expected = "db2 create tablespace";
247 
248         final int actualOptionsSize = ret.getOptions().length;
249         final int actualPhrasesSize = ret.getPhrases().length;
250         Assert.assertEquals("phrase: '" + cmdIn + "'", expected, actual);
251         Assert.assertEquals("options: '" + cmdIn + "'", 0, actualOptionsSize);
252         Assert.assertEquals("phrases: '" + cmdIn + "'", 0, actualPhrasesSize);
253     }
254 
255     /**
256      * Tests the command 'db2 create tablespace'
257      *
258      * @throws AbstractZemucanException
259      *             Never.
260      */
261     @Test
262     public void test14() throws AbstractZemucanException {
263         final String cmdIn = "db2 create tablespace"; //$NON-NLS-1$
264 
265         final ReturnOptions ret = ImplementationLexicalAnalyzer.getInstance()
266                 .analyzePhrase(cmdIn);
267 
268         final String actual = ret.getPhrase();
269 
270         final String expected = "db2 create tablespace";
271 
272         Assert.assertEquals("phrase: '" + cmdIn + "'", expected, actual);
273         Assert.assertTrue("options: '" + cmdIn + "'",
274                 ret.getOptions().length == 0);
275         Assert.assertTrue("phrases: '" + cmdIn + "'",
276                 ret.getPhrases().length == 0);
277     }
278 
279     /**
280      * Tests the command 'db2 create ta'
281      *
282      * @throws AbstractZemucanException
283      *             Never.
284      */
285     @Test
286     public void test15() throws AbstractZemucanException {
287         final String cmdIn = "db2 create ta"; //$NON-NLS-1$
288 
289         final ReturnOptions ret = ImplementationLexicalAnalyzer.getInstance()
290                 .analyzePhrase(cmdIn);
291 
292         final String actual = ret.getPhrase();
293 
294         final String expected = "db2 create table";
295 
296         Assert.assertEquals("phrase: '" + cmdIn + "'", expected, actual);
297         Assert.assertTrue("options: '" + cmdIn + "'",
298                 ret.getOptions().length == 0);
299         Assert.assertTrue("phrases: '" + cmdIn + "'",
300                 ret.getPhrases().length == 2);
301     }
302 
303     /**
304      * Tests the command 'db2 create table'
305      *
306      * @throws AbstractZemucanException
307      *             Never.
308      */
309     @Test
310     public void test16() throws AbstractZemucanException {
311         final String cmdIn = "db2 create table"; //$NON-NLS-1$
312 
313         final ReturnOptions ret = ImplementationLexicalAnalyzer.getInstance()
314                 .analyzePhrase(cmdIn);
315 
316         final String actual = ret.getPhrase();
317 
318         final String expected = "db2 create table";
319 
320         Assert.assertEquals("phrase: '" + cmdIn + "'", expected, actual);
321         // <tableName>
322         Assert.assertTrue("options: '" + cmdIn + "'",
323                 ret.getOptions().length == 1);
324         Assert.assertTrue("phrases: '" + cmdIn + "'",
325                 ret.getPhrases().length == 1);
326     }
327 
328     /**
329      * Tests the command 'db2 create table '
330      *
331      * @throws AbstractZemucanException
332      *             Never.
333      */
334     @Test
335     public void test17() throws AbstractZemucanException {
336         final String cmdIn = "db2 create table "; //$NON-NLS-1$
337 
338         final ReturnOptions ret = ImplementationLexicalAnalyzer.getInstance()
339                 .analyzePhrase(cmdIn);
340 
341         final String actual = ret.getPhrase();
342 
343         final String expected = "db2 create table ";
344 
345         Assert.assertEquals("phrase: '" + cmdIn + "'", expected, actual);
346         // <tableName>
347         Assert.assertTrue("options: '" + cmdIn + "'",
348                 ret.getOptions().length == 1);
349         Assert.assertTrue("phrases: '" + cmdIn + "'",
350                 ret.getPhrases().length == 0);
351     }
352 
353     /**
354      * Tests the command 'db2 create table t1'
355      *
356      * @throws AbstractZemucanException
357      *             Never.
358      */
359     @Test
360     public void test18() throws AbstractZemucanException {
361         final String cmdIn = "db2 create table t1"; //$NON-NLS-1$
362 
363         final ReturnOptions ret = ImplementationLexicalAnalyzer.getInstance()
364                 .analyzePhrase(cmdIn);
365 
366         final String actual = ret.getPhrase();
367 
368         final String expected = "db2 create table t1 (";
369 
370         Assert.assertEquals("phrase: '" + cmdIn + "'", expected, actual);
371         Assert.assertTrue("options: '" + cmdIn + "'",
372                 ret.getOptions().length == 0);
373         Assert.assertTrue("phrases: '" + cmdIn + "'",
374                 ret.getPhrases().length == 0);
375     }
376 
377     /**
378      * Tests the command 'db2 create table t1 '
379      *
380      * @throws AbstractZemucanException
381      *             Never.
382      */
383     @Test
384     public void test19() throws AbstractZemucanException {
385         final String cmdIn = "db2 create table t1 "; //$NON-NLS-1$
386 
387         final ReturnOptions ret = ImplementationLexicalAnalyzer.getInstance()
388                 .analyzePhrase(cmdIn);
389 
390         final String actual = ret.getPhrase();
391 
392         final String expected = "db2 create table t1 (";
393 
394         Assert.assertEquals("phrase: '" + cmdIn + "'", expected, actual);
395         Assert.assertTrue("options: '" + cmdIn + "'",
396                 ret.getOptions().length == 0);
397         Assert.assertTrue("phrases: '" + cmdIn + "'",
398                 ret.getPhrases().length == 0);
399     }
400 
401     /**
402      * Tests the command 'd'
403      *
404      * @throws AbstractZemucanException
405      *             Never.
406      */
407     @Test
408     public void test2() throws AbstractZemucanException {
409         final String cmdIn = "d"; //$NON-NLS-1$
410 
411         final ReturnOptions ret = ImplementationLexicalAnalyzer.getInstance()
412                 .analyzePhrase(cmdIn);
413 
414         final String actual = ret.getPhrase();
415 
416         final String expected = "db2";
417 
418         final int actualOptionsSize = ret.getOptions().length;
419         final int actualPhrasesSize = ret.getPhrases().length;
420         Assert.assertEquals("phrase '" + cmdIn + "'", expected, actual);
421         // EMPTY
422         Assert.assertEquals("options '" + cmdIn + "'", 0, actualOptionsSize);
423         // db2, db2ilist, db2auto, db2fm, db2fmcu
424         Assert.assertEquals("phrases '" + cmdIn + "'", 5, actualPhrasesSize);
425     }
426 
427     /**
428      * Tests the command 'db2 create table t1 ('
429      *
430      * @throws AbstractZemucanException
431      *             Never.
432      */
433     @Test
434     public void test20() throws AbstractZemucanException {
435         final String cmdIn = "db2 create table t1 ("; //$NON-NLS-1$
436 
437         final ReturnOptions ret = ImplementationLexicalAnalyzer.getInstance()
438                 .analyzePhrase(cmdIn);
439 
440         final String actual = ret.getPhrase();
441 
442         final String expected = "db2 create table t1 ( ";
443 
444         Assert.assertEquals("phrase: '" + cmdIn + "'", expected, actual);
445         Assert.assertTrue("options: '" + cmdIn + "'",
446                 ret.getOptions().length == 1);
447         Assert.assertTrue("phrases: '" + cmdIn + "'",
448                 ret.getPhrases().length == 0);
449     }
450 
451     /**
452      * Tests the command 'db2 create table t1('
453      *
454      * @throws AbstractZemucanException
455      *             Never.
456      */
457     @Test
458     public void test21() throws AbstractZemucanException {
459         final String cmdIn = "db2 create table t1("; //$NON-NLS-1$
460 
461         final ReturnOptions ret = ImplementationLexicalAnalyzer.getInstance()
462                 .analyzePhrase(cmdIn);
463 
464         final String actual = ret.getPhrase();
465 
466         final String expected = "db2 create table t1( ";
467 
468         Assert.assertEquals("phrase: '" + cmdIn + "'", expected, actual);
469         // <colName>
470         Assert.assertTrue("options: '" + cmdIn + "'",
471                 ret.getOptions().length == 1);
472         Assert.assertTrue("phrases: '" + cmdIn + "'",
473                 ret.getPhrases().length == 0);
474     }
475 
476     /**
477      * Tests the command 'db2 create table t1 (c1'
478      *
479      * @throws AbstractZemucanException
480      *             Never.
481      */
482     @Test
483     public void test22() throws AbstractZemucanException {
484         final String cmdIn = "db2 create table t1 (c1"; //$NON-NLS-1$
485 
486         final ReturnOptions ret = ImplementationLexicalAnalyzer.getInstance()
487                 .analyzePhrase(cmdIn);
488 
489         final String actual = ret.getPhrase();
490 
491         final String expected = "db2 create table t1 (c1 ";
492 
493         Assert.assertEquals("phrase: '" + cmdIn + "'", expected, actual);
494         // int, char
495         Assert.assertTrue("options: '" + cmdIn + "'",
496                 ret.getOptions().length == 2);
497         Assert.assertTrue("phrases: '" + cmdIn + "'",
498                 ret.getPhrases().length == 0);
499     }
500 
501     /**
502      * Tests the command 'db2 create table t1( c1'
503      *
504      * @throws AbstractZemucanException
505      *             Never.
506      */
507     @Test
508     public void test23() throws AbstractZemucanException {
509         final String cmdIn = "db2 create table t1( c1"; //$NON-NLS-1$
510 
511         final ReturnOptions ret = ImplementationLexicalAnalyzer.getInstance()
512                 .analyzePhrase(cmdIn);
513 
514         final String actual = ret.getPhrase();
515 
516         final String expected = "db2 create table t1( c1 ";
517 
518         Assert.assertEquals("phrase: '" + cmdIn + "'", expected, actual);
519         // int, char
520         Assert.assertTrue("options: '" + cmdIn + "'",
521                 ret.getOptions().length == 2);
522         Assert.assertTrue("phrases: '" + cmdIn + "'",
523                 ret.getPhrases().length == 0);
524     }
525 
526     /**
527      * Tests the command 'db2 create table t1 ( c1 int )'
528      *
529      * @throws AbstractZemucanException
530      *             Never.
531      */
532     @Test
533     public void test24() throws AbstractZemucanException {
534         final String cmdIn = "db2 create table t1 ( c1 int )"; //$NON-NLS-1$
535 
536         final ReturnOptions ret = ImplementationLexicalAnalyzer.getInstance()
537                 .analyzePhrase(cmdIn);
538 
539         final String actual = ret.getPhrase();
540 
541         final String expected = "db2 create table t1 ( c1 int )";
542 
543         Assert.assertEquals("phrase: '" + cmdIn + "'", expected, actual);
544         Assert.assertTrue("options: '" + cmdIn + "'",
545                 ret.getOptions().length == 0);
546         Assert.assertTrue("phrases: '" + cmdIn + "'",
547                 ret.getPhrases().length == 0);
548     }
549 
550     /**
551      * Tests the command ' db2'
552      *
553      * @throws AbstractZemucanException
554      *             Never.
555      */
556     @Test
557     public void test25() throws AbstractZemucanException {
558         final String cmdIn = " db2"; //$NON-NLS-1$
559 
560         final ReturnOptions ret = ImplementationLexicalAnalyzer.getInstance()
561                 .analyzePhrase(cmdIn);
562 
563         final String actual = ret.getPhrase();
564 
565         final String expected = "db2";
566 
567         final int actualOptionsSize = ret.getOptions().length;
568         final int actualPhrasesSize = ret.getPhrases().length;
569         Assert.assertEquals("phrase: '" + cmdIn + "'", expected, actual);
570         // catalog, create, attach
571         Assert.assertEquals("options: '" + cmdIn + "'", 3, actualOptionsSize);
572         // db2ilist, db2auto, db2fm, db2fmcu
573         Assert.assertEquals("phrases: '" + cmdIn + "'", 4, actualPhrasesSize);
574     }
575 
576     /**
577      * Tests the command ' db2'
578      *
579      * @throws AbstractZemucanException
580      *             Never.
581      */
582     @Test
583     public void test25a() throws AbstractZemucanException {
584         final String cmdIn = "  db2"; //$NON-NLS-1$
585 
586         final ReturnOptions ret = ImplementationLexicalAnalyzer.getInstance()
587                 .analyzePhrase(cmdIn);
588 
589         final String actual = ret.getPhrase();
590 
591         final String expected = "db2";
592 
593         final int actualOptionsSize = ret.getOptions().length;
594         final int actualPhrasesSize = ret.getPhrases().length;
595         Assert.assertEquals("phrase: '" + cmdIn + "'", expected, actual);
596         // catalog, create, attach
597         Assert.assertEquals("options: '" + cmdIn + "'", 3, actualOptionsSize);
598         // db2ilist, db2auto, db2fm, db2fmcu
599         Assert.assertEquals("phrases: '" + cmdIn + "'", 4, actualPhrasesSize);
600     }
601 
602     /**
603      * Tests the command 'DB'
604      *
605      * @throws AbstractZemucanException
606      *             Never.
607      */
608     @Test
609     public void test26() throws AbstractZemucanException {
610         final String cmdIn = "DB"; //$NON-NLS-1$
611 
612         final ReturnOptions ret = ImplementationLexicalAnalyzer.getInstance()
613                 .analyzePhrase(cmdIn);
614 
615         final String actual = ret.getPhrase();
616 
617         final String expected = "db2";
618 
619         final int actualOptionsSize = ret.getOptions().length;
620         final int actualPhrasesSize = ret.getPhrases().length;
621         Assert.assertEquals("phrase: '" + cmdIn + "'", expected, actual);
622         // EMPTY
623         Assert.assertEquals("options: '" + cmdIn + "'", 0, actualOptionsSize);
624         // db2ilist, db2auto, db2fm, db2fmcu, db2
625         Assert.assertEquals("phrases: '" + cmdIn + "'", 5, actualPhrasesSize);
626     }
627 
628     /**
629      * Tests the command ' DB'
630      *
631      * @throws AbstractZemucanException
632      *             Never.
633      */
634     @Test
635     public void test26a() throws AbstractZemucanException {
636         final String cmdIn = "  DB"; //$NON-NLS-1$
637 
638         final ReturnOptions ret = ImplementationLexicalAnalyzer.getInstance()
639                 .analyzePhrase(cmdIn);
640 
641         final String actual = ret.getPhrase();
642 
643         final String expected = "db2";
644 
645         final int actualOptionsSize = ret.getOptions().length;
646         final int actualPhrasesSize = ret.getPhrases().length;
647         Assert.assertEquals("phrase: '" + cmdIn + "'", expected, actual);
648         // db2
649         Assert.assertEquals("options: '" + cmdIn + "'", 0, actualOptionsSize);
650         // db2ilist, db2auto, db2fm, db2fmcu, db2
651         Assert.assertEquals("phrases: '" + cmdIn + "'", 5, actualPhrasesSize);
652     }
653 
654     /**
655      * Tests the command 'DB2 CREA'
656      *
657      * @throws AbstractZemucanException
658      *             Never.
659      */
660     @Test
661     public void test27() throws AbstractZemucanException {
662         final String cmdIn = "DB2 CREA"; //$NON-NLS-1$
663 
664         final ReturnOptions ret = ImplementationLexicalAnalyzer.getInstance()
665                 .analyzePhrase(cmdIn);
666 
667         final String actual = ret.getPhrase();
668 
669         final String expected = "DB2 create";
670 
671         final int actualOptionsSize = ret.getOptions().length;
672         final int actualPhrasesSize = ret.getPhrases().length;
673         Assert.assertEquals("phrase: '" + cmdIn + "'", expected, actual);
674         Assert.assertEquals("options: '" + cmdIn + "'", 0, actualOptionsSize);
675         Assert.assertEquals("phrases: '" + cmdIn + "'", 0, actualPhrasesSize);
676     }
677 
678     /**
679      * Tests the command ' DB2 CREA'
680      *
681      * @throws AbstractZemucanException
682      *             Never.
683      */
684     @Test
685     public void test27A() throws AbstractZemucanException {
686         final String cmdIn = "  DB2  CREA"; //$NON-NLS-1$
687 
688         final ReturnOptions ret = ImplementationLexicalAnalyzer.getInstance()
689                 .analyzePhrase(cmdIn);
690 
691         final String actual = ret.getPhrase();
692 
693         final String expected = "DB2  create";
694 
695         final int actualOptionsSize = ret.getOptions().length;
696         final int actualPhrasesSize = ret.getPhrases().length;
697         Assert.assertEquals("phrase: '" + cmdIn + "'", expected, actual);
698         Assert.assertEquals("options: '" + cmdIn + "'", 0, actualOptionsSize);
699         Assert.assertEquals("phrases: '" + cmdIn + "'", 0, actualPhrasesSize);
700     }
701 
702     /**
703      * Tests the command 'db'
704      *
705      * @throws AbstractZemucanException
706      *             Never.
707      */
708     @Test
709     public void test3() throws AbstractZemucanException {
710         final String cmdIn = "db"; //$NON-NLS-1$
711 
712         final ReturnOptions ret = ImplementationLexicalAnalyzer.getInstance()
713                 .analyzePhrase(cmdIn);
714 
715         final String actual = ret.getPhrase();
716 
717         final String expected = "db2";
718 
719         final int actualOptionsSize = ret.getOptions().length;
720         final int actualPhrasesSize = ret.getPhrases().length;
721         Assert.assertEquals("phrase: '" + cmdIn + "'", expected, actual);
722         // EMPTY
723         Assert.assertEquals("options: '" + cmdIn + "'", 0, actualOptionsSize);
724         // db2, db2ilist, db2auto, db2fm, db2fmcu
725         Assert.assertEquals("phrases: '" + cmdIn + "'", 5, actualPhrasesSize);
726     }
727 
728     /**
729      * Tests the command 'db2'
730      *
731      * @throws AbstractZemucanException
732      *             Never.
733      */
734     @Test
735     public void test4() throws AbstractZemucanException {
736         final String cmdIn = "db2"; //$NON-NLS-1$
737 
738         final ReturnOptions ret = ImplementationLexicalAnalyzer.getInstance()
739                 .analyzePhrase(cmdIn);
740 
741         final String actual = ret.getPhrase();
742 
743         final String expected = "db2";
744 
745         final int actualOptionsSize = ret.getOptions().length;
746         final int actualPhrasesSize = ret.getPhrases().length;
747         Assert.assertEquals("phrase: '" + cmdIn + "'", expected, actual);
748         // catalog, create, attach
749         Assert.assertEquals("options: '" + cmdIn + "'", 3, actualOptionsSize);
750         // db2ilist, db2auto, db2fm, db2fmcu
751         Assert.assertEquals("phrases: '" + cmdIn + "'", 4, actualPhrasesSize);
752     }
753 
754     /**
755      * Tests the command 'db2 '
756      *
757      * @throws AbstractZemucanException
758      *             Never.
759      */
760     @Test
761     public void test5() throws AbstractZemucanException {
762         final String cmdIn = "db2 "; //$NON-NLS-1$
763 
764         final ReturnOptions ret = ImplementationLexicalAnalyzer.getInstance()
765                 .analyzePhrase(cmdIn);
766 
767         final String actual = ret.getPhrase();
768 
769         final String expected = "db2 ";
770 
771         Assert.assertEquals("phrase: '" + cmdIn + "'", expected, actual);
772         // catalog, create, attach
773         Assert.assertTrue("options: '" + cmdIn + "'",
774                 ret.getOptions().length == 3);
775         Assert.assertTrue("phrases: '" + cmdIn + "'",
776                 ret.getPhrases().length == 0);
777     }
778 
779     /**
780      * Tests the command 'db2 '
781      *
782      * @throws AbstractZemucanException
783      *             Never.
784      */
785     @Test
786     public void test5a() throws AbstractZemucanException {
787         final String cmdIn = "db2  "; //$NON-NLS-1$
788 
789         final ReturnOptions ret = ImplementationLexicalAnalyzer.getInstance()
790                 .analyzePhrase(cmdIn);
791 
792         final String actual = ret.getPhrase();
793 
794         final String expected = "db2 ";
795 
796         Assert.assertEquals("phrase: '" + cmdIn + "'", expected, actual);
797         // catalog, create, attach
798         Assert.assertTrue("options: '" + cmdIn + "'",
799                 ret.getOptions().length == 3);
800         Assert.assertTrue("phrases: '" + cmdIn + "'",
801                 ret.getPhrases().length == 0);
802     }
803 
804     /**
805      * Tests the command 'db2 c'
806      *
807      * @throws AbstractZemucanException
808      *             Never.
809      */
810     @Test
811     public void test6() throws AbstractZemucanException {
812         final String cmdIn = "db2 a"; //$NON-NLS-1$
813 
814         final ReturnOptions ret = ImplementationLexicalAnalyzer.getInstance()
815                 .analyzePhrase(cmdIn);
816 
817         final String actual = ret.getPhrase();
818 
819         final String expected = "db2 attach";
820 
821         final int actualOptionsSize = ret.getOptions().length;
822         final int actualPhrasesSize = ret.getPhrases().length;
823         Assert.assertEquals("phrase: '" + cmdIn + "'", expected, actual);
824         Assert.assertEquals("options: '" + cmdIn + "'", 0, actualOptionsSize);
825         Assert.assertEquals("phrases: '" + cmdIn + "'", 0, actualPhrasesSize);
826     }
827 
828     /**
829      * Tests the command 'db2 c'
830      *
831      * @throws AbstractZemucanException
832      *             Never.
833      */
834     @Test
835     public void test6a() throws AbstractZemucanException {
836         final String cmdIn = "db2 c"; //$NON-NLS-1$
837 
838         final ReturnOptions ret = ImplementationLexicalAnalyzer.getInstance()
839                 .analyzePhrase(cmdIn);
840 
841         final String actual = ret.getPhrase();
842 
843         final String expected = "db2 c";
844 
845         Assert.assertEquals("phrase: '" + cmdIn + "'", expected, actual);
846         Assert.assertTrue("options: '" + cmdIn + "'",
847                 ret.getOptions().length == 0);
848         Assert.assertTrue("phrases: '" + cmdIn + "'",
849                 ret.getPhrases().length == 2);
850     }
851 
852     // TODO v2.0 tests "db2 update db" AquĆ­ se usan alias y no
853     // funciona
854 
855     /**
856      * Tests the command 'db2 c'
857      *
858      * @throws AbstractZemucanException
859      *             Never.
860      */
861     @Test
862     public void test7() throws AbstractZemucanException {
863         final String cmdIn = "db2 cr"; //$NON-NLS-1$
864 
865         final ReturnOptions ret = ImplementationLexicalAnalyzer.getInstance()
866                 .analyzePhrase(cmdIn);
867 
868         final String actual = ret.getPhrase();
869 
870         final String expected = "db2 create";
871 
872         final int actualOptionsSize = ret.getOptions().length;
873         final int actualPhrasesSize = ret.getPhrases().length;
874         Assert.assertEquals("phrase: '" + cmdIn + "'", expected, actual);
875         Assert.assertEquals("options: '" + cmdIn + "'", 0, actualOptionsSize);
876         Assert.assertEquals("phrases: '" + cmdIn + "'", 0, actualPhrasesSize);
877     }
878 
879     /**
880      * Tests the command 'db2 crea'
881      *
882      * @throws AbstractZemucanException
883      *             Never.
884      */
885     @Test
886     public void test8() throws AbstractZemucanException {
887         final String cmdIn = "db2 crea"; //$NON-NLS-1$
888 
889         final ReturnOptions ret = ImplementationLexicalAnalyzer.getInstance()
890                 .analyzePhrase(cmdIn);
891 
892         final String actual = ret.getPhrase();
893 
894         final String expected = "db2 create";
895 
896         final int actualOptionsSize = ret.getOptions().length;
897         final int actualPhrasesSize = ret.getPhrases().length;
898         Assert.assertEquals("phrase: '" + cmdIn + "'", expected, actual);
899         Assert.assertEquals("options: '" + cmdIn + "'", 0, actualOptionsSize);
900         Assert.assertEquals("phrases: '" + cmdIn + "'", 0, actualPhrasesSize);
901     }
902 
903     /**
904      * Tests the command ' db2 crea'
905      *
906      * @throws AbstractZemucanException
907      *             Never.
908      */
909     @Test
910     public void test8a() throws AbstractZemucanException {
911         final String cmdIn = "  db2   crea"; //$NON-NLS-1$
912 
913         final ReturnOptions ret = ImplementationLexicalAnalyzer.getInstance()
914                 .analyzePhrase(cmdIn);
915 
916         final String actual = ret.getPhrase();
917 
918         final String expected = "db2   create";
919 
920         final int actualOptionsSize = ret.getOptions().length;
921         final int actualPhrasesSize = ret.getPhrases().length;
922         Assert.assertEquals("phrase: '" + cmdIn + "'", expected, actual);
923         Assert.assertEquals("options: '" + cmdIn + "'", 0, actualOptionsSize);
924         Assert.assertEquals("phrases: '" + cmdIn + "'", 0, actualPhrasesSize);
925     }
926 
927     /**
928      * Tests the command 'db2 crea '
929      *
930      * @throws AbstractZemucanException
931      *             Never.
932      */
933     @Test
934     public void test9() throws AbstractZemucanException {
935         final String cmdIn = "db2 crea "; //$NON-NLS-1$
936 
937         final ReturnOptions ret = ImplementationLexicalAnalyzer.getInstance()
938                 .analyzePhrase(cmdIn);
939 
940         final String actual = ret.getPhrase();
941 
942         final String expected = "db2 crea ";
943 
944         Assert.assertEquals("phrase: '" + cmdIn + "'", expected, actual);
945         Assert.assertTrue("options: '" + cmdIn + "'",
946                 ret.getOptions().length == 0);
947         Assert.assertTrue("phrases: '" + cmdIn + "'",
948                 ret.getPhrases().length == 0);
949     }
950 
951     /**
952      * Tests case 1: Multiples phrases and multiples options. command 'db2'
953      *
954      * @throws AbstractZemucanException
955      */
956     @Test
957     public void testCase1() throws AbstractZemucanException {
958         final String cmdIn = "db2"; //$NON-NLS-1$
959 
960         final ReturnOptions ret = ImplementationLexicalAnalyzer.getInstance()
961                 .analyzePhrase(cmdIn);
962 
963         final String actual = ret.getPhrase();
964 
965         final String expected = "db2";
966 
967         final int actualOptionsSize = ret.getOptions().length;
968         final int actualPhrasesSize = ret.getPhrases().length;
969         Assert.assertEquals("phrase: '" + cmdIn + "'", expected, actual);
970         // catalog, create, attach
971         Assert.assertEquals("options: '" + cmdIn + "'", 3, actualOptionsSize);
972         // db2ilist, db2auto, db2fm, db2fmcu
973         Assert.assertEquals("phrases: '" + cmdIn + "'", 4, actualPhrasesSize);
974     }
975 
976     /**
977      * Tests case 2: Multiples phrases and one option. command '???' TODO v1.0
978      * no he encontrado un caso.
979      *
980      * @throws AbstractZemucanException
981      */
982     // TODO v1.0 @Test
983     public void testCase2() throws AbstractZemucanException {
984         final String cmdIn = "???"; //$NON-NLS-1$
985 
986         final ReturnOptions ret = ImplementationLexicalAnalyzer.getInstance()
987                 .analyzePhrase(cmdIn);
988 
989         final String actual = ret.getPhrase();
990 
991         final String expected = "???";
992 
993         final int actualOptionsSize = ret.getOptions().length;
994         final int actualPhrasesSize = ret.getPhrases().length;
995         Assert.assertEquals("phrase: '" + cmdIn + "' TODO", expected, actual);
996         // ????
997         Assert.assertEquals("options: '" + cmdIn + "' TODO", -1,
998                 actualOptionsSize);
999         // ????
1000         Assert.assertEquals("phrases: '" + cmdIn + "' TODO", -1,
1001                 actualPhrasesSize);
1002     }
1003 
1004     /**
1005      * Tests case 3: Multiples phrases and zero options. command 'db2 c'
1006      *
1007      * @throws AbstractZemucanException
1008      */
1009     @Test
1010     public void testCase3() throws AbstractZemucanException {
1011         final String cmdIn = "db2 c"; //$NON-NLS-1$
1012 
1013         final ReturnOptions ret = ImplementationLexicalAnalyzer.getInstance()
1014                 .analyzePhrase(cmdIn);
1015 
1016         final String actual = ret.getPhrase();
1017 
1018         final String expected = "db2 c";
1019 
1020         final int actualOptionsSize = ret.getOptions().length;
1021         final int actualPhrasesSize = ret.getPhrases().length;
1022         Assert.assertEquals("phrase: '" + cmdIn + "'", expected, actual);
1023         Assert.assertEquals("options: '" + cmdIn + "'", 0, actualOptionsSize);
1024         Assert.assertEquals("phrases: '" + cmdIn + "'", 2, actualPhrasesSize);
1025     }
1026 
1027     /**
1028      * Tests case 4: One phrase and multiples options. command 'db2fm'
1029      *
1030      * @throws AbstractZemucanException
1031      */
1032     @Test
1033     public void testCase4() throws AbstractZemucanException {
1034         final String cmdIn = "db2fm"; //$NON-NLS-1$
1035 
1036         final ReturnOptions ret = ImplementationLexicalAnalyzer.getInstance()
1037                 .analyzePhrase(cmdIn);
1038 
1039         final String actual = ret.getPhrase();
1040 
1041         final String expected = "db2fm";
1042 
1043         final int actualOptionsSize = ret.getOptions().length;
1044         final int actualPhrasesSize = ret.getPhrases().length;
1045         Assert.assertEquals("phrase: '" + cmdIn + "'", expected, actual);
1046         // -t, -i
1047         Assert.assertEquals("options: '" + cmdIn + "'", 2, actualOptionsSize);
1048         // db2fmcu
1049         Assert.assertEquals("phrases: '" + cmdIn + "'", 1, actualPhrasesSize);
1050     }
1051 
1052     /**
1053      * Tests case 5: One phrase and one option. command 'db2 create table'
1054      *
1055      * @throws AbstractZemucanException
1056      */
1057     @Test
1058     public void testCase5() throws AbstractZemucanException {
1059         final String cmdIn = "db2 create table"; //$NON-NLS-1$
1060 
1061         final ReturnOptions ret = ImplementationLexicalAnalyzer.getInstance()
1062                 .analyzePhrase(cmdIn);
1063 
1064         final String actual = ret.getPhrase();
1065 
1066         final String expected = "db2 create table";
1067 
1068         final int actualOptionsSize = ret.getOptions().length;
1069         final int actualPhrasesSize = ret.getPhrases().length;
1070         Assert.assertEquals("phrase: '" + cmdIn + "'", expected, actual);
1071         Assert.assertEquals("options: '" + cmdIn + "'", 1, actualOptionsSize);
1072         Assert.assertEquals("phrases: '" + cmdIn + "'", 1, actualPhrasesSize);
1073     }
1074 
1075     /**
1076      * Tests case 6: One phrase and zero options. command 'db2 create tables'
1077      *
1078      * @throws AbstractZemucanException
1079      */
1080     @Test
1081     public void testCase6() throws AbstractZemucanException {
1082         final String cmdIn = "db2 create tables"; //$NON-NLS-1$
1083 
1084         final ReturnOptions ret = ImplementationLexicalAnalyzer.getInstance()
1085                 .analyzePhrase(cmdIn);
1086 
1087         final String actual = ret.getPhrase();
1088 
1089         final String expected = "db2 create tablespace";
1090 
1091         final int actualOptionsSize = ret.getOptions().length;
1092         final int actualPhrasesSize = ret.getPhrases().length;
1093         Assert.assertEquals("phrase: '" + cmdIn + "'", expected, actual);
1094         Assert.assertEquals("options: '" + cmdIn + "'", 0, actualOptionsSize);
1095         // The only option is added in the phrase.
1096         Assert.assertEquals("phrases: '" + cmdIn + "'", 0, actualPhrasesSize);
1097     }
1098 
1099     /**
1100      * Tests case 7: Zero phrases and multiples options. command 'db2 create'
1101      *
1102      * @throws AbstractZemucanException
1103      */
1104     @Test
1105     public void testCase7() throws AbstractZemucanException {
1106         final String cmdIn = "db2 create"; //$NON-NLS-1$
1107 
1108         final ReturnOptions ret = ImplementationLexicalAnalyzer.getInstance()
1109                 .analyzePhrase(cmdIn);
1110 
1111         final String actual = ret.getPhrase();
1112 
1113         final String expected = "db2 create table";
1114 
1115         final int actualOptionsSize = ret.getOptions().length;
1116         final int actualPhrasesSize = ret.getPhrases().length;
1117         Assert.assertEquals("phrase: '" + cmdIn + "'", expected, actual);
1118         Assert.assertEquals("options: '" + cmdIn + "'", 2, actualOptionsSize);
1119         Assert.assertEquals("phrases: '" + cmdIn + "'", 0, actualPhrasesSize);
1120     }
1121 
1122     /**
1123      * Tests case 8: Zero phrases and one option. command 'db2 create table'
1124      *
1125      * @throws AbstractZemucanException
1126      */
1127     @Test
1128     public void testCase8() throws AbstractZemucanException {
1129         final String cmdIn = "db2 create table "; //$NON-NLS-1$
1130 
1131         final ReturnOptions ret = ImplementationLexicalAnalyzer.getInstance()
1132                 .analyzePhrase(cmdIn);
1133 
1134         final String actual = ret.getPhrase();
1135 
1136         final String expected = "db2 create table ";
1137 
1138         final int actualOptionsSize = ret.getOptions().length;
1139         final int actualPhrasesSize = ret.getPhrases().length;
1140         Assert.assertEquals("phrase: '" + cmdIn + "'", expected, actual);
1141         Assert.assertEquals("options: '" + cmdIn + "'", 1, actualOptionsSize);
1142         Assert.assertEquals("phrases: '" + cmdIn + "'", 0, actualPhrasesSize);
1143     }
1144 
1145     /**
1146      * Tests case 9: Zero phrases and zero options. command 'db2 create
1147      * tablespace'
1148      *
1149      * @throws AbstractZemucanException
1150      */
1151     @Test
1152     public void testCase9() throws AbstractZemucanException {
1153         final String cmdIn = "db2 create tablespace"; //$NON-NLS-1$
1154 
1155         final ReturnOptions ret = ImplementationLexicalAnalyzer.getInstance()
1156                 .analyzePhrase(cmdIn);
1157 
1158         final String actual = ret.getPhrase();
1159 
1160         final String expected = "db2 create tablespace";
1161 
1162         final int actualOptionsSize = ret.getOptions().length;
1163         final int actualPhrasesSize = ret.getPhrases().length;
1164         Assert.assertEquals("phrase: '" + cmdIn + "'", expected, actual);
1165         Assert.assertEquals("options: '" + cmdIn + "'", 0, actualOptionsSize);
1166         Assert.assertEquals("phrases: '" + cmdIn + "'", 0, actualPhrasesSize);
1167     }
1168 }