Skip to content

Commit 0a26b7a

Browse files
committed
fixed handling of cleanup actions in merge
1 parent fb1c9e2 commit 0a26b7a

3 files changed

Lines changed: 48 additions & 9 deletions

File tree

core-tests/integration-tests/core-it/src/test/kotlin/org/evomaster/core/problem/rest/IntegrationTestRestBase.kt

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -49,19 +49,21 @@ abstract class IntegrationTestRestBase : RestTestBase() {
4949
injector = init(args)
5050
}
5151

52-
fun getPirToRest() = injector.getInstance(PirToRest::class.java)
52+
fun getPirToRest() = injector.getInstance(PirToRest::class.java)!!
5353

5454
fun getArchive() = injector.getInstance(Archive::class.java) as Archive<RestIndividual>
5555

5656
fun getSecurityRest() = injector.getInstance(RestSecurityBuilder::class.java) as RestSecurityBuilder
5757

58-
fun getEMConfig() = injector.getInstance(EMConfig::class.java)
58+
fun getEMConfig() = injector.getInstance(EMConfig::class.java)!!
5959

60-
fun getBuilder() = injector.getInstance(RestIndividualBuilder::class.java)
60+
fun getBuilder() = injector.getInstance(RestIndividualBuilder::class.java)!!
6161

62-
fun getSecurityOracle() = injector.getInstance(RestSecurityOracle::class.java)
62+
fun getSecurityOracle() = injector.getInstance(RestSecurityOracle::class.java)!!
6363

64-
fun getExecutionPhaseController() = injector.getInstance(ExecutionPhaseController::class.java)
64+
fun getExecutionPhaseController() = injector.getInstance(ExecutionPhaseController::class.java)!!
65+
66+
fun getFitnessFunction() = injector.getInstance(AbstractRestFitness::class.java)!!
6567

6668
/**
6769
* Create and evaluate an individual
@@ -79,10 +81,10 @@ abstract class IntegrationTestRestBase : RestTestBase() {
7981
*/
8082
val ind = sampler.createIndividual(sampleT, actions.toMutableList())
8183

82-
val ff = injector.getInstance(AbstractRestFitness::class.java)
84+
val ff = getFitnessFunction()
8385
val ei = ff.calculateCoverage(ind)!!
8486

8587
return ei
8688
}
8789

88-
}
90+
}

core-tests/integration-tests/core-it/src/test/kotlin/org/evomaster/core/problem/rest/cleanupuuid/CleanUpUUIDTest.kt

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import com.fasterxml.jackson.databind.ObjectMapper
77
import org.evomaster.core.problem.enterprise.SampleType
88
import org.evomaster.core.problem.rest.IntegrationTestRestBase
99
import org.evomaster.core.problem.rest.data.RestCallResult
10+
import org.evomaster.core.problem.rest.service.RestIndividualBuilder
1011
import org.junit.jupiter.api.Assertions.*
1112
import org.junit.jupiter.api.BeforeAll
1213
import org.junit.jupiter.api.BeforeEach
@@ -258,5 +259,36 @@ class CleanUpUUIDTest: IntegrationTestRestBase() {
258259
}
259260

260261

261-
//TODO merge (various combinations)
262+
@Test
263+
fun testMergePost() {
264+
265+
assertEquals(0, CleanUpUUIDApplication.numberExistingData())
266+
267+
val pirTest = getPirToRest()
268+
269+
val postx = pirTest.fromVerbPath("post", "/api/resources")!!
270+
val x = createIndividual(listOf(postx), SampleType.RANDOM)
271+
val resx = x.evaluatedMainActions()[0].result as RestCallResult
272+
assertEquals(201, resx.getStatusCode())
273+
assertEquals(1, getReturnedSize(resx))
274+
275+
val posty = pirTest.fromVerbPath("post", "/api/resources")!!
276+
val y = createIndividual(listOf(posty), SampleType.RANDOM)
277+
val resy = y.evaluatedMainActions()[0].result as RestCallResult
278+
assertEquals(201, resy.getStatusCode())
279+
assertEquals(1, getReturnedSize(resy))
280+
281+
val m = getBuilder().merge(x.individual,y.individual)
282+
assertEquals(2, m.size())
283+
284+
val z = getFitnessFunction().calculateCoverage(m)!!
285+
286+
assertEquals(2, z.evaluatedMainActions().size)
287+
assertEquals(2, z.individual.seeMainExecutableActions().size)
288+
assertEquals(2, z.individual.seeCleanUpActions().size)
289+
290+
//delete should had been automatically added
291+
assertEquals(0, CleanUpUUIDApplication.numberExistingData())
292+
}
293+
262294
}

core/src/main/kotlin/org/evomaster/core/problem/rest/service/RestIndividualBuilder.kt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,12 +98,17 @@ class RestIndividualBuilder {
9898
*/
9999
fun merge(first: RestIndividual, second: RestIndividual): RestIndividual {
100100

101-
val before = first.seeAllActions().size + second.seeAllActions().size
101+
val before = first.seeAllActions().size + second.seeAllActions().size -
102+
//cleanup actions are going to be removed, as anyway automatically added
103+
//when evaluating fitness... and check for duplicates is done there
104+
first.seeCleanUpActions().size - second.seeCleanUpActions().size
102105

103106
val base = first.copy() as RestIndividual
104107
base.ensureFlattenedStructure()
108+
base.removeAllCleanUp()
105109
val other = second.copy() as RestIndividual
106110
other.ensureFlattenedStructure()
111+
other.removeAllCleanUp()
107112

108113
/*
109114
we need to reset local ids in other, to avoid clashes with ids in base.

0 commit comments

Comments
 (0)