From cf2ce90321e999d2da2586c9f7cc5b428c45c840 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Malte=20Mo=CC=88ser?= <mail@maltemoeser.de>
Date: Mon, 15 Dec 2014 15:58:50 +0100
Subject: [PATCH] Add tests for project validator

---
 .../controllerInController.md2                |  5 ++
 .../controllerInWorkflow.md2                  |  5 ++
 .../modelInWorkflow.md2                       |  5 ++
 .../viewInModel.md2                           |  5 ++
 .../workflowInModel.md2                       | 13 +++++
 .../ModelElementPackageCongruenceTest.xtend   | 56 +++++++++++++++++++
 .../framework/tests/utils/ModelProvider.java  | 16 ++++++
 7 files changed, 105 insertions(+)
 create mode 100644 de.wwu.md2.framework.tests/models/de/wwu/md2/framework/tests/dsl/project/validator/modelElementPackageCongruence/controllerInController.md2
 create mode 100644 de.wwu.md2.framework.tests/models/de/wwu/md2/framework/tests/dsl/project/validator/modelElementPackageCongruence/controllerInWorkflow.md2
 create mode 100644 de.wwu.md2.framework.tests/models/de/wwu/md2/framework/tests/dsl/project/validator/modelElementPackageCongruence/modelInWorkflow.md2
 create mode 100644 de.wwu.md2.framework.tests/models/de/wwu/md2/framework/tests/dsl/project/validator/modelElementPackageCongruence/viewInModel.md2
 create mode 100644 de.wwu.md2.framework.tests/models/de/wwu/md2/framework/tests/dsl/project/validator/modelElementPackageCongruence/workflowInModel.md2
 create mode 100644 de.wwu.md2.framework.tests/src/de/wwu/md2/framework/tests/dsl/project/validator/ModelElementPackageCongruenceTest.xtend

diff --git a/de.wwu.md2.framework.tests/models/de/wwu/md2/framework/tests/dsl/project/validator/modelElementPackageCongruence/controllerInController.md2 b/de.wwu.md2.framework.tests/models/de/wwu/md2/framework/tests/dsl/project/validator/modelElementPackageCongruence/controllerInController.md2
new file mode 100644
index 00000000..62a20e7e
--- /dev/null
+++ b/de.wwu.md2.framework.tests/models/de/wwu/md2/framework/tests/dsl/project/validator/modelElementPackageCongruence/controllerInController.md2
@@ -0,0 +1,5 @@
+package TestProject.controllers
+
+remoteConnection testConnection {
+    uri "test"
+}
diff --git a/de.wwu.md2.framework.tests/models/de/wwu/md2/framework/tests/dsl/project/validator/modelElementPackageCongruence/controllerInWorkflow.md2 b/de.wwu.md2.framework.tests/models/de/wwu/md2/framework/tests/dsl/project/validator/modelElementPackageCongruence/controllerInWorkflow.md2
new file mode 100644
index 00000000..ab1467b8
--- /dev/null
+++ b/de.wwu.md2.framework.tests/models/de/wwu/md2/framework/tests/dsl/project/validator/modelElementPackageCongruence/controllerInWorkflow.md2
@@ -0,0 +1,5 @@
+package TestProject.workflows
+
+remoteConnection testConnection {
+    uri "test"
+}
diff --git a/de.wwu.md2.framework.tests/models/de/wwu/md2/framework/tests/dsl/project/validator/modelElementPackageCongruence/modelInWorkflow.md2 b/de.wwu.md2.framework.tests/models/de/wwu/md2/framework/tests/dsl/project/validator/modelElementPackageCongruence/modelInWorkflow.md2
new file mode 100644
index 00000000..f7d3b977
--- /dev/null
+++ b/de.wwu.md2.framework.tests/models/de/wwu/md2/framework/tests/dsl/project/validator/modelElementPackageCongruence/modelInWorkflow.md2
@@ -0,0 +1,5 @@
+package TestProject.workflows
+
+entity Test {
+
+}
diff --git a/de.wwu.md2.framework.tests/models/de/wwu/md2/framework/tests/dsl/project/validator/modelElementPackageCongruence/viewInModel.md2 b/de.wwu.md2.framework.tests/models/de/wwu/md2/framework/tests/dsl/project/validator/modelElementPackageCongruence/viewInModel.md2
new file mode 100644
index 00000000..feeb2bfb
--- /dev/null
+++ b/de.wwu.md2.framework.tests/models/de/wwu/md2/framework/tests/dsl/project/validator/modelElementPackageCongruence/viewInModel.md2
@@ -0,0 +1,5 @@
+package TestProject.models
+
+FlowLayoutPane MediaCapturingView2 (vertical) {
+    
+}
diff --git a/de.wwu.md2.framework.tests/models/de/wwu/md2/framework/tests/dsl/project/validator/modelElementPackageCongruence/workflowInModel.md2 b/de.wwu.md2.framework.tests/models/de/wwu/md2/framework/tests/dsl/project/validator/modelElementPackageCongruence/workflowInModel.md2
new file mode 100644
index 00000000..b8a20f9d
--- /dev/null
+++ b/de.wwu.md2.framework.tests/models/de/wwu/md2/framework/tests/dsl/project/validator/modelElementPackageCongruence/workflowInModel.md2
@@ -0,0 +1,13 @@
+package TestProject.models
+
+WorkflowElement LocationDetection
+    fires LocationDetectionEvent {
+        start LocationDetection
+    }
+    
+App CurrentStateProjectApp {
+    WorkflowElements {
+        LocationDetection (startable: "Start Controller 1")
+    }
+    appName "functionTestApp"
+}
diff --git a/de.wwu.md2.framework.tests/src/de/wwu/md2/framework/tests/dsl/project/validator/ModelElementPackageCongruenceTest.xtend b/de.wwu.md2.framework.tests/src/de/wwu/md2/framework/tests/dsl/project/validator/ModelElementPackageCongruenceTest.xtend
new file mode 100644
index 00000000..dd31a1bd
--- /dev/null
+++ b/de.wwu.md2.framework.tests/src/de/wwu/md2/framework/tests/dsl/project/validator/ModelElementPackageCongruenceTest.xtend
@@ -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)
+    }
+}
diff --git a/de.wwu.md2.framework.tests/src/de/wwu/md2/framework/tests/utils/ModelProvider.java b/de.wwu.md2.framework.tests/src/de/wwu/md2/framework/tests/utils/ModelProvider.java
index 6b929bfe..1f7d5dad 100644
--- a/de.wwu.md2.framework.tests/src/de/wwu/md2/framework/tests/utils/ModelProvider.java
+++ b/de.wwu.md2.framework.tests/src/de/wwu/md2/framework/tests/utils/ModelProvider.java
@@ -27,12 +27,28 @@ 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***//