Skip to content
This repository was archived by the owner on Feb 16, 2024. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ class GraphElementBuilder(graph: S2GraphLike) {
val (ts, operation, logType, srcId, tgtId, label) = (parts(0), parts(1), parts(2), parts(3), parts(4), parts(5))
val props = if (parts.length >= 7) fromJsonToProperties(Json.parse(parts(6)).asOpt[JsObject].getOrElse(Json.obj())) else Map.empty[String, Any]
val tempDirection = if (parts.length >= 8) parts(7) else "out"
val direction = if (tempDirection != "out" && tempDirection != "in") "out" else tempDirection
val direction = if (tempDirection != "out" && tempDirection != "in" && tempDirection != "undirected") "out" else tempDirection
val edge = toEdge(srcId, tgtId, label, direction, props, ts.toLong, operation)
Option(edge)
} recover {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package org.apache.s2graph.core

import org.apache.s2graph.core.mysqls.Label
import org.scalatest._

class GraphElementBuilderTest extends FunSuite with Matchers with TestCommon with TestCommonWithModels {
initTests()

/*
In Test CommonWithModels,
- labelName: undirectedLabelName is created as undirected label.
- labelName: labelName is created as directed label.
*/
val timestamp = "1"
val operation = "insert"
val logType = "edge"
val srcId = 1L
val tgtId = 101L
val props = "{}"
val outDirection = "out"
val inDirection = "in"


test("toEdge with directed label. direction out.") {
val parts = Array(
timestamp, operation, logType, srcId.toString, tgtId.toString, labelName, props, outDirection
)

val s2EdgeLike = builder.toEdge(parts).get
s2EdgeLike.srcVertex.id.innerId.value shouldBe(srcId)
s2EdgeLike.tgtVertex.id.innerId.value shouldBe(tgtId)
s2EdgeLike.getDirection() shouldBe("out")

}
test("toEdge with directed label. direction in.") {
val parts = Array(
timestamp, operation, logType, srcId.toString, tgtId.toString, labelName, props, inDirection
)

val s2EdgeLike = builder.toEdge(parts).get
s2EdgeLike.srcVertex.id.innerId.value shouldBe(srcId)
s2EdgeLike.tgtVertex.id.innerId.value shouldBe(tgtId)
s2EdgeLike.getDirection() shouldBe("in")

}
test("toEdge with undirected label. direction out.") {
// undirectedLabelName has tgtColumnType as string.
val parts = Array(
timestamp, operation, logType, srcId.toString, tgtId.toString, undirectedLabelName, props, outDirection
)

val s2EdgeLike = builder.toEdge(parts).get
s2EdgeLike.srcVertex.id.innerId.value shouldBe(srcId)
s2EdgeLike.tgtVertex.id.innerId.value shouldBe(tgtId.toString)
s2EdgeLike.getDirection() shouldBe("out")
}
}