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 23:10:20 -0500 (dom, 06 mar 2011) $:
26   * Revision: $LastChangedRevision: 1917 $:
27   * URL:      $HeadURL: https://zemucan.svn.sourceforge.net/svnroot/zemucan/branches/zemucan_v1/source-code/grammarReaderImplXML/src/test/java/name/angoca/zemucan/grammarReader/impl/xml/ImplementationXMLGrammarReaderTest.java $:
28   */
29  package name.angoca.zemucan.grammarReader.impl.xml;
30  
31  import java.io.StringReader;
32  
33  import name.angoca.zemucan.AbstractZemucanException;
34  import name.angoca.zemucan.ParameterNullException;
35  import name.angoca.zemucan.core.graph.model.DuplicatedNodeException;
36  import name.angoca.zemucan.core.graph.model.EmptyGrammarException;
37  import name.angoca.zemucan.core.graph.model.EndingNodeNotDefinedException;
38  import name.angoca.zemucan.core.graph.model.Graph;
39  import name.angoca.zemucan.core.graph.model.NodeNotComesFromStartingNodeException;
40  import name.angoca.zemucan.core.graph.model.NodeNotGoesToEndingNodeException;
41  import name.angoca.zemucan.core.graph.model.NotExistingChildNodeException;
42  import name.angoca.zemucan.core.graph.model.ReferencingStartingNodeException;
43  import name.angoca.zemucan.core.graph.model.StartingNode;
44  import name.angoca.zemucan.core.graph.model.StartingNodeNotDefinedException;
45  import name.angoca.zemucan.grammarReader.api.DelimitersIncorrectlyDefinedException;
46  import name.angoca.zemucan.grammarReader.api.GeneralGrammarFileProblemException;
47  import name.angoca.zemucan.grammarReader.api.GrammarReaderController;
48  import name.angoca.zemucan.tools.Constants;
49  import name.angoca.zemucan.tools.configurator.Configurator;
50  import name.angoca.zemucan.tools.test.RandomTestRunner;
51  
52  import org.junit.After;
53  import org.junit.AfterClass;
54  import org.junit.Assert;
55  import org.junit.BeforeClass;
56  import org.junit.Test;
57  import org.junit.runner.RunWith;
58  import org.slf4j.Logger;
59  import org.slf4j.LoggerFactory;
60  import org.xml.sax.InputSource;
61  
62  /**
63   * Tests for the graph constructor.
64   * <p>
65   * <b>Control Version</b>
66   * <p>
67   * <ul>
68   * <li>0.0.1 Class creation.</li>
69   * <li>0.1.0 More tests and corrections for the existing ones.</li>
70   * <li>0.1.1 final.</li>
71   * <li>0.2.0 SetUp and TeadDown.</li>
72   * <li>1.0.0 Moved to version 1.</li>
73   * <li>1.1.0 Delimiters as part of the grammar.</li>
74   * <li>1.2.0 Exception hierarchy changed.</li>
75   * <li>1.3.0 Name changed.</li>
76   * <li>1.4.0 More tests and throws.</li>
77   * <li>1.5.0 Graph structure.</li>
78   * <li>1.6.0 Empty grammar.</li>
79   * <li>1.6.1 GraphToken renamed by GraphNode</li>
80   * <li>1.6.2 Constant renamed</li>
81   * <li>1.7.0 GrammarReader separated from Graph.</li>
82   * <li>1.7.1 idNode.</li>
83   * <li>1.7.2 Graph.</li>
84   * <li>1.8.0 Directory tests.</li>
85   * <li>1.8.1 XML Schema.</li>
86   * <li>1.8.2 Double input source.</li>
87   * <li>1.8.3 No deprecated, inputReader instead.</li>
88   * <li>1.8.4 GraphNode Hierarchy.</li>
89   * <li>1.8.5 Destroy instance in the after method.</li>
90   * </ul>
91   *
92   * @author Andres Gomez Casanova <a
93   *         href="mailto:a n g o c a at y a h o o dot c o m" >(AngocA)</a>
94   * @version 1.8.5 2010-09-25
95   */
96  @RunWith(RandomTestRunner.class)
97  public final class ImplementationXMLGrammarReaderTest {
98      /**
99       * Open tag children.
100      */
101     private static final String CHILDREN = "<children>"; //$NON-NLS-1$
102 
103     /**
104      * Close tag children.
105      */
106     private static final String CHILDREN_2 = "</children>"; //$NON-NLS-1$
107     /**
108      * The 'create' word.
109      */
110     private static final String CREATE = "create"; //$NON-NLS-1$
111     /**
112      * Delimiters 'abc'.
113      */
114     private static final String DELIMITERS_ABC_DELIMITERS = "delimiters=\"abc\""; //$NON-NLS-1$
115     /**
116      * Delimiters ;()\.
117      */
118     private static final String DELIMITERS_DELIMITERS = "delimiters=\" ;()\""; //$NON-NLS-1$
119     /**
120      * Less than.
121      */
122     private static final String GRAMMAR_1_CLOSE = ">";
123     /**
124      * XML schema grammar. TODO v1.0 rename project twice
125      */
126     private static final String GRAMMAR_1_OPEN = "<grammar xmlns=\"http://zemucan.sourceforge.net/\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"http://zemucan.sourceforge.net/ grammar.xsd\" schemaVersion=\"1.1\" ";
127     /**
128      * Close tag grammar.
129      */
130     private static final String GRAMMAR_2 = "</grammar>"; //$NON-NLS-1$
131     /**
132      * create id tag.
133      */
134     private static final String ID_CREATE_ID = "<id>create</id>"; //$NON-NLS-1$
135     /**
136      * ending_node id tag.
137      */
138     private static final String ID_ENDING_NODE_ID = "<id>ENDING_NODE</id>"; //$NON-NLS-1$
139     /**
140      * starting_node id tag.
141      */
142     private static final String ID_STARTING_NODE_ID = "<id>STARTING_NODE</id>"; //$NON-NLS-1$
143     /**
144      * table id tag.
145      */
146     private static final String ID_TABLE_ID = "<id>table</id>"; //$NON-NLS-1$
147     /**
148      * create idToken tag.
149      */
150     private static final String ID_TOKEN_CREATE_ID_TOKEN = "<idToken>create</idToken>"; //$NON-NLS-1$
151     /**
152      * ending_node idToken tag.
153      */
154     private static final String ID_TOKEN_ENDING_NODE_ID_TOKEN = "<idToken>ENDING_NODE</idToken>"; //$NON-NLS-1$
155     /**
156      * table idToken tag.
157      */
158     private static final String ID_TOKEN_TABLE_ID_TOKEN = "<idToken>table</idToken>"; //$NON-NLS-1$
159     /**
160      * Logger.
161      */
162     private static final Logger LOGGER = LoggerFactory
163             .getLogger(ImplementationXMLGrammarReaderTest.class);
164     /**
165      * create name tag.
166      */
167     private static final String NAME_CREATE_NAME = "<name>create</name>"; //$NON-NLS-1$
168     /**
169      * ending_node name tag.
170      */
171     private static final String NAME_ENDING_NODE_NAME = "<name>ENDING_NODE</name>"; //$NON-NLS-1$
172     /**
173      * starting_node name tag.
174      */
175     private static final String NAME_STARTING_NODE_NAME = "<name>STARTING_NODE</name>"; //$NON-NLS-1$
176     /**
177      * table name tag.
178      */
179     private static final String NAME_TABLE_NAME = "<name>table</name>"; //$NON-NLS-1$
180     /**
181      * The 'normal graph' words.
182      */
183     private static final String NORMAL_GRAPH = "normal graph"; //$NON-NLS-1$
184     /**
185      * reserved tag.
186      */
187     private static final String RESERVED = "<reserved />"; //$NON-NLS-1$
188     /**
189      * The 'table' word.
190      */
191     private static final String TABLE = "table"; //$NON-NLS-1$
192     /**
193      * Open token tag.
194      */
195     private static final String TOKEN = "<token>"; //$NON-NLS-1$
196     /**
197      * Close token tag.
198      */
199     private static final String TOKEN_2 = "</token>"; //$NON-NLS-1$
200     /**
201      * Open tokens tag.
202      */
203     private static final String TOKENS = "<tokens>"; //$NON-NLS-1$
204     /**
205      * Close tokens tag.
206      */
207     private static final String TOKENS_2 = "</tokens>"; //$NON-NLS-1$
208     /**
209      * Name of the XML reader.
210      */
211     private static final String XML_GRAMMAR_READER = "name.angoca.zemucan.grammarReader.impl.xml.ImplementationXMLGrammarReader"; //$NON-NLS-1$
212 
213     /**
214      * Sets the configuration file.
215      */
216     @BeforeClass
217     public static void oneTimeSetUp() {
218         System.setProperty(Constants.ZEMUCAN_CONF_XML_PROPERTY,
219                 "sa_conf-test.xml"); //$NON-NLS-1$
220     }
221 
222     /**
223      * Clears the configuration file name property at the end of the test.
224      */
225     @AfterClass
226     public static void oneTimeTearDown() {
227         // TODO v1.0 revisar si el nombre estandar es este en la doc junit
228         System.clearProperty(Constants.ZEMUCAN_CONF_XML_PROPERTY);
229     }
230 
231     /**
232      * Destroys the configurator and grammar reader instances.
233      */
234     @After
235     public void tearDown() {
236         Configurator.destroyInstance();
237         GrammarReaderController.destroyInstance();
238     }
239 
240     /**
241      * Tests a grammar that has a duplicated node.
242      *
243      * @throws AbstractZemucanException
244      *             Never.
245      */
246     @Test
247     public void testBuildDuplicatedNode() throws AbstractZemucanException {
248         String xml = ""; //$NON-NLS-1$
249         xml += ImplementationXMLGrammarReaderTest.GRAMMAR_1_OPEN;
250         xml += ImplementationXMLGrammarReaderTest.DELIMITERS_DELIMITERS;
251         xml += ImplementationXMLGrammarReaderTest.GRAMMAR_1_CLOSE;
252         xml += ImplementationXMLGrammarReaderTest.TOKENS;
253         // Starting Node.
254         xml += ImplementationXMLGrammarReaderTest.TOKEN;
255         xml += ImplementationXMLGrammarReaderTest.ID_STARTING_NODE_ID;
256         xml += ImplementationXMLGrammarReaderTest.NAME_STARTING_NODE_NAME;
257         xml += ImplementationXMLGrammarReaderTest.RESERVED;
258         xml += ImplementationXMLGrammarReaderTest.CHILDREN;
259         xml += ImplementationXMLGrammarReaderTest.ID_TOKEN_ENDING_NODE_ID_TOKEN;
260         xml += ImplementationXMLGrammarReaderTest.CHILDREN_2;
261         xml += ImplementationXMLGrammarReaderTest.TOKEN_2;
262         // Ending Node.
263         xml += ImplementationXMLGrammarReaderTest.TOKEN;
264         xml += ImplementationXMLGrammarReaderTest.ID_ENDING_NODE_ID;
265         xml += ImplementationXMLGrammarReaderTest.NAME_ENDING_NODE_NAME;
266         xml += ImplementationXMLGrammarReaderTest.RESERVED;
267         xml += ImplementationXMLGrammarReaderTest.TOKEN_2;
268         // Duplicated Ending node.
269         xml += ImplementationXMLGrammarReaderTest.TOKEN;
270         xml += ImplementationXMLGrammarReaderTest.ID_ENDING_NODE_ID;
271         xml += ImplementationXMLGrammarReaderTest.NAME_ENDING_NODE_NAME;
272         xml += ImplementationXMLGrammarReaderTest.RESERVED;
273         xml += ImplementationXMLGrammarReaderTest.TOKEN_2;
274         xml += ImplementationXMLGrammarReaderTest.TOKENS_2;
275         xml += ImplementationXMLGrammarReaderTest.GRAMMAR_2;
276 
277         final Graph graph = new Graph("duplicated node", false); //$NON-NLS-1$
278         final InputSource contentToParse = new InputSource(
279                 new StringReader(xml));
280         final InputSource contentToValidate = new InputSource(new StringReader(
281                 xml));
282         ImplementationXMLGrammarReaderTest.LOGGER
283                 .info("testBuildDuplicatedNode");
284         ImplementationXMLGrammarReaderTest.LOGGER.debug(xml);
285         final ImplementationXMLGrammarReader grammar = new ImplementationXMLGrammarReader(
286                 graph, contentToParse, contentToValidate);
287 
288         Exception e = null;
289         try {
290             grammar.generateGraph();
291         } catch (final Exception exception) {
292             e = exception;
293         }
294         Assert.assertTrue("DuplicatedNodeException",
295                 e instanceof DuplicatedNodeException);
296     }
297 
298     /**
299      * Tests a grammar that has an empty file.
300      *
301      * @throws AbstractZemucanException
302      *             Never
303      */
304     @Test
305     public void testBuildEmptyFile() throws AbstractZemucanException {
306         final String xml = ""; //$NON-NLS-1$
307 
308         final Graph graph = new Graph("empty file", false); //$NON-NLS-1$
309         final InputSource contentToParse = new InputSource(
310                 new StringReader(xml));
311         final InputSource contentToValidate = new InputSource(new StringReader(
312                 xml));
313         ImplementationXMLGrammarReaderTest.LOGGER.info("testBuildEmptyFile");
314         ImplementationXMLGrammarReaderTest.LOGGER.debug(xml);
315         final ImplementationXMLGrammarReader grammar = new ImplementationXMLGrammarReader(
316                 graph, contentToParse, contentToValidate);
317 
318         Exception e = null;
319         try {
320             grammar.generateGraph();
321         } catch (final Exception exception) {
322             e = exception;
323         }
324         Assert.assertTrue("XMLProblemException",
325                 e instanceof XMLProblemException);
326     }
327 
328     /**
329      * Tests a grammar that has an invalid structure.
330      *
331      * @throws AbstractZemucanException
332      *             Never
333      */
334     @Test
335     public void testBuildInvalidStructure() throws AbstractZemucanException {
336         String xml = ""; //$NON-NLS-1$
337         xml += ImplementationXMLGrammarReaderTest.GRAMMAR_1_OPEN;
338         xml += ImplementationXMLGrammarReaderTest.DELIMITERS_DELIMITERS;
339         xml += ImplementationXMLGrammarReaderTest.GRAMMAR_1_CLOSE;
340         xml += ImplementationXMLGrammarReaderTest.TOKENS;
341         xml += ImplementationXMLGrammarReaderTest.TOKEN;
342         xml += ImplementationXMLGrammarReaderTest.ID_STARTING_NODE_ID;
343 
344         final Graph graph = new Graph("incomplete structure", false); //$NON-NLS-1$
345         final InputSource contentToParse = new InputSource(
346                 new StringReader(xml));
347         final InputSource contentToValidate = new InputSource(new StringReader(
348                 xml));
349         ImplementationXMLGrammarReaderTest.LOGGER
350                 .info("testBuildInvalidStructure");
351         ImplementationXMLGrammarReaderTest.LOGGER.debug(xml);
352         final ImplementationXMLGrammarReader grammar = new ImplementationXMLGrammarReader(
353                 graph, contentToParse, contentToValidate);
354 
355         Exception e = null;
356         try {
357             grammar.generateGraph();
358         } catch (final Exception exception) {
359             e = exception;
360         }
361         Assert.assertTrue("XMLProblemException",
362                 e instanceof XMLProblemException);
363     }
364 
365     /**
366      * Tests that a simple graph inverted can be constructed.
367      *
368      * @throws AbstractZemucanException
369      *             Never
370      */
371     @Test
372     public void testBuildInverted() throws AbstractZemucanException {
373         final String xml = this.testBuildInvertedText();
374 
375         final Graph actual = new Graph("grammar inversed", true); //$NON-NLS-1$
376         final InputSource contentToParse = new InputSource(
377                 new StringReader(xml));
378         final InputSource contentToValidate = new InputSource(new StringReader(
379                 xml));
380         ImplementationXMLGrammarReaderTest.LOGGER.info("testBuildInverted");
381         ImplementationXMLGrammarReaderTest.LOGGER.debug(xml);
382         final ImplementationXMLGrammarReader grammar = new ImplementationXMLGrammarReader(
383                 actual, contentToParse, contentToValidate);
384         grammar.generateGraph();
385         grammar.getStartingNode();
386 
387         final Graph expected = new Graph("grammar inversed", true); //$NON-NLS-1$
388 
389         expected.addNode(Constants.ENDING_NODE, Constants.ENDING_NODE, true);
390         expected.addNode(ImplementationXMLGrammarReaderTest.TABLE,
391                 ImplementationXMLGrammarReaderTest.TABLE, true);
392         expected.addNode(ImplementationXMLGrammarReaderTest.CREATE,
393                 ImplementationXMLGrammarReaderTest.CREATE, true);
394         expected
395                 .addNode(Constants.STARTING_NODE, Constants.STARTING_NODE, true);
396 
397         expected.firstPhaseFinished();
398 
399         expected.addRelation(ImplementationXMLGrammarReaderTest.TABLE,
400                 Constants.ENDING_NODE);
401         expected.addRelation(ImplementationXMLGrammarReaderTest.CREATE,
402                 ImplementationXMLGrammarReaderTest.TABLE);
403         expected.addRelation(Constants.STARTING_NODE,
404                 ImplementationXMLGrammarReaderTest.CREATE);
405         expected.secondPhaseFinished();
406 
407         Assert.assertEquals("Simple graph", expected, actual); //$NON-NLS-1$
408     }
409 
410     private String testBuildInvertedText() {
411         String xml = ""; //$NON-NLS-1$
412         xml += ImplementationXMLGrammarReaderTest.GRAMMAR_1_OPEN;
413         xml += ImplementationXMLGrammarReaderTest.DELIMITERS_DELIMITERS;
414         xml += ImplementationXMLGrammarReaderTest.GRAMMAR_1_CLOSE;
415         xml += ImplementationXMLGrammarReaderTest.TOKENS;
416         // Ending Node.
417         xml += ImplementationXMLGrammarReaderTest.TOKEN;
418         xml += ImplementationXMLGrammarReaderTest.ID_ENDING_NODE_ID;
419         xml += ImplementationXMLGrammarReaderTest.NAME_ENDING_NODE_NAME;
420         xml += ImplementationXMLGrammarReaderTest.RESERVED;
421         xml += ImplementationXMLGrammarReaderTest.TOKEN_2;
422         // table Node.
423         xml += ImplementationXMLGrammarReaderTest.TOKEN;
424         xml += ImplementationXMLGrammarReaderTest.ID_TABLE_ID;
425         xml += ImplementationXMLGrammarReaderTest.NAME_TABLE_NAME;
426         xml += ImplementationXMLGrammarReaderTest.RESERVED;
427         xml += ImplementationXMLGrammarReaderTest.CHILDREN;
428         xml += ImplementationXMLGrammarReaderTest.ID_TOKEN_ENDING_NODE_ID_TOKEN;
429         xml += ImplementationXMLGrammarReaderTest.CHILDREN_2;
430         xml += ImplementationXMLGrammarReaderTest.TOKEN_2;
431         // create Node.
432         xml += ImplementationXMLGrammarReaderTest.TOKEN;
433         xml += ImplementationXMLGrammarReaderTest.ID_CREATE_ID;
434         xml += ImplementationXMLGrammarReaderTest.NAME_CREATE_NAME;
435         xml += ImplementationXMLGrammarReaderTest.RESERVED;
436         xml += ImplementationXMLGrammarReaderTest.CHILDREN;
437         xml += ImplementationXMLGrammarReaderTest.ID_TOKEN_TABLE_ID_TOKEN;
438         xml += ImplementationXMLGrammarReaderTest.CHILDREN_2;
439         xml += ImplementationXMLGrammarReaderTest.TOKEN_2;
440         // Starting Node.
441         xml += ImplementationXMLGrammarReaderTest.TOKEN;
442         xml += ImplementationXMLGrammarReaderTest.ID_STARTING_NODE_ID;
443         xml += ImplementationXMLGrammarReaderTest.NAME_STARTING_NODE_NAME;
444         xml += ImplementationXMLGrammarReaderTest.RESERVED;
445         xml += ImplementationXMLGrammarReaderTest.CHILDREN;
446         xml += ImplementationXMLGrammarReaderTest.ID_TOKEN_CREATE_ID_TOKEN;
447         xml += ImplementationXMLGrammarReaderTest.CHILDREN_2;
448         xml += ImplementationXMLGrammarReaderTest.TOKEN_2;
449 
450         xml += ImplementationXMLGrammarReaderTest.TOKENS_2;
451         xml += ImplementationXMLGrammarReaderTest.GRAMMAR_2;
452         return xml;
453     }
454 
455     /**
456      * Tests a grammar that has a node does not come from StartingNode.
457      *
458      * @throws AbstractZemucanException
459      *             Never
460      */
461     @Test
462     public void testBuildNodeNotComeFromStartingNode()
463             throws AbstractZemucanException {
464         final String xml = this.testBuildNodeNotComeFromStartingNodeText();
465 
466         final Graph graph = new Graph("node without parent", false); //$NON-NLS-1$
467         final InputSource contentToParse = new InputSource(
468                 new StringReader(xml));
469         final InputSource contentToValidate = new InputSource(new StringReader(
470                 xml));
471         ImplementationXMLGrammarReaderTest.LOGGER
472                 .info("testBuildNodeNotComeFromStartingNode");
473         ImplementationXMLGrammarReaderTest.LOGGER.debug(xml);
474         final ImplementationXMLGrammarReader grammar = new ImplementationXMLGrammarReader(
475                 graph, contentToParse, contentToValidate);
476 
477         Exception e = null;
478         try {
479             grammar.generateGraph();
480         } catch (final Exception exception) {
481             e = exception;
482         }
483         Assert.assertTrue("NodeNotComesFromStartingNodeException",
484                 e instanceof NodeNotComesFromStartingNodeException);
485     }
486 
487     private String testBuildNodeNotComeFromStartingNodeText() {
488         String xml = ""; //$NON-NLS-1$
489         xml += ImplementationXMLGrammarReaderTest.GRAMMAR_1_OPEN;
490         xml += ImplementationXMLGrammarReaderTest.DELIMITERS_DELIMITERS;
491         xml += ImplementationXMLGrammarReaderTest.GRAMMAR_1_CLOSE;
492         xml += ImplementationXMLGrammarReaderTest.TOKENS;
493         // Starting Node.
494         xml += ImplementationXMLGrammarReaderTest.TOKEN;
495         xml += ImplementationXMLGrammarReaderTest.ID_STARTING_NODE_ID;
496         xml += ImplementationXMLGrammarReaderTest.NAME_STARTING_NODE_NAME;
497         xml += ImplementationXMLGrammarReaderTest.RESERVED;
498         xml += ImplementationXMLGrammarReaderTest.CHILDREN;
499         xml += ImplementationXMLGrammarReaderTest.ID_TOKEN_TABLE_ID_TOKEN;
500         xml += ImplementationXMLGrammarReaderTest.CHILDREN_2;
501         xml += ImplementationXMLGrammarReaderTest.TOKEN_2;
502         // create Node.
503         xml += ImplementationXMLGrammarReaderTest.TOKEN;
504         xml += ImplementationXMLGrammarReaderTest.ID_CREATE_ID;
505         xml += ImplementationXMLGrammarReaderTest.NAME_CREATE_NAME;
506         xml += ImplementationXMLGrammarReaderTest.RESERVED;
507         xml += ImplementationXMLGrammarReaderTest.CHILDREN;
508         xml += ImplementationXMLGrammarReaderTest.ID_TOKEN_ENDING_NODE_ID_TOKEN;
509         xml += ImplementationXMLGrammarReaderTest.CHILDREN_2;
510         xml += ImplementationXMLGrammarReaderTest.TOKEN_2;
511         // table Node.
512         xml += ImplementationXMLGrammarReaderTest.TOKEN;
513         xml += ImplementationXMLGrammarReaderTest.ID_TABLE_ID;
514         xml += ImplementationXMLGrammarReaderTest.NAME_TABLE_NAME;
515         xml += ImplementationXMLGrammarReaderTest.RESERVED;
516         xml += ImplementationXMLGrammarReaderTest.CHILDREN;
517         xml += ImplementationXMLGrammarReaderTest.ID_TOKEN_ENDING_NODE_ID_TOKEN;
518         xml += ImplementationXMLGrammarReaderTest.CHILDREN_2;
519         xml += ImplementationXMLGrammarReaderTest.TOKEN_2;
520         // Ending Node.
521         xml += ImplementationXMLGrammarReaderTest.TOKEN;
522         xml += ImplementationXMLGrammarReaderTest.ID_ENDING_NODE_ID;
523         xml += ImplementationXMLGrammarReaderTest.NAME_ENDING_NODE_NAME;
524         xml += ImplementationXMLGrammarReaderTest.RESERVED;
525         xml += ImplementationXMLGrammarReaderTest.TOKEN_2;
526         xml += ImplementationXMLGrammarReaderTest.TOKENS_2;
527         xml += ImplementationXMLGrammarReaderTest.GRAMMAR_2;
528         return xml;
529     }
530 
531     /**
532      * Tests a grammar that has a node that does not go to EndingNode.
533      *
534      * @throws AbstractZemucanException
535      *             Never
536      */
537     @Test
538     public void testBuildNodeNotGoesToEndingNode()
539             throws AbstractZemucanException {
540         final String xml = this.testBuildNodeNotGoesToEndingNodeText();
541 
542         final Graph graph = new Graph("node without children", false); //$NON-NLS-1$
543         final InputSource contentToParse = new InputSource(
544                 new StringReader(xml));
545         final InputSource contentToValidate = new InputSource(new StringReader(
546                 xml));
547         ImplementationXMLGrammarReaderTest.LOGGER
548                 .info("testBuildNodeNotGoesToEndingNode");
549         ImplementationXMLGrammarReaderTest.LOGGER.debug(xml);
550         final ImplementationXMLGrammarReader grammar = new ImplementationXMLGrammarReader(
551                 graph, contentToParse, contentToValidate);
552 
553         Exception e = null;
554         try {
555             grammar.generateGraph();
556         } catch (final Exception exception) {
557             e = exception;
558         }
559         Assert.assertTrue("NodeNotGoesToEndingNodeException",
560                 e instanceof NodeNotGoesToEndingNodeException);
561     }
562 
563     private String testBuildNodeNotGoesToEndingNodeText() {
564         String xml = ""; //$NON-NLS-1$
565         xml += ImplementationXMLGrammarReaderTest.GRAMMAR_1_OPEN;
566         xml += ImplementationXMLGrammarReaderTest.DELIMITERS_DELIMITERS;
567         xml += ImplementationXMLGrammarReaderTest.GRAMMAR_1_CLOSE;
568         xml += ImplementationXMLGrammarReaderTest.TOKENS;
569         // Starting Node.
570         xml += ImplementationXMLGrammarReaderTest.TOKEN;
571         xml += ImplementationXMLGrammarReaderTest.ID_STARTING_NODE_ID;
572         xml += ImplementationXMLGrammarReaderTest.NAME_STARTING_NODE_NAME;
573         xml += ImplementationXMLGrammarReaderTest.RESERVED;
574         xml += ImplementationXMLGrammarReaderTest.CHILDREN;
575         xml += ImplementationXMLGrammarReaderTest.ID_TOKEN_CREATE_ID_TOKEN;
576         xml += ImplementationXMLGrammarReaderTest.CHILDREN_2;
577         xml += ImplementationXMLGrammarReaderTest.TOKEN_2;
578         // create Node.
579         xml += ImplementationXMLGrammarReaderTest.TOKEN;
580         xml += ImplementationXMLGrammarReaderTest.ID_CREATE_ID;
581         xml += ImplementationXMLGrammarReaderTest.NAME_CREATE_NAME;
582         xml += ImplementationXMLGrammarReaderTest.RESERVED;
583         xml += ImplementationXMLGrammarReaderTest.CHILDREN;
584         xml += ImplementationXMLGrammarReaderTest.ID_TOKEN_TABLE_ID_TOKEN;
585         xml += ImplementationXMLGrammarReaderTest.ID_TOKEN_ENDING_NODE_ID_TOKEN;
586         xml += ImplementationXMLGrammarReaderTest.CHILDREN_2;
587         xml += ImplementationXMLGrammarReaderTest.TOKEN_2;
588         // table Node.
589         xml += ImplementationXMLGrammarReaderTest.TOKEN;
590         xml += ImplementationXMLGrammarReaderTest.ID_TABLE_ID;
591         xml += ImplementationXMLGrammarReaderTest.NAME_TABLE_NAME;
592         xml += ImplementationXMLGrammarReaderTest.RESERVED;
593         xml += ImplementationXMLGrammarReaderTest.TOKEN_2;
594         // Ending Node.
595         xml += ImplementationXMLGrammarReaderTest.TOKEN;
596         xml += ImplementationXMLGrammarReaderTest.ID_ENDING_NODE_ID;
597         xml += ImplementationXMLGrammarReaderTest.NAME_ENDING_NODE_NAME;
598         xml += ImplementationXMLGrammarReaderTest.RESERVED;
599         xml += ImplementationXMLGrammarReaderTest.TOKEN_2;
600         xml += ImplementationXMLGrammarReaderTest.TOKENS_2;
601         xml += ImplementationXMLGrammarReaderTest.GRAMMAR_2;
602         return xml;
603     }
604 
605     /**
606      * Tests a grammar that has a node that references to StartingNode.
607      *
608      * @throws AbstractZemucanException
609      *             Never
610      */
611     @Test
612     public void testBuildNodeReferencingStartingNode()
613             throws AbstractZemucanException {
614         final String xml = this.testEmptyGrammarText();
615 
616         final Graph graph = new Graph("referencing StartingNode", false); //$NON-NLS-1$
617         final InputSource contentToParse = new InputSource(
618                 new StringReader(xml));
619         final InputSource contentToValidate = new InputSource(new StringReader(
620                 xml));
621         ImplementationXMLGrammarReaderTest.LOGGER
622                 .info("testBuildNodeReferencingStartingNode");
623         ImplementationXMLGrammarReaderTest.LOGGER.debug(xml);
624         final ImplementationXMLGrammarReader grammar = new ImplementationXMLGrammarReader(
625                 graph, contentToParse, contentToValidate);
626 
627         Exception e = null;
628         try {
629             grammar.generateGraph();
630         } catch (final Exception exception) {
631             e = exception;
632         }
633         Assert.assertTrue("ReferencingStartingNodeException",
634                 e instanceof ReferencingStartingNodeException);
635     }
636 
637     /**
638      * Tests a grammar that has an ending node.
639      *
640      * @throws AbstractZemucanException
641      *             Never
642      */
643     @Test
644     public void testBuildNoEndingNode() throws AbstractZemucanException {
645         String xml = ""; //$NON-NLS-1$
646         xml += ImplementationXMLGrammarReaderTest.GRAMMAR_1_OPEN;
647         xml += ImplementationXMLGrammarReaderTest.DELIMITERS_DELIMITERS;
648         xml += ImplementationXMLGrammarReaderTest.GRAMMAR_1_CLOSE;
649         xml += ImplementationXMLGrammarReaderTest.TOKENS;
650         // Starting Node.
651         xml += ImplementationXMLGrammarReaderTest.TOKEN;
652         xml += ImplementationXMLGrammarReaderTest.ID_STARTING_NODE_ID;
653         xml += ImplementationXMLGrammarReaderTest.NAME_STARTING_NODE_NAME;
654         xml += ImplementationXMLGrammarReaderTest.RESERVED;
655         xml += ImplementationXMLGrammarReaderTest.CHILDREN;
656         xml += ImplementationXMLGrammarReaderTest.ID_TOKEN_CREATE_ID_TOKEN;
657         xml += ImplementationXMLGrammarReaderTest.CHILDREN_2;
658         xml += ImplementationXMLGrammarReaderTest.TOKEN_2;
659         // create Node.
660         xml += ImplementationXMLGrammarReaderTest.TOKEN;
661         xml += ImplementationXMLGrammarReaderTest.ID_CREATE_ID;
662         xml += ImplementationXMLGrammarReaderTest.NAME_CREATE_NAME;
663         xml += ImplementationXMLGrammarReaderTest.RESERVED;
664         xml += ImplementationXMLGrammarReaderTest.TOKEN_2;
665         xml += ImplementationXMLGrammarReaderTest.TOKENS_2;
666         xml += ImplementationXMLGrammarReaderTest.GRAMMAR_2;
667 
668         final String id = "no ending node"; //$NON-NLS-1$
669         final Graph graph = new Graph(id, false);
670         final InputSource contentToParse = new InputSource(
671                 new StringReader(xml));
672         final InputSource contentToValidate = new InputSource(new StringReader(
673                 xml));
674         ImplementationXMLGrammarReaderTest.LOGGER.info("testBuildNoEndingNode");
675         ImplementationXMLGrammarReaderTest.LOGGER.debug(xml);
676         final ImplementationXMLGrammarReader grammar = new ImplementationXMLGrammarReader(
677                 graph, contentToParse, contentToValidate);
678 
679         Exception e = null;
680         try {
681             grammar.generateGraph();
682         } catch (final Exception exception) {
683             e = exception;
684         }
685         Assert.assertTrue("EndingNodeNotDefinedException",
686                 e instanceof EndingNodeNotDefinedException);
687     }
688 
689     /**
690      * Tests a grammar that has a node without the id tag.
691      *
692      * @throws AbstractZemucanException
693      *             Never
694      */
695     @Test
696     public void testBuildNoId() throws AbstractZemucanException {
697         String xml = ""; //$NON-NLS-1$
698         xml += ImplementationXMLGrammarReaderTest.GRAMMAR_1_OPEN;
699         xml += ImplementationXMLGrammarReaderTest.DELIMITERS_DELIMITERS;
700         xml += ImplementationXMLGrammarReaderTest.GRAMMAR_1_CLOSE;
701         xml += ImplementationXMLGrammarReaderTest.TOKENS;
702         // Starting Node.
703         xml += ImplementationXMLGrammarReaderTest.TOKEN;
704         xml += ImplementationXMLGrammarReaderTest.ID_STARTING_NODE_ID;
705         xml += ImplementationXMLGrammarReaderTest.NAME_STARTING_NODE_NAME;
706         xml += ImplementationXMLGrammarReaderTest.RESERVED;
707         xml += ImplementationXMLGrammarReaderTest.CHILDREN;
708         xml += ImplementationXMLGrammarReaderTest.ID_TOKEN_CREATE_ID_TOKEN;
709         xml += ImplementationXMLGrammarReaderTest.CHILDREN_2;
710         xml += ImplementationXMLGrammarReaderTest.TOKEN_2;
711         // create Node.
712         xml += ImplementationXMLGrammarReaderTest.TOKEN;
713         xml += ImplementationXMLGrammarReaderTest.NAME_CREATE_NAME;
714         xml += ImplementationXMLGrammarReaderTest.RESERVED;
715         xml += ImplementationXMLGrammarReaderTest.CHILDREN;
716         xml += ImplementationXMLGrammarReaderTest.ID_TOKEN_ENDING_NODE_ID_TOKEN;
717         xml += ImplementationXMLGrammarReaderTest.CHILDREN_2;
718         xml += ImplementationXMLGrammarReaderTest.TOKEN_2;
719         // Ending Node.
720         xml += ImplementationXMLGrammarReaderTest.TOKEN;
721         xml += ImplementationXMLGrammarReaderTest.ID_ENDING_NODE_ID;
722         xml += ImplementationXMLGrammarReaderTest.NAME_ENDING_NODE_NAME;
723         xml += ImplementationXMLGrammarReaderTest.RESERVED;
724         xml += ImplementationXMLGrammarReaderTest.TOKEN_2;
725         xml += ImplementationXMLGrammarReaderTest.TOKENS_2;
726         xml += ImplementationXMLGrammarReaderTest.GRAMMAR_2;
727 
728         final Graph graph = new Graph("node without id", false); //$NON-NLS-1$
729         final InputSource contentToParse = new InputSource(
730                 new StringReader(xml));
731         final InputSource contentToValidate = new InputSource(new StringReader(
732                 xml));
733         ImplementationXMLGrammarReaderTest.LOGGER.info("testBuildNoId");
734         ImplementationXMLGrammarReaderTest.LOGGER.debug(xml);
735         final ImplementationXMLGrammarReader grammar = new ImplementationXMLGrammarReader(
736                 graph, contentToParse, contentToValidate);
737 
738         Exception e = null;
739         try {
740             grammar.generateGraph();
741         } catch (final Exception exception) {
742             e = exception;
743         }
744         Assert.assertTrue("NoIdDefinedInNodeException",
745                 e instanceof NoIdDefinedInNodeException);
746     }
747 
748     /**
749      * Tests a grammar that has a node without the id tag.
750      *
751      * @throws AbstractZemucanException
752      *             Never
753      */
754     @Test
755     public void testBuildNoIdNoName() throws AbstractZemucanException {
756         String xml = ""; //$NON-NLS-1$
757         xml += ImplementationXMLGrammarReaderTest.GRAMMAR_1_OPEN;
758         xml += ImplementationXMLGrammarReaderTest.DELIMITERS_DELIMITERS;
759         xml += ImplementationXMLGrammarReaderTest.GRAMMAR_1_CLOSE;
760         xml += ImplementationXMLGrammarReaderTest.TOKENS;
761         // Starting Node.
762         xml += ImplementationXMLGrammarReaderTest.TOKEN;
763         xml += ImplementationXMLGrammarReaderTest.ID_STARTING_NODE_ID;
764         xml += ImplementationXMLGrammarReaderTest.NAME_STARTING_NODE_NAME;
765         xml += ImplementationXMLGrammarReaderTest.RESERVED;
766         xml += ImplementationXMLGrammarReaderTest.CHILDREN;
767         xml += ImplementationXMLGrammarReaderTest.ID_TOKEN_CREATE_ID_TOKEN;
768         xml += ImplementationXMLGrammarReaderTest.CHILDREN_2;
769         xml += ImplementationXMLGrammarReaderTest.TOKEN_2;
770         // create Node.
771         xml += ImplementationXMLGrammarReaderTest.TOKEN;
772         xml += ImplementationXMLGrammarReaderTest.RESERVED;
773         xml += ImplementationXMLGrammarReaderTest.CHILDREN;
774         xml += ImplementationXMLGrammarReaderTest.ID_TOKEN_ENDING_NODE_ID_TOKEN;
775         xml += ImplementationXMLGrammarReaderTest.CHILDREN_2;
776         xml += ImplementationXMLGrammarReaderTest.TOKEN_2;
777         // Ending Node.
778         xml += ImplementationXMLGrammarReaderTest.TOKEN;
779         xml += ImplementationXMLGrammarReaderTest.ID_ENDING_NODE_ID;
780         xml += ImplementationXMLGrammarReaderTest.NAME_ENDING_NODE_NAME;
781         xml += ImplementationXMLGrammarReaderTest.RESERVED;
782         xml += ImplementationXMLGrammarReaderTest.TOKEN_2;
783         xml += ImplementationXMLGrammarReaderTest.TOKENS_2;
784         xml += ImplementationXMLGrammarReaderTest.GRAMMAR_2;
785 
786         final Graph graph = new Graph("node without id nor name", false); //$NON-NLS-1$
787         final InputSource contentToParse = new InputSource(
788                 new StringReader(xml));
789         final InputSource contentToValidate = new InputSource(new StringReader(
790                 xml));
791         ImplementationXMLGrammarReaderTest.LOGGER.info("testBuildNoIdNoName");
792         ImplementationXMLGrammarReaderTest.LOGGER.debug(xml);
793         final ImplementationXMLGrammarReader grammar = new ImplementationXMLGrammarReader(
794                 graph, contentToParse, contentToValidate);
795 
796         Exception e = null;
797         try {
798             grammar.generateGraph();
799         } catch (final Exception exception) {
800             e = exception;
801         }
802         Assert.assertTrue("NoIdNoNameDefinedInNodeException",
803                 e instanceof NoIdNoNameDefinedInNodeException);
804     }
805 
806     /**
807      * Tests a grammar that has a node without the name tag.
808      *
809      * @throws AbstractZemucanException
810      *             Never
811      */
812     @Test
813     public void testBuildNoName() throws AbstractZemucanException {
814         String xml = ""; //$NON-NLS-1$
815         xml += ImplementationXMLGrammarReaderTest.GRAMMAR_1_OPEN;
816         xml += ImplementationXMLGrammarReaderTest.DELIMITERS_DELIMITERS;
817         xml += ImplementationXMLGrammarReaderTest.GRAMMAR_1_CLOSE;
818         xml += ImplementationXMLGrammarReaderTest.TOKENS;
819         // Starting Node.
820         xml += ImplementationXMLGrammarReaderTest.TOKEN;
821         xml += ImplementationXMLGrammarReaderTest.ID_STARTING_NODE_ID;
822         xml += ImplementationXMLGrammarReaderTest.NAME_STARTING_NODE_NAME;
823         xml += ImplementationXMLGrammarReaderTest.RESERVED;
824         xml += ImplementationXMLGrammarReaderTest.CHILDREN;
825         xml += ImplementationXMLGrammarReaderTest.ID_TOKEN_CREATE_ID_TOKEN;
826         xml += ImplementationXMLGrammarReaderTest.CHILDREN_2;
827         xml += ImplementationXMLGrammarReaderTest.TOKEN_2;
828         // create Node.
829         xml += ImplementationXMLGrammarReaderTest.TOKEN;
830         xml += ImplementationXMLGrammarReaderTest.ID_CREATE_ID;
831         xml += ImplementationXMLGrammarReaderTest.RESERVED;
832         xml += ImplementationXMLGrammarReaderTest.CHILDREN;
833         xml += ImplementationXMLGrammarReaderTest.ID_TOKEN_ENDING_NODE_ID_TOKEN;
834         xml += ImplementationXMLGrammarReaderTest.CHILDREN_2;
835         xml += ImplementationXMLGrammarReaderTest.TOKEN_2;
836         // Ending Node.
837         xml += ImplementationXMLGrammarReaderTest.TOKEN;
838         xml += ImplementationXMLGrammarReaderTest.ID_ENDING_NODE_ID;
839         xml += ImplementationXMLGrammarReaderTest.NAME_ENDING_NODE_NAME;
840         xml += ImplementationXMLGrammarReaderTest.RESERVED;
841         xml += ImplementationXMLGrammarReaderTest.TOKEN_2;
842         xml += ImplementationXMLGrammarReaderTest.TOKENS_2;
843         xml += ImplementationXMLGrammarReaderTest.GRAMMAR_2;
844 
845         final Graph graph = new Graph("node without name", false); //$NON-NLS-1$
846         final InputSource contentToParse = new InputSource(
847                 new StringReader(xml));
848         final InputSource contentToValidate = new InputSource(new StringReader(
849                 xml));
850         ImplementationXMLGrammarReaderTest.LOGGER.info("testBuildNoName");
851         ImplementationXMLGrammarReaderTest.LOGGER.debug(xml);
852         final ImplementationXMLGrammarReader grammar = new ImplementationXMLGrammarReader(
853                 graph, contentToParse, contentToValidate);
854 
855         Exception e = null;
856         try {
857             grammar.generateGraph();
858         } catch (final Exception exception) {
859             e = exception;
860         }
861         Assert.assertTrue("NoNameDefinedInNodeException",
862                 e instanceof NoNameDefinedInNodeException);
863     }
864 
865     /**
866      * Tests a grammar that has no nodes.
867      *
868      * @throws AbstractZemucanException
869      *             Never
870      */
871     @Test
872     public void testBuildNoNodes() throws AbstractZemucanException {
873         String xml = ""; //$NON-NLS-1$
874         xml += ImplementationXMLGrammarReaderTest.GRAMMAR_1_OPEN;
875         xml += ImplementationXMLGrammarReaderTest.DELIMITERS_DELIMITERS;
876         xml += ImplementationXMLGrammarReaderTest.GRAMMAR_1_CLOSE;
877         xml += ImplementationXMLGrammarReaderTest.TOKENS;
878         xml += ImplementationXMLGrammarReaderTest.TOKENS_2;
879         xml += ImplementationXMLGrammarReaderTest.GRAMMAR_2;
880 
881         final String id = ImplementationXMLGrammarReaderTest.NORMAL_GRAPH;
882         final Graph graph = new Graph(id, false);
883         final InputSource contentToParse = new InputSource(
884                 new StringReader(xml));
885         final InputSource contentToValidate = new InputSource(new StringReader(
886                 xml));
887         ImplementationXMLGrammarReaderTest.LOGGER.info("testBuildNoNodes");
888         ImplementationXMLGrammarReaderTest.LOGGER.debug(xml);
889         final ImplementationXMLGrammarReader grammar = new ImplementationXMLGrammarReader(
890                 graph, contentToParse, contentToValidate);
891 
892         Exception e = null;
893         try {
894             grammar.generateGraph();
895         } catch (final Exception exception) {
896             e = exception;
897         }
898         Assert.assertTrue("StartingNodeNotDefinedException",
899                 e instanceof StartingNodeNotDefinedException);
900     }
901 
902     /**
903      * Tests a grammar that does not have starting node.
904      *
905      * @throws AbstractZemucanException
906      *             Never
907      */
908     @Test
909     public void testBuildNoStartingNode() throws AbstractZemucanException {
910         String xml = ""; //$NON-NLS-1$
911         xml += ImplementationXMLGrammarReaderTest.GRAMMAR_1_OPEN;
912         xml += ImplementationXMLGrammarReaderTest.DELIMITERS_DELIMITERS;
913         xml += ImplementationXMLGrammarReaderTest.GRAMMAR_1_CLOSE;
914         xml += ImplementationXMLGrammarReaderTest.TOKENS;
915         // create Node.
916         xml += ImplementationXMLGrammarReaderTest.TOKEN;
917         xml += ImplementationXMLGrammarReaderTest.ID_CREATE_ID;
918         xml += ImplementationXMLGrammarReaderTest.NAME_CREATE_NAME;
919         xml += ImplementationXMLGrammarReaderTest.RESERVED;
920         xml += ImplementationXMLGrammarReaderTest.CHILDREN;
921         xml += ImplementationXMLGrammarReaderTest.ID_TOKEN_ENDING_NODE_ID_TOKEN;
922         xml += ImplementationXMLGrammarReaderTest.CHILDREN_2;
923         xml += ImplementationXMLGrammarReaderTest.TOKEN_2;
924         // Ending Node.
925         xml += ImplementationXMLGrammarReaderTest.TOKEN;
926         xml += ImplementationXMLGrammarReaderTest.ID_ENDING_NODE_ID;
927         xml += ImplementationXMLGrammarReaderTest.NAME_ENDING_NODE_NAME;
928         xml += ImplementationXMLGrammarReaderTest.RESERVED;
929         xml += ImplementationXMLGrammarReaderTest.TOKEN_2;
930         xml += ImplementationXMLGrammarReaderTest.TOKENS_2;
931         xml += ImplementationXMLGrammarReaderTest.GRAMMAR_2;
932 
933         final String id = "no StartingNode"; //$NON-NLS-1$
934         final Graph graph = new Graph(id, false);
935         final InputSource contentToParse = new InputSource(
936                 new StringReader(xml));
937         final InputSource contentToValidate = new InputSource(new StringReader(
938                 xml));
939         ImplementationXMLGrammarReaderTest.LOGGER
940                 .info("testBuildNoStartingNode");
941         ImplementationXMLGrammarReaderTest.LOGGER.debug(xml);
942         final ImplementationXMLGrammarReader grammar = new ImplementationXMLGrammarReader(
943                 graph, contentToParse, contentToValidate);
944 
945         Exception e = null;
946         try {
947             grammar.generateGraph();
948         } catch (final Exception exception) {
949             e = exception;
950         }
951         Assert.assertTrue("StartingNodeNotDefinedException",
952                 e instanceof StartingNodeNotDefinedException);
953     }
954 
955     /**
956      * Tests a grammar that has defined all the nodes that are children.
957      *
958      * @throws AbstractZemucanException
959      *             Never
960      */
961     @Test
962     public void testBuildNotAllChildren() throws AbstractZemucanException {
963         String xml = ""; //$NON-NLS-1$
964         xml += ImplementationXMLGrammarReaderTest.GRAMMAR_1_OPEN;
965         xml += ImplementationXMLGrammarReaderTest.DELIMITERS_DELIMITERS;
966         xml += ImplementationXMLGrammarReaderTest.GRAMMAR_1_CLOSE;
967         xml += ImplementationXMLGrammarReaderTest.TOKENS;
968         // Starting Node.
969         xml += ImplementationXMLGrammarReaderTest.TOKEN;
970         xml += ImplementationXMLGrammarReaderTest.ID_STARTING_NODE_ID;
971         xml += ImplementationXMLGrammarReaderTest.NAME_STARTING_NODE_NAME;
972         xml += ImplementationXMLGrammarReaderTest.RESERVED;
973         xml += ImplementationXMLGrammarReaderTest.CHILDREN;
974         xml += ImplementationXMLGrammarReaderTest.ID_TOKEN_ENDING_NODE_ID_TOKEN;
975         xml += ImplementationXMLGrammarReaderTest.CHILDREN_2;
976         xml += ImplementationXMLGrammarReaderTest.TOKEN_2;
977         xml += ImplementationXMLGrammarReaderTest.TOKENS_2;
978         xml += ImplementationXMLGrammarReaderTest.GRAMMAR_2;
979 
980         final Graph graph = new Graph("not all children", false); //$NON-NLS-1$
981         final InputSource contentToParse = new InputSource(
982                 new StringReader(xml));
983         final InputSource contentToValidate = new InputSource(new StringReader(
984                 xml));
985         ImplementationXMLGrammarReaderTest.LOGGER
986                 .info("testBuildNotAllChildren");
987         ImplementationXMLGrammarReaderTest.LOGGER.debug(xml);
988         final ImplementationXMLGrammarReader grammar = new ImplementationXMLGrammarReader(
989                 graph, contentToParse, contentToValidate);
990 
991         Exception e = null;
992         try {
993             grammar.generateGraph();
994         } catch (final Exception exception) {
995             e = exception;
996         }
997         Assert.assertTrue("NotExistingChildNodeException",
998                 e instanceof NotExistingChildNodeException);
999     }
1000 
1001     /**
1002      * Tests a grammar that has the starting node is not connected to the ending
1003      * node.
1004      *
1005      * @throws AbstractZemucanException
1006      *             Never
1007      */
1008     @Test
1009     public void testBuildNotConnectedGraph() throws AbstractZemucanException {
1010         String xml = ""; //$NON-NLS-1$
1011         xml += ImplementationXMLGrammarReaderTest.GRAMMAR_1_OPEN;
1012         xml += ImplementationXMLGrammarReaderTest.DELIMITERS_DELIMITERS;
1013         xml += ImplementationXMLGrammarReaderTest.GRAMMAR_1_CLOSE;
1014         xml += ImplementationXMLGrammarReaderTest.TOKENS;
1015         // Starting Node.
1016         xml += ImplementationXMLGrammarReaderTest.TOKEN;
1017         xml += ImplementationXMLGrammarReaderTest.ID_STARTING_NODE_ID;
1018         xml += ImplementationXMLGrammarReaderTest.NAME_STARTING_NODE_NAME;
1019         xml += ImplementationXMLGrammarReaderTest.RESERVED;
1020         xml += ImplementationXMLGrammarReaderTest.TOKEN_2;
1021         // Ending Node.
1022         xml += ImplementationXMLGrammarReaderTest.TOKEN;
1023         xml += ImplementationXMLGrammarReaderTest.ID_ENDING_NODE_ID;
1024         xml += ImplementationXMLGrammarReaderTest.NAME_ENDING_NODE_NAME;
1025         xml += ImplementationXMLGrammarReaderTest.RESERVED;
1026         xml += ImplementationXMLGrammarReaderTest.TOKEN_2;
1027         xml += ImplementationXMLGrammarReaderTest.TOKENS_2;
1028         xml += ImplementationXMLGrammarReaderTest.GRAMMAR_2;
1029 
1030         final Graph graph = new Graph("not connected graph", false); //$NON-NLS-1$
1031         final InputSource contentToParse = new InputSource(
1032                 new StringReader(xml));
1033         final InputSource contentToValidate = new InputSource(new StringReader(
1034                 xml));
1035         ImplementationXMLGrammarReaderTest.LOGGER
1036                 .info("testBuildNotConnectedGraph");
1037         ImplementationXMLGrammarReaderTest.LOGGER.debug(xml);
1038         final ImplementationXMLGrammarReader grammar = new ImplementationXMLGrammarReader(
1039                 graph, contentToParse, contentToValidate);
1040 
1041         Exception e = null;
1042         try {
1043             grammar.generateGraph();
1044         } catch (final Exception exception) {
1045             e = exception;
1046         }
1047         Assert.assertTrue("NodeNotComesFromStartingNodeException",
1048                 e instanceof NodeNotComesFromStartingNodeException);
1049     }
1050 
1051     /**
1052      * Tests a grammar that has a file with an unknown structure.
1053      *
1054      * @throws AbstractZemucanException
1055      *             Never
1056      */
1057     @Test
1058     public void testBuildUnknownStructure() throws AbstractZemucanException {
1059         final String xml = "This can be a test file"; //$NON-NLS-1$
1060 
1061         final Graph graph = new Graph("invalid structure", false); //$NON-NLS-1$
1062         final InputSource contentToParse = new InputSource(
1063                 new StringReader(xml));
1064         final InputSource contentToValidate = new InputSource(new StringReader(
1065                 xml));
1066         ImplementationXMLGrammarReaderTest.LOGGER
1067                 .info("testBuildUnknownStructure");
1068         ImplementationXMLGrammarReaderTest.LOGGER.debug(xml);
1069         final ImplementationXMLGrammarReader grammar = new ImplementationXMLGrammarReader(
1070                 graph, contentToParse, contentToValidate);
1071 
1072         Exception e = null;
1073         try {
1074             grammar.generateGraph();
1075         } catch (final Exception exception) {
1076             e = exception;
1077         }
1078         Assert.assertTrue("XMLProblemException",
1079                 e instanceof XMLProblemException);
1080     }
1081 
1082     /**
1083      * Tests that a simple graph can be constructed with extra tokens.
1084      *
1085      * @throws AbstractZemucanException
1086      *             Never
1087      */
1088     @Test
1089     public void testBuildWithExtraTokens() throws AbstractZemucanException {
1090         final String xml = this.testBuildWithExtraTokensText();
1091 
1092         final String id = ImplementationXMLGrammarReaderTest.NORMAL_GRAPH;
1093         final Graph actual = new Graph(id, true);
1094         final InputSource contentToParse = new InputSource(
1095                 new StringReader(xml));
1096         final InputSource contentToValidate = new InputSource(new StringReader(
1097                 xml));
1098         ImplementationXMLGrammarReaderTest.LOGGER
1099                 .info("testBuildWithExtraTokens");
1100         ImplementationXMLGrammarReaderTest.LOGGER.debug(xml);
1101         final ImplementationXMLGrammarReader grammar = new ImplementationXMLGrammarReader(
1102                 actual, contentToParse, contentToValidate);
1103         grammar.generateGraph();
1104         grammar.getStartingNode();
1105 
1106         final Graph expected = new Graph(
1107                 ImplementationXMLGrammarReaderTest.NORMAL_GRAPH, true);
1108         expected
1109                 .addNode(Constants.STARTING_NODE, Constants.STARTING_NODE, true);
1110         expected.addNode(ImplementationXMLGrammarReaderTest.CREATE,
1111                 ImplementationXMLGrammarReaderTest.CREATE, true);
1112         expected.addNode(Constants.ENDING_NODE, Constants.ENDING_NODE, true);
1113 
1114         expected.firstPhaseFinished();
1115 
1116         expected.addRelation(Constants.STARTING_NODE,
1117                 ImplementationXMLGrammarReaderTest.CREATE);
1118         expected.addRelation(ImplementationXMLGrammarReaderTest.CREATE,
1119                 Constants.ENDING_NODE);
1120 
1121         expected.secondPhaseFinished();
1122 
1123         Assert.assertEquals("Simple graph with extra tokens", expected, //$NON-NLS-1$
1124                 actual);
1125     }
1126 
1127     private String testBuildWithExtraTokensText() {
1128         String xml = ""; //$NON-NLS-1$
1129         xml += ImplementationXMLGrammarReaderTest.GRAMMAR_1_OPEN;
1130         xml += ImplementationXMLGrammarReaderTest.DELIMITERS_DELIMITERS;
1131         xml += ImplementationXMLGrammarReaderTest.GRAMMAR_1_CLOSE;
1132         xml += ImplementationXMLGrammarReaderTest.TOKENS;
1133         // Starting Node.
1134         xml += ImplementationXMLGrammarReaderTest.TOKEN;
1135         xml += ImplementationXMLGrammarReaderTest.ID_STARTING_NODE_ID;
1136         xml += ImplementationXMLGrammarReaderTest.NAME_STARTING_NODE_NAME;
1137         xml += ImplementationXMLGrammarReaderTest.RESERVED;
1138         xml += ImplementationXMLGrammarReaderTest.CHILDREN;
1139         xml += ImplementationXMLGrammarReaderTest.ID_TOKEN_CREATE_ID_TOKEN;
1140         xml += ImplementationXMLGrammarReaderTest.CHILDREN_2;
1141         xml += ImplementationXMLGrammarReaderTest.TOKEN_2;
1142         // create Node.
1143         xml += ImplementationXMLGrammarReaderTest.TOKEN;
1144         xml += ImplementationXMLGrammarReaderTest.ID_CREATE_ID;
1145         xml += ImplementationXMLGrammarReaderTest.NAME_CREATE_NAME;
1146         xml += ImplementationXMLGrammarReaderTest.RESERVED;
1147         xml += ImplementationXMLGrammarReaderTest.CHILDREN;
1148         xml += ImplementationXMLGrammarReaderTest.ID_TOKEN_ENDING_NODE_ID_TOKEN;
1149         xml += ImplementationXMLGrammarReaderTest.CHILDREN_2;
1150         xml += ImplementationXMLGrammarReaderTest.TOKEN_2;
1151         // Ending Node.
1152         xml += ImplementationXMLGrammarReaderTest.TOKEN;
1153         xml += ImplementationXMLGrammarReaderTest.ID_ENDING_NODE_ID;
1154         xml += ImplementationXMLGrammarReaderTest.NAME_ENDING_NODE_NAME;
1155         xml += ImplementationXMLGrammarReaderTest.RESERVED;
1156         xml += ImplementationXMLGrammarReaderTest.TOKEN_2;
1157         xml += ImplementationXMLGrammarReaderTest.TOKENS_2;
1158         xml += ImplementationXMLGrammarReaderTest.GRAMMAR_2;
1159         return xml;
1160     }
1161 
1162     /**
1163      * Tests that a simple graph can be constructed without extra tokens.
1164      *
1165      * @throws AbstractZemucanException
1166      *             Never
1167      */
1168     @Test
1169     public void testBuildWithoutExtraTokens() throws AbstractZemucanException {
1170         final String xml = this.testBuildWithExtraTokensText();
1171 
1172         final String id = ImplementationXMLGrammarReaderTest.NORMAL_GRAPH;
1173         final Graph actual = new Graph(id, false);
1174         final InputSource contentToParse = new InputSource(
1175                 new StringReader(xml));
1176         final InputSource contentToValidate = new InputSource(new StringReader(
1177                 xml));
1178         ImplementationXMLGrammarReaderTest.LOGGER
1179                 .info("testBuildWithoutExtraTokens");
1180         ImplementationXMLGrammarReaderTest.LOGGER.debug(xml);
1181         final ImplementationXMLGrammarReader grammar = new ImplementationXMLGrammarReader(
1182                 actual, contentToParse, contentToValidate);
1183         grammar.generateGraph();
1184         grammar.getStartingNode();
1185 
1186         final Graph expected = new Graph(
1187                 ImplementationXMLGrammarReaderTest.NORMAL_GRAPH, false);
1188         expected
1189                 .addNode(Constants.STARTING_NODE, Constants.STARTING_NODE, true);
1190         expected.addNode(ImplementationXMLGrammarReaderTest.CREATE,
1191                 ImplementationXMLGrammarReaderTest.CREATE, true);
1192         expected.addNode(Constants.ENDING_NODE, Constants.ENDING_NODE, true);
1193 
1194         expected.firstPhaseFinished();
1195 
1196         expected.addRelation(Constants.STARTING_NODE,
1197                 ImplementationXMLGrammarReaderTest.CREATE);
1198         expected.addRelation(ImplementationXMLGrammarReaderTest.CREATE,
1199                 Constants.ENDING_NODE);
1200 
1201         expected.secondPhaseFinished();
1202 
1203         Assert.assertEquals("Simple graph without extra tokens", expected, //$NON-NLS-1$
1204                 actual);
1205     }
1206 
1207     /**
1208      * Tests that the configuration file has only one delimiters tag.
1209      *
1210      * @throws AbstractZemucanException
1211      *             Never
1212      */
1213     @Test
1214     public void testDoubleDelimiters() throws AbstractZemucanException {
1215         final String xml = this.testDoubleDelimitersText();
1216 
1217         final Graph graph = new Graph("double delimieters", false); //$NON-NLS-1$
1218         final InputSource contentToParse = new InputSource(
1219                 new StringReader(xml));
1220         final InputSource contentToValidate = new InputSource(new StringReader(
1221                 xml));
1222         ImplementationXMLGrammarReaderTest.LOGGER.info("testDoubleDelimiters");
1223         ImplementationXMLGrammarReaderTest.LOGGER.debug(xml);
1224         final ImplementationXMLGrammarReader grammar = new ImplementationXMLGrammarReader(
1225                 graph, contentToParse, contentToValidate);
1226 
1227         Exception e = null;
1228         try {
1229             grammar.generateGraph();
1230         } catch (final Exception exception) {
1231             e = exception;
1232         }
1233         Assert.assertTrue("XMLProblemException",
1234                 e instanceof XMLProblemException);
1235     }
1236 
1237     private String testDoubleDelimitersText() {
1238         String xml = ""; //$NON-NLS-1$
1239         xml += ImplementationXMLGrammarReaderTest.GRAMMAR_1_OPEN;
1240         xml += ImplementationXMLGrammarReaderTest.DELIMITERS_DELIMITERS;
1241         xml += ImplementationXMLGrammarReaderTest.DELIMITERS_ABC_DELIMITERS;
1242         xml += ImplementationXMLGrammarReaderTest.GRAMMAR_1_CLOSE;
1243         xml += ImplementationXMLGrammarReaderTest.TOKENS;
1244         // Starting Node.
1245         xml += ImplementationXMLGrammarReaderTest.TOKEN;
1246         xml += ImplementationXMLGrammarReaderTest.ID_STARTING_NODE_ID;
1247         xml += ImplementationXMLGrammarReaderTest.NAME_STARTING_NODE_NAME;
1248         xml += ImplementationXMLGrammarReaderTest.RESERVED;
1249         xml += ImplementationXMLGrammarReaderTest.CHILDREN;
1250         xml += ImplementationXMLGrammarReaderTest.ID_TOKEN_CREATE_ID_TOKEN;
1251         xml += ImplementationXMLGrammarReaderTest.CHILDREN_2;
1252         xml += ImplementationXMLGrammarReaderTest.TOKEN_2;
1253         // create Node.
1254         xml += ImplementationXMLGrammarReaderTest.TOKEN;
1255         xml += ImplementationXMLGrammarReaderTest.ID_CREATE_ID;
1256         xml += ImplementationXMLGrammarReaderTest.NAME_CREATE_NAME;
1257         xml += ImplementationXMLGrammarReaderTest.RESERVED;
1258         xml += ImplementationXMLGrammarReaderTest.CHILDREN;
1259         xml += ImplementationXMLGrammarReaderTest.ID_TOKEN_ENDING_NODE_ID_TOKEN;
1260         xml += ImplementationXMLGrammarReaderTest.CHILDREN_2;
1261         xml += ImplementationXMLGrammarReaderTest.TOKEN_2;
1262         // Ending Node.
1263         xml += ImplementationXMLGrammarReaderTest.TOKEN;
1264         xml += ImplementationXMLGrammarReaderTest.ID_ENDING_NODE_ID;
1265         xml += ImplementationXMLGrammarReaderTest.NAME_ENDING_NODE_NAME;
1266         xml += ImplementationXMLGrammarReaderTest.RESERVED;
1267         xml += ImplementationXMLGrammarReaderTest.TOKEN_2;
1268         xml += ImplementationXMLGrammarReaderTest.TOKENS_2;
1269         xml += ImplementationXMLGrammarReaderTest.GRAMMAR_2;
1270         return xml;
1271     }
1272 
1273     /**
1274      * Tests that the configuration file has wrongly defined the delimiters.
1275      *
1276      * @throws AbstractZemucanException
1277      *             Never
1278      */
1279     @Test
1280     public void testEmptyDelimiters() throws AbstractZemucanException {
1281         String xml = ""; //$NON-NLS-1$
1282         xml += ImplementationXMLGrammarReaderTest.GRAMMAR_1_OPEN
1283                 + " delimiters=\"\""
1284                 + ImplementationXMLGrammarReaderTest.GRAMMAR_1_CLOSE;
1285         xml += ImplementationXMLGrammarReaderTest.TOKENS;
1286         // Starting Node.
1287         xml += ImplementationXMLGrammarReaderTest.TOKEN;
1288         xml += ImplementationXMLGrammarReaderTest.ID_STARTING_NODE_ID;
1289         xml += ImplementationXMLGrammarReaderTest.NAME_STARTING_NODE_NAME;
1290         xml += ImplementationXMLGrammarReaderTest.RESERVED;
1291         xml += ImplementationXMLGrammarReaderTest.CHILDREN;
1292         xml += ImplementationXMLGrammarReaderTest.ID_TOKEN_CREATE_ID_TOKEN;
1293         xml += ImplementationXMLGrammarReaderTest.CHILDREN_2;
1294         xml += ImplementationXMLGrammarReaderTest.TOKEN_2;
1295         // create Node.
1296         xml += ImplementationXMLGrammarReaderTest.TOKEN;
1297         xml += ImplementationXMLGrammarReaderTest.ID_CREATE_ID;
1298         xml += ImplementationXMLGrammarReaderTest.NAME_CREATE_NAME;
1299         xml += ImplementationXMLGrammarReaderTest.RESERVED;
1300         xml += ImplementationXMLGrammarReaderTest.CHILDREN;
1301         xml += ImplementationXMLGrammarReaderTest.ID_TOKEN_ENDING_NODE_ID_TOKEN;
1302         xml += ImplementationXMLGrammarReaderTest.CHILDREN_2;
1303         xml += ImplementationXMLGrammarReaderTest.TOKEN_2;
1304         // Ending Node.
1305         xml += ImplementationXMLGrammarReaderTest.TOKEN;
1306         xml += ImplementationXMLGrammarReaderTest.ID_ENDING_NODE_ID;
1307         xml += ImplementationXMLGrammarReaderTest.NAME_ENDING_NODE_NAME;
1308         xml += ImplementationXMLGrammarReaderTest.RESERVED;
1309         xml += ImplementationXMLGrammarReaderTest.TOKEN_2;
1310         xml += ImplementationXMLGrammarReaderTest.TOKENS_2;
1311         xml += ImplementationXMLGrammarReaderTest.GRAMMAR_2;
1312 
1313         final Graph graph = new Graph("delimiters", false); //$NON-NLS-1$
1314         final InputSource contentToParse = new InputSource(
1315                 new StringReader(xml));
1316         final InputSource contentToValidate = new InputSource(new StringReader(
1317                 xml));
1318         ImplementationXMLGrammarReaderTest.LOGGER.info("testEmptyDelimiters");
1319         ImplementationXMLGrammarReaderTest.LOGGER.debug(xml);
1320         final ImplementationXMLGrammarReader grammar = new ImplementationXMLGrammarReader(
1321                 graph, contentToParse, contentToValidate);
1322 
1323         Exception e = null;
1324         try {
1325             grammar.generateGraph();
1326         } catch (final Exception exception) {
1327             e = exception;
1328         }
1329         Assert.assertTrue("DelimitersIncorrectlyDefinedException",
1330                 e instanceof DelimitersIncorrectlyDefinedException);
1331     }
1332 
1333     /**
1334      * Tests that the configuration file has only StartingNode and EndingNode.
1335      *
1336      * @throws AbstractZemucanException
1337      *             Never
1338      */
1339     @Test
1340     public void testEmptyGrammar() throws AbstractZemucanException {
1341         String xml = ""; //$NON-NLS-1$
1342         xml += ImplementationXMLGrammarReaderTest.GRAMMAR_1_OPEN;
1343         xml += ImplementationXMLGrammarReaderTest.DELIMITERS_DELIMITERS;
1344         xml += ImplementationXMLGrammarReaderTest.GRAMMAR_1_CLOSE;
1345         xml += ImplementationXMLGrammarReaderTest.TOKENS;
1346         // Starting Node.
1347         xml += ImplementationXMLGrammarReaderTest.TOKEN;
1348         xml += ImplementationXMLGrammarReaderTest.ID_STARTING_NODE_ID;
1349         xml += ImplementationXMLGrammarReaderTest.NAME_STARTING_NODE_NAME;
1350         xml += ImplementationXMLGrammarReaderTest.RESERVED;
1351         xml += ImplementationXMLGrammarReaderTest.CHILDREN;
1352         xml += ImplementationXMLGrammarReaderTest.ID_TOKEN_ENDING_NODE_ID_TOKEN;
1353         xml += ImplementationXMLGrammarReaderTest.CHILDREN_2;
1354         xml += ImplementationXMLGrammarReaderTest.TOKEN_2;
1355         // Ending Node.
1356         xml += ImplementationXMLGrammarReaderTest.TOKEN;
1357         xml += ImplementationXMLGrammarReaderTest.ID_ENDING_NODE_ID;
1358         xml += ImplementationXMLGrammarReaderTest.NAME_ENDING_NODE_NAME;
1359         xml += ImplementationXMLGrammarReaderTest.RESERVED;
1360         xml += ImplementationXMLGrammarReaderTest.TOKEN_2;
1361         xml += ImplementationXMLGrammarReaderTest.TOKENS_2;
1362         xml += ImplementationXMLGrammarReaderTest.GRAMMAR_2;
1363 
1364         final Graph graph = new Graph("empty grammar", false); //$NON-NLS-1$
1365         final InputSource contentToParse = new InputSource(
1366                 new StringReader(xml));
1367         final InputSource contentToValidate = new InputSource(new StringReader(
1368                 xml));
1369         ImplementationXMLGrammarReaderTest.LOGGER.info("testEmptyGrammar");
1370         ImplementationXMLGrammarReaderTest.LOGGER.debug(xml);
1371         final ImplementationXMLGrammarReader grammar = new ImplementationXMLGrammarReader(
1372                 graph, contentToParse, contentToValidate);
1373 
1374         Exception e = null;
1375         try {
1376             grammar.generateGraph();
1377         } catch (final Exception exception) {
1378             e = exception;
1379         }
1380         Assert.assertTrue("EmptyGrammarException",
1381                 e instanceof EmptyGrammarException);
1382     }
1383 
1384     private String testEmptyGrammarText() {
1385         String xml = ""; //$NON-NLS-1$
1386         xml += ImplementationXMLGrammarReaderTest.GRAMMAR_1_OPEN;
1387         xml += ImplementationXMLGrammarReaderTest.DELIMITERS_DELIMITERS;
1388         xml += ImplementationXMLGrammarReaderTest.GRAMMAR_1_CLOSE;
1389         xml += ImplementationXMLGrammarReaderTest.TOKENS;
1390         // Starting Node.
1391         xml += ImplementationXMLGrammarReaderTest.TOKEN;
1392         xml += ImplementationXMLGrammarReaderTest.ID_STARTING_NODE_ID;
1393         xml += ImplementationXMLGrammarReaderTest.NAME_STARTING_NODE_NAME;
1394         xml += ImplementationXMLGrammarReaderTest.RESERVED;
1395         xml += ImplementationXMLGrammarReaderTest.CHILDREN;
1396         xml += ImplementationXMLGrammarReaderTest.ID_TOKEN_CREATE_ID_TOKEN;
1397         xml += ImplementationXMLGrammarReaderTest.CHILDREN_2;
1398         xml += ImplementationXMLGrammarReaderTest.TOKEN_2;
1399         // create Node.
1400         xml += ImplementationXMLGrammarReaderTest.TOKEN;
1401         xml += ImplementationXMLGrammarReaderTest.ID_CREATE_ID;
1402         xml += ImplementationXMLGrammarReaderTest.NAME_CREATE_NAME;
1403         xml += ImplementationXMLGrammarReaderTest.RESERVED;
1404         xml += ImplementationXMLGrammarReaderTest.CHILDREN;
1405         xml += ImplementationXMLGrammarReaderTest.ID_TOKEN_ENDING_NODE_ID_TOKEN;
1406         xml += "    <idToken>STARTING_NODE</idToken>"; //$NON-NLS-1$
1407         xml += ImplementationXMLGrammarReaderTest.CHILDREN_2;
1408         xml += ImplementationXMLGrammarReaderTest.TOKEN_2;
1409         // Ending Node.
1410         xml += ImplementationXMLGrammarReaderTest.TOKEN;
1411         xml += ImplementationXMLGrammarReaderTest.ID_ENDING_NODE_ID;
1412         xml += ImplementationXMLGrammarReaderTest.NAME_ENDING_NODE_NAME;
1413         xml += ImplementationXMLGrammarReaderTest.RESERVED;
1414         xml += ImplementationXMLGrammarReaderTest.TOKEN_2;
1415         xml += ImplementationXMLGrammarReaderTest.TOKENS_2;
1416         xml += ImplementationXMLGrammarReaderTest.GRAMMAR_2;
1417         return xml;
1418     }
1419 
1420     /**
1421      * Tests that a simple graph is different with and without extra tokens.
1422      *
1423      * @throws AbstractZemucanException
1424      *             Never
1425      */
1426     @Test
1427     public void testErrorBuildWithExtraTokens() throws AbstractZemucanException {
1428         final String xml = this.testBuildWithExtraTokensText();
1429 
1430         final String id = ImplementationXMLGrammarReaderTest.NORMAL_GRAPH;
1431         final Graph actual = new Graph(id, true);
1432         final InputSource contentToParse = new InputSource(
1433                 new StringReader(xml));
1434         final InputSource contentToValidate = new InputSource(new StringReader(
1435                 xml));
1436         ImplementationXMLGrammarReaderTest.LOGGER
1437                 .info("testErrorBuildWithExtraTokens");
1438         ImplementationXMLGrammarReaderTest.LOGGER.debug(xml);
1439         final ImplementationXMLGrammarReader grammar = new ImplementationXMLGrammarReader(
1440                 actual, contentToParse, contentToValidate);
1441         grammar.generateGraph();
1442         grammar.getStartingNode();
1443 
1444         final Graph expected = new Graph(
1445                 ImplementationXMLGrammarReaderTest.NORMAL_GRAPH, false);
1446         expected
1447                 .addNode(Constants.STARTING_NODE, Constants.STARTING_NODE, true);
1448         expected.addNode(ImplementationXMLGrammarReaderTest.CREATE,
1449                 ImplementationXMLGrammarReaderTest.CREATE, true);
1450         expected.addNode(Constants.ENDING_NODE, Constants.ENDING_NODE, true);
1451 
1452         expected.firstPhaseFinished();
1453 
1454         expected.addRelation(Constants.STARTING_NODE,
1455                 ImplementationXMLGrammarReaderTest.CREATE);
1456         expected.addRelation(ImplementationXMLGrammarReaderTest.CREATE,
1457                 Constants.ENDING_NODE);
1458 
1459         expected.secondPhaseFinished();
1460 
1461         Assert.assertFalse(
1462                 "Simple graph different with or without extra tokens", //$NON-NLS-1$
1463                 actual.equals(expected));
1464         Assert.assertFalse(
1465                 "Simple graph different with or without extra tokens", //$NON-NLS-1$
1466                 expected.equals(actual));
1467     }
1468 
1469     /**
1470      * Tests a grammar file in a directory.
1471      *
1472      * @throws AbstractZemucanException
1473      *             Never.
1474      */
1475     @Test
1476     public final void testGrammarFileInDirectory()
1477             throws AbstractZemucanException {
1478         Configurator.getInstance().setProperty(
1479                 Constants.GRAMMAR_READER_NAME_PROPERTY,
1480                 ImplementationXMLGrammarReaderTest.XML_GRAMMAR_READER);
1481         Configurator.getInstance().setProperty(
1482                 Constants.GRAMMAR_FILE_DESCRIPTORS_PROPERTY,
1483                 "grammar-test/directory1/grammar-test-1.xml"); //$NON-NLS-1$
1484 
1485         final StartingNode node = GrammarReaderController.getInstance()
1486                 .getStartingNode();
1487 
1488         Assert.assertTrue("Grammar file in a directory", node != null);
1489     }
1490 
1491     /**
1492      * Tests a grammar file that are in a given directory.
1493      *
1494      * @throws AbstractZemucanException
1495      *             Never.
1496      */
1497     @Test
1498     public final void testGrammarFileInOneDirectory()
1499             throws AbstractZemucanException {
1500         Configurator.getInstance().setProperty(
1501                 Constants.GRAMMAR_READER_NAME_PROPERTY,
1502                 ImplementationXMLGrammarReaderTest.XML_GRAMMAR_READER);
1503         Configurator.getInstance().setProperty(
1504                 Constants.GRAMMAR_FILE_DESCRIPTORS_PROPERTY,
1505                 "grammar-test/directory1"); //$NON-NLS-1$
1506 
1507         final StartingNode node = GrammarReaderController.getInstance()
1508                 .getStartingNode();
1509 
1510         Assert.assertTrue("One grammar file in one directory", node != null);
1511     }
1512 
1513     /**
1514      * Tests a set of grammar files that are in several directories.
1515      *
1516      * @throws AbstractZemucanException
1517      *             Never.
1518      */
1519     @Test
1520     public final void testGrammarFilesInDirectories()
1521             throws AbstractZemucanException {
1522         Configurator.getInstance().setProperty(
1523                 Constants.GRAMMAR_READER_NAME_PROPERTY,
1524                 ImplementationXMLGrammarReaderTest.XML_GRAMMAR_READER);
1525         Configurator.getInstance().setProperty(
1526                 Constants.GRAMMAR_FILE_DESCRIPTORS_PROPERTY,
1527                 "grammar-test/directory1;grammar-test/directory2"); //$NON-NLS-1$
1528 
1529         final StartingNode node = GrammarReaderController.getInstance()
1530                 .getStartingNode();
1531 
1532         Assert.assertTrue(
1533                 "Three different file grammars in several directories",
1534                 node != null);
1535     }
1536 
1537     /**
1538      * Tests a grammar file in a directory.
1539      *
1540      * @throws AbstractZemucanException
1541      *             Never.
1542      */
1543     @Test
1544     public final void testGrammarFilesInDirectory()
1545             throws AbstractZemucanException {
1546         Configurator.getInstance().setProperty(
1547                 Constants.GRAMMAR_READER_NAME_PROPERTY,
1548                 ImplementationXMLGrammarReaderTest.XML_GRAMMAR_READER);
1549         Configurator.getInstance().setProperty(
1550                 Constants.GRAMMAR_FILE_DESCRIPTORS_PROPERTY,
1551                 "grammar-test/directory2/grammar-test-1.xml;" //$NON-NLS-1$
1552                         + "grammar-test/directory2/grammar-test-2.xml"); //$NON-NLS-1$
1553 
1554         final StartingNode node = GrammarReaderController.getInstance()
1555                 .getStartingNode();
1556 
1557         Assert.assertTrue("Grammar files in a directory", node != null);
1558     }
1559 
1560     /**
1561      * Tests a set of grammar files that are in a given directory.
1562      *
1563      * @throws AbstractZemucanException
1564      *             Never.
1565      */
1566     @Test
1567     public final void testGrammarFilesInOneDirectory()
1568             throws AbstractZemucanException {
1569         Configurator.getInstance().setProperty(
1570                 Constants.GRAMMAR_READER_NAME_PROPERTY,
1571                 ImplementationXMLGrammarReaderTest.XML_GRAMMAR_READER);
1572         Configurator.getInstance().setProperty(
1573                 Constants.GRAMMAR_FILE_DESCRIPTORS_PROPERTY,
1574                 "grammar-test/directory2"); //$NON-NLS-1$
1575 
1576         final StartingNode node = GrammarReaderController.getInstance()
1577                 .getStartingNode();
1578 
1579         Assert.assertTrue("Two different grammar files in one directory",
1580                 node != null);
1581     }
1582 
1583     /**
1584      * Tests that the configuration file has at least one delimiters tag.
1585      *
1586      * @throws AbstractZemucanException
1587      *             Never
1588      */
1589     @Test
1590     public void testNoDelimiters() throws AbstractZemucanException {
1591         String xml = ""; //$NON-NLS-1$
1592         xml += ImplementationXMLGrammarReaderTest.GRAMMAR_1_OPEN;
1593         xml += ImplementationXMLGrammarReaderTest.GRAMMAR_1_CLOSE;
1594         xml += ImplementationXMLGrammarReaderTest.TOKENS;
1595         // Starting Node.
1596         xml += ImplementationXMLGrammarReaderTest.TOKEN;
1597         xml += ImplementationXMLGrammarReaderTest.ID_STARTING_NODE_ID;
1598         xml += ImplementationXMLGrammarReaderTest.NAME_STARTING_NODE_NAME;
1599         xml += ImplementationXMLGrammarReaderTest.RESERVED;
1600         xml += ImplementationXMLGrammarReaderTest.CHILDREN;
1601         xml += ImplementationXMLGrammarReaderTest.ID_TOKEN_CREATE_ID_TOKEN;
1602         xml += ImplementationXMLGrammarReaderTest.CHILDREN_2;
1603         xml += ImplementationXMLGrammarReaderTest.TOKEN_2;
1604         // create Node.
1605         xml += ImplementationXMLGrammarReaderTest.TOKEN;
1606         xml += ImplementationXMLGrammarReaderTest.ID_CREATE_ID;
1607         xml += ImplementationXMLGrammarReaderTest.NAME_CREATE_NAME;
1608         xml += ImplementationXMLGrammarReaderTest.RESERVED;
1609         xml += ImplementationXMLGrammarReaderTest.CHILDREN;
1610         xml += ImplementationXMLGrammarReaderTest.ID_TOKEN_ENDING_NODE_ID_TOKEN;
1611         xml += ImplementationXMLGrammarReaderTest.CHILDREN_2;
1612         xml += ImplementationXMLGrammarReaderTest.TOKEN_2;
1613         // Ending Node.
1614         xml += ImplementationXMLGrammarReaderTest.TOKEN;
1615         xml += ImplementationXMLGrammarReaderTest.ID_ENDING_NODE_ID;
1616         xml += ImplementationXMLGrammarReaderTest.NAME_ENDING_NODE_NAME;
1617         xml += ImplementationXMLGrammarReaderTest.RESERVED;
1618         xml += ImplementationXMLGrammarReaderTest.TOKEN_2;
1619         xml += ImplementationXMLGrammarReaderTest.TOKENS_2;
1620         xml += ImplementationXMLGrammarReaderTest.GRAMMAR_2;
1621 
1622         final Graph graph = new Graph("delimiters", false); //$NON-NLS-1$
1623         final InputSource contentToParse = new InputSource(
1624                 new StringReader(xml));
1625         final InputSource contentToValidate = new InputSource(new StringReader(
1626                 xml));
1627         ImplementationXMLGrammarReaderTest.LOGGER.info("testNoDelimiters");
1628         ImplementationXMLGrammarReaderTest.LOGGER.debug(xml);
1629         final ImplementationXMLGrammarReader grammar = new ImplementationXMLGrammarReader(
1630                 graph, contentToParse, contentToValidate);
1631 
1632         Exception e = null;
1633         try {
1634             grammar.generateGraph();
1635         } catch (final Exception exception) {
1636             e = exception;
1637         }
1638         Assert.assertTrue("DelimitersIncorrectlyDefinedException",
1639                 e instanceof DelimitersIncorrectlyDefinedException);
1640     }
1641 
1642     /**
1643      * Tests a not existing file as grammar.
1644      *
1645      * @throws AbstractZemucanException
1646      *             Never.
1647      */
1648     @Test
1649     public void testNotExistingFile() throws AbstractZemucanException {
1650         final Graph actual = new Graph("grammar not existing", true); //$NON-NLS-1$
1651         ImplementationXMLGrammarReaderTest.LOGGER.info("testNotExistingFile");
1652         final ImplementationXMLGrammarReader grammar = new ImplementationXMLGrammarReader(
1653                 actual, "NotExistingGrammarFile.xml");
1654 
1655         Exception e = null;
1656         try {
1657             grammar.generateGraph();
1658         } catch (final Exception exception) {
1659             e = exception;
1660         }
1661         Assert.assertTrue("GeneralGrammarFileProblemException",
1662                 e instanceof GeneralGrammarFileProblemException);
1663     }
1664 
1665     /**
1666      * Tests that the configuration file is null.
1667      *
1668      * @throws AbstractZemucanException
1669      *             Never
1670      */
1671     @Test
1672     public void testNullContent1() throws AbstractZemucanException {
1673         final String xml = ""; //$NON-NLS-1$
1674 
1675         final Graph graph = new Graph("null content", false); //$NON-NLS-1$
1676         final InputSource contentToParse = new InputSource(
1677                 new StringReader(xml));
1678         final InputSource contentToValidate = null;
1679         ImplementationXMLGrammarReaderTest.LOGGER
1680                 .info("testNullContentToParse");
1681 
1682         Exception e = null;
1683         try {
1684             new ImplementationXMLGrammarReader(graph, contentToParse,
1685                     contentToValidate);
1686         } catch (final Exception exception) {
1687             e = exception;
1688         }
1689         Assert.assertTrue("ParameterNullException",
1690                 e instanceof ParameterNullException);
1691     }
1692 
1693     /**
1694      * Tests that the configuration file is null.
1695      *
1696      * @throws AbstractZemucanException
1697      *             Never
1698      */
1699     @Test
1700     public void testNullContent2() throws AbstractZemucanException {
1701         final String xml = ""; //$NON-NLS-1$
1702 
1703         final Graph graph = new Graph("null content", false); //$NON-NLS-1$
1704         final InputSource contentToParse = null;
1705         final InputSource contentToValidate = new InputSource(new StringReader(
1706                 xml));
1707         ImplementationXMLGrammarReaderTest.LOGGER
1708                 .info("testNullContentToValidate");
1709 
1710         Exception e = null;
1711         try {
1712             new ImplementationXMLGrammarReader(graph, contentToParse,
1713                     contentToValidate);
1714         } catch (final Exception exception) {
1715             e = exception;
1716         }
1717         Assert.assertTrue("ParameterNullException",
1718                 e instanceof ParameterNullException);
1719     }
1720 
1721     /**
1722      * Tests that a graph cannot be null.
1723      *
1724      * @throws AbstractZemucanException
1725      *             Never
1726      */
1727     @Test
1728     public void testNullGraph() throws AbstractZemucanException {
1729         final String xml = ""; //$NON-NLS-1$
1730 
1731         final InputSource contentToParse = new InputSource(
1732                 new StringReader(xml));
1733         final InputSource contentToValidate = new InputSource(new StringReader(
1734                 xml));
1735         ImplementationXMLGrammarReaderTest.LOGGER.info("testNullGraph");
1736 
1737         Exception e = null;
1738         try {
1739             new ImplementationXMLGrammarReader(null, contentToParse,
1740                     contentToValidate);
1741         } catch (final Exception exception) {
1742             e = exception;
1743         }
1744         Assert.assertTrue("ParameterNullException",
1745                 e instanceof ParameterNullException);
1746     }
1747 
1748     /**
1749      * Test the exception thrown when no filename defined.
1750      *
1751      * @throws AbstractZemucanException
1752      *             Never
1753      */
1754     @Test
1755     public void testReadNoFileDefined() throws AbstractZemucanException {
1756         final Graph actual = new Graph("grammar with file as null", true); //$NON-NLS-1$
1757         final String name = null;
1758         ImplementationXMLGrammarReaderTest.LOGGER.info("testReadNoFileDefined");
1759 
1760         Exception e = null;
1761         try {
1762             new ImplementationXMLGrammarReader(actual, name);
1763         } catch (final Exception exception) {
1764             e = exception;
1765         }
1766         Assert.assertTrue("ParameterNullException",
1767                 e instanceof ParameterNullException);
1768     }
1769 
1770 }