Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add: test for RelationIdentifier #119

Merged
merged 1 commit into from Jan 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
37 changes: 37 additions & 0 deletions src/test/scala/domain/table/ddl/column/ColumnTypeSpec.scala
@@ -1,5 +1,6 @@
package domain.table.ddl.column

import org.janusgraph.graphdb.relations.RelationIdentifier
import org.scalatest.funspec.AnyFunSpec
import org.scalatest.matchers.should.Matchers

Expand All @@ -9,19 +10,41 @@ import java.util
class ColumnTypeSpec extends AnyFunSpec with Matchers {
describe("apply") {
it("success") {
// Boolean
ColumnType.apply(false) shouldBe ColumnTypeBoolean

// Byte
ColumnType.apply(1.toByte) shouldBe ColumnTypeByte(ColumnLength(1))

// Short
ColumnType.apply(1.toShort) shouldBe ColumnTypeShort(ColumnLength(1))

// Int
ColumnType.apply(1) shouldBe ColumnTypeInt(ColumnLength(1))

// Long
ColumnType.apply(1.toLong) shouldBe ColumnTypeLong(ColumnLength(1))

// Float
ColumnType.apply(1.1.toFloat) shouldBe ColumnTypeFloat(ColumnLength(3))

// Double
ColumnType.apply(1.1) shouldBe ColumnTypeDouble(ColumnLength(3))

// util.UUID
ColumnType.apply(util.UUID.randomUUID()) shouldBe ColumnTypeUUID

// Date
ColumnType.apply(Instant.MAX) shouldBe ColumnTypeDate(ColumnLength(37))
ColumnType.apply(Instant.MIN) shouldBe ColumnTypeDate(ColumnLength(27))

// Char
ColumnType.apply('a') shouldBe ColumnTypeCharacter(ColumnLength(1))

// String
ColumnType.apply("string") shouldBe ColumnTypeString(ColumnLength(6))

// util.ArrayList
val arrayList1 = new util.ArrayList[String]()
arrayList1.add("a")
ColumnType.apply(arrayList1) shouldBe ColumnTypeString(ColumnLength(1))
Expand All @@ -30,6 +53,15 @@ class ColumnTypeSpec extends AnyFunSpec with Matchers {
arrayList2.add("a")
arrayList2.add("a")
ColumnType.apply(arrayList2) shouldBe ColumnTypeUnknown

// RelationalIdentifier
val relationIdentifier =
new RelationIdentifier(new Object(), 1, 1, new Object())
ColumnType.apply(relationIdentifier) shouldBe ColumnTypeString(
ColumnLength(57)
)

// the other
ColumnType.apply(Seq.empty) shouldBe ColumnTypeUnknown
}
}
Expand Down Expand Up @@ -710,6 +742,11 @@ class ColumnTypeSpec extends AnyFunSpec with Matchers {
arrayList2.add("a")
ColumnType.apply(arrayList2).toSqlSentence shouldBe "TEXT"

// RelationalIdentifier
val relationIdentifier =
new RelationIdentifier(new Object(), 1, 1, new Object())
ColumnType.apply(relationIdentifier).toSqlSentence shouldBe "VARCHAR(57)"

// the others
ColumnType.apply(Seq.empty).toSqlSentence shouldBe "TEXT"
}
Expand Down
32 changes: 32 additions & 0 deletions src/test/scala/domain/table/dml/RecordValueSpec.scala
@@ -1,5 +1,6 @@
package domain.table.dml

import org.janusgraph.graphdb.relations.RelationIdentifier
import org.scalatest.funspec.AnyFunSpec
import org.scalatest.matchers.should.Matchers

Expand All @@ -10,25 +11,42 @@ import java.util
class RecordValueSpec extends AnyFunSpec with Matchers {
describe("toSqlSentence") {
it("success") {
// Boolean
RecordValue(
Map(("boolean", false))
).toSqlSentence shouldBe ("boolean", "false")

// Byte
RecordValue(Map(("byte", 1.toByte))).toSqlSentence shouldBe ("byte", "1")

// Short
RecordValue(
Map(("short", 1.toShort))
).toSqlSentence shouldBe ("short", "1")

// Int
RecordValue(Map(("int", 1))).toSqlSentence shouldBe ("int", "1")

// Long
RecordValue(Map(("long", 1.toLong))).toSqlSentence shouldBe ("long", "1")

// Float
RecordValue(
Map(("float", 1.toFloat))
).toSqlSentence shouldBe ("float", "1.0")

// Double
RecordValue(
Map(("double", 1.toDouble))
).toSqlSentence shouldBe ("double", "1.0")

// util.UUID
val uuid = util.UUID.randomUUID()
RecordValue(
Map(("uuid", uuid))
).toSqlSentence shouldBe ("uuid", s"'$uuid'")

// Date
val dateMin = Instant.MIN
RecordValue(
Map(("dateMin", dateMin))
Expand All @@ -37,13 +55,18 @@ class RecordValueSpec extends AnyFunSpec with Matchers {
RecordValue(
Map(("dateMax", dateMax))
).toSqlSentence shouldBe ("dateMax", s"'${Timestamp.from(dateMax)}'")

// Char
RecordValue(
Map(("char", 'a'))
).toSqlSentence shouldBe ("char", "'a'")

// String
RecordValue(
Map(("string", 1.toString))
).toSqlSentence shouldBe ("string", "'1'")

// util.ArrayList
val arrayList1 = new util.ArrayList[String]()
arrayList1.add("a")
RecordValue(
Expand All @@ -56,6 +79,15 @@ class RecordValueSpec extends AnyFunSpec with Matchers {
RecordValue(
Map(("arrayList2", arrayList2))
).toSqlSentence shouldBe ("arrayList2", "'[a, a]'")

// RelationIdentifier
val relationIdentifier =
new RelationIdentifier(new Object(), 1, 1, new Object())
RecordValue(
Map("RelationIdentifier" -> relationIdentifier)
).toSqlSentence shouldBe ("RelationIdentifier", s"'${relationIdentifier.toString}'")

// the other
RecordValue(
Map(("unknown", Seq(1)))
).toSqlSentence shouldBe ("unknown", "'List(1)'")
Expand Down