Created
June 2, 2022 01:39
-
-
Save deusaquilus/00db19409bac2f633eea84412cf06aca to your computer and use it in GitHub Desktop.
Testing Null Option[Product] with OrientDB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package io.getquill.context.orientdb | |
import io.getquill.{ Insert, Literal, OrientDBSyncContext } | |
import io.getquill.context.encoding.OptionalNestedSpec | |
import io.getquill.context.orientdb.orientdb.{ resetSchema, setup } | |
import org.scalatest.BeforeAndAfterAll | |
class OptionalProductEncodingJdbcSpec extends OptionalNestedSpec with BeforeAndAfterAll { | |
val context: OrientDBSyncContext[Literal.type] = orientdb.testSyncDB | |
import context._ | |
override protected def beforeEach() = { | |
import Setup._ | |
// Since the setup() function sets up the schema for the `Contact` object we literally need a different schema | |
// for every test (since there are multiple definitions of `Contact` | |
context.run(infix"DROP Class Contact".as[Insert[Int]]) | |
context.run(infix"CREATE Class Contact".as[Insert[Int]]) | |
context.run(infix"CREATE Property Contact.firstName STRING".as[Insert[Int]]) | |
context.run(infix"CREATE Property Contact.lastName STRING (MANDATORY TRUE)".as[Insert[Int]]) | |
context.run(infix"CREATE Property Contact.age INTEGER".as[Insert[Int]]) | |
context.run(infix"CREATE Property Contact.addressFk INTEGER".as[Insert[Int]]) | |
context.run(infix"insert into Contact SET firstName = 'Place', lastName = null, age = 123, addressFk = 444".as[Insert[Contact]]) | |
() | |
} | |
override protected def afterAll() = { | |
// Reset the schema for future contexts that have their own version of | |
// the `Contact` table e.g. CaseClassQueryOrientSpec | |
resetSchema(context.currDatabase) | |
} | |
"1.Optional Inner Product" - { | |
import `1.Optional Inner Product`._ | |
"1.Ex1 - Not null inner product" in { | |
context.run(`1.Ex1 - Not null inner product insert`) | |
context.run(data).filter(_.firstName == "Joe") mustEqual List(`1.Ex1 - Not null inner product result`) | |
} | |
"1.Ex1 Auto - Not null inner product" in { | |
val result = `1.Ex1 - Not null inner product result` | |
context.run(data.insertValue(lift(result))) | |
context.run(data).filter(_.firstName == "Joe") mustEqual List(result) | |
} | |
// "1.Ex2 - null inner product" in { | |
// context.run(`1.Ex2 - null inner product insert`) | |
// context.run(data) mustEqual List(`1.Ex2 - null inner product result`) | |
// } | |
// "1.Ex2 Auto - null inner product" in { | |
// val result = `1.Ex2 - null inner product result` | |
// context.run(data.insertValue(lift(result))) | |
// context.run(data) mustEqual List(result) | |
// } | |
} | |
"2.Optional Inner Product" - { | |
import `2.Optional Inner Product with Optional Leaf`._ | |
"2.Ex1 - Not null inner product" in { | |
context.run(`2.Ex1 - not-null insert`) | |
context.run(data).filter(_.firstName == "Joe") mustEqual List(`2.Ex1 - not-null result`) | |
} | |
"2.Ex1 Auto - Not null inner product" in { | |
val result = `2.Ex1 - not-null result` | |
context.run(data.insertValue(lift(result))) | |
context.run(data).filter(_.firstName == "Joe") mustEqual List(result) | |
} | |
"2.Ex2 - Not null inner product" in { | |
context.run(`2.Ex2 - Null inner product insert`) | |
context.run(data) mustEqual List(`2.Ex2 - Null inner product result`) | |
} | |
"2.Ex2 Auto - Not null inner product" in { | |
val result = `2.Ex2 - Null inner product result` | |
context.run(data.insertValue(lift(result))) | |
context.run(data) mustEqual List(result) | |
} | |
"2.Ex3 - Null inner leaf" in { | |
context.run(`2.Ex3 - Null inner leaf insert`) | |
context.run(data) mustEqual List(`2.Ex3 - Null inner leaf result`) | |
} | |
"2.Ex3 Auto - Null inner leaf" in { | |
val result = `2.Ex3 - Null inner leaf result` | |
context.run(data.insertValue(lift(result))) | |
context.run(data) mustEqual List(result) | |
} | |
} | |
"3.Optional Nested Inner Product" - { | |
import `3.Optional Nested Inner Product`._ | |
"3.Ex1 - Null inner product insert" in { | |
context.run(`3.Ex1 - Null inner product insert`) | |
context.run(data) mustEqual List(`3.Ex1 - Null inner product result`) | |
} | |
"3.Ex1 Auto - Null inner product insert" in { | |
val result = `3.Ex1 - Null inner product result` | |
context.run(data.insertValue(lift(result))) | |
context.run(data) mustEqual List(result) | |
} | |
"3.Ex2 - Null inner leaf" in { | |
context.run(`3.Ex2 - Null inner leaf insert`) | |
context.run(data) mustEqual List(`3.Ex2 - Null inner leaf result`) | |
} | |
"3.Ex2 Auto - Null inner leaf" in { | |
val result = `3.Ex2 - Null inner leaf result` | |
context.run(data.insertValue(lift(result))) | |
context.run(data) mustEqual List(result) | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package io.getquill.context.orientdb | |
import com.orientechnologies.orient.core.db.{ ODatabasePool, ODatabaseSession, ODatabaseType, OrientDB, OrientDBConfig } | |
import com.orientechnologies.orient.core.metadata.schema.OSchema | |
import io.getquill.Literal | |
import io.getquill.OrientDBContextConfig | |
import io.getquill.OrientDBMirrorContext | |
import io.getquill.OrientDBSyncContext | |
import io.getquill.TestEntities | |
import io.getquill.util.LoadConfig | |
object orientdb { | |
private val databaseName = "GratefulDeadConcerts" | |
private val conf = OrientDBContextConfig(LoadConfig("ctx")) | |
var setupDone: Boolean = false | |
val tableList = List( | |
"DecodeNullTestEntity", | |
"EncodingTestEntity", | |
"ListEntity", | |
"ListsEntity", | |
"ListFrozen", | |
"MapEntity", | |
"MapsEntity", | |
"MapFrozen", | |
"TestEntity", | |
"TestEntity2", | |
"TestEntity3", | |
"Person", | |
"OrderTestEntity", | |
"SetsEntity", | |
"Contact", | |
"Address" | |
) | |
private def setup(): Unit = { | |
val orientDB = new OrientDB(conf.dbUrl, "root", "root", OrientDBConfig.defaultConfig()) | |
orientDB.createIfNotExists(databaseName, ODatabaseType.MEMORY) | |
val pool = new ODatabasePool(conf.dbUrl, "root", "root") | |
val schema = pool.acquire().getMetadata.getSchema | |
tableList.foreach(tbl => getOrCreateClass(schema, tbl)) | |
setupDone = true | |
} | |
private def getOrCreateClass(iSchema: OSchema, iClassName: String): Unit = { | |
if (!iSchema.existsClass(iClassName)) { | |
iSchema.createClass(iClassName) | |
() | |
} | |
} | |
def mirrorContext = { | |
if (!setupDone) { setup() } | |
new OrientDBMirrorContext(Literal) with TestEntities | |
} | |
def testSyncDB = { | |
if (!setupDone) { setup() } | |
new OrientDBSyncContext(Literal, "ctx") | |
} | |
def resetSchema(db: ODatabaseSession) = { | |
val schema = db.getMetadata.getSchema | |
tableList.foreach(tbl => schema.dropClass(tbl)) | |
tableList.foreach(tbl => schema.createClass(tbl)) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment