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/ImplementationLexicalAnalyzerAcceptanceTest.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
37 import org.concordion.integration.junit4.ConcordionRunner;
38 import org.junit.AfterClass;
39 import org.junit.BeforeClass;
40 import org.junit.runner.RunWith;
41
42 /**
43 * Class that executes the commands for Condordion.
44 * <p>
45 * <b>Control Version</b>
46 * <p>
47 * <ul>
48 * <li>1.0.0 Class creation.</li>
49 * <li>1.0.1 After class.</li>
50 * </ul>
51 *
52 * @author Andres Gomez Casanova <a
53 * href="mailto:a n g o c a at y a h o o dot c o m" >(AngocA)</a>
54 * @version 1.0.1 2010-09-27
55 */
56 @RunWith(ConcordionRunner.class)
57 public class ImplementationLexicalAnalyzerAcceptanceTest {
58
59 /**
60 * Load the graph.
61 *
62 * @throws AbstractZemucanException
63 * Never
64 */
65 @BeforeClass
66 public static void setUpBeforeClass() throws AbstractZemucanException {
67 System.setProperty(Constants.ZEMUCAN_CONF_XML_PROPERTY,
68 "sa_conf-test-realGrammar.xml"); //$NON-NLS-1$
69 Configurator.getInstance().setProperty(
70 Constants.GRAMMAR_READER_NAME_PROPERTY,
71 Configurator.GRAMMAR_READER_NAME_VALUE);
72
73 // Creates the Lexical analyzer instance.
74 ImplementationLexicalAnalyzer.getInstance();
75 }
76
77 /**
78 * Clears the configuration file name property at the end of the test.
79 */
80 @AfterClass
81 public static void tearDownAfterClass() {
82 GrammarReaderController.destroyInstance();
83
84 // Destroy any existent instance.
85 ImplementationLexicalAnalyzer.destroyInstance();
86
87 // Recreates the configurator instance.
88 Configurator.destroyInstance();
89 System.clearProperty(Constants.ZEMUCAN_CONF_XML_PROPERTY);
90 }
91
92 /**
93 * Analyze phrase.
94 *
95 * @param in
96 * Typed command.
97 * @return Analyzes returned.
98 * @throws AbstractZemucanException
99 * Never.
100 */
101 public ReturnOptions/* ! */analyzePhrase(final String/* ! */in)
102 throws AbstractZemucanException {
103 assert in != null;
104
105 final ReturnOptions ret = ImplementationLexicalAnalyzer.getInstance()
106 .analyzePhrase(in);
107
108 assert ret != null;
109
110 return ret;
111 }
112
113 /**
114 * Returns the the first option of a returned option.
115 *
116 * @param returnOptions
117 * Answer.
118 * @return First phrase
119 * @throws AbstractZemucanException
120 * Never.
121 */
122 public String/* ! */getFirstOption(final ReturnOptions/* ! */returnOptions)
123 throws AbstractZemucanException {
124 assert returnOptions != null;
125
126 final String ret = returnOptions.getOptions()[0];
127
128 assert ret != null;
129
130 return ret;
131 }
132
133 /**
134 * Returns the the first phrase of a returned option.
135 *
136 * @param returnOptions
137 * Answer.
138 * @return First phrase
139 * @throws AbstractZemucanException
140 * Never.
141 */
142 public String/* ! */getFirstPhrase(final ReturnOptions/* ! */returnOptions)
143 throws AbstractZemucanException {
144 assert returnOptions != null;
145
146 final String ret = returnOptions.getPhrases()[0];
147
148 assert ret != null;
149
150 return ret;
151 }
152
153 /**
154 * Returns the options of a given command
155 *
156 * @param returnOptions
157 * Answer.
158 * @return Quantity of options.
159 * @throws AbstractZemucanException
160 * Never.
161 */
162 public int qtyOfOptions(final ReturnOptions/* ! */returnOptions)
163 throws AbstractZemucanException {
164 assert returnOptions != null;
165
166 final int ret = returnOptions.getOptions().length;
167
168 return ret;
169 }
170
171 /**
172 * Returns the phrases of a given command
173 *
174 * @param returnOptions
175 * Answer.
176 * @return Quantity of phrases.
177 * @throws AbstractZemucanException
178 * Never.
179 */
180 public int qtyOfPhrases(final ReturnOptions/* ! */returnOptions)
181 throws AbstractZemucanException {
182 assert returnOptions != null;
183
184 final int ret = returnOptions.getPhrases().length;
185
186 return ret;
187 }
188 }