Skip to content

Commit

Permalink
Merge pull request #148 from hasanheroglu/testbench-integration
Browse files Browse the repository at this point in the history
Testbench integration
  • Loading branch information
egekorkan authored Jun 23, 2023
2 parents bbee04c + b3085ad commit 806c95b
Show file tree
Hide file tree
Showing 16 changed files with 6,001 additions and 3,019 deletions.
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
"electron-json-storage": "^4.5.0",
"js-beautify": "^1.14.4",
"js-combinatorics": "^0.6.1",
"json-schema-faker": "^0.5.0-rcv.46",
"json-schema-faker": "0.5.0-rcv.46",
"jsonld-streaming-parser": "^2.4.3",
"mermaid": "9.1.2",
"monaco-editor": "^0.33.0",
Expand All @@ -61,7 +61,8 @@
"vue": "^2.6.14",
"vue-router": "^3.5.1",
"vuex": "^3.6.2",
"vuex-electron-store": "^1.4.26"
"vuex-electron-store": "^1.4.26",
"wot-testbench": "^1.1.2"
},
"devDependencies": {
"@types/electron-devtools-installer": "^2.2.0",
Expand Down
41 changes: 41 additions & 0 deletions src/backend/Api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,12 @@ import VtCall from './VtCall';
import * as stream from 'stream';
import * as fs from 'fs';
import * as path from 'path';
import { Testbench } from 'wot-testbench';
import Servient from '@node-wot/core';

let tdConsumer: null | TdConsumer = null;
const testbenchServient = new Servient();
let testbench: Testbench = new Testbench(testbenchServient);

export function retrieveProtocols(td: string): ProtocolEnum[] | null {
const protocols = [] as ProtocolEnum[];
Expand Down Expand Up @@ -453,3 +457,40 @@ export function loadExampleTd(exampleTdPath: string) {
});
});
}

export async function testConformance(testConfig) {
if (tdConsumer) {
const consumedTd = await tdConsumer.getConsumedTd();
testbench.setTestConfig(testConfig);
await testbench.testThing(true, consumedTd.tdConsumed!);
return testbench.getTestReport();
}
}

export async function testVulnerability(testConfig) {
if (tdConsumer) {
const consumedTd = await tdConsumer.getConsumedTd();
testbench.setTestConfig(testConfig);
await testbench.testVulnerabilities(true, consumedTd.tdConsumed!);
return testbench.getTestReport();
}
}

export async function fastTest(): Promise<any> {
if (tdConsumer) { 
const consumedTd = await tdConsumer.getConsumedTd();
return await testbench.fastTest(true, true, consumedTd.tdConsumed!);
}

Promise.reject("No consumed TD is available!");
}

export async function testAllLevels(testConfig) {
if (tdConsumer) {
const consumedTd = await tdConsumer.getConsumedTd();
testbench.setTestConfig(testConfig);
return await testbench.testAllLevels(true, consumedTd.tdConsumed!);
}

Promise.reject("No consumed TD is available!");
}
85 changes: 85 additions & 0 deletions src/components/01_atoms/aConformanceTestElement.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
<template>
<div>
<label
:class="passed ? 'passed-test' : 'failed-test'"
v-on:click="toggleResultDetail"
>{{interactionName}}</label>
<div class="test-result-detail"
v-show="showResultDetail"
>
<textarea class="result-detail" disabled>
{{ resultDetail }}
</textarea>
</div>
</div>
</template>

<script lang="ts">
import Vue from 'vue';
export default Vue.extend({
name: 'aConformanceTestElement',
components: {},
created() {
if (!this.passed) {
this.$emit('test-failed');
}
},
data() {
return {
showResultDetail: false
}
},
props: {
interactionName: {
type: String,
required: true
},
passed: {
type: Boolean,
required: true
},
resultDetail: {
type: Object,
required: true
}
},
methods: {
toggleResultDetail() {
this.showResultDetail = !this.showResultDetail;
}
}
})
</script>


<style scoped>
.passed-test {
padding-left: 5px;
color: white;
background-color: green;
display: block;
}
.passed-test:hover {
background-color: rgba(0, 128, 0, 0.6);
}
.failed-test {
padding-left: 5px;
color: white;
background-color: red;
display: block;
}
.failed-test:hover {
background-color: rgba(255, 0, 0, 0.7);
}
.result-detail {
display: block;
width: 100%;
height: 150px;
}
</style>
84 changes: 84 additions & 0 deletions src/components/01_atoms/aCoverageTestElement.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
<template>
<div class="coverage-test-element-container">
<label
:class="passed ? 'passed-test' : 'failed-test'"
v-on:click="toggleResultDetail"
>{{ interactionName }}</label>
<div class="test-result-detail"
v-show="showResultDetail"
>
<textarea class="result-detail" disabled>
{{ resultDetail }}
</textarea>
</div>
</div>
</template>

<script lang="ts">
import Vue from 'vue';
export default Vue.extend({
name: "aCoverageTestElement",
created() {
if (!this.passed) {
this.$emit('test-failed');
}
},
data() {
return {
showResultDetail: false,
}
},
props: {
interactionName: {
type: String,
required: true
},
resultDetail: {
type: Object,
required: true
},
passed: {
type: Boolean,
required: false
}
},
methods: {
toggleResultDetail() {
this.showResultDetail = !this.showResultDetail;
}
}
});
</script>

<style scoped>
.passed-test {
padding-left: 5px;
color: white;
background-color: green;
display: block;
}
.passed-test:hover {
background-color: rgba(0, 128, 0, 0.6);
}
.failed-test {
padding-left: 5px;
color: white;
background-color: red;
display: block;
}
.failed-test:hover {
background-color: rgba(255, 0, 0, 0.7);
}
.result-detail {
display: block;
width: 100%;
height: 150px;
}
</style>
70 changes: 70 additions & 0 deletions src/components/01_atoms/aVulnerabilityTestElement.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
<template>
<div class="vulnerability-test-result-containter">
<label class="vulnerability-test-result-label"
v-on:click="toggleResultDetail"
>{{ interactionName }}</label>
<div class="vulnerability-test-result-detail"
v-show="showResultDetail"
>
<textarea class="vulnerability-result-detail" disabled>
{{ resultDetail }}
</textarea>
</div>
</div>
</template>

<script lang="ts">
import Vue from 'vue';
export default Vue.extend({
name: 'aVulnerabilityTestElement',
components: {},
data() {
return {
showResultDetail: false
}
},
props: {
interactionName: {
type: String,
required: true
},
resultDetail: {
type: Object,
required: true
}
},
methods: {
toggleResultDetail() {
this.showResultDetail = !this.showResultDetail;
}
}
})
</script>

<style scoped>
.vulnerability-test-result-containter {
margin: 2px;
}
.vulnerability-test-result-label {
padding-left: 5px;
color: white;
background-color: gray;
display: block;
border: 1px solid black;
border-radius: 2px;
}
.vulnerability-test-result-label:hover {
background-color: rgba(128, 128, 128, 0.5);
}
.vulnerability-result-detail {
display: block;
width: 100%;
height: 100px;
}
</style>
Loading

0 comments on commit 806c95b

Please sign in to comment.