Skip to content

Commit

Permalink
Close #120 - Applying GitHub comments
Browse files Browse the repository at this point in the history
  • Loading branch information
TebaleloS committed Apr 19, 2024
1 parent 1d31880 commit 9c5bb99
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 33 deletions.
26 changes: 18 additions & 8 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 @@ -45,19 +45,29 @@ trait TestData {
protected val partitioningSubmitDTO3: PartitioningSubmitDTO =
partitioningSubmitDTO1.copy(authorIfNew = "yetAnotherAuthor")

val additionalDataDTO: AdditionalDataDTO = Map(
"key1" -> Some("value1"),
"key2" -> None,
"key3" -> Some("value3")
)

// Measure
protected val measureDTO1: MeasureDTO = MeasureDTO("count", Seq("1"))
protected val measureDTO2: MeasureDTO = MeasureDTO("count", Seq("*"))

// Additional Data
protected val additionalDataDTO1: AdditionalDataDTO = Map("key" -> Option("value"))
protected val additionalDataDTO2: AdditionalDataDTO = Map.empty
protected val additionalDataDTO1: AdditionalDataDTO = Map(
"key1" -> Some("value1"),
"key2" -> None,
"key3" -> Some("value3")
)
protected val additionalDataDTO2: AdditionalDataDTO = Map(
"key1" -> Some("value1"),
"key2" -> Some("value2"),
"key3" -> Some("value3")
)
protected val additionalDataDTO3: AdditionalDataDTO = Map.empty

// Additional Data DTO as a sequence
protected val additionalDataDTOSeq1: Seq[(String, Option[String])] = Seq(
"key1" -> Some("value1"),
"key2" -> None,
"key3" -> Some("value3")
)

// Additional Data submit DTO
protected val additionalDataSubmitDTO1: AdditionalDataSubmitDTO = AdditionalDataSubmitDTO(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ package za.co.absa.atum.server.api.repository

import org.junit.runner.RunWith
import org.mockito.Mockito.{mock, when}
import za.co.absa.atum.model.dto.AdditionalDataDTO
import za.co.absa.atum.model.dto.{AdditionalDataDTO, MeasureDTO}
import za.co.absa.atum.server.api.database.runs.functions.{
CreateOrUpdateAdditionalData,
CreatePartitioningIfNotExists,
Expand All @@ -30,7 +30,6 @@ import za.co.absa.atum.server.api.TestData
import za.co.absa.fadb.exceptions.ErrorInDataException
import za.co.absa.fadb.status.FunctionStatus
import zio._
import zio.prelude.data.Optional.AllValuesAreNullable
import zio.test.Assertion.failsWithA
import zio.test._
import zio.test.junit.ZTestJUnitRunner
Expand Down Expand Up @@ -63,18 +62,17 @@ class PartitioningRepositorySpec extends ZIOSpecDefault with TestData {
// Get Partitioning Measures Mocks
private val getPartitioningMeasuresMock = mock(classOf[GetPartitioningMeasures])

when(getPartitioningMeasuresMock.apply(partitioningDTO1)).thenReturn{ZIO.succeed(Seq().empty)}
when(getPartitioningMeasuresMock.apply(partitioningDTO2)).thenReturn(ZIO.fail(new Exception("boom!")))
when(getPartitioningMeasuresMock.apply(partitioningDTO3)).thenReturn(ZIO.fail(new Exception("boom!")))
when(getPartitioningMeasuresMock.apply(partitioningDTO1)).thenReturn(ZIO.succeed(Seq(measureDTO1, measureDTO2)))
when(getPartitioningMeasuresMock.apply(partitioningDTO2)).thenReturn(ZIO.fail(DatabaseError("boom!")))

private val getPartitioningMeasuresMockLayer = ZLayer.succeed(getPartitioningMeasuresMock)

// Get Partitioning Additional Data Mocks
private val getPartitioningAdditionalDataMock = mock(classOf[GetPartitioningAdditionalData])

when(getPartitioningAdditionalDataMock.apply(partitioningDTO1)).thenReturn(ZIO.succeed(Seq()))
when(getPartitioningAdditionalDataMock.apply(partitioningDTO2)).thenReturn(ZIO.fail(new Exception("boom!")))
when(getPartitioningAdditionalDataMock.apply(partitioningDTO3)).thenReturn(ZIO.fail(new Exception("boom!")))
when(getPartitioningAdditionalDataMock.apply(partitioningDTO1))
.thenReturn(ZIO.succeed(additionalDataDTOSeq1))
when(getPartitioningAdditionalDataMock.apply(partitioningDTO2)).thenReturn(ZIO.fail(DatabaseError("boom!")))

private val getPartitioningAdditionalDataMockLayer = ZLayer.succeed(getPartitioningAdditionalDataMock)

Expand Down Expand Up @@ -121,35 +119,25 @@ class PartitioningRepositorySpec extends ZIOSpecDefault with TestData {
test("Returns expected Seq") {
for {
result <- PartitioningRepository.getPartitioningMeasures(partitioningDTO1)
} yield assertTrue(result.getOrElse(Seq()).isEmpty)
} yield assertTrue(result.isInstanceOf[Seq[MeasureDTO]] && result == Seq(measureDTO1, measureDTO2))
},
test("Returns expected Exception") {
assertZIO(PartitioningRepository.getPartitioningMeasures(partitioningDTO2).exit)(
failsWithA[DatabaseError]
)
},
test("Returns expected Exception") {
assertZIO(PartitioningRepository.getPartitioningMeasures(partitioningDTO3).exit)(
failsWithA[DatabaseError]
)
}
),

suite("GetPartitioningAdditionalDataSuite")(
test("Returns expected Right with empty Map") {
for {
result <- PartitioningRepository.getPartitioningAdditionalData(partitioningDTO1)
} yield assertTrue(result.isInstanceOf[AdditionalDataDTO])
} yield assertTrue(result.isInstanceOf[AdditionalDataDTO] && result == additionalDataDTO1)
},
test("Returns expected Left with DatabaseError") {
assertZIO(PartitioningRepository.getPartitioningAdditionalData(partitioningDTO2).exit)(
failsWithA[DatabaseError]
)
},
test("Returns expected Exception") {
assertZIO(PartitioningRepository.getPartitioningAdditionalData(partitioningDTO3).exit)(
failsWithA[DatabaseError]
)
}
)
).provide(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,17 +47,14 @@ class PartitioningServiceSpec extends ZIOSpecDefault with TestData {
.thenReturn(ZIO.fail(DatabaseError("boom!")))

when(partitioningRepositoryMock.getPartitioningMeasures(partitioningDTO1))
.thenReturn(ZIO.succeed(Seq.empty[MeasureDTO]))
.thenReturn(ZIO.succeed(Seq(measureDTO1, measureDTO2)))
when(partitioningRepositoryMock.getPartitioningMeasures(partitioningDTO2))
.thenReturn(ZIO.fail(DatabaseError("boom!")))

when(partitioningRepositoryMock.getPartitioningAdditionalData(partitioningDTO1))
.thenReturn(ZIO.succeed(additionalDataDTO1))
when(partitioningRepositoryMock.getPartitioningAdditionalData(partitioningDTO2))
.thenReturn(ZIO.fail(DatabaseError("boom!")))
when(partitioningRepositoryMock.getPartitioningAdditionalData(partitioningDTO3))
.thenReturn(ZIO.fail(DatabaseError("boom!")))


private val partitioningRepositoryMockLayer = ZLayer.succeed(partitioningRepositoryMock)

Expand Down Expand Up @@ -102,7 +99,10 @@ class PartitioningServiceSpec extends ZIOSpecDefault with TestData {
test("Returns expected Right with Seq[MeasureDTO]") {
for {
result <- PartitioningService.getPartitioningMeasures(partitioningDTO1)
} yield assertTrue(result.isInstanceOf[Seq[MeasureDTO]])
} yield assertTrue{
result.isInstanceOf[Seq[MeasureDTO]]
result == Seq(measureDTO1, measureDTO2)
}
},
test("Returns expected ServiceError") {
assertZIO(PartitioningService.getPartitioningMeasures(partitioningDTO2).exit)(
Expand Down

0 comments on commit 9c5bb99

Please sign in to comment.