From 9c5bb995900032241befe3550aa7719ae87b128b Mon Sep 17 00:00:00 2001 From: AB019TC Date: Fri, 19 Apr 2024 13:06:57 +0200 Subject: [PATCH] Close #120 - Applying GitHub comments --- .../za/co/absa/atum/server/api/TestData.scala | 26 +++++++++++------ .../PartitioningRepositorySpec.scala | 28 ++++++------------- .../api/service/PartitioningServiceSpec.scala | 10 +++---- 3 files changed, 31 insertions(+), 33 deletions(-) diff --git a/server/src/test/scala/za/co/absa/atum/server/api/TestData.scala b/server/src/test/scala/za/co/absa/atum/server/api/TestData.scala index bd2c54764..4e8f84500 100644 --- a/server/src/test/scala/za/co/absa/atum/server/api/TestData.scala +++ b/server/src/test/scala/za/co/absa/atum/server/api/TestData.scala @@ -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( diff --git a/server/src/test/scala/za/co/absa/atum/server/api/repository/PartitioningRepositorySpec.scala b/server/src/test/scala/za/co/absa/atum/server/api/repository/PartitioningRepositorySpec.scala index db9b5c490..9c8aeda42 100644 --- a/server/src/test/scala/za/co/absa/atum/server/api/repository/PartitioningRepositorySpec.scala +++ b/server/src/test/scala/za/co/absa/atum/server/api/repository/PartitioningRepositorySpec.scala @@ -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, @@ -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 @@ -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) @@ -121,17 +119,12 @@ 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] - ) } ), @@ -139,17 +132,12 @@ class PartitioningRepositorySpec extends ZIOSpecDefault with TestData { 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( diff --git a/server/src/test/scala/za/co/absa/atum/server/api/service/PartitioningServiceSpec.scala b/server/src/test/scala/za/co/absa/atum/server/api/service/PartitioningServiceSpec.scala index 9e20d6e1e..0e0d550d8 100644 --- a/server/src/test/scala/za/co/absa/atum/server/api/service/PartitioningServiceSpec.scala +++ b/server/src/test/scala/za/co/absa/atum/server/api/service/PartitioningServiceSpec.scala @@ -47,7 +47,7 @@ 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!"))) @@ -55,9 +55,6 @@ class PartitioningServiceSpec extends ZIOSpecDefault with TestData { .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) @@ -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)(