Skip to content
Permalink
Browse files

Changes related to pull request.

  • Loading branch information...
bogdanmarculescu committed Sep 26, 2019
1 parent 0d11f0b commit 32950ff1334b8c5e524aa47f06c186944b4e8f9f
Showing with 102 additions and 86 deletions.
  1. +3 −3 core/src/main/kotlin/org/evomaster/core/output/TestCaseWriter.kt
  2. +2 −3 core/src/main/kotlin/org/evomaster/core/problem/rest/service/AbstractRestFitness.kt
  3. +1 −1 core/src/main/kotlin/org/evomaster/core/search/gene/ArrayGene.kt
  4. +1 −1 core/src/main/kotlin/org/evomaster/core/search/gene/Base64StringGene.kt
  5. +1 −1 core/src/main/kotlin/org/evomaster/core/search/gene/BooleanGene.kt
  6. +1 −1 core/src/main/kotlin/org/evomaster/core/search/gene/CycleObjectGene.kt
  7. +1 −1 core/src/main/kotlin/org/evomaster/core/search/gene/DateGene.kt
  8. +1 −1 core/src/main/kotlin/org/evomaster/core/search/gene/DateTimeGene.kt
  9. +1 −1 core/src/main/kotlin/org/evomaster/core/search/gene/DisruptiveGene.kt
  10. +1 −1 core/src/main/kotlin/org/evomaster/core/search/gene/DoubleGene.kt
  11. +1 −1 core/src/main/kotlin/org/evomaster/core/search/gene/EnumGene.kt
  12. +1 −1 core/src/main/kotlin/org/evomaster/core/search/gene/FloatGene.kt
  13. +1 −1 core/src/main/kotlin/org/evomaster/core/search/gene/Gene.kt
  14. +18 −12 core/src/main/kotlin/org/evomaster/core/search/gene/GeneUtils.kt
  15. +1 −1 core/src/main/kotlin/org/evomaster/core/search/gene/ImmutableDataHolderGene.kt
  16. +1 −1 core/src/main/kotlin/org/evomaster/core/search/gene/IntegerGene.kt
  17. +1 −1 core/src/main/kotlin/org/evomaster/core/search/gene/LongGene.kt
  18. +1 −1 core/src/main/kotlin/org/evomaster/core/search/gene/MapGene.kt
  19. +3 −3 core/src/main/kotlin/org/evomaster/core/search/gene/ObjectGene.kt
  20. +1 −1 core/src/main/kotlin/org/evomaster/core/search/gene/OptionalGene.kt
  21. +4 −5 core/src/main/kotlin/org/evomaster/core/search/gene/StringGene.kt
  22. +1 −1 core/src/main/kotlin/org/evomaster/core/search/gene/TimeGene.kt
  23. +2 −1 core/src/main/kotlin/org/evomaster/core/search/gene/regex/AnyCharacterRxGene.kt
  24. +2 −1 core/src/main/kotlin/org/evomaster/core/search/gene/regex/CharacterClassEscapeRxGene.kt
  25. +2 −1 core/src/main/kotlin/org/evomaster/core/search/gene/regex/CharacterRangeRxGene.kt
  26. +2 −1 core/src/main/kotlin/org/evomaster/core/search/gene/regex/DisjunctionListRxGene.kt
  27. +2 −1 core/src/main/kotlin/org/evomaster/core/search/gene/regex/DisjunctionRxGene.kt
  28. +2 −1 core/src/main/kotlin/org/evomaster/core/search/gene/regex/PatternCharacterBlock.kt
  29. +2 −1 core/src/main/kotlin/org/evomaster/core/search/gene/regex/QuantifierRxGene.kt
  30. +2 −2 core/src/main/kotlin/org/evomaster/core/search/gene/regex/RegexGene.kt
  31. +2 −1 core/src/main/kotlin/org/evomaster/core/search/gene/sql/SqlAutoIncrementGene.kt
  32. +2 −1 core/src/main/kotlin/org/evomaster/core/search/gene/sql/SqlForeignKeyGene.kt
  33. +4 −2 core/src/main/kotlin/org/evomaster/core/search/gene/sql/SqlJSONGene.kt
  34. +2 −1 core/src/main/kotlin/org/evomaster/core/search/gene/sql/SqlNullable.kt
  35. +2 −1 core/src/main/kotlin/org/evomaster/core/search/gene/sql/SqlPrimaryKeyGene.kt
  36. +2 −1 core/src/main/kotlin/org/evomaster/core/search/gene/sql/SqlUUIDGene.kt
  37. +3 −2 core/src/main/kotlin/org/evomaster/core/search/gene/sql/SqlXMLGene.kt
  38. +1 −1 core/src/test/kotlin/org/evomaster/core/database/extract/postgres/SqlXMLColumnTest.kt
  39. +4 −5 core/src/test/kotlin/org/evomaster/core/output/formatter/OutputFormatterTest.kt
  40. +7 −8 core/src/test/kotlin/org/evomaster/core/search/gene/GeneUtilsEscapeTest.kt
  41. +8 −8 core/src/test/kotlin/org/evomaster/core/search/gene/ObjectGeneTest.kt
  42. +2 −2 e2e-tests/spring-examples/src/test/java/org/evomaster/e2etests/spring/examples/sort/SortEMTest.java
  43. +0 −1 experiments/src/main/kotlin/org/evomaster/experiments/objects/service/ObjFitness.kt
