Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJuergen Haug2017-08-04 14:20:50 -0400
committerJuergen Haug2017-08-04 14:20:50 -0400
commit43150a212b7307880b959c3e72554609f7d37bd1 (patch)
treee4846f512673bdf262e2e700377fb33726eb9810
parent92528738ac06f5e1e6d48ef3cf1658e5c8b616f1 (diff)
downloadorg.eclipse.etrice-43150a212b7307880b959c3e72554609f7d37bd1.tar.gz
org.eclipse.etrice-43150a212b7307880b959c3e72554609f7d37bd1.tar.xz
org.eclipse.etrice-43150a212b7307880b959c3e72554609f7d37bd1.zip
[core.genmodel.fsm] corrected test
-rw-r--r--tests/org.eclipse.etrice.ui.behavior.tests/src/org/eclipse/etrice/ui/behavior/commands/TestFSMGenModel.xtend30
-rw-r--r--tests/org.eclipse.etrice.ui.behavior.tests/xtend-gen/org/eclipse/etrice/ui/behavior/commands/TestFSMGenModel.java83
2 files changed, 63 insertions, 50 deletions
diff --git a/tests/org.eclipse.etrice.ui.behavior.tests/src/org/eclipse/etrice/ui/behavior/commands/TestFSMGenModel.xtend b/tests/org.eclipse.etrice.ui.behavior.tests/src/org/eclipse/etrice/ui/behavior/commands/TestFSMGenModel.xtend
index 40de02af1..14a9d10ee 100644
--- a/tests/org.eclipse.etrice.ui.behavior.tests/src/org/eclipse/etrice/ui/behavior/commands/TestFSMGenModel.xtend
+++ b/tests/org.eclipse.etrice.ui.behavior.tests/src/org/eclipse/etrice/ui/behavior/commands/TestFSMGenModel.xtend
@@ -15,6 +15,7 @@ package org.eclipse.etrice.ui.behavior.commands
import com.google.common.collect.Sets
import java.util.List
import org.eclipse.emf.common.util.URI
+import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl
import org.eclipse.emf.ecore.util.EcoreUtil
import org.eclipse.etrice.core.RoomStandaloneSetup
import org.eclipse.etrice.core.TestBase
@@ -25,6 +26,8 @@ import org.eclipse.etrice.core.genmodel.fsm.IDiagnostician
import org.eclipse.etrice.core.genmodel.fsm.NullDiagnostician
import org.eclipse.etrice.core.genmodel.fsm.NullLogger
import org.eclipse.etrice.core.genmodel.fsm.fsmgen.GraphContainer
+import org.eclipse.etrice.core.genmodel.fsm.fsmgen.Link
+import org.eclipse.etrice.core.genmodel.fsm.fsmgen.Node
import org.eclipse.etrice.core.room.ActorClass
import org.eclipse.etrice.core.room.RoomModel
import org.eclipse.etrice.ui.behavior.BehaviorTestActivator
@@ -36,16 +39,15 @@ import static org.junit.Assert.assertNotNull
import static org.junit.Assert.assertTrue
class TestFSMGenModel extends TestBase {
-
+
+ val injector = new RoomStandaloneSetup().createInjectorAndDoEMFRegistration()
protected IDiagnostician diagnostician = new NullDiagnostician
- protected extension ExtendedFsmGenBuilder builder
+ protected extension ExtendedFsmGenBuilder builder = new ExtendedFsmGenBuilder(injector, diagnostician)
protected def createResourceSetWithGc(String roomFile, String actorName) {
prepare(BehaviorTestActivator.^default.getBundle())
val res = getResource(roomFile)
- val actor = (res.contents.get(0) as RoomModel).actorClasses.findFirst[name.equals(actorName)]
- val injector = new RoomStandaloneSetup().createInjectorAndDoEMFRegistration()
- builder = new ExtendedFsmGenBuilder(injector, diagnostician)
+ val actor = (res.contents.get(0) as RoomModel).actorClasses.findFirst[name.equals(actorName)]
val gc = builder.createTransformedModel(actor) => [gc |
assertNotNull("graph context was created", gc)
@@ -53,6 +55,7 @@ class TestFSMGenModel extends TestBase {
val logger = new NullLogger
FsmGenChecker.check(gc, logger)
assertFalse("logger has no errors", logger.hasErrors)
+// save(gc, actor.name)
]
res.resourceSet.createResource(URI.createURI('dummy://' + actorName + '.fsmgen')) => [
@@ -62,6 +65,14 @@ class TestFSMGenModel extends TestBase {
return res.resourceSet
}
+ protected def save(GraphContainer gc, String fileName) {
+ val rs = new ResourceSetImpl
+ val uri = URI.createFileURI("./output/" + fileName + ".fsmgen")
+ val res = rs.createResource(uri)
+ res.contents.add(gc)
+ res.save(newHashMap)
+ }
+
@Test
def void testBaseClass() {
val rs = createResourceSetWithGc("InheritedStateMachine.room", "Base")
@@ -91,14 +102,15 @@ class TestFSMGenModel extends TestBase {
def void checkAgainstRoom(GraphContainer gc, List<ActorClass> actorClasses) {
// genmodel should refer to latest fsm (check in-memory ref)
- val genModelRefs = (gc.graph.nodes.map[stateGraphNode] + gc.graph.links.map[transition]).toSet
+ val genModelRefs = (EcoreUtil.getAllContents(gc, true).filter(Node).map[stateGraphNode] + EcoreUtil.getAllContents(gc, true).filter(Link).map[transition]).toSet
EcoreUtil.getAllContents(actorClasses.last, false).filter(StateGraphItem).forEach[
- assertTrue('missing ' + toString, genModelRefs.contains(it))
+ assertTrue('missing ' + EcoreUtil.getURI(it), genModelRefs.contains(it))
]
- // all fsm items should be in genmodel (check name)
+ // all fsm items should be in genmodel (check name)
+ // node, there are duplicate names in subgraphs => not complete
val stateGraphItemsNames = EcoreUtil.getAllContents(actorClasses, true).filter(StateGraphItem).map[name].toIterable.toSortedSet
- val namesFromGenModel = (gc.graph.nodes.map[stateGraphNode.name] + gc.graph.links.map[transition.name]).toSortedSet
+ val namesFromGenModel = genModelRefs.map[name].toSortedSet
assertEquals(stateGraphItemsNames, namesFromGenModel)
}
diff --git a/tests/org.eclipse.etrice.ui.behavior.tests/xtend-gen/org/eclipse/etrice/ui/behavior/commands/TestFSMGenModel.java b/tests/org.eclipse.etrice.ui.behavior.tests/xtend-gen/org/eclipse/etrice/ui/behavior/commands/TestFSMGenModel.java
index e949d938e..79dbbaecc 100644
--- a/tests/org.eclipse.etrice.ui.behavior.tests/xtend-gen/org/eclipse/etrice/ui/behavior/commands/TestFSMGenModel.java
+++ b/tests/org.eclipse.etrice.ui.behavior.tests/xtend-gen/org/eclipse/etrice/ui/behavior/commands/TestFSMGenModel.java
@@ -15,6 +15,7 @@ import com.google.common.collect.Iterables;
import com.google.common.collect.Iterators;
import com.google.common.collect.Sets;
import com.google.inject.Injector;
+import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Set;
@@ -25,6 +26,7 @@ import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.ecore.resource.ResourceSet;
+import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
import org.eclipse.emf.ecore.util.EcoreUtil;
import org.eclipse.etrice.core.RoomStandaloneSetup;
import org.eclipse.etrice.core.TestBase;
@@ -36,13 +38,14 @@ import org.eclipse.etrice.core.genmodel.fsm.FsmGenChecker;
import org.eclipse.etrice.core.genmodel.fsm.IDiagnostician;
import org.eclipse.etrice.core.genmodel.fsm.NullDiagnostician;
import org.eclipse.etrice.core.genmodel.fsm.NullLogger;
-import org.eclipse.etrice.core.genmodel.fsm.fsmgen.Graph;
import org.eclipse.etrice.core.genmodel.fsm.fsmgen.GraphContainer;
import org.eclipse.etrice.core.genmodel.fsm.fsmgen.Link;
import org.eclipse.etrice.core.genmodel.fsm.fsmgen.Node;
import org.eclipse.etrice.core.room.ActorClass;
import org.eclipse.etrice.core.room.RoomModel;
import org.eclipse.etrice.ui.behavior.BehaviorTestActivator;
+import org.eclipse.xtext.xbase.lib.CollectionLiterals;
+import org.eclipse.xtext.xbase.lib.Exceptions;
import org.eclipse.xtext.xbase.lib.Extension;
import org.eclipse.xtext.xbase.lib.Functions.Function1;
import org.eclipse.xtext.xbase.lib.IterableExtensions;
@@ -56,10 +59,12 @@ import org.osgi.framework.Bundle;
@SuppressWarnings("all")
public class TestFSMGenModel extends TestBase {
+ private final Injector injector = new RoomStandaloneSetup().createInjectorAndDoEMFRegistration();
+
protected IDiagnostician diagnostician = new NullDiagnostician();
@Extension
- protected ExtendedFsmGenBuilder builder;
+ protected ExtendedFsmGenBuilder builder = new ExtendedFsmGenBuilder(this.injector, this.diagnostician);
protected ResourceSet createResourceSetWithGc(final String roomFile, final String actorName) {
BehaviorTestActivator _default = BehaviorTestActivator.getDefault();
@@ -77,10 +82,6 @@ public class TestFSMGenModel extends TestBase {
}
};
final ActorClass actor = IterableExtensions.<ActorClass>findFirst(_actorClasses, _function);
- RoomStandaloneSetup _roomStandaloneSetup = new RoomStandaloneSetup();
- final Injector injector = _roomStandaloneSetup.createInjectorAndDoEMFRegistration();
- ExtendedFsmGenBuilder _extendedFsmGenBuilder = new ExtendedFsmGenBuilder(injector, this.diagnostician);
- this.builder = _extendedFsmGenBuilder;
GraphContainer _createTransformedModel = this.builder.createTransformedModel(actor);
final Procedure1<GraphContainer> _function_1 = new Procedure1<GraphContainer>() {
@Override
@@ -107,6 +108,20 @@ public class TestFSMGenModel extends TestBase {
return res.getResourceSet();
}
+ protected void save(final GraphContainer gc, final String fileName) {
+ try {
+ final ResourceSetImpl rs = new ResourceSetImpl();
+ final URI uri = URI.createFileURI((("./output/" + fileName) + ".fsmgen"));
+ final Resource res = rs.createResource(uri);
+ EList<EObject> _contents = res.getContents();
+ _contents.add(gc);
+ HashMap<Object, Object> _newHashMap = CollectionLiterals.<Object, Object>newHashMap();
+ res.save(_newHashMap);
+ } catch (Throwable _e) {
+ throw Exceptions.sneakyThrow(_e);
+ }
+ }
+
@Test
public void testBaseClass() {
final ResourceSet rs = this.createResourceSetWithGc("InheritedStateMachine.room", "Base");
@@ -190,72 +205,58 @@ public class TestFSMGenModel extends TestBase {
}
public void checkAgainstRoom(final GraphContainer gc, final List<ActorClass> actorClasses) {
- Graph _graph = gc.getGraph();
- EList<Node> _nodes = _graph.getNodes();
+ TreeIterator<Object> _allContents = EcoreUtil.<Object>getAllContents(gc, true);
+ Iterator<Node> _filter = Iterators.<Node>filter(_allContents, Node.class);
final Function1<Node, StateGraphNode> _function = new Function1<Node, StateGraphNode>() {
@Override
public StateGraphNode apply(final Node it) {
return it.getStateGraphNode();
}
};
- List<StateGraphNode> _map = ListExtensions.<Node, StateGraphNode>map(_nodes, _function);
- Graph _graph_1 = gc.getGraph();
- EList<Link> _links = _graph_1.getLinks();
+ Iterator<StateGraphNode> _map = IteratorExtensions.<Node, StateGraphNode>map(_filter, _function);
+ TreeIterator<Object> _allContents_1 = EcoreUtil.<Object>getAllContents(gc, true);
+ Iterator<Link> _filter_1 = Iterators.<Link>filter(_allContents_1, Link.class);
final Function1<Link, TransitionBase> _function_1 = new Function1<Link, TransitionBase>() {
@Override
public TransitionBase apply(final Link it) {
return it.getTransition();
}
};
- List<TransitionBase> _map_1 = ListExtensions.<Link, TransitionBase>map(_links, _function_1);
- Iterable<StateGraphItem> _plus = Iterables.<StateGraphItem>concat(_map, _map_1);
- final Set<StateGraphItem> genModelRefs = IterableExtensions.<StateGraphItem>toSet(_plus);
+ Iterator<TransitionBase> _map_1 = IteratorExtensions.<Link, TransitionBase>map(_filter_1, _function_1);
+ Iterator<StateGraphItem> _plus = Iterators.<StateGraphItem>concat(_map, _map_1);
+ final Set<StateGraphItem> genModelRefs = IteratorExtensions.<StateGraphItem>toSet(_plus);
ActorClass _last = IterableExtensions.<ActorClass>last(actorClasses);
- TreeIterator<Object> _allContents = EcoreUtil.<Object>getAllContents(_last, false);
- Iterator<StateGraphItem> _filter = Iterators.<StateGraphItem>filter(_allContents, StateGraphItem.class);
+ TreeIterator<Object> _allContents_2 = EcoreUtil.<Object>getAllContents(_last, false);
+ Iterator<StateGraphItem> _filter_2 = Iterators.<StateGraphItem>filter(_allContents_2, StateGraphItem.class);
final Procedure1<StateGraphItem> _function_2 = new Procedure1<StateGraphItem>() {
@Override
public void apply(final StateGraphItem it) {
- String _string = it.toString();
- String _plus = ("missing " + _string);
+ URI _uRI = EcoreUtil.getURI(it);
+ String _plus = ("missing " + _uRI);
boolean _contains = genModelRefs.contains(it);
Assert.assertTrue(_plus, _contains);
}
};
- IteratorExtensions.<StateGraphItem>forEach(_filter, _function_2);
- TreeIterator<Object> _allContents_1 = EcoreUtil.<Object>getAllContents(actorClasses, true);
- Iterator<StateGraphItem> _filter_1 = Iterators.<StateGraphItem>filter(_allContents_1, StateGraphItem.class);
+ IteratorExtensions.<StateGraphItem>forEach(_filter_2, _function_2);
+ TreeIterator<Object> _allContents_3 = EcoreUtil.<Object>getAllContents(actorClasses, true);
+ Iterator<StateGraphItem> _filter_3 = Iterators.<StateGraphItem>filter(_allContents_3, StateGraphItem.class);
final Function1<StateGraphItem, String> _function_3 = new Function1<StateGraphItem, String>() {
@Override
public String apply(final StateGraphItem it) {
return it.getName();
}
};
- Iterator<String> _map_2 = IteratorExtensions.<StateGraphItem, String>map(_filter_1, _function_3);
+ Iterator<String> _map_2 = IteratorExtensions.<StateGraphItem, String>map(_filter_3, _function_3);
Iterable<String> _iterable = IteratorExtensions.<String>toIterable(_map_2);
final TreeSet<String> stateGraphItemsNames = this.<String>toSortedSet(_iterable);
- Graph _graph_2 = gc.getGraph();
- EList<Node> _nodes_1 = _graph_2.getNodes();
- final Function1<Node, String> _function_4 = new Function1<Node, String>() {
- @Override
- public String apply(final Node it) {
- StateGraphNode _stateGraphNode = it.getStateGraphNode();
- return _stateGraphNode.getName();
- }
- };
- List<String> _map_3 = ListExtensions.<Node, String>map(_nodes_1, _function_4);
- Graph _graph_3 = gc.getGraph();
- EList<Link> _links_1 = _graph_3.getLinks();
- final Function1<Link, String> _function_5 = new Function1<Link, String>() {
+ final Function1<StateGraphItem, String> _function_4 = new Function1<StateGraphItem, String>() {
@Override
- public String apply(final Link it) {
- TransitionBase _transition = it.getTransition();
- return _transition.getName();
+ public String apply(final StateGraphItem it) {
+ return it.getName();
}
};
- List<String> _map_4 = ListExtensions.<Link, String>map(_links_1, _function_5);
- Iterable<String> _plus_1 = Iterables.<String>concat(_map_3, _map_4);
- final TreeSet<String> namesFromGenModel = this.<String>toSortedSet(_plus_1);
+ Iterable<String> _map_3 = IterableExtensions.<StateGraphItem, String>map(genModelRefs, _function_4);
+ final TreeSet<String> namesFromGenModel = this.<String>toSortedSet(_map_3);
Assert.assertEquals(stateGraphItemsNames, namesFromGenModel);
}

Back to the top