Skip to content

Commit 6b48ffa

Browse files
Fixes for pr
1 parent da93924 commit 6b48ffa

5 files changed

Lines changed: 37 additions & 56 deletions

File tree

core-tests/e2e-tests/spring/spring-rest-openapi-v3/src/test/kotlin/org/evomaster/e2etests/spring/openapi/v3/SpringTestBase.kt

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,16 @@ package org.evomaster.e2etests.spring.openapi.v3
33
import org.evomaster.client.java.controller.InstrumentedSutStarter
44
import org.evomaster.client.java.instrumentation.InputProperties
55
import org.evomaster.client.java.instrumentation.InstrumentingAgent
6+
import org.evomaster.client.java.instrumentation.shared.ClassName
67
import org.evomaster.e2etests.utils.RestTestBase
8+
import org.junit.jupiter.api.Assertions
79
import org.junit.jupiter.api.BeforeAll
10+
import java.util.Optional.ofNullable
11+
import kotlin.reflect.KClass
12+
import kotlin.reflect.KMutableProperty1
13+
import kotlin.reflect.full.createInstance
14+
import kotlin.reflect.full.memberProperties
15+
import kotlin.reflect.jvm.isAccessible
816

917
/**
1018
* Created by arcuri82 on 03-Mar-20.
@@ -25,4 +33,23 @@ abstract class SpringTestBase : RestTestBase(){
2533
}
2634
}
2735

36+
protected fun initDtoClass(name: String): Pair<KClass<out Any>, Any> {
37+
val className = ClassName("org.foo.dto.$name")
38+
val klass = loadClass(className).kotlin
39+
Assertions.assertNotNull(klass)
40+
return Pair(klass, klass.createInstance())
41+
}
42+
43+
protected fun assertProperty(klass: KClass<out Any>, instance: Any, propertyName: String, propertyValue: Any?) {
44+
val property = klass.memberProperties
45+
.firstOrNull { it.name == propertyName } as? KMutableProperty1<Any, Any?>
46+
Assertions.assertNotNull(property)
47+
48+
property?.let {
49+
it.isAccessible = true
50+
it.set(instance, ofNullable(propertyValue))
51+
}
52+
Assertions.assertEquals(ofNullable(propertyValue), property?.get(instance))
53+
}
54+
2855
}

core-tests/e2e-tests/spring/spring-rest-openapi-v3/src/test/kotlin/org/evomaster/e2etests/spring/openapi/v3/jsonpatchobjectvalue/JsonPatchObjectValueDtoEMTest.kt

Lines changed: 4 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,11 @@
11
package org.evomaster.e2etests.spring.openapi.v3.jsonpatchobjectvalue
22

33
import com.foo.rest.examples.spring.openapi.v3.jsonpatchobjectvalue.JsonPatchObjectValueController
4-
import org.evomaster.client.java.instrumentation.shared.ClassName
54
import org.evomaster.core.problem.rest.data.HttpVerb
65
import org.evomaster.e2etests.spring.openapi.v3.SpringTestBase
76
import org.junit.jupiter.api.Assertions
87
import org.junit.jupiter.api.BeforeAll
98
import org.junit.jupiter.api.Test
10-
import java.util.Optional.ofNullable
11-
import kotlin.reflect.KClass
12-
import kotlin.reflect.KMutableProperty1
13-
import kotlin.reflect.full.createInstance
14-
import kotlin.reflect.full.memberProperties
15-
import kotlin.reflect.jvm.isAccessible
169

1710
/**
1811
* E2E test: JSON Patch DTO with a NON-PRIMITIVE value.
@@ -51,6 +44,10 @@ class JsonPatchObjectValueDtoEMTest : SpringTestBase() {
5144
) { args: MutableList<String> ->
5245

5346
setOption(args, "dtoForRequestPayload", "true")
47+
// This SUT intentionally has no authentication, and the PATCH returns 2xx, so the
48+
// security oracle would flag a fault 208 (Anonymous Modifications). It is irrelevant to
49+
// what we assert here (JSON Patch DTO generation), so we disable it to keep the suite clean.
50+
setOption(args, "security", "false")
5451

5552
val solution = initAndRun(args)
5653

@@ -81,23 +78,4 @@ class JsonPatchObjectValueDtoEMTest : SpringTestBase() {
8178
assertProperty(klass, instance, "label", "a label")
8279
assertProperty(klass, instance, "quantity", 7)
8380
}
84-
85-
private fun initDtoClass(name: String): Pair<KClass<out Any>, Any> {
86-
val className = ClassName("org.foo.dto.$name")
87-
val klass = loadClass(className).kotlin
88-
Assertions.assertNotNull(klass)
89-
return Pair(klass, klass.createInstance())
90-
}
91-
92-
private fun assertProperty(klass: KClass<out Any>, instance: Any, propertyName: String, propertyValue: Any?) {
93-
val property = klass.memberProperties
94-
.firstOrNull { it.name == propertyName } as? KMutableProperty1<Any, Any?>
95-
Assertions.assertNotNull(property)
96-
97-
property?.let {
98-
it.isAccessible = true
99-
it.set(instance, ofNullable(propertyValue))
100-
}
101-
Assertions.assertEquals(ofNullable(propertyValue), property?.get(instance))
102-
}
10381
}

core-tests/e2e-tests/spring/spring-rest-openapi-v3/src/test/kotlin/org/evomaster/e2etests/spring/openapi/v3/jsonpatchstringvalue/JsonPatchStringValueDtoEMTest.kt

Lines changed: 4 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,11 @@
11
package org.evomaster.e2etests.spring.openapi.v3.jsonpatchstringvalue
22

33
import com.foo.rest.examples.spring.openapi.v3.jsonpatchstringvalue.JsonPatchStringValueController
4-
import org.evomaster.client.java.instrumentation.shared.ClassName
54
import org.evomaster.core.problem.rest.data.HttpVerb
65
import org.evomaster.e2etests.spring.openapi.v3.SpringTestBase
76
import org.junit.jupiter.api.Assertions
87
import org.junit.jupiter.api.BeforeAll
98
import org.junit.jupiter.api.Test
10-
import java.util.Optional.ofNullable
11-
import kotlin.reflect.KClass
12-
import kotlin.reflect.KMutableProperty1
13-
import kotlin.reflect.full.createInstance
14-
import kotlin.reflect.full.memberProperties
15-
import kotlin.reflect.jvm.isAccessible
169

1710
/**
1811
* E2E test: JSON Patch DTO with a PRIMITIVE (string) value.
@@ -50,6 +43,10 @@ class JsonPatchStringValueDtoEMTest : SpringTestBase() {
5043
) { args: MutableList<String> ->
5144

5245
setOption(args, "dtoForRequestPayload", "true")
46+
// This SUT intentionally has no authentication, and the PATCH returns 2xx, so the
47+
// security oracle would flag a fault 208 (Anonymous Modifications). It is irrelevant to
48+
// what we assert here (JSON Patch DTO generation), so we disable it to keep the suite clean.
49+
setOption(args, "security", "false")
5350

5451
val solution = initAndRun(args)
5552

@@ -72,23 +69,4 @@ class JsonPatchStringValueDtoEMTest : SpringTestBase() {
7269
// A JSON Patch value can be any JSON value; here it is a primitive string inlined as a literal.
7370
assertProperty(klass, instance, "value", "EvoMaster")
7471
}
75-
76-
private fun initDtoClass(name: String): Pair<KClass<out Any>, Any> {
77-
val className = ClassName("org.foo.dto.$name")
78-
val klass = loadClass(className).kotlin
79-
Assertions.assertNotNull(klass)
80-
return Pair(klass, klass.createInstance())
81-
}
82-
83-
private fun assertProperty(klass: KClass<out Any>, instance: Any, propertyName: String, propertyValue: Any?) {
84-
val property = klass.memberProperties
85-
.firstOrNull { it.name == propertyName } as? KMutableProperty1<Any, Any?>
86-
Assertions.assertNotNull(property)
87-
88-
property?.let {
89-
it.isAccessible = true
90-
it.set(instance, ofNullable(propertyValue))
91-
}
92-
Assertions.assertEquals(ofNullable(propertyValue), property?.get(instance))
93-
}
9472
}

core/src/main/kotlin/org/evomaster/core/output/dto/DtoWriter.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,6 @@ class DtoWriter(
138138
dtoClass.addField(GeneToDto.FIELD_PATH, DtoField(GeneToDto.FIELD_PATH, GeneToDto.TYPE_STRING))
139139
dtoClass.addField(GeneToDto.FIELD_FROM, DtoField(GeneToDto.FIELD_FROM, GeneToDto.TYPE_STRING))
140140
dtoClass.addField(GeneToDto.FIELD_VALUE, DtoField(GeneToDto.FIELD_VALUE, anyType()))
141-
dtoCollector[dtoName] = dtoClass
142141

143142
gene.operations.filterIsInstance<JsonPatchPathValueGene>().forEach { operation ->
144143
when (val valueGene = operation.pathValueChoice.activeGene().second.getLeafGene()) {

core/src/main/kotlin/org/evomaster/core/output/dto/GeneToDto.kt

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -116,11 +116,10 @@ class GeneToDto(
116116
val result = mutableListOf<String>()
117117
result.add(dtoOutput.getNewListStatement(JSON_PATCH_OPERATION_DTO, listVarName))
118118

119-
var operationCounter = 1
120-
gene.operations.forEach { operation ->
119+
gene.operations.forEachIndexed { index, operation ->
121120
val childCounter = mutableListOf<Int>().apply {
122121
addAll(counters)
123-
add(operationCounter++)
122+
add(index + 1)
124123
}
125124
val operationCall = getJsonPatchOperationCall(operation, childCounter)
126125
result.addAll(operationCall.objectCalls)

0 commit comments

Comments
 (0)