Skip to content

Commit

Permalink
Merge pull request #904 from modelix/fix/do-not-require-registered-co…
Browse files Browse the repository at this point in the history
…ncept-for-serialization-to-NodeData

fix(model-api): do not require registered concept for serialization to NodeData
  • Loading branch information
odzhychko authored Jul 18, 2024
2 parents e453922 + 704f6cc commit 6bf3cf6
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 1 deletion.
1 change: 1 addition & 0 deletions model-api/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ kotlin {
}
val commonTest by getting {
dependencies {
implementation(project(":model-datastructure"))
implementation(kotlin("test"))
implementation(libs.kotest.assertions.core)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ fun ModelData.nodeUID(node: NodeData): String = node.uid(this)

fun INode.asData(): NodeData = NodeData(
id = reference.serialize(),
concept = concept?.getUID(),
concept = getConceptReference()?.getUID(),
role = roleInParent,
properties = getPropertyRoles().associateWithNotNull { getPropertyValue(it) },
references = getReferenceRoles().associateWithNotNull { getReferenceTargetRef(it)?.serialize() },
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
* Copyright (c) 2024.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.modelix.model.data

import org.modelix.model.api.ChildLinkFromName
import org.modelix.model.api.ConceptReference
import org.modelix.model.api.INode
import org.modelix.model.api.TreePointer
import org.modelix.model.api.getRootNode
import org.modelix.model.client.IdGenerator
import org.modelix.model.lazy.CLTree
import org.modelix.model.lazy.NonCachingObjectStore
import org.modelix.model.persistent.MapBasedStore
import kotlin.test.Test
import kotlin.test.assertEquals

class ModelDataTest {

@Test
fun nodeWithConceptReferenceButWithoutRegisteredConceptCanSerialized() {
val aChildLink = ChildLinkFromName("aChildLink")
val aConceptReference = ConceptReference("aConceptReference")
val rootNode = createEmptyRootNode()
rootNode.addNewChild(aChildLink, -1, aConceptReference)

val nodeData = rootNode.asData()

val child = nodeData.children.single { child -> child.role == aChildLink.getUID() }
assertEquals(aConceptReference.getUID(), child.concept)
}
}

internal fun createEmptyRootNode(): INode {
val tree = CLTree(NonCachingObjectStore(MapBasedStore()))
val branch = TreePointer(tree, IdGenerator.getInstance(1))
return branch.getRootNode()
}

0 comments on commit 6bf3cf6

Please sign in to comment.