Commit a1aaa642 authored by Philip Makedonski's avatar Philip Makedonski
Browse files

+ added initial support for checking individual OCL constraints, operations, and expressions

+ included examples
parent a952952d
Loading
Loading
Loading
Loading
+22 −12
Original line number Diff line number Diff line
Package generated_from_ExampleAPI_yaml {
    Type String
    Type TODO_RESOLVE_REFERENCED
    Use "\"ExampleAPI.yaml\"" as SOURCE_MAPPING
    Use "\"generated/java\"" as TARGET_MAPPING
    Use "ExampleAPI.yaml" as SOURCE_MAPPING
    Use "generated/java" as TARGET_MAPPING
    Collection SearchResults of SearchResults___item
    Structure SearchResults___item (
        string id,
@@ -10,26 +10,36 @@ Package generated_from_ExampleAPI_yaml {
        string created
    )
    Type string
    Map SearchResults to "\"#/components/schemas/SearchResults\"" in SOURCE_MAPPING as SearchResults_SOURCE_MAPPING
    Map SearchResults to "\"SearchResults\"" in TARGET_MAPPING as SearchResults_TARGET_MAPPING
    Map SearchResults to "#/components/schemas/SearchResults" in SOURCE_MAPPING as SearchResults_SOURCE_MAPPING
    Map SearchResults to "SearchResults" in TARGET_MAPPING as SearchResults_TARGET_MAPPING
    Structure ResourceData (
        string id,
        string ^size,
        string created
    )
    Map ResourceData to "\"#/components/schemas/ResourceData\"" in SOURCE_MAPPING as ResourceData_SOURCE_MAPPING
    Map ResourceData to "\"ResourceData\"" in TARGET_MAPPING as ResourceData_TARGET_MAPPING
    Map ResourceData to "#/components/schemas/ResourceData" in SOURCE_MAPPING as ResourceData_SOURCE_MAPPING {
        id -> "id",
        ^size -> "size",
        created -> "created" }
    Map ResourceData to "ResourceData" in TARGET_MAPPING as ResourceData_TARGET_MAPPING {
        id -> "id",
        ^size -> "size",
        created -> "created" }
    Structure Subscription (
        Credentials credentials
    )
    Structure Credentials (
        string user
    )
    Map Subscription to "\"#/components/schemas/Subscription\"" in SOURCE_MAPPING as Subscription_SOURCE_MAPPING
    Map Subscription to "\"Subscription\"" in TARGET_MAPPING as Subscription_TARGET_MAPPING
    Map Subscription to "#/components/schemas/Subscription" in SOURCE_MAPPING as Subscription_SOURCE_MAPPING {
        credentials -> "credentials" }
    Map Subscription to "Subscription" in TARGET_MAPPING as Subscription_TARGET_MAPPING {
        credentials -> "credentials" }
    Structure AuthenticatedNotification ( )
    Map AuthenticatedNotification to "\"#/components/schemas/AuthenticatedNotification\"" in SOURCE_MAPPING as AuthenticatedNotification_SOURCE_MAPPING
    Map AuthenticatedNotification to "\"AuthenticatedNotification\"" in TARGET_MAPPING as AuthenticatedNotification_TARGET_MAPPING
    Map Credentials to "\"#/components/schemas/Credentials\"" in SOURCE_MAPPING as Credentials_SOURCE_MAPPING
    Map Credentials to "\"Credentials\"" in TARGET_MAPPING as Credentials_TARGET_MAPPING
    Map AuthenticatedNotification to "#/components/schemas/AuthenticatedNotification" in SOURCE_MAPPING as AuthenticatedNotification_SOURCE_MAPPING
    Map AuthenticatedNotification to "AuthenticatedNotification" in TARGET_MAPPING as AuthenticatedNotification_TARGET_MAPPING
    Map Credentials to "#/components/schemas/Credentials" in SOURCE_MAPPING as Credentials_SOURCE_MAPPING {
        user -> "user" }
    Map Credentials to "Credentials" in TARGET_MAPPING as Credentials_TARGET_MAPPING {
        user -> "user" }
}
 No newline at end of file
+76 −0
Original line number Diff line number Diff line
Package Wizardry {
    Type integer
    Type string
    Type Integer
    Type String
    
    Collection iCol of integer
//    Collection nCol of iCol
    
    Message Gate http accepts string, integer, String, Integer
    Component node {
        gate http interface
        gate http interface2
        gate http interface3
    } 
    
    Configuration base {  
        node sut as SUT,
//        node sut as Tester,
        node tester as Tester,
        connect sut::interface to tester::interface,
        connect sut::interface2 to tester::interface,
        connect sut::interface to tester::interface3
    }
    Test example uses base {
        tester::interface sends "hello"{string} to sut::interface
        tester::interface sends 1 {Integer} to sut::interface
        tester::interface sends 1 to sut::interface //TODO: unspecified type not resolved -> standard library Integer required
        //better error messages?
//        tester::interface3 receives 2 from sut::interface2
        
        
    }
    
	Annotation Initial conditions
	Annotation Expected behaviour
	Annotation Final conditions
	Annotation Test Purpose Description
	Annotation when
	Annotation then
       
    Objective name {
    	Description: "example"
    	References: "reference"
    }

	Test Purpose Description exampl {
		Objective: name
		Configuration: base
		Expected behaviour
		ensure that {
			when {
				tester::interface sends "hello" to sut::interface
			}	
			then {
				tester::interface receives "hello back" from sut::interface
			}				
		} 		
	}		 

	Test Purpose Description exampl2 {
		Objective: name
		Configuration: base
		Expected behaviour
		ensure that {
			when {
				tester::interface sends "hello" to sut::interface
			}	
			then {
				tester::interface receives "hello back" from sut::interface
			}				
		} 		
	}		
	
    
} 
+36 −0
Original line number Diff line number Diff line
@@ -6,10 +6,18 @@ import java.util.Arrays;
import java.util.List;
import java.util.function.Consumer;

import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.ecore.util.EcoreUtil;
import org.eclipse.epsilon.evl.execute.UnsatisfiedConstraint;
import org.eclipse.ocl.pivot.ExpressionInOCL;
import org.eclipse.ocl.pivot.utilities.OCL;
import org.eclipse.ocl.pivot.utilities.ParserException;
import org.eclipse.ocl.pivot.utilities.Query;
import org.eclipse.xtext.EcoreUtil2;
import org.etsi.mts.tdl.GateType;
import org.etsi.mts.tdl.Package;
import org.etsi.mts.tdl.tdlPackage;
import org.etsi.mts.tdl.asn2tdl.ASN2TDLTranslator;
import org.etsi.mts.tdl.constraints.evl.Validator;
import org.etsi.mts.tdl.helper.TDLHelper;
@@ -26,6 +34,8 @@ public class Standalone {
		Standalone app = new Standalone();
		//folder
		String path = "examples/basics";

		path = "examples/basics";
		app.processElements(path, app::listElements);

		//TODO: may fail
@@ -33,6 +43,13 @@ public class Standalone {
		//TODO: may fail
//		app.processElements(path, app::translate);

		TDLHelper.resetResourceSet();
		path = "examples/validation/Example.tdltx";
		//TODO: can only be used in isolation as it interferes with OCL delegates afterwards..
//		app.processElements(path, app::validateOCL);
		//TODO: may fail due to literal value use without data type
//		app.processElements(path, app::validate);
		
		TDLHelper.resetResourceSet();
		path = "examples/openapi";
		app.processElements(path, openapiExtension, app::importOpenAPI);
@@ -118,6 +135,25 @@ public class Standalone {
		}
	}

	private void validateOCL(String path) {
		Resource resource = TDLHelper.load(path);
		OCL ocl = OCL.newInstance(TDLHelper.getResourceSet());
		EClass contextEClass = tdlPackage.Literals.GATE_TYPE;
		try {
			ExpressionInOCL query = ocl.createQuery(contextEClass,
					"self.allDataTypes()"
					);
			Query queryEval = ocl.createQuery(query);
			for (var o : EcoreUtil2.getAllContentsOfType(resource.getContents().get(0), GateType.class)) {
				System.out.println(o.allDataTypes());
				System.out.println(queryEval.evaluateUnboxed(o));
			}
		} catch (ParserException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	
	private void translate(String path) {
		Resource resource = TDLHelper.load(path);
		try {