|
| 1 | +/* |
| 2 | + * Copyright (c) 2024. |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | + |
| 17 | +package org.modelix.model.data |
| 18 | + |
| 19 | +import org.modelix.model.api.ChildLinkFromName |
| 20 | +import org.modelix.model.api.ConceptReference |
| 21 | +import org.modelix.model.api.INode |
| 22 | +import org.modelix.model.api.TreePointer |
| 23 | +import org.modelix.model.api.getRootNode |
| 24 | +import org.modelix.model.client.IdGenerator |
| 25 | +import org.modelix.model.lazy.CLTree |
| 26 | +import org.modelix.model.lazy.NonCachingObjectStore |
| 27 | +import org.modelix.model.persistent.MapBasedStore |
| 28 | +import kotlin.test.Test |
| 29 | +import kotlin.test.assertEquals |
| 30 | + |
| 31 | +class ModelDataTest { |
| 32 | + |
| 33 | + @Test |
| 34 | + fun nodeWithConceptReferenceButWithoutRegisteredConceptCanSerialized() { |
| 35 | + val aChildLink = ChildLinkFromName("aChildLink") |
| 36 | + val aConceptReference = ConceptReference("aConceptReference") |
| 37 | + val rootNode = createEmptyRootNode() |
| 38 | + rootNode.addNewChild(aChildLink, -1, aConceptReference) |
| 39 | + |
| 40 | + val nodeData = rootNode.asData() |
| 41 | + |
| 42 | + val child = nodeData.children.single { child -> child.role == aChildLink.getUID() } |
| 43 | + assertEquals(aConceptReference.getUID(), child.concept) |
| 44 | + } |
| 45 | +} |
| 46 | + |
| 47 | +internal fun createEmptyRootNode(): INode { |
| 48 | + val tree = CLTree(NonCachingObjectStore(MapBasedStore())) |
| 49 | + val branch = TreePointer(tree, IdGenerator.getInstance(1)) |
| 50 | + return branch.getRootNode() |
| 51 | +} |
0 commit comments