Skip to content
This repository has been archived by the owner on Mar 2, 2020. It is now read-only.

Commit

Permalink
Merge remote-tracking branch 'origin/fix-ts-export' into releases/0.3
Browse files Browse the repository at this point in the history
  • Loading branch information
junkerm committed Apr 3, 2019
2 parents cf58d97 + afa3fde commit 6087465
Show file tree
Hide file tree
Showing 8 changed files with 314 additions and 196 deletions.
1 change: 1 addition & 0 deletions bundles/specmate-testspecification/.classpath
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" output="bin" path="src"/>
<classpathentry kind="src" path="test"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
<classpathentry kind="con" path="aQute.bnd.classpath.container"/>
<classpathentry kind="output" path="bin"/>
Expand Down
4 changes: 3 additions & 1 deletion bundles/specmate-testspecification/bnd.bnd
Original file line number Diff line number Diff line change
@@ -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,\
Expand All @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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<TestParameter> parameters = getParameters(testSpecification);
Expand All @@ -62,29 +62,29 @@ public TestSpecificationSkeleton generate(TestSpecification testSpecification) {
*/
private List<ParameterAssignment> 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<TestParameter> getParameters(TestSpecification testSpecification) {
return SpecmateEcoreUtil.pickInstancesOf(testSpecification.getContents(), TestParameter.class).stream()
.sorted(this.parameterComparator).collect(Collectors.toList());
.sorted(parameterComparator).collect(Collectors.toList());
}

private List<TestCase> 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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ protected void generateTestCaseHeader(StringBuilder sb, TestSpecification ts, Te
protected void generateTestCaseParameterAssignments(StringBuilder sb, List<ParameterAssignment> 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));
}
Expand All @@ -60,7 +60,7 @@ protected void generateTestCaseParameterAssignments(StringBuilder sb, List<Param
protected String generateFileName(TestSpecification testSpecification) {
return replaceInvalidChars(testSpecification.getName()) + ".csv";
}

protected String escapeString(String stringToCheck, String characterToEscape) {
String escapeCharacter = (stringToCheck.substring(0, 1).equals(characterToEscape)) ? "'" : "";
return escapeCharacter;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,65 +1,69 @@
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) {
return replaceInvalidChars(testSpecification.getName()) + "Test";
}

@Override
protected void generateHeader(StringBuilder sb, TestSpecification testSpecification,
List<TestParameter> 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<ParameterAssignment> 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<TestParameter> 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<ParameterAssignment> assignments) {
for (ParameterAssignment pAssignment : assignments) {
appendParameterValue(sb, pAssignment);
}
}
}
Original file line number Diff line number Diff line change
@@ -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;
}
}
Original file line number Diff line number Diff line change
@@ -1,30 +1,30 @@
<div *ngIf="visible" class="card">
<h5 class="card-header">
{{'ErrorsandWarnings' | translate}}
<button id="linksactions-expand-button" type="button" class="btn btn-sm btn-secondary pull-right"
(click)="isCollapsed = !isCollapsed" [attr.aria-expanded]="!isCollapsed" aria-controls="collapseExample"><i
*ngIf="isCollapsed" class="fa fa-angle-double-down"></i><i *ngIf="!isCollapsed"
class="fa fa-angle-double-up"></i></button>
</h5>
<div class="card-body">
<p class="card-text">
<short-model-error-message-display [model]="model"></short-model-error-message-display>
<span *ngIf="warnings && warnings.length == 0" class="text-success">
<i aria-hidden="true" class="fa fa-check"></i>&nbsp;{{'NoWarnings' | translate}}.
</span>
</p>
</div>
<table *ngIf="warnings && warnings.length > 0" class="table">
<colgroup>
<col width="50%" />
<col width="50%" />
</colgroup>
<thead>
<tr>
<th>Elements</th>
<th>Message</th>
</tr>
</thead>
<tbody *ngFor="let warningList of warnings" warning [warnElements]="warningList"></tbody>
</table>
<div *ngIf="visible && showErrors" class="card">
<h5 class="card-header">
{{'ErrorsandWarnings' | translate}}
<button id="linksactions-expand-button" type="button" class="btn btn-sm btn-secondary pull-right"
(click)="isCollapsed = !isCollapsed" [attr.aria-expanded]="!isCollapsed" aria-controls="collapseExample"><i
*ngIf="isCollapsed" class="fa fa-angle-double-down"></i><i *ngIf="!isCollapsed"
class="fa fa-angle-double-up"></i></button>
</h5>
<div class="card-body">
<p class="card-text">
<short-model-error-message-display [model]="model"></short-model-error-message-display>
<span *ngIf="warnings && warnings.length == 0" class="text-success">
<i aria-hidden="true" class="fa fa-check"></i>&nbsp;{{'NoWarnings' | translate}}.
</span>
</p>
</div>
<table *ngIf="warnings && warnings.length > 0" class="table">
<colgroup>
<col width="50%" />
<col width="50%" />
</colgroup>
<thead>
<tr>
<th>Elements</th>
<th>Message</th>
</tr>
</thead>
<tbody *ngFor="let warningList of warnings" warning [warnElements]="warningList"></tbody>
</table>
</div>
Loading

0 comments on commit 6087465

Please sign in to comment.