Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use controllers via MockMvc in Spring integration tests #2447

Merged
merged 19 commits into from
Aug 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
09386dc
Use controllers via `MockMvc` in concrete execution and update result…
IlyaMuravjov Jul 25, 2023
3ad9a64
Make `createGetMockMvcResponseModel` work when there's no `@RequestMa…
IlyaMuravjov Jul 26, 2023
488de3c
Introduce `executableToCall`
IlyaMuravjov Jul 26, 2023
8107fda
Replace `executableToCall` with `MockMvc.perform` for Spring controllers
IlyaMuravjov Jul 26, 2023
fc72b62
Remove handling of Spring controllers from `SpringUtExecutionInstrume…
IlyaMuravjov Jul 26, 2023
5655f5b
Add `utCustomModelConstructorFinder` property to `UtModelConstructor`
IlyaMuravjov Jul 27, 2023
0b8d364
Add `UtSpringMockMvcResultActionsModel` and its `UtCustomModelConstru…
IlyaMuravjov Jul 27, 2023
1bf7ab8
Add `UtCustomModel` (i.e. common parent of all framework specific mod…
IlyaMuravjov Jul 27, 2023
9fddb97
Properly handle `UtCustomModel`
IlyaMuravjov Jul 27, 2023
3257dea
Add `origin` to `UtSpringMockMvcResultActionsModel`
IlyaMuravjov Jul 27, 2023
58cc415
Split `CgMethodTestSet.executableId` into `executableUnderTest` and `…
IlyaMuravjov Jul 27, 2023
6107f0e
Enable `UtMockMvcResultActionsModelConstructor` for subtypes of `Resu…
IlyaMuravjov Jul 27, 2023
d5529ee
Add `CgCustomAssertConstructor` to `CgComponents`
IlyaMuravjov Jul 28, 2023
6790e71
Add custom asserts for `MockMvc.perform()` result
IlyaMuravjov Jul 28, 2023
6cc441e
Remove redundant code
IlyaMuravjov Jul 28, 2023
40f3228
Handle `modelTagName` for `UtCustomModel`
IlyaMuravjov Jul 28, 2023
bfd5827
Fix compilation after rebase
IlyaMuravjov Jul 28, 2023
06a2ebd
Fix JS compilation
IlyaMuravjov Jul 28, 2023
e5dd7c1
Address comments in #2447
IlyaMuravjov Jul 31, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,8 @@ abstract class UtExecution(
testMethodName: String? = this.testMethodName,
displayName: String? = this.displayName,
): UtExecution

val executableToCall get() = stateBefore.executableToCall
}

/**
Expand Down Expand Up @@ -287,11 +289,33 @@ class UtFailedExecution(
}
}

/**
* @property executableToCall executable that is called in the test body and whose result is used in asserts as `actual`.
*
* Most often [executableToCall] is just method under test, but it may be changed to different executable if more
* appropriate way of calling specific method is found (for example, Spring controller methods are called via `MockMvc`).
*
* `null` value of [executableToCall] indicates that method under test should be called in the test body.
*/
open class EnvironmentModels(
val thisInstance: UtModel?,
val parameters: List<UtModel>,
val statics: Map<FieldId, UtModel>
val statics: Map<FieldId, UtModel>,
val executableToCall: ExecutableId?,
) {
@Deprecated("Now `executableToCall` also need to be passed to `EnvironmentModels` constructor " +
"(see more details in `EnvironmentModels` class documentation)", level = DeprecationLevel.ERROR)
constructor(
thisInstance: UtModel?,
parameters: List<UtModel>,
statics: Map<FieldId, UtModel>,
) : this(
thisInstance = thisInstance,
parameters = parameters,
statics = statics,
executableToCall = null,
)

override fun toString() = buildString {
append("this=$thisInstance")
appendOptional("parameters", parameters)
Expand All @@ -305,8 +329,9 @@ open class EnvironmentModels(
fun copy(
thisInstance: UtModel? = this.thisInstance,
parameters: List<UtModel> = this.parameters,
statics: Map<FieldId, UtModel> = this.statics
) = EnvironmentModels(thisInstance, parameters, statics)
statics: Map<FieldId, UtModel> = this.statics,
executableToCall: ExecutableId? = this.executableToCall,
) = EnvironmentModels(thisInstance, parameters, statics, executableToCall)
}

/**
Expand All @@ -315,7 +340,8 @@ open class EnvironmentModels(
object MissingState : EnvironmentModels(
thisInstance = null,
parameters = emptyList(),
statics = emptyMap()
statics = emptyMap(),
executableToCall = null,
)

/**
Expand Down Expand Up @@ -550,6 +576,21 @@ data class UtArrayModel(
override fun hashCode(): Int = id
}

/**
* Wrapper of [origin] model, that can be handled in a different
* way in some situations (e.g. during value construction).
*/
sealed class UtModelWithCompositeOrigin(
id: Int?,
classId: ClassId,
modelName: String = id.toString(),
open val origin: UtCompositeModel?,
) : UtReferenceModel(
id = id,
classId = classId,
modelName = modelName
)

/**
* Model for complex objects with assemble instructions.
*
Expand All @@ -564,8 +605,8 @@ data class UtAssembleModel private constructor(
override val modelName: String,
val instantiationCall: UtStatementCallModel,
val modificationsChain: List<UtStatementModel>,
val origin: UtCompositeModel?
) : UtReferenceModel(id, classId, modelName) {
override val origin: UtCompositeModel?
) : UtModelWithCompositeOrigin(id, classId, modelName, origin) {

/**
* Creates a new [UtAssembleModel].
Expand Down Expand Up @@ -703,7 +744,17 @@ class UtLambdaModel(
}
}

object UtSpringContextModel : UtReferenceModel(
/**
* Common parent of all framework-specific models (e.g. Spring-specific models)
*/
abstract class UtCustomModel(
id: Int?,
classId: ClassId,
modelName: String = id.toString(),
override val origin: UtCompositeModel? = null,
) : UtModelWithCompositeOrigin(id, classId, modelName, origin)

object UtSpringContextModel : UtCustomModel(
id = null,
classId = SpringModelUtils.applicationContextClassId,
modelName = "applicationContext"
Expand All @@ -721,6 +772,23 @@ data class SpringRepositoryId(
val entityClassId: ClassId,
)

class UtSpringMockMvcResultActionsModel(
id: Int?,
origin: UtCompositeModel?,
val status: Int,
val errorMessage: String?,
val contentAsString: String,
val viewName: String?,
// model for mvcResult.modelAndView?.model
val model: UtModel?
// TODO add headers and other data
) : UtCustomModel(
origin = origin,
classId = SpringModelUtils.resultActionsClassId,
id = id,
modelName = "mockMvcResultActions@$id"
)

/**
* Model for a step to obtain [UtAssembleModel].
*/
Expand Down
Loading