|
@@ -17,19 +17,11 @@ import junit.framework.Assert;
|
|
|
import org.eclipse.xtext.EcoreUtil2;
|
|
import org.eclipse.xtext.EcoreUtil2;
|
|
|
import org.eclipse.xtext.junit4.InjectWith;
|
|
import org.eclipse.xtext.junit4.InjectWith;
|
|
|
import org.eclipse.xtext.junit4.XtextRunner;
|
|
import org.eclipse.xtext.junit4.XtextRunner;
|
|
|
-import org.eclipse.xtext.parser.IParser;
|
|
|
|
|
import org.junit.runner.RunWith;
|
|
import org.junit.runner.RunWith;
|
|
|
-import org.yakindu.sct.model.sgraph.SpecificationElement;
|
|
|
|
|
import org.yakindu.sct.model.sgraph.State;
|
|
import org.yakindu.sct.model.sgraph.State;
|
|
|
import org.yakindu.sct.model.sgraph.Statechart;
|
|
import org.yakindu.sct.model.sgraph.Statechart;
|
|
|
import org.yakindu.sct.model.sgraph.resource.AbstractSCTResource;
|
|
import org.yakindu.sct.model.sgraph.resource.AbstractSCTResource;
|
|
|
-import org.yakindu.sct.model.stext.resource.impl.StextResource;
|
|
|
|
|
-import org.yakindu.sct.refactoring.refactor.util.SctEqualityHelper;
|
|
|
|
|
-import org.yakindu.sct.refactoring.refactor.util.TestHelper;
|
|
|
|
|
-import org.yakindu.sct.refactoring.refactor.util.TestInjectorProvider;
|
|
|
|
|
-import org.yakindu.sct.test.models.RefactoringTestModels;
|
|
|
|
|
-
|
|
|
|
|
-import com.google.inject.Inject;
|
|
|
|
|
|
|
+import org.yakindu.sct.test.models.TestModelInjectorProvider;
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* Base test class for state based refactorings.
|
|
* Base test class for state based refactorings.
|
|
@@ -38,30 +30,15 @@ import com.google.inject.Inject;
|
|
|
*
|
|
*
|
|
|
*/
|
|
*/
|
|
|
@RunWith(XtextRunner.class)
|
|
@RunWith(XtextRunner.class)
|
|
|
-@InjectWith(TestInjectorProvider.class)
|
|
|
|
|
-public abstract class StateBasedRefactoringTest {
|
|
|
|
|
-
|
|
|
|
|
- @Inject
|
|
|
|
|
- protected IParser parser;
|
|
|
|
|
-
|
|
|
|
|
- @Inject
|
|
|
|
|
- protected RefactoringTestModels models;
|
|
|
|
|
-
|
|
|
|
|
- protected TestHelper helper = new TestHelper();
|
|
|
|
|
-
|
|
|
|
|
- protected void compareStatecharts(Statechart initial, Statechart expected) {
|
|
|
|
|
- SctEqualityHelper equalityHelper = new SctEqualityHelper();
|
|
|
|
|
- if (!equalityHelper.equals(initial, expected)) {
|
|
|
|
|
- Assert.fail("Equality check on statecharts failed!");
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
|
|
+@InjectWith(TestModelInjectorProvider.class)
|
|
|
|
|
+public abstract class StateBasedRefactoringTest extends RefactoringTest {
|
|
|
|
|
|
|
|
protected void testRefactoringOnState(String pathToInitialSct,
|
|
protected void testRefactoringOnState(String pathToInitialSct,
|
|
|
String pathToExpectedSct, String stateName) {
|
|
String pathToExpectedSct, String stateName) {
|
|
|
Statechart initial = models
|
|
Statechart initial = models
|
|
|
.loadStatechartFromResource(pathToInitialSct);
|
|
.loadStatechartFromResource(pathToInitialSct);
|
|
|
|
|
|
|
|
- State state = helper.getStateByName(initial, stateName);
|
|
|
|
|
|
|
+ State state = getStateByName(initial, stateName);
|
|
|
|
|
|
|
|
AbstractRefactoring<?> refactoring = getRefactoring(state);
|
|
AbstractRefactoring<?> refactoring = getRefactoring(state);
|
|
|
((AbstractSCTResource) initial.eResource()).setSerializerEnabled(true);
|
|
((AbstractSCTResource) initial.eResource()).setSerializerEnabled(true);
|
|
@@ -82,7 +59,7 @@ public abstract class StateBasedRefactoringTest {
|
|
|
Statechart initial = models
|
|
Statechart initial = models
|
|
|
.loadStatechartFromResource(pathToInitialSct);
|
|
.loadStatechartFromResource(pathToInitialSct);
|
|
|
|
|
|
|
|
- State state = helper.getStateByName(initial, stateName);
|
|
|
|
|
|
|
+ State state = getStateByName(initial, stateName);
|
|
|
|
|
|
|
|
AbstractRefactoring<?> refactoring = getRefactoring(state);
|
|
AbstractRefactoring<?> refactoring = getRefactoring(state);
|
|
|
if (expectedResult) {
|
|
if (expectedResult) {
|
|
@@ -93,12 +70,15 @@ public abstract class StateBasedRefactoringTest {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- private void parseAllSpecifications(Statechart sct) {
|
|
|
|
|
- List<SpecificationElement> allSpecElements = EcoreUtil2.getAllContentsOfType(sct, SpecificationElement.class);
|
|
|
|
|
- for (SpecificationElement specificationElement : allSpecElements) {
|
|
|
|
|
- ((StextResource)sct.eResource()).parseSpecificationElement(specificationElement);
|
|
|
|
|
|
|
+ protected abstract AbstractRefactoring<?> getRefactoring(State state);
|
|
|
|
|
+
|
|
|
|
|
+ protected State getStateByName(Statechart statechart, String name) {
|
|
|
|
|
+ List<State> allStates = EcoreUtil2.getAllContentsOfType(statechart, State.class);
|
|
|
|
|
+ for (State state : allStates) {
|
|
|
|
|
+ if (state.getName().equals(name)) {
|
|
|
|
|
+ return state;
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
+ return null;
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
- protected abstract AbstractRefactoring<?> getRefactoring(State state);
|
|
|
|
|
}
|
|
}
|