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 10:15:32 -0500 (dom, 06 mar 2011) $:
26   * Revision: $LastChangedRevision: 1913 $:
27   * URL:      $HeadURL: https://zemucan.svn.sourceforge.net/svnroot/zemucan/branches/zemucan_v1/source-code/graph/src/test/java/name/angoca/zemucan/core/graph/model/GraphNodeTest.java $:
28   */
29  package name.angoca.zemucan.core.graph.model;
30  
31  import java.util.List;
32  
33  import name.angoca.zemucan.AbstractZemucanException;
34  import name.angoca.zemucan.core.graph.api.InvalidGraphNodeException;
35  import name.angoca.zemucan.core.graph.api.NullGraphNodeException;
36  import name.angoca.zemucan.tools.test.RandomTestRunner;
37  
38  import org.junit.Assert;
39  import org.junit.Test;
40  import org.junit.runner.RunWith;
41  
42  /**
43   * These are the test for a node in the graph.
44   * <p>
45   * <b>Control Version</b>
46   * <p>
47   * <ul>
48   * <li>0.0.1 Class creation.</li>
49   * <li>0.0.2 Recommendations from PMD.</li>
50   * <li>0.0.3 Organized.</li>
51   * <li>0.1.0 jUnit 4 annotations.</li>
52   * <li>0.1.1 condition as a variable.</li>
53   * <li>1.0.0 Moved to version 1.</li>
54   * <li>1.1.0 Exception hierarchy changed.</li>
55   * <li>1.1.0 Symmetric test, congruent, transitivity and messages.</li>
56   * <li>1.2.0 More tests.</li>
57   * <li>1.3.0 Referencing StartingNode.</li>
58   * <li>1.4.0 test AddParent.</li>
59   * <li>1.4.1 GraphToken renamed by GraphNode</li>
60   * <li>1.5.0 GrammarReader separated from Graph.</li>
61   * <li>1.6.0 Node.</li>
62   * <li>1.7.0 Constructors, toStrings and removes.</li>
63   * <li>1.7.1 GraphNode Hierarchy.</li>
64   * </ul>
65   *
66   * @author Andres Gomez Casanova <a
67   *         href="mailto:a n g o c a at y a h o o dot c o m">(AngocA)</a>
68   * @version 1.7.1 2010-08-29
69   */
70  @RunWith(RandomTestRunner.class)
71  public final class GraphNodeTest {
72  
73      /**
74       * The 'a' word.
75       */
76      private static final String A = "a"; //$NON-NLS-1$
77      /**
78       * The 'child' word.
79       */
80      private static final String CHILD = "child"; //$NON-NLS-1$
81      /**
82       * The 'create' word.
83       */
84      private static final String CREATE = "create"; //$NON-NLS-1$
85      /**
86       * The 'graphnode' word.
87       */
88      private static final String GRAPHNODE = "graphnode"; //$NON-NLS-1$
89      /**
90       * The 'node' word.
91       */
92      private static final String NODE = "node"; //$NON-NLS-1$
93      /**
94       * The 'parent' word.
95       */
96      private static final String PARENT = "parent"; //$NON-NLS-1$
97      /**
98       * The 'table' word.
99       */
100     private static final String TABLE = "table"; //$NON-NLS-1$
101     /**
102      * The '&lt;tablename&gt;' word.
103      */
104     private static final String TABLENAME = "<tableName>"; //$NON-NLS-1$
105     /**
106      * The 'tablepsace' word.
107      */
108     private static final String TABLESPACE = "tablespace"; //$NON-NLS-1$
109 
110     /**
111      * Default constructor.
112      */
113     public GraphNodeTest() {
114         // Nothing.
115     }
116 
117     /**
118      * Test that a graph node be referenced by EndingNode as parent of it.
119      *
120      * @throws AbstractZemucanException
121      *             Never.
122      */
123     @Test
124     public void testAddEndingNodeParent() throws AbstractZemucanException {
125         final Graph graph = new Graph("test", false);
126 
127         final String name = GraphNodeTest.NODE;
128         final EndingNode node = new EndingNode(graph);
129 
130         final GraphNode graphNode = new GraphNode(name, graph);
131 
132         Exception e = null;
133         try {
134             graphNode.addParent(node);
135         } catch (final Exception exception) {
136             e = exception;
137         }
138         Assert.assertTrue("ReferencingEndingNodeException",
139                 e instanceof ReferencingEndingNodeException);
140     }
141 
142     /**
143      * Test that a graph node cannot receive a null way.
144      *
145      * @throws AbstractZemucanException
146      *             Never.
147      */
148     @Test
149     public void testAddNullChild() throws AbstractZemucanException {
150         final String name = GraphNodeTest.NODE;
151         final GraphNode nul = null;
152 
153         final GraphNode graphNode = new GraphNode(name,
154                 new Graph("test", false));
155 
156         Exception e = null;
157         try {
158             graphNode.addChild(nul);
159         } catch (final Exception exception) {
160             e = exception;
161         }
162         Assert.assertTrue("NullGraphNodeException",
163                 e instanceof NullGraphNodeException);
164     }
165 
166     /**
167      * Test that a graph node cannot receive a null parent.
168      *
169      * @throws AbstractZemucanException
170      *             Never.
171      */
172     @Test
173     public void testAddNullParent() throws AbstractZemucanException {
174         final String name = GraphNodeTest.NODE;
175         final GraphNode nul = null;
176 
177         final GraphNode graphNode = new GraphNode(name,
178                 new Graph("test", false));
179 
180         Exception e = null;
181         try {
182             graphNode.addParent(nul);
183         } catch (final Exception exception) {
184             e = exception;
185         }
186         Assert.assertTrue("NullGraphNodeException",
187                 e instanceof NullGraphNodeException);
188     }
189 
190     /**
191      * Adds twice the same child node.
192      *
193      * @throws AbstractZemucanException
194      *             Never.
195      */
196     @Test
197     public void testAddTwiceSameChild() throws AbstractZemucanException {
198         final Graph graph = new Graph("test", false);
199 
200         final String name = GraphNodeTest.NODE;
201         final GraphNode node = new GraphNode(name, graph);
202 
203         final String childName = GraphNodeTest.CHILD;
204         final GraphNode child = new GraphNode(childName, graph);
205 
206         node.addChild(child);
207         node.addChild(child);
208 
209         final int children = node.getChildren().size();
210 
211         Assert.assertTrue("One child", children == 1); //$NON-NLS-1$
212     }
213 
214     /**
215      * Adds twice the same parent node.
216      *
217      * @throws AbstractZemucanException
218      *             Never.
219      */
220     @Test
221     public void testAddTwiceSameParent() throws AbstractZemucanException {
222         final Graph graph = new Graph("test", false);
223 
224         final String name = GraphNodeTest.NODE;
225         final GraphNode node = new GraphNode(name, graph);
226 
227         final String parentName = GraphNodeTest.PARENT;
228         final GraphNode parent = new GraphNode(parentName, graph);
229 
230         node.addParent(parent);
231         node.addParent(parent);
232 
233         final int parents = node.getParents().size();
234 
235         Assert.assertTrue("One parent", parents == 1); //$NON-NLS-1$
236     }
237 
238     /**
239      * Tests if two consecutive calls returns the same value.
240      *
241      * @throws AbstractZemucanException
242      *             Never
243      */
244     @Test
245     public void testCongruent() throws AbstractZemucanException {
246         final String node = "test"; //$NON-NLS-1$
247 
248         final GraphNode node1 = new GraphNode(node, new Graph("test", false));
249         final int val1 = node1.hashCode();
250         final int val2 = node1.hashCode();
251 
252         final boolean val = val1 == val2;
253 
254         Assert.assertTrue("Two consecutive calls return the same value", val); //$NON-NLS-1$
255     }
256 
257     /**
258      * Tests that the graph node has to receive a not null parameter.
259      *
260      * @throws AbstractZemucanException
261      *             Never.
262      */
263     @Test(expected = AssertionError.class)
264     public void testConstructorNull1() throws AbstractZemucanException {
265         new GraphNode(null, new Graph("test", false));
266     }
267 
268     /**
269      * Tests that the graph node has to receive a not null parameter.
270      *
271      * @throws AbstractZemucanException
272      *             Never.
273      */
274     @Test(expected = AssertionError.class)
275     public void testConstructorNull2() throws AbstractZemucanException {
276         new GraphNode(GraphNodeTest.A, null, new Graph("test", false));
277     }
278 
279     /**
280      * Test two identical nodes with different children.
281      *
282      * @throws AbstractZemucanException
283      *             Never
284      */
285     @Test
286     public void testEqualsDifferentChildren()
287             throws AbstractZemucanException {
288         final Graph graph = new Graph("test", false);
289 
290         final String node11 = GraphNodeTest.CREATE;
291         final String node12 = GraphNodeTest.TABLE;
292         final String node21 = GraphNodeTest.CREATE;
293         final String node22 = GraphNodeTest.TABLESPACE;
294 
295         final GraphNode actual = new GraphNode(node11, graph);
296         final GraphNode child1 = new GraphNode(node12, graph);
297         actual.addChild(child1);
298         final GraphNode expected = new GraphNode(node21, graph);
299         final GraphNode child2 = new GraphNode(node22, graph);
300         expected.addChild(child2);
301         final boolean condition1 = actual.equals(expected);
302         final boolean condition2 = expected.equals(actual);
303 
304         Assert.assertFalse("1 - Two identical nodes with different children "//$NON-NLS-1$
305                 + "(a.equals(e))", condition1); //$NON-NLS-1$
306         Assert.assertFalse("2 - Two identical nodes with different children "//$NON-NLS-1$
307                 + "(e.equals(a))", condition2); //$NON-NLS-1$
308     }
309 
310     /**
311      * Test two different nodes (reserved and non reserved).
312      *
313      * @throws AbstractZemucanException
314      *             Never.
315      */
316     @Test
317     public void testEqualsDifferentMixed() throws AbstractZemucanException {
318         final Graph graph = new Graph("test", false);
319 
320         final String node1 = GraphNodeTest.CREATE;
321         final String node2 = GraphNodeTest.TABLENAME;
322 
323         final GraphNode actual = new GraphNode(node1, graph);
324         final NonReservedGraphNode expected = new NonReservedGraphNode(node2,
325                 graph);
326         final boolean condition1 = actual.equals(expected);
327         final boolean condition2 = expected.equals(actual);
328 
329         Assert.assertFalse("1 - Two different nodes - mixed", //$NON-NLS-1$
330                 condition1);
331         Assert.assertFalse("2 - Two different nodes - mixed", //$NON-NLS-1$
332                 condition2);
333     }
334 
335     /**
336      * Test two different nodes (non reserved).
337      *
338      * @throws AbstractZemucanException
339      *             Never.
340      */
341     @Test
342     public void testEqualsDifferentNotReserved()
343             throws AbstractZemucanException {
344         final Graph graph = new Graph("test", false);
345 
346         final String node1 = GraphNodeTest.TABLENAME;
347         final String node2 = "<colName>"; //$NON-NLS-1$
348 
349         final NonReservedGraphNode actual = new NonReservedGraphNode(node1,
350                 graph);
351         final NonReservedGraphNode expected = new NonReservedGraphNode(node2,
352                 graph);
353         final boolean condition = actual.equals(expected);
354         final boolean condition2 = expected.equals(actual);
355 
356         Assert.assertFalse("two different nodes - non reserved", //$NON-NLS-1$
357                 condition);
358         Assert.assertFalse("two different nodes - non reserved 2", //$NON-NLS-1$
359                 condition2);
360     }
361 
362     /**
363      * Test two identical nodes with different parents.
364      *
365      * @throws AbstractZemucanException
366      *             Never
367      */
368     @Test
369     public void testEqualsDifferentParents()
370             throws AbstractZemucanException {
371         final Graph graph = new Graph("test", false);
372 
373         final String node11 = GraphNodeTest.CREATE;
374         final String node12 = GraphNodeTest.TABLE;
375         final String node21 = GraphNodeTest.CREATE;
376         final String node22 = GraphNodeTest.TABLESPACE;
377 
378         final GraphNode actual = new GraphNode(node11, graph);
379         final GraphNode parent1 = new GraphNode(node12, graph);
380         actual.addParent(parent1);
381         final GraphNode expected = new GraphNode(node21, graph);
382         final GraphNode parent2 = new GraphNode(node22, graph);
383         expected.addParent(parent2);
384         final boolean condition1 = actual.equals(expected);
385         final boolean condition2 = expected.equals(actual);
386 
387         Assert.assertFalse("1 - Two identical nodes with different parents "//$NON-NLS-1$
388                 + "(a.equals(e))", condition1); //$NON-NLS-1$
389         Assert.assertFalse("2 - Two identical nodes with different parents "//$NON-NLS-1$
390                 + "(e.equals(a))", condition2); //$NON-NLS-1$
391     }
392 
393     /**
394      * Test two different nodes (reserved).
395      *
396      * @throws AbstractZemucanException
397      *             Never.
398      */
399     @Test
400     public void testEqualsDifferentReserved()
401             throws AbstractZemucanException {
402         final Graph graph = new Graph("test", false);
403 
404         final String node1 = GraphNodeTest.CREATE;
405         final String node2 = GraphNodeTest.TABLE;
406 
407         final GraphNode actual = new GraphNode(node1, graph);
408         final GraphNode expected = new GraphNode(node2, graph);
409         final boolean condition = actual.equals(expected);
410         final boolean condition2 = expected.equals(actual);
411 
412         Assert.assertFalse("two different node - reserved", condition); //$NON-NLS-1$
413         Assert.assertFalse("two different node - reserved 2", condition2); //$NON-NLS-1$
414     }
415 
416     /**
417      * Test two identical nodes with one of them with more children.
418      *
419      * @throws AbstractZemucanException
420      *             Never.
421      */
422     @Test
423     public void testEqualsMoreChildren() throws AbstractZemucanException {
424         final Graph graph = new Graph("test", false);
425 
426         final String node11 = GraphNodeTest.CREATE;
427         final String node12 = GraphNodeTest.TABLE;
428         final String node21 = GraphNodeTest.CREATE;
429         final String node22 = GraphNodeTest.TABLE;
430         final String node23 = GraphNodeTest.TABLESPACE;
431 
432         final GraphNode actual = new GraphNode(node11, graph);
433         final GraphNode child1 = new GraphNode(node12, graph);
434         actual.addChild(child1);
435         final GraphNode expected = new GraphNode(node21, graph);
436         final GraphNode child2 = new GraphNode(node22, graph);
437         expected.addChild(child2);
438         final GraphNode child3 = new GraphNode(node23, graph);
439         expected.addChild(child3);
440         final boolean condition1 = actual.equals(expected);
441         final boolean condition2 = expected.equals(actual);
442 
443         Assert.assertFalse("1 - two identical node, one with children", //$NON-NLS-1$
444                 condition1);
445         Assert.assertFalse("2- two identical node, one with children", //$NON-NLS-1$
446                 condition2);
447     }
448 
449     /**
450      * Test two identical nodes that represents a not reserved word.
451      *
452      * @throws AbstractZemucanException
453      *             Never.
454      */
455     @Test
456     public void testEqualsNotReserved() throws AbstractZemucanException {
457         final Graph graph = new Graph("test", false);
458 
459         final String node1 = GraphNodeTest.TABLENAME;
460         final String node2 = GraphNodeTest.TABLENAME;
461 
462         final NonReservedGraphNode actual = new NonReservedGraphNode(node1,
463                 graph);
464         final NonReservedGraphNode expected = new NonReservedGraphNode(node2,
465                 graph);
466         final boolean condition = actual.equals(expected);
467         final boolean condition2 = expected.equals(actual);
468 
469         Assert.assertTrue("two identical node reserved", condition); //$NON-NLS-1$
470         Assert.assertTrue("two identical node reserved2", condition2); //$NON-NLS-1$
471     }
472 
473     /**
474      * Test equals with other null.
475      *
476      * @throws AbstractZemucanException
477      *             Never.
478      */
479     @Test
480     public void testEqualsNull() throws AbstractZemucanException {
481         final String node1 = GraphNodeTest.CREATE;
482 
483         final GraphNode actual = new GraphNode(node1, new Graph("test", false));
484 
485         final GraphNode nullObject = null;
486 
487         final boolean condition = actual.equals(nullObject);
488 
489         Assert.assertFalse("equals with null value", condition); //$NON-NLS-1$
490     }
491 
492     /**
493      * Test equals with other object.
494      *
495      * @throws AbstractZemucanException
496      *             Never.
497      */
498     @Test
499     public void testEqualsOtherObject() throws AbstractZemucanException {
500         final Graph graph = new Graph("test", false);
501 
502         final String node1 = GraphNodeTest.CREATE;
503 
504         final GraphNode actual = new GraphNode(node1, graph);
505         final StartingNode expected = new StartingNode(graph);
506         final boolean condition = actual.equals(expected);
507         final boolean condition2 = expected.equals(actual);
508 
509         Assert.assertFalse("equals with two identical objects", //$NON-NLS-1$
510                 condition);
511         Assert.assertFalse("equals with two identical objects 2", //$NON-NLS-1$
512                 condition2);
513     }
514 
515     /**
516      * Test two identical nodes that represents a reserved word.
517      *
518      * @throws AbstractZemucanException
519      *             never.
520      */
521     @Test
522     public void testEqualsReserved() throws AbstractZemucanException {
523         final Graph graph = new Graph("test", false);
524 
525         final String node1 = GraphNodeTest.CREATE;
526         final String node2 = GraphNodeTest.CREATE;
527 
528         final GraphNode actual = new GraphNode(node1, graph);
529         final GraphNode expected = new GraphNode(node2, graph);
530         final boolean condition = actual.equals(expected);
531         final boolean condition2 = expected.equals(actual);
532 
533         Assert.assertTrue("two identical nodes - reserved word", //$NON-NLS-1$
534                 condition);
535         Assert.assertTrue("two identical nodes - reserved word 2", //$NON-NLS-1$
536                 condition2);
537     }
538 
539     /**
540      * Test two identical nodes with same children.
541      *
542      * @throws AbstractZemucanException
543      *             Never.
544      */
545     @Test
546     public void testEqualsSameChildren() throws AbstractZemucanException {
547         final Graph graph = new Graph("test", false);
548 
549         final String node11 = GraphNodeTest.CREATE;
550         final String node12 = GraphNodeTest.TABLE;
551         final String node21 = GraphNodeTest.CREATE;
552         final String node22 = GraphNodeTest.TABLE;
553 
554         final GraphNode actual = new GraphNode(node11, graph);
555         final GraphNode child1 = new GraphNode(node12, graph);
556         actual.addChild(child1);
557         final GraphNode expected = new GraphNode(node21, graph);
558         final GraphNode child2 = new GraphNode(node22, graph);
559         expected.addChild(child2);
560         final boolean condition = actual.equals(expected);
561         final boolean condition2 = expected.equals(actual);
562 
563         Assert.assertTrue("Two identical nodes with same children", condition); //$NON-NLS-1$
564         Assert.assertTrue("Two identical nodes with same children2", //$NON-NLS-1$
565                 condition2);
566     }
567 
568     /**
569      * Test a the hashcode of two different nodes.
570      *
571      * @throws AbstractZemucanException
572      *             Never.
573      */
574     @Test
575     public void testHashCodeDifferent() throws AbstractZemucanException {
576         final Graph graph = new Graph("test", false);
577 
578         final String node1 = GraphNodeTest.CREATE;
579         final String node2 = GraphNodeTest.TABLENAME;
580 
581         final GraphNode actual = new GraphNode(node1, graph);
582         final NonReservedGraphNode expected = new NonReservedGraphNode(node2,
583                 graph);
584 
585         final int actualHashcode = actual.hashCode();
586         final int expectedHashcode = expected.hashCode();
587         final boolean condition = actualHashcode == expectedHashcode;
588 
589         Assert.assertFalse("Hashcode of two different nodes", condition); //$NON-NLS-1$
590     }
591 
592     /**
593      * Test a the hashcode of two different objects.
594      *
595      * @throws AbstractZemucanException
596      *             Never.
597      */
598     @Test
599     public void testHashCodeDifferentWithChildren()
600             throws AbstractZemucanException {
601         final Graph graph = new Graph("test", false);
602 
603         final String node1 = GraphNodeTest.CREATE;
604         final String node2 = GraphNodeTest.CREATE;
605         final String node21 = GraphNodeTest.TABLE;
606 
607         final NonReservedGraphNode actual = new NonReservedGraphNode(node1,
608                 graph);
609         final NonReservedGraphNode expected = new NonReservedGraphNode(node2,
610                 graph);
611         final NonReservedGraphNode child = new NonReservedGraphNode(node21,
612                 graph);
613         expected.addChild(child);
614 
615         final int actualHash = actual.hashCode();
616         final int expectedHash = expected.hashCode();
617 
618         final boolean condition = actualHash == expectedHash;
619 
620         Assert.assertFalse("Hashcode of two different objects", condition); //$NON-NLS-1$
621     }
622 
623     /**
624      * Test a the hashcode of two identical non reserved nodes.
625      *
626      * @throws AbstractZemucanException
627      *             Never.
628      */
629     @Test
630     public void testHashCodeIdenticalNotReserved()
631             throws AbstractZemucanException {
632         final Graph graph = new Graph("test", false);
633 
634         final String node1 = GraphNodeTest.TABLENAME;
635         final String node2 = GraphNodeTest.TABLENAME;
636 
637         final NonReservedGraphNode actual = new NonReservedGraphNode(node1,
638                 graph);
639         final NonReservedGraphNode expected = new NonReservedGraphNode(node2,
640                 graph);
641 
642         final boolean condition = actual.hashCode() == expected.hashCode();
643 
644         Assert.assertTrue("Hashcod of two identical non reserved nodes", //$NON-NLS-1$
645                 condition);
646     }
647 
648     /**
649      * Test a the hashcode of two identical reserved nodes.
650      *
651      * @throws AbstractZemucanException
652      *             Never.
653      */
654     @Test
655     public void testHashCodeIdenticalReserved()
656             throws AbstractZemucanException {
657         final Graph graph = new Graph("test", false);
658 
659         final String node1 = GraphNodeTest.CREATE;
660         final String node2 = GraphNodeTest.CREATE;
661 
662         final GraphNode actual = new GraphNode(node1, graph);
663         final GraphNode expected = new GraphNode(node2, graph);
664 
665         final boolean condition = actual.hashCode() == expected.hashCode();
666 
667         Assert.assertTrue("Hashcode of two identical reserved nodes", //$NON-NLS-1$
668                 condition);
669     }
670 
671     /**
672      * Test the creation of a node with an invalid name.
673      *
674      * @throws InvalidGraphNodeException
675      *             Never
676      */
677     @Test
678     public void testInvalidName() throws InvalidGraphNodeException {
679         final String node = ""; //$NON-NLS-1$
680 
681         Exception e = null;
682         try {
683             new GraphNode(node, new Graph("test", false));
684         } catch (final Exception exception) {
685             e = exception;
686         }
687         Assert.assertTrue("InvalidGraphNodeException",
688                 e instanceof InvalidGraphNodeException);
689     }
690 
691     /**
692      * Tests that a node cannot reference to StartingNode.
693      *
694      * @throws AbstractZemucanException
695      *             Never.
696      */
697     @Test
698     public void testReferencingStartingNode()
699             throws AbstractZemucanException {
700         final Graph graph = new Graph("test", false);
701 
702         final String name = GraphNodeTest.GRAPHNODE;
703 
704         final GraphNode graphNode = new GraphNode(name, graph);
705         final StartingNode starting = new StartingNode(graph);
706 
707         Exception e = null;
708         try {
709             graphNode.addChild(starting);
710         } catch (final Exception exception) {
711             e = exception;
712         }
713         Assert.assertTrue("ReferencingStartingNodeException",
714                 e instanceof ReferencingStartingNodeException);
715     }
716 
717     /**
718      * Removes a child from the list of children.
719      *
720      * @throws AbstractZemucanException
721      *             Never.
722      */
723     @Test
724     public void testRemoveChild() throws AbstractZemucanException {
725         final Graph graph = new Graph("test", false);
726 
727         final String name = GraphNodeTest.GRAPHNODE;
728         final GraphNode graphNode = new GraphNode(name, graph);
729 
730         int size = graphNode.getChildren().size();
731 
732         Assert.assertTrue("No children", size == 0); //$NON-NLS-1$
733 
734         final String childName = GraphNodeTest.CHILD;
735         final GraphNode child = new GraphNode(childName, graph);
736 
737         graphNode.addChild(child);
738 
739         size = graphNode.getChildren().size();
740 
741         Assert.assertTrue("One child", size == 1); //$NON-NLS-1$
742 
743         graphNode.removeChild(child);
744 
745         size = graphNode.getChildren().size();
746 
747         Assert.assertTrue("No children after remove", size == 0); //$NON-NLS-1$
748     }
749 
750     /**
751      * Tries to remove a null child.
752      *
753      * @throws AbstractZemucanException
754      *             Never.
755      */
756     @Test
757     public void testRemoveNullChild() throws AbstractZemucanException {
758         final String name = GraphNodeTest.GRAPHNODE;
759         final GraphNode graphNode = new GraphNode(name,
760                 new Graph("test", false));
761 
762         Exception e = null;
763         try {
764             graphNode.removeChild(null);
765         } catch (final Exception exception) {
766             e = exception;
767         }
768         Assert.assertTrue("NullGraphNodeException",
769                 e instanceof NullGraphNodeException);
770     }
771 
772     /**
773      * Tries to remove a null parent.
774      *
775      * @throws AbstractZemucanException
776      *             Never.
777      */
778     @Test
779     public void testRemoveNullParent() throws AbstractZemucanException {
780         final String name = GraphNodeTest.GRAPHNODE;
781         final GraphNode graphNode = new GraphNode(name,
782                 new Graph("test", false));
783 
784         Exception e = null;
785         try {
786             graphNode.removeParent(null);
787         } catch (final Exception exception) {
788             e = exception;
789         }
790         Assert.assertTrue("NullGraphNodeException",
791                 e instanceof NullGraphNodeException);
792     }
793 
794     /**
795      * Removes a parent from the list of parents.
796      *
797      * @throws AbstractZemucanException
798      *             Never.
799      */
800     @Test
801     public void testRemoveParent() throws AbstractZemucanException {
802         final Graph graph = new Graph("test", false);
803 
804         final String name = GraphNodeTest.GRAPHNODE;
805         final GraphNode graphNode = new GraphNode(name, graph);
806 
807         int size = graphNode.getParents().size();
808 
809         Assert.assertTrue("No parents", size == 0); //$NON-NLS-1$
810 
811         final String parentName = GraphNodeTest.PARENT;
812         final GraphNode parent = new GraphNode(parentName, graph);
813 
814         graphNode.addParent(parent);
815 
816         size = graphNode.getParents().size();
817 
818         Assert.assertTrue("One parents", size == 1); //$NON-NLS-1$
819 
820         graphNode.removeParent(parent);
821 
822         size = graphNode.getParents().size();
823 
824         Assert.assertTrue("No parents after remove", size == 0); //$NON-NLS-1$
825     }
826 
827     /**
828      * Represents a reserved word in capitals with a reserved word not in
829      * capitals.
830      *
831      * @throws AbstractZemucanException
832      *             Never.
833      */
834     @Test
835     public void testRepresentCapitalReservedFalse()
836             throws AbstractZemucanException {
837         final String node1 = GraphNodeTest.CREATE;
838         final String node2 = "TABLE"; //$NON-NLS-1$
839 
840         final GraphNode node = new GraphNode(node1, new Graph("test", false));
841         final boolean condition = node.represent(node2);
842 
843         Assert.assertFalse("Represents capitals with no capitals", condition); //$NON-NLS-1$
844     }
845 
846     /**
847      * Represents a reserved word in capitals.
848      *
849      * @throws AbstractZemucanException
850      *             Never.
851      */
852     @Test
853     public void testRepresentCapitalReservedTrue()
854             throws AbstractZemucanException {
855         final String node1 = GraphNodeTest.CREATE;
856         final String node2 = "CREATE"; //$NON-NLS-1$
857 
858         final GraphNode node = new GraphNode(node1, new Graph("test", false));
859         final boolean condition = node.represent(node2);
860 
861         Assert.assertTrue("Represents capitals", condition); //$NON-NLS-1$
862     }
863 
864     /**
865      * Represents a word with a not reserved word.
866      *
867      * @throws AbstractZemucanException
868      *             Never.
869      */
870     @Test
871     public void testRepresentNotReservedTrue()
872             throws AbstractZemucanException {
873         final String node1 = GraphNodeTest.TABLENAME;
874         final String node2 = "Employees"; //$NON-NLS-1$
875 
876         final NonReservedGraphNode node = new NonReservedGraphNode(node1,
877                 new Graph("test", false));
878         final boolean condition = node.represent(node2);
879 
880         Assert.assertTrue("Represents a no reserved word", condition); //$NON-NLS-1$
881     }
882 
883     /**
884      * Represents two different reserved words.
885      *
886      * @throws AbstractZemucanException
887      *             Never.
888      */
889     @Test
890     public void testRepresentReservedFalse()
891             throws AbstractZemucanException {
892         final String node1 = GraphNodeTest.CREATE;
893         final String node2 = GraphNodeTest.TABLE;
894 
895         final GraphNode node = new GraphNode(node1, new Graph("test", false));
896         final boolean condition = node.represent(node2);
897 
898         Assert.assertFalse("Represents a reserved word", condition); //$NON-NLS-1$
899     }
900 
901     /**
902      * Represents a reserved word.
903      *
904      * @throws AbstractZemucanException
905      *             Never.
906      */
907     @Test
908     public void testRepresentReservedTrue() throws AbstractZemucanException {
909         final String node1 = GraphNodeTest.CREATE;
910         final String node2 = GraphNodeTest.CREATE;
911 
912         final GraphNode node = new GraphNode(node1, new Graph("test", false));
913         final boolean condition = node.represent(node2);
914 
915         Assert.assertTrue("Not represents a reserved word", condition); //$NON-NLS-1$
916     }
917 
918     /**
919      * Tests the represents method that can not receive a null parameter.
920      *
921      * @throws AbstractZemucanException
922      *             Never.
923      */
924     @Test(expected = AssertionError.class)
925     public void testRepresentsNull() throws AbstractZemucanException {
926         final GraphNode node = new GraphNode(GraphNodeTest.A, new Graph("test",
927                 false));
928 
929         node.represent(null);
930     }
931 
932     /**
933      * Tests addParent.
934      *
935      * @throws AbstractZemucanException
936      *             Never.
937      */
938     @Test
939     public void testSeveralOperations() throws AbstractZemucanException {
940         final Graph graph = new Graph("test", false);
941 
942         final String text1 = "test1"; //$NON-NLS-1$
943         final String text2 = "test2"; //$NON-NLS-1$
944 
945         final NonReservedGraphNode node1 = new NonReservedGraphNode(text1,
946                 graph);
947         final NonReservedGraphNode node2 = new NonReservedGraphNode(text2,
948                 graph);
949 
950         node1.addParent(node2);
951         node1.getParents();
952 
953         node2.setName(text1);
954 
955         node1.setComeFromStartingNode(false);
956         node1.isComeFromStartingNode();
957 
958         node2.setGoToEndingNode(false);
959         node2.isGoToEndingNode();
960     }
961 
962     /**
963      * Tests the getter methods.
964      *
965      * @throws AbstractZemucanException
966      *             Never.
967      */
968     @Test
969     public void testSimpleMethods() throws AbstractZemucanException {
970         final String name = GraphNodeTest.GRAPHNODE;
971         String graphname = "test";
972 
973         final GraphNode graphNode = new GraphNode(name, new Graph(graphname,
974                 false));
975 
976         String actual = graphNode.getId();
977 
978         String expected = graphname + ":" + name;
979 
980         Assert.assertEquals("id", expected, actual); //$NON-NLS-1$
981 
982         actual = graphNode.getName();
983 
984         expected = name;
985 
986         Assert.assertEquals("name", expected, actual); //$NON-NLS-1$
987 
988         final List<AbstractGraphNode> ways = graphNode.getChildren();
989 
990         final boolean condition = ways.size() == 0;
991 
992         Assert.assertTrue("ways", condition); //$NON-NLS-1$
993     }
994 
995     /**
996      * Tests the symmetry of equals not reserved.
997      *
998      * @throws AbstractZemucanException
999      *             Never.
1000      */
1001     @Test
1002     public void testSymmetricNotReserved() throws AbstractZemucanException {
1003         final String text = "test"; //$NON-NLS-1$
1004 
1005         final NonReservedGraphNode actual = new NonReservedGraphNode(text,
1006                 new Graph("test", false));
1007 
1008         final boolean value = actual.equals(actual);
1009 
1010         Assert.assertTrue("Symmetry not reserved", value); //$NON-NLS-1$
1011     }
1012 
1013     /**
1014      * Tests the symmetry of equals reserved.
1015      *
1016      * @throws AbstractZemucanException
1017      *             Never.
1018      */
1019     @Test
1020     public void testSymmetricReserved() throws AbstractZemucanException {
1021         final String text = "test"; //$NON-NLS-1$
1022 
1023         final GraphNode actual = new GraphNode(text, new Graph("test", false));
1024 
1025         final boolean value = actual.equals(actual);
1026 
1027         Assert.assertTrue("Symmetry reserved", value); //$NON-NLS-1$
1028     }
1029 
1030     /**
1031      * Test a node that is not a reserved word.
1032      *
1033      * @throws AbstractZemucanException
1034      *             Never.
1035      */
1036     @Test
1037     public void testToStringNotReserved() throws AbstractZemucanException {
1038         final String nodeIn = GraphNodeTest.TABLENAME;
1039         final String nodeOut = "<tableName>::{<tableName>\n0\n0\nfalse|false}"; //$NON-NLS-1$
1040 
1041         final NonReservedGraphNode actualnode = new NonReservedGraphNode(
1042                 nodeIn, new Graph("test", false));
1043         final String actual = actualnode.toString();
1044         final String expected = nodeOut;
1045 
1046         Assert.assertEquals("Not represents a not reserved word", expected, //$NON-NLS-1$
1047                 actual);
1048     }
1049 
1050     /**
1051      * Test a node that is a reserved word.
1052      *
1053      * @throws AbstractZemucanException
1054      *             Never.
1055      */
1056     @Test
1057     public void testToStringReserved() throws AbstractZemucanException {
1058         final String nodeIn = GraphNodeTest.CREATE;
1059         final String nodeOut = "create|R::{create\n0\n0\nfalse|false}"; //$NON-NLS-1$
1060 
1061         final GraphNode actualnode = new GraphNode(nodeIn, new Graph("test",
1062                 false));
1063         final String actual = actualnode.toString();
1064         final String expected = nodeOut;
1065 
1066         Assert.assertEquals("Is a reserved word", expected, actual); //$NON-NLS-1$
1067     }
1068 
1069     /**
1070      * Test a node with children.
1071      *
1072      * @throws AbstractZemucanException
1073      *             Never.
1074      */
1075     @Test
1076     public void testToStringWithChildren() throws AbstractZemucanException {
1077         final Graph graph = new Graph("test", false);
1078 
1079         final String nodeIn = GraphNodeTest.TABLENAME;
1080         final String nodeIn1 = GraphNodeTest.TABLENAME;
1081         final String nodeOut = GraphNodeTest.TABLENAME + "::" + '{'
1082                 + GraphNodeTest.TABLENAME
1083                 + "\n0\n1\t[" + GraphNodeTest.TABLENAME + "]\nfalse|false}"; //$NON-NLS-1$ //$NON-NLS-2$
1084 
1085         final NonReservedGraphNode actualnode = new NonReservedGraphNode(
1086                 nodeIn, graph);
1087         final NonReservedGraphNode actualnode1 = new NonReservedGraphNode(
1088                 nodeIn1, graph);
1089         actualnode.addChild(actualnode1);
1090 
1091         final String actual = actualnode.toString();
1092         final String expected = nodeOut;
1093 
1094         Assert.assertEquals("String of a node", expected, actual); //$NON-NLS-1$
1095     }
1096 
1097     /**
1098      * Test a node with parents.
1099      *
1100      * @throws AbstractZemucanException
1101      *             Never.
1102      */
1103     @Test
1104     public void testToStringWithParents() throws AbstractZemucanException {
1105         final Graph graph = new Graph("test", false);
1106 
1107         final String nodeIn = GraphNodeTest.TABLENAME;
1108         final String nodeIn1 = GraphNodeTest.TABLENAME;
1109         final String nodeOut = GraphNodeTest.TABLENAME + "::" + '{'
1110                 + GraphNodeTest.TABLENAME
1111                 + "\n1\t<" + GraphNodeTest.TABLENAME + ">\n0\nfalse|false}"; //$NON-NLS-1$ //$NON-NLS-2$
1112 
1113         final NonReservedGraphNode actualnode = new NonReservedGraphNode(
1114                 nodeIn, graph);
1115         final NonReservedGraphNode actualnode1 = new NonReservedGraphNode(
1116                 nodeIn1, graph);
1117         actualnode.addParent(actualnode1);
1118 
1119         final String actual = actualnode.toString();
1120         final String expected = nodeOut;
1121 
1122         Assert.assertEquals("String of a node", expected, actual); //$NON-NLS-1$
1123     }
1124 
1125     /**
1126      * Tests the transitivity of the equals.
1127      *
1128      * @throws AbstractZemucanException
1129      *             Never.
1130      */
1131     @Test
1132     public void testTransitivity() throws AbstractZemucanException {
1133         final Graph graph = new Graph("test", false);
1134 
1135         final String node = "test"; //$NON-NLS-1$
1136 
1137         final GraphNode node1 = new GraphNode(node, graph);
1138         final GraphNode node2 = new GraphNode(node, graph);
1139         final GraphNode node3 = new GraphNode(node, graph);
1140 
1141         final boolean val1 = node1.equals(node2) == node2.equals(node3);
1142         final boolean val2 = node1.equals(node3);
1143 
1144         final boolean val = val1 == val2;
1145 
1146         Assert.assertTrue("Transitivity", val); //$NON-NLS-1$
1147     }
1148 }