-
Notifications
You must be signed in to change notification settings - Fork 88
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
198 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
...src/main/kotlin/com/foo/rest/examples/spring/openapi/v3/bbdefault/BBDefaultApplication.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package com.foo.rest.examples.spring.openapi.v3.bbdefault | ||
|
||
import com.foo.rest.examples.spring.openapi.v3.base.BaseApplication | ||
import org.springframework.boot.SpringApplication | ||
import org.springframework.boot.autoconfigure.SpringBootApplication | ||
import org.springframework.boot.autoconfigure.security.servlet.SecurityAutoConfiguration | ||
import org.springframework.http.ResponseEntity | ||
import org.springframework.web.bind.annotation.GetMapping | ||
import org.springframework.web.bind.annotation.RequestHeader | ||
import org.springframework.web.bind.annotation.RequestMapping | ||
import org.springframework.web.bind.annotation.RequestParam | ||
import org.springframework.web.bind.annotation.RestController | ||
|
||
|
||
@SpringBootApplication(exclude = [SecurityAutoConfiguration::class]) | ||
@RequestMapping(path = ["/api/bbdefault"]) | ||
@RestController | ||
open class BBDefaultApplication { | ||
|
||
companion object { | ||
@JvmStatic | ||
fun main(args: Array<String>) { | ||
SpringApplication.run(BBDefaultApplication::class.java, *args) | ||
} | ||
} | ||
|
||
@GetMapping | ||
open fun get(@RequestParam data: String?) : ResponseEntity<String> { | ||
|
||
if(data == "foo") | ||
return ResponseEntity.ok("OK") | ||
|
||
return ResponseEntity.status(400).build() | ||
} | ||
} |
47 changes: 47 additions & 0 deletions
47
e2e-tests/spring-rest-openapi-v3/src/main/resources/static/openapi-bbdefault.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
{ | ||
"openapi": "3.0.1", | ||
"info": { | ||
"title": "OpenAPI definition", | ||
"version": "v0" | ||
}, | ||
"servers": [ | ||
{ | ||
"url": "http://localhost:8080", | ||
"description": "Generated server url" | ||
} | ||
], | ||
"paths": { | ||
"/api/bbdefault": { | ||
"get": { | ||
"tags": [ | ||
"bb-default-application" | ||
], | ||
"operationId": "get", | ||
"parameters": [ | ||
{ | ||
"name": "data", | ||
"in": "query", | ||
"required": false, | ||
"schema": { | ||
"type": "string", | ||
"default": "foo" | ||
} | ||
} | ||
], | ||
"responses": { | ||
"200": { | ||
"description": "OK", | ||
"content": { | ||
"*/*": { | ||
"schema": { | ||
"type": "string" | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
}, | ||
"components": {} | ||
} |
16 changes: 16 additions & 0 deletions
16
.../src/test/kotlin/com/foo/rest/examples/spring/openapi/v3/bbdefault/BBDefaultController.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package com.foo.rest.examples.spring.openapi.v3.bbdefault | ||
|
||
import com.foo.rest.examples.spring.openapi.v3.SpringController | ||
import org.evomaster.client.java.controller.problem.ProblemInfo | ||
import org.evomaster.client.java.controller.problem.RestProblem | ||
|
||
class BBDefaultController : SpringController(BBDefaultApplication::class.java){ | ||
|
||
|
||
override fun getProblemInfo(): ProblemInfo { | ||
return RestProblem( | ||
"http://localhost:$sutPort/openapi-bbdefault.json", | ||
null | ||
) | ||
} | ||
} |
85 changes: 85 additions & 0 deletions
85
...-v3/src/test/kotlin/org/evomaster/e2etests/spring/openapi/v3/bbdefault/BBDefaultEMTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
package org.evomaster.e2etests.spring.openapi.v3.bbdefault | ||
|
||
import com.foo.rest.examples.spring.openapi.v3.bbauth.BBAuthController | ||
import com.foo.rest.examples.spring.openapi.v3.bbdefault.BBDefaultController | ||
import org.evomaster.core.problem.rest.HttpVerb | ||
import org.evomaster.e2etests.spring.openapi.v3.SpringTestBase | ||
import org.junit.jupiter.api.Assertions | ||
import org.junit.jupiter.api.BeforeAll | ||
import org.junit.jupiter.api.Test | ||
|
||
class BBDefaultEMTest : SpringTestBase() { | ||
|
||
companion object { | ||
@BeforeAll | ||
@JvmStatic | ||
fun init() { | ||
initClass(BBDefaultController()) | ||
} | ||
} | ||
|
||
|
||
@Test | ||
fun testRunEMOk() { | ||
runTestHandlingFlakyAndCompilation( | ||
"BBDefaultEMOk", | ||
"org.foo.BBDefaultEMOk", | ||
20 | ||
) { args: MutableList<String> -> | ||
|
||
args.add("--blackBox") | ||
args.add("true") | ||
args.add("--bbTargetUrl") | ||
args.add(baseUrlOfSut) | ||
args.add("--bbSwaggerUrl") | ||
args.add("$baseUrlOfSut/openapi-bbdefault.json") | ||
args.add("--bbExperiments") | ||
args.add("false") | ||
|
||
args.add("--probRestDefault") | ||
args.add("0.5") | ||
|
||
//make sure we do not solve it via taint analysis | ||
args.add("--baseTaintAnalysisProbability") | ||
args.add("0") | ||
|
||
val solution = initAndRun(args) | ||
|
||
Assertions.assertTrue(solution.individuals.size >= 1) | ||
assertHasAtLeastOne(solution, HttpVerb.GET, 200, "/api/bbdefault", "OK") | ||
} | ||
} | ||
|
||
@Test | ||
fun testRunEMFail() { | ||
runTestHandlingFlakyAndCompilation( | ||
"BBDefaultEMFail", | ||
"org.foo.BBDefaultEMFail", | ||
20 | ||
) { args: MutableList<String> -> | ||
|
||
args.add("--blackBox") | ||
args.add("true") | ||
args.add("--bbTargetUrl") | ||
args.add(baseUrlOfSut) | ||
args.add("--bbSwaggerUrl") | ||
args.add("$baseUrlOfSut/openapi-bbdefault.json") | ||
args.add("--bbExperiments") | ||
args.add("false") | ||
|
||
args.add("--probRestDefault") | ||
args.add("0.0") // no way in BB should be able to get the right string with no further info | ||
|
||
//make sure we do not solve it via taint analysis | ||
args.add("--baseTaintAnalysisProbability") | ||
args.add("0") | ||
|
||
val solution = initAndRun(args) | ||
|
||
Assertions.assertTrue(solution.individuals.size >= 1) | ||
assertHasAtLeastOne(solution, HttpVerb.GET, 400, "/api/bbdefault", null) | ||
assertNone(solution,HttpVerb.GET,200,"/api/bbdefault", "OK") | ||
} | ||
} | ||
|
||
} |