Skip to content

Commit 5c36fcc

Browse files
committed
setting up E2E
1 parent 6d44ba3 commit 5c36fcc

5 files changed

Lines changed: 208 additions & 4 deletions

File tree

core-tests/e2e-tests/spring/spring-rest-openapi-v3/src/main/kotlin/com/foo/rest/examples/spring/openapi/v3/namedexample/NamedExampleApplication.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import org.springframework.boot.autoconfigure.SpringBootApplication
55
import org.springframework.boot.autoconfigure.security.servlet.SecurityAutoConfiguration
66
import org.springframework.http.ResponseEntity
77
import org.springframework.web.bind.annotation.GetMapping
8+
import org.springframework.web.bind.annotation.PostMapping
89
import org.springframework.web.bind.annotation.RequestBody
910
import org.springframework.web.bind.annotation.RequestMapping
1011
import org.springframework.web.bind.annotation.RequestParam
@@ -25,8 +26,8 @@ open class NamedExampleApplication {
2526
}
2627

2728

28-
@GetMapping
29-
open fun get(
29+
@PostMapping
30+
open fun post(
3031
@QueryParam("q0") q0: String?,
3132
@QueryParam("q1") q1: String?,
3233
@QueryParam("q2") q2: String?,
Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
1+
openapi: 3.1.0
2+
info:
3+
title: OpenAPI definition
4+
version: v0
5+
servers:
6+
- url: http://localhost:8080
7+
description: Generated server url
8+
paths:
9+
/api/namedexample:
10+
post:
11+
tags:
12+
- named-example-application
13+
operationId: post
14+
parameters:
15+
- name: q0
16+
in: query
17+
required: false
18+
schema:
19+
type: string
20+
examples:
21+
foo:
22+
value: "fooq0"
23+
- name: q1
24+
in: query
25+
required: false
26+
schema:
27+
type: string
28+
examples:
29+
foo:
30+
value: "fooq1"
31+
a0:
32+
value: "X"
33+
a1:
34+
value: "X"
35+
a2:
36+
value: "X"
37+
a3:
38+
value: "X"
39+
a4:
40+
value: "X"
41+
a5:
42+
value: "X"
43+
a6:
44+
value: "X"
45+
a7:
46+
value: "X"
47+
a8:
48+
value: "X"
49+
a9:
50+
value: "X"
51+
- name: q2
52+
in: query
53+
required: false
54+
schema:
55+
type: string
56+
examples:
57+
foo:
58+
value: "fooq2"
59+
b0:
60+
value: "X"
61+
b1:
62+
value: "X"
63+
b2:
64+
value: "X"
65+
b3:
66+
value: "X"
67+
b4:
68+
value: "X"
69+
b5:
70+
value: "X"
71+
b6:
72+
value: "X"
73+
b7:
74+
value: "X"
75+
b8:
76+
value: "X"
77+
b9:
78+
value: "X"
79+
- name: q3
80+
in: query
81+
required: false
82+
schema:
83+
type: string
84+
examples:
85+
foo:
86+
value: "fooq3"
87+
c0:
88+
value: "X"
89+
c1:
90+
value: "X"
91+
c2:
92+
value: "X"
93+
c3:
94+
value: "X"
95+
c4:
96+
value: "X"
97+
c5:
98+
value: "X"
99+
c6:
100+
value: "X"
101+
c7:
102+
value: "X"
103+
c8:
104+
value: "X"
105+
c9:
106+
value: "X"
107+
- name: q4
108+
in: query
109+
required: false
110+
schema:
111+
type: string
112+
examples:
113+
foo:
114+
value: "fooq4"
115+
a0:
116+
value: "X"
117+
a1:
118+
value: "X"
119+
requestBody:
120+
required: true
121+
content:
122+
application/json:
123+
schema:
124+
$ref: '#/components/schemas/NamedExampleDto'
125+
examples:
126+
foo:
127+
value:
128+
data: "fooBody"
129+
responses:
130+
'200':
131+
description: OK
132+
content:
133+
'*/*':
134+
schema:
135+
type: string
136+
components:
137+
schemas:
138+
NamedExampleDto:
139+
type: object
140+
properties:
141+
data:
142+
type: string
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package com.foo.rest.examples.spring.openapi.v3.namedexample
2+
3+
import com.foo.rest.examples.spring.openapi.v3.SpringController
4+
import org.evomaster.client.java.controller.problem.ProblemInfo
5+
import org.evomaster.client.java.controller.problem.RestProblem
6+
7+
class NamedExampleController : SpringController(NamedExampleApplication::class.java){
8+
9+
10+
override fun getProblemInfo(): ProblemInfo {
11+
return RestProblem(
12+
"http://localhost:$sutPort/openapi-named-example.yaml",
13+
null
14+
)
15+
}
16+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package org.evomaster.e2etests.spring.openapi.v3.namedexample
2+
3+
import com.foo.rest.examples.spring.openapi.v3.namedexample.NamedExampleController
4+
import org.evomaster.core.problem.rest.data.HttpVerb
5+
import org.evomaster.e2etests.spring.openapi.v3.SpringTestBase
6+
import org.junit.jupiter.api.Assertions
7+
import org.junit.jupiter.api.BeforeAll
8+
import org.junit.jupiter.api.Test
9+
10+
class NamedExampleEMTest : SpringTestBase(){
11+
12+
companion object {
13+
@BeforeAll
14+
@JvmStatic
15+
fun init() {
16+
initClass(NamedExampleController())
17+
}
18+
}
19+
20+
@Test
21+
fun testRunEM() {
22+
runTestHandlingFlakyAndCompilation(
23+
"NamedExampleEM",
24+
200,
25+
) { args: MutableList<String> ->
26+
27+
val solution = initAndRun(args)
28+
29+
Assertions.assertTrue(solution.individuals.size >= 1)
30+
assertHasAtLeastOne(solution, HttpVerb.POST, 200, "/object", "OK")
31+
32+
TODO add checks on named example target
33+
}
34+
}
35+
36+
}

core/src/main/kotlin/org/evomaster/core/search/gene/collection/EnumGene.kt

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,17 @@ class EnumGene<T : Comparable<T>>(
7070
log.warn("Enum Gene (name: $name) has empty list of values")
7171
values = listOf()
7272
}else{
73-
val list = data
74-
.toSet() // we want no duplicate
73+
74+
val elements = if(valueNames == null){
75+
// we want no duplicate
76+
data.toSet()
77+
} else {
78+
//if we have named value, then we must not use a set, as there might be duplicates, and
79+
//we would need to know which names map to which duplicated value
80+
data
81+
}
82+
83+
val list = elements
7584
.toList() // need ordering to specify index of selection, so Set would not do
7685
.sorted() // sort, to make meaningful list comparisons
7786
.map { if (it is String) it.intern() as T else it } //if strings, make sure to intern them

0 commit comments

Comments
 (0)