Skip to content

Commit

Permalink
Testing #120 db integration
Browse files Browse the repository at this point in the history
  • Loading branch information
TebaleloS committed Apr 24, 2024
1 parent 44c3664 commit 7e30a62
Show file tree
Hide file tree
Showing 5 changed files with 99 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -158,4 +158,43 @@ class GetPartitioningAdditionalDataTest extends DBTestSuite{
}
}

// Integration test
test("Testing actual data") {
val partitioning = JsonBString(
"""
|{
| "version": 1,
| "keys": ["string1", "string2"],
| "keysToValues": {
| "string1": "string1",
| "string2": "string2"
| }
|}
|""".stripMargin
)

function("runs.get_partitioning_additional_data")
.setParam("i_partitioning", partitioning)
.execute { queryResult =>
var rowCount = 0

queryResult.foreach(row => {

rowCount += 1

println(s"Row number ${rowCount}")
println(s"Row: ${row}")
val columnCount = row.resultSet.getMetaData.getColumnCount
for (i <- 1 to columnCount) {
println(s"Column ${i}: ${row.resultSet.getString(i)}")
}
println()

})

println()
println(s"Total rows: $rowCount")
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -139,5 +139,44 @@ class GetPartitioningMeasuresTest extends DBTestSuite {
}
}

//integration testing
test("Testing actual data") {
val partitioning = JsonBString(
"""
|{
| "version": 1,
| "keys": ["string1", "string2"],
| "keysToValues": {
| "string1": "string1",
| "string2": "string2"
| }
|}
|""".stripMargin
)

function("runs.get_partitioning_measures")
.setParam("i_partitioning", partitioning)
.execute { queryResult =>
var rowCount = 0

queryResult.foreach(row => {

rowCount+= 1

println(s"Row number ${rowCount}")
println(s"Row: ${row}")
val columnCount = row.resultSet.getMetaData.getColumnCount
for (i <- 1 to columnCount) {
println(s"Column ${i}: ${row.resultSet.getString(i)}")
}
println()

})

println()
println(s"Total rows: $rowCount")
}
}

}

Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,17 @@ class PartitioningControllerImpl(partitioningService: PartitioningService)
for {
_ <- partitioningService.createPartitioningIfNotExists(partitioningSubmitDTO)
.mapError(serviceError => InternalServerErrorResponse(serviceError.message))
// _ <- ZIO.logInfo(s"Partitioning ${partitioningSubmitDTO} created")
measures <- partitioningService.getPartitioningMeasures(partitioningSubmitDTO.partitioning)
.mapError {
serviceError: ServiceError => InternalServerErrorResponse(serviceError.message)
}
// _ <- ZIO.logInfo(s"Measures for partitioning ${partitioningSubmitDTO} retrievedM")
additionalData <- partitioningService.getPartitioningAdditionalData(partitioningSubmitDTO.partitioning)
.mapError {
serviceError: ServiceError => InternalServerErrorResponse(serviceError.message)
}
// _ <- ZIO.logInfo(s"Additional data for partitioning ${partitioningSubmitDTO} retrievedA")
} yield AtumContextDTO(partitioningSubmitDTO.partitioning, measures.toSet, additionalData)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,19 @@ import za.co.absa.atum.server.api.database.DoobieImplicits.Sequence.get
class GetPartitioningMeasures (implicit schema: DBSchema, dbEngine: DoobieEngine[Task])
extends DoobieMultipleResultFunction[PartitioningDTO, MeasureDTO, Task]
{
import za.co.absa.atum.server.api.database.DoobieImplicits.Jsonb.jsonbPutUsingString

override def sql(values: PartitioningDTO)(implicit read: Read[MeasureDTO]): Fragment = {
val partitioning = PartitioningForDB.fromSeqPartitionDTO(values)
val partitioningJsonString = Json.toJson(partitioning).toString

sql"""SELECT ${Fragment.const(selectEntry)} FROM ${Fragment.const(functionName)}(
// println(partitioning)
println(partitioningJsonString)
val sqlResults = sql"""SELECT ${Fragment.const(selectEntry)} FROM ${Fragment.const(functionName)}(
${
import za.co.absa.atum.server.api.database.DoobieImplicits.Jsonb.jsonbPutUsingString
partitioningJsonString
}
) ${Fragment.const(alias)};"""
println(sqlResults)
sqlResults
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,18 @@ class GetPartitioningMeasuresSpec extends ConfigProviderSpec {
getPartitioningMeasures <- ZIO.service[GetPartitioningMeasures]
result <- getPartitioningMeasures(partitioningDTO).either
} yield assertTrue(result.isLeft)
},

test ("Returns expected sequence of Measures with existing partitioning") {
val partitioningDTO: PartitioningDTO = Seq(PartitionDTO("string1", "string1"), PartitionDTO("string2", "string2"))
for {
getPartitioningMeasures <- ZIO.service[GetPartitioningMeasures]
result <- getPartitioningMeasures(partitioningDTO).either
} yield assertTrue{
println("Returned results: " + result)
result.isInstanceOf[Right[_, _]]
}

}
).provide(
GetPartitioningMeasures.layer,
Expand Down

0 comments on commit 7e30a62

Please sign in to comment.