Skip to content

Commit

Permalink
Validator + validator tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Julia65 committed Dec 15, 2014
1 parent a46cd4c commit 95c07a0
Show file tree
Hide file tree
Showing 7 changed files with 235 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package CurrentStateProject.controllers

main {
appVersion "1.0"
modelVersion "1.0"
}
remoteConnection CitizenAppRemoteConnection {
uri "http://localhost:8081/Backend/"
}
contentProvider Complaint localComplaintProvider {
providerType CitizenAppRemoteConnection
}

WorkflowElement LocationDetection{
onInit {
action CustomAction init{

}
}
action CustomAction next {
bind action FireEvent(LocationEvent) on LocationVerifyView.Next2.onClick
}
processChain LocationProcessChain{
step LocationDetection:
view LocationDetectionView
}
}

WorkflowElement SubmitComplaint {
onInit {
action CustomAction init {
}
}
action CustomAction next {
bind action FireEvent(LocationEvent) on LocationVerifyView.Next2.onClick
}
processChain ComplaintProcessChain {
step SubmitComplaint:
view SubmitComplaintView
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package CurrentStateProject.models

entity Complaint {
loc: Location // use current MD2 location instead!--> No, current MD2 location is a content provider, not an entity!
descriptions : string
feedback : string
status : ComplaintStatus
}

entity Location {
myStreet: string
myStreetNo: string
myPostalCode: integer
myCity: string
myCountry: string
myLatitude: float
myLongitude: float
}

enum ComplaintStatus {
"User is filling out complaint",
"Complaint is sent to administration",
"Complaint is in process",
"Complaint has been handled by the administration"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
package CurrentStateProject.views

GridLayoutPane LocationDetectionView (columns 2, rows 9) {
Label TitleLbl ("Enter your location") // better: As Title of Activity
Spacer
TextInput streetLbl {tooltip "street"}
TextInput streetNoLbl {tooltip "no"}
IntegerInput zipLbl {tooltip "zip" }
TextInput cityLbl {tooltip "city"}
TextInput countryLbl {tooltip "country" width 100%}
Spacer {width 1%}
Label latitudeLbl ("Latitude:")
Label latitudeValueLbl ("")
Label longitudeLbl ("Longitude:")
Label longitudeValueLbl ("")
Spacer {width 1%}
Button DetectLocationBtn {text "My Location"}
Button Cancel {text "Cancel"}
Button Next {text "Next"}
//NavigationBar(Cancel, next)
Spacer {width 1%}
}

FlowLayoutPane LocationVerifyView (vertical) {
Label TitleLbl ("Verify Location") // better: As Title of Activity

FlowLayoutPane StreetView (horizontal) {
LocationDetectionView.streetLbl -> streetLbl2
LocationDetectionView.streetNoLbl -> streetNoLbl2
}
FlowLayoutPane CityView (horizontal) {
LocationDetectionView.zipLbl -> zipLbl2
LocationDetectionView.cityLbl -> cityLbl2
}

LocationDetectionView.countryLbl -> countryLbl2
Spacer {width 1%}
LocationDetectionView.latitudeLbl -> latitudeLbl2
LocationDetectionView.longitudeLbl -> longitudeLbl2

//NavigationBar(Cancel, previous, next)
LocationDetectionView.Cancel -> Cancel2
LocationDetectionView.Next -> Next2
Button Previous {text "Previous"}
}

FlowLayoutPane SubmitComplaintView (vertical) {
Label TitleLbl ("Submit Complaint") // better: As Title of Activity
Image UploadImg {
src "uploadedImage.png"
}
FlowLayoutPane StreetView (horizontal) {
LocationDetectionView.streetLbl -> streetLbl3
LocationDetectionView.streetNoLbl -> streetNoLbl3
}
FlowLayoutPane CityView (horizontal) {
LocationDetectionView.zipLbl -> zipLbl3
LocationDetectionView.cityLbl -> cityLbl3
}

LocationDetectionView.countryLbl -> countryLbl3
Spacer {width 1%}
LocationDetectionView.latitudeLbl -> latitudeLbl3
LocationDetectionView.longitudeLbl -> longitudeLbl3

TextInput DescriptionTxt {
label "Additional Description"
type textarea
}
//NavigationBar(Cancel, next "Submit complaint")
LocationDetectionView.Cancel -> Cancel3
Button submitComplaint {text "Submit complaint"}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package CurrentStateProject.workflows

/*
* Implement the workflow here
*/

WorkflowElement LocationDetection
fires LocationEvent {
start LocationDetection
}

WorkflowElement SubmitComplaint
fires SubmitEvent {
start LocationDetection
}
fires anotherEvent{
start LocationDetection
}
App Citizenapp {
WorkflowElements {
LocationDetection (startable: "Start Controller 1"),
SubmitComplaint
}
appName "currentStateApp"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package de.wwu.md2.framework.tests.dsl.workflow.functionTest

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.eclipse.emf.ecore.resource.ResourceSet
import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl
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.validation.ControllerValidator
import de.wwu.md2.framework.mD2.MD2Package

@InjectWith(typeof(MD2InjectorProvider))
@RunWith(typeof(XtextRunner))
class validatorTest {

@Inject extension ParseHelper<MD2Model>
@Inject extension ValidationTestHelper
MD2Model workflowModel;
MD2Model controllerModel;
MD2Model viewModel;
MD2Model modelModel;
ResourceSet rs;

@Before
def void setUp() {
rs = new ResourceSetImpl();
workflowModel = WORKFLOW_VALIDATOR_W.load.parse(rs);
controllerModel = WORKFLOW_VALIDATOR_C.load.parse(rs);
viewModel = WORKFLOW_VALIDATOR_V.load.parse(rs);
modelModel = WORKFLOW_VALIDATOR_M.load.parse(rs);
}

@Test
def checkIfSpecifiedEventsAreFiredInControllerTest(){
workflowModel.assertNoErrors();
//workflowModel.assertNoIssues();
workflowModel.assertWarning(MD2Package::eINSTANCE.workflowEvent,ControllerValidator::FIREEVENT)
}

@Test
def checkEventExistsInCorrectWorkflowElementTest(){
//controllerModel.assertNoErrors();
//controllerModel.assertNoIssues();
controllerModel.assertError(MD2Package::eINSTANCE.fireEventAction,ControllerValidator::EVENTREFERENCE);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,17 @@ public class ModelProvider {

public static String VALIDATOR_MODEL_M = "dsl/model/validator/Model.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 @@ -30,6 +30,7 @@ import de.wwu.md2.framework.mD2.WorkflowElementEntry import de.wwu.md2.framework
import de.wwu.md2.framework.mD2.CustomAction
import de.wwu.md2.framework.mD2.EventBindingTask
import java.util.ArrayList
import de.wwu.md2.framework.mD2.SimpleActionRef

/**
* Valaidators for all controller elements of MD2.
Expand All @@ -45,6 +46,7 @@ class ControllerValidator extends AbstractMD2JavaValidator {
/// Action Validators
/////////////////////////////////////////////////////////


/**
* Ensures that the operations 'save' and 'remove' can only be used for none-read-only content providers
* in the ContentProviderOperationAction.
Expand All @@ -66,6 +68,7 @@ class ControllerValidator extends AbstractMD2JavaValidator {
}
}

public static final String EVENTREFERENCE = "EventReference";
/**
* Checks whether an event which is fired in a controller is specified in the corresponding workflowelement
* in the workflowelement file
Expand All @@ -76,11 +79,13 @@ class ControllerValidator extends AbstractMD2JavaValidator {

val workflowElementInController = (action.eContainer.eContainer.eContainer.eContainer as WorkflowElement)
if(workflowElementInWorkflow.name != workflowElementInController.name){
error("Event not specified in WorkflowElement", MD2Package.eINSTANCE.fireEventAction_WorkflowEvent)
error("Event not specified in WorkflowElement", MD2Package.eINSTANCE.fireEventAction_WorkflowEvent, -1, EVENTREFERENCE)
}
}

/*

public static final String FIREEVENT = "fireevent";
/**
* Checks whether an event, which is specified in an workflowelemententry is fired in the
* corresponding controller workflowelement
*/
Expand All @@ -95,12 +100,13 @@ class ControllerValidator extends AbstractMD2JavaValidator {
}

for (ev : eventBindingTasks) {
fireEventActions += ev.actions.filter(typeof(SimpleAction)).filter(typeof (FireEventAction))
val test = ev.actions.filter(typeof(SimpleActionRef)).map[a|a.action].filter(typeof (FireEventAction))
fireEventActions.addAll(test)
}
val correspondingEvents = fireEventActions.filter[it.workflowEvent == event]

if(correspondingEvents.length == 0){
warning("Event " + event.name + " is not fired in the corresponding controller", MD2Package.eINSTANCE.workflowEvent_Name)
warning("Event " + event.name + " is not fired in the corresponding controller", MD2Package.eINSTANCE.workflowEvent_Name, -1, FIREEVENT)
}
}

Expand Down

0 comments on commit 95c07a0

Please sign in to comment.