1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96 @RunWith(RandomTestRunner.class)
97 public final class ImplementationXMLGrammarReaderTest {
98
99
100
101 private static final String CHILDREN = "<children>";
102
103
104
105
106 private static final String CHILDREN_2 = "</children>";
107
108
109
110 private static final String CREATE = "create";
111
112
113
114 private static final String DELIMITERS_ABC_DELIMITERS = "delimiters=\"abc\"";
115
116
117
118 private static final String DELIMITERS_DELIMITERS = "delimiters=\" ;()\"";
119
120
121
122 private static final String GRAMMAR_1_CLOSE = ">";
123
124
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
129
130 private static final String GRAMMAR_2 = "</grammar>";
131
132
133
134 private static final String ID_CREATE_ID = "<id>create</id>";
135
136
137
138 private static final String ID_ENDING_NODE_ID = "<id>ENDING_NODE</id>";
139
140
141
142 private static final String ID_STARTING_NODE_ID = "<id>STARTING_NODE</id>";
143
144
145
146 private static final String ID_TABLE_ID = "<id>table</id>";
147
148
149
150 private static final String ID_TOKEN_CREATE_ID_TOKEN = "<idToken>create</idToken>";
151
152
153
154 private static final String ID_TOKEN_ENDING_NODE_ID_TOKEN = "<idToken>ENDING_NODE</idToken>";
155
156
157
158 private static final String ID_TOKEN_TABLE_ID_TOKEN = "<idToken>table</idToken>";
159
160
161
162 private static final Logger LOGGER = LoggerFactory
163 .getLogger(ImplementationXMLGrammarReaderTest.class);
164
165
166
167 private static final String NAME_CREATE_NAME = "<name>create</name>";
168
169
170
171 private static final String NAME_ENDING_NODE_NAME = "<name>ENDING_NODE</name>";
172
173
174
175 private static final String NAME_STARTING_NODE_NAME = "<name>STARTING_NODE</name>";
176
177
178
179 private static final String NAME_TABLE_NAME = "<name>table</name>";
180
181
182
183 private static final String NORMAL_GRAPH = "normal graph";
184
185
186
187 private static final String RESERVED = "<reserved />";
188
189
190
191 private static final String TABLE = "table";
192
193
194
195 private static final String TOKEN = "<token>";
196
197
198
199 private static final String TOKEN_2 = "</token>";
200
201
202
203 private static final String TOKENS = "<tokens>";
204
205
206
207 private static final String TOKENS_2 = "</tokens>";
208
209
210
211 private static final String XML_GRAMMAR_READER = "name.angoca.zemucan.grammarReader.impl.xml.ImplementationXMLGrammarReader";
212
213
214
215
216 @BeforeClass
217 public static void oneTimeSetUp() {
218 System.setProperty(Constants.ZEMUCAN_CONF_XML_PROPERTY,
219 "sa_conf-test.xml");
220 }
221
222
223
224
225 @AfterClass
226 public static void oneTimeTearDown() {
227
228 System.clearProperty(Constants.ZEMUCAN_CONF_XML_PROPERTY);
229 }
230
231
232
233
234 @After
235 public void tearDown() {
236 Configurator.destroyInstance();
237 GrammarReaderController.destroyInstance();
238 }
239
240
241
242
243
244
245
246 @Test
247 public void testBuildDuplicatedNode() throws AbstractZemucanException {
248 String xml = "";
249 xml += ImplementationXMLGrammarReaderTest.GRAMMAR_1_OPEN;
250 xml += ImplementationXMLGrammarReaderTest.DELIMITERS_DELIMITERS;
251 xml += ImplementationXMLGrammarReaderTest.GRAMMAR_1_CLOSE;
252 xml += ImplementationXMLGrammarReaderTest.TOKENS;
253
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
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
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);
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
300
301
302
303
304 @Test
305 public void testBuildEmptyFile() throws AbstractZemucanException {
306 final String xml = "";
307
308 final Graph graph = new Graph("empty file", false);
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
330
331
332
333
334 @Test
335 public void testBuildInvalidStructure() throws AbstractZemucanException {
336 String xml = "";
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);
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
367
368
369
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);
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);
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);
408 }
409
410 private String testBuildInvertedText() {
411 String xml = "";
412 xml += ImplementationXMLGrammarReaderTest.GRAMMAR_1_OPEN;
413 xml += ImplementationXMLGrammarReaderTest.DELIMITERS_DELIMITERS;
414 xml += ImplementationXMLGrammarReaderTest.GRAMMAR_1_CLOSE;
415 xml += ImplementationXMLGrammarReaderTest.TOKENS;
416
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
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
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
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
457
458
459
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);
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 = "";
489 xml += ImplementationXMLGrammarReaderTest.GRAMMAR_1_OPEN;
490 xml += ImplementationXMLGrammarReaderTest.DELIMITERS_DELIMITERS;
491 xml += ImplementationXMLGrammarReaderTest.GRAMMAR_1_CLOSE;
492 xml += ImplementationXMLGrammarReaderTest.TOKENS;
493
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
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
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
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
533
534
535
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);
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 = "";
565 xml += ImplementationXMLGrammarReaderTest.GRAMMAR_1_OPEN;
566 xml += ImplementationXMLGrammarReaderTest.DELIMITERS_DELIMITERS;
567 xml += ImplementationXMLGrammarReaderTest.GRAMMAR_1_CLOSE;
568 xml += ImplementationXMLGrammarReaderTest.TOKENS;
569
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
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
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
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
607
608
609
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);
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
639
640
641
642
643 @Test
644 public void testBuildNoEndingNode() throws AbstractZemucanException {
645 String xml = "";
646 xml += ImplementationXMLGrammarReaderTest.GRAMMAR_1_OPEN;
647 xml += ImplementationXMLGrammarReaderTest.DELIMITERS_DELIMITERS;
648 xml += ImplementationXMLGrammarReaderTest.GRAMMAR_1_CLOSE;
649 xml += ImplementationXMLGrammarReaderTest.TOKENS;
650
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
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";
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
691
692
693
694
695 @Test
696 public void testBuildNoId() throws AbstractZemucanException {
697 String xml = "";
698 xml += ImplementationXMLGrammarReaderTest.GRAMMAR_1_OPEN;
699 xml += ImplementationXMLGrammarReaderTest.DELIMITERS_DELIMITERS;
700 xml += ImplementationXMLGrammarReaderTest.GRAMMAR_1_CLOSE;
701 xml += ImplementationXMLGrammarReaderTest.TOKENS;
702
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
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
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);
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
750
751
752
753
754 @Test
755 public void testBuildNoIdNoName() throws AbstractZemucanException {
756 String xml = "";
757 xml += ImplementationXMLGrammarReaderTest.GRAMMAR_1_OPEN;
758 xml += ImplementationXMLGrammarReaderTest.DELIMITERS_DELIMITERS;
759 xml += ImplementationXMLGrammarReaderTest.GRAMMAR_1_CLOSE;
760 xml += ImplementationXMLGrammarReaderTest.TOKENS;
761
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
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
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);
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
808
809
810
811
812 @Test
813 public void testBuildNoName() throws AbstractZemucanException {
814 String xml = "";
815 xml += ImplementationXMLGrammarReaderTest.GRAMMAR_1_OPEN;
816 xml += ImplementationXMLGrammarReaderTest.DELIMITERS_DELIMITERS;
817 xml += ImplementationXMLGrammarReaderTest.GRAMMAR_1_CLOSE;
818 xml += ImplementationXMLGrammarReaderTest.TOKENS;
819
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
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
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);
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
867
868
869
870
871 @Test
872 public void testBuildNoNodes() throws AbstractZemucanException {
873 String xml = "";
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
904
905
906
907
908 @Test
909 public void testBuildNoStartingNode() throws AbstractZemucanException {
910 String xml = "";
911 xml += ImplementationXMLGrammarReaderTest.GRAMMAR_1_OPEN;
912 xml += ImplementationXMLGrammarReaderTest.DELIMITERS_DELIMITERS;
913 xml += ImplementationXMLGrammarReaderTest.GRAMMAR_1_CLOSE;
914 xml += ImplementationXMLGrammarReaderTest.TOKENS;
915
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
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";
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
957
958
959
960
961 @Test
962 public void testBuildNotAllChildren() throws AbstractZemucanException {
963 String xml = "";
964 xml += ImplementationXMLGrammarReaderTest.GRAMMAR_1_OPEN;
965 xml += ImplementationXMLGrammarReaderTest.DELIMITERS_DELIMITERS;
966 xml += ImplementationXMLGrammarReaderTest.GRAMMAR_1_CLOSE;
967 xml += ImplementationXMLGrammarReaderTest.TOKENS;
968
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);
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
1003
1004
1005
1006
1007
1008 @Test
1009 public void testBuildNotConnectedGraph() throws AbstractZemucanException {
1010 String xml = "";
1011 xml += ImplementationXMLGrammarReaderTest.GRAMMAR_1_OPEN;
1012 xml += ImplementationXMLGrammarReaderTest.DELIMITERS_DELIMITERS;
1013 xml += ImplementationXMLGrammarReaderTest.GRAMMAR_1_CLOSE;
1014 xml += ImplementationXMLGrammarReaderTest.TOKENS;
1015
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
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);
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
1053
1054
1055
1056
1057 @Test
1058 public void testBuildUnknownStructure() throws AbstractZemucanException {
1059 final String xml = "This can be a test file";
1060
1061 final Graph graph = new Graph("invalid structure", false);
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
1084
1085
1086
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,
1124 actual);
1125 }
1126
1127 private String testBuildWithExtraTokensText() {
1128 String xml = "";
1129 xml += ImplementationXMLGrammarReaderTest.GRAMMAR_1_OPEN;
1130 xml += ImplementationXMLGrammarReaderTest.DELIMITERS_DELIMITERS;
1131 xml += ImplementationXMLGrammarReaderTest.GRAMMAR_1_CLOSE;
1132 xml += ImplementationXMLGrammarReaderTest.TOKENS;
1133
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
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
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
1164
1165
1166
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,
1204 actual);
1205 }
1206
1207
1208
1209
1210
1211
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);
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 = "";
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
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
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
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
1275
1276
1277
1278
1279 @Test
1280 public void testEmptyDelimiters() throws AbstractZemucanException {
1281 String xml = "";
1282 xml += ImplementationXMLGrammarReaderTest.GRAMMAR_1_OPEN
1283 + " delimiters=\"\""
1284 + ImplementationXMLGrammarReaderTest.GRAMMAR_1_CLOSE;
1285 xml += ImplementationXMLGrammarReaderTest.TOKENS;
1286
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
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
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);
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
1335
1336
1337
1338
1339 @Test
1340 public void testEmptyGrammar() throws AbstractZemucanException {
1341 String xml = "";
1342 xml += ImplementationXMLGrammarReaderTest.GRAMMAR_1_OPEN;
1343 xml += ImplementationXMLGrammarReaderTest.DELIMITERS_DELIMITERS;
1344 xml += ImplementationXMLGrammarReaderTest.GRAMMAR_1_CLOSE;
1345 xml += ImplementationXMLGrammarReaderTest.TOKENS;
1346
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
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);
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 = "";
1386 xml += ImplementationXMLGrammarReaderTest.GRAMMAR_1_OPEN;
1387 xml += ImplementationXMLGrammarReaderTest.DELIMITERS_DELIMITERS;
1388 xml += ImplementationXMLGrammarReaderTest.GRAMMAR_1_CLOSE;
1389 xml += ImplementationXMLGrammarReaderTest.TOKENS;
1390
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
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>";
1407 xml += ImplementationXMLGrammarReaderTest.CHILDREN_2;
1408 xml += ImplementationXMLGrammarReaderTest.TOKEN_2;
1409
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
1422
1423
1424
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",
1463 actual.equals(expected));
1464 Assert.assertFalse(
1465 "Simple graph different with or without extra tokens",
1466 expected.equals(actual));
1467 }
1468
1469
1470
1471
1472
1473
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");
1484
1485 final StartingNode node = GrammarReaderController.getInstance()
1486 .getStartingNode();
1487
1488 Assert.assertTrue("Grammar file in a directory", node != null);
1489 }
1490
1491
1492
1493
1494
1495
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");
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
1515
1516
1517
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");
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
1539
1540
1541
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;"
1552 + "grammar-test/directory2/grammar-test-2.xml");
1553
1554 final StartingNode node = GrammarReaderController.getInstance()
1555 .getStartingNode();
1556
1557 Assert.assertTrue("Grammar files in a directory", node != null);
1558 }
1559
1560
1561
1562
1563
1564
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");
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
1585
1586
1587
1588
1589 @Test
1590 public void testNoDelimiters() throws AbstractZemucanException {
1591 String xml = "";
1592 xml += ImplementationXMLGrammarReaderTest.GRAMMAR_1_OPEN;
1593 xml += ImplementationXMLGrammarReaderTest.GRAMMAR_1_CLOSE;
1594 xml += ImplementationXMLGrammarReaderTest.TOKENS;
1595
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
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
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);
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
1644
1645
1646
1647
1648 @Test
1649 public void testNotExistingFile() throws AbstractZemucanException {
1650 final Graph actual = new Graph("grammar not existing", true);
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
1667
1668
1669
1670
1671 @Test
1672 public void testNullContent1() throws AbstractZemucanException {
1673 final String xml = "";
1674
1675 final Graph graph = new Graph("null content", false);
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
1695
1696
1697
1698
1699 @Test
1700 public void testNullContent2() throws AbstractZemucanException {
1701 final String xml = "";
1702
1703 final Graph graph = new Graph("null content", false);
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
1723
1724
1725
1726
1727 @Test
1728 public void testNullGraph() throws AbstractZemucanException {
1729 final String xml = "";
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
1750
1751
1752
1753
1754 @Test
1755 public void testReadNoFileDefined() throws AbstractZemucanException {
1756 final Graph actual = new Graph("grammar with file as null", true);
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 }