Skip to content

Commit

Permalink
Fixes #120 - Fixing bugs from ControllerSpec
Browse files Browse the repository at this point in the history
  • Loading branch information
TebaleloS committed Apr 18, 2024
1 parent 975648b commit ed67783
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,12 @@ class PartitioningControllerImpl(partitioningService: PartitioningService)
_ <- partitioningService.createPartitioningIfNotExists(partitioningSubmitDTO)
.mapError(serviceError => InternalServerErrorResponse(serviceError.message))
measures <- partitioningService.getPartitioningMeasures(partitioningSubmitDTO.partitioning)
.mapError { serviceError: ServiceError =>
InternalServerErrorResponse(serviceError.message)
.mapError {
serviceError: ServiceError => InternalServerErrorResponse(serviceError.message)
}
additionalData <- partitioningService.getPartitioningAdditionalData(partitioningSubmitDTO.partitioning).mapError { serviceError: ServiceError =>
InternalServerErrorResponse(serviceError.message)
additionalData <- partitioningService.getPartitioningAdditionalData(partitioningSubmitDTO.partitioning)
.mapError {
serviceError: ServiceError => InternalServerErrorResponse(serviceError.message)
}
} yield AtumContextDTO(partitioningSubmitDTO.partitioning, measures.toSet, additionalData)
}
Expand Down
20 changes: 16 additions & 4 deletions server/src/test/scala/za/co/absa/atum/server/api/TestData.scala
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,21 @@

package za.co.absa.atum.server.api

import za.co.absa.atum.model.dto.{AdditionalDataDTO, AdditionalDataSubmitDTO, AtumContextDTO, CheckpointDTO, MeasureDTO, PartitionDTO, PartitioningDTO, PartitioningSubmitDTO}

import za.co.absa.atum.model.dto._
import java.time.ZonedDateTime
import java.util.UUID

trait TestData {

// Partitioning DTO
protected val partitioningDTO1: PartitioningDTO = Seq(PartitionDTO("key1", "val1"), PartitionDTO("key2", "val2"))
protected val partitioningDTO2: PartitioningDTO = Seq(PartitionDTO("Invali", "invalid"), PartitionDTO("invalid", "invalid"))
protected val partitioningDTO1: PartitioningDTO = Seq(
PartitionDTO("key1", "val1"),
PartitionDTO("key2", "val2")
)
protected val partitioningDTO2: PartitioningDTO = Seq(
PartitionDTO("Invali", "invalid"),
PartitionDTO("invalid", "invalid")
)
protected val partitioningDTO3: PartitioningDTO = Seq.empty

// Partitioning submit DTO
Expand Down Expand Up @@ -78,6 +83,13 @@ trait TestData {
measures = Set(MeasureDTO("count", Seq("1")))
)

// Expected Atum context
protected val expectedAtumContextDTO1: AtumContextDTO = AtumContextDTO(
partitioning = partitioningSubmitDTO1.partitioning,
measures = Set(measureDTO2),
additionalData = Map.empty
)

// Checkpoint
protected val checkpointDTO1: CheckpointDTO = CheckpointDTO(
id = UUID.randomUUID(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ package za.co.absa.atum.server.api.controller

import org.junit.runner.RunWith
import org.mockito.Mockito.{mock, when}
import za.co.absa.atum.model.dto.{AtumContextDTO, MeasureDTO}
import za.co.absa.atum.server.api.TestData
import za.co.absa.atum.server.api.exception.ServiceError
import za.co.absa.atum.server.api.service.PartitioningService
Expand All @@ -37,7 +36,7 @@ class PartitioningControllerSpec extends ZIOSpecDefault with TestData {
.thenReturn(ZIO.right(()))
when(partitioningServiceMock.getPartitioningMeasures(partitioningDTO1))
.thenReturn(ZIO.succeed(Seq(measureDTO2)))
when(partitioningServiceMock.getPartitioningAdditionalData(partitioningDTO2))
when(partitioningServiceMock.getPartitioningAdditionalData(partitioningDTO1))
.thenReturn(ZIO.succeed(Map.empty))

when(partitioningServiceMock.createPartitioningIfNotExists(partitioningSubmitDTO2))
Expand All @@ -50,17 +49,9 @@ class PartitioningControllerSpec extends ZIOSpecDefault with TestData {
suite("PartitioningControllerSpec")(
suite("CreatePartitioningIfNotExistsSuite")(
test("Returns expected AtumContextDTO") {
val expectedAtumContextDTO = AtumContextDTO(
partitioning = partitioningSubmitDTO1.partitioning,
measures = Set(MeasureDTO("count", Seq("*"))),
additionalData = Map.empty
)
for {
result <- PartitioningController.createPartitioningIfNotExists(partitioningSubmitDTO1)
} yield assertTrue {
println(result)
result == expectedAtumContextDTO
}
} yield assertTrue (result == expectedAtumContextDTO1)
},
test("Returns expected InternalServerErrorResponse") {
assertZIO(PartitioningController.createPartitioningIfNotExists(partitioningSubmitDTO2).exit)(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ import za.co.absa.atum.server.api.database.runs.functions.{
CreateOrUpdateAdditionalData,
CreatePartitioningIfNotExists,
GetPartitioningAdditionalData,
GetPartitioningMeasures}
GetPartitioningMeasures
}
import za.co.absa.atum.server.api.exception.DatabaseError
import za.co.absa.atum.server.api.TestData
import za.co.absa.fadb.exceptions.ErrorInDataException
Expand Down

0 comments on commit ed67783

Please sign in to comment.