4
4
import static org .junit .Assert .assertFalse ;
5
5
import static org .junit .Assert .assertTrue ;
6
6
7
+ import java .io .IOException ;
7
8
import java .util .Arrays ;
8
9
9
10
import org .eclipse .emf .ecore .EObject ;
10
11
import org .eclipse .emf .ecore .resource .Resource ;
12
+ import org .eclipse .emf .ecore .util .EcoreUtil ;
11
13
import org .eclipse .emf .henshin .interpreter .Engine ;
12
14
import org .eclipse .emf .henshin .interpreter .impl .EGraphImpl ;
13
15
import org .eclipse .emf .henshin .interpreter .impl .EngineImpl ;
17
19
import org .junit .Test ;
18
20
19
21
public class TopologyControlRuleTests {
20
- private static final String TOPOLOGY_INSTANCE_TWO_NODES = "../../../../instance/Topology.xmi" ;
22
+ private static final String PROJECT_ROOT_RELATIVE_PATH = "../../../.." ;
23
+
24
+ private static final String TOPOLOGY_INSTANCE_TWO_NODES = PROJECT_ROOT_RELATIVE_PATH + "/instance/Topology.xmi" ;
25
+ private static final String TOPOLOGY_INSTANCE_TEMP = PROJECT_ROOT_RELATIVE_PATH + "/output/Topology.xmi" ;
21
26
22
27
private HenshinResourceSet resourceSet ;
23
28
@@ -105,6 +110,8 @@ public void testCreateTriangleForbiddenByApplicationCondition1() {
105
110
assertTrue (setLinkState ("1->2" , LinkState .ACTIVE ));
106
111
assertTrue (addLink_Refined ("1->3" , 1 ));
107
112
113
+ saveCurrentTopology ();
114
+
108
115
assertFalse (addLink_Refined ("3->2" , 6 ));
109
116
}
110
117
@@ -176,4 +183,20 @@ private boolean setLinkState_Refined(final String linkId, final int newState) {
176
183
private EObject getTopology () {
177
184
return this .graph .getRoots ().get (0 );
178
185
}
186
+
187
+ @ SuppressWarnings ("unused" )
188
+ /**
189
+ * Utility function for saving the current state of the topology
190
+ */
191
+ private void saveCurrentTopology () {
192
+ final Resource topologyResource = this .resourceSet .getResource (TOPOLOGY_INSTANCE_TWO_NODES );
193
+ final Resource tempResource = this .resourceSet .createResource (TOPOLOGY_INSTANCE_TEMP );
194
+ final EObject copiedTopology = EcoreUtil .copy (topologyResource .getContents ().get (0 ));
195
+ tempResource .getContents ().add (copiedTopology );
196
+ try {
197
+ tempResource .save (null );
198
+ } catch (final IOException e ) {
199
+ e .printStackTrace ();
200
+ }
201
+ }
179
202
}
0 commit comments