diff --git a/bundles/specmate-testspecification/.classpath b/bundles/specmate-testspecification/.classpath index b263de401..284fd3742 100644 --- a/bundles/specmate-testspecification/.classpath +++ b/bundles/specmate-testspecification/.classpath @@ -1,6 +1,7 @@ + diff --git a/bundles/specmate-testspecification/bnd.bnd b/bundles/specmate-testspecification/bnd.bnd index a5947a3c2..973078919 100644 --- a/bundles/specmate-testspecification/bnd.bnd +++ b/bundles/specmate-testspecification/bnd.bnd @@ -1,4 +1,5 @@ -buildpath: \ + org.apache.servicemix.bundles.junit;version=4.12,\ specmate-model-gen;version=latest,\ specmate-common;version=latest,\ org.eclipse.emf.cdo,\ @@ -16,7 +17,8 @@ org.sat4j.pb,\ specmate-emfrest-api;version=latest,\ specmate-rest;version=latest,\ - org.apache.commons.lang3;version=3.5 + org.apache.commons.lang3;version=3.5,\ + org.eclipse.equinox.common Private-Package: \ com.specmate.testspecification.internal.services,\ com.specmate.testspecification.internal.testskeleton \ No newline at end of file diff --git a/bundles/specmate-testspecification/src/com/specmate/testspecification/internal/testskeleton/BaseSkeleton.java b/bundles/specmate-testspecification/src/com/specmate/testspecification/internal/testskeleton/BaseSkeleton.java index 837335c1f..536265301 100644 --- a/bundles/specmate-testspecification/src/com/specmate/testspecification/internal/testskeleton/BaseSkeleton.java +++ b/bundles/specmate-testspecification/src/com/specmate/testspecification/internal/testskeleton/BaseSkeleton.java @@ -39,7 +39,7 @@ public TestSpecificationSkeleton generate(TestSpecification testSpecification) { StringBuilder sb = new StringBuilder(); TestSpecificationSkeleton tss = TestspecificationFactory.eINSTANCE.createTestSpecificationSkeleton(); - tss.setLanguage(this.language); + tss.setLanguage(language); tss.setName(generateFileName(testSpecification)); List parameters = getParameters(testSpecification); @@ -62,29 +62,29 @@ public TestSpecificationSkeleton generate(TestSpecification testSpecification) { */ private List getTestCaseParameterAssignments(TestCase tc) { return SpecmateEcoreUtil.pickInstancesOf(tc.getContents(), ParameterAssignment.class).stream() - .sorted(this.assignmentComparator).collect(Collectors.toList()); + .sorted(assignmentComparator).collect(Collectors.toList()); } /** Return Test parameters sorted by type (input before output) */ private List getParameters(TestSpecification testSpecification) { return SpecmateEcoreUtil.pickInstancesOf(testSpecification.getContents(), TestParameter.class).stream() - .sorted(this.parameterComparator).collect(Collectors.toList()); + .sorted(parameterComparator).collect(Collectors.toList()); } private List getTestCases(TestSpecification testSpecification) { return SpecmateEcoreUtil.pickInstancesOf(testSpecification.getContents(), TestCase.class); } - protected String replaceInvalidChars(String r) { - r = startsNumerical.matcher(r).replaceAll(""); - return invalidChars.matcher(r).replaceAll("_"); + 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())); sb.append("__"); - sb.append(replaceInvalidChars(pa.getValue())); + sb.append(replaceInvalidChars(pa.getCondition())); } protected void appendDateComment(StringBuilder sb) { diff --git a/bundles/specmate-testspecification/src/com/specmate/testspecification/internal/testskeleton/CSVTestSpecificationSkeleton.java b/bundles/specmate-testspecification/src/com/specmate/testspecification/internal/testskeleton/CSVTestSpecificationSkeleton.java index ad8d011f3..880ec5216 100644 --- a/bundles/specmate-testspecification/src/com/specmate/testspecification/internal/testskeleton/CSVTestSpecificationSkeleton.java +++ b/bundles/specmate-testspecification/src/com/specmate/testspecification/internal/testskeleton/CSVTestSpecificationSkeleton.java @@ -49,7 +49,7 @@ protected void generateTestCaseHeader(StringBuilder sb, TestSpecification ts, Te protected void generateTestCaseParameterAssignments(StringBuilder sb, List assignments) { StringJoiner joiner = new StringJoiner(COL_SEP); for (ParameterAssignment assignment : assignments) { - String assignmentValue = assignment.getValue(); + String assignmentValue = assignment.getCondition(); String characterToEscape = "="; joiner.add(StringUtils.wrap(escapeString(assignmentValue, characterToEscape) + assignmentValue, TEXT_WRAP)); } @@ -60,7 +60,7 @@ protected void generateTestCaseParameterAssignments(StringBuilder sb, List parameters) { - sb.append("import org.junit.Test;\n"); - sb.append("import org.junit.Assert;\n\n"); - appendDateComment(sb); - sb.append("public class "); - sb.append(getClassName(testSpecification)); - sb.append(" {\n\n"); - } - - @Override - protected void generateTestCaseFooter(StringBuilder sb, TestCase tc) { - sb.append("() {\n"); - sb.append("\t\tAssert.throw();\n"); - sb.append("\t}\n\n"); - } - - @Override - protected void generateTestCaseHeader(StringBuilder sb, TestSpecification ts, TestCase tc) { - sb.append("\t/*\n"); - sb.append("\t * Testfall: "); - sb.append(tc.getName()); - sb.append("\n\t */\n"); - sb.append("\t@Test\n"); - sb.append("\tpublic void "); - sb.append(getClassName(ts)); - } - - @Override - protected void generateFooter(StringBuilder sb, TestSpecification testSpecification) { - sb.append("}"); - } - - @Override - protected void generateTestCaseParameterAssignments(StringBuilder sb, List assignments) { - for (ParameterAssignment pAssignment : assignments) { - appendParameterValue(sb, pAssignment); - } - } -} +package com.specmate.testspecification.internal.testskeleton; + +import java.util.List; + +import com.specmate.model.testspecification.ParameterAssignment; +import com.specmate.model.testspecification.TestCase; +import com.specmate.model.testspecification.TestParameter; +import com.specmate.model.testspecification.TestSpecification; + +public class JavaTestSpecificationSkeleton extends BaseSkeleton { + + public JavaTestSpecificationSkeleton(String language) { + super(language); + } + + @Override + protected String generateFileName(TestSpecification testSpecification) { + return getClassName(testSpecification) + ".java"; + } + + private String getClassName(TestSpecification testSpecification) { + String tsName = testSpecification.getName(); + if (tsName == null) { + tsName = ""; + } + return replaceInvalidChars(tsName) + "Test"; + } + + @Override + protected void generateHeader(StringBuilder sb, TestSpecification testSpecification, + List parameters) { + sb.append("import org.junit.Test;\n"); + sb.append("import org.junit.Assert;\n\n"); + appendDateComment(sb); + sb.append("public class "); + sb.append(getClassName(testSpecification)); + sb.append(" {\n\n"); + } + + @Override + protected void generateTestCaseFooter(StringBuilder sb, TestCase tc) { + sb.append("() {\n"); + sb.append("\t\tAssert.throw();\n"); + sb.append("\t}\n\n"); + } + + @Override + protected void generateTestCaseHeader(StringBuilder sb, TestSpecification ts, TestCase tc) { + sb.append("\t/*\n"); + sb.append("\t * Testfall: "); + sb.append(tc.getName()); + sb.append("\n\t */\n"); + sb.append("\t@Test\n"); + sb.append("\tpublic void "); + sb.append(getClassName(ts)); + } + + @Override + protected void generateFooter(StringBuilder sb, TestSpecification testSpecification) { + sb.append("}"); + } + + @Override + protected void generateTestCaseParameterAssignments(StringBuilder sb, List assignments) { + for (ParameterAssignment pAssignment : assignments) { + appendParameterValue(sb, pAssignment); + } + } +} diff --git a/bundles/specmate-testspecification/test/com/specmate/testspecification/test/TestSkeletonTest.java b/bundles/specmate-testspecification/test/com/specmate/testspecification/test/TestSkeletonTest.java new file mode 100644 index 000000000..49688caef --- /dev/null +++ b/bundles/specmate-testspecification/test/com/specmate/testspecification/test/TestSkeletonTest.java @@ -0,0 +1,102 @@ +package com.specmate.testspecification.test; + +import java.util.Arrays; + +import org.junit.Assert; +import org.junit.Test; + +import com.specmate.model.testspecification.ParameterAssignment; +import com.specmate.model.testspecification.ParameterType; +import com.specmate.model.testspecification.TestCase; +import com.specmate.model.testspecification.TestParameter; +import com.specmate.model.testspecification.TestSpecification; +import com.specmate.model.testspecification.TestSpecificationSkeleton; +import com.specmate.model.testspecification.TestspecificationFactory; +import com.specmate.testspecification.internal.testskeleton.JavaTestSpecificationSkeleton; + +public class TestSkeletonTest { + @Test + public void testJavaSkeleton() { + TestSpecification ts = getTestSpecification(); + + JavaTestSpecificationSkeleton skel = new JavaTestSpecificationSkeleton("JAVA"); + TestSpecificationSkeleton result = skel.generate(ts); + String code = result.getCode(); + + Assert.assertTrue(code.contains("public void TSTest___in1__in11___in2__in12___out1__out11___out2__out12()")); + Assert.assertTrue(code.contains("public void TSTest___in1__in21___in2__in22___out1__out21___out2__out22()")); + } + + private TestSpecification getTestSpecification() { + TestspecificationFactory f = TestspecificationFactory.eINSTANCE; + TestSpecification ts = f.createTestSpecification(); + ts.setName("TS"); + + TestParameter input1 = f.createTestParameter(); + input1.setId("in1"); + input1.setName("in1"); + input1.setType(ParameterType.INPUT); + + TestParameter input2 = f.createTestParameter(); + input2.setId("in2"); + input2.setName("in2"); + input2.setType(ParameterType.INPUT); + + TestParameter output1 = f.createTestParameter(); + output1.setId("out1"); + output1.setName("out1"); + output1.setType(ParameterType.OUTPUT); + + TestParameter output2 = f.createTestParameter(); + output2.setId("out2"); + output2.setName("out2"); + output2.setType(ParameterType.OUTPUT); + + ts.getContents().addAll(Arrays.asList(input1, input2, output1, output2)); + + TestCase tc1 = f.createTestCase(); + tc1.setId("tc1"); + tc1.setName("tc1"); + + ParameterAssignment assIn11 = f.createParameterAssignment(); + assIn11.setParameter(input1); + assIn11.setValue("in11"); + + ParameterAssignment assIn12 = f.createParameterAssignment(); + assIn12.setParameter(input2); + assIn12.setValue("in12"); + + ParameterAssignment assOut11 = f.createParameterAssignment(); + assOut11.setParameter(output1); + assOut11.setValue("out11"); + + ParameterAssignment assOut12 = f.createParameterAssignment(); + assOut12.setParameter(output2); + assOut12.setValue("out12"); + tc1.getContents().addAll(Arrays.asList(assIn11, assIn12, assOut11, assOut12)); + + TestCase tc2 = f.createTestCase(); + tc2.setId("tc2"); + tc2.setName("tc2"); + + ParameterAssignment assIn21 = f.createParameterAssignment(); + assIn21.setParameter(input1); + assIn21.setValue("in21"); + + ParameterAssignment assIn22 = f.createParameterAssignment(); + assIn22.setParameter(input2); + assIn22.setValue("in22"); + + ParameterAssignment assOut21 = f.createParameterAssignment(); + assOut21.setParameter(output1); + assOut21.setValue("out21"); + + ParameterAssignment assOut22 = f.createParameterAssignment(); + assOut22.setParameter(output2); + assOut22.setValue("out22"); + tc2.getContents().addAll(Arrays.asList(assIn21, assIn22, assOut21, assOut22)); + + ts.getContents().addAll(Arrays.asList(tc1, tc2)); + return ts; + } +} diff --git a/web/src/app/modules/views/side/modules/errors-warnings/components/errors-warnings.component.html b/web/src/app/modules/views/side/modules/errors-warnings/components/errors-warnings.component.html index 912d85111..ed89420ee 100644 --- a/web/src/app/modules/views/side/modules/errors-warnings/components/errors-warnings.component.html +++ b/web/src/app/modules/views/side/modules/errors-warnings/components/errors-warnings.component.html @@ -1,30 +1,30 @@ -
-
- {{'ErrorsandWarnings' | translate}} - -
-
-

- - -  {{'NoWarnings' | translate}}. - -

-
- - - - - - - - - - - - -
ElementsMessage
+
+
+ {{'ErrorsandWarnings' | translate}} + +
+
+

+ + +  {{'NoWarnings' | translate}}. + +

+
+ + + + + + + + + + + + +
ElementsMessage
\ No newline at end of file diff --git a/web/src/app/modules/views/side/modules/errors-warnings/components/errors-warnings.component.ts b/web/src/app/modules/views/side/modules/errors-warnings/components/errors-warnings.component.ts index 44a3367f3..2abcb845f 100644 --- a/web/src/app/modules/views/side/modules/errors-warnings/components/errors-warnings.component.ts +++ b/web/src/app/modules/views/side/modules/errors-warnings/components/errors-warnings.component.ts @@ -1,92 +1,101 @@ -import { Component } from '@angular/core'; -import { ValidationResult } from '../../../../../../validation/validation-result'; -import { ValidationService } from '../../../../../forms/modules/validation/services/validation.service'; -import { AdditionalInformationService } from '../../links-actions/services/additional-information.service'; -import { Arrays } from '../../../../../../util/arrays'; -import { IContainer } from '../../../../../../model/IContainer'; - -@Component({ - moduleId: module.id.toString(), - selector: 'errors-warnings', - templateUrl: 'errors-warnings.component.html', - styleUrls: ['errors-warnings.component.css'] -}) -export class ErrorsWarings { - private _isCollapsed = false; - public set isCollapsed(collapsed: boolean) { - this._isCollapsed = collapsed; - } - - public get isCollapsed(): boolean { - if (!this.warnings) { - return true; - } - return this._isCollapsed; - } - - public get model(): IContainer { - return this.additionalInformationService.element; - } - - public visible = true; - constructor(private validationService: ValidationService, - private additionalInformationService: AdditionalInformationService) { } - - - private _currentWarningStringSet = new Set(); - private _currentWarnings: ValidationResult[][] = []; - public get warnings(): ValidationResult[][] { - /* - * Returns a list of Validation Errors grouped by affected elements. - * Every entry of warnings() is a list of errors that affect the same list of elements. - * For each of those lists a warning component will be created, that lists those elements - * as well as all error messages. - * [[ Errors affecting Elements A,B,C], [Errors affecting Element D],...] - */ - if (!this.additionalInformationService.element) { - return; - } - // We want to avoid excessive UI updates so we cache the warnings and only change the list when they have changed. - let invalidResults = this.validationService.findValidationResults(this.additionalInformationService.element, elem => !elem.isValid); - let newWarnings: ValidationResult[][] = []; - let newWarningStringSet = new Set(); - let changed = false; - for (const key in invalidResults) { - let list = invalidResults[key]; - let groupedList = Arrays.groupBy(list, ErrorsWarings.getResultURLString); - for (const resStr in groupedList) { - if (groupedList.hasOwnProperty(resStr)) { - const subList = groupedList[resStr]; - let arrStr = ErrorsWarings.getArrayURLString(subList); - // We encounter an element we dont have in the cache - if (!this._currentWarningStringSet.has(arrStr)) { - changed = true; - } - newWarningStringSet.add(arrStr); - newWarnings.push(subList); - } - } - } - // The number of warnings has changed. - if (newWarnings.length != this._currentWarnings.length) { - changed = true; - } - if (changed) { - // Update the UI. - Promise.resolve().then( () => { - this._currentWarningStringSet = newWarningStringSet; - this._currentWarnings = newWarnings; - }); - } - return this._currentWarnings; - } - - private static getResultURLString(result: ValidationResult): string { - return result.elements.map(element => element.url).sort().join(' '); - } - - private static getArrayURLString(array: ValidationResult[]): string { - return array.map(ErrorsWarings.getResultURLString).sort(). join(','); - } - -} +import { Component } from '@angular/core'; +import { ValidationResult } from '../../../../../../validation/validation-result'; +import { ValidationService } from '../../../../../forms/modules/validation/services/validation.service'; +import { AdditionalInformationService } from '../../links-actions/services/additional-information.service'; +import { Arrays } from '../../../../../../util/arrays'; +import { IContainer } from '../../../../../../model/IContainer'; + +@Component({ + moduleId: module.id.toString(), + selector: 'errors-warnings', + templateUrl: 'errors-warnings.component.html', + styleUrls: ['errors-warnings.component.css'] +}) +export class ErrorsWarings { + private _isCollapsed = false; + public set isCollapsed(collapsed: boolean) { + this._isCollapsed = collapsed; + } + + public get isCollapsed(): boolean { + if (!this.warnings) { + return true; + } + return this._isCollapsed; + } + + public get model(): IContainer { + return this.additionalInformationService.element; + } + + public visible = true; + constructor(private validationService: ValidationService, + private additionalInformationService: AdditionalInformationService) { } + + + private _currentWarningStringSet = new Set(); + private _currentWarnings: ValidationResult[][] = []; + public get warnings(): ValidationResult[][] { + /* + * Returns a list of Validation Errors grouped by affected elements. + * Every entry of warnings() is a list of errors that affect the same list of elements. + * For each of those lists a warning component will be created, that lists those elements + * as well as all error messages. + * [[ Errors affecting Elements A,B,C], [Errors affecting Element D],...] + */ + if (!this.additionalInformationService.element) { + return; + } + // We want to avoid excessive UI updates so we cache the warnings and only change the list when they have changed. + let invalidResults = this.validationService.findValidationResults(this.additionalInformationService.element, elem => !elem.isValid); + let newWarnings: ValidationResult[][] = []; + let newWarningStringSet = new Set(); + let changed = false; + for (const key in invalidResults) { + let list = invalidResults[key]; + let groupedList = Arrays.groupBy(list, ErrorsWarings.getResultURLString); + for (const resStr in groupedList) { + if (groupedList.hasOwnProperty(resStr)) { + const subList = groupedList[resStr]; + let arrStr = ErrorsWarings.getArrayURLString(subList); + // We encounter an element we dont have in the cache + if (!this._currentWarningStringSet.has(arrStr)) { + changed = true; + } + newWarningStringSet.add(arrStr); + newWarnings.push(subList); + } + } + } + // The number of warnings has changed. + if (newWarnings.length != this._currentWarnings.length) { + changed = true; + } + if (changed) { + // Update the UI. + Promise.resolve().then( () => { + this._currentWarningStringSet = newWarningStringSet; + this._currentWarnings = newWarnings; + }); + } + return this._currentWarnings; + } + + private static getResultURLString(result: ValidationResult): string { + return result.elements.map(element => element.url).sort().join(' '); + } + + private static getArrayURLString(array: ValidationResult[]): string { + return array.map(ErrorsWarings.getResultURLString).sort(). join(','); + } + + // Errors and Warnings shall not be shown in folder view + public get showErrors(): boolean { + if (this.model !== undefined + && this.model.className === 'Folder') { + return false; + } + return true; + } + +}