-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'feature/workflow-file-tests' into mapapps
Conflicts: de.wwu.md2.framework.tests/src/de/wwu/md2/framework/tests/utils/ModelProvider.java
- Loading branch information
Showing
12 changed files
with
172 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 5 additions & 0 deletions
5
...work/tests/dsl/project/validator/modelElementPackageCongruence/controllerInController.md2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package TestProject.controllers | ||
|
||
remoteConnection testConnection { | ||
uri "test" | ||
} |
5 changes: 5 additions & 0 deletions
5
...mework/tests/dsl/project/validator/modelElementPackageCongruence/controllerInWorkflow.md2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package TestProject.workflows | ||
|
||
remoteConnection testConnection { | ||
uri "test" | ||
} |
5 changes: 5 additions & 0 deletions
5
...2/framework/tests/dsl/project/validator/modelElementPackageCongruence/modelInWorkflow.md2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package TestProject.workflows | ||
|
||
entity Test { | ||
|
||
} |
5 changes: 5 additions & 0 deletions
5
...u/md2/framework/tests/dsl/project/validator/modelElementPackageCongruence/viewInModel.md2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package TestProject.models | ||
|
||
FlowLayoutPane MediaCapturingView2 (vertical) { | ||
|
||
} |
13 changes: 13 additions & 0 deletions
13
...2/framework/tests/dsl/project/validator/modelElementPackageCongruence/workflowInModel.md2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package TestProject.models | ||
|
||
WorkflowElement LocationDetection | ||
fires LocationDetectionEvent { | ||
start LocationDetection | ||
} | ||
|
||
App CurrentStateProjectApp { | ||
WorkflowElements { | ||
LocationDetection (startable: "Start Controller 1") | ||
} | ||
appName "functionTestApp" | ||
} |
56 changes: 56 additions & 0 deletions
56
.../de/wwu/md2/framework/tests/dsl/project/validator/ModelElementPackageCongruenceTest.xtend
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package de.wwu.md2.framework.tests.dsl.project.validator | ||
|
||
import org.eclipse.xtext.junit4.InjectWith | ||
import de.wwu.md2.framework.MD2InjectorProvider | ||
import org.junit.runner.RunWith | ||
import org.eclipse.xtext.junit4.XtextRunner | ||
import javax.inject.Inject | ||
import org.eclipse.xtext.junit4.util.ParseHelper | ||
import de.wwu.md2.framework.mD2.MD2Model | ||
import org.junit.Before | ||
import static extension de.wwu.md2.framework.tests.utils.ModelProvider.* | ||
|
||
import org.junit.Test | ||
import org.eclipse.xtext.junit4.validation.ValidationTestHelper | ||
|
||
import de.wwu.md2.framework.mD2.MD2Package | ||
import de.wwu.md2.framework.validation.ProjectValidator | ||
|
||
@InjectWith(typeof(MD2InjectorProvider)) | ||
@RunWith(typeof(XtextRunner)) | ||
|
||
class ModelElementPackageCongruenceTest { | ||
@Inject extension ParseHelper<MD2Model> | ||
@Inject extension ValidationTestHelper | ||
|
||
MD2Model controllerModel; | ||
MD2Model modelModel; | ||
MD2Model viewModel; | ||
MD2Model workflowModel | ||
MD2Model testModel | ||
|
||
@Before | ||
def void setUp() { | ||
controllerModel = PROJECT_VALIDATOR_MEC_CIW.load.parse | ||
modelModel = PROJECT_VALIDATOR_MEC_MIW.load.parse | ||
viewModel = PROJECT_VALIDATOR_MEC_VIM.load.parse | ||
workflowModel = PROJECT_VALIDATOR_MEC_WIM.load.parse | ||
testModel = PROJECT_VALIDATOR_MEC_CIC.load.parse | ||
} | ||
|
||
/** | ||
* Test whether the correct error is thrown when model elements are declared in the wrong file. | ||
*/ | ||
@Test | ||
def checkModelElementCompliesWithPackageTest() { | ||
controllerModel.assertError(MD2Package::eINSTANCE.MD2Model, ProjectValidator::MODELELEMENT_PACKAGE) | ||
modelModel.assertError(MD2Package::eINSTANCE.MD2Model, ProjectValidator::MODELELEMENT_PACKAGE) | ||
viewModel.assertError(MD2Package::eINSTANCE.MD2Model, ProjectValidator::MODELELEMENT_PACKAGE) | ||
workflowModel.assertError(MD2Package::eINSTANCE.MD2Model, ProjectValidator::MODELELEMENT_PACKAGE) | ||
} | ||
|
||
@Test | ||
def checkNoErrorForCorrectPackage(){ | ||
testModel.assertNoError(ProjectValidator::MODELELEMENT_PACKAGE) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
68 changes: 68 additions & 0 deletions
68
de.wwu.md2.framework/src/de/wwu/md2/framework/validation/ProjectValidator.xtend
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
package de.wwu.md2.framework.validation | ||
|
||
import com.google.inject.Inject | ||
import org.eclipse.xtext.validation.Check | ||
import org.eclipse.xtext.validation.EValidatorRegistrar | ||
import java.util.Arrays | ||
import de.wwu.md2.framework.mD2.Model | ||
import de.wwu.md2.framework.mD2.View | ||
import de.wwu.md2.framework.mD2.Controller | ||
import de.wwu.md2.framework.mD2.Workflow | ||
import de.wwu.md2.framework.mD2.MD2Package | ||
import de.wwu.md2.framework.mD2.MD2Model | ||
import de.wwu.md2.framework.util.MD2Util | ||
|
||
/** | ||
* Validators for all high-level elements (model, view, workflow and controller). | ||
*/ | ||
class ProjectValidator extends AbstractMD2JavaValidator { | ||
|
||
@Inject | ||
override register(EValidatorRegistrar registrar) { | ||
// nothing to do | ||
} | ||
|
||
@Inject | ||
private MD2Util util; | ||
|
||
/** | ||
* Enforce that the declared package name complies with the actual package location | ||
* | ||
* @param model | ||
*/ | ||
@Check | ||
def checkPackageNameCompliesWithLocation(MD2Model model) { | ||
val pkgName = util.getPackageNameFromPath(model.eResource().getURI()); | ||
if(!model.getPackage().getPkgName().equals(pkgName)) { | ||
warning("The specified package does not match the actual location of the file", MD2Package.eINSTANCE.getMD2Model_Package()); | ||
} | ||
} | ||
|
||
|
||
public static final String MODELELEMENT_PACKAGE = "modelelement_package"; | ||
/** | ||
* Ensure that all elements belonging to a certain layer are stored in the appropriate | ||
* package. E.g., throw an error if a view is stored in the package models. | ||
* | ||
* @param model | ||
*/ | ||
@Check | ||
def checkModelElementCompliesWithPackage(MD2Model model) { | ||
|
||
// split package name | ||
var lst = model.getPackage().getPkgName().split("\\.") | ||
|
||
val modelLayer = model.getModelLayer() | ||
|
||
if (modelLayer instanceof Model && !lst.contains("models")) { | ||
error("You tried to put a model element in a non-model package", MD2Package.eINSTANCE.getMD2Model_ModelLayer(), -1, MODELELEMENT_PACKAGE); | ||
} else if (modelLayer instanceof View && !lst.contains("views")) { | ||
error("You tried to put a view element in a non-view package", MD2Package.eINSTANCE.getMD2Model_ModelLayer(), -1, MODELELEMENT_PACKAGE); | ||
} else if (modelLayer instanceof Controller && !lst.contains("controllers")) { | ||
error("You tried to put a controller element in a non-controller package", MD2Package.eINSTANCE.getMD2Model_ModelLayer(), -1, MODELELEMENT_PACKAGE); | ||
} else if (modelLayer instanceof Workflow && !lst.contains("workflows")) { | ||
error("You tried to put a workflow element in a non-workflow package", MD2Package.eINSTANCE.getMD2Model_ModelLayer(), -1, MODELELEMENT_PACKAGE); | ||
} | ||
} | ||
|
||
} |