-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #62 from ergon/feature/dope-246-integration-tests
DOPE-246: added integration tests with test containers
- Loading branch information
Showing
14 changed files
with
991 additions
and
2 deletions.
There are no files selected for viewing
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
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
69 changes: 69 additions & 0 deletions
69
core/src/integrationTest/kotlin/ch/ergon/dope/clauses/DeleteIntegrationTest.kt
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
package ch.ergon.dope.clauses | ||
|
||
import ch.ergon.dope.QueryBuilder | ||
import ch.ergon.dope.integrationTest.BaseIntegrationTest | ||
import ch.ergon.dope.integrationTest.TestCouchbaseDatabase.idField | ||
import ch.ergon.dope.integrationTest.TestCouchbaseDatabase.resetDatabase | ||
import ch.ergon.dope.integrationTest.TestCouchbaseDatabase.testBucket | ||
import ch.ergon.dope.integrationTest.toMapValues | ||
import ch.ergon.dope.integrationTest.tryUntil | ||
import ch.ergon.dope.resolvable.expression.unaliased.type.arithmetic.add | ||
import ch.ergon.dope.resolvable.expression.unaliased.type.relational.isEqualTo | ||
import ch.ergon.dope.resolvable.fromable.useKeys | ||
import kotlin.test.AfterTest | ||
import kotlin.test.Test | ||
import kotlin.test.assertEquals | ||
|
||
class DeleteIntegrationTest : BaseIntegrationTest() { | ||
@AfterTest | ||
fun reset() { | ||
resetDatabase() | ||
} | ||
|
||
@Test | ||
fun `delete single document and return id field`() { | ||
val dopeQuery = QueryBuilder() | ||
.deleteFrom( | ||
testBucket.useKeys("employee:1"), | ||
) | ||
.returning( | ||
idField, | ||
).build() | ||
|
||
tryUntil { | ||
val queryResult = queryWithoutParameters(dopeQuery) | ||
val result = queryResult.toMapValues() | ||
|
||
assertEquals(1, result["id"]) | ||
} | ||
} | ||
|
||
@Test | ||
fun `delete every document in bucket`() { | ||
val deleteEverythingDopeQuery = QueryBuilder() | ||
.deleteFrom( | ||
testBucket, | ||
) | ||
.where( | ||
1.add(1).isEqualTo(2), | ||
) | ||
.returning( | ||
idField, | ||
).build() | ||
|
||
val selectEverythingDopeQuery = QueryBuilder() | ||
.selectFrom( | ||
testBucket, | ||
).build() | ||
|
||
tryUntil { | ||
val selectBeforeDeleteQueryResult = queryWithoutParameters(selectEverythingDopeQuery) | ||
val deleteQueryResult = queryWithoutParameters(deleteEverythingDopeQuery) | ||
val selectAfterDeleteQueryResult = queryWithoutParameters(selectEverythingDopeQuery) | ||
|
||
assertEquals(15, selectBeforeDeleteQueryResult.rows.size) | ||
assertEquals(15, deleteQueryResult.rows.size) | ||
assertEquals(0, selectAfterDeleteQueryResult.rows.size) | ||
} | ||
} | ||
} |
116 changes: 116 additions & 0 deletions
116
core/src/integrationTest/kotlin/ch/ergon/dope/clauses/JoinIntegrationTest.kt
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
package ch.ergon.dope.clauses | ||
|
||
import ch.ergon.dope.QueryBuilder | ||
import ch.ergon.dope.integrationTest.BaseIntegrationTest | ||
import ch.ergon.dope.integrationTest.TestCouchbaseDatabase.testBucket | ||
import ch.ergon.dope.integrationTest.toMapValues | ||
import ch.ergon.dope.integrationTest.tryUntil | ||
import ch.ergon.dope.resolvable.clause.model.OrderByType.ASC | ||
import ch.ergon.dope.resolvable.clause.model.OrderByType.DESC | ||
import ch.ergon.dope.resolvable.clause.model.joinHint.HashOrNestedLoopHint.NESTED_LOOP | ||
import ch.ergon.dope.resolvable.clause.model.joinHint.indexHint | ||
import ch.ergon.dope.resolvable.expression.alias | ||
import ch.ergon.dope.resolvable.expression.unaliased.type.Field | ||
import ch.ergon.dope.resolvable.expression.unaliased.type.meta.meta | ||
import ch.ergon.dope.resolvable.expression.unaliased.type.relational.isEqualTo | ||
import ch.ergon.dope.validtype.StringType | ||
import kotlin.test.Test | ||
import kotlin.test.assertEquals | ||
|
||
class JoinIntegrationTest : BaseIntegrationTest() { | ||
@Test | ||
fun `join all orders on employee id`() { | ||
val employeeAlias = testBucket.alias("e") | ||
val orderAlias = testBucket.alias("o") | ||
val employeeNameField = Field<StringType>("name", employeeAlias.alias) | ||
val orderNumberField = Field<StringType>("orderNumber", orderAlias.alias) | ||
val orderEmployeeIdField = Field<StringType>("employee", orderAlias.alias) | ||
val dopeQuery = QueryBuilder() | ||
.select( | ||
employeeNameField, | ||
orderNumberField, | ||
) | ||
.from( | ||
employeeAlias, | ||
) | ||
.join( | ||
orderAlias, | ||
orderEmployeeIdField.isEqualTo(meta(employeeAlias).id), | ||
).orderBy( | ||
orderNumberField, | ||
ASC, | ||
).build() | ||
|
||
tryUntil { | ||
val queryResult = queryWithoutParameters(dopeQuery) | ||
|
||
assertEquals(5, queryResult.rows.size) | ||
assertEquals(mapOf("name" to "employee1", "orderNumber" to "order1"), queryResult.toMapValues(rowNumber = 0)) | ||
assertEquals(mapOf("name" to "employee2", "orderNumber" to "order2"), queryResult.toMapValues(rowNumber = 1)) | ||
assertEquals(mapOf("name" to "employee3", "orderNumber" to "order3"), queryResult.toMapValues(rowNumber = 2)) | ||
assertEquals(mapOf("name" to "employee4", "orderNumber" to "order4"), queryResult.toMapValues(rowNumber = 3)) | ||
assertEquals(mapOf("name" to "employee5", "orderNumber" to "order5"), queryResult.toMapValues(rowNumber = 4)) | ||
} | ||
} | ||
|
||
@Test | ||
fun `join documents with multiple joins`() { | ||
val employeeAlias = testBucket.alias("e") | ||
val clientAlias = testBucket.alias("c") | ||
val orderAlias = testBucket.alias("o") | ||
val employeeNameField = Field<StringType>("name", employeeAlias.alias) | ||
val clientNameField = Field<StringType>("name", clientAlias.alias) | ||
val orderNumberField = Field<StringType>("orderNumber", orderAlias.alias) | ||
val orderEmployeeIdField = Field<StringType>("employee", orderAlias.alias) | ||
val orderClientIdField = Field<StringType>("client", orderAlias.alias) | ||
val dopeQuery = QueryBuilder() | ||
.select( | ||
orderNumberField, | ||
employeeNameField.alias("employeeName"), | ||
clientNameField.alias("clientName"), | ||
) | ||
.from( | ||
orderAlias, | ||
) | ||
.join( | ||
employeeAlias, | ||
orderEmployeeIdField.isEqualTo(meta(employeeAlias).id), | ||
hashOrNestedLoopHint = NESTED_LOOP, | ||
) | ||
.innerJoin( | ||
clientAlias, | ||
orderClientIdField.isEqualTo(meta(clientAlias).id), | ||
keysOrIndexHint = indexHint(), | ||
).orderBy( | ||
orderNumberField, | ||
DESC, | ||
) | ||
.build() | ||
|
||
tryUntil { | ||
val queryResult = queryWithoutParameters(dopeQuery) | ||
|
||
assertEquals(5, queryResult.rows.size) | ||
assertEquals( | ||
mapOf("employeeName" to "employee5", "orderNumber" to "order5", "clientName" to "client5"), | ||
queryResult.toMapValues(rowNumber = 0), | ||
) | ||
assertEquals( | ||
mapOf("employeeName" to "employee4", "orderNumber" to "order4", "clientName" to "client4"), | ||
queryResult.toMapValues(rowNumber = 1), | ||
) | ||
assertEquals( | ||
mapOf("employeeName" to "employee3", "orderNumber" to "order3", "clientName" to "client3"), | ||
queryResult.toMapValues(rowNumber = 2), | ||
) | ||
assertEquals( | ||
mapOf("employeeName" to "employee2", "orderNumber" to "order2", "clientName" to "client2"), | ||
queryResult.toMapValues(rowNumber = 3), | ||
) | ||
assertEquals( | ||
mapOf("employeeName" to "employee1", "orderNumber" to "order1", "clientName" to "client1"), | ||
queryResult.toMapValues(rowNumber = 4), | ||
) | ||
} | ||
} | ||
} |
Oops, something went wrong.