Skip to content
Merged
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public void runEMTest() throws Throwable {
runTestHandlingFlakyAndCompilation(
"GenomeNexusExampleGeneratedEMTest",
"org.bar.GenomeNexusExampleGeneratedEMTest",
500,
2000,
true,
(args) -> {
Solution<RestIndividual> solution = initAndRun(args);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public void runEMTest() throws Throwable {
runTestHandlingFlakyAndCompilation(
"ProxyPrintExampleGeneratedEMTest",
"org.foo.ProxyPrintExampleGeneratedEMTest",
5_000,
7_000,
true,
(args) -> {
setOption(args, "taintForceSelectionOfGenesWithSpecialization", "true");
Expand All @@ -34,7 +34,7 @@ public void runEMTest() throws Throwable {

assertHasAtLeastOne(solution, HttpVerb.POST, 200, "/api/json", "Printing");
},
3
6
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ public void testFindOneOnGivenEndpoint(String endpoint) throws Throwable {
assertFalse(solution.getIndividuals().isEmpty());
assertHasAtLeastOne(solution, HttpVerb.GET, 400, endpoint, null);
assertHasAtLeastOne(solution, HttpVerb.GET, 200, endpoint, null);
});
},
6);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package com.foo.rest.examples.spring.openapi.v3.namedexample

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.PostMapping
import org.springframework.web.bind.annotation.RequestBody
import org.springframework.web.bind.annotation.RequestMapping
import org.springframework.web.bind.annotation.RequestParam
import org.springframework.web.bind.annotation.RestController
import javax.ws.rs.QueryParam

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


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


@PostMapping
open fun post(
@QueryParam("q0") q0: String?,
@QueryParam("q1") q1: String?,
@QueryParam("q2") q2: String?,
@QueryParam("q3") q3: String?,
@QueryParam("q4") q4: String?,
@RequestBody dto: NamedExampleDto
) : ResponseEntity<String> {

//on purpose do nothing with input... should still be selected in test suites due to BB coverage

return ResponseEntity.ok("OK")
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.foo.rest.examples.spring.openapi.v3.namedexample

class NamedExampleDto {

var data : String? = null
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
openapi: 3.1.0
info:
title: OpenAPI definition
version: v0
servers:
- url: http://localhost:8080
description: Generated server url
paths:
/api/namedexample:
post:
tags:
- named-example-application
operationId: post
parameters:
- name: q0
in: query
required: false
schema:
type: string
examples:
foo:
value: "fooq0"
- name: q1
in: query
required: false
schema:
type: string
examples:
foo:
value: "fooq1"
a0:
value: "X"
a1:
value: "X"
a2:
value: "X"
a3:
value: "X"
a4:
value: "X"
a5:
value: "X"
a6:
value: "X"
a7:
value: "X"
a8:
value: "X"
a9:
value: "X"
- name: q2
in: query
required: false
schema:
type: string
examples:
foo:
value: "fooq2"
b0:
value: "X"
b1:
value: "X"
b2:
value: "X"
b3:
value: "X"
b4:
value: "X"
b5:
value: "X"
b6:
value: "X"
b7:
value: "X"
b8:
value: "X"
b9:
value: "X"
- name: q3
in: query
required: false
schema:
type: string
examples:
foo:
value: "fooq3"
c0:
value: "X"
c1:
value: "X"
c2:
value: "X"
c3:
value: "X"
c4:
value: "X"
c5:
value: "X"
c6:
value: "X"
c7:
value: "X"
c8:
value: "X"
c9:
value: "X"
- name: q4
in: query
required: false
schema:
type: string
examples:
foo:
value: "fooq4"
a0:
value: "X"
a1:
value: "X"
requestBody:
required: true
content:
application/json:
schema:
$ref: '#/components/schemas/NamedExampleDto'
examples:
foo:
value:
data: "fooBody"
responses:
'200':
description: OK
content:
'*/*':
schema:
type: string
components:
schemas:
NamedExampleDto:
type: object
properties:
data:
type: string
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.foo.rest.examples.spring.openapi.v3.namedexample

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 NamedExampleController : SpringController(NamedExampleApplication::class.java){


override fun getProblemInfo(): ProblemInfo {
return RestProblem(
"http://localhost:$sutPort/openapi-named-example.yaml",
null
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class MapDoubleGsonEMTest : SpringTestBase() {
fun basicEMTest() {
runTestHandlingFlakyAndCompilation(
"MapDoubleGsonEMTestGenerated",
1_000
2_000
) { args: List<String> ->

setOption(args, "taintForceSelectionOfGenesWithSpecialization", "true")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class MapDoubleJacksonEMTest : SpringTestBase() {
fun basicEMTest() {
runTestHandlingFlakyAndCompilation(
"MapDoubleJacksonEM",
1000
2000
) { args: List<String> ->

setOption(args, "taintForceSelectionOfGenesWithSpecialization", "true")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class MapListIntJacksonEMTest : SpringTestBase() {
fun basicEMTest() {
runTestHandlingFlakyAndCompilation(
"MapListIntJacksonEM",
2000
3000
) { args: List<String> ->

setOption(args, "taintForceSelectionOfGenesWithSpecialization", "true")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package org.evomaster.e2etests.spring.openapi.v3.namedexample

import com.foo.rest.examples.spring.openapi.v3.namedexample.NamedExampleController
import junit.framework.TestCase.assertTrue
import org.evomaster.core.problem.rest.data.HttpVerb
import org.evomaster.core.search.service.IdMapper
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 NamedExampleEMTest : SpringTestBase(){

companion object {
@BeforeAll
@JvmStatic
fun init() {
initClass(NamedExampleController())
}
}

@Test
fun testRunEM() {
runTestHandlingFlakyAndCompilation(
"NamedExampleEM",
200,
) { args: MutableList<String> ->

val (injector, solution) = initAndDebug(args)

Assertions.assertTrue(solution.individuals.size >= 1)
assertHasAtLeastOne(solution, HttpVerb.POST, 200, "/api/namedexample", "OK")

val fv = solution.overall

val idMapper = injector.getInstance(IdMapper::class.java)
val covered = fv.coveredTargets().any{ IdMapper.isNamedExample(idMapper.getDescriptiveId(it))}
Assertions.assertTrue(covered)
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class JsonColumnEMTest : SpringRestPostgresTestBase(){
runTestHandlingFlakyAndCompilation(
"JsonColumnEM",
"org.bar.JsonColumnEM",
10
100
) { args ->
val solution = initAndRun(args)

Expand All @@ -47,4 +47,4 @@ class JsonColumnEMTest : SpringRestPostgresTestBase(){
})
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ class OneMaxMutator {
m.close()

val tp = reportFP(config.mutatedGeneFile, improve)
val covered = solution.overall.coveredTargets() * 1.0 /n
val covered = solution.overall.numberOfCoveredTargets() * 1.0 /n

val result = Pair(tp, covered)
map.getOrPut(expId){ mutableListOf()}.add(result)
Expand All @@ -125,4 +125,4 @@ class OneMaxMutator {

fun main(array: Array<String>){
OneMaxMutator().mutatorExp()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ public static void initClass() throws Exception {
}

@Test
public void testRunEM() throws Throwable {
public void JsonEMTest_testRunEM() throws Throwable {

runTestHandlingFlakyAndCompilation(
"JsonEMTest",
5_000,
5,
10_000,
6,
(args) -> {

setOption(args, "taintForceSelectionOfGenesWithSpecialization", "true");
Expand Down
5 changes: 5 additions & 0 deletions core/src/main/kotlin/org/evomaster/core/EMConfig.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2836,6 +2836,11 @@ class EMConfig {
@Probability(true)
var probRestExamples = 0.20

@Cfg("If any action contains any named example, make sure, with a given probability, that ALL fields for that example" +
" are using the provided values by the user")
@Probability(false)
var probNamedExamples = 0.50

@Cfg("In REST, enable the supports of 'links' between resources defined in the OpenAPI schema, if any." +
" When sampling a test case, if the last call has links, given this probability new calls are" +
" added for the link.")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ class SortingHelper {
* The purpose is to give an example of sorting based on fitness information.
*/
private val coveredTargets: Comparator<EvaluatedIndividual<*>> = compareBy {
it.fitness.coveredTargets()
it.fitness.numberOfCoveredTargets()
}

/**
Expand Down
Loading
Loading