Skip to content

Commit 806c95b

Browse files
authored
Merge pull request #148 from hasanheroglu/testbench-integration
Testbench integration
2 parents bbee04c + b3085ad commit 806c95b

16 files changed

+6001
-3019
lines changed

package.json

+3-2
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
"electron-json-storage": "^4.5.0",
5151
"js-beautify": "^1.14.4",
5252
"js-combinatorics": "^0.6.1",
53-
"json-schema-faker": "^0.5.0-rcv.46",
53+
"json-schema-faker": "0.5.0-rcv.46",
5454
"jsonld-streaming-parser": "^2.4.3",
5555
"mermaid": "9.1.2",
5656
"monaco-editor": "^0.33.0",
@@ -61,7 +61,8 @@
6161
"vue": "^2.6.14",
6262
"vue-router": "^3.5.1",
6363
"vuex": "^3.6.2",
64-
"vuex-electron-store": "^1.4.26"
64+
"vuex-electron-store": "^1.4.26",
65+
"wot-testbench": "^1.1.2"
6566
},
6667
"devDependencies": {
6768
"@types/electron-devtools-installer": "^2.2.0",

src/backend/Api.ts

+41
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,12 @@ import VtCall from './VtCall';
1414
import * as stream from 'stream';
1515
import * as fs from 'fs';
1616
import * as path from 'path';
17+
import { Testbench } from 'wot-testbench';
18+
import Servient from '@node-wot/core';
1719

1820
let tdConsumer: null | TdConsumer = null;
21+
const testbenchServient = new Servient();
22+
let testbench: Testbench = new Testbench(testbenchServient);
1923

2024
export function retrieveProtocols(td: string): ProtocolEnum[] | null {
2125
const protocols = [] as ProtocolEnum[];
@@ -453,3 +457,40 @@ export function loadExampleTd(exampleTdPath: string) {
453457
});
454458
});
455459
}
460+
461+
export async function testConformance(testConfig) {
462+
if (tdConsumer) {
463+
const consumedTd = await tdConsumer.getConsumedTd();
464+
testbench.setTestConfig(testConfig);
465+
await testbench.testThing(true, consumedTd.tdConsumed!);
466+
return testbench.getTestReport();
467+
}
468+
}
469+
470+
export async function testVulnerability(testConfig) {
471+
if (tdConsumer) {
472+
const consumedTd = await tdConsumer.getConsumedTd();
473+
testbench.setTestConfig(testConfig);
474+
await testbench.testVulnerabilities(true, consumedTd.tdConsumed!);
475+
return testbench.getTestReport();
476+
}
477+
}
478+
479+
export async function fastTest(): Promise<any> {
480+
if (tdConsumer) { 
481+
const consumedTd = await tdConsumer.getConsumedTd();
482+
return await testbench.fastTest(true, true, consumedTd.tdConsumed!);
483+
}
484+
485+
Promise.reject("No consumed TD is available!");
486+
}
487+
488+
export async function testAllLevels(testConfig) {
489+
if (tdConsumer) {
490+
const consumedTd = await tdConsumer.getConsumedTd();
491+
testbench.setTestConfig(testConfig);
492+
return await testbench.testAllLevels(true, consumedTd.tdConsumed!);
493+
}
494+
495+
Promise.reject("No consumed TD is available!");
496+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
<template>
2+
<div>
3+
<label
4+
:class="passed ? 'passed-test' : 'failed-test'"
5+
v-on:click="toggleResultDetail"
6+
>{{interactionName}}</label>
7+
<div class="test-result-detail"
8+
v-show="showResultDetail"
9+
>
10+
<textarea class="result-detail" disabled>
11+
{{ resultDetail }}
12+
</textarea>
13+
</div>
14+
</div>
15+
</template>
16+
17+
<script lang="ts">
18+
import Vue from 'vue';
19+
20+
export default Vue.extend({
21+
name: 'aConformanceTestElement',
22+
components: {},
23+
created() {
24+
if (!this.passed) {
25+
this.$emit('test-failed');
26+
}
27+
},
28+
data() {
29+
return {
30+
showResultDetail: false
31+
}
32+
},
33+
props: {
34+
interactionName: {
35+
type: String,
36+
required: true
37+
},
38+
passed: {
39+
type: Boolean,
40+
required: true
41+
},
42+
resultDetail: {
43+
type: Object,
44+
required: true
45+
}
46+
},
47+
methods: {
48+
toggleResultDetail() {
49+
this.showResultDetail = !this.showResultDetail;
50+
}
51+
}
52+
})
53+
</script>
54+
55+
56+
<style scoped>
57+
.passed-test {
58+
padding-left: 5px;
59+
color: white;
60+
background-color: green;
61+
display: block;
62+
}
63+
64+
.passed-test:hover {
65+
background-color: rgba(0, 128, 0, 0.6);
66+
}
67+
68+
.failed-test {
69+
padding-left: 5px;
70+
color: white;
71+
background-color: red;
72+
display: block;
73+
74+
}
75+
76+
.failed-test:hover {
77+
background-color: rgba(255, 0, 0, 0.7);
78+
}
79+
80+
.result-detail {
81+
display: block;
82+
width: 100%;
83+
height: 150px;
84+
}
85+
</style>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
<template>
2+
<div class="coverage-test-element-container">
3+
<label
4+
:class="passed ? 'passed-test' : 'failed-test'"
5+
v-on:click="toggleResultDetail"
6+
>{{ interactionName }}</label>
7+
<div class="test-result-detail"
8+
v-show="showResultDetail"
9+
>
10+
<textarea class="result-detail" disabled>
11+
{{ resultDetail }}
12+
</textarea>
13+
</div>
14+
</div>
15+
</template>
16+
17+
<script lang="ts">
18+
import Vue from 'vue';
19+
20+
export default Vue.extend({
21+
name: "aCoverageTestElement",
22+
created() {
23+
if (!this.passed) {
24+
this.$emit('test-failed');
25+
}
26+
},
27+
data() {
28+
return {
29+
showResultDetail: false,
30+
}
31+
},
32+
props: {
33+
interactionName: {
34+
type: String,
35+
required: true
36+
},
37+
resultDetail: {
38+
type: Object,
39+
required: true
40+
},
41+
passed: {
42+
type: Boolean,
43+
required: false
44+
}
45+
},
46+
methods: {
47+
toggleResultDetail() {
48+
this.showResultDetail = !this.showResultDetail;
49+
}
50+
}
51+
});
52+
53+
</script>
54+
55+
<style scoped>
56+
.passed-test {
57+
padding-left: 5px;
58+
color: white;
59+
background-color: green;
60+
display: block;
61+
}
62+
63+
.passed-test:hover {
64+
background-color: rgba(0, 128, 0, 0.6);
65+
}
66+
67+
.failed-test {
68+
padding-left: 5px;
69+
color: white;
70+
background-color: red;
71+
display: block;
72+
73+
}
74+
75+
.failed-test:hover {
76+
background-color: rgba(255, 0, 0, 0.7);
77+
}
78+
79+
.result-detail {
80+
display: block;
81+
width: 100%;
82+
height: 150px;
83+
}
84+
</style>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
<template>
2+
<div class="vulnerability-test-result-containter">
3+
<label class="vulnerability-test-result-label"
4+
v-on:click="toggleResultDetail"
5+
>{{ interactionName }}</label>
6+
<div class="vulnerability-test-result-detail"
7+
v-show="showResultDetail"
8+
>
9+
<textarea class="vulnerability-result-detail" disabled>
10+
{{ resultDetail }}
11+
</textarea>
12+
</div>
13+
</div>
14+
</template>
15+
16+
<script lang="ts">
17+
import Vue from 'vue';
18+
19+
export default Vue.extend({
20+
name: 'aVulnerabilityTestElement',
21+
components: {},
22+
data() {
23+
return {
24+
showResultDetail: false
25+
}
26+
},
27+
props: {
28+
interactionName: {
29+
type: String,
30+
required: true
31+
},
32+
resultDetail: {
33+
type: Object,
34+
required: true
35+
}
36+
},
37+
methods: {
38+
toggleResultDetail() {
39+
this.showResultDetail = !this.showResultDetail;
40+
}
41+
}
42+
})
43+
</script>
44+
45+
<style scoped>
46+
47+
.vulnerability-test-result-containter {
48+
margin: 2px;
49+
}
50+
51+
.vulnerability-test-result-label {
52+
padding-left: 5px;
53+
color: white;
54+
background-color: gray;
55+
display: block;
56+
border: 1px solid black;
57+
border-radius: 2px;
58+
}
59+
60+
.vulnerability-test-result-label:hover {
61+
background-color: rgba(128, 128, 128, 0.5);
62+
}
63+
64+
.vulnerability-result-detail {
65+
display: block;
66+
width: 100%;
67+
height: 100px;
68+
}
69+
70+
</style>

0 commit comments

Comments
 (0)