Permalink
Browse files

minor cleaning/refactoring

  • Loading branch information...
arcuri82 committed Nov 24, 2018
1 parent 1e25170 commit 1a03cd2eaa5054f440ed3c2b49e85d7cff1a6555
Showing with 10 additions and 38 deletions.
  1. +4 −4 README.md
  2. +4 −32 core/src/main/kotlin/org/evomaster/core/database/DbAction.kt
  3. +2 −2 pom.xml
@@ -170,9 +170,9 @@ install the snapshot version of the Java client into your local Maven repository
(e.g., under *~/.m2*).
Once the client library is imported, you need to create a class that extends either
`org.evomaster.clientJava.controller.EmbeddedSutController`
`org.evomaster.client.java.controller.EmbeddedSutController`
or
`org.evomaster.clientJava.controller.ExternalSutController`.
`org.evomaster.client.java.controller.ExternalSutController`.
Both these classes extend `SutController`.
The difference is on whether the SUT is started in the same JVM of the EvoMaster
driver (*embedded*), or in a separated JVM (*external*).
@@ -195,7 +195,7 @@ For example, those methods specify how to start the SUT, how it should be stoppe
and how to reset its state.
The EvoMaster Java client library also provides further utility classes to help
writing those controllers/drivers.
For example, `org.evomaster.clientJava.controller.db.DbCleaner` helps in resetting
For example, `org.evomaster.client.java.controller.db.DbCleaner` helps in resetting
the state of a database (if any is used by the SUT).
Until better documentation and tutorials are provided,
@@ -206,7 +206,7 @@ and the existing examples in
Once a class `X` that is a descendant of `SutController` is written, you need
to be able to start the EvoMaster driver, by using the
`org.evomaster.clientJava.controller.InstrumentedSutStarter`
`org.evomaster.client.java.controller.InstrumentedSutStarter`
class.
For example, in the source code of the class `X`, you could add:
@@ -50,42 +50,28 @@ class DbAction(
return true
}
//FIXME need refactoring
fun randomizeDbActionGenes(actions: List<DbAction>, randomness: Randomness) {
/*
At this point, SQL genes are particular, as they can have
references to each other (eg Foreign Keys)
FIXME: refactoring to put such concept at higher level directly in Gene.
And, in any case, shouldn't something specific just for Rest
*/
val all = actions.flatMap { it.seeGenes() }
all.asSequence()
.filter { it.isMutable() }
.forEach {
if (it is SqlPrimaryKeyGene) {
val g = it.gene
if (g is SqlForeignKeyGene) {
g.randomize(randomness, false, all)
} else {
it.randomize(randomness, false)
}
} else if (it is SqlForeignKeyGene) {
it.randomize(randomness, false, all)
} else {
it.randomize(randomness, false)
}
it.randomize(randomness, false, all)
}
if (javaClass.desiredAssertionStatus()) {
//TODO refactor if/when Kotlin will support lazy asserts
//https://youtrack.jetbrains.com/issue/KT-22292
assert(DbAction.verifyForeignKeys(actions))
}
}
private val DEFAULT_MAX_NUMBER_OF_ATTEMPTS_TO_REPAIR_ACTIONS = 5
private const val DEFAULT_MAX_NUMBER_OF_ATTEMPTS_TO_REPAIR_ACTIONS = 5
/**
* Some actions might break schema constraints
@@ -121,7 +107,7 @@ class DbAction(
while (geneToRepair != null && attemptCounter < maxNumberOfAttemptsToRepairAnAction) {
val previousGenes = actions.subList(0, geneToRepairAndActionIndex.second).flatMap { it.seeGenes() }
randomizeGene(geneToRepair, randomness, previousGenes)
geneToRepair.randomize(randomness, true, previousGenes)
if (actionIndexToRepair == previousActionIndexToRepair) {
//
@@ -151,20 +137,6 @@ class DbAction(
}
}
private fun randomizeGene(gene: Gene, randomness: Randomness, previousGenes: List<Gene>) {
when (gene) {
is SqlForeignKeyGene -> gene.randomize(randomness, true, previousGenes)
else ->
if (gene is SqlPrimaryKeyGene && gene.gene is SqlForeignKeyGene) {
//FIXME: this needs refactoring
gene.gene.randomize(randomness, true, previousGenes)
} else {
//TODO other cases
gene.randomize(randomness, true)
}
}
}
/**
* Returns true iff all action are valid wrt the schema.
* For example
@@ -94,7 +94,7 @@
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.version>1.8</java.version>
<kotlin.version>1.3.0</kotlin.version>
<kotlin.version>1.3.10</kotlin.version>
<kotlin.compiler.incremental>true</kotlin.compiler.incremental>
<junit.jupiter.version>5.3.1</junit.jupiter.version>
<junit.platform.version>1.3.1</junit.platform.version>
@@ -482,7 +482,7 @@
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>2.23.0</version>
<version>2.23.4</version>
<scope>test</scope>
</dependency>
</dependencies>

0 comments on commit 1a03cd2

Please sign in to comment.