diff --git a/core/src/main/kotlin/org/evomaster/core/problem/api/ApiWsIndividual.kt b/core/src/main/kotlin/org/evomaster/core/problem/api/ApiWsIndividual.kt index 70326a3ecd..82b4d2fbee 100644 --- a/core/src/main/kotlin/org/evomaster/core/problem/api/ApiWsIndividual.kt +++ b/core/src/main/kotlin/org/evomaster/core/problem/api/ApiWsIndividual.kt @@ -27,7 +27,7 @@ abstract class ApiWsIndividual ( */ children: MutableList, childTypeVerifier: (Class<*>) -> Boolean, - groups : GroupsOfChildren = getEnterpriseTopGroups(children, children.size, 0) + groups : GroupsOfChildren = getEnterpriseTopGroups(children, children.size, 0, 0, 0) ): EnterpriseIndividual(sampleType, trackOperator, index, children, childTypeVerifier, groups){ diff --git a/core/src/main/kotlin/org/evomaster/core/problem/enterprise/EnterpriseIndividual.kt b/core/src/main/kotlin/org/evomaster/core/problem/enterprise/EnterpriseIndividual.kt index e47beda727..74b6a01f8a 100644 --- a/core/src/main/kotlin/org/evomaster/core/problem/enterprise/EnterpriseIndividual.kt +++ b/core/src/main/kotlin/org/evomaster/core/problem/enterprise/EnterpriseIndividual.kt @@ -9,6 +9,7 @@ import org.evomaster.core.sql.SqlActionUtils import org.evomaster.core.mongo.MongoDbAction import org.evomaster.core.problem.api.ApiWsIndividual import org.evomaster.core.problem.externalservice.ApiExternalServiceAction +import org.evomaster.core.problem.externalservice.DnsAction import org.evomaster.core.search.* import org.evomaster.core.search.gene.utils.GeneUtils import org.evomaster.core.search.service.Randomness @@ -46,7 +47,10 @@ abstract class EnterpriseIndividual( */ children: MutableList, childTypeVerifier: (Class<*>) -> Boolean, - groups : GroupsOfChildren = getEnterpriseTopGroups(children,children.size,0) + /** + * if no group definition is specified, then it is assumed that all action are for the MAIN group + */ + groups : GroupsOfChildren = getEnterpriseTopGroups(children,children.size,0, 0, 0) ) : Individual( trackOperator, index, @@ -59,52 +63,70 @@ abstract class EnterpriseIndividual( /** * Return group definition for the given children. - * The first [sizeDb] are assumed to be database actions, followed by [sizeMain] main actions + * The first [sizeSQL] are assumed to be database actions, followed by [sizeMain] main actions */ fun getEnterpriseTopGroups( children: List, sizeMain: Int, - sizeDb: Int + sizeSQL: Int, + sizeMongo: Int, + sizeDNS: Int ) : GroupsOfChildren{ - if(children.size != sizeDb + sizeMain){ + if(children.size != sizeSQL +sizeMongo + sizeDNS + sizeMain){ throw IllegalArgumentException("Group size mismatch. Expected a total of ${children.size}, but" + - " got main=$sizeMain and db=$sizeDb") + " got main=$sizeMain, sql=$sizeSQL, mongo=$sizeMongo, dns=$sizeDNS") + } + if(sizeSQL < 0){ + throw IllegalArgumentException("Negative size for sizeSQL: $sizeSQL") + } + if(sizeMongo < 0){ + throw IllegalArgumentException("Negative size for sizeMongo: $sizeMain") } - if(sizeDb < 0){ - throw IllegalArgumentException("Negative size for sizeDb: $sizeDb") + if(sizeDNS < 0){ + throw IllegalArgumentException("Negative size for sizeDNS: $sizeMain") } if(sizeMain < 0){ throw IllegalArgumentException("Negative size for sizeMain: $sizeMain") } - //TODO in future ll need to refactor to handle multiple databases and NoSQL ones - //CHANGE: This is momentary. Needs refactor to handle multiple databases + /* + TODO in future ll need to refactor to handle multiple databases, possibly handled with + one action group per database... + but is it really common that a SUT directly access several databases of same kind? + */ val startIndexSQL = children.indexOfFirst { a -> a is SqlAction } val endIndexSQL = children.indexOfLast { a -> a is SqlAction } - val startIndexMongo = children.indexOfFirst { a -> a is MongoDbAction } - val endIndexMongo = children.indexOfLast { a -> a is MongoDbAction } - val db = ChildGroup(GroupsOfChildren.INITIALIZATION_SQL,{e -> e is ActionComponent && e.flatten().all { a -> a is SqlAction }}, - if(sizeDb==0) -1 else startIndexSQL , if(sizeDb==0) -1 else endIndexSQL + if(sizeSQL==0) -1 else startIndexSQL , if(sizeSQL==0) -1 else endIndexSQL ) + val startIndexMongo = children.indexOfFirst { a -> a is MongoDbAction } + val endIndexMongo = children.indexOfLast { a -> a is MongoDbAction } val mongodb = ChildGroup(GroupsOfChildren.INITIALIZATION_MONGO,{e -> e is ActionComponent && e.flatten().all { a -> a is MongoDbAction }}, - if(sizeDb==0) -1 else startIndexMongo , if(sizeDb==0) -1 else endIndexMongo + if(sizeMongo==0) -1 else startIndexMongo , if(sizeMongo==0) -1 else endIndexMongo + ) + + val startIndexDns = children.indexOfFirst { a -> a is DnsAction } + val endIndexDns = children.indexOfLast { a -> a is DnsAction } + val dns = ChildGroup(GroupsOfChildren.INITIALIZATION_DNS,{e -> e is ActionComponent && e.flatten().all { a -> a is DnsAction }}, + if(sizeDNS==0) -1 else startIndexDns , if(sizeDNS==0) -1 else endIndexDns ) - val main = ChildGroup(GroupsOfChildren.MAIN, {e -> e !is SqlAction && e !is ApiExternalServiceAction }, - if(sizeMain == 0) -1 else sizeDb, if(sizeMain == 0) -1 else sizeDb + sizeMain - 1) + val initSize = sizeSQL+sizeMongo+sizeDNS + + val main = ChildGroup(GroupsOfChildren.MAIN, {e -> e !is EnvironmentAction }, + if(sizeMain == 0) -1 else initSize, if(sizeMain == 0) -1 else initSize + sizeMain - 1) - return GroupsOfChildren(children, listOf(db, mongodb, main)) + return GroupsOfChildren(children, listOf(db, mongodb, dns, main)) } } /** * a list of db actions for its Initialization */ - private val dbInitialization: List + private val sqlInitialization: List get() { return groupsView()!!.getAllInGroup(GroupsOfChildren.INITIALIZATION_SQL) .flatMap { (it as ActionComponent).flatten() } @@ -117,9 +139,10 @@ abstract class EnterpriseIndividual( ActionFilter.MAIN_EXECUTABLE -> groupsView()!!.getAllInGroup(GroupsOfChildren.MAIN) .flatMap { (it as ActionComponent).flatten() } .filter { it !is SqlAction && it !is ApiExternalServiceAction } - ActionFilter.INIT -> groupsView()!!.getAllInGroup(GroupsOfChildren.INITIALIZATION_SQL) - .flatMap { (it as ActionComponent).flatten() } + groupsView()!!.getAllInGroup(GroupsOfChildren.INITIALIZATION_MONGO) - .flatMap { (it as ActionComponent).flatten() } + ActionFilter.INIT -> + groupsView()!! + .getAllInGroup(GroupsOfChildren.INITIALIZATION_SQL).flatMap { (it as ActionComponent).flatten() } + groupsView()!! + .getAllInGroup(GroupsOfChildren.INITIALIZATION_MONGO).flatMap { (it as ActionComponent).flatten()} // WARNING: this can still return DbAction, MongoDbAction and External ones... ActionFilter.NO_INIT -> groupsView()!!.getAllInGroup(GroupsOfChildren.MAIN).flatMap { (it as ActionComponent).flatten() } ActionFilter.ONLY_SQL -> seeAllActions().filterIsInstance() @@ -214,7 +237,7 @@ abstract class EnterpriseIndividual( if (!verifyInitializationActions()) { if (log.isTraceEnabled) log.trace("invoke GeneUtils.repairBrokenDbActionsList") - val previous = dbInitialization.toMutableList() + val previous = sqlInitialization.toMutableList() SqlActionUtils.repairBrokenDbActionsList(previous, randomness) resetInitializingActions(previous) Lazy.assert{verifyInitializationActions()} @@ -222,7 +245,7 @@ abstract class EnterpriseIndividual( } override fun hasAnyAction(): Boolean { - return super.hasAnyAction() || dbInitialization.isNotEmpty() + return super.hasAnyAction() || sqlInitialization.isNotEmpty() } override fun size() = seeMainExecutableActions().size @@ -266,7 +289,7 @@ abstract class EnterpriseIndividual( } /** - * remove specified dbactions i.e., [actions] from [dbInitialization] + * remove specified dbactions i.e., [actions] from [sqlInitialization] */ fun removeInitDbActions(actions: List) { killChildren { it is SqlAction && actions.contains(it)} @@ -276,6 +299,6 @@ abstract class EnterpriseIndividual( * @return a list table names which are used to insert data directly */ open fun getInsertTableNames(): List{ - return dbInitialization.filterNot { it.representExistingData }.map { it.table.name } + return sqlInitialization.filterNot { it.representExistingData }.map { it.table.name } } } diff --git a/core/src/main/kotlin/org/evomaster/core/problem/externalservice/DnsAction.kt b/core/src/main/kotlin/org/evomaster/core/problem/externalservice/DnsAction.kt new file mode 100644 index 0000000000..bb229afde8 --- /dev/null +++ b/core/src/main/kotlin/org/evomaster/core/problem/externalservice/DnsAction.kt @@ -0,0 +1,21 @@ +package org.evomaster.core.problem.externalservice + +import org.evomaster.core.search.EnvironmentAction +import org.evomaster.core.search.StructuralElement +import org.evomaster.core.search.gene.Gene + + +//TODO +class DnsAction(children: List) : EnvironmentAction(children) { + override fun getName(): String { + TODO("Not yet implemented") + } + + override fun seeTopGenes(): List { + TODO("Not yet implemented") + } + + override fun copyContent(): StructuralElement { + TODO("Not yet implemented") + } +} \ No newline at end of file diff --git a/core/src/main/kotlin/org/evomaster/core/problem/graphql/GraphQLIndividual.kt b/core/src/main/kotlin/org/evomaster/core/problem/graphql/GraphQLIndividual.kt index 45b973c165..b409376140 100644 --- a/core/src/main/kotlin/org/evomaster/core/problem/graphql/GraphQLIndividual.kt +++ b/core/src/main/kotlin/org/evomaster/core/problem/graphql/GraphQLIndividual.kt @@ -16,8 +16,10 @@ class GraphQLIndividual( sampleType: SampleType, allActions : MutableList, mainSize : Int = allActions.size, - dbSize: Int = 0, - groups : GroupsOfChildren = getEnterpriseTopGroups(allActions,mainSize,dbSize) + sqlSize: Int = 0, + mongoSize: Int = 0, + dnsSize: Int = 0, + groups : GroupsOfChildren = getEnterpriseTopGroups(allActions,mainSize,sqlSize,mongoSize,dnsSize) ) : ApiWsIndividual( sampleType = sampleType, children = allActions, @@ -35,7 +37,9 @@ class GraphQLIndividual( sampleType, children.map { it.copy() }.toMutableList() as MutableList, mainSize = groupsView()!!.sizeOfGroup(GroupsOfChildren.MAIN), - dbSize = groupsView()!!.sizeOfGroup(GroupsOfChildren.INITIALIZATION_SQL) + sqlSize = groupsView()!!.sizeOfGroup(GroupsOfChildren.INITIALIZATION_SQL), + mongoSize = groupsView()!!.sizeOfGroup(GroupsOfChildren.INITIALIZATION_MONGO), + dnsSize = groupsView()!!.sizeOfGroup(GroupsOfChildren.INITIALIZATION_DNS) ) } diff --git a/core/src/main/kotlin/org/evomaster/core/problem/gui/GuiIndividual.kt b/core/src/main/kotlin/org/evomaster/core/problem/gui/GuiIndividual.kt index 67b3a512a1..7e0524a848 100644 --- a/core/src/main/kotlin/org/evomaster/core/problem/gui/GuiIndividual.kt +++ b/core/src/main/kotlin/org/evomaster/core/problem/gui/GuiIndividual.kt @@ -33,5 +33,5 @@ abstract class GuiIndividual ( */ children: MutableList, childTypeVerifier: (Class<*>) -> Boolean, - groups : GroupsOfChildren = getEnterpriseTopGroups(children, children.size, 0) + groups : GroupsOfChildren = getEnterpriseTopGroups(children, children.size, 0, 0 ,0) ): EnterpriseIndividual(sampleType, trackOperator, index, children, childTypeVerifier, groups) diff --git a/core/src/main/kotlin/org/evomaster/core/problem/rest/RestIndividual.kt b/core/src/main/kotlin/org/evomaster/core/problem/rest/RestIndividual.kt index 9db9c8b8a0..c2e65d5f61 100644 --- a/core/src/main/kotlin/org/evomaster/core/problem/rest/RestIndividual.kt +++ b/core/src/main/kotlin/org/evomaster/core/problem/rest/RestIndividual.kt @@ -33,8 +33,10 @@ class RestIndividual( index : Int = -1, allActions : MutableList, mainSize : Int = allActions.size, - dbSize: Int = 0, - groups : GroupsOfChildren = getEnterpriseTopGroups(allActions,mainSize,dbSize) + sqlSize: Int = 0, + mongoSize: Int = 0, + dnsSize: Int = 0, + groups : GroupsOfChildren = getEnterpriseTopGroups(allActions,mainSize,sqlSize,mongoSize,dnsSize) ): ApiWsIndividual(sampleType, trackOperator, index, allActions, childTypeVerifier = { RestResourceCalls::class.java.isAssignableFrom(it) @@ -81,8 +83,9 @@ class RestIndividual( index, children.map { it.copy() }.toMutableList() as MutableList, mainSize = groupsView()!!.sizeOfGroup(GroupsOfChildren.MAIN), - //CHANGE: This is momentary for testing. Needs refactor to handle multiple databases - dbSize = groupsView()!!.sizeOfGroup(GroupsOfChildren.INITIALIZATION_MONGO ) + groupsView()!!.sizeOfGroup(GroupsOfChildren.INITIALIZATION_SQL ) + sqlSize = groupsView()!!.sizeOfGroup(GroupsOfChildren.INITIALIZATION_SQL), + mongoSize = groupsView()!!.sizeOfGroup(GroupsOfChildren.INITIALIZATION_MONGO), + dnsSize = groupsView()!!.sizeOfGroup(GroupsOfChildren.INITIALIZATION_DNS) ) } diff --git a/core/src/main/kotlin/org/evomaster/core/problem/rpc/RPCIndividual.kt b/core/src/main/kotlin/org/evomaster/core/problem/rpc/RPCIndividual.kt index c5b1af64bc..74c9aef22e 100644 --- a/core/src/main/kotlin/org/evomaster/core/problem/rpc/RPCIndividual.kt +++ b/core/src/main/kotlin/org/evomaster/core/problem/rpc/RPCIndividual.kt @@ -27,8 +27,10 @@ class RPCIndividual( index: Int = -1, allActions: MutableList, mainSize: Int = allActions.size, - dbSize: Int = 0, - groups: GroupsOfChildren = getEnterpriseTopGroups(allActions, mainSize, dbSize) + sqlSize: Int = 0, + mongoSize: Int = 0, + dnsSize: Int = 0, + groups: GroupsOfChildren = getEnterpriseTopGroups(allActions, mainSize, sqlSize,mongoSize,dnsSize) ) : ApiWsIndividual( sampleType, trackOperator, index, allActions, @@ -65,7 +67,7 @@ class RPCIndividual( ) }}) }, - mainSize = actions.size, dbSize = dbInitialization.size) + mainSize = actions.size, sqlSize = dbInitialization.size) /** * TODO: Verify the implementation @@ -126,7 +128,9 @@ class RPCIndividual( index, children.map { it.copy() }.toMutableList() as MutableList, mainSize = groupsView()!!.sizeOfGroup(GroupsOfChildren.MAIN), - dbSize = groupsView()!!.sizeOfGroup(GroupsOfChildren.INITIALIZATION_SQL) + sqlSize = groupsView()!!.sizeOfGroup(GroupsOfChildren.INITIALIZATION_SQL), + mongoSize = groupsView()!!.sizeOfGroup(GroupsOfChildren.INITIALIZATION_MONGO), + dnsSize = groupsView()!!.sizeOfGroup(GroupsOfChildren.INITIALIZATION_DNS) ) } diff --git a/core/src/main/kotlin/org/evomaster/core/problem/webfrontend/WebIndividual.kt b/core/src/main/kotlin/org/evomaster/core/problem/webfrontend/WebIndividual.kt index 1f5e0cb9c9..3cac6f667d 100644 --- a/core/src/main/kotlin/org/evomaster/core/problem/webfrontend/WebIndividual.kt +++ b/core/src/main/kotlin/org/evomaster/core/problem/webfrontend/WebIndividual.kt @@ -14,8 +14,10 @@ class WebIndividual( sampleType: SampleType, children: MutableList, mainSize : Int = children.size, - dbSize: Int = 0, - groups : GroupsOfChildren = getEnterpriseTopGroups(children,mainSize,dbSize) + sqlSize: Int = 0, + mongoSize: Int = 0, + dnsSize: Int = 0, + groups : GroupsOfChildren = getEnterpriseTopGroups(children,mainSize,sqlSize,mongoSize,dnsSize) ) : GuiIndividual( sampleType = sampleType, children = children, @@ -31,7 +33,9 @@ class WebIndividual( sampleType, children.map { it.copy() }.toMutableList() as MutableList, mainSize = groupsView()!!.sizeOfGroup(GroupsOfChildren.MAIN), - dbSize = groupsView()!!.sizeOfGroup(GroupsOfChildren.INITIALIZATION_SQL) + sqlSize = groupsView()!!.sizeOfGroup(GroupsOfChildren.INITIALIZATION_SQL), + mongoSize = groupsView()!!.sizeOfGroup(GroupsOfChildren.INITIALIZATION_MONGO), + dnsSize = groupsView()!!.sizeOfGroup(GroupsOfChildren.INITIALIZATION_DNS) ) } diff --git a/core/src/main/kotlin/org/evomaster/core/search/EnvironmentAction.kt b/core/src/main/kotlin/org/evomaster/core/search/EnvironmentAction.kt index 7fa3a8b4b6..bcde6639cf 100644 --- a/core/src/main/kotlin/org/evomaster/core/search/EnvironmentAction.kt +++ b/core/src/main/kotlin/org/evomaster/core/search/EnvironmentAction.kt @@ -4,7 +4,7 @@ import org.evomaster.core.search.action.Action /** - * An action used to setup the environment of a test: eg databases and external services + * An action used to set up the environment of a test: eg databases and external services */ abstract class EnvironmentAction(children: List) : Action(children){ diff --git a/core/src/main/kotlin/org/evomaster/core/search/GroupsOfChildren.kt b/core/src/main/kotlin/org/evomaster/core/search/GroupsOfChildren.kt index af18fec076..643c3494cc 100644 --- a/core/src/main/kotlin/org/evomaster/core/search/GroupsOfChildren.kt +++ b/core/src/main/kotlin/org/evomaster/core/search/GroupsOfChildren.kt @@ -27,6 +27,8 @@ class GroupsOfChildren( const val INITIALIZATION_MONGO = "INITIALIZATION_MONGO" + const val INITIALIZATION_DNS = "INITIALIZATION_DNS" + const val EXTERNAL_SERVICES = "EXTERNAL_SERVICES" const val RESOURCE_SQL = "RESOURCE_SQL"