@@ -6,6 +6,7 @@ import org.evomaster.core.problem.rest.data.RestCallAction
66import org.evomaster.core.problem.rest.data.RestCallResult
77import org.evomaster.core.problem.rest.classifier.AIModel
88import org.evomaster.core.problem.rest.classifier.AIResponseClassification
9+ import org.evomaster.core.problem.rest.classifier.InputFieldType
910import org.evomaster.core.problem.rest.classifier.quantifier.ModelEvaluation
1011import org.evomaster.core.problem.rest.classifier.deterministic.Deterministic400Classifier
1112import org.evomaster.core.problem.rest.classifier.probabilistic.gaussian.Gaussian400Classifier
@@ -14,6 +15,8 @@ import org.evomaster.core.problem.rest.classifier.probabilistic.kde.KDE400Classi
1415import org.evomaster.core.problem.rest.classifier.probabilistic.knn.KNN400Classifier
1516import org.evomaster.core.problem.rest.classifier.probabilistic.nn.NN400Classifier
1617import org.evomaster.core.problem.rest.data.Endpoint
18+ import org.evomaster.core.problem.rest.param.BodyParam
19+ import org.evomaster.core.search.gene.ObjectGene
1720import org.evomaster.core.search.service.Randomness
1821import org.slf4j.Logger
1922import org.slf4j.LoggerFactory
@@ -295,20 +298,49 @@ class AIResponseClassifier : AIModel {
295298 return
296299 }
297300 }
298- // TODO
299301 }
300302
301303 private fun repairAction (
302304 call : RestCallAction ,
303305 classification : AIResponseClassification
304306 ) {
305- call.randomize(randomness, true )
306-
307307 /*
308- TODO: in the future we might want to only modify the variables that break the constraints.
308+ We might want to only modify the variables that break the constraints.
309309 This information might be available when using a Decision Tree, but likely not for a Neural Network.
310- Anyway, AIResponseClassification would need to be extended to handle this extra info, when available.
311310 */
311+ if (classification.invalidFields.isEmpty()) {
312+ // no info available
313+ call.randomize(randomness, true )
314+ return
315+ }
316+
317+ for (field in classification.invalidFields) {
318+ when (field.type) {
319+
320+ InputFieldType .QUERY -> {
321+ val param = call.parameters.find { it.name == field.name }
322+ ? : throw IllegalStateException (" Field '${field.name} ' is not referring to any valid query parameter" )
323+ param.seeGenes()
324+ .filter { it.isMutable() }
325+ .forEach { it.randomize(randomness, true ) }
326+ }
327+
328+ InputFieldType .BODY -> {
329+ val body = call.parameters.find{ it is BodyParam }
330+ ? : throw IllegalStateException (" Using field in body but no payload is defined" )
331+ if (field.isWholeBody()){
332+ body.primaryGene().randomize(randomness, true )
333+ } else {
334+ // TODO if we going to handle other types of genes in payload, we need to extend this
335+ val payload = body.primaryGene() as ObjectGene
336+ val target = payload.getField(field.name)
337+ ? : throw IllegalStateException (" Field '${field.name} ' is not referring to any valid payload" )
338+ target.randomize(randomness, true )
339+ }
340+ }
341+ }
342+ }
343+ call.postRandomizedChecks(randomness)
312344 }
313345
314346 /* *
0 commit comments