@@ -574,9 +574,9 @@ class TestCaseWriter {
if (bodyParam.isJson()) {

val body = if (readable) {
OutputFormatter.JSON_FORMATTER.getFormatted(bodyParam.gene.getValueAsPrintableString(mode = "JSON", targetFormat = format))
OutputFormatter.JSON_FORMATTER.getFormatted(bodyParam.gene.getValueAsPrintableString(mode = GeneUtils.EscapeMode.JSON, targetFormat = format))
} else {
bodyParam.gene.getValueAsPrintableString(mode = "JSON", targetFormat = format)
bodyParam.gene.getValueAsPrintableString(mode = GeneUtils.EscapeMode.JSON, targetFormat = format)
}

//needed as JSON uses ""
@@ -612,7 +612,7 @@ class TestCaseWriter {
val body = bodyParam.gene.getValueAsPrintableString("xml")
lines.add(".body(\"$body\")")
} */ else if (bodyParam.isTextPlain()) {
val body = bodyParam.gene.getValueAsPrintableString(mode = "text", targetFormat = format)
val body = bodyParam.gene.getValueAsPrintableString(mode = GeneUtils.EscapeMode.TEXT, targetFormat = format)
if (body != "\"\"") {
lines.add(".body($body)")
}
@@ -3,7 +3,6 @@ package org.evomaster.core.problem.rest.service
import com.google.inject.Inject
import org.evomaster.client.java.controller.api.EMTestUtils
import org.evomaster.client.java.controller.api.dto.*
import org.evomaster.core.EMConfig
import org.evomaster.core.database.DatabaseExecution
import org.evomaster.core.problem.rest.*
import org.evomaster.core.problem.rest.auth.NoAuth
@@ -343,9 +342,9 @@ abstract class AbstractRestFitness<T> : FitnessFunction<T>() where T : Individua

val bodyEntity = if (body != null && body is BodyParam) {
val mode = when {
body.isJson() -> "json"
body.isJson() -> GeneUtils.EscapeMode.JSON
//body.isXml() -> "xml" // might have to handle here: <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
body.isTextPlain() -> "text"
body.isTextPlain() -> GeneUtils.EscapeMode.TEXT
else -> throw IllegalStateException("Cannot handle body type: " + body.contentType())
}
Entity.entity(body.gene.getValueAsPrintableString(mode = mode, targetFormat = configuration.outputFormat), body.contentType())
@@ -77,7 +77,7 @@ class ArrayGene<T>(
}
}

override fun getValueAsPrintableString(previousGenes: List<Gene>, mode: String?, targetFormat: OutputFormat?): String {
override fun getValueAsPrintableString(previousGenes: List<Gene>, mode: GeneUtils.EscapeMode?, targetFormat: OutputFormat?): String {
return "[" +
elements.map { g -> g.getValueAsPrintableString(previousGenes, mode, targetFormat) }.joinToString(", ") +
"]"
@@ -20,7 +20,7 @@ class Base64StringGene(
data.standardMutation(randomness, apc, allGenes)
}

override fun getValueAsPrintableString(previousGenes: List<Gene>, mode: String?, targetFormat: OutputFormat?): String {
override fun getValueAsPrintableString(previousGenes: List<Gene>, mode: GeneUtils.EscapeMode?, targetFormat: OutputFormat?): String {
return Base64.getEncoder().encodeToString(data.value.toByteArray())
}

@@ -27,7 +27,7 @@ class BooleanGene(name: String, var value: Boolean = true) : Gene(name) {
value = ! value
}

override fun getValueAsPrintableString(previousGenes: List<Gene>, mode: String?, targetFormat: OutputFormat?): String {
override fun getValueAsPrintableString(previousGenes: List<Gene>, mode: GeneUtils.EscapeMode?, targetFormat: OutputFormat?): String {
return value.toString()
}

@@ -29,7 +29,7 @@ class CycleObjectGene(name: String) : ObjectGene(name, listOf()) {
randomize(randomness, true, allGenes)
}

override fun getValueAsPrintableString(previousGenes: List<Gene>, mode: String?, targetFormat: OutputFormat?): String {
override fun getValueAsPrintableString(previousGenes: List<Gene>, mode: GeneUtils.EscapeMode?, targetFormat: OutputFormat?): String {
throw IllegalStateException("CycleObjectGene has no value")
}

@@ -49,7 +49,7 @@ class DateGene(

}

override fun getValueAsPrintableString(previousGenes: List<Gene>, mode: String?, targetFormat: OutputFormat?): String {
override fun getValueAsPrintableString(previousGenes: List<Gene>, mode: GeneUtils.EscapeMode?, targetFormat: OutputFormat?): String {
return "\"${getValueAsRawString()}\""
}

@@ -48,7 +48,7 @@ open class DateTimeGene(
gene.standardMutation(randomness, apc, allGenes)
}

override fun getValueAsPrintableString(previousGenes: List<Gene>, mode: String?, targetFormat: OutputFormat?): String {
override fun getValueAsPrintableString(previousGenes: List<Gene>, mode: GeneUtils.EscapeMode?, targetFormat: OutputFormat?): String {
return "\"${getValueAsRawString()}\""
}

@@ -34,7 +34,7 @@ class DisruptiveGene<out T>(name: String, val gene: T, var probability: Double)
}
}

override fun getValueAsPrintableString(previousGenes: List<Gene>, mode: String?, targetFormat: OutputFormat?): String {
override fun getValueAsPrintableString(previousGenes: List<Gene>, mode: GeneUtils.EscapeMode?, targetFormat: OutputFormat?): String {
return gene.getValueAsPrintableString(previousGenes, mode, targetFormat)
}

@@ -35,7 +35,7 @@ class DoubleGene(name: String,

}

override fun getValueAsPrintableString(previousGenes: List<Gene>, mode: String?, targetFormat: OutputFormat?): String {
override fun getValueAsPrintableString(previousGenes: List<Gene>, mode: GeneUtils.EscapeMode?, targetFormat: OutputFormat?): String {
return value.toString()
}

@@ -47,7 +47,7 @@ class EnumGene<T>(
index = next
}

override fun getValueAsPrintableString(previousGenes: List<Gene>, mode: String?, targetFormat: OutputFormat?): String {
override fun getValueAsPrintableString(previousGenes: List<Gene>, mode: GeneUtils.EscapeMode?, targetFormat: OutputFormat?): String {

val res = values[index]
if(res is String){
@@ -35,7 +35,7 @@ class FloatGene(name: String,
value = k.toFloat()
}

override fun getValueAsPrintableString(previousGenes: List<Gene>, mode: String?, targetFormat: OutputFormat?): String {
override fun getValueAsPrintableString(previousGenes: List<Gene>, mode: GeneUtils.EscapeMode?, targetFormat: OutputFormat?): String {
return value.toString()
}

@@ -95,7 +95,7 @@ abstract class Gene(var name: String) {
*/
abstract fun getValueAsPrintableString(
previousGenes: List<Gene> = listOf(),
mode: String? = null,
mode: GeneUtils.EscapeMode? = null,
targetFormat: OutputFormat? = null
) : String

@@ -3,8 +3,9 @@ package org.evomaster.core.search.gene
import org.evomaster.core.output.OutputFormat
import org.evomaster.core.search.service.AdaptiveParameterControl
import org.evomaster.core.search.service.Randomness
import java.net.URLEncoder
import kotlin.math.pow

import org.apache.commons.lang3.StringEscapeUtils

object GeneUtils {

@@ -13,23 +14,26 @@ object GeneUtils {
*/
private val intpow2 = (0..30).map { 2.0.pow(it).toInt() }


/**
* The [EscapeMode] enum is here to clarify the supported types of Escape modes.
*
* Different purposes require different modes of escape (e.g. URI may require percent encoding). This is to
* keep track of what modes are supported and how they map to the respective implementations.
*
* Any mode that is not supported will go under NONE, and will result in no escapes being applied at all. The
* purpose is to ensure that, even if the mode being used is unsupported, the system will not throw an exception.
* It may not behave as desired, but it should not crash.
*
*/
enum class EscapeMode {
/**
* The [EscapeMode] enum is here to clarify the supported types of Escape modes.
*
* Different purposes require different modes of escape (e.g. URI may require percent encoding). This is to
* keep track of what modes are supported and how they map to the respective implementations.
*
* Any mode that is not supported will go under NONE, and will result in no escapes being applied at all. The
* purpose is to ensure that, even if the mode being used is unsupported, the system will not throw an exception.
* It may not behave as desired, but it should not crash.
*
*/

URI,
SQL,
ASSERTION,
JSON,
TEXT,
XML,
NONE
}

@@ -166,6 +170,7 @@ object GeneUtils {
EscapeMode.JSON -> applyJsonEscapes(string, format)
EscapeMode.TEXT -> applyTextEscapes(string, format)
EscapeMode.NONE -> string
EscapeMode.XML -> StringEscapeUtils.escapeXml(string)
}
//if(forQueries) return applyQueryEscapes(string, format)
//else return applyAssertionEscapes(string, format)
@@ -191,6 +196,7 @@ object GeneUtils {
}

fun applyUriEscapes(string: String, format: OutputFormat):String{
//val ret = URLEncoder.encode(string, "utf-8")
val ret = string.replace("\\", "%5C")
.replace("\"", "%22")
.replace("\n", "%0A")
@@ -32,7 +32,7 @@ class ImmutableDataHolderGene(name: String, val value: String, val inQuotes: Boo
throw IllegalStateException("Not supposed to modify an immutable gene")
}

override fun getValueAsPrintableString(previousGenes: List<Gene>, mode: String?, targetFormat: OutputFormat?): String {
override fun getValueAsPrintableString(previousGenes: List<Gene>, mode: GeneUtils.EscapeMode?, targetFormat: OutputFormat?): String {

if(inQuotes){
return "\"$value\""
@@ -91,7 +91,7 @@ class IntegerGene(

}

override fun getValueAsPrintableString(previousGenes: List<Gene>, mode: String?, targetFormat: OutputFormat?): String {
override fun getValueAsPrintableString(previousGenes: List<Gene>, mode: GeneUtils.EscapeMode?, targetFormat: OutputFormat?): String {
return value.toString()
}
}
@@ -42,7 +42,7 @@ class LongGene(
value += (sign * delta)
}

override fun getValueAsPrintableString(previousGenes: List<Gene>, mode: String?, targetFormat: OutputFormat?): String {
override fun getValueAsPrintableString(previousGenes: List<Gene>, mode: GeneUtils.EscapeMode?, targetFormat: OutputFormat?): String {
return value.toString()
}

@@ -82,7 +82,7 @@ class MapGene<T>(
}
}

override fun getValueAsPrintableString(previousGenes: List<Gene>, mode: String?, targetFormat: OutputFormat?): String {
override fun getValueAsPrintableString(previousGenes: List<Gene>, mode: GeneUtils.EscapeMode?, targetFormat: OutputFormat?): String {
return "{" +
elements.filter { f ->
f !is CycleObjectGene &&
@@ -53,12 +53,12 @@ open class ObjectGene(name: String, val fields: List<out Gene>, val refType : St
gene.standardMutation(randomness, apc, allGenes)
}

override fun getValueAsPrintableString(previousGenes: List<Gene>, mode: String?, targetFormat: OutputFormat?) : String{
override fun getValueAsPrintableString(previousGenes: List<Gene>, mode: GeneUtils.EscapeMode?, targetFormat: OutputFormat?) : String{

val buffer = StringBuffer()

//by default, return in JSON format
if (mode == null || mode.equals(JSON_MODE, ignoreCase = true)) {
if (mode == null || mode.equals(GeneUtils.EscapeMode.JSON)) {
buffer.append("{")

fields.filter {
@@ -70,7 +70,7 @@ open class ObjectGene(name: String, val fields: List<out Gene>, val refType : St

buffer.append("}")

} else if (mode.equals(XML_MODE, ignoreCase = true)) {
} else if (mode.equals(GeneUtils.EscapeMode.XML)) {

/*
Note: this is a very basic support, which should not really depend
@@ -64,7 +64,7 @@ class OptionalGene(name: String,
}
}

override fun getValueAsPrintableString(previousGenes: List<Gene>, mode: String?, targetFormat: OutputFormat?): String {
override fun getValueAsPrintableString(previousGenes: List<Gene>, mode: GeneUtils.EscapeMode?, targetFormat: OutputFormat?): String {
return gene.getValueAsPrintableString(mode = mode, targetFormat = targetFormat)
}

@@ -10,12 +10,11 @@ import org.evomaster.core.output.OutputFormat
import org.evomaster.core.parser.RegexHandler
import org.evomaster.core.parser.RegexUtils
import org.evomaster.core.search.gene.GeneUtils.getDelta
import org.evomaster.core.search.gene.regex.RegexGene
import org.evomaster.core.search.service.AdaptiveParameterControl
import org.evomaster.core.search.service.Randomness
import org.slf4j.Logger
import org.slf4j.LoggerFactory
import java.util.stream.Collectors
import org.evomaster.core.search.gene.GeneUtils.EscapeMode


class StringGene(
@@ -339,7 +338,7 @@ class StringGene(
}
}

override fun getValueAsPrintableString(previousGenes: List<Gene>, mode: String?, targetFormat: OutputFormat?): String {
override fun getValueAsPrintableString(previousGenes: List<Gene>, mode: EscapeMode?, targetFormat: OutputFormat?): String {

val specializationGene = getSpecializationGene()

@@ -348,14 +347,14 @@ class StringGene(
}

val rawValue = getValueAsRawString()
if (mode != null && mode.equals("xml")) {
if (mode != null && mode.equals(EscapeMode.XML)) {
return StringEscapeUtils.escapeXml(rawValue)
} else {
when {
// TODO this code should be refactored with other getValueAsPrintableString() methods
(targetFormat == null) -> return "\"${rawValue}\""
//"\"${rawValue.replace("\"", "\\\"")}\""
(mode != null) -> return "\"${GeneUtils.applyEscapes(rawValue, GeneUtils.EscapeMode.valueOf(mode.toUpperCase()), targetFormat)}\""
(mode != null) -> return "\"${GeneUtils.applyEscapes(rawValue, mode, targetFormat)}\""
else -> return "\"${GeneUtils.applyEscapes(rawValue, GeneUtils.EscapeMode.TEXT ,targetFormat)}\""
}

@@ -52,7 +52,7 @@ class TimeGene(
gene.standardMutation(randomness, apc, allGenes)
}

override fun getValueAsPrintableString(previousGenes: List<Gene>, mode: String?, targetFormat: OutputFormat?): String {
override fun getValueAsPrintableString(previousGenes: List<Gene>, mode: GeneUtils.EscapeMode?, targetFormat: OutputFormat?): String {
return "\"${getValueAsRawString()}\""
}

@@ -2,6 +2,7 @@ package org.evomaster.core.search.gene.regex

import org.evomaster.core.output.OutputFormat
import org.evomaster.core.search.gene.Gene
import org.evomaster.core.search.gene.GeneUtils
import org.evomaster.core.search.service.AdaptiveParameterControl
import org.evomaster.core.search.service.Randomness

@@ -25,7 +26,7 @@ class AnyCharacterRxGene : RxAtom("."){
randomize(randomness, true, allGenes)
}

override fun getValueAsPrintableString(previousGenes: List<Gene>, mode: String?, targetFormat: OutputFormat?): String {
override fun getValueAsPrintableString(previousGenes: List<Gene>, mode: GeneUtils.EscapeMode?, targetFormat: OutputFormat?): String {
/*
TODO should \ be handled specially?
*/
@@ -2,6 +2,7 @@ package org.evomaster.core.search.gene.regex

import org.evomaster.core.output.OutputFormat
import org.evomaster.core.search.gene.Gene
import org.evomaster.core.search.gene.GeneUtils
import org.evomaster.core.search.service.AdaptiveParameterControl
import org.evomaster.core.search.service.Randomness

@@ -56,7 +57,7 @@ class CharacterClassEscapeRxGene(
}
}

override fun getValueAsPrintableString(previousGenes: List<Gene>, mode: String?, targetFormat: OutputFormat?): String {
override fun getValueAsPrintableString(previousGenes: List<Gene>, mode: GeneUtils.EscapeMode?, targetFormat: OutputFormat?): String {
return value
}

@@ -2,6 +2,7 @@ package org.evomaster.core.search.gene.regex

import org.evomaster.core.output.OutputFormat
import org.evomaster.core.search.gene.Gene
import org.evomaster.core.search.gene.GeneUtils
import org.evomaster.core.search.service.AdaptiveParameterControl
import org.evomaster.core.search.service.Randomness

@@ -78,7 +79,7 @@ class CharacterRangeRxGene(
}
}

override fun getValueAsPrintableString(previousGenes: List<Gene>, mode: String?, targetFormat: OutputFormat?): String {
override fun getValueAsPrintableString(previousGenes: List<Gene>, mode: GeneUtils.EscapeMode?, targetFormat: OutputFormat?): String {
/*
TODO should \ be handled specially?
In any case, would have same handling as AnyCharacterRxGene
@@ -2,6 +2,7 @@ package org.evomaster.core.search.gene.regex

import org.evomaster.core.output.OutputFormat
import org.evomaster.core.search.gene.Gene
import org.evomaster.core.search.gene.GeneUtils
import org.evomaster.core.search.service.AdaptiveParameterControl
import org.evomaster.core.search.service.Randomness

@@ -49,7 +50,7 @@ class DisjunctionListRxGene(

}

override fun getValueAsPrintableString(previousGenes: List<Gene>, mode: String?, targetFormat: OutputFormat?): String {
override fun getValueAsPrintableString(previousGenes: List<Gene>, mode: GeneUtils.EscapeMode?, targetFormat: OutputFormat?): String {
if (disjunctions.isEmpty()) {
return ""
}

0 comments on commit 32950ff

Please sign in to comment.
You can’t perform that action at this time.