Skip to content

Commit 76ad646

Browse files
committed
Add UtCustomModel (i.e. common parent of all framework specific models)
1 parent 7cfd759 commit 76ad646

File tree

5 files changed

+25
-11
lines changed

5 files changed

+25
-11
lines changed

utbot-framework-api/src/main/kotlin/org/utbot/framework/plugin/api/Api.kt

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -727,7 +727,17 @@ class UtLambdaModel(
727727
}
728728
}
729729

730-
object UtSpringContextModel : UtReferenceModel(
730+
/**
731+
* Common parent of all framework-specific models (e.g. Spring-specific models)
732+
*/
733+
abstract class UtCustomModel(
734+
val origin: UtCompositeModel? = null,
735+
id: Int?,
736+
classId: ClassId,
737+
modelName: String = id.toString()
738+
) : UtReferenceModel(id, classId, modelName)
739+
740+
object UtSpringContextModel : UtCustomModel(
731741
id = null,
732742
classId = SpringModelUtils.applicationContextClassId,
733743
modelName = "applicationContext"
@@ -746,15 +756,18 @@ data class SpringRepositoryId(
746756
)
747757

748758
class UtSpringMockMvcResultActionsModel(
759+
id: Int?,
749760
val status: Int,
750761
val errorMessage: String?,
751762
val contentAsString: String,
752763
val viewName: String?,
753764
// model for mvcResult.modelAndView?.model
754765
val model: UtModel?
755766
// TODO add headers and other data
756-
) : UtModel(
757-
classId = SpringModelUtils.resultActionsClassId
767+
) : UtCustomModel(
768+
classId = SpringModelUtils.resultActionsClassId,
769+
id = id,
770+
modelName = "mockMvcResultActions@$id"
758771
)
759772

760773
/**

utbot-framework/src/main/kotlin/org/utbot/framework/codegen/domain/models/builders/SpringTestClassModelBuilder.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@ import org.utbot.framework.plugin.api.UtArrayModel
1010
import org.utbot.framework.plugin.api.UtAssembleModel
1111
import org.utbot.framework.plugin.api.UtClassRefModel
1212
import org.utbot.framework.plugin.api.UtCompositeModel
13+
import org.utbot.framework.plugin.api.UtCustomModel
1314
import org.utbot.framework.plugin.api.UtDirectSetFieldModel
1415
import org.utbot.framework.plugin.api.UtEnumConstantModel
1516
import org.utbot.framework.plugin.api.UtLambdaModel
1617
import org.utbot.framework.plugin.api.UtModel
1718
import org.utbot.framework.plugin.api.UtNullModel
1819
import org.utbot.framework.plugin.api.UtPrimitiveModel
19-
import org.utbot.framework.plugin.api.UtSpringContextModel
2020
import org.utbot.framework.plugin.api.UtStatementCallModel
2121
import org.utbot.framework.plugin.api.UtVoidModel
2222
import org.utbot.framework.plugin.api.isMockModel
@@ -109,8 +109,8 @@ class SpringTestClassModelBuilder(val context: CgContext): TestClassModelBuilder
109109
is UtPrimitiveModel,
110110
is UtClassRefModel,
111111
is UtVoidModel,
112-
is UtEnumConstantModel,
113-
is UtSpringContextModel -> {}
112+
is UtEnumConstantModel -> {}
113+
is UtCustomModel -> currentModel.origin?.let { collectRecursively(it, allModels) }
114114
is UtLambdaModel -> {
115115
currentModel.capturedValues.forEach { collectRecursively(it, allModels) }
116116
}

utbot-framework/src/main/kotlin/org/utbot/framework/fields/ExecutionStateAnalyzer.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,14 @@ import org.utbot.framework.plugin.api.UtArrayModel
1010
import org.utbot.framework.plugin.api.UtAssembleModel
1111
import org.utbot.framework.plugin.api.UtClassRefModel
1212
import org.utbot.framework.plugin.api.UtCompositeModel
13+
import org.utbot.framework.plugin.api.UtCustomModel
1314
import org.utbot.framework.plugin.api.UtEnumConstantModel
1415
import org.utbot.framework.plugin.api.UtExecution
1516
import org.utbot.framework.plugin.api.UtLambdaModel
1617
import org.utbot.framework.plugin.api.UtModel
1718
import org.utbot.framework.plugin.api.UtNullModel
1819
import org.utbot.framework.plugin.api.UtPrimitiveModel
1920
import org.utbot.framework.plugin.api.UtReferenceModel
20-
import org.utbot.framework.plugin.api.UtSpringContextModel
2121
import org.utbot.framework.plugin.api.UtSymbolicExecution
2222
import org.utbot.framework.plugin.api.UtVoidModel
2323
import org.utbot.framework.util.UtModelVisitor
@@ -238,7 +238,7 @@ private class FieldStateVisitor : UtModelVisitor<FieldData>() {
238238
recordFieldState(data, element)
239239
}
240240

241-
override fun visit(element: UtSpringContextModel, data: FieldData) {
241+
override fun visit(element: UtCustomModel, data: FieldData) {
242242
recordFieldState(data, element)
243243
}
244244

utbot-framework/src/main/kotlin/org/utbot/framework/util/UtModelVisitor.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@ import org.utbot.framework.plugin.api.UtArrayModel
44
import org.utbot.framework.plugin.api.UtAssembleModel
55
import org.utbot.framework.plugin.api.UtClassRefModel
66
import org.utbot.framework.plugin.api.UtCompositeModel
7+
import org.utbot.framework.plugin.api.UtCustomModel
78
import org.utbot.framework.plugin.api.UtEnumConstantModel
89
import org.utbot.framework.plugin.api.UtLambdaModel
910
import org.utbot.framework.plugin.api.UtModel
1011
import org.utbot.framework.plugin.api.UtNullModel
1112
import org.utbot.framework.plugin.api.UtPrimitiveModel
1213
import org.utbot.framework.plugin.api.UtReferenceModel
13-
import org.utbot.framework.plugin.api.UtSpringContextModel
1414
import org.utbot.framework.plugin.api.UtVoidModel
1515
import java.util.Collections
1616
import java.util.IdentityHashMap
@@ -36,7 +36,7 @@ abstract class UtModelVisitor<D> {
3636
is UtAssembleModel -> visit(element, data)
3737
is UtCompositeModel -> visit(element, data)
3838
is UtLambdaModel -> visit(element, data)
39-
is UtSpringContextModel -> visit(element, data)
39+
is UtCustomModel -> visit(element, data)
4040
}
4141
}
4242

@@ -46,7 +46,7 @@ abstract class UtModelVisitor<D> {
4646
protected abstract fun visit(element: UtAssembleModel, data: D)
4747
protected abstract fun visit(element: UtCompositeModel, data: D)
4848
protected abstract fun visit(element: UtLambdaModel, data: D)
49-
protected abstract fun visit(element: UtSpringContextModel, data: D)
49+
protected abstract fun visit(element: UtCustomModel, data: D)
5050

5151
/**
5252
* Returns true when we can traverse the given model.

utbot-instrumentation/src/main/kotlin/org/utbot/instrumentation/instrumentation/spring/UtMockMvcResultActionsModelConstructor.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ class UtMockMvcResultActionsModelConstructor : UtCustomModelConstructor {
2929
val modelAndView = mvcResultGetModelAndViewMethodId.method.invoke(mvcResult)
3030

3131
return UtSpringMockMvcResultActionsModel(
32+
id = id,
3233
status = responseGetStatusMethodId.method.invoke(response) as Int,
3334
errorMessage = responseGetErrorMessageMethodId.method.invoke(response) as String?,
3435
contentAsString = responseGetContentAsStringMethodId.method.invoke(response) as String,

0 commit comments

Comments
 (0)