diff --git a/platform/workspaceModel/storage/tests/testSrc/com/intellij/workspaceModel/storage/entities/TestEntities.kt b/platform/workspaceModel/storage/tests/testSrc/com/intellij/workspaceModel/storage/entities/TestEntities.kt index a0842d4886bc..e03510ce211c 100644 --- a/platform/workspaceModel/storage/tests/testSrc/com/intellij/workspaceModel/storage/entities/TestEntities.kt +++ b/platform/workspaceModel/storage/tests/testSrc/com/intellij/workspaceModel/storage/entities/TestEntities.kt @@ -44,7 +44,6 @@ internal class ModifiableSampleEntity : ModifiableWorkspaceEntityBase by EntityDataDelegation() var fileProperty: VirtualFileUrl by EntityDataDelegation() - } internal fun WorkspaceEntityStorageBuilder.addSampleEntity(stringProperty: String, diff --git a/platform/workspaceModel/storage/tests/testSrc/com/intellij/workspaceModel/storage/propertyBased/EntityManipulations.kt b/platform/workspaceModel/storage/tests/testSrc/com/intellij/workspaceModel/storage/propertyBased/EntityManipulations.kt index aa3fd210addb..71904510dfb1 100644 --- a/platform/workspaceModel/storage/tests/testSrc/com/intellij/workspaceModel/storage/propertyBased/EntityManipulations.kt +++ b/platform/workspaceModel/storage/tests/testSrc/com/intellij/workspaceModel/storage/propertyBased/EntityManipulations.kt @@ -12,7 +12,33 @@ import org.jetbrains.jetCheck.ImperativeCommand import org.junit.Assert internal fun getEntityManipulation(workspace: WorkspaceEntityStorageBuilderImpl): Generator? { - return Generator.anyOf(RemoveSomeEntity.create(workspace), EntityManipulation.addManipulations(workspace)) + return Generator.anyOf( + RemoveSomeEntity.create(workspace), + EntityManipulation.addManipulations(workspace), + EntityManipulation.modifyManipulations(workspace) + ) +} + +internal interface EntityManipulation { + fun addManipulation(storage: WorkspaceEntityStorageBuilderImpl): AddEntity + fun modifyManipulation(storage: WorkspaceEntityStorageBuilderImpl): ModifyEntity + + companion object { + fun addManipulations(storage: WorkspaceEntityStorageBuilderImpl): Generator { + return Generator.sampledFrom(manipulations.map { it.addManipulation(storage) }) + } + + fun modifyManipulations(storage: WorkspaceEntityStorageBuilderImpl): Generator> { + return Generator.sampledFrom(manipulations.map { it.modifyManipulation(storage) }) + } + + private val manipulations = listOf( + SampleEntityManipulation, + ParentEntityManipulation, + ChildEntityManipulation, + ChildWithOptionalParentManipulation + ) + } } // Common for all entities @@ -48,21 +74,21 @@ internal abstract class AddEntity(protected val storage: WorkspaceEntityStorageB } } -internal interface EntityManipulation { - fun addManipulation(storage: WorkspaceEntityStorageBuilderImpl): AddEntity - //fun modify(storage: WorkspaceEntityStorageBuilderImpl) +internal abstract class ModifyEntity(protected val storage: WorkspaceEntityStorageBuilderImpl, + private val entityDescription: String, + private val classId: Int) : ImperativeCommand { + abstract fun modifyEntity(entity: E, someProperty: String, env: ImperativeCommand.Environment): Boolean - companion object { - fun addManipulations(storage: WorkspaceEntityStorageBuilderImpl): Generator { - return Generator.sampledFrom(manipulations.map { it.addManipulation(storage) }) - } + final override fun performCommand(env: ImperativeCommand.Environment) { + env.logMessage("Trying to modify $entityDescription entity") + val property = env.generateValue(randomNames, null) - private val manipulations = listOf( - SampleEntityManipulation, - ParentEntityManipulation, - ChildEntityManipulation, - ChildWithOptionalParentManipulation - ) + val entityId = env.generateValue(EntityIdOfFamilyGenerator.create(storage, classId), null) + if (entityId == null) return + + val entity = storage.entityDataByIdOrDie(entityId).createEntity(storage) as E + modifyEntity(entity, property, env) + env.logMessage("----------------------------------") } } @@ -77,6 +103,21 @@ private object ChildWithOptionalParentManipulation : EntityManipulation { } } } + + override fun modifyManipulation(storage: WorkspaceEntityStorageBuilderImpl): ModifyEntity { + return object : ModifyEntity(storage, "ChildWithOptionalParent", + ChildWithOptionalParentEntity::class.java.toClassId()) { + override fun modifyEntity(entity: ChildWithOptionalParentEntity, someProperty: String, env: ImperativeCommand.Environment): Boolean { + val selectedModification = env.generateValue(Generator.integers(0, 0), null) + val modification: ModifiableChildWithOptionalParentEntity.() -> Unit = when (selectedModification) { + 0 -> { -> childProperty = env.generateValue(randomNames, "Change childProperty to %s") } + else -> error("Undefined modification") + } + storage.modifyEntity(ModifiableChildWithOptionalParentEntity::class.java, entity, modification) + return true + } + } + } } private object ChildEntityManipulation : EntityManipulation { @@ -90,6 +131,20 @@ private object ChildEntityManipulation : EntityManipulation { } } } + + override fun modifyManipulation(storage: WorkspaceEntityStorageBuilderImpl): ModifyEntity { + return object : ModifyEntity(storage, "Child", ChildEntity::class.java.toClassId()) { + override fun modifyEntity(entity: ChildEntity, someProperty: String, env: ImperativeCommand.Environment): Boolean { + val selectedModification = env.generateValue(Generator.integers(0, 0), null) + val modification: ModifiableChildEntity.() -> Unit = when (selectedModification) { + 0 -> { -> childProperty = env.generateValue(randomNames, "Change childProperty to %s") } + else -> error("Undefined modification") + } + storage.modifyEntity(ModifiableChildEntity::class.java, entity, modification) + return true + } + } + } } private object ParentEntityManipulation : EntityManipulation { @@ -100,6 +155,20 @@ private object ParentEntityManipulation : EntityManipulation { } } } + + override fun modifyManipulation(storage: WorkspaceEntityStorageBuilderImpl): ModifyEntity { + return object : ModifyEntity(storage, "Parent", ParentEntity::class.java.toClassId()) { + override fun modifyEntity(entity: ParentEntity, someProperty: String, env: ImperativeCommand.Environment): Boolean { + val selectedModification = env.generateValue(Generator.integers(0, 0), null) + val modification: ModifiableParentEntity.() -> Unit = when (selectedModification) { + 0 -> { -> parentProperty = env.generateValue(randomNames, "Change parentProperty to %s") } + else -> error("Undefined modification") + } + storage.modifyEntity(ModifiableParentEntity::class.java, entity, modification) + return true + } + } + } } private object SampleEntityManipulation : EntityManipulation { @@ -110,5 +179,20 @@ private object SampleEntityManipulation : EntityManipulation { } } } + + override fun modifyManipulation(storage: WorkspaceEntityStorageBuilderImpl): ModifyEntity { + return object : ModifyEntity(storage, "Sample", SampleEntity::class.java.toClassId()) { + override fun modifyEntity(entity: SampleEntity, someProperty: String, env: ImperativeCommand.Environment): Boolean { + val selectedModification = env.generateValue(Generator.integers(0, 1), null) + val modification: ModifiableSampleEntity.() -> Unit = when (selectedModification) { + 0 -> { -> booleanProperty = env.generateValue(Generator.booleans(), "Change booleanProperty to %s") } + 1 -> { -> stringProperty = env.generateValue(randomNames, "Change stringProperty to %s") } + else -> error("Undefined modification") + } + storage.modifyEntity(ModifiableSampleEntity::class.java, entity, modification) + return true + } + } + } }