|
| 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.mpsadapters |
| 18 | + |
| 19 | +import org.modelix.model.api.BuiltinLanguages |
| 20 | +import org.modelix.model.api.ConceptReference |
| 21 | +import org.modelix.model.api.INode |
| 22 | + |
| 23 | +class ReplaceNodeTest : MpsAdaptersTestBase("SimpleProject") { |
| 24 | + |
| 25 | + fun testReplaceNode() { |
| 26 | + readAction { |
| 27 | + assertEquals(1, mpsProject.projectModules.size) |
| 28 | + } |
| 29 | + |
| 30 | + val repositoryNode: INode = MPSRepositoryAsNode(mpsProject.repository) |
| 31 | + |
| 32 | + writeActionOnEdt { |
| 33 | + val module = repositoryNode.getChildren(BuiltinLanguages.MPSRepositoryConcepts.Repository.modules) |
| 34 | + .single { it.getPropertyValue(BuiltinLanguages.jetbrains_mps_lang_core.INamedConcept.name) == "Solution1" } |
| 35 | + val model = module.getChildren(BuiltinLanguages.MPSRepositoryConcepts.Module.models).single() |
| 36 | + val rootNode = model.getChildren(BuiltinLanguages.MPSRepositoryConcepts.Model.rootNodes).single() |
| 37 | + |
| 38 | + val oldProperties = rootNode.getAllProperties().toSet() |
| 39 | + val oldReferences = rootNode.getAllReferenceTargetRefs().toSet() |
| 40 | + val oldChildren = rootNode.allChildren.toList() |
| 41 | + |
| 42 | + val newConcept = ConceptReference("mps:f3061a53-9226-4cc5-a443-f952ceaf5816/1083245097125") |
| 43 | + val newNode = rootNode.replaceNode(newConcept) |
| 44 | + |
| 45 | + assertEquals(oldProperties, newNode.getAllProperties().toSet()) |
| 46 | + assertEquals(oldReferences, newNode.getAllReferenceTargetRefs().toSet()) |
| 47 | + assertEquals(oldChildren, newNode.allChildren.toList()) |
| 48 | + assertEquals(newConcept, newNode.getConceptReference()) |
| 49 | + } |
| 50 | + } |
| 51 | +} |
0 commit comments