+ * Two modes of operation: + *
+ * Configuration via system properties: + *
Extend {@link PredefinedTests} to add more entries; no other class + * needs to change. + */ +public final class JUnitTestDescriptor { + + /** Human-readable label shown in the selection dialog. */ + private final String label; + + /** + * Fully-qualified class name of the JUnit test class, + * e.g. {@code com.example.myapp.tests.MyFeatureTest}. + */ + private final String testClassName; + + /** + * Optional method name. When {@code null} the whole class is run. + * When set, only that single test method is run, + * e.g. {@code testParseValidDocument}. + */ + private final String testMethodName; + + private final String testObjective; + + // ----------------------------------------------------------------------- + + /** + * Creates a descriptor for running an entire test class. + */ + public JUnitTestDescriptor(String label, String testClassName) { + this(label, testClassName, null, null); + } + + public JUnitTestDescriptor(String label, String testClassName, String testMethodName) { + this(label, testClassName, testMethodName, null); + } + + + /** + * Creates a descriptor for running a single test method. + */ + public JUnitTestDescriptor(String label, String testClassName, String testMethodName, String testObjective) { + this.label = label; + this.testClassName = testClassName; + this.testMethodName = testMethodName; + this.testObjective = testObjective; + } + + // ----------------------------------------------------------------------- + + public String getLabel() { return label; } + public String getTestClassName() { return testClassName; } + public String getTestMethodName() { return testMethodName; } + public String getTestObjective() { return testObjective; } + + /** Returns {@code true} when only a single method should be executed. */ + public boolean hasSingleMethod() { return testMethodName != null && !testMethodName.isEmpty(); } + public boolean hastestObjective() { return testObjective != null && !testObjective.isEmpty(); } + + @Override + public String toString() { return label; } +} \ No newline at end of file diff --git a/plugins/org.etsi.mts.tdl.execution.java/src/org/etsi/mts/tdl/execution/java/eclipse/commands/RenderHandler.java b/plugins/org.etsi.mts.tdl.execution.java/src/org/etsi/mts/tdl/execution/java/eclipse/commands/RenderHandler.java index a9a05cf7e4b5cf95288a8f341f1fa32ab34fd159..90788bb300e9abb7cc521d9cd9707088d941b429 100644 --- a/plugins/org.etsi.mts.tdl.execution.java/src/org/etsi/mts/tdl/execution/java/eclipse/commands/RenderHandler.java +++ b/plugins/org.etsi.mts.tdl.execution.java/src/org/etsi/mts/tdl/execution/java/eclipse/commands/RenderHandler.java @@ -25,7 +25,9 @@ import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl; import org.eclipse.emf.ecore.util.EcoreUtil; import org.eclipse.jface.viewers.ISelection; import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.ui.IEditorInput; import org.eclipse.ui.handlers.HandlerUtil; +import org.eclipse.ui.part.FileEditorInput; import org.etsi.mts.tdl.Package; import org.etsi.mts.tdl.execution.java.codegen.JUnitTestGenerator; import org.etsi.mts.tdl.execution.java.codegen.Settings; @@ -39,7 +41,10 @@ public class RenderHandler extends AbstractHandler implements IHandler { IFile tdl = null; ISelection selection = HandlerUtil.getCurrentSelection(event); - if (selection instanceof IStructuredSelection && !selection.isEmpty()) { + IEditorInput input = HandlerUtil.getActiveEditorInput(event); + if (input != null && input instanceof FileEditorInput) { + tdl = ((FileEditorInput) input).getFile(); + } else if (selection instanceof IStructuredSelection && !selection.isEmpty()) { Object element = ((IStructuredSelection) selection).getFirstElement(); if (element instanceof IFile) { String ext = ((IFile) element).getFileExtension(); @@ -69,7 +74,8 @@ public class RenderHandler extends AbstractHandler implements IHandler { preferences.get(Settings.INJECTOR, ""), preferences.get(Settings.DATE_FORMAT, ""), preferences.get(Settings.USE_MAPPING, ""), - preferences.getBoolean(Settings.UNMAPPED_DATA, false)); + preferences.getBoolean(Settings.UNMAPPED_DATA, false), + preferences.getBoolean(Settings.LOG_BEHAVIOUR_TRACES, false)); JUnitTestGenerator generator = new JUnitTestGenerator(model, settings); diff --git a/plugins/org.etsi.mts.tdl.execution.java/src/org/etsi/mts/tdl/execution/java/eclipse/commands/RunJUnitTestHandler.java b/plugins/org.etsi.mts.tdl.execution.java/src/org/etsi/mts/tdl/execution/java/eclipse/commands/RunJUnitTestHandler.java new file mode 100644 index 0000000000000000000000000000000000000000..a0922b5a72d6eb1edf19597a19011339eb957742 --- /dev/null +++ b/plugins/org.etsi.mts.tdl.execution.java/src/org/etsi/mts/tdl/execution/java/eclipse/commands/RunJUnitTestHandler.java @@ -0,0 +1,286 @@ +package org.etsi.mts.tdl.execution.java.eclipse.commands; + +import java.util.Iterator; +import java.util.List; + +import org.eclipse.core.commands.AbstractHandler; +import org.eclipse.core.commands.ExecutionEvent; +import org.eclipse.core.commands.ExecutionException; +import org.eclipse.core.resources.IContainer; +import org.eclipse.core.resources.IFile; +import org.eclipse.core.resources.IFolder; +import org.eclipse.core.resources.IProject; +import org.eclipse.core.resources.ProjectScope; +import org.eclipse.core.resources.ResourcesPlugin; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.NullProgressMonitor; +import org.eclipse.core.runtime.Path; +import org.eclipse.core.runtime.Status; +import org.eclipse.debug.core.DebugPlugin; +import org.eclipse.debug.core.ILaunchConfiguration; +import org.eclipse.debug.core.ILaunchConfigurationType; +import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy; +import org.eclipse.debug.core.ILaunchManager; +import org.eclipse.debug.ui.DebugUITools; +import org.eclipse.emf.common.util.URI; +import org.eclipse.emf.ecore.resource.Resource; +import org.eclipse.emf.ecore.util.EcoreUtil; +import org.eclipse.jdt.core.IType; +import org.eclipse.jdt.core.JavaCore; +import org.eclipse.jdt.core.JavaModelException; +import org.eclipse.jdt.launching.IJavaLaunchConfigurationConstants; +import org.eclipse.jface.dialogs.ErrorDialog; +import org.eclipse.jface.dialogs.IDialogConstants; +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.ui.IEditorInput; +import org.eclipse.ui.IFileEditorInput; +import org.eclipse.ui.IWorkbenchWindow; +import org.eclipse.ui.handlers.HandlerUtil; +import org.eclipse.ui.part.FileEditorInput; +import org.eclipse.xtext.EcoreUtil2; +import org.eclipse.xtext.resource.XtextResourceSet; +import org.etsi.mts.tdl.Package; +import org.etsi.mts.tdl.TestDescription; +import org.etsi.mts.tdl.execution.java.codegen.Settings; +import org.etsi.mts.tdl.execution.java.eclipse.ui.PropertyPage; +import org.osgi.service.prefs.Preferences; + +import com.google.inject.Guice; +import com.google.inject.Injector; + +/** + * Handles the "Run Specific JUnit Test…" command. + * + *
Configuration names follow the pattern:
+ * {@code
After {@link #open()} returns {@link IDialogConstants#OK_ID} call + * {@link #getSelectedTest()} to retrieve the chosen descriptor.
+ */ +public class SelectJUnitTestDialog extends Dialog { + + private final ListTDLtx
-This is a parameterized project for TDLtx. 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.
TDL Textual Plain Template
+Plain project template without any example content.
TDLtx
-This is a parameterized project for TDLtx. 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.
TDL Textual for Test Purposes using TDL-TO
+Project template for Test Purpose specification using TDL-TO, includes an example Test Purpose to get started.
TDL Textual for Test Purpose Descriptions
+Project template for Test Purpose Description specification using TDL-TO, includes an example Test Purpose Description to get started.
Package Example {\n ...\n}
") +final class TDLtxProjectBaseTPD { + //TODO: remove after testing + val advanced = check("Advanced:", false) + val advancedGroup = group("Properties") +// val name = combo("Package Name:", #["Example", "Sample", "Tutorial", "Pack"], "The name of the package", advancedGroup) + val name = text("Main Package Name:", "Main", "The name of the main package") + val path = text("Path:", "tdl", "The package path to place the files in", advancedGroup) + //TODO: add other options + val importStandard = check("Import TDL Library", true, "Import TDL standard library definitions.", advancedGroup) + val importHTTP = check("Import HTTP Library", false, "Import TDL HTTP library definitions.", advancedGroup) + val extendedNature = check("Add additional natures", false, "Add Eclipse Plug-in and Java natures", advancedGroup) + + @Inject + PluginImageHelper pluginImageHelper + + override protected updateVariables() { + name.enabled = advanced.value + path.enabled = advanced.value + importStandard.enabled = advanced.value + importHTTP.enabled = advanced.value + extendedNature.enabled = advanced.value + if (!advanced.value) { + name.value = "Main" + path.value = "tdl" + importStandard.value = true + importHTTP.value = false + extendedNature.value = false + } + } + + override protected validate() { + //TODO: validate name as well + if (path.value.matches('[a-z][a-z0-9_.]*(/[a-z][a-z0-9_.]*)*')) + null + else + new Status(ERROR, "Wizard", "'" + path + "' is not a valid package name") + //TODO: validate data definitions as well + } + + override generateProjects(IProjectGenerator generator) { + generator.generate(new PluginProjectFactory => [ + projectName = projectInfo.projectName + location = projectInfo.locationPath + projectNatures += #[XtextProjectHelper.NATURE_ID] + builderIds += #[XtextProjectHelper.BUILDER_ID] + if (extendedNature.value) { + projectNatures += #[JavaCore.NATURE_ID, "org.eclipse.pde.PluginNature"] + builderIds += #[JavaCore.BUILDER_ID] + } + folders += "src" + //TODO: remove hardcoded import + var imports = "" + if (importStandard.value) { + addFile('''src/«path»/TDL.tdltx''', TemplateHelper.getLibrary("TDL")) + imports += "Import all from TDL\n" + } + if (importHTTP.value) { + addFile('''src/«path»/HTTP.tdltx''', TemplateHelper.getLibrary("HTTP")) + imports += "Import all from HTTP\n" + imports += "Import all from HTTP.MessageBased\n" + } + addFile('''src/«path»/«name».tdltx''', ''' + /* + * This is an example package + */ + Package «name» { + «imports» + //Example definitions to get started + Message Gate api accepts String + + Component node { + gate api http + } + + Configuration nodeTC { + node sut as SUT, + node tester as Tester, + connect server=sut::http to client=tester::http + } + + @PICS Boolean F1 + @PICS Boolean F2 + + Objective TO_01 { + Description: "Test document generation" + References: "Epic #xy" + } + + Test Purpose Description TP_01 { + Objective: TO_01 + Configuration: nodeTC + PICS: (F1 or F2) on tester + Initial conditions + with { + client sends "initiate" to server + } + + Expected behaviour + ensure that { + when { + client sends "request" to server + } + then { + client receives "response" from server + } + } + } + } + ''') + ]) + //TODO: make more robust and share among other templates + open(projectInfo.projectName+"/src/"+path+"/"+name+".tdltx") + } + + private def open(String filePath) { + val path = new Path(filePath) + val ifile=ResourcesPlugin.getWorkspace().getRoot().getFile(path) +// val page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(); + val page = PlatformUI.workbench.workbenchWindows.get(0).activePage + Display.^default.asyncExec(new Runnable() { + + override run() { + IDE.openEditor(page, ifile) + } + + }) + } + + protected override ListTDLtx with OpenAPI
-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.
TDL Textual for Executable Tests
+Project template for executable tests.
TDLtx
This is a parameterized project for TDLtx. 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.
TDL Textual Plain Template
Plain project template without any example content.
TDLtx with OpenAPI
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.
TDL Textual for Executable Tests
Project template for executable tests.
TDLtx
This is a parameterized project for TDLtx. 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.
TDL Textual for Test Purposes using TDL-TO
Project template for Test Purpose specification using TDL-TO, includes an example Test Purpose to get started.
TDL Textual for Test Purpose Descriptions
Project template for Test Purpose Description specification using TDL-TO, includes an example Test Purpose Description to get started.
Package Example { ... }
+TDLtxProjectExecutable_Label=TDL Textual Project for Executable Tests +TDLtxProjectExecutable_Description=TDL Textual for Executable Tests
TODO: This is a parameterized project for TDL Textual. 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.
null if none.
+ */
+ private String lastPath;
+
+
+ private String[] extensions = null;
+
+ private File filterPath = null;
+
+ /**
+ * The special label text for directory chooser,
+ * or null if none.
+ */
+ private String dirChooserLabelText;
+
+ /**
+ * Creates a new path field editor
+ */
+ protected FileListEditor() {
+ }
+
+ /**
+ * Creates a path field editor.
+ *
+ * @param name the name of the preference this field editor works on
+ * @param labelText the label text of the field editor
+ * @param dirChooserLabelText the label text displayed for the directory chooser
+ * @param parent the parent of the field editor's control
+ */
+ public FileListEditor(String name, String labelText,
+ String dirChooserLabelText, Composite parent) {
+ init(name, labelText);
+ this.dirChooserLabelText = dirChooserLabelText;
+ createControl(parent);
+ adapt();
+ }
+
+ private void adapt() {
+ getAddButton().removeListener(SWT.Selection, getAddButton().getListeners(SWT.Selection)[0]);
+ getAddButton().addListener(SWT.Selection, e -> {
+ addPressed();
+ });
+ }
+
+ @Override
+ protected String createList(String[] items) {
+ StringBuilder path = new StringBuilder("");//$NON-NLS-1$
+
+ for (String item : items) {
+ path.append(item);
+ path.append(File.pathSeparator);
+ }
+ return path.toString();
+ }
+
+ /**
+ * Notifies that the Add button has been pressed.
+ */
+ private void addPressed() {
+ setPresentsDefaultValue(false);
+ String[] input = getNewFileListInputObject();
+
+ if (input != null && input.length > 0) {
+ int index = getList().getSelectionIndex();
+ Listnull
+ * to set the filter to the system's default value
+ */
+ public void setFileExtensions(String[] extensions) {
+ this.extensions = extensions;
+ }
+
+ /**
+ * Sets the initial path for the Browse dialog.
+ * @param path initial path for the Browse dialog
+ * @since 3.6
+ */
+ public void setFilterPath(File path) {
+ filterPath = path;
+ }
+
+}
diff --git a/plugins/org.etsi.mts.tdl.wizards/src/org/etsi/mts/tdl/wizards/importWizards/ImportWizard.java b/plugins/org.etsi.mts.tdl.wizards/src/org/etsi/mts/tdl/wizards/importWizards/ImportWizard.java
index efd3a19ce7535e7b63ca74e03660837fffc97ced..98f8337fbf81f086c4c6184e7588f0b47a5cf7ee 100644
--- a/plugins/org.etsi.mts.tdl.wizards/src/org/etsi/mts/tdl/wizards/importWizards/ImportWizard.java
+++ b/plugins/org.etsi.mts.tdl.wizards/src/org/etsi/mts/tdl/wizards/importWizards/ImportWizard.java
@@ -28,15 +28,16 @@ public class ImportWizard extends Wizard implements IImportWizard {
//TODO: use eclipse way?
//TODO: separate location for source?
if (mainPage.isCopySource()) {
- IPath sourcePath = mainPage.getSourcePath();
- try {
- java.nio.file.Files.copy(
- Path.of(sourcePath.toOSString()),
- Path.of(file.getParent().getLocation().append(sourcePath.lastSegment()).toOSString()),
- StandardCopyOption.REPLACE_EXISTING);
- } catch (IOException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
+ for (IPath sourcePath : mainPage.getSourcePaths()) {
+ try {
+ java.nio.file.Files.copy(
+ Path.of(sourcePath.toOSString()),
+ Path.of(file.getParent().getLocation().append(sourcePath.lastSegment()).toOSString()),
+ StandardCopyOption.REPLACE_EXISTING);
+ } catch (IOException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
}
}
if (file == null)
diff --git a/plugins/org.etsi.mts.tdl.wizards/src/org/etsi/mts/tdl/wizards/importWizards/ImportWizardPage.java b/plugins/org.etsi.mts.tdl.wizards/src/org/etsi/mts/tdl/wizards/importWizards/ImportWizardPage.java
index fc4d17f8d6c7fad0e7d940b66ca0759279c2ab9b..ff8c097016dfc43824374c059098659ed8b6c9b4 100644
--- a/plugins/org.etsi.mts.tdl.wizards/src/org/etsi/mts/tdl/wizards/importWizards/ImportWizardPage.java
+++ b/plugins/org.etsi.mts.tdl.wizards/src/org/etsi/mts/tdl/wizards/importWizards/ImportWizardPage.java
@@ -1,48 +1,64 @@
package org.etsi.mts.tdl.wizards.importWizards;
import java.io.InputStream;
+import java.time.LocalDateTime;
+import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
-import java.util.Collection;
+import java.util.Calendar;
+import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.List;
+import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IWorkspace;
import org.eclipse.core.resources.IWorkspaceRoot;
import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Path;
import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.preferences.InstanceScope;
+import org.eclipse.jface.preference.DirectoryFieldEditor;
import org.eclipse.jface.preference.FileFieldEditor;
+import org.eclipse.jface.preference.IPreferenceStore;
+import org.eclipse.jface.preference.ListEditor;
+import org.eclipse.jface.preference.PathEditor;
+import org.eclipse.jface.preference.StringFieldEditor;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.layout.RowLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Label;
import org.eclipse.ui.dialogs.WizardNewFileCreationPage;
import org.eclipse.xtext.util.StringInputStream;
-import org.etsi.mts.tdl.json2tdl.JSONConverter;
-import org.etsi.mts.tdl.openapi2tdl.next.ConverterNext;
+import org.etsi.mts.tdl.transform.Converter;
+import org.etsi.mts.tdl.transform.ProtocolServerBridge;
import org.osgi.service.prefs.Preferences;
-
public class ImportWizardPage extends WizardNewFileCreationPage {
- protected FileFieldEditor editor;
+ protected FileFieldEditor fileEditor;
private boolean inline = false;
private boolean copySource = false;
- private IPath sourcePath;
+ private boolean overwrite = true;
+ private List