Skip to content

Commit 183ce66

Browse files
authored
Merge pull request #538 from modelix/test/bulk-sync-lib-multiplatform-test
Migrate bulk-sync-lib tests from jvm to multiplatform
2 parents 121630a + d954e85 commit 183ce66

File tree

10 files changed

+676
-432
lines changed

10 files changed

+676
-432
lines changed

bulk-model-sync-lib/build.gradle.kts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,19 @@ kotlin {
2121
}
2222
}
2323

24-
val jvmTest by getting {
24+
val commonTest by getting {
2525
dependencies {
2626
implementation(project(":model-api"))
2727
implementation(libs.kotlin.serialization.json)
28-
implementation(project(":model-client", configuration = "jvmRuntimeElements"))
28+
implementation(project(":model-client"))
2929
implementation(kotlin("test"))
3030
}
3131
}
32+
33+
val jvmTest by getting {
34+
dependencies {
35+
implementation(project(":model-client", configuration = "jvmRuntimeElements"))
36+
}
37+
}
3238
}
3339
}
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
/*
2+
* Copyright (c) 2023-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.sync.bulk
18+
19+
import org.modelix.model.api.IBranch
20+
import org.modelix.model.api.PBranch
21+
import org.modelix.model.api.getRootNode
22+
import org.modelix.model.client.IdGenerator
23+
import org.modelix.model.data.ModelData
24+
import org.modelix.model.lazy.CLTree
25+
import org.modelix.model.lazy.ObjectStoreCache
26+
import org.modelix.model.persistent.MapBasedStore
27+
import kotlin.js.JsName
28+
import kotlin.test.Test
29+
import kotlin.test.assertEquals
30+
31+
class ModelExporterTest {
32+
// language=json
33+
private var serializedModel = """
34+
{
35+
"root": {
36+
"id": "node:001",
37+
"children": [
38+
{
39+
"id": "node:002",
40+
"properties": {
41+
"propA": "ValueA",
42+
"propB": "ValueB"
43+
},
44+
"children": [
45+
{
46+
"id": "node:004",
47+
"references": {
48+
"refA": "node:003"
49+
}
50+
}
51+
]
52+
},
53+
{
54+
"id": "node:003",
55+
"properties": {
56+
"purpose": "reference sync test"
57+
},
58+
"references": {
59+
"root": "node:001",
60+
"self": "node:003"
61+
}
62+
}
63+
]
64+
}
65+
}
66+
""".trimIndent()
67+
68+
private val model = ModelData.fromJson(serializedModel)
69+
70+
private fun runTest(body: IBranch.() -> Unit) {
71+
val branch = PBranch(CLTree(ObjectStoreCache(MapBasedStore())), IdGenerator.getInstance(1))
72+
branch.runWrite {
73+
model.load(branch)
74+
}
75+
body(branch)
76+
}
77+
78+
@Test
79+
@JsName("export_conforms_to_input")
80+
fun `export conforms to input`() = runTest {
81+
val exported = computeRead { getRootNode().asExported() }
82+
assertEquals(model.root, exported)
83+
}
84+
}
Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2023.
2+
* Copyright (c) 2023-2024.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -16,7 +16,6 @@
1616

1717
package org.modelix.model.sync.bulk
1818

19-
import org.junit.jupiter.api.Test
2019
import org.modelix.model.api.IBranch
2120
import org.modelix.model.api.INode
2221
import org.modelix.model.api.PBranch
@@ -30,6 +29,8 @@ import org.modelix.model.lazy.CLTree
3029
import org.modelix.model.lazy.ObjectStoreCache
3130
import org.modelix.model.persistent.MapBasedStore
3231
import org.modelix.model.withAutoTransactions
32+
import kotlin.js.JsName
33+
import kotlin.test.Test
3334
import kotlin.test.assertEquals
3435

3536
/**
@@ -94,6 +95,7 @@ class ModelImporterOrderPropertyTest {
9495
}
9596

9697
@Test
98+
@JsName("nodes_in_unordered_child_link_are_added_and_removed")
9799
fun `nodes in unordered child link are added and removed`() {
98100
// language=json
99101
val dataBeforeImportJson = """
@@ -173,6 +175,7 @@ class ModelImporterOrderPropertyTest {
173175
}
174176

175177
@Test
178+
@JsName("nodes_in_unordered_child_link_can_change_child_link_inside_same_parent")
176179
fun `nodes in unordered child link can change child link inside same parent`() {
177180
// language=json
178181
val dataBeforeImportJson = """
@@ -242,6 +245,7 @@ class ModelImporterOrderPropertyTest {
242245
}
243246

244247
@Test
248+
@JsName("nodes_in_unordered_child_link_can_change_parent")
245249
fun `nodes in unordered child link can change parent`() {
246250
// language=json
247251
val dataBeforeImportJson = """
@@ -314,6 +318,7 @@ class ModelImporterOrderPropertyTest {
314318
}
315319

316320
@Test
321+
@JsName("children_without_resolvable_role_are_ordered")
317322
fun `children without resolvable role are ordered`() {
318323
// language=json
319324
val dataBeforeImportJson = """

0 commit comments

Comments
 (0)