mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
[Workspace Model] Add new tests for soft links
GitOrigin-RevId: a919775d70020d2d6fb60e5550e22b9fe4e1d823
This commit is contained in:
committed by
intellij-monorepo-bot
parent
26c35fc2e4
commit
3f6e45534e
+18
-5
@@ -3,12 +3,8 @@ package com.intellij.workspaceModel.storage
|
||||
|
||||
import com.intellij.testFramework.UsefulTestCase.assertEmpty
|
||||
import com.intellij.testFramework.UsefulTestCase.assertOneElement
|
||||
import com.intellij.workspaceModel.storage.impl.WorkspaceEntityStorageBuilderImpl
|
||||
import com.intellij.workspaceModel.storage.entities.*
|
||||
import com.intellij.workspaceModel.storage.entities.ModifiableNamedEntity
|
||||
import com.intellij.workspaceModel.storage.entities.ModifiableWithListSoftLinksEntity
|
||||
import com.intellij.workspaceModel.storage.entities.NamedEntity
|
||||
import com.intellij.workspaceModel.storage.entities.WithSoftLinkEntity
|
||||
import com.intellij.workspaceModel.storage.impl.WorkspaceEntityStorageBuilderImpl
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Assert.assertTrue
|
||||
import org.junit.Test
|
||||
@@ -320,6 +316,23 @@ class ReplaceBySourceTest {
|
||||
builder.assertConsistency()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `replace by source with composite id`() {
|
||||
val builder = WorkspaceEntityStorageBuilderImpl.create()
|
||||
val replacement = WorkspaceEntityStorageBuilderImpl.create()
|
||||
val namedEntity = replacement.addNamedEntity("MyName")
|
||||
val composedEntity = replacement.addComposedIdSoftRefEntity("AnotherName", namedEntity.persistentId())
|
||||
replacement.addWithSoftLinkEntity(composedEntity.persistentId())
|
||||
|
||||
replacement.assertConsistency()
|
||||
builder.replaceBySource({ true }, replacement)
|
||||
builder.assertConsistency()
|
||||
|
||||
assertOneElement(builder.entities(NamedEntity::class.java).toList())
|
||||
assertOneElement(builder.entities(ComposedIdSoftRefEntity::class.java).toList())
|
||||
assertOneElement(builder.entities(WithSoftLinkEntity::class.java).toList())
|
||||
}
|
||||
|
||||
/*
|
||||
Not sure if this should work this way. We can track persistentId changes in builder, but what if we perform replaceBySource with storage?
|
||||
@Test
|
||||
|
||||
+56
-4
@@ -2,14 +2,17 @@
|
||||
package com.intellij.workspaceModel.storage
|
||||
|
||||
import com.intellij.testFramework.UsefulTestCase.assertOneElement
|
||||
import com.intellij.workspaceModel.storage.entities.*
|
||||
import com.intellij.workspaceModel.storage.impl.WorkspaceEntityStorageBuilderImpl
|
||||
import com.intellij.workspaceModel.storage.entities.ModifiableNamedEntity
|
||||
import com.intellij.workspaceModel.storage.entities.ModifiableWithSoftLinkEntity
|
||||
import com.intellij.workspaceModel.storage.entities.MySource
|
||||
import com.intellij.workspaceModel.storage.entities.NameId
|
||||
import junit.framework.Assert.assertEquals
|
||||
import junit.framework.Assert.assertNotNull
|
||||
import org.junit.Test
|
||||
|
||||
/**
|
||||
* Soft reference
|
||||
* Persistent id via soft reference
|
||||
* Persistent id via strong reference
|
||||
*/
|
||||
class SoftLinksTest {
|
||||
@Test
|
||||
fun `test add diff with soft links`() {
|
||||
@@ -82,4 +85,53 @@ class SoftLinksTest {
|
||||
assertNotNull(builder.resolve(NameId(id)))
|
||||
assertOneElement(builder.indexes.softLinks.getValues(NameId(id)))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `change persistent id part`() {
|
||||
val builder = WorkspaceEntityStorageBuilderImpl.create()
|
||||
val entity = builder.addNamedEntity("Name")
|
||||
builder.addWithSoftLinkEntity(entity.persistentId())
|
||||
|
||||
builder.modifyEntity(ModifiableNamedEntity::class.java, entity) {
|
||||
this.name = "newName"
|
||||
}
|
||||
|
||||
builder.assertConsistency()
|
||||
|
||||
assertEquals("newName", builder.entities(WithSoftLinkEntity::class.java).single().link.presentableName)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `change persistent id part of composed id entity`() {
|
||||
val builder = WorkspaceEntityStorageBuilderImpl.create()
|
||||
val entity = builder.addNamedEntity("Name")
|
||||
builder.addComposedIdSoftRefEntity("AnotherName", entity.persistentId())
|
||||
|
||||
builder.modifyEntity(ModifiableNamedEntity::class.java, entity) {
|
||||
this.name = "newName"
|
||||
}
|
||||
|
||||
builder.assertConsistency()
|
||||
|
||||
val updatedPersistentId = builder.entities(ComposedIdSoftRefEntity::class.java).single().persistentId()
|
||||
assertEquals("newName", updatedPersistentId.link.presentableName)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `change persistent id part of composed id entity and with linked entity`() {
|
||||
val builder = WorkspaceEntityStorageBuilderImpl.create()
|
||||
val entity = builder.addNamedEntity("Name")
|
||||
val composedIdEntity = builder.addComposedIdSoftRefEntity("AnotherName", entity.persistentId())
|
||||
builder.addWithSoftLinkEntity(composedIdEntity.persistentId())
|
||||
|
||||
builder.modifyEntity(ModifiableNamedEntity::class.java, entity) {
|
||||
this.name = "newName"
|
||||
}
|
||||
|
||||
builder.assertConsistency()
|
||||
|
||||
val updatedPersistentId = builder.entities(ComposedIdSoftRefEntity::class.java).single().persistentId()
|
||||
assertEquals("newName", updatedPersistentId.link.presentableName)
|
||||
assertEquals("newName", (builder.entities(WithSoftLinkEntity::class.java).single().link as ComposedId).link.presentableName)
|
||||
}
|
||||
}
|
||||
+51
-5
@@ -29,6 +29,13 @@ internal data class AnotherNameId(private val name: String) : PersistentEntityId
|
||||
override fun toString(): String = name
|
||||
}
|
||||
|
||||
internal data class ComposedId(internal val name: String, internal val link: NameId) : PersistentEntityId<ComposedIdSoftRefEntity>() {
|
||||
override val parentId: PersistentEntityId<*>?
|
||||
get() = null
|
||||
override val presentableName: String
|
||||
get() = "$name - ${link.presentableName}"
|
||||
}
|
||||
|
||||
// ------------------------------ Entity With Persistent Id ------------------
|
||||
|
||||
internal class NamedEntityData : WorkspaceEntityData.WithCalculablePersistentId<NamedEntity>() {
|
||||
@@ -59,7 +66,7 @@ internal fun WorkspaceEntityStorageBuilderImpl.addNamedEntity(name: String, sour
|
||||
|
||||
internal class WithSoftLinkEntityData : WorkspaceEntityData<WithSoftLinkEntity>(), SoftLinkable {
|
||||
|
||||
lateinit var link: NameId
|
||||
lateinit var link: PersistentEntityId<*>
|
||||
|
||||
override fun createEntity(snapshot: WorkspaceEntityStorage): WithSoftLinkEntity {
|
||||
return WithSoftLinkEntity(link).also { addMetaData(it, snapshot) }
|
||||
@@ -70,18 +77,18 @@ internal class WithSoftLinkEntityData : WorkspaceEntityData<WithSoftLinkEntity>(
|
||||
override fun updateLink(oldLink: PersistentEntityId<*>,
|
||||
newLink: PersistentEntityId<*>,
|
||||
affectedIds: MutableList<Pair<PersistentEntityId<*>, PersistentEntityId<*>>>): Boolean {
|
||||
this.link = newLink as NameId
|
||||
this.link = newLink
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
internal class WithSoftLinkEntity(val link: NameId) : WorkspaceEntityBase()
|
||||
internal class WithSoftLinkEntity(val link: PersistentEntityId<*>) : WorkspaceEntityBase()
|
||||
|
||||
internal class ModifiableWithSoftLinkEntity : ModifiableWorkspaceEntityBase<WithSoftLinkEntity>() {
|
||||
var link: NameId by EntityDataDelegation()
|
||||
var link: PersistentEntityId<*> by EntityDataDelegation()
|
||||
}
|
||||
|
||||
internal fun WorkspaceEntityStorageBuilderImpl.addWithSoftLinkEntity(link: NameId, source: EntitySource = MySource) =
|
||||
internal fun WorkspaceEntityStorageBuilderImpl.addWithSoftLinkEntity(link: PersistentEntityId<*>, source: EntitySource = MySource) =
|
||||
addEntity(ModifiableWithSoftLinkEntity::class.java, source) {
|
||||
this.link = link
|
||||
}
|
||||
@@ -124,3 +131,42 @@ internal fun WorkspaceEntityStorageBuilderImpl.addWithListSoftLinksEntity(name:
|
||||
this.name = name
|
||||
this.links = links
|
||||
}
|
||||
|
||||
// --------------------------- Entity with composed persistent id via soft reference ------------------
|
||||
|
||||
internal class ComposedIdSoftRefEntityData: WorkspaceEntityData.WithCalculablePersistentId<ComposedIdSoftRefEntity>(), SoftLinkable {
|
||||
lateinit var name: String
|
||||
lateinit var link: NameId
|
||||
|
||||
override fun createEntity(snapshot: WorkspaceEntityStorage): ComposedIdSoftRefEntity {
|
||||
return ComposedIdSoftRefEntity(name, link).also { addMetaData(it, snapshot) }
|
||||
}
|
||||
|
||||
override fun getLinks(): Set<PersistentEntityId<*>> = setOf(link)
|
||||
|
||||
override fun updateLink(oldLink: PersistentEntityId<*>,
|
||||
newLink: PersistentEntityId<*>,
|
||||
affectedIds: MutableList<Pair<PersistentEntityId<*>, PersistentEntityId<*>>>): Boolean {
|
||||
if (oldLink != link) return false
|
||||
this.link = newLink as NameId
|
||||
return true
|
||||
}
|
||||
|
||||
override fun persistentId() = ComposedId(name, link)
|
||||
}
|
||||
|
||||
internal class ComposedIdSoftRefEntity(val name: String, val link: NameId) : WorkspaceEntityBase(), WorkspaceEntityWithPersistentId {
|
||||
override fun persistentId(): ComposedId = ComposedId(name, link)
|
||||
}
|
||||
|
||||
internal class ModifiableComposedIdSoftRefEntity : ModifiableWorkspaceEntityBase<ComposedIdSoftRefEntity>() {
|
||||
var name: String by EntityDataDelegation()
|
||||
var link: NameId by EntityDataDelegation()
|
||||
}
|
||||
|
||||
internal fun WorkspaceEntityStorageBuilderImpl.addComposedIdSoftRefEntity(name: String, link: NameId, source: EntitySource = MySource): ComposedIdSoftRefEntity {
|
||||
return addEntity(ModifiableComposedIdSoftRefEntity::class.java, source) {
|
||||
this.name = name
|
||||
this.link = link
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user