/*******************************************************************************
* Copyright (c) 2019 itemis AG (http://www.itemis.eu) and others.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0.
......@@ -8,9 +7,14 @@
*******************************************************************************/
package org.etsi.mts.tdl.ui.wizard
/**
* @author miklossy - Initial contribution and API
*/
import java.nio.file.Files
import java.nio.file.Path
import org.eclipse.core.runtime.Platform
import org.osgi.framework.Bundle
import java.net.URL
import java.io.File
import java.net.URI
class TemplateContent {
//TODO: can we access the shared templates instead?
public static val Example = '''
......@@ -40,5 +44,6 @@ class TemplateContent {
tester::interface sends "hello" {string} to sut::interface
}
}
'''
'''
}
package org.etsi.mts.tdl.ui.wizard;
import java.io.File;
import java.net.URI;
import java.net.URL;
import java.nio.file.Files;
import java.nio.file.Path;
import org.eclipse.core.runtime.FileLocator;
import org.eclipse.core.runtime.Platform;
import org.eclipse.xtext.xbase.lib.Exceptions;
import org.osgi.framework.Bundle;
public class TemplateHelper {
enum Libraries {
Standard, HTTP
}
public static String getLibrary(String name) {
String library = "";
try {
System.out.println("Get standard library...");
String absolutePath = Path.of("templates/"+name+".tdltx").toFile().getAbsolutePath();
System.out.println(" Path: " + absolutePath);
String source = "templates/"+name+".tdltx";
URI uri = new File(source).toURI();
if (Platform.isRunning()) {
System.out.println("Running as plugin...");
Bundle bundle = Platform.getBundle("org.etsi.mts.tdl.tx.ui");
URL url = bundle.getEntry(source);
uri = url.toURI();
uri = FileLocator.resolve(url).toURI();
} else {
System.out.println("Get from class localtion...");
String binPath = TemplateContent.class.getClass().getProtectionDomain().getCodeSource()
.getLocation().getPath();
String projectPath = new File(binPath).getParent();
uri = new File(((projectPath + "/") + source)).toURI();
}
// System.out.println(uri);
library = Files.readString(Path.of(uri));
} catch (Throwable _e) {
throw Exceptions.sneakyThrow(_e);
}
return library;
}
}
......@@ -8,3 +8,5 @@ TDLtxProjectWithOpenAPI_Label=TDLtx with OpenAPI
TDLtxProjectWithOpenAPI_Description=<p><b>TDLtx with OpenAPI</b></p> <p>This is a parameterized project for TDLtx with the option to import data definitions from OpenAPI. You can set a parameter to modify the content in the generated file and a parameter to set the path the file is created in.</p><p><img href="project_template.png"/></p>
TDLtxFileFromOpenAPI_Label=Data definitions import from OpenAPI
TDLtxFileFromOpenAPI_Description=Create a new package for TDLtx from OpenAPI data definitions.
TDLtxLibrary_Label=TDLtx Library
TDLtxLibrary_Description=Add library for TDL.
Package HTTP {
Package MessageBasedConfiguration {
Import all from MessageBased
Message Gate HTTPGate accepts Request,Response
Component API {
//Add variables and timers here or define new component types and configurations
gate HTTPGate http
}
Configuration BasicClientServer {
API client as Tester,
API server as SUT,
connect client::http to server::http
}
} Note : "Message based types and instances"
Package MessageBased {
Import all from Standard
//Generic Method type
Type Method
Method mGET
Method mPOST
Method mPUT
Method mPATCH
Method mDELETE
//Generic Request type
Structure Request (
String uri,
optional Method method,
optional Headers headers,
optional Parameters parameters,
optional Body body
)
//Generic Request instances
Request GET ( )
Request POST ( )
Request PUT ( )
Request PATCH ( )
Request DELETE ( )
//Generic Response type
Structure Response (
optional Integer status,
optional String statusMessage,
optional Headers headers,
optional Body body
)
//Generic Response instances, name = status code
Response r200 (statusMessage = "OK")
Response r201 (statusMessage = "Created")
Response r204 (statusMessage = "No Content")
Response r400 (statusMessage = "Bad Request")
Response r401 (statusMessage = "Not Found")
Response r403 (statusMessage = "Not Authorized")
Response r404 (statusMessage = "Forbidden")
//Generic Response instances, name = status message
Response OK (status = "200")
Response Created (status = "201")
Response NoContent (status = "204")
Response BadRequest (status = "400")
Response NotFound (status = "404")
Response NotAuthorized (status = "401")
Response Forbidden (status = "403")
//supporting types
Collection Parameters of Parameter
Structure Parameter (
Location location,
String ^name,
String ^value
)
Type Location
Location path
Location query
//may need a structure, not necessarily relevant in standardized testing
Location cookie
//separate headers -> not necessary
//Location header;
Collection Headers of Header
Structure Header (
String ^name,
String ^value
//not relevant in TDL?
//optional contentLength of type Integer,
//optional contentType of type String
)
//Base body for extension
Structure Body ( )
//Basic string body
Structure StringBody extends Body (
String text
)
//Basic wrapper for collection responses
Structure CollectionBody extends Body (
Bodies items
)
//Any body can be included
//If consistent type is needed, a custom subtype shall be defined and used
Collection Bodies of Body
//Custom collection data instances can be defined
// - inline in the responses
// - predefined as a separate data element
//Custom collection data instances can be defined
//to enforce type consistency specific for API
//Basic form body
Structure FormBody extends Body (
String field,
String content
)
}
}
\ No newline at end of file
Package Standard {
//TODO: extract to standard library
Constraint length
Constraint minLength
Constraint maxLength
Constraint range
Constraint format
Constraint union
Constraint uniontype
Type Boolean
Type Integer
Type String
Type Verdict
//TODO: these do not work at present -> literal values take precedence?
// Boolean true
// Boolean false
Boolean True
Boolean False
Verdict pass
Verdict fail
Verdict inconclusive
Time second
Annotation Master
Annotation MappingName
//standard annotations for STO
Annotation Initial conditions
Annotation Expected behaviour
Annotation Final conditions
Annotation Test Purpose Description
Annotation when
Annotation then
Predefined == returns Boolean
Predefined != returns Boolean
Predefined and returns Boolean
Predefined or returns Boolean
Predefined xor returns Boolean
Predefined not returns Boolean
Predefined < returns Boolean
Predefined > returns Boolean
Predefined <= returns Boolean
Predefined >= returns Boolean
Predefined +
Predefined -
Predefined *
Predefined /
Predefined mod
Predefined size returns Integer
}
\ No newline at end of file
......@@ -15,7 +15,10 @@ Require-Bundle: org.etsi.mts.tdl.model,
org.eclipse.core.runtime,
org.etsi.mts.tdl.common,
org.antlr.runtime;bundle-version="[3.2.0,3.2.1)",
org.eclipse.epsilon.evl.emf.validation
org.eclipse.epsilon.evl.emf.validation,
org.eclipse.epsilon.evl.engine,
org.eclipse.epsilon.eol.engine,
org.eclipse.epsilon.emc.emf
Bundle-RequiredExecutionEnvironment: JavaSE-11
Export-Package: org.etsi.mts.tdl.parser.antlr.internal,
org.etsi.mts.tdl.scoping,
......