Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
package com.foo.rest.examples.bb.advancedformats

import org.evomaster.e2etests.utils.CoveredTargets
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.*
import java.net.URI
import java.util.UUID

@SpringBootApplication(exclude = [SecurityAutoConfiguration::class])
@RequestMapping(path = ["/api/advancedformats"])
@RestController
open class BBAdvancedFormatsApplication {

companion object {
@JvmStatic
fun main(args: Array<String>) {
SpringApplication.run(BBAdvancedFormatsApplication::class.java, *args)
}
}


@GetMapping("/uuid")
open fun getUuid(
@RequestParam(required = true) x: String?
) : ResponseEntity<String> {

if (x == null) {
return ResponseEntity.status(400).build()
}

UUID.fromString(x)

CoveredTargets.cover("uuid")

return ResponseEntity.status(200).body("OK")
}

@GetMapping("/email")
open fun getEmail(
@RequestParam(required = true) x: String?
) : ResponseEntity<String> {

if (x == null || !x.contains('@')) {
return ResponseEntity.status(400).build()
}

CoveredTargets.cover("email")

return ResponseEntity.status(200).body("OK")
}

@GetMapping("/uri")
open fun getUri(
@RequestParam(required = true) x: String?
) : ResponseEntity<String> {

if (x == null) {
return ResponseEntity.status(400).build()
}

URI(x)

CoveredTargets.cover("uri")

return ResponseEntity.status(200).body("OK")
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
{
"openapi": "3.0.1",
"info": {
"title": "OpenAPI definition",
"version": "v0"
},
"servers": [
{
"url": "http://localhost:8080",
"description": "Generated server url"
}
],
"paths": {
"/api/advancedformats/uuid": {
"get": {
"tags": [
"bb-advanced-formats-application"
],
"operationId": "getUuid",
"parameters": [
{
"name": "x",
"in": "query",
"required": false,
"schema": {
"type": "string",
"format": "uuid"
}
}
],
"responses": {
"200": {
"description": "OK",
"content": {
"*/*": {
"schema": {
"type": "string"
}
}
}
}
}
}
},
"/api/advancedformats/uri": {
"get": {
"tags": [
"bb-advanced-formats-application"
],
"operationId": "getUri",
"parameters": [
{
"name": "x",
"in": "query",
"required": false,
"schema": {
"type": "string",
"format": "uri"
}
}
],
"responses": {
"200": {
"description": "OK",
"content": {
"*/*": {
"schema": {
"type": "string"
}
}
}
}
}
}
},
"/api/advancedformats/email": {
"get": {
"tags": [
"bb-advanced-formats-application"
],
"operationId": "getEmail",
"parameters": [
{
"name": "x",
"in": "query",
"required": false,
"schema": {
"type": "string",
"format": "email"
}
}
],
"responses": {
"200": {
"description": "OK",
"content": {
"*/*": {
"schema": {
"type": "string"
}
}
}
}
}
}
}
},
"components": {}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.foo.rest.examples.bb.advancedformats

import com.foo.rest.examples.bb.SpringController
import org.evomaster.client.java.controller.problem.ProblemInfo
import org.evomaster.client.java.controller.problem.RestProblem

class BBAdvancedFormatsController : SpringController(BBAdvancedFormatsApplication::class.java){


override fun getProblemInfo(): ProblemInfo {
return RestProblem(
"http://localhost:$sutPort/openapi-bbadvancedformats.json",
null
)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package org.evomaster.e2etests.spring.rest.bb.advancedformats

import com.foo.rest.examples.bb.advancedformats.BBAdvancedFormatsController
import com.foo.rest.examples.bb.exampleobject.BBExampleObjectController
import org.evomaster.core.output.OutputFormat
import org.evomaster.core.problem.rest.data.HttpVerb
import org.evomaster.core.problem.rest.param.BodyParam
import org.evomaster.e2etests.spring.rest.bb.SpringTestBase
import org.evomaster.e2etests.utils.EnterpriseTestBase
import org.junit.jupiter.api.Assertions.assertTrue
import org.junit.jupiter.api.BeforeAll
import org.junit.jupiter.params.ParameterizedTest
import org.junit.jupiter.params.provider.EnumSource

class BBAdvancedFormatsEMTest : SpringTestBase() {

companion object {
init {
shouldApplyInstrumentation = false
}

@BeforeAll
@JvmStatic
fun init() {
initClass(BBAdvancedFormatsController())
}
}

@ParameterizedTest
@EnumSource
fun testBlackBoxOutput(outputFormat: OutputFormat) {

executeAndEvaluateBBTest(
outputFormat,
"advancedformats",
100,
3,
listOf("uuid","uri","email")
){ args: MutableList<String> ->

setOption(args, "schema", "$baseUrlOfSut/openapi-bbadvancedformats.json")
setOption(args, "enableAdvancedFormats", "true")

val solution = initAndRun(args)

assertTrue(solution.individuals.size >= 1)
assertHasAtLeastOne(solution, HttpVerb.GET, 200, "/api/advancedformats/uuid", "OK")
assertHasAtLeastOne(solution, HttpVerb.GET, 200, "/api/advancedformats/uri", "OK")
assertHasAtLeastOne(solution, HttpVerb.GET, 200, "/api/advancedformats/email", "OK")
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public void testDeterminismOfLog(boolean enableConstraintHandling){
OpenAPI schema = (new OpenAPIParser()).readLocation("swagger-ahm/ahm.json", null, null).getOpenAPI();
isDeterminismConsumer( new ArrayList<>(), (args) -> RestActionBuilderV3.INSTANCE
.getModelsFromSwagger(schema, new LinkedHashMap<>(),
new RestActionBuilderV3.Options(false,enableConstraintHandling,false,0.0,0.0,true)));
new RestActionBuilderV3.Options(false,enableConstraintHandling,false,0.0,0.0,true,false)));
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public void testDeterminismOfLog(boolean enableConstraintHandling){
OpenAPI schema = (new OpenAPIParser()).readLocation("swagger-ahm/ahm.json", null, null).getOpenAPI();
isDeterminismConsumer( new ArrayList<>(), (args) -> {
RestActionBuilderV3.INSTANCE.getModelsFromSwagger(schema, new LinkedHashMap<>(),
new RestActionBuilderV3.Options(false,enableConstraintHandling,false,0.0,0.0,true));
new RestActionBuilderV3.Options(false,enableConstraintHandling,false,0.0,0.0,true,false));
});
}

Expand Down
4 changes: 4 additions & 0 deletions core/src/main/kotlin/org/evomaster/core/EMConfig.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2906,6 +2906,10 @@ class EMConfig {
@Cfg("Whether to employ constraints specified in API schema (e.g., OpenAPI) in test generation")
var enableSchemaConstraintHandling = true

@Experimental
@Cfg("Whether to enable the handling of new type formats in OpenAPI schemas, e.g., the ones introduced in 3.1.0")
var enableAdvancedFormats = false

@Cfg("a probability of enabling single insertion strategy to insert rows into database.")
@Probability(activating = true)
var probOfEnablingSingleInsertionForTable = 0.5
Expand Down
Loading