@@ -33,12 +33,19 @@ import io.ktor.server.websocket.WebSockets
33
33
import org.jsoup.Jsoup
34
34
import org.jsoup.nodes.Element
35
35
import org.jsoup.select.Evaluator
36
+ import org.modelix.model.api.IReferenceLink
37
+ import org.modelix.model.api.ITree
38
+ import org.modelix.model.api.NodeReferenceById
36
39
import org.modelix.model.client.successful
40
+ import org.modelix.model.client2.ModelClientV2
41
+ import org.modelix.model.client2.runWrite
37
42
import org.modelix.model.lazy.CLVersion
43
+ import org.modelix.model.lazy.RepositoryId
38
44
import org.modelix.model.server.api.v2.VersionDelta
39
45
import org.modelix.model.server.store.InMemoryStoreClient
40
46
import org.modelix.model.server.store.LocalModelClient
41
47
import kotlin.test.Test
48
+ import kotlin.test.assertEquals
42
49
import kotlin.test.assertNotNull
43
50
import kotlin.test.assertTrue
44
51
import io.ktor.client.plugins.contentnegotiation.ContentNegotiation as ClientContentNegotiation
@@ -63,6 +70,12 @@ class ContentExplorerTest {
63
70
}
64
71
}
65
72
73
+ private suspend fun ApplicationTestBuilder.createModelClient (): ModelClientV2 {
74
+ val url = " http://localhost/v2"
75
+ val modelClient = ModelClientV2 .builder().url(url).client(client).build().also { it.init () }
76
+ return modelClient
77
+ }
78
+
66
79
@Test
67
80
fun `node inspector finds root node` () = runTest {
68
81
val client = createClient {
@@ -79,6 +92,34 @@ class ContentExplorerTest {
79
92
assertTrue(response.successful)
80
93
}
81
94
95
+ @Test
96
+ fun `node inspector can handle unresolvable references` () = runTest {
97
+ val modelClient = createModelClient()
98
+ val repoId = RepositoryId (" node-inspector-null-ref" )
99
+ val branchRef = repoId.getBranchReference(" master" )
100
+ val refLinkName = " myUnresolvableRef"
101
+ val refLinkTargetRef = NodeReferenceById (" notAResolvableId" )
102
+
103
+ modelClient.initRepository(repoId)
104
+
105
+ modelClient.runWrite(branchRef) { root ->
106
+ root.setReferenceTarget(IReferenceLink .fromName(refLinkName), refLinkTargetRef)
107
+ }
108
+
109
+ val versionHash = modelClient.pullHash(branchRef)
110
+
111
+ val response = client.get(" /content/$versionHash /${ITree .ROOT_ID } /" )
112
+ val html = Jsoup .parse(response.bodyAsText())
113
+ val nameCell = html.selectXpath(""" //td[text()="$refLinkName "]""" ).first() ? : error(" table cell not found" )
114
+ val row = checkNotNull(nameCell.parent()) { " table row not found" }
115
+ val targetNodeIdCell = row.allElements[2 ] // index 0 is the row itself and 1 the nameCell
116
+ val targetRefCell = row.allElements[3 ]
117
+
118
+ assertTrue(response.successful)
119
+ assertEquals(" null" , targetNodeIdCell.text())
120
+ assertEquals(refLinkTargetRef.serialize(), targetRefCell.text())
121
+ }
122
+
82
123
@Test
83
124
fun `nodes can be expanded` () = runTest {
84
125
val client = createClient {
0 commit comments