1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
|
18 | |
|
19 | |
|
20 | |
|
21 | |
|
22 | |
package net.sourceforge.combean.test.graph.util; |
23 | |
|
24 | |
import junit.framework.TestCase; |
25 | |
import net.sourceforge.combean.adapters.drasys.graph.DRAGraphWithEditIAsGraph; |
26 | |
import net.sourceforge.combean.graph.alg.AbstractGraphAlg; |
27 | |
import net.sourceforge.combean.graph.decorators.TransposedGraph; |
28 | |
import net.sourceforge.combean.graph.except.UnsupportedGraphProperty; |
29 | |
import net.sourceforge.combean.interfaces.graph.Graph; |
30 | |
import net.sourceforge.combean.interfaces.graph.prop.ConstructableGraphProp; |
31 | |
import net.sourceforge.combean.interfaces.graph.prop.DirectedEdgeNeighborhoodGraphProp; |
32 | |
import net.sourceforge.combean.interfaces.graph.prop.GlobalNodesGraphProp; |
33 | |
import net.sourceforge.combean.interfaces.graph.prop.NeighborhoodGraphProp; |
34 | |
import net.sourceforge.combean.test.helpers.stubs.GraphWithoutProperties; |
35 | |
import net.sourceforge.combean.util.except.UnsupportedMethodException; |
36 | |
|
37 | |
|
38 | |
|
39 | |
|
40 | |
|
41 | |
public class TestGraphPropertyInitializer extends TestCase { |
42 | |
|
43 | 15 | private GraphWithoutProperties noPropGraph = null; |
44 | 15 | private DRAGraphWithEditIAsGraph draGraph = null; |
45 | 15 | private DirectedEdgeNeighborhoodGraphProp transposedGraph = null; |
46 | 15 | private DirectedEdgeNeighborhoodGraphProp doubleTransposedGraph = null; |
47 | |
|
48 | 15 | private AlgNeedingNothing algNeedingNothing = null; |
49 | 15 | private AlgNeedingNeighborhoodAndGlobalNodes algNeedingSomething = null; |
50 | 15 | private AlgNeedingAlsoConstruction algNeedingAlsoConstr = null; |
51 | |
|
52 | 15 | protected class AlgNeedingNothing extends AbstractGraphAlg { |
53 | |
|
54 | |
|
55 | |
|
56 | |
|
57 | |
public void run() { |
58 | 0 | throw new UnsupportedMethodException(); |
59 | |
} |
60 | |
} |
61 | |
|
62 | 30 | protected class AlgNeedingNeighborhoodAndGlobalNodes extends AbstractGraphAlg { |
63 | |
|
64 | 30 | private NeighborhoodGraphProp neigh = null; |
65 | 30 | private GlobalNodesGraphProp globNodes = null; |
66 | |
|
67 | |
|
68 | |
|
69 | |
|
70 | |
public void run() { |
71 | 0 | throw new UnsupportedMethodException(); |
72 | |
} |
73 | |
|
74 | |
public void checkIfGraphIsSet(Graph g) { |
75 | 3 | assertEquals(g, this.neigh); |
76 | 3 | assertEquals(g, this.globNodes); |
77 | 3 | assertEquals(g, getGraph()); |
78 | 3 | } |
79 | |
|
80 | |
public void checkIfNestedGraphIsSet(Graph g, Graph innerG) { |
81 | 6 | assertEquals(g, this.neigh); |
82 | 6 | assertEquals(innerG, this.globNodes); |
83 | 6 | assertEquals(g, getGraph()); |
84 | 6 | } |
85 | |
} |
86 | |
|
87 | 30 | protected class AlgNeedingAlsoConstruction |
88 | |
extends AlgNeedingNeighborhoodAndGlobalNodes { |
89 | 15 | private ConstructableGraphProp constructableG = null; |
90 | |
|
91 | 0 | boolean foo() { return this.constructableG == null; }; |
92 | |
} |
93 | |
|
94 | |
public static void main(String[] args) { |
95 | 0 | junit.textui.TestRunner.run(TestGraphPropertyInitializer.class); |
96 | 0 | } |
97 | |
|
98 | |
|
99 | |
|
100 | |
|
101 | |
protected void setUp() throws Exception { |
102 | 15 | super.setUp(); |
103 | |
|
104 | 15 | this.noPropGraph = new GraphWithoutProperties(); |
105 | 15 | this.draGraph = new DRAGraphWithEditIAsGraph(); |
106 | 15 | this.transposedGraph = new TransposedGraph(this.draGraph); |
107 | 15 | this.doubleTransposedGraph = new TransposedGraph(this.transposedGraph); |
108 | |
|
109 | 15 | this.algNeedingNothing = new AlgNeedingNothing(); |
110 | 15 | this.algNeedingSomething = new AlgNeedingNeighborhoodAndGlobalNodes(); |
111 | 15 | this.algNeedingAlsoConstr = new AlgNeedingAlsoConstruction(); |
112 | 15 | } |
113 | |
|
114 | |
|
115 | |
|
116 | |
|
117 | |
protected void tearDown() throws Exception { |
118 | 15 | super.tearDown(); |
119 | 15 | } |
120 | |
|
121 | |
|
122 | |
|
123 | |
|
124 | |
|
125 | |
public TestGraphPropertyInitializer(String name) { |
126 | 15 | super(name); |
127 | 15 | } |
128 | |
|
129 | |
public final void testSetGraphOnAlgNeedingNothing() { |
130 | 3 | this.algNeedingNothing.setGraph(this.noPropGraph); |
131 | 3 | assertEquals(this.noPropGraph, this.algNeedingNothing.getGraph()); |
132 | |
|
133 | 3 | this.algNeedingNothing.setGraph(this.draGraph); |
134 | 3 | assertEquals(this.draGraph, this.algNeedingNothing.getGraph()); |
135 | 3 | } |
136 | |
|
137 | |
public final void testSetGraphOnAlgNeedingSomething() { |
138 | |
try { |
139 | 3 | this.algNeedingSomething.setGraph(this.noPropGraph); |
140 | 0 | fail("exception should be thrown because graph does not have " + |
141 | |
"the required properties"); |
142 | |
} |
143 | 3 | catch (UnsupportedGraphProperty e) { |
144 | |
|
145 | 0 | } |
146 | |
|
147 | 3 | this.algNeedingSomething.setGraph(this.draGraph); |
148 | 3 | this.algNeedingSomething.checkIfGraphIsSet(this.draGraph); |
149 | 3 | } |
150 | |
|
151 | |
public final void testSetGraphOnNestedGraph() { |
152 | 3 | this.algNeedingSomething.setGraph(this.transposedGraph); |
153 | 3 | this.algNeedingSomething.checkIfNestedGraphIsSet(this.transposedGraph, |
154 | |
this.draGraph); |
155 | 3 | } |
156 | |
|
157 | |
public final void testSetGraphOnDoubleNestedGraph() { |
158 | 3 | this.algNeedingSomething.setGraph(this.doubleTransposedGraph); |
159 | 3 | this.algNeedingSomething.checkIfNestedGraphIsSet( |
160 | |
this.doubleTransposedGraph, this.draGraph); |
161 | 3 | } |
162 | |
|
163 | |
public final void testSetGraphWithPropertyNotVisibleThroughNestedGraph() { |
164 | |
try { |
165 | 3 | this.algNeedingAlsoConstr.setGraph(this.transposedGraph); |
166 | 0 | fail("construction property must not be visible through transposed graph"); |
167 | |
} |
168 | 3 | catch (UnsupportedGraphProperty e) { |
169 | |
|
170 | 0 | } |
171 | 3 | } |
172 | |
} |