From 2b50b279abf056527aaefa7a13e018ca67f6ed1d Mon Sep 17 00:00:00 2001 From: junkerm Date: Tue, 20 Aug 2019 15:17:03 +0200 Subject: [PATCH] Test procedure export to csv (#472) * refactor test specification export * wip: only testing is missing * add tests * change output folder of test (to bin_test) * remove duplicate files * fix imports --- bundles/specmate-testspecification/.classpath | 2 +- bundles/specmate-testspecification/.gitignore | 5 +- bundles/specmate-testspecification/bnd.bnd | 4 +- .../testspecification/api/ITestExporter.java | 19 +++ .../api/ITestProcedureExporter.java | 5 + .../testspecification/api/packageinfo | 1 + .../exporters/CSVTestProcedureExporter.java | 54 +++++++++ .../CSVTestSpecificationExporter.java} | 35 +++--- .../internal/exporters/ExportUtil.java | 27 +++++ .../JavaTestSpecificationExporter.java} | 15 ++- .../JavascriptTestSpecificationExporter.java} | 15 ++- .../TestSpecificationExporterBase.java} | 45 +++++--- .../CEGNodeEvaluation.java | 3 +- .../CEGNodeEvaluationComparator.java | 47 ++++---- .../CEGTestCaseGenerator.java | 29 +++-- .../ProcessNodeEvaluation.java | 2 +- .../ProcessTestCaseGenerator.java | 4 +- .../TaggedBoolean.java | 2 +- .../TestCaseGeneratorBase.java | 2 +- .../internal/services/TestExportService.java | 108 ++++++++++++++++++ .../services/TestGeneratorService.java | 2 + .../TestSkeletonGeneratorService.java | 86 -------------- .../test/CEGTestGenerationTest.java | 2 +- .../test/TestExportTestProcedure.java | 57 +++++++++ ....java => TestExportTestSpecification.java} | 35 ++++-- .../export-testprocedure-button.component.css | 4 + ...export-testprocedure-button.component.html | 6 +- ...ecification-skeleton-button.component.html | 3 - .../test-export-button.component.css} | 8 +- .../test-export-button.component.html | 1 + .../test-export-button.component.ts} | 23 ++-- .../test-export-button.module.ts} | 8 +- .../components/links-actions.component.html | 16 ++- .../links-actions/links-actions.module.ts | 4 +- web/src/assets/i18n/de.json | 1 + web/src/assets/i18n/gb.json | 1 + web/tsconfig.json | 6 + 37 files changed, 474 insertions(+), 213 deletions(-) create mode 100644 bundles/specmate-testspecification/src/com/specmate/testspecification/api/ITestExporter.java create mode 100644 bundles/specmate-testspecification/src/com/specmate/testspecification/api/ITestProcedureExporter.java create mode 100644 bundles/specmate-testspecification/src/com/specmate/testspecification/api/packageinfo create mode 100644 bundles/specmate-testspecification/src/com/specmate/testspecification/internal/exporters/CSVTestProcedureExporter.java rename bundles/specmate-testspecification/src/com/specmate/testspecification/internal/{testskeleton/CSVTestSpecificationSkeleton.java => exporters/CSVTestSpecificationExporter.java} (58%) create mode 100644 bundles/specmate-testspecification/src/com/specmate/testspecification/internal/exporters/ExportUtil.java rename bundles/specmate-testspecification/src/com/specmate/testspecification/internal/{testskeleton/JavaTestSpecificationSkeleton.java => exporters/JavaTestSpecificationExporter.java} (75%) rename bundles/specmate-testspecification/src/com/specmate/testspecification/internal/{testskeleton/JavascriptTestSpecificationSkeleton.java => exporters/JavascriptTestSpecificationExporter.java} (74%) rename bundles/specmate-testspecification/src/com/specmate/testspecification/internal/{testskeleton/BaseSkeleton.java => exporters/TestSpecificationExporterBase.java} (81%) rename bundles/specmate-testspecification/src/com/specmate/testspecification/internal/{services => generators}/CEGNodeEvaluation.java (84%) rename bundles/specmate-testspecification/src/com/specmate/testspecification/internal/{services => generators}/CEGNodeEvaluationComparator.java (67%) rename bundles/specmate-testspecification/src/com/specmate/testspecification/internal/{services => generators}/CEGTestCaseGenerator.java (94%) rename bundles/specmate-testspecification/src/com/specmate/testspecification/internal/{services => generators}/ProcessNodeEvaluation.java (71%) rename bundles/specmate-testspecification/src/com/specmate/testspecification/internal/{services => generators}/ProcessTestCaseGenerator.java (96%) rename bundles/specmate-testspecification/src/com/specmate/testspecification/internal/{services => generators}/TaggedBoolean.java (88%) rename bundles/specmate-testspecification/src/com/specmate/testspecification/internal/{services => generators}/TestCaseGeneratorBase.java (95%) create mode 100644 bundles/specmate-testspecification/src/com/specmate/testspecification/internal/services/TestExportService.java delete mode 100644 bundles/specmate-testspecification/src/com/specmate/testspecification/internal/services/TestSkeletonGeneratorService.java create mode 100644 bundles/specmate-testspecification/test/com/specmate/testspecification/test/TestExportTestProcedure.java rename bundles/specmate-testspecification/test/com/specmate/testspecification/test/{TestSkeletonTest.java => TestExportTestSpecification.java} (73%) delete mode 100644 web/src/app/modules/actions/modules/get-test-specification-skeleton-button/components/get-test-specification-skeleton-button.component.html rename web/src/app/modules/actions/modules/{get-test-specification-skeleton-button/components/get-test-specification-skeleton-button.component.css => test-export-button/components/test-export-button.component.css} (92%) create mode 100644 web/src/app/modules/actions/modules/test-export-button/components/test-export-button.component.html rename web/src/app/modules/actions/modules/{get-test-specification-skeleton-button/components/get-test-specification-skeleton-button.component.ts => test-export-button/components/test-export-button.component.ts} (63%) rename web/src/app/modules/actions/modules/{get-test-specification-skeleton-button/get-test-specification-skeleton-button.module.ts => test-export-button/test-export-button.module.ts} (64%) create mode 100644 web/tsconfig.json diff --git a/bundles/specmate-testspecification/.classpath b/bundles/specmate-testspecification/.classpath index 530cb6920..5e112c302 100644 --- a/bundles/specmate-testspecification/.classpath +++ b/bundles/specmate-testspecification/.classpath @@ -1,7 +1,7 @@ - + diff --git a/bundles/specmate-testspecification/.gitignore b/bundles/specmate-testspecification/.gitignore index 57b341172..94eb59772 100644 --- a/bundles/specmate-testspecification/.gitignore +++ b/bundles/specmate-testspecification/.gitignore @@ -1,2 +1,3 @@ -/bin/ -/generated/ +/bin/ +/generated/ +/bin_test/ diff --git a/bundles/specmate-testspecification/bnd.bnd b/bundles/specmate-testspecification/bnd.bnd index ffd75622b..b8219d885 100644 --- a/bundles/specmate-testspecification/bnd.bnd +++ b/bundles/specmate-testspecification/bnd.bnd @@ -23,4 +23,6 @@ specmate-metrics;version=latest Private-Package: \ com.specmate.testspecification.internal.services,\ - com.specmate.testspecification.internal.testskeleton \ No newline at end of file + com.specmate.testspecification.internal.exporters +-privatepackage: com.specmate.testspecification.internal.generators +Export-Package: com.specmate.testspecification.api \ No newline at end of file diff --git a/bundles/specmate-testspecification/src/com/specmate/testspecification/api/ITestExporter.java b/bundles/specmate-testspecification/src/com/specmate/testspecification/api/ITestExporter.java new file mode 100644 index 000000000..81da03ab3 --- /dev/null +++ b/bundles/specmate-testspecification/src/com/specmate/testspecification/api/ITestExporter.java @@ -0,0 +1,19 @@ +package com.specmate.testspecification.api; + +import com.specmate.model.testspecification.TestSpecificationSkeleton; + +public interface ITestExporter { + + /** getter for language */ + String getLanguage(); + + /** Generates an export for the test specification */ + TestSpecificationSkeleton generate(Object object); + + /** Signals that this exporter can export test specifications */ + boolean canExportTestSpecification(); + + /** Signals that this exporter can export test procedures */ + boolean canExportTestProcedure(); + +} \ No newline at end of file diff --git a/bundles/specmate-testspecification/src/com/specmate/testspecification/api/ITestProcedureExporter.java b/bundles/specmate-testspecification/src/com/specmate/testspecification/api/ITestProcedureExporter.java new file mode 100644 index 000000000..6e1765f5d --- /dev/null +++ b/bundles/specmate-testspecification/src/com/specmate/testspecification/api/ITestProcedureExporter.java @@ -0,0 +1,5 @@ +package com.specmate.testspecification.api; + +public interface ITestProcedureExporter { + +} diff --git a/bundles/specmate-testspecification/src/com/specmate/testspecification/api/packageinfo b/bundles/specmate-testspecification/src/com/specmate/testspecification/api/packageinfo new file mode 100644 index 000000000..60c8a9215 --- /dev/null +++ b/bundles/specmate-testspecification/src/com/specmate/testspecification/api/packageinfo @@ -0,0 +1 @@ +version 1.0.0 diff --git a/bundles/specmate-testspecification/src/com/specmate/testspecification/internal/exporters/CSVTestProcedureExporter.java b/bundles/specmate-testspecification/src/com/specmate/testspecification/internal/exporters/CSVTestProcedureExporter.java new file mode 100644 index 000000000..a812f7eaa --- /dev/null +++ b/bundles/specmate-testspecification/src/com/specmate/testspecification/internal/exporters/CSVTestProcedureExporter.java @@ -0,0 +1,54 @@ +package com.specmate.testspecification.internal.exporters; + +import static com.specmate.testspecification.internal.exporters.ExportUtil.CSV_COL_SEP; +import static com.specmate.testspecification.internal.exporters.ExportUtil.CSV_LINE_SEP; + +import java.util.List; +import java.util.StringJoiner; + +import org.osgi.service.component.annotations.Component; + +import com.specmate.model.support.util.SpecmateEcoreUtil; +import com.specmate.model.testspecification.TestProcedure; +import com.specmate.model.testspecification.TestSpecificationSkeleton; +import com.specmate.model.testspecification.TestStep; +import com.specmate.model.testspecification.TestspecificationFactory; +import com.specmate.testspecification.api.ITestExporter; + +@Component(immediate = true) +public class CSVTestProcedureExporter implements ITestExporter { + private static final String HEADER = "Step Name" + CSV_COL_SEP + "Action" + CSV_COL_SEP + "Expected Outcome"; + + @Override + public boolean canExportTestProcedure() { + return true; + } + + @Override + public boolean canExportTestSpecification() { + return false; + } + + @Override + public String getLanguage() { + return "csv"; + } + + @Override + public TestSpecificationSkeleton generate(Object object) { + TestProcedure testprocedure = (TestProcedure) object; + StringJoiner joiner = new StringJoiner(CSV_LINE_SEP); + joiner.add(HEADER); + List testSteps = SpecmateEcoreUtil.pickInstancesOf(testprocedure.getContents(), TestStep.class); + for (TestStep step : testSteps) { + joiner.add(step.getName() + CSV_COL_SEP + step.getDescription() + CSV_COL_SEP + step.getExpectedOutcome()); + } + TestSpecificationSkeleton skelleton = TestspecificationFactory.eINSTANCE.createTestSpecificationSkeleton(); + skelleton.setName(ExportUtil.replaceInvalidChars(testprocedure.getName()) + ".csv"); + skelleton.setLanguage(getLanguage()); + skelleton.setCode(joiner.toString()); + return skelleton; + + } + +} diff --git a/bundles/specmate-testspecification/src/com/specmate/testspecification/internal/testskeleton/CSVTestSpecificationSkeleton.java b/bundles/specmate-testspecification/src/com/specmate/testspecification/internal/exporters/CSVTestSpecificationExporter.java similarity index 58% rename from bundles/specmate-testspecification/src/com/specmate/testspecification/internal/testskeleton/CSVTestSpecificationSkeleton.java rename to bundles/specmate-testspecification/src/com/specmate/testspecification/internal/exporters/CSVTestSpecificationExporter.java index 4492cd24e..d0de448da 100644 --- a/bundles/specmate-testspecification/src/com/specmate/testspecification/internal/testskeleton/CSVTestSpecificationSkeleton.java +++ b/bundles/specmate-testspecification/src/com/specmate/testspecification/internal/exporters/CSVTestSpecificationExporter.java @@ -1,33 +1,37 @@ -package com.specmate.testspecification.internal.testskeleton; +package com.specmate.testspecification.internal.exporters; + +import static com.specmate.testspecification.internal.exporters.ExportUtil.replaceInvalidChars; import java.util.List; import java.util.StringJoiner; import org.apache.commons.lang3.StringUtils; +import org.osgi.service.component.annotations.Component; import com.specmate.model.testspecification.ParameterAssignment; import com.specmate.model.testspecification.TestCase; import com.specmate.model.testspecification.TestParameter; import com.specmate.model.testspecification.TestSpecification; +import com.specmate.testspecification.api.ITestExporter; -public class CSVTestSpecificationSkeleton extends BaseSkeleton { - - private static final String TEXT_WRAP = "\""; - private static final String COL_SEP = ";"; +/** Exports a test specification as CSV */ +@Component(immediate = true, service = ITestExporter.class) +public class CSVTestSpecificationExporter extends TestSpecificationExporterBase { - public CSVTestSpecificationSkeleton(String language) { - super(language); + public CSVTestSpecificationExporter() { + super("csv"); } @Override protected void generateHeader(StringBuilder sb, TestSpecification testSpecification2, List parameters) { - StringJoiner joiner = new StringJoiner(COL_SEP); + StringJoiner joiner = new StringJoiner(ExportUtil.CSV_COL_SEP); joiner.add("\"TC\""); for (TestParameter param : parameters) { - joiner.add(StringUtils.wrap(param.getType().toString() + " - " + param.getName(), TEXT_WRAP)); + joiner.add( + StringUtils.wrap(param.getType().toString() + " - " + param.getName(), ExportUtil.CSV_TEXT_WRAP)); } - sb.append(joiner).append("\n"); + sb.append(joiner).append(ExportUtil.CSV_LINE_SEP); } @Override @@ -37,22 +41,23 @@ protected void generateFooter(StringBuilder sb, TestSpecification testSpecificat @Override protected void generateTestCaseFooter(StringBuilder sb, TestCase tc) { - sb.append("\n"); + sb.append(ExportUtil.CSV_LINE_SEP); } @Override protected void generateTestCaseHeader(StringBuilder sb, TestSpecification ts, TestCase tc) { - sb.append(tc.getName() + COL_SEP); + sb.append(tc.getName() + ExportUtil.CSV_COL_SEP); } @Override protected void generateTestCaseParameterAssignments(StringBuilder sb, List assignments) { - StringJoiner joiner = new StringJoiner(COL_SEP); + StringJoiner joiner = new StringJoiner(ExportUtil.CSV_COL_SEP); for (ParameterAssignment assignment : assignments) { String assignmentValue = assignment.getCondition(); String characterToEscape = "="; - String escapeString = StringUtils.isEmpty(assignmentValue) ? "" : escapeString(assignmentValue, characterToEscape); - joiner.add(StringUtils.wrap(escapeString + assignmentValue, TEXT_WRAP)); + String escapeString = StringUtils.isEmpty(assignmentValue) ? "" + : escapeString(assignmentValue, characterToEscape); + joiner.add(StringUtils.wrap(escapeString + assignmentValue, ExportUtil.CSV_TEXT_WRAP)); } sb.append(joiner.toString()); } diff --git a/bundles/specmate-testspecification/src/com/specmate/testspecification/internal/exporters/ExportUtil.java b/bundles/specmate-testspecification/src/com/specmate/testspecification/internal/exporters/ExportUtil.java new file mode 100644 index 000000000..41f27f9f7 --- /dev/null +++ b/bundles/specmate-testspecification/src/com/specmate/testspecification/internal/exporters/ExportUtil.java @@ -0,0 +1,27 @@ +package com.specmate.testspecification.internal.exporters; + +import java.util.regex.Pattern; + +/** Utility methods for exporting test specifications and procedures */ +public class ExportUtil { + + /** Char to wrap text fields in */ + public static final String CSV_TEXT_WRAP = "\""; + /** Char to separate columns */ + public static final String CSV_COL_SEP = ";"; + /** Char used for line end */ + public static final String CSV_LINE_SEP = "\n"; + + /** pattern that detects a number at the beginning */ + private static Pattern startsNumerical = Pattern.compile("^[0-9]"); + + /** invalid characters for test names */ + private static Pattern invalidChars = Pattern.compile("[^a-zA-Z_0-9\\_]"); + + /** Replaces potentially invalid characters for names */ + public static String replaceInvalidChars(String name) { + name = startsNumerical.matcher(name).replaceAll(""); + return invalidChars.matcher(name).replaceAll("_"); + } + +} diff --git a/bundles/specmate-testspecification/src/com/specmate/testspecification/internal/testskeleton/JavaTestSpecificationSkeleton.java b/bundles/specmate-testspecification/src/com/specmate/testspecification/internal/exporters/JavaTestSpecificationExporter.java similarity index 75% rename from bundles/specmate-testspecification/src/com/specmate/testspecification/internal/testskeleton/JavaTestSpecificationSkeleton.java rename to bundles/specmate-testspecification/src/com/specmate/testspecification/internal/exporters/JavaTestSpecificationExporter.java index 257112f1b..46f49beb3 100644 --- a/bundles/specmate-testspecification/src/com/specmate/testspecification/internal/testskeleton/JavaTestSpecificationSkeleton.java +++ b/bundles/specmate-testspecification/src/com/specmate/testspecification/internal/exporters/JavaTestSpecificationExporter.java @@ -1,16 +1,23 @@ -package com.specmate.testspecification.internal.testskeleton; +package com.specmate.testspecification.internal.exporters; + +import static com.specmate.testspecification.internal.exporters.ExportUtil.replaceInvalidChars; import java.util.List; +import org.osgi.service.component.annotations.Component; + import com.specmate.model.testspecification.ParameterAssignment; import com.specmate.model.testspecification.TestCase; import com.specmate.model.testspecification.TestParameter; import com.specmate.model.testspecification.TestSpecification; +import com.specmate.testspecification.api.ITestExporter; -public class JavaTestSpecificationSkeleton extends BaseSkeleton { +/** Exports a test specification to java */ +@Component(immediate = true, service = ITestExporter.class) +public class JavaTestSpecificationExporter extends TestSpecificationExporterBase { - public JavaTestSpecificationSkeleton(String language) { - super(language); + public JavaTestSpecificationExporter() { + super("java"); } @Override diff --git a/bundles/specmate-testspecification/src/com/specmate/testspecification/internal/testskeleton/JavascriptTestSpecificationSkeleton.java b/bundles/specmate-testspecification/src/com/specmate/testspecification/internal/exporters/JavascriptTestSpecificationExporter.java similarity index 74% rename from bundles/specmate-testspecification/src/com/specmate/testspecification/internal/testskeleton/JavascriptTestSpecificationSkeleton.java rename to bundles/specmate-testspecification/src/com/specmate/testspecification/internal/exporters/JavascriptTestSpecificationExporter.java index a0f185ee6..1a3f8c52a 100644 --- a/bundles/specmate-testspecification/src/com/specmate/testspecification/internal/testskeleton/JavascriptTestSpecificationSkeleton.java +++ b/bundles/specmate-testspecification/src/com/specmate/testspecification/internal/exporters/JavascriptTestSpecificationExporter.java @@ -1,16 +1,23 @@ -package com.specmate.testspecification.internal.testskeleton; +package com.specmate.testspecification.internal.exporters; + +import static com.specmate.testspecification.internal.exporters.ExportUtil.replaceInvalidChars; import java.util.List; +import org.osgi.service.component.annotations.Component; + import com.specmate.model.testspecification.ParameterAssignment; import com.specmate.model.testspecification.TestCase; import com.specmate.model.testspecification.TestParameter; import com.specmate.model.testspecification.TestSpecification; +import com.specmate.testspecification.api.ITestExporter; -public class JavascriptTestSpecificationSkeleton extends BaseSkeleton { +/** Exports a test specification to javascript */ +@Component(immediate = true, service = ITestExporter.class) +public class JavascriptTestSpecificationExporter extends TestSpecificationExporterBase { - public JavascriptTestSpecificationSkeleton(String language) { - super(language); + public JavascriptTestSpecificationExporter() { + super("javascript"); } @Override diff --git a/bundles/specmate-testspecification/src/com/specmate/testspecification/internal/testskeleton/BaseSkeleton.java b/bundles/specmate-testspecification/src/com/specmate/testspecification/internal/exporters/TestSpecificationExporterBase.java similarity index 81% rename from bundles/specmate-testspecification/src/com/specmate/testspecification/internal/testskeleton/BaseSkeleton.java rename to bundles/specmate-testspecification/src/com/specmate/testspecification/internal/exporters/TestSpecificationExporterBase.java index 536265301..0e031e586 100644 --- a/bundles/specmate-testspecification/src/com/specmate/testspecification/internal/testskeleton/BaseSkeleton.java +++ b/bundles/specmate-testspecification/src/com/specmate/testspecification/internal/exporters/TestSpecificationExporterBase.java @@ -1,10 +1,11 @@ -package com.specmate.testspecification.internal.testskeleton; +package com.specmate.testspecification.internal.exporters; + +import static com.specmate.testspecification.internal.exporters.ExportUtil.replaceInvalidChars; import java.text.SimpleDateFormat; import java.util.Comparator; import java.util.Date; import java.util.List; -import java.util.regex.Pattern; import java.util.stream.Collectors; import com.specmate.model.support.util.SpecmateEcoreUtil; @@ -14,28 +15,43 @@ import com.specmate.model.testspecification.TestSpecification; import com.specmate.model.testspecification.TestSpecificationSkeleton; import com.specmate.model.testspecification.TestspecificationFactory; +import com.specmate.testspecification.api.ITestExporter; /** Base class for Test Specification Exporters (aka "Skeletons") */ -public abstract class BaseSkeleton { +public abstract class TestSpecificationExporterBase implements ITestExporter { + /** the language for the export */ protected String language; - private static Pattern startsNumerical = Pattern.compile("^[0-9]"); - private static Pattern invalidChars = Pattern.compile("[^a-zA-Z_0-9\\_]"); - Comparator parameterComparator = (p1, p2) -> compareParameter(p1, p2); Comparator assignmentComparator = (a1, a2) -> compareParameter(a1.getParameter(), a2.getParameter()); - public BaseSkeleton(String language) { + /** constructor */ + public TestSpecificationExporterBase(String language) { this.language = language; } - private static int compareParameter(TestParameter p1, TestParameter p2) { - return p1.getType().compareTo(p2.getType()) * 10 + Integer.signum(p1.getName().compareTo(p2.getName())); + /** getter for language */ + @Override + public String getLanguage() { + return language; + } + + @Override + public boolean canExportTestProcedure() { + return false; + } + + @Override + public boolean canExportTestSpecification() { + return true; } - public TestSpecificationSkeleton generate(TestSpecification testSpecification) { + /** Generates an export for the test specification */ + @Override + public TestSpecificationSkeleton generate(Object obj) { + TestSpecification testSpecification = (TestSpecification) obj; StringBuilder sb = new StringBuilder(); TestSpecificationSkeleton tss = TestspecificationFactory.eINSTANCE.createTestSpecificationSkeleton(); @@ -57,6 +73,10 @@ public TestSpecificationSkeleton generate(TestSpecification testSpecification) { return tss; } + private static int compareParameter(TestParameter p1, TestParameter p2) { + return p1.getType().compareTo(p2.getType()) * 10 + Integer.signum(p1.getName().compareTo(p2.getName())); + } + /** * Return Test parameter assignments sorted by type (input before output) */ @@ -75,11 +95,6 @@ private List getTestCases(TestSpecification testSpecification) { return SpecmateEcoreUtil.pickInstancesOf(testSpecification.getContents(), TestCase.class); } - protected String replaceInvalidChars(String name) { - name = startsNumerical.matcher(name).replaceAll(""); - return invalidChars.matcher(name).replaceAll("_"); - } - protected void appendParameterValue(StringBuilder sb, ParameterAssignment pa) { sb.append("___"); sb.append(replaceInvalidChars(pa.getParameter().getName())); diff --git a/bundles/specmate-testspecification/src/com/specmate/testspecification/internal/services/CEGNodeEvaluation.java b/bundles/specmate-testspecification/src/com/specmate/testspecification/internal/generators/CEGNodeEvaluation.java similarity index 84% rename from bundles/specmate-testspecification/src/com/specmate/testspecification/internal/services/CEGNodeEvaluation.java rename to bundles/specmate-testspecification/src/com/specmate/testspecification/internal/generators/CEGNodeEvaluation.java index ebbdffa72..bceba4035 100644 --- a/bundles/specmate-testspecification/src/com/specmate/testspecification/internal/services/CEGNodeEvaluation.java +++ b/bundles/specmate-testspecification/src/com/specmate/testspecification/internal/generators/CEGNodeEvaluation.java @@ -1,8 +1,9 @@ -package com.specmate.testspecification.internal.services; +package com.specmate.testspecification.internal.generators; import java.util.Comparator; import java.util.TreeMap; +import com.specmate.model.base.IContainer; import com.specmate.model.requirements.CEGNode; @SuppressWarnings("serial") diff --git a/bundles/specmate-testspecification/src/com/specmate/testspecification/internal/services/CEGNodeEvaluationComparator.java b/bundles/specmate-testspecification/src/com/specmate/testspecification/internal/generators/CEGNodeEvaluationComparator.java similarity index 67% rename from bundles/specmate-testspecification/src/com/specmate/testspecification/internal/services/CEGNodeEvaluationComparator.java rename to bundles/specmate-testspecification/src/com/specmate/testspecification/internal/generators/CEGNodeEvaluationComparator.java index fef29deed..d02bd2888 100644 --- a/bundles/specmate-testspecification/src/com/specmate/testspecification/internal/services/CEGNodeEvaluationComparator.java +++ b/bundles/specmate-testspecification/src/com/specmate/testspecification/internal/generators/CEGNodeEvaluationComparator.java @@ -1,14 +1,15 @@ -package com.specmate.testspecification.internal.services; +package com.specmate.testspecification.internal.generators; import java.util.Comparator; import java.util.Iterator; -import java.util.Map.Entry; import java.util.Set; +import java.util.Map.Entry; +import com.specmate.model.base.IContainer; import com.specmate.model.requirements.CEGNode; public class CEGNodeEvaluationComparator implements Comparator { - + @Override public int compare(CEGNodeEvaluation nodeEval1, CEGNodeEvaluation nodeEval2) { Set> sortedNodeSet1 = nodeEval1.entrySet(); @@ -24,11 +25,13 @@ public int compare(CEGNodeEvaluation nodeEval1, CEGNodeEvaluation nodeEval2) { CEGNode node2 = sortedNodeSetEntry2.getKey(); /* - * Compare properties of both evaluations until they differ Check order: 1. - * Compare names of nodes 2. Compare conditions of nodes 3. Compare - * taggedBoolean value property of nodes 4. Compare taggedBoolean tag property - * of nodes - */ + * Compare properties of both evaluations until they differ + * Check order: + * 1. Compare names of nodes + * 2. Compare conditions of nodes + * 3. Compare taggedBoolean value property of nodes + * 4. Compare taggedBoolean tag property of nodes + * */ int result = node1.getVariable().compareTo(node2.getVariable()); if (result != 0) { return result; @@ -37,20 +40,22 @@ public int compare(CEGNodeEvaluation nodeEval1, CEGNodeEvaluation nodeEval2) { int conditionResult = node1.getCondition().compareTo(node2.getCondition()); if (conditionResult != 0) { return conditionResult; - } + } - /* - * Check if the taggedBoolean values are also equal Order: false < true + /* + * Check if the taggedBoolean values are also equal + * Order: false < true */ TaggedBoolean taggedBoolean1 = sortedNodeSetEntry1.getValue(); TaggedBoolean taggedBoolean2 = sortedNodeSetEntry2.getValue(); int boolResult = Boolean.compare(taggedBoolean1.value, taggedBoolean2.value); if (boolResult != 0) { return boolResult; - } + } /* - * Values are also equal, check if the tags are equal Order: all < any < auto + * Values are also equal, check if the tags are equal + * Order: all < any < auto */ int tagResult = taggedBoolean1.tag.compareTo(taggedBoolean2.tag); if (tagResult != 0) { @@ -58,21 +63,21 @@ public int compare(CEGNodeEvaluation nodeEval1, CEGNodeEvaluation nodeEval2) { } } /* - * Both or one of the sets has come to an end Either one set of evaluation is a - * subset of the other, or they are the same + * Both or one of the sets has come to an end + * Either one set of evaluation is a subset of the other, or they are the same */ if (!it1.hasNext() && !it2.hasNext()) { /* - * Both sets are the same Even if the current test generation heuristic does not - * create two sets which are the same, we still need this in order to delete - * evaluations from the set - */ + * Both sets are the same + * Even if the current test generation heuristic does not create two sets which are the same, + * we still need this in order to delete evaluations from the set + */ return 0; - } + } if (!it1.hasNext()) { // set1 is smaller, set nodeEval1 < nodeEval2 return -1; - } + } // set2 is smaller, set nodeEval2 < nodeEval1 return 1; } diff --git a/bundles/specmate-testspecification/src/com/specmate/testspecification/internal/services/CEGTestCaseGenerator.java b/bundles/specmate-testspecification/src/com/specmate/testspecification/internal/generators/CEGTestCaseGenerator.java similarity index 94% rename from bundles/specmate-testspecification/src/com/specmate/testspecification/internal/services/CEGTestCaseGenerator.java rename to bundles/specmate-testspecification/src/com/specmate/testspecification/internal/generators/CEGTestCaseGenerator.java index b085936e7..4be794927 100644 --- a/bundles/specmate-testspecification/src/com/specmate/testspecification/internal/services/CEGTestCaseGenerator.java +++ b/bundles/specmate-testspecification/src/com/specmate/testspecification/internal/generators/CEGTestCaseGenerator.java @@ -1,4 +1,4 @@ -package com.specmate.testspecification.internal.services; +package com.specmate.testspecification.internal.generators; import java.util.ArrayList; import java.util.Collection; @@ -51,10 +51,10 @@ import com.specmate.model.testspecification.TestParameter; import com.specmate.model.testspecification.TestSpecification; import com.specmate.model.testspecification.TestspecificationFactory; -import com.specmate.testspecification.internal.services.TaggedBoolean.ETag; +import com.specmate.testspecification.internal.generators.TaggedBoolean.ETag; public class CEGTestCaseGenerator extends TestCaseGeneratorBase { - + private Comparator nodeEvalSetComparator; public CEGTestCaseGenerator(TestSpecification specification) { @@ -133,13 +133,13 @@ protected void generateTestCases() throws SpecmateException { } /** Creates a test case for a single node evaluation. */ - private TestCase createTestCase(CEGNodeEvaluation evaluation, TestSpecification specification, - boolean isConsistent) { + private TestCase createTestCase(CEGNodeEvaluation evaluation, TestSpecification specification, boolean isConsistent) { TestCase testCase = super.createTestCase(specification); testCase.setConsistent(isConsistent); List parameters = SpecmateEcoreUtil.pickInstancesOf(specification.getContents(), TestParameter.class); - + Multimap variableToNodeMap = ArrayListMultimap.create(); + evaluation.keySet().stream().forEach(n -> variableToNodeMap.put(((CEGNode) n).getVariable(), n)); for (TestParameter parameter : parameters) { List constraints = new ArrayList<>(); Collection relevantNodes = getRelevantNodes(evaluation, parameter.getName()); @@ -207,8 +207,8 @@ private String negateCondition(String condition) { * @return * @throws SpecmateException */ - private Pair, SortedSet> computeEvaluations() - throws SpecmateException { + private Pair, SortedSet> computeEvaluations() throws SpecmateException { + // TODO: fix ordering, SortedSet instead of Set SortedSet consistentEvaluations = getInitialEvaluations(); SortedSet inconsistentEvaluations = new TreeSet(nodeEvalSetComparator); SortedSet intermediateEvaluations = getIntermediateEvaluations(consistentEvaluations); @@ -260,16 +260,16 @@ private SortedSet getInitialEvaluations() { CEGNodeEvaluation negativeEvaluation = new CEGNodeEvaluation(); negativeEvaluation.put(cegNode, new TaggedBoolean(false, TaggedBoolean.ETag.ALL)); evaluations.add(negativeEvaluation); - }); + }); return evaluations; } - + /** - * Initializes a comparator which defines the ordering of the SortedSets + * Initializes a comparator which defines the ordering of the SortedSets * containing the different evaluations */ - private void initComparator() { - nodeEvalSetComparator = new CEGNodeEvaluationComparator(); + private void initComparator () { + nodeEvalSetComparator = new CEGNodeEvaluationComparator (); } /** Retrieves a node that has predecessors with out a set value */ @@ -409,8 +409,7 @@ private Pair, SortedSet> mergeCo return Pair.of(result, new TreeSet<>(nodeEvalSetComparator)); } - private SortedSet getMergeCandiate(SortedSet evaluations) - throws SpecmateException { + private SortedSet getMergeCandiate(SortedSet evaluations) throws SpecmateException { // Map to track between logical variables and evaluations TreeMap var2EvalMap = new TreeMap( new Comparator() { diff --git a/bundles/specmate-testspecification/src/com/specmate/testspecification/internal/services/ProcessNodeEvaluation.java b/bundles/specmate-testspecification/src/com/specmate/testspecification/internal/generators/ProcessNodeEvaluation.java similarity index 71% rename from bundles/specmate-testspecification/src/com/specmate/testspecification/internal/services/ProcessNodeEvaluation.java rename to bundles/specmate-testspecification/src/com/specmate/testspecification/internal/generators/ProcessNodeEvaluation.java index c65d8a5e8..71fdb95cc 100644 --- a/bundles/specmate-testspecification/src/com/specmate/testspecification/internal/services/ProcessNodeEvaluation.java +++ b/bundles/specmate-testspecification/src/com/specmate/testspecification/internal/generators/ProcessNodeEvaluation.java @@ -1,4 +1,4 @@ -package com.specmate.testspecification.internal.services; +package com.specmate.testspecification.internal.generators; import java.util.HashMap; diff --git a/bundles/specmate-testspecification/src/com/specmate/testspecification/internal/services/ProcessTestCaseGenerator.java b/bundles/specmate-testspecification/src/com/specmate/testspecification/internal/generators/ProcessTestCaseGenerator.java similarity index 96% rename from bundles/specmate-testspecification/src/com/specmate/testspecification/internal/services/ProcessTestCaseGenerator.java rename to bundles/specmate-testspecification/src/com/specmate/testspecification/internal/generators/ProcessTestCaseGenerator.java index 8bb62004d..2bd937ceb 100644 --- a/bundles/specmate-testspecification/src/com/specmate/testspecification/internal/services/ProcessTestCaseGenerator.java +++ b/bundles/specmate-testspecification/src/com/specmate/testspecification/internal/generators/ProcessTestCaseGenerator.java @@ -1,4 +1,4 @@ -package com.specmate.testspecification.internal.services; +package com.specmate.testspecification.internal.generators; import java.util.ArrayList; import java.util.HashMap; @@ -38,7 +38,7 @@ import com.specmate.model.testspecification.TestSpecification; import com.specmate.model.testspecification.TestStep; import com.specmate.model.testspecification.TestspecificationFactory; -import com.specmate.testspecification.internal.services.TaggedBoolean.ETag; +import com.specmate.testspecification.internal.generators.TaggedBoolean.ETag; public class ProcessTestCaseGenerator extends TestCaseGeneratorBase { diff --git a/bundles/specmate-testspecification/src/com/specmate/testspecification/internal/services/TaggedBoolean.java b/bundles/specmate-testspecification/src/com/specmate/testspecification/internal/generators/TaggedBoolean.java similarity index 88% rename from bundles/specmate-testspecification/src/com/specmate/testspecification/internal/services/TaggedBoolean.java rename to bundles/specmate-testspecification/src/com/specmate/testspecification/internal/generators/TaggedBoolean.java index b4b55971c..539fc9c5f 100644 --- a/bundles/specmate-testspecification/src/com/specmate/testspecification/internal/services/TaggedBoolean.java +++ b/bundles/specmate-testspecification/src/com/specmate/testspecification/internal/generators/TaggedBoolean.java @@ -1,4 +1,4 @@ -package com.specmate.testspecification.internal.services; +package com.specmate.testspecification.internal.generators; class TaggedBoolean { diff --git a/bundles/specmate-testspecification/src/com/specmate/testspecification/internal/services/TestCaseGeneratorBase.java b/bundles/specmate-testspecification/src/com/specmate/testspecification/internal/generators/TestCaseGeneratorBase.java similarity index 95% rename from bundles/specmate-testspecification/src/com/specmate/testspecification/internal/services/TestCaseGeneratorBase.java rename to bundles/specmate-testspecification/src/com/specmate/testspecification/internal/generators/TestCaseGeneratorBase.java index a254f97d0..0621e96b3 100644 --- a/bundles/specmate-testspecification/src/com/specmate/testspecification/internal/services/TestCaseGeneratorBase.java +++ b/bundles/specmate-testspecification/src/com/specmate/testspecification/internal/generators/TestCaseGeneratorBase.java @@ -1,4 +1,4 @@ -package com.specmate.testspecification.internal.services; +package com.specmate.testspecification.internal.generators; import java.util.List; import com.specmate.common.AssertUtil; diff --git a/bundles/specmate-testspecification/src/com/specmate/testspecification/internal/services/TestExportService.java b/bundles/specmate-testspecification/src/com/specmate/testspecification/internal/services/TestExportService.java new file mode 100644 index 000000000..936b703de --- /dev/null +++ b/bundles/specmate-testspecification/src/com/specmate/testspecification/internal/services/TestExportService.java @@ -0,0 +1,108 @@ +package com.specmate.testspecification.internal.services; + +import java.util.HashMap; +import java.util.Map; + +import javax.ws.rs.core.MultivaluedMap; +import javax.ws.rs.core.Response; + +import org.osgi.service.component.annotations.Activate; +import org.osgi.service.component.annotations.Component; +import org.osgi.service.component.annotations.Reference; +import org.osgi.service.component.annotations.ReferenceCardinality; +import org.osgi.service.component.annotations.ReferencePolicy; +import org.osgi.service.log.LogService; + +import com.specmate.common.exception.SpecmateException; +import com.specmate.common.exception.SpecmateValidationException; +import com.specmate.emfrest.api.IRestService; +import com.specmate.emfrest.api.RestServiceBase; +import com.specmate.metrics.ICounter; +import com.specmate.metrics.IMetricsService; +import com.specmate.model.testspecification.TestProcedure; +import com.specmate.model.testspecification.TestSpecification; +import com.specmate.model.testspecification.TestSpecificationSkeleton; +import com.specmate.rest.RestResult; +import com.specmate.testspecification.api.ITestExporter; + +/** Service that exports a test specification in various formats */ +@Component(immediate = true, service = IRestService.class) +public class TestExportService extends RestServiceBase { + private final String LANGUAGE_PARAM = "language"; + private Map testSpecificationExporters = new HashMap(); + private Map testProcedureExporters = new HashMap(); + private IMetricsService metricsService; + private ICounter exportCounter; + private LogService logService; + + @Activate + public void activate() throws SpecmateException { + exportCounter = metricsService.createCounter("export_counter", "Total number of exported test specifications"); + } + + @Override + public String getServiceName() { + return "export"; + } + + @Override + public boolean canGet(Object object) { + return (object instanceof TestSpecification) || (object instanceof TestProcedure); + } + + @Override + public RestResult get(Object object, MultivaluedMap queryParams, String token) + throws SpecmateException { + + String language = queryParams.getFirst(LANGUAGE_PARAM); + if (language == null) { + throw new SpecmateValidationException("Language for export not specified."); + } + ITestExporter generator = null; + if (object instanceof TestSpecification) { + generator = testSpecificationExporters.get(language); + } else if (object instanceof TestProcedure) { + generator = testProcedureExporters.get(language); + } + if (generator == null) { + throw new SpecmateValidationException("Generator for langauge " + language + " does not exist."); + } + exportCounter.inc(); + return new RestResult(Response.Status.OK, generator.generate(object)); + } + + @Reference + public void setMetricsService(IMetricsService metricsService) { + this.metricsService = metricsService; + } + + @Reference + public void setLogService(LogService logService) { + this.logService = logService; + } + + @Reference(cardinality = ReferenceCardinality.MULTIPLE, policy = ReferencePolicy.DYNAMIC) + public void addTestSpecificationExporter(ITestExporter exporter) { + if (exporter.canExportTestProcedure()) { + addToExporterCollection(exporter, testProcedureExporters); + } + if (exporter.canExportTestSpecification()) { + addToExporterCollection(exporter, testSpecificationExporters); + } + } + + public void removeTestSpecificationExporter(ITestExporter exporter) { + ITestExporter existing = testSpecificationExporters.get(exporter.getLanguage()); + if (existing == exporter) { + testSpecificationExporters.remove(exporter.getLanguage()); + } + } + + private void addToExporterCollection(ITestExporter exporter, Map exporterMap) { + if (exporterMap.containsKey(exporter.getLanguage())) { + logService.log(LogService.LOG_WARNING, "Test exporter for langugae " + exporter.getLanguage() + + " already exists. Ignoring: " + exporter.getClass().getName()); + } + exporterMap.put(exporter.getLanguage(), exporter); + } +} diff --git a/bundles/specmate-testspecification/src/com/specmate/testspecification/internal/services/TestGeneratorService.java b/bundles/specmate-testspecification/src/com/specmate/testspecification/internal/services/TestGeneratorService.java index b2ec7dfd3..9df82b1af 100644 --- a/bundles/specmate-testspecification/src/com/specmate/testspecification/internal/services/TestGeneratorService.java +++ b/bundles/specmate-testspecification/src/com/specmate/testspecification/internal/services/TestGeneratorService.java @@ -18,6 +18,8 @@ import com.specmate.model.requirements.CEGModel; import com.specmate.model.testspecification.TestSpecification; import com.specmate.rest.RestResult; +import com.specmate.testspecification.internal.generators.CEGTestCaseGenerator; +import com.specmate.testspecification.internal.generators.ProcessTestCaseGenerator; /** * Service for generating test cases for a test specification that is linked to diff --git a/bundles/specmate-testspecification/src/com/specmate/testspecification/internal/services/TestSkeletonGeneratorService.java b/bundles/specmate-testspecification/src/com/specmate/testspecification/internal/services/TestSkeletonGeneratorService.java deleted file mode 100644 index 0903f195c..000000000 --- a/bundles/specmate-testspecification/src/com/specmate/testspecification/internal/services/TestSkeletonGeneratorService.java +++ /dev/null @@ -1,86 +0,0 @@ -package com.specmate.testspecification.internal.services; - -import java.util.HashMap; -import java.util.Map; - -import javax.ws.rs.core.MultivaluedMap; -import javax.ws.rs.core.Response; - -import org.osgi.service.component.annotations.Activate; -import org.osgi.service.component.annotations.Component; -import org.osgi.service.component.annotations.Reference; - -import com.specmate.common.exception.SpecmateException; -import com.specmate.common.exception.SpecmateValidationException; -import com.specmate.emfrest.api.IRestService; -import com.specmate.emfrest.api.RestServiceBase; -import com.specmate.metrics.ICounter; -import com.specmate.metrics.IMetricsService; -import com.specmate.model.testspecification.TestSpecification; -import com.specmate.model.testspecification.TestSpecificationSkeleton; -import com.specmate.rest.RestResult; -import com.specmate.testspecification.internal.testskeleton.BaseSkeleton; -import com.specmate.testspecification.internal.testskeleton.CSVTestSpecificationSkeleton; -import com.specmate.testspecification.internal.testskeleton.JavaTestSpecificationSkeleton; -import com.specmate.testspecification.internal.testskeleton.JavascriptTestSpecificationSkeleton; - -@Component(immediate = true, service = IRestService.class) -public class TestSkeletonGeneratorService extends RestServiceBase { - private final String LPARAM = "language"; - private final String JAVA = "java"; - private final String JAVASCRIPT = "javascript"; - private final String CSV = "csv"; - private Map skeletonGenerators; - private IMetricsService metricsService; - private ICounter exportCounter; - - @Activate - public void activate() throws SpecmateException { - this.skeletonGenerators = new HashMap<>(); - this.skeletonGenerators.put(this.JAVA, new JavaTestSpecificationSkeleton(this.JAVA)); - this.skeletonGenerators.put(this.JAVASCRIPT, new JavascriptTestSpecificationSkeleton(this.JAVASCRIPT)); - this.skeletonGenerators.put(this.CSV, new CSVTestSpecificationSkeleton(this.CSV)); - this.exportCounter = metricsService.createCounter("export_counter", "Total number of exported test specifications"); - } - - @Override - public String getServiceName() { - return "generateTestSkeleton"; - } - - @Override - public boolean canGet(Object object) { - return object instanceof TestSpecification; - } - - @Override - public RestResult get(Object object, MultivaluedMap queryParams, String token) - throws SpecmateException { - - String language = queryParams.getFirst(this.LPARAM); - if (language == null) { - throw new SpecmateValidationException("Language for test skeleton not specified."); - } - - BaseSkeleton generator = this.skeletonGenerators.get(language); - if (generator == null) { - throw new SpecmateValidationException("Generator for langauge " + language + " does not exist."); - } - - if (!(object instanceof TestSpecification)) { - throw new SpecmateValidationException( - "Cannot generate test skeleton for object of type " + object.getClass().getName()); - } - - TestSpecification ts = (TestSpecification) object; - - this.exportCounter.inc(); - - return new RestResult(Response.Status.OK, generator.generate(ts)); - } - - @Reference - public void setMetricsService(IMetricsService metricsService) { - this.metricsService = metricsService; - } -} diff --git a/bundles/specmate-testspecification/test/com/specmate/testspecification/test/CEGTestGenerationTest.java b/bundles/specmate-testspecification/test/com/specmate/testspecification/test/CEGTestGenerationTest.java index d82043161..7c4b55364 100644 --- a/bundles/specmate-testspecification/test/com/specmate/testspecification/test/CEGTestGenerationTest.java +++ b/bundles/specmate-testspecification/test/com/specmate/testspecification/test/CEGTestGenerationTest.java @@ -16,7 +16,7 @@ import com.specmate.model.testspecification.TestCase; import com.specmate.model.testspecification.TestSpecification; import com.specmate.model.testspecification.TestspecificationFactory; -import com.specmate.testspecification.internal.services.CEGTestCaseGenerator; +import com.specmate.testspecification.internal.generators.CEGTestCaseGenerator; public class CEGTestGenerationTest { diff --git a/bundles/specmate-testspecification/test/com/specmate/testspecification/test/TestExportTestProcedure.java b/bundles/specmate-testspecification/test/com/specmate/testspecification/test/TestExportTestProcedure.java new file mode 100644 index 000000000..7a65dc742 --- /dev/null +++ b/bundles/specmate-testspecification/test/com/specmate/testspecification/test/TestExportTestProcedure.java @@ -0,0 +1,57 @@ +package com.specmate.testspecification.test; + +import org.junit.Assert; +import org.junit.Test; + +import com.specmate.model.testspecification.TestProcedure; +import com.specmate.model.testspecification.TestSpecificationSkeleton; +import com.specmate.model.testspecification.TestStep; +import com.specmate.model.testspecification.TestspecificationFactory; +import com.specmate.testspecification.internal.exporters.CSVTestProcedureExporter; + +public class TestExportTestProcedure { + + @Test + public void testCSVExport_FilledTestProcedure() { + TestProcedure tp = getTestProcedure(); + + CSVTestProcedureExporter exporter = new CSVTestProcedureExporter(); + TestSpecificationSkeleton result = exporter.generate(tp); + String code = result.getCode(); + Assert.assertEquals("Step Name;Action;Expected Outcome\n" + "step-1;Description1;Outcome1\n" + + "step-2;Description2;Outcome2", code); + } + + @Test + public void testCSVExport_EmptyTestProcedure() { + TestProcedure tp = getTestProcedure(); + tp.getContents().clear(); + CSVTestProcedureExporter exporter = new CSVTestProcedureExporter(); + TestSpecificationSkeleton result = exporter.generate(tp); + String code = result.getCode(); + Assert.assertEquals("Step Name;Action;Expected Outcome", code); + } + + private TestProcedure getTestProcedure() { + TestspecificationFactory f = TestspecificationFactory.eINSTANCE; + TestProcedure tp = f.createTestProcedure(); + tp.setId("tp-id-1"); + tp.setName("TP"); + + TestStep step1 = f.createTestStep(); + step1.setId("step-id-2"); + step1.setName("step-1"); + step1.setDescription("Description1"); + step1.setExpectedOutcome("Outcome1"); + tp.getContents().add(step1); + + TestStep step2 = f.createTestStep(); + step2.setId("step-id-3"); + step2.setName("step-2"); + step2.setDescription("Description2"); + step2.setExpectedOutcome("Outcome2"); + tp.getContents().add(step2); + + return tp; + } +} \ No newline at end of file diff --git a/bundles/specmate-testspecification/test/com/specmate/testspecification/test/TestSkeletonTest.java b/bundles/specmate-testspecification/test/com/specmate/testspecification/test/TestExportTestSpecification.java similarity index 73% rename from bundles/specmate-testspecification/test/com/specmate/testspecification/test/TestSkeletonTest.java rename to bundles/specmate-testspecification/test/com/specmate/testspecification/test/TestExportTestSpecification.java index e44ff58c5..64a953066 100644 --- a/bundles/specmate-testspecification/test/com/specmate/testspecification/test/TestSkeletonTest.java +++ b/bundles/specmate-testspecification/test/com/specmate/testspecification/test/TestExportTestSpecification.java @@ -12,30 +12,45 @@ import com.specmate.model.testspecification.TestSpecification; import com.specmate.model.testspecification.TestSpecificationSkeleton; import com.specmate.model.testspecification.TestspecificationFactory; -import com.specmate.testspecification.internal.testskeleton.CSVTestSpecificationSkeleton; -import com.specmate.testspecification.internal.testskeleton.JavaTestSpecificationSkeleton; +import com.specmate.testspecification.internal.exporters.CSVTestSpecificationExporter; +import com.specmate.testspecification.internal.exporters.JavaTestSpecificationExporter; +import com.specmate.testspecification.internal.exporters.JavascriptTestSpecificationExporter; -public class TestSkeletonTest { +public class TestExportTestSpecification { @Test - public void testJavaSkeleton() { + public void testJavaExport() { TestSpecification ts = getTestSpecification(); - JavaTestSpecificationSkeleton skel = new JavaTestSpecificationSkeleton("JAVA"); + JavaTestSpecificationExporter skel = new JavaTestSpecificationExporter(); TestSpecificationSkeleton result = skel.generate(ts); String code = result.getCode(); Assert.assertTrue(code.contains("public void TSTest___in1__in11___in2_____out1__out11___out2__out12()")); Assert.assertTrue(code.contains("public void TSTest___in1__in21___in2__in22___out1__out21___out2__out22()")); } - + + @Test + public void testJavascriptExport() { + TestSpecification ts = getTestSpecification(); + + JavascriptTestSpecificationExporter skel = new JavascriptTestSpecificationExporter(); + TestSpecificationSkeleton result = skel.generate(ts); + String code = result.getCode(); + + Assert.assertTrue(code.contains(" it('TS___in1__in11___in2_____out1__out11___out2__out12', () => {\n" + + " throw new Error('not implemented yet');\n" + " });")); + Assert.assertTrue(code.contains("it('TS___in1__in21___in2__in22___out1__out21___out2__out22', () => {\n" + + " throw new Error('not implemented yet');\n" + " });")); + } + @Test - public void testCSVSkeleton() { + public void testCSVExport() { TestSpecification ts = getTestSpecification(); - CSVTestSpecificationSkeleton skel = new CSVTestSpecificationSkeleton("CSV"); + CSVTestSpecificationExporter skel = new CSVTestSpecificationExporter(); TestSpecificationSkeleton result = skel.generate(ts); String code = result.getCode(); - + Assert.assertTrue(code.contains("\"TC\";\"INPUT - in1\";\"INPUT - in2\";\"OUTPUT - out1\";\"OUTPUT - out2\"")); Assert.assertTrue(code.contains("tc1;\"in11\";;\"out11\";\"out12\"")); Assert.assertTrue(code.contains("tc2;\"in21\";\"in22\";\"out21\";\"out22\"")); @@ -77,7 +92,7 @@ private TestSpecification getTestSpecification() { assIn11.setParameter(input1); assIn11.setCondition("in11"); - //empty input assignment + // empty input assignment ParameterAssignment assIn12 = f.createParameterAssignment(); assIn12.setParameter(input2); assIn12.setCondition(""); diff --git a/web/src/app/modules/actions/modules/export-testprocedure-button/components/export-testprocedure-button.component.css b/web/src/app/modules/actions/modules/export-testprocedure-button/components/export-testprocedure-button.component.css index e69de29bb..32dfd52bc 100644 --- a/web/src/app/modules/actions/modules/export-testprocedure-button/components/export-testprocedure-button.component.css +++ b/web/src/app/modules/actions/modules/export-testprocedure-button/components/export-testprocedure-button.component.css @@ -0,0 +1,4 @@ +.btn.btn-link { + padding: 0px; + margin: 0px; +} \ No newline at end of file diff --git a/web/src/app/modules/actions/modules/export-testprocedure-button/components/export-testprocedure-button.component.html b/web/src/app/modules/actions/modules/export-testprocedure-button/components/export-testprocedure-button.component.html index bad22b1e9..fdbef54bc 100644 --- a/web/src/app/modules/actions/modules/export-testprocedure-button/components/export-testprocedure-button.component.html +++ b/web/src/app/modules/actions/modules/export-testprocedure-button/components/export-testprocedure-button.component.html @@ -1,4 +1,2 @@ -
- -
\ No newline at end of file + diff --git a/web/src/app/modules/actions/modules/get-test-specification-skeleton-button/components/get-test-specification-skeleton-button.component.html b/web/src/app/modules/actions/modules/get-test-specification-skeleton-button/components/get-test-specification-skeleton-button.component.html deleted file mode 100644 index 314a1d8fb..000000000 --- a/web/src/app/modules/actions/modules/get-test-specification-skeleton-button/components/get-test-specification-skeleton-button.component.html +++ /dev/null @@ -1,3 +0,0 @@ -
- -
\ No newline at end of file diff --git a/web/src/app/modules/actions/modules/get-test-specification-skeleton-button/components/get-test-specification-skeleton-button.component.css b/web/src/app/modules/actions/modules/test-export-button/components/test-export-button.component.css similarity index 92% rename from web/src/app/modules/actions/modules/get-test-specification-skeleton-button/components/get-test-specification-skeleton-button.component.css rename to web/src/app/modules/actions/modules/test-export-button/components/test-export-button.component.css index 4311c5e7a..58a9132d5 100644 --- a/web/src/app/modules/actions/modules/get-test-specification-skeleton-button/components/get-test-specification-skeleton-button.component.css +++ b/web/src/app/modules/actions/modules/test-export-button/components/test-export-button.component.css @@ -1,4 +1,4 @@ -.btn.btn-link { - padding: 0px; - margin: 0px; -} +.btn.btn-link { + padding: 0px; + margin: 0px; +} diff --git a/web/src/app/modules/actions/modules/test-export-button/components/test-export-button.component.html b/web/src/app/modules/actions/modules/test-export-button/components/test-export-button.component.html new file mode 100644 index 000000000..fe03a5660 --- /dev/null +++ b/web/src/app/modules/actions/modules/test-export-button/components/test-export-button.component.html @@ -0,0 +1 @@ + diff --git a/web/src/app/modules/actions/modules/get-test-specification-skeleton-button/components/get-test-specification-skeleton-button.component.ts b/web/src/app/modules/actions/modules/test-export-button/components/test-export-button.component.ts similarity index 63% rename from web/src/app/modules/actions/modules/get-test-specification-skeleton-button/components/get-test-specification-skeleton-button.component.ts rename to web/src/app/modules/actions/modules/test-export-button/components/test-export-button.component.ts index 941ab7a39..1a58bb051 100644 --- a/web/src/app/modules/actions/modules/get-test-specification-skeleton-button/components/get-test-specification-skeleton-button.component.ts +++ b/web/src/app/modules/actions/modules/test-export-button/components/test-export-button.component.ts @@ -5,28 +5,29 @@ import { saveAs } from 'file-saver'; import { TestSpecification } from '../../../../../model/TestSpecification'; import { TestSpecificationSkeleton } from '../../../../../model/TestSpecificationSkeleton'; import { SpecmateDataService } from '../../../../data/modules/data-service/services/specmate-data.service'; +import { IContainer } from '../../../../../model/IContainer'; @Component({ moduleId: module.id.toString(), - selector: 'get-test-specification-skeleton-button', - templateUrl: 'get-test-specification-skeleton-button.component.html', - styleUrls: ['get-test-specification-skeleton-button.component.css'] + selector: 'test-export-button', + templateUrl: 'test-export-button.component.html', + styleUrls: ['test-export-button.component.css'] }) -export class GetTestSpecificationSkeletonButton { +export class TestExportButton { - private _testspecification: TestSpecification; + private _element: IContainer; private _lang: string; private static UTF8_BOM = '\ufeff'; @Input() - public set testspecification(testspecification: TestSpecification) { - if (!testspecification) { + public set element(element: IContainer) { + if (!element) { return; } - this._testspecification = testspecification; + this._element = element; } @Input() @@ -42,14 +43,14 @@ export class GetTestSpecificationSkeletonButton { return; } - const data: TestSpecificationSkeleton = await this.dataService.performQuery(this._testspecification.url, 'generateTestSkeleton', + const data: TestSpecificationSkeleton = await this.dataService.performQuery(this._element.url, 'export', { language: new LowerCasePipe().transform(this._lang)}); if (data === undefined) { throw new Error('Could not load test specification skeleton for ' + this._lang); } - saveAs(new Blob([GetTestSpecificationSkeletonButton.UTF8_BOM + data.code], {type: 'text/plain;charset=utf-8'}), data.name); + saveAs(new Blob([TestExportButton.UTF8_BOM + data.code], {type: 'text/plain;charset=utf-8'}), data.name); } public get language(): string { @@ -57,7 +58,7 @@ export class GetTestSpecificationSkeletonButton { } public get enabled(): boolean { - if (this._testspecification === undefined) { + if (this._element === undefined) { return false; } diff --git a/web/src/app/modules/actions/modules/get-test-specification-skeleton-button/get-test-specification-skeleton-button.module.ts b/web/src/app/modules/actions/modules/test-export-button/test-export-button.module.ts similarity index 64% rename from web/src/app/modules/actions/modules/get-test-specification-skeleton-button/get-test-specification-skeleton-button.module.ts rename to web/src/app/modules/actions/modules/test-export-button/test-export-button.module.ts index 7cf7fc617..eb0f75a3b 100644 --- a/web/src/app/modules/actions/modules/get-test-specification-skeleton-button/get-test-specification-skeleton-button.module.ts +++ b/web/src/app/modules/actions/modules/test-export-button/test-export-button.module.ts @@ -1,7 +1,7 @@ import { NgModule } from '@angular/core'; import { BrowserModule } from '@angular/platform-browser'; import { SpecmateSharedModule } from '../../../specmate/specmate.shared.module'; -import { GetTestSpecificationSkeletonButton } from './components/get-test-specification-skeleton-button.component'; +import { TestExportButton } from './components/test-export-button.component'; @NgModule({ imports: [ @@ -11,11 +11,11 @@ import { GetTestSpecificationSkeletonButton } from './components/get-test-specif ], declarations: [ // COMPONENTS IN THIS MODULE - GetTestSpecificationSkeletonButton + TestExportButton ], exports: [ // THE COMPONENTS VISIBLE TO THE OUTSIDE - GetTestSpecificationSkeletonButton + TestExportButton ], providers: [ // SERVICES @@ -25,4 +25,4 @@ import { GetTestSpecificationSkeletonButton } from './components/get-test-specif ] }) -export class GetTestSpecificationSkeletonButtonModule { } +export class TestExportButtonModule { } diff --git a/web/src/app/modules/views/side/modules/links-actions/components/links-actions.component.html b/web/src/app/modules/views/side/modules/links-actions/components/links-actions.component.html index c6e1c36e0..d20061ff9 100644 --- a/web/src/app/modules/views/side/modules/links-actions/components/links-actions.component.html +++ b/web/src/app/modules/views/side/modules/links-actions/components/links-actions.component.html @@ -28,19 +28,27 @@
  • - + {{'exportTestprocedure' | translate}}:
    +
      +
    • + +
    • +
    • + +
    • +
  • {{'exportTestspecification' | translate}}:
    • - +
    • - +
    • - +
  • diff --git a/web/src/app/modules/views/side/modules/links-actions/links-actions.module.ts b/web/src/app/modules/views/side/modules/links-actions/links-actions.module.ts index d33031308..8b9f877f6 100644 --- a/web/src/app/modules/views/side/modules/links-actions/links-actions.module.ts +++ b/web/src/app/modules/views/side/modules/links-actions/links-actions.module.ts @@ -4,7 +4,7 @@ import { NgbModule } from '@ng-bootstrap/ng-bootstrap'; import { TranslateModule } from '@ngx-translate/core'; import { CegModelGeneratorButtonModule } from '../../../../actions/modules/ceg-model-generator-button/ceg-model-generator-button.module'; import { ExportTestprocedureButtonModule } from '../../../../actions/modules/export-testprocedure-button/export-testprocedure-button.module'; -import { GetTestSpecificationSkeletonButtonModule } from '../../../../actions/modules/get-test-specification-skeleton-button/get-test-specification-skeleton-button.module'; +import { TestExportButtonModule } from '../../../../actions/modules/test-export-button/test-export-button.module'; import { TestSpecificationGeneratorButtonModule } from '../../../../actions/modules/test-specification-generator-button/test-specification-generator-button.module'; import { NavigatorModule } from '../../../../navigation/modules/navigator/navigator.module'; import { SpecmateSharedModule } from '../../../../specmate/specmate.shared.module'; @@ -19,7 +19,7 @@ import { AdditionalInformationService } from './services/additional-information. NavigatorModule, TestSpecificationGeneratorButtonModule, ExportTestprocedureButtonModule, - GetTestSpecificationSkeletonButtonModule, + TestExportButtonModule, SpecmateSharedModule, TranslateModule, CegModelGeneratorButtonModule, diff --git a/web/src/assets/i18n/de.json b/web/src/assets/i18n/de.json index 24605b05d..4dd212a26 100644 --- a/web/src/assets/i18n/de.json +++ b/web/src/assets/i18n/de.json @@ -128,6 +128,7 @@ "elementCouldNotBeUpdated": "Element konnte nicht geƤndert werden", "errorLoggedOut": "Sie wurden aufgrund eines unbekannten Fehlers abgemeldet.", "expand": "", + "exportAlm": "Nach ALM exportieren", "exportTestprocedure": "Testprozedur exportieren", "exportTestspecification": "Testspezifikation exportieren", "failed": "Fehler", diff --git a/web/src/assets/i18n/gb.json b/web/src/assets/i18n/gb.json index a7fcdbb8f..f637343c2 100644 --- a/web/src/assets/i18n/gb.json +++ b/web/src/assets/i18n/gb.json @@ -128,6 +128,7 @@ "elementCouldNotBeUpdated": "Could nto update element", "errorLoggedOut": "You were logged out due to an unknown error.", "expand": "", + "exportAlm": "Export to ALM", "exportTestprocedure": "Export test procedure", "exportTestspecification": "Export test specification", "failed": "Failed", diff --git a/web/tsconfig.json b/web/tsconfig.json new file mode 100644 index 000000000..ea275f424 --- /dev/null +++ b/web/tsconfig.json @@ -0,0 +1,6 @@ +{ + "compilerOptions": { + "target": "es5", + "experimentalDecorators": true, + } +} \ No newline at end of file