Skip to content

Commit

Permalink
Merge branch 'feature/workflow-file-tests' into mapapps
Browse files Browse the repository at this point in the history
Conflicts:
	de.wwu.md2.framework.tests/src/de/wwu/md2/framework/tests/utils/ModelProvider.java
  • Loading branch information
maltemoeser committed Dec 19, 2014
2 parents 818033f + cf2ce90 commit fce05e8
Show file tree
Hide file tree
Showing 12 changed files with 172 additions and 39 deletions.
2 changes: 1 addition & 1 deletion de.wwu.md2.framework.tests/.classpath
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<classpathentry kind="src" path="src"/>
<classpathentry kind="src" path="src-gen"/>
<classpathentry kind="src" path="models"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="output" path="bin"/>
</classpath>
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package TestProject.controllers

remoteConnection testConnection {
uri "test"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package TestProject.workflows

remoteConnection testConnection {
uri "test"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package TestProject.workflows

entity Test {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package TestProject.models

FlowLayoutPane MediaCapturingView2 (vertical) {

}
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"
}
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)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,27 @@ public class ModelProvider {
public static String VALIDATOR_MODEL_M = "dsl/model/validator/Model.md2";


//***Project***//

public static String PROJECT_VALIDATOR_MEC_CIW = "dsl/project/validator/modelElementPackageCongruence/controllerInWorkflow.md2";
public static String PROJECT_VALIDATOR_MEC_MIW = "dsl/project/validator/modelElementPackageCongruence/modelInWorkflow.md2";
public static String PROJECT_VALIDATOR_MEC_VIM = "dsl/project/validator/modelElementPackageCongruence/viewInModel.md2";
public static String PROJECT_VALIDATOR_MEC_WIM = "dsl/project/validator/modelElementPackageCongruence/workflowInModel.md2";
public static String PROJECT_VALIDATOR_MEC_CIC = "dsl/project/validator/modelElementPackageCongruence/controllerInController.md2";

//***Workflow***//

public static String WORKFLOW_FUNCTION_W = "dsl/workflow/functionTest/workflow.md2";
public static String WORKFLOW_FUNCTION_C = "dsl/workflow/functionTest/controller.md2";
public static String WORKFLOW_FUNCTION_V = "dsl/workflow/functionTest/view.md2";
public static String WORKFLOW_FUNCTION_M = "dsl/workflow/functionTest/model.md2";

public static String WORKFLOW_VALIDATOR_W = "dsl/workflow/validator/workflow.md2";
public static String WORKFLOW_VALIDATOR_C = "dsl/workflow/validator/controller.md2";
public static String WORKFLOW_VALIDATOR_V = "dsl/workflow/validator/view.md2";
public static String WORKFLOW_VALIDATOR_M = "dsl/workflow/validator/model.md2";


//***Controller***//

public static final String BASIC_CONTROLLER_M = "dsl/controller/Model.md2";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
import de.wwu.md2.framework.mD2.ViewGUIElementReference;
import de.wwu.md2.framework.mD2.WidthParam;
import de.wwu.md2.framework.mD2.ProcessChain;
import de.wwu.md2.framework.mD2.Workflow;
import de.wwu.md2.framework.util.MD2Util;

public class LegacyValidator extends AbstractMD2JavaValidator {
Expand All @@ -76,43 +77,6 @@ public void register(EValidatorRegistrar registrar) {
// nothing to do
}

/////////////////////////////////////////////////////////
/// General
/////////////////////////////////////////////////////////

/**
* Enforce that the declared package name complies with the actual package location
*
* @param model
*/
@Check
public void checkPackageNameCompliesWithLocation(MD2Model model) {
String 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());
}
}

/**
* Ensure that all elements belonging to a certain layer are stored in the appropriate
* package. If e.g. a view is stored in the package models throw an error.
*
* @param model
*/
@Check
public void checkModelElemenetCompliesWithPackage(MD2Model model) {

// split package name
List<String> lst = Arrays.asList(model.getPackage().getPkgName().split("\\."));

if (model.getModelLayer() instanceof Model && !lst.contains("models")) {
error("You tried to put a model element in a non-model package", MD2Package.eINSTANCE.getMD2Model_ModelLayer());
} else if (model.getModelLayer() instanceof View && !lst.contains("views")) {
error("You tried to put a view element in a non-view package", MD2Package.eINSTANCE.getMD2Model_ModelLayer());
} else if (model.getModelLayer() instanceof Controller && !lst.contains("controllers")) {
error("You tried to put a controller element in a non-controller package", MD2Package.eINSTANCE.getMD2Model_ModelLayer());
}
}


/////////////////////////////////////////////////////////
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/
@ComposedChecks(validators= {
LegacyValidator.class,
ProjectValidator.class,
ControllerValidator.class,
ModelValidator.class,
ViewValidator.class
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import org.eclipse.xtext.validation.Check
import org.eclipse.xtext.validation.EValidatorRegistrar

/**
* Valaidators for all model elements of MD2.
* Validators for all model elements of MD2.
*/
class ModelValidator extends AbstractMD2JavaValidator {

Expand Down
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);
}
}

}

0 comments on commit fce05e8

Please sign in to comment.