From dfd91b441e6d47afe031adbf2727ef2260772c41 Mon Sep 17 00:00:00 2001 From: vanderleik Date: Sat, 13 Apr 2024 14:23:52 -0300 Subject: [PATCH 1/5] feat: VIN-441 - refazendo os DTOs --- .../services/degustacao/AromasService.java | 2 - .../GustatoryInspectionService.java | 3 - .../OlfactoryInspectionService.java | 3 - .../services/degustacao/TastingService.java | 3 - .../degustacao/VisualInspectionService.java | 3 - .../degustacao/impl/AromasServiceImpl.java | 2 - .../impl/GustatoryInspectionServiceImpl.java | 2 - .../impl/OlfactoryInspectionServiceImpl.java | 2 - .../degustacao/impl/TastingServiceImpl.java | 2 - .../impl/VisualInspectionServiceImpl.java | 2 - .../bff/client/degustacao/AromasClient.java | 2 - .../degustacao/GustatoryInspectionClient.java | 2 - .../degustacao/OlfactoryInspectionClient.java | 2 - .../bff/client/degustacao/TastingClient.java | 2 - .../degustacao/VisualInspectionClient.java | 2 - .../degustacao/AromasController.java | 2 - .../GustatoryInspectionController.java | 2 - .../OlfactoryInspectionController.java | 2 - .../degustacao/TastingController.java | 2 - .../VisualInspectionController.java | 2 - .../dtos/general/ErrorResponseDTO.java | 4 + .../inputs/degustacao/AromasInputDTO.java | 32 -- .../GustatoryInspectionInputDTO.java | 29 -- .../OlfactoryInspectionInputDTO.java | 25 - .../degustacao/TastingCardInputDTO.java | 37 +- .../inputs/degustacao/TastingInputDTO.java | 22 - .../degustacao/VisualInspectionInputDTO.java | 27 - .../outputs/degustacao/AromasOutputDTO.java | 29 -- .../GustatoryInspectionOutputDTO.java | 27 - .../OlfactoryInspectionOutputDTO.java | 23 - .../degustacao/TastingCardOutputDTO.java | 39 +- .../outputs/degustacao/TastingOutputDTO.java | 20 - .../degustacao/VisualInspectionOutputDTO.java | 25 - .../impl/AromasServiceImplTest.java | 470 +++++++++-------- .../GustatoryInspectionServiceImplTest.java | 456 ++++++++--------- .../OlfactoryInspectionServiceImplTest.java | 434 ++++++++-------- .../impl/TastingCardServiceImplTest.java | 452 ++++++++-------- .../impl/TastingServiceImplTest.java | 362 +++++++------ .../impl/VisualInspectionServiceImplTest.java | 420 ++++++++------- .../degustacao/AromasControllerTest.java | 422 ++++++++------- .../GustatoryInspectionControllerTest.java | 410 ++++++++------- .../OlfactoryInspectionControllerTest.java | 484 +++++++++--------- .../degustacao/TastingCardControllerTest.java | 408 ++++++++------- .../degustacao/TastingControllerTest.java | 464 ++++++++--------- .../VisualInspectionControllerTest.java | 406 ++++++++------- 45 files changed, 2647 insertions(+), 2924 deletions(-) create mode 100644 bff/src/main/java/com/vinhonotas/bff/interfaces/dtos/general/ErrorResponseDTO.java delete mode 100644 bff/src/main/java/com/vinhonotas/bff/interfaces/dtos/inputs/degustacao/AromasInputDTO.java delete mode 100644 bff/src/main/java/com/vinhonotas/bff/interfaces/dtos/inputs/degustacao/GustatoryInspectionInputDTO.java delete mode 100644 bff/src/main/java/com/vinhonotas/bff/interfaces/dtos/inputs/degustacao/OlfactoryInspectionInputDTO.java delete mode 100644 bff/src/main/java/com/vinhonotas/bff/interfaces/dtos/inputs/degustacao/TastingInputDTO.java delete mode 100644 bff/src/main/java/com/vinhonotas/bff/interfaces/dtos/inputs/degustacao/VisualInspectionInputDTO.java delete mode 100644 bff/src/main/java/com/vinhonotas/bff/interfaces/dtos/outputs/degustacao/AromasOutputDTO.java delete mode 100644 bff/src/main/java/com/vinhonotas/bff/interfaces/dtos/outputs/degustacao/GustatoryInspectionOutputDTO.java delete mode 100644 bff/src/main/java/com/vinhonotas/bff/interfaces/dtos/outputs/degustacao/OlfactoryInspectionOutputDTO.java delete mode 100644 bff/src/main/java/com/vinhonotas/bff/interfaces/dtos/outputs/degustacao/TastingOutputDTO.java delete mode 100644 bff/src/main/java/com/vinhonotas/bff/interfaces/dtos/outputs/degustacao/VisualInspectionOutputDTO.java diff --git a/bff/src/main/java/com/vinhonotas/bff/application/services/degustacao/AromasService.java b/bff/src/main/java/com/vinhonotas/bff/application/services/degustacao/AromasService.java index 3edf63cb..5c7f5030 100644 --- a/bff/src/main/java/com/vinhonotas/bff/application/services/degustacao/AromasService.java +++ b/bff/src/main/java/com/vinhonotas/bff/application/services/degustacao/AromasService.java @@ -1,7 +1,5 @@ package com.vinhonotas.bff.application.services.degustacao; -import com.vinhonotas.bff.interfaces.dtos.inputs.degustacao.AromasInputDTO; -import com.vinhonotas.bff.interfaces.dtos.outputs.degustacao.AromasOutputDTO; import org.springframework.web.bind.annotation.PathVariable; import java.util.List; diff --git a/bff/src/main/java/com/vinhonotas/bff/application/services/degustacao/GustatoryInspectionService.java b/bff/src/main/java/com/vinhonotas/bff/application/services/degustacao/GustatoryInspectionService.java index 27290f22..54ecad90 100644 --- a/bff/src/main/java/com/vinhonotas/bff/application/services/degustacao/GustatoryInspectionService.java +++ b/bff/src/main/java/com/vinhonotas/bff/application/services/degustacao/GustatoryInspectionService.java @@ -1,8 +1,5 @@ package com.vinhonotas.bff.application.services.degustacao; -import com.vinhonotas.bff.interfaces.dtos.inputs.degustacao.GustatoryInspectionInputDTO; -import com.vinhonotas.bff.interfaces.dtos.outputs.degustacao.GustatoryInspectionOutputDTO; - import java.util.List; public interface GustatoryInspectionService { diff --git a/bff/src/main/java/com/vinhonotas/bff/application/services/degustacao/OlfactoryInspectionService.java b/bff/src/main/java/com/vinhonotas/bff/application/services/degustacao/OlfactoryInspectionService.java index 7bab7d5b..53af5a02 100644 --- a/bff/src/main/java/com/vinhonotas/bff/application/services/degustacao/OlfactoryInspectionService.java +++ b/bff/src/main/java/com/vinhonotas/bff/application/services/degustacao/OlfactoryInspectionService.java @@ -1,8 +1,5 @@ package com.vinhonotas.bff.application.services.degustacao; -import com.vinhonotas.bff.interfaces.dtos.inputs.degustacao.OlfactoryInspectionInputDTO; -import com.vinhonotas.bff.interfaces.dtos.outputs.degustacao.OlfactoryInspectionOutputDTO; - import java.util.List; public interface OlfactoryInspectionService { diff --git a/bff/src/main/java/com/vinhonotas/bff/application/services/degustacao/TastingService.java b/bff/src/main/java/com/vinhonotas/bff/application/services/degustacao/TastingService.java index 6366ed89..39d2e484 100644 --- a/bff/src/main/java/com/vinhonotas/bff/application/services/degustacao/TastingService.java +++ b/bff/src/main/java/com/vinhonotas/bff/application/services/degustacao/TastingService.java @@ -1,8 +1,5 @@ package com.vinhonotas.bff.application.services.degustacao; -import com.vinhonotas.bff.interfaces.dtos.inputs.degustacao.TastingInputDTO; -import com.vinhonotas.bff.interfaces.dtos.outputs.degustacao.TastingOutputDTO; - import java.util.List; public interface TastingService { diff --git a/bff/src/main/java/com/vinhonotas/bff/application/services/degustacao/VisualInspectionService.java b/bff/src/main/java/com/vinhonotas/bff/application/services/degustacao/VisualInspectionService.java index 187a8c9f..e2a909b7 100644 --- a/bff/src/main/java/com/vinhonotas/bff/application/services/degustacao/VisualInspectionService.java +++ b/bff/src/main/java/com/vinhonotas/bff/application/services/degustacao/VisualInspectionService.java @@ -1,8 +1,5 @@ package com.vinhonotas.bff.application.services.degustacao; -import com.vinhonotas.bff.interfaces.dtos.inputs.degustacao.VisualInspectionInputDTO; -import com.vinhonotas.bff.interfaces.dtos.outputs.degustacao.VisualInspectionOutputDTO; - import java.util.List; public interface VisualInspectionService { diff --git a/bff/src/main/java/com/vinhonotas/bff/application/services/degustacao/impl/AromasServiceImpl.java b/bff/src/main/java/com/vinhonotas/bff/application/services/degustacao/impl/AromasServiceImpl.java index b138e5a0..7b5465ae 100644 --- a/bff/src/main/java/com/vinhonotas/bff/application/services/degustacao/impl/AromasServiceImpl.java +++ b/bff/src/main/java/com/vinhonotas/bff/application/services/degustacao/impl/AromasServiceImpl.java @@ -4,8 +4,6 @@ import com.vinhonotas.bff.application.services.exceptions.BadRequestException; import com.vinhonotas.bff.application.services.exceptions.NotFoundException; import com.vinhonotas.bff.client.degustacao.AromasClient; -import com.vinhonotas.bff.interfaces.dtos.inputs.degustacao.AromasInputDTO; -import com.vinhonotas.bff.interfaces.dtos.outputs.degustacao.AromasOutputDTO; import com.vinhonotas.bff.utils.MessagesConstants; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; diff --git a/bff/src/main/java/com/vinhonotas/bff/application/services/degustacao/impl/GustatoryInspectionServiceImpl.java b/bff/src/main/java/com/vinhonotas/bff/application/services/degustacao/impl/GustatoryInspectionServiceImpl.java index 62f874b1..507d8496 100644 --- a/bff/src/main/java/com/vinhonotas/bff/application/services/degustacao/impl/GustatoryInspectionServiceImpl.java +++ b/bff/src/main/java/com/vinhonotas/bff/application/services/degustacao/impl/GustatoryInspectionServiceImpl.java @@ -4,8 +4,6 @@ import com.vinhonotas.bff.application.services.exceptions.BadRequestException; import com.vinhonotas.bff.application.services.exceptions.NotFoundException; import com.vinhonotas.bff.client.degustacao.GustatoryInspectionClient; -import com.vinhonotas.bff.interfaces.dtos.inputs.degustacao.GustatoryInspectionInputDTO; -import com.vinhonotas.bff.interfaces.dtos.outputs.degustacao.GustatoryInspectionOutputDTO; import com.vinhonotas.bff.utils.MessagesConstants; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; diff --git a/bff/src/main/java/com/vinhonotas/bff/application/services/degustacao/impl/OlfactoryInspectionServiceImpl.java b/bff/src/main/java/com/vinhonotas/bff/application/services/degustacao/impl/OlfactoryInspectionServiceImpl.java index 54e113d1..02ef9a50 100644 --- a/bff/src/main/java/com/vinhonotas/bff/application/services/degustacao/impl/OlfactoryInspectionServiceImpl.java +++ b/bff/src/main/java/com/vinhonotas/bff/application/services/degustacao/impl/OlfactoryInspectionServiceImpl.java @@ -4,8 +4,6 @@ import com.vinhonotas.bff.application.services.exceptions.BadRequestException; import com.vinhonotas.bff.application.services.exceptions.NotFoundException; import com.vinhonotas.bff.client.degustacao.OlfactoryInspectionClient; -import com.vinhonotas.bff.interfaces.dtos.inputs.degustacao.OlfactoryInspectionInputDTO; -import com.vinhonotas.bff.interfaces.dtos.outputs.degustacao.OlfactoryInspectionOutputDTO; import com.vinhonotas.bff.utils.MessagesConstants; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; diff --git a/bff/src/main/java/com/vinhonotas/bff/application/services/degustacao/impl/TastingServiceImpl.java b/bff/src/main/java/com/vinhonotas/bff/application/services/degustacao/impl/TastingServiceImpl.java index 150fa4b7..49f1ee92 100644 --- a/bff/src/main/java/com/vinhonotas/bff/application/services/degustacao/impl/TastingServiceImpl.java +++ b/bff/src/main/java/com/vinhonotas/bff/application/services/degustacao/impl/TastingServiceImpl.java @@ -4,8 +4,6 @@ import com.vinhonotas.bff.application.services.exceptions.BadRequestException; import com.vinhonotas.bff.application.services.exceptions.NotFoundException; import com.vinhonotas.bff.client.degustacao.TastingClient; -import com.vinhonotas.bff.interfaces.dtos.inputs.degustacao.TastingInputDTO; -import com.vinhonotas.bff.interfaces.dtos.outputs.degustacao.TastingOutputDTO; import com.vinhonotas.bff.utils.MessagesConstants; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; diff --git a/bff/src/main/java/com/vinhonotas/bff/application/services/degustacao/impl/VisualInspectionServiceImpl.java b/bff/src/main/java/com/vinhonotas/bff/application/services/degustacao/impl/VisualInspectionServiceImpl.java index 263d80ad..7d1b0daf 100644 --- a/bff/src/main/java/com/vinhonotas/bff/application/services/degustacao/impl/VisualInspectionServiceImpl.java +++ b/bff/src/main/java/com/vinhonotas/bff/application/services/degustacao/impl/VisualInspectionServiceImpl.java @@ -4,8 +4,6 @@ import com.vinhonotas.bff.application.services.exceptions.BadRequestException; import com.vinhonotas.bff.application.services.exceptions.NotFoundException; import com.vinhonotas.bff.client.degustacao.VisualInspectionClient; -import com.vinhonotas.bff.interfaces.dtos.inputs.degustacao.VisualInspectionInputDTO; -import com.vinhonotas.bff.interfaces.dtos.outputs.degustacao.VisualInspectionOutputDTO; import com.vinhonotas.bff.utils.MessagesConstants; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; diff --git a/bff/src/main/java/com/vinhonotas/bff/client/degustacao/AromasClient.java b/bff/src/main/java/com/vinhonotas/bff/client/degustacao/AromasClient.java index fd8a4ecf..02a43f20 100644 --- a/bff/src/main/java/com/vinhonotas/bff/client/degustacao/AromasClient.java +++ b/bff/src/main/java/com/vinhonotas/bff/client/degustacao/AromasClient.java @@ -1,8 +1,6 @@ package com.vinhonotas.bff.client.degustacao; import com.vinhonotas.bff.configuration.FeignConfig; -import com.vinhonotas.bff.interfaces.dtos.inputs.degustacao.AromasInputDTO; -import com.vinhonotas.bff.interfaces.dtos.outputs.degustacao.AromasOutputDTO; import jakarta.validation.Valid; import org.springframework.cloud.openfeign.FeignClient; import org.springframework.web.bind.annotation.*; diff --git a/bff/src/main/java/com/vinhonotas/bff/client/degustacao/GustatoryInspectionClient.java b/bff/src/main/java/com/vinhonotas/bff/client/degustacao/GustatoryInspectionClient.java index 9fc79bc3..e6a73f9b 100644 --- a/bff/src/main/java/com/vinhonotas/bff/client/degustacao/GustatoryInspectionClient.java +++ b/bff/src/main/java/com/vinhonotas/bff/client/degustacao/GustatoryInspectionClient.java @@ -1,8 +1,6 @@ package com.vinhonotas.bff.client.degustacao; import com.vinhonotas.bff.configuration.FeignConfig; -import com.vinhonotas.bff.interfaces.dtos.inputs.degustacao.GustatoryInspectionInputDTO; -import com.vinhonotas.bff.interfaces.dtos.outputs.degustacao.GustatoryInspectionOutputDTO; import jakarta.validation.Valid; import org.springframework.cloud.openfeign.FeignClient; import org.springframework.web.bind.annotation.*; diff --git a/bff/src/main/java/com/vinhonotas/bff/client/degustacao/OlfactoryInspectionClient.java b/bff/src/main/java/com/vinhonotas/bff/client/degustacao/OlfactoryInspectionClient.java index bade4e2b..d6ea76a4 100644 --- a/bff/src/main/java/com/vinhonotas/bff/client/degustacao/OlfactoryInspectionClient.java +++ b/bff/src/main/java/com/vinhonotas/bff/client/degustacao/OlfactoryInspectionClient.java @@ -1,8 +1,6 @@ package com.vinhonotas.bff.client.degustacao; import com.vinhonotas.bff.configuration.FeignConfig; -import com.vinhonotas.bff.interfaces.dtos.inputs.degustacao.OlfactoryInspectionInputDTO; -import com.vinhonotas.bff.interfaces.dtos.outputs.degustacao.OlfactoryInspectionOutputDTO; import jakarta.validation.Valid; import org.springframework.cloud.openfeign.FeignClient; import org.springframework.web.bind.annotation.*; diff --git a/bff/src/main/java/com/vinhonotas/bff/client/degustacao/TastingClient.java b/bff/src/main/java/com/vinhonotas/bff/client/degustacao/TastingClient.java index c1fec4d5..4b247bea 100644 --- a/bff/src/main/java/com/vinhonotas/bff/client/degustacao/TastingClient.java +++ b/bff/src/main/java/com/vinhonotas/bff/client/degustacao/TastingClient.java @@ -1,8 +1,6 @@ package com.vinhonotas.bff.client.degustacao; import com.vinhonotas.bff.configuration.FeignConfig; -import com.vinhonotas.bff.interfaces.dtos.inputs.degustacao.TastingInputDTO; -import com.vinhonotas.bff.interfaces.dtos.outputs.degustacao.TastingOutputDTO; import jakarta.validation.Valid; import org.springframework.cloud.openfeign.FeignClient; import org.springframework.web.bind.annotation.*; diff --git a/bff/src/main/java/com/vinhonotas/bff/client/degustacao/VisualInspectionClient.java b/bff/src/main/java/com/vinhonotas/bff/client/degustacao/VisualInspectionClient.java index 6421879e..0a39c399 100644 --- a/bff/src/main/java/com/vinhonotas/bff/client/degustacao/VisualInspectionClient.java +++ b/bff/src/main/java/com/vinhonotas/bff/client/degustacao/VisualInspectionClient.java @@ -1,8 +1,6 @@ package com.vinhonotas.bff.client.degustacao; import com.vinhonotas.bff.configuration.FeignConfig; -import com.vinhonotas.bff.interfaces.dtos.inputs.degustacao.VisualInspectionInputDTO; -import com.vinhonotas.bff.interfaces.dtos.outputs.degustacao.VisualInspectionOutputDTO; import jakarta.validation.Valid; import org.springframework.cloud.openfeign.FeignClient; import org.springframework.web.bind.annotation.*; diff --git a/bff/src/main/java/com/vinhonotas/bff/interfaces/controllers/degustacao/AromasController.java b/bff/src/main/java/com/vinhonotas/bff/interfaces/controllers/degustacao/AromasController.java index 39ceb6e3..b9886e44 100644 --- a/bff/src/main/java/com/vinhonotas/bff/interfaces/controllers/degustacao/AromasController.java +++ b/bff/src/main/java/com/vinhonotas/bff/interfaces/controllers/degustacao/AromasController.java @@ -1,8 +1,6 @@ package com.vinhonotas.bff.interfaces.controllers.degustacao; import com.vinhonotas.bff.application.services.degustacao.AromasService; -import com.vinhonotas.bff.interfaces.dtos.inputs.degustacao.AromasInputDTO; -import com.vinhonotas.bff.interfaces.dtos.outputs.degustacao.AromasOutputDTO; import jakarta.validation.Valid; import lombok.RequiredArgsConstructor; import org.springframework.http.ResponseEntity; diff --git a/bff/src/main/java/com/vinhonotas/bff/interfaces/controllers/degustacao/GustatoryInspectionController.java b/bff/src/main/java/com/vinhonotas/bff/interfaces/controllers/degustacao/GustatoryInspectionController.java index e8950389..57473c53 100644 --- a/bff/src/main/java/com/vinhonotas/bff/interfaces/controllers/degustacao/GustatoryInspectionController.java +++ b/bff/src/main/java/com/vinhonotas/bff/interfaces/controllers/degustacao/GustatoryInspectionController.java @@ -1,8 +1,6 @@ package com.vinhonotas.bff.interfaces.controllers.degustacao; import com.vinhonotas.bff.application.services.degustacao.GustatoryInspectionService; -import com.vinhonotas.bff.interfaces.dtos.inputs.degustacao.GustatoryInspectionInputDTO; -import com.vinhonotas.bff.interfaces.dtos.outputs.degustacao.GustatoryInspectionOutputDTO; import jakarta.validation.Valid; import lombok.RequiredArgsConstructor; import org.springframework.http.ResponseEntity; diff --git a/bff/src/main/java/com/vinhonotas/bff/interfaces/controllers/degustacao/OlfactoryInspectionController.java b/bff/src/main/java/com/vinhonotas/bff/interfaces/controllers/degustacao/OlfactoryInspectionController.java index 196352c4..007de081 100644 --- a/bff/src/main/java/com/vinhonotas/bff/interfaces/controllers/degustacao/OlfactoryInspectionController.java +++ b/bff/src/main/java/com/vinhonotas/bff/interfaces/controllers/degustacao/OlfactoryInspectionController.java @@ -1,8 +1,6 @@ package com.vinhonotas.bff.interfaces.controllers.degustacao; import com.vinhonotas.bff.application.services.degustacao.OlfactoryInspectionService; -import com.vinhonotas.bff.interfaces.dtos.inputs.degustacao.OlfactoryInspectionInputDTO; -import com.vinhonotas.bff.interfaces.dtos.outputs.degustacao.OlfactoryInspectionOutputDTO; import jakarta.validation.Valid; import lombok.RequiredArgsConstructor; import org.springframework.http.ResponseEntity; diff --git a/bff/src/main/java/com/vinhonotas/bff/interfaces/controllers/degustacao/TastingController.java b/bff/src/main/java/com/vinhonotas/bff/interfaces/controllers/degustacao/TastingController.java index fc6471c5..1ab01a5c 100644 --- a/bff/src/main/java/com/vinhonotas/bff/interfaces/controllers/degustacao/TastingController.java +++ b/bff/src/main/java/com/vinhonotas/bff/interfaces/controllers/degustacao/TastingController.java @@ -1,8 +1,6 @@ package com.vinhonotas.bff.interfaces.controllers.degustacao; import com.vinhonotas.bff.application.services.degustacao.TastingService; -import com.vinhonotas.bff.interfaces.dtos.inputs.degustacao.TastingInputDTO; -import com.vinhonotas.bff.interfaces.dtos.outputs.degustacao.TastingOutputDTO; import jakarta.validation.Valid; import lombok.RequiredArgsConstructor; import org.springframework.http.ResponseEntity; diff --git a/bff/src/main/java/com/vinhonotas/bff/interfaces/controllers/degustacao/VisualInspectionController.java b/bff/src/main/java/com/vinhonotas/bff/interfaces/controllers/degustacao/VisualInspectionController.java index 214570ea..8adb668a 100644 --- a/bff/src/main/java/com/vinhonotas/bff/interfaces/controllers/degustacao/VisualInspectionController.java +++ b/bff/src/main/java/com/vinhonotas/bff/interfaces/controllers/degustacao/VisualInspectionController.java @@ -1,8 +1,6 @@ package com.vinhonotas.bff.interfaces.controllers.degustacao; import com.vinhonotas.bff.application.services.degustacao.VisualInspectionService; -import com.vinhonotas.bff.interfaces.dtos.inputs.degustacao.VisualInspectionInputDTO; -import com.vinhonotas.bff.interfaces.dtos.outputs.degustacao.VisualInspectionOutputDTO; import jakarta.validation.Valid; import lombok.RequiredArgsConstructor; import org.springframework.http.ResponseEntity; diff --git a/bff/src/main/java/com/vinhonotas/bff/interfaces/dtos/general/ErrorResponseDTO.java b/bff/src/main/java/com/vinhonotas/bff/interfaces/dtos/general/ErrorResponseDTO.java new file mode 100644 index 00000000..fae950cc --- /dev/null +++ b/bff/src/main/java/com/vinhonotas/bff/interfaces/dtos/general/ErrorResponseDTO.java @@ -0,0 +1,4 @@ +package com.vinhonotas.bff.interfaces.dtos.general; + +public record ErrorResponseDTO(String message) { +} diff --git a/bff/src/main/java/com/vinhonotas/bff/interfaces/dtos/inputs/degustacao/AromasInputDTO.java b/bff/src/main/java/com/vinhonotas/bff/interfaces/dtos/inputs/degustacao/AromasInputDTO.java deleted file mode 100644 index 589e919c..00000000 --- a/bff/src/main/java/com/vinhonotas/bff/interfaces/dtos/inputs/degustacao/AromasInputDTO.java +++ /dev/null @@ -1,32 +0,0 @@ -package com.vinhonotas.bff.interfaces.dtos.inputs.degustacao; - -import lombok.Builder; -import lombok.Data; - -import java.time.LocalDate; -import java.time.LocalDateTime; - -@Data -@Builder -public class AromasInputDTO { - - private LocalDate tastingData; - private String wineTasted; - private String fruity; - private String dryFruits; - private String florals; - private String vegetablesAndHerbs; - private String minerals; - private String spices; - private String animals; - private String empireumatics; - private String wood; - private String chemicals; - private String lacteal; - private String sweets; - private LocalDateTime dthreg; - private String userreg; - private LocalDateTime dthalt; - private String useralt; - -} diff --git a/bff/src/main/java/com/vinhonotas/bff/interfaces/dtos/inputs/degustacao/GustatoryInspectionInputDTO.java b/bff/src/main/java/com/vinhonotas/bff/interfaces/dtos/inputs/degustacao/GustatoryInspectionInputDTO.java deleted file mode 100644 index 2be8c94b..00000000 --- a/bff/src/main/java/com/vinhonotas/bff/interfaces/dtos/inputs/degustacao/GustatoryInspectionInputDTO.java +++ /dev/null @@ -1,29 +0,0 @@ -package com.vinhonotas.bff.interfaces.dtos.inputs.degustacao; - -import lombok.Builder; -import lombok.Data; - -import java.time.LocalDate; -import java.time.LocalDateTime; - -@Data -@Builder -public class GustatoryInspectionInputDTO { - - private LocalDate tastingData; - private String wineTasted; - private String body; - private String sweetness; - private String tannin; - private String classification; - private String acidity; - private String alcohol; - private String persistence; - private String maturity; - private String typicality; - private LocalDateTime dthreg; - private String userreg; - private LocalDateTime dthalt; - private String useralt; - -} diff --git a/bff/src/main/java/com/vinhonotas/bff/interfaces/dtos/inputs/degustacao/OlfactoryInspectionInputDTO.java b/bff/src/main/java/com/vinhonotas/bff/interfaces/dtos/inputs/degustacao/OlfactoryInspectionInputDTO.java deleted file mode 100644 index fe6f8d91..00000000 --- a/bff/src/main/java/com/vinhonotas/bff/interfaces/dtos/inputs/degustacao/OlfactoryInspectionInputDTO.java +++ /dev/null @@ -1,25 +0,0 @@ -package com.vinhonotas.bff.interfaces.dtos.inputs.degustacao; - -import lombok.Builder; -import lombok.Data; - -import java.time.LocalDate; -import java.time.LocalDateTime; - -@Data -@Builder -public class OlfactoryInspectionInputDTO { - - private LocalDate tastingData; - private String wineTasted; - private String intensity; - private String persistence; - private String quality; - private AromasInputDTO aromas; - private String classification; - private LocalDateTime dthreg; - private String userreg; - private LocalDateTime dthalt; - private String useralt; - -} diff --git a/bff/src/main/java/com/vinhonotas/bff/interfaces/dtos/inputs/degustacao/TastingCardInputDTO.java b/bff/src/main/java/com/vinhonotas/bff/interfaces/dtos/inputs/degustacao/TastingCardInputDTO.java index 084f69a0..7d34a14d 100644 --- a/bff/src/main/java/com/vinhonotas/bff/interfaces/dtos/inputs/degustacao/TastingCardInputDTO.java +++ b/bff/src/main/java/com/vinhonotas/bff/interfaces/dtos/inputs/degustacao/TastingCardInputDTO.java @@ -10,15 +10,44 @@ @Builder public class TastingCardInputDTO { - private LocalDate tastingData; private String wineTasted; + private LocalDate tastingData; private String harvest; private String grapes; private String country; private String region; - private VisualInspectionInputDTO visualInspection; - private OlfactoryInspectionInputDTO olfactoryInspection; - private GustatoryInspectionInputDTO gustatoryInspection; + private String clarity; + private String brightness; + private String viscosity; + private String colorRed; + private String colorWhite; + private String colorRose; + private String visualInspectionClassification; + private String intensity; + private String olfactoryInspectionPersistence; + private String quality; + private String fruity; + private String dryFruits; + private String florals; + private String vegetablesAndHerbs; + private String minerals; + private String spices; + private String animals; + private String empireumatics; + private String wood; + private String chemicals; + private String lacteal; + private String sweets; + private String olfactoryInspectionClassification; + private String body; + private String sweetness; + private String tannin; + private String acidity; + private String alcohol; + private String gustatoryInspectionPersistence; + private String maturity; + private String typicality; + private String gustatoryInspectionClassification; private String opinion; private String pointScale; private LocalDateTime dthreg; diff --git a/bff/src/main/java/com/vinhonotas/bff/interfaces/dtos/inputs/degustacao/TastingInputDTO.java b/bff/src/main/java/com/vinhonotas/bff/interfaces/dtos/inputs/degustacao/TastingInputDTO.java deleted file mode 100644 index 32102c4f..00000000 --- a/bff/src/main/java/com/vinhonotas/bff/interfaces/dtos/inputs/degustacao/TastingInputDTO.java +++ /dev/null @@ -1,22 +0,0 @@ -package com.vinhonotas.bff.interfaces.dtos.inputs.degustacao; - -import lombok.Builder; -import lombok.Data; - -import java.time.LocalDate; -import java.time.LocalDateTime; -import java.util.Set; - -@Data -@Builder -public class TastingInputDTO { - - private LocalDate tastingData; - private String tastingType; - private Set tastingCards; - private LocalDateTime dthreg; - private String userreg; - private LocalDateTime dthalt; - private String useralt; - -} diff --git a/bff/src/main/java/com/vinhonotas/bff/interfaces/dtos/inputs/degustacao/VisualInspectionInputDTO.java b/bff/src/main/java/com/vinhonotas/bff/interfaces/dtos/inputs/degustacao/VisualInspectionInputDTO.java deleted file mode 100644 index 68a1b2ea..00000000 --- a/bff/src/main/java/com/vinhonotas/bff/interfaces/dtos/inputs/degustacao/VisualInspectionInputDTO.java +++ /dev/null @@ -1,27 +0,0 @@ -package com.vinhonotas.bff.interfaces.dtos.inputs.degustacao; - -import lombok.Builder; -import lombok.Data; - -import java.time.LocalDate; -import java.time.LocalDateTime; - -@Data -@Builder -public class VisualInspectionInputDTO { - - private LocalDate tastingData; - private String wineTasted; - private String clarity; - private String brightness; - private String viscosity; - private String colorRed; - private String colorWhite; - private String colorRose; - private String classification; - private LocalDateTime dthreg; - private String userreg; - private LocalDateTime dthalt; - private String useralt; - -} diff --git a/bff/src/main/java/com/vinhonotas/bff/interfaces/dtos/outputs/degustacao/AromasOutputDTO.java b/bff/src/main/java/com/vinhonotas/bff/interfaces/dtos/outputs/degustacao/AromasOutputDTO.java deleted file mode 100644 index 6694f63e..00000000 --- a/bff/src/main/java/com/vinhonotas/bff/interfaces/dtos/outputs/degustacao/AromasOutputDTO.java +++ /dev/null @@ -1,29 +0,0 @@ -package com.vinhonotas.bff.interfaces.dtos.outputs.degustacao; - -import lombok.Builder; -import lombok.Data; - -import java.time.LocalDate; -import java.util.UUID; - -@Data -@Builder -public class AromasOutputDTO { - - private UUID id; - private LocalDate tastingData; - private String wineTasted; - private String fruity; - private String dryFruits; - private String florals; - private String vegetablesAndHerbs; - private String minerals; - private String spices; - private String animals; - private String empireumatics; - private String wood; - private String chemicals; - private String lacteal; - private String sweets; - -} diff --git a/bff/src/main/java/com/vinhonotas/bff/interfaces/dtos/outputs/degustacao/GustatoryInspectionOutputDTO.java b/bff/src/main/java/com/vinhonotas/bff/interfaces/dtos/outputs/degustacao/GustatoryInspectionOutputDTO.java deleted file mode 100644 index 59e3347f..00000000 --- a/bff/src/main/java/com/vinhonotas/bff/interfaces/dtos/outputs/degustacao/GustatoryInspectionOutputDTO.java +++ /dev/null @@ -1,27 +0,0 @@ -package com.vinhonotas.bff.interfaces.dtos.outputs.degustacao; - -import lombok.Builder; -import lombok.Data; - -import java.time.LocalDate; -import java.util.UUID; - -@Data -@Builder -public class GustatoryInspectionOutputDTO { - - private UUID id; - private LocalDate tastingData; - private String wineTasted; - private String body; - private String sweetness; - private String tannin; - private String classification; - private String acidity; - private String alcohol; - private String persistence; - private String maturity; - private String typicality; - private TastingCardOutputDTO tastingCard; - -} diff --git a/bff/src/main/java/com/vinhonotas/bff/interfaces/dtos/outputs/degustacao/OlfactoryInspectionOutputDTO.java b/bff/src/main/java/com/vinhonotas/bff/interfaces/dtos/outputs/degustacao/OlfactoryInspectionOutputDTO.java deleted file mode 100644 index 9cea43e9..00000000 --- a/bff/src/main/java/com/vinhonotas/bff/interfaces/dtos/outputs/degustacao/OlfactoryInspectionOutputDTO.java +++ /dev/null @@ -1,23 +0,0 @@ -package com.vinhonotas.bff.interfaces.dtos.outputs.degustacao; - -import lombok.Builder; -import lombok.Data; - -import java.time.LocalDate; -import java.util.UUID; - -@Data -@Builder -public class OlfactoryInspectionOutputDTO { - - private UUID id; - private LocalDate tastingData; - private String wineTasted; - private String intensity; - private String persistence; - private String quality; - private AromasOutputDTO aromas; - private String classification; - private TastingCardOutputDTO tastingCard; - -} diff --git a/bff/src/main/java/com/vinhonotas/bff/interfaces/dtos/outputs/degustacao/TastingCardOutputDTO.java b/bff/src/main/java/com/vinhonotas/bff/interfaces/dtos/outputs/degustacao/TastingCardOutputDTO.java index de69f60e..5233bba8 100644 --- a/bff/src/main/java/com/vinhonotas/bff/interfaces/dtos/outputs/degustacao/TastingCardOutputDTO.java +++ b/bff/src/main/java/com/vinhonotas/bff/interfaces/dtos/outputs/degustacao/TastingCardOutputDTO.java @@ -1,6 +1,5 @@ package com.vinhonotas.bff.interfaces.dtos.outputs.degustacao; -import com.vinhonotas.bff.domain.enums.EnumPointScale; import lombok.Builder; import lombok.Data; @@ -12,17 +11,45 @@ public class TastingCardOutputDTO { private UUID id; - private LocalDate tastingData; private String wineTasted; + private LocalDate tastingData; private String harvest; private String grapes; private String country; private String region; - private VisualInspectionOutputDTO visualInspection; - private OlfactoryInspectionOutputDTO olfactoryInspection; - private GustatoryInspectionOutputDTO gustatoryInspection; + private String clarity; + private String brightness; + private String viscosity; + private String colorRed; + private String colorWhite; + private String colorRose; + private String visualInspectionClassification; + private String intensity; + private String olfactoryInspectionPersistence; + private String quality; + private String fruity; + private String dryFruits; + private String florals; + private String vegetablesAndHerbs; + private String minerals; + private String spices; + private String animals; + private String empireumatics; + private String wood; + private String chemicals; + private String lacteal; + private String sweets; + private String olfactoryInspectionClassification; + private String body; + private String sweetness; + private String tannin; + private String acidity; + private String alcohol; + private String gustatoryInspectionPersistence; + private String maturity; + private String typicality; + private String gustatoryInspectionClassification; private String opinion; private String pointScale; - private TastingOutputDTO tasting; } diff --git a/bff/src/main/java/com/vinhonotas/bff/interfaces/dtos/outputs/degustacao/TastingOutputDTO.java b/bff/src/main/java/com/vinhonotas/bff/interfaces/dtos/outputs/degustacao/TastingOutputDTO.java deleted file mode 100644 index 446cdb2a..00000000 --- a/bff/src/main/java/com/vinhonotas/bff/interfaces/dtos/outputs/degustacao/TastingOutputDTO.java +++ /dev/null @@ -1,20 +0,0 @@ -package com.vinhonotas.bff.interfaces.dtos.outputs.degustacao; - -import com.vinhonotas.bff.domain.enums.EnumTastingType; -import lombok.Builder; -import lombok.Data; - -import java.time.LocalDate; -import java.util.Set; -import java.util.UUID; - -@Data -@Builder -public class TastingOutputDTO { - - private UUID id; - private LocalDate tastingData; - private String tastingType; - private Set tastingCards; - -} diff --git a/bff/src/main/java/com/vinhonotas/bff/interfaces/dtos/outputs/degustacao/VisualInspectionOutputDTO.java b/bff/src/main/java/com/vinhonotas/bff/interfaces/dtos/outputs/degustacao/VisualInspectionOutputDTO.java deleted file mode 100644 index 3ef0189c..00000000 --- a/bff/src/main/java/com/vinhonotas/bff/interfaces/dtos/outputs/degustacao/VisualInspectionOutputDTO.java +++ /dev/null @@ -1,25 +0,0 @@ -package com.vinhonotas.bff.interfaces.dtos.outputs.degustacao; - -import lombok.Builder; -import lombok.Data; - -import java.time.LocalDate; -import java.util.UUID; - -@Data -@Builder -public class VisualInspectionOutputDTO { - - private UUID id; - private LocalDate tastingData; - private String wineTasted; - private String clarity; - private String brightness; - private String viscosity; - private String colorRed; - private String colorWhite; - private String colorRose; - private String classification; - private TastingCardOutputDTO tastingCard; - -} diff --git a/bff/src/test/java/com/vinhonotas/bff/application/services/degustacao/impl/AromasServiceImplTest.java b/bff/src/test/java/com/vinhonotas/bff/application/services/degustacao/impl/AromasServiceImplTest.java index 40ad1eb7..b26626f6 100644 --- a/bff/src/test/java/com/vinhonotas/bff/application/services/degustacao/impl/AromasServiceImplTest.java +++ b/bff/src/test/java/com/vinhonotas/bff/application/services/degustacao/impl/AromasServiceImplTest.java @@ -1,236 +1,234 @@ -package com.vinhonotas.bff.application.services.degustacao.impl; - -import com.vinhonotas.bff.application.services.exceptions.BadRequestException; -import com.vinhonotas.bff.client.degustacao.AromasClient; -import com.vinhonotas.bff.domain.enums.*; -import com.vinhonotas.bff.interfaces.dtos.inputs.degustacao.AromasInputDTO; -import com.vinhonotas.bff.interfaces.dtos.outputs.degustacao.AromasOutputDTO; -import com.vinhonotas.bff.utils.MessagesConstants; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.DisplayName; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; -import org.mockito.InjectMocks; -import org.mockito.Mock; -import org.mockito.junit.jupiter.MockitoExtension; - -import java.time.LocalDate; -import java.util.List; -import java.util.UUID; - -import static org.junit.jupiter.api.Assertions.*; -import static org.mockito.Mockito.*; - -@ExtendWith(MockitoExtension.class) -class AromasServiceImplTest { - - @InjectMocks - private AromasServiceImpl aromasService; - - @Mock - private AromasClient aromasClient; - - private AromasOutputDTO aromasOutputDTO; - private AromasInputDTO aromasInputDTO; - - @BeforeEach - void setUp() { - aromasOutputDTO = createAromasOutputDTO(); - aromasInputDTO = createAromasInputDTO(); - } - - @Test - @DisplayName("Deve criar um novo registro de Aromas") - void testCreate() { - when(aromasClient.createAromas(aromasInputDTO)).thenReturn(aromasOutputDTO); - - AromasOutputDTO response = assertDoesNotThrow(() -> aromasService.createAromas(aromasInputDTO)); - - assertNotNull(response); - assertEquals(aromasOutputDTO.getTastingData(), response.getTastingData()); - assertEquals(aromasOutputDTO.getWineTasted(), response.getWineTasted()); - assertEquals(aromasOutputDTO.getFruity(), response.getFruity()); - assertEquals(aromasOutputDTO.getDryFruits(), response.getDryFruits()); - assertEquals(aromasOutputDTO.getFlorals(), response.getFlorals()); - assertEquals(aromasOutputDTO.getVegetablesAndHerbs(), response.getVegetablesAndHerbs()); - assertEquals(aromasOutputDTO.getMinerals(), response.getMinerals()); - assertEquals(aromasOutputDTO.getSpices(), response.getSpices()); - assertEquals(aromasOutputDTO.getAnimals(), response.getAnimals()); - assertEquals(aromasOutputDTO.getEmpireumatics(), response.getEmpireumatics()); - assertEquals(aromasOutputDTO.getWood(), response.getWood()); - assertEquals(aromasOutputDTO.getChemicals(), response.getChemicals()); - assertEquals(aromasOutputDTO.getLacteal(), response.getLacteal()); - assertEquals(aromasOutputDTO.getSweets(), response.getSweets()); - verify(aromasClient).createAromas(aromasInputDTO); - } - - @Test - @DisplayName("Deve lançar BadRequestException ao tentar criar um novo registro de Aromas") - void testCreateThrowsBadRequestException() { - when(aromasClient.createAromas(aromasInputDTO)).thenThrow(new BadRequestException(MessagesConstants.ERROR_WHEN_SAVING)); - - Exception exception = assertThrows(Exception.class, () -> aromasService.createAromas(aromasInputDTO)); - - assertEquals(MessagesConstants.ERROR_WHEN_SAVING, exception.getMessage()); - } - - @Test - @DisplayName("Deve retornar uma lista de Aromas") - void testGetAll() { - when(aromasClient.getAllAromas()).thenReturn(List.of(aromasOutputDTO)); - - List list = assertDoesNotThrow(() -> aromasService.getAllAromas()); - - assertNotNull(list); - assertFalse(list.isEmpty()); - assertEquals(1, list.size()); - assertEquals(aromasOutputDTO.getTastingData(), list.get(0).getTastingData()); - assertEquals(aromasOutputDTO.getWineTasted(), list.get(0).getWineTasted()); - assertEquals(aromasOutputDTO.getFruity(), list.get(0).getFruity()); - assertEquals(aromasOutputDTO.getDryFruits(), list.get(0).getDryFruits()); - assertEquals(aromasOutputDTO.getFlorals(), list.get(0).getFlorals()); - assertEquals(aromasOutputDTO.getVegetablesAndHerbs(), list.get(0).getVegetablesAndHerbs()); - assertEquals(aromasOutputDTO.getMinerals(), list.get(0).getMinerals()); - assertEquals(aromasOutputDTO.getSpices(), list.get(0).getSpices()); - assertEquals(aromasOutputDTO.getAnimals(), list.get(0).getAnimals()); - assertEquals(aromasOutputDTO.getEmpireumatics(), list.get(0).getEmpireumatics()); - assertEquals(aromasOutputDTO.getWood(), list.get(0).getWood()); - assertEquals(aromasOutputDTO.getChemicals(), list.get(0).getChemicals()); - assertEquals(aromasOutputDTO.getLacteal(), list.get(0).getLacteal()); - assertEquals(aromasOutputDTO.getSweets(), list.get(0).getSweets()); - verify(aromasClient).getAllAromas(); - } - - @Test - @DisplayName("Deve lançar BadRequestException ao tentar retornar uma lista de Aromas") - void testGetAllThrowsBadRequestException() { - when(aromasClient.getAllAromas()).thenReturn(List.of()); - Exception exception = assertThrows(Exception.class, () -> aromasService.getAllAromas()); - - assertEquals(MessagesConstants.NOT_FOUND, exception.getMessage()); - } - - @Test - @DisplayName("Deve retornar um registro de Aromas") - void testGetById() { - when(aromasClient.getAromasById("f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e")).thenReturn(aromasOutputDTO); - - AromasOutputDTO entity = assertDoesNotThrow(() -> aromasService.getAromasById("f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e")); - - assertNotNull(entity); - assertEquals(aromasOutputDTO.getTastingData(), entity.getTastingData()); - assertEquals(aromasOutputDTO.getWineTasted(), entity.getWineTasted()); - assertEquals(aromasOutputDTO.getFruity(), entity.getFruity()); - assertEquals(aromasOutputDTO.getDryFruits(), entity.getDryFruits()); - assertEquals(aromasOutputDTO.getFlorals(), entity.getFlorals()); - assertEquals(aromasOutputDTO.getVegetablesAndHerbs(), entity.getVegetablesAndHerbs()); - assertEquals(aromasOutputDTO.getMinerals(), entity.getMinerals()); - assertEquals(aromasOutputDTO.getSpices(), entity.getSpices()); - assertEquals(aromasOutputDTO.getAnimals(), entity.getAnimals()); - assertEquals(aromasOutputDTO.getEmpireumatics(), entity.getEmpireumatics()); - assertEquals(aromasOutputDTO.getWood(), entity.getWood()); - assertEquals(aromasOutputDTO.getChemicals(), entity.getChemicals()); - assertEquals(aromasOutputDTO.getLacteal(), entity.getLacteal()); - assertEquals(aromasOutputDTO.getSweets(), entity.getSweets()); - verify(aromasClient).getAromasById("f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e"); - } - - @Test - @DisplayName("Deve lançar BadRequestException ao tentar retornar um registro de Aromas") - void testGetByIdThrowsBadRequestException() { - when(aromasClient.getAromasById("f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e")).thenReturn(null); - Exception exception = assertThrows(Exception.class, () -> aromasService.getAromasById("f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e")); - - assertEquals(MessagesConstants.NOT_FOUND, exception.getMessage()); - } - - @Test - @DisplayName("Deve atualizar um registro de Aromas") - void testUpdate() { - when(aromasClient.updateAromas("f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e", aromasInputDTO)).thenReturn(aromasOutputDTO); - - AromasOutputDTO aromasUpdated = assertDoesNotThrow(() -> aromasService.updateAromas("f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e", aromasInputDTO)); - - assertNotNull(aromasUpdated); - assertEquals(aromasOutputDTO.getTastingData(), aromasUpdated.getTastingData()); - assertEquals(aromasOutputDTO.getWineTasted(), aromasUpdated.getWineTasted()); - assertEquals(aromasOutputDTO.getFruity(), aromasUpdated.getFruity()); - assertEquals(aromasOutputDTO.getDryFruits(), aromasUpdated.getDryFruits()); - assertEquals(aromasOutputDTO.getFlorals(), aromasUpdated.getFlorals()); - assertEquals(aromasOutputDTO.getVegetablesAndHerbs(), aromasUpdated.getVegetablesAndHerbs()); - assertEquals(aromasOutputDTO.getMinerals(), aromasUpdated.getMinerals()); - assertEquals(aromasOutputDTO.getSpices(), aromasUpdated.getSpices()); - assertEquals(aromasOutputDTO.getAnimals(), aromasUpdated.getAnimals()); - assertEquals(aromasOutputDTO.getEmpireumatics(), aromasUpdated.getEmpireumatics()); - assertEquals(aromasOutputDTO.getWood(), aromasUpdated.getWood()); - assertEquals(aromasOutputDTO.getChemicals(), aromasUpdated.getChemicals()); - assertEquals(aromasOutputDTO.getLacteal(), aromasUpdated.getLacteal()); - assertEquals(aromasOutputDTO.getSweets(), aromasUpdated.getSweets()); - verify(aromasClient).updateAromas("f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e", aromasInputDTO); - } - - @Test - @DisplayName("Deve lançar BadRequestException ao tentar atualizar um registro de Aromas") - void testUpdateThrowsBadRequestException() { - when(aromasClient.updateAromas("f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e", aromasInputDTO)).thenThrow(new BadRequestException(MessagesConstants.ERROR_WHEN_UPDATING)); - Exception exception = assertThrows(Exception.class, () -> aromasService.updateAromas("f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e", aromasInputDTO)); - - assertEquals(MessagesConstants.ERROR_WHEN_UPDATING, exception.getMessage()); - } - - @Test - @DisplayName("Deve deletar um registro de Aromas") - void testDelete() { - assertDoesNotThrow(() -> aromasService.deleteAromas("f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e")); - verify(aromasClient).deleteAromas("f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e"); - } - - @Test - @DisplayName("Deve lançar BadRequestException ao tentar deletar um registro de Aromas") - void testDeleteThrowsBadRequestException() { - doThrow(BadRequestException.class).when(aromasClient).deleteAromas("f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e"); - - Exception exception = assertThrows(Exception.class, () -> aromasService.deleteAromas("f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e")); - assertEquals(MessagesConstants.ERROR_WHEN_DELETING, exception.getMessage()); - } - - private AromasInputDTO createAromasInputDTO() { - return AromasInputDTO.builder() - .tastingData(LocalDate.now()) - .wineTasted("Wine Tasted") - .fruity(EnumFruityType.RASPBERRY.getCode()) - .dryFruits(EnumDryFruitsType.BRUNETTE.getCode()) - .florals(EnumFloralsType.CLOVE.getCode()) - .vegetablesAndHerbs(EnumVegetablesAndHerbsType.FENNEL.getCode()) - .minerals(EnumMineralsType.EARTH.getCode()) - .spices(EnumSpicesType.INDIAN_CLOVE.getCode()) - .animals(EnumAnimalsType.LEATHER.getCode()) - .empireumatics(EnumEmpireumaticsType.CARAMEL.getCode()) - .wood(EnumWoodType.SAWDUST.getCode()) - .chemicals(EnumChemicalsAndEtherealType.ACETONE.getCode()) - .lacteal(EnumLactealType.BUTTER.getCode()) - .sweets(EnumSweetsType.BULLET.getCode()) - .build(); - } - - private AromasOutputDTO createAromasOutputDTO() { - return AromasOutputDTO.builder() - .id(UUID.fromString("f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e")) - .tastingData(LocalDate.now()) - .wineTasted("Wine Tasted") - .fruity(EnumFruityType.RASPBERRY.getCode()) - .dryFruits(EnumDryFruitsType.BRUNETTE.getCode()) - .florals(EnumFloralsType.CLOVE.getCode()) - .vegetablesAndHerbs(EnumVegetablesAndHerbsType.FENNEL.getCode()) - .minerals(EnumMineralsType.EARTH.getCode()) - .spices(EnumSpicesType.INDIAN_CLOVE.getCode()) - .animals(EnumAnimalsType.LEATHER.getCode()) - .empireumatics(EnumEmpireumaticsType.CARAMEL.getCode()) - .wood(EnumWoodType.SAWDUST.getCode()) - .chemicals(EnumChemicalsAndEtherealType.ACETONE.getCode()) - .lacteal(EnumLactealType.BUTTER.getCode()) - .sweets(EnumSweetsType.BULLET.getCode()) - .build(); - } - -} \ No newline at end of file +//package com.vinhonotas.bff.application.services.degustacao.impl; +// +//import com.vinhonotas.bff.application.services.exceptions.BadRequestException; +//import com.vinhonotas.bff.client.degustacao.AromasClient; +//import com.vinhonotas.bff.domain.enums.*; +//import com.vinhonotas.bff.utils.MessagesConstants; +//import org.junit.jupiter.api.BeforeEach; +//import org.junit.jupiter.api.DisplayName; +//import org.junit.jupiter.api.Test; +//import org.junit.jupiter.api.extension.ExtendWith; +//import org.mockito.InjectMocks; +//import org.mockito.Mock; +//import org.mockito.junit.jupiter.MockitoExtension; +// +//import java.time.LocalDate; +//import java.util.List; +//import java.util.UUID; +// +//import static org.junit.jupiter.api.Assertions.*; +//import static org.mockito.Mockito.*; +// +//@ExtendWith(MockitoExtension.class) +//class AromasServiceImplTest { +// +// @InjectMocks +// private AromasServiceImpl aromasService; +// +// @Mock +// private AromasClient aromasClient; +// +// private AromasOutputDTO aromasOutputDTO; +// private AromasInputDTO aromasInputDTO; +// +// @BeforeEach +// void setUp() { +// aromasOutputDTO = createAromasOutputDTO(); +// aromasInputDTO = createAromasInputDTO(); +// } +// +// @Test +// @DisplayName("Deve criar um novo registro de Aromas") +// void testCreate() { +// when(aromasClient.createAromas(aromasInputDTO)).thenReturn(aromasOutputDTO); +// +// AromasOutputDTO response = assertDoesNotThrow(() -> aromasService.createAromas(aromasInputDTO)); +// +// assertNotNull(response); +// assertEquals(aromasOutputDTO.getTastingData(), response.getTastingData()); +// assertEquals(aromasOutputDTO.getWineTasted(), response.getWineTasted()); +// assertEquals(aromasOutputDTO.getFruity(), response.getFruity()); +// assertEquals(aromasOutputDTO.getDryFruits(), response.getDryFruits()); +// assertEquals(aromasOutputDTO.getFlorals(), response.getFlorals()); +// assertEquals(aromasOutputDTO.getVegetablesAndHerbs(), response.getVegetablesAndHerbs()); +// assertEquals(aromasOutputDTO.getMinerals(), response.getMinerals()); +// assertEquals(aromasOutputDTO.getSpices(), response.getSpices()); +// assertEquals(aromasOutputDTO.getAnimals(), response.getAnimals()); +// assertEquals(aromasOutputDTO.getEmpireumatics(), response.getEmpireumatics()); +// assertEquals(aromasOutputDTO.getWood(), response.getWood()); +// assertEquals(aromasOutputDTO.getChemicals(), response.getChemicals()); +// assertEquals(aromasOutputDTO.getLacteal(), response.getLacteal()); +// assertEquals(aromasOutputDTO.getSweets(), response.getSweets()); +// verify(aromasClient).createAromas(aromasInputDTO); +// } +// +// @Test +// @DisplayName("Deve lançar BadRequestException ao tentar criar um novo registro de Aromas") +// void testCreateThrowsBadRequestException() { +// when(aromasClient.createAromas(aromasInputDTO)).thenThrow(new BadRequestException(MessagesConstants.ERROR_WHEN_SAVING)); +// +// Exception exception = assertThrows(Exception.class, () -> aromasService.createAromas(aromasInputDTO)); +// +// assertEquals(MessagesConstants.ERROR_WHEN_SAVING, exception.getMessage()); +// } +// +// @Test +// @DisplayName("Deve retornar uma lista de Aromas") +// void testGetAll() { +// when(aromasClient.getAllAromas()).thenReturn(List.of(aromasOutputDTO)); +// +// List list = assertDoesNotThrow(() -> aromasService.getAllAromas()); +// +// assertNotNull(list); +// assertFalse(list.isEmpty()); +// assertEquals(1, list.size()); +// assertEquals(aromasOutputDTO.getTastingData(), list.get(0).getTastingData()); +// assertEquals(aromasOutputDTO.getWineTasted(), list.get(0).getWineTasted()); +// assertEquals(aromasOutputDTO.getFruity(), list.get(0).getFruity()); +// assertEquals(aromasOutputDTO.getDryFruits(), list.get(0).getDryFruits()); +// assertEquals(aromasOutputDTO.getFlorals(), list.get(0).getFlorals()); +// assertEquals(aromasOutputDTO.getVegetablesAndHerbs(), list.get(0).getVegetablesAndHerbs()); +// assertEquals(aromasOutputDTO.getMinerals(), list.get(0).getMinerals()); +// assertEquals(aromasOutputDTO.getSpices(), list.get(0).getSpices()); +// assertEquals(aromasOutputDTO.getAnimals(), list.get(0).getAnimals()); +// assertEquals(aromasOutputDTO.getEmpireumatics(), list.get(0).getEmpireumatics()); +// assertEquals(aromasOutputDTO.getWood(), list.get(0).getWood()); +// assertEquals(aromasOutputDTO.getChemicals(), list.get(0).getChemicals()); +// assertEquals(aromasOutputDTO.getLacteal(), list.get(0).getLacteal()); +// assertEquals(aromasOutputDTO.getSweets(), list.get(0).getSweets()); +// verify(aromasClient).getAllAromas(); +// } +// +// @Test +// @DisplayName("Deve lançar BadRequestException ao tentar retornar uma lista de Aromas") +// void testGetAllThrowsBadRequestException() { +// when(aromasClient.getAllAromas()).thenReturn(List.of()); +// Exception exception = assertThrows(Exception.class, () -> aromasService.getAllAromas()); +// +// assertEquals(MessagesConstants.NOT_FOUND, exception.getMessage()); +// } +// +// @Test +// @DisplayName("Deve retornar um registro de Aromas") +// void testGetById() { +// when(aromasClient.getAromasById("f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e")).thenReturn(aromasOutputDTO); +// +// AromasOutputDTO entity = assertDoesNotThrow(() -> aromasService.getAromasById("f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e")); +// +// assertNotNull(entity); +// assertEquals(aromasOutputDTO.getTastingData(), entity.getTastingData()); +// assertEquals(aromasOutputDTO.getWineTasted(), entity.getWineTasted()); +// assertEquals(aromasOutputDTO.getFruity(), entity.getFruity()); +// assertEquals(aromasOutputDTO.getDryFruits(), entity.getDryFruits()); +// assertEquals(aromasOutputDTO.getFlorals(), entity.getFlorals()); +// assertEquals(aromasOutputDTO.getVegetablesAndHerbs(), entity.getVegetablesAndHerbs()); +// assertEquals(aromasOutputDTO.getMinerals(), entity.getMinerals()); +// assertEquals(aromasOutputDTO.getSpices(), entity.getSpices()); +// assertEquals(aromasOutputDTO.getAnimals(), entity.getAnimals()); +// assertEquals(aromasOutputDTO.getEmpireumatics(), entity.getEmpireumatics()); +// assertEquals(aromasOutputDTO.getWood(), entity.getWood()); +// assertEquals(aromasOutputDTO.getChemicals(), entity.getChemicals()); +// assertEquals(aromasOutputDTO.getLacteal(), entity.getLacteal()); +// assertEquals(aromasOutputDTO.getSweets(), entity.getSweets()); +// verify(aromasClient).getAromasById("f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e"); +// } +// +// @Test +// @DisplayName("Deve lançar BadRequestException ao tentar retornar um registro de Aromas") +// void testGetByIdThrowsBadRequestException() { +// when(aromasClient.getAromasById("f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e")).thenReturn(null); +// Exception exception = assertThrows(Exception.class, () -> aromasService.getAromasById("f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e")); +// +// assertEquals(MessagesConstants.NOT_FOUND, exception.getMessage()); +// } +// +// @Test +// @DisplayName("Deve atualizar um registro de Aromas") +// void testUpdate() { +// when(aromasClient.updateAromas("f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e", aromasInputDTO)).thenReturn(aromasOutputDTO); +// +// AromasOutputDTO aromasUpdated = assertDoesNotThrow(() -> aromasService.updateAromas("f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e", aromasInputDTO)); +// +// assertNotNull(aromasUpdated); +// assertEquals(aromasOutputDTO.getTastingData(), aromasUpdated.getTastingData()); +// assertEquals(aromasOutputDTO.getWineTasted(), aromasUpdated.getWineTasted()); +// assertEquals(aromasOutputDTO.getFruity(), aromasUpdated.getFruity()); +// assertEquals(aromasOutputDTO.getDryFruits(), aromasUpdated.getDryFruits()); +// assertEquals(aromasOutputDTO.getFlorals(), aromasUpdated.getFlorals()); +// assertEquals(aromasOutputDTO.getVegetablesAndHerbs(), aromasUpdated.getVegetablesAndHerbs()); +// assertEquals(aromasOutputDTO.getMinerals(), aromasUpdated.getMinerals()); +// assertEquals(aromasOutputDTO.getSpices(), aromasUpdated.getSpices()); +// assertEquals(aromasOutputDTO.getAnimals(), aromasUpdated.getAnimals()); +// assertEquals(aromasOutputDTO.getEmpireumatics(), aromasUpdated.getEmpireumatics()); +// assertEquals(aromasOutputDTO.getWood(), aromasUpdated.getWood()); +// assertEquals(aromasOutputDTO.getChemicals(), aromasUpdated.getChemicals()); +// assertEquals(aromasOutputDTO.getLacteal(), aromasUpdated.getLacteal()); +// assertEquals(aromasOutputDTO.getSweets(), aromasUpdated.getSweets()); +// verify(aromasClient).updateAromas("f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e", aromasInputDTO); +// } +// +// @Test +// @DisplayName("Deve lançar BadRequestException ao tentar atualizar um registro de Aromas") +// void testUpdateThrowsBadRequestException() { +// when(aromasClient.updateAromas("f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e", aromasInputDTO)).thenThrow(new BadRequestException(MessagesConstants.ERROR_WHEN_UPDATING)); +// Exception exception = assertThrows(Exception.class, () -> aromasService.updateAromas("f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e", aromasInputDTO)); +// +// assertEquals(MessagesConstants.ERROR_WHEN_UPDATING, exception.getMessage()); +// } +// +// @Test +// @DisplayName("Deve deletar um registro de Aromas") +// void testDelete() { +// assertDoesNotThrow(() -> aromasService.deleteAromas("f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e")); +// verify(aromasClient).deleteAromas("f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e"); +// } +// +// @Test +// @DisplayName("Deve lançar BadRequestException ao tentar deletar um registro de Aromas") +// void testDeleteThrowsBadRequestException() { +// doThrow(BadRequestException.class).when(aromasClient).deleteAromas("f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e"); +// +// Exception exception = assertThrows(Exception.class, () -> aromasService.deleteAromas("f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e")); +// assertEquals(MessagesConstants.ERROR_WHEN_DELETING, exception.getMessage()); +// } +// +// private AromasInputDTO createAromasInputDTO() { +// return AromasInputDTO.builder() +// .tastingData(LocalDate.now()) +// .wineTasted("Wine Tasted") +// .fruity(EnumFruityType.RASPBERRY.getCode()) +// .dryFruits(EnumDryFruitsType.BRUNETTE.getCode()) +// .florals(EnumFloralsType.CLOVE.getCode()) +// .vegetablesAndHerbs(EnumVegetablesAndHerbsType.FENNEL.getCode()) +// .minerals(EnumMineralsType.EARTH.getCode()) +// .spices(EnumSpicesType.INDIAN_CLOVE.getCode()) +// .animals(EnumAnimalsType.LEATHER.getCode()) +// .empireumatics(EnumEmpireumaticsType.CARAMEL.getCode()) +// .wood(EnumWoodType.SAWDUST.getCode()) +// .chemicals(EnumChemicalsAndEtherealType.ACETONE.getCode()) +// .lacteal(EnumLactealType.BUTTER.getCode()) +// .sweets(EnumSweetsType.BULLET.getCode()) +// .build(); +// } +// +// private AromasOutputDTO createAromasOutputDTO() { +// return AromasOutputDTO.builder() +// .id(UUID.fromString("f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e")) +// .tastingData(LocalDate.now()) +// .wineTasted("Wine Tasted") +// .fruity(EnumFruityType.RASPBERRY.getCode()) +// .dryFruits(EnumDryFruitsType.BRUNETTE.getCode()) +// .florals(EnumFloralsType.CLOVE.getCode()) +// .vegetablesAndHerbs(EnumVegetablesAndHerbsType.FENNEL.getCode()) +// .minerals(EnumMineralsType.EARTH.getCode()) +// .spices(EnumSpicesType.INDIAN_CLOVE.getCode()) +// .animals(EnumAnimalsType.LEATHER.getCode()) +// .empireumatics(EnumEmpireumaticsType.CARAMEL.getCode()) +// .wood(EnumWoodType.SAWDUST.getCode()) +// .chemicals(EnumChemicalsAndEtherealType.ACETONE.getCode()) +// .lacteal(EnumLactealType.BUTTER.getCode()) +// .sweets(EnumSweetsType.BULLET.getCode()) +// .build(); +// } +// +//} \ No newline at end of file diff --git a/bff/src/test/java/com/vinhonotas/bff/application/services/degustacao/impl/GustatoryInspectionServiceImplTest.java b/bff/src/test/java/com/vinhonotas/bff/application/services/degustacao/impl/GustatoryInspectionServiceImplTest.java index 58eccbf0..105a4bcc 100644 --- a/bff/src/test/java/com/vinhonotas/bff/application/services/degustacao/impl/GustatoryInspectionServiceImplTest.java +++ b/bff/src/test/java/com/vinhonotas/bff/application/services/degustacao/impl/GustatoryInspectionServiceImplTest.java @@ -1,229 +1,227 @@ -package com.vinhonotas.bff.application.services.degustacao.impl; - -import com.vinhonotas.bff.application.services.exceptions.BadRequestException; -import com.vinhonotas.bff.client.degustacao.GustatoryInspectionClient; -import com.vinhonotas.bff.domain.enums.*; -import com.vinhonotas.bff.interfaces.dtos.inputs.degustacao.GustatoryInspectionInputDTO; -import com.vinhonotas.bff.interfaces.dtos.outputs.degustacao.GustatoryInspectionOutputDTO; -import com.vinhonotas.bff.interfaces.dtos.outputs.degustacao.TastingCardOutputDTO; -import com.vinhonotas.bff.utils.MessagesConstants; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.DisplayName; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; -import org.mockito.InjectMocks; -import org.mockito.Mock; -import org.mockito.Mockito; -import org.mockito.junit.jupiter.MockitoExtension; - -import java.time.LocalDate; -import java.util.List; -import java.util.UUID; - -import static org.junit.jupiter.api.Assertions.*; -import static org.mockito.Mockito.*; - -@ExtendWith(MockitoExtension.class) -class GustatoryInspectionServiceImplTest { - - @InjectMocks - private GustatoryInspectionServiceImpl service; - - @Mock - private GustatoryInspectionClient client; - - private GustatoryInspectionInputDTO inputDTO; - private GustatoryInspectionOutputDTO outputDTO; - - @BeforeEach - void setUp() { - inputDTO = createGustatoryInspectionInputDTO(); - outputDTO = createGustatoryInspectionOutputDTO(); - } - - @Test - @DisplayName("Deve criar uma inspeção gustativa") - void testCreate() { - when(client.createGustatoryInspection(inputDTO)).thenReturn(outputDTO); - - GustatoryInspectionOutputDTO result = assertDoesNotThrow(() -> service.createGustatoryInspection(inputDTO)); - assertNotNull(result); - assertEquals(outputDTO.getId(), result.getId()); - assertEquals(outputDTO.getTastingData(), result.getTastingData()); - assertEquals(outputDTO.getWineTasted(), result.getWineTasted()); - assertEquals(outputDTO.getBody(), result.getBody()); - assertEquals(outputDTO.getSweetness(), result.getSweetness()); - assertEquals(outputDTO.getTannin(), result.getTannin()); - assertEquals(outputDTO.getClassification(), result.getClassification()); - assertEquals(outputDTO.getAcidity(), result.getAcidity()); - assertEquals(outputDTO.getAlcohol(), result.getAlcohol()); - assertEquals(outputDTO.getPersistence(), result.getPersistence()); - assertEquals(outputDTO.getMaturity(), result.getMaturity()); - assertEquals(outputDTO.getTypicality(), result.getTypicality()); - assertEquals(outputDTO.getTastingCard(), result.getTastingCard()); - verify(client).createGustatoryInspection(inputDTO); - } - - @Test - @DisplayName("Deve lançar BadRequestException ao criar uma inspeção gustativa") - void testCreateThrowBadRequestException() { - when(client.createGustatoryInspection(inputDTO)).thenThrow(new BadRequestException(MessagesConstants.ERROR_WHEN_SAVING)); - - Exception exception = assertThrows(Exception.class, () -> service.createGustatoryInspection(inputDTO)); - assertEquals(MessagesConstants.ERROR_WHEN_SAVING, exception.getMessage()); - verify(client).createGustatoryInspection(inputDTO); - } - - @Test - @DisplayName("Deve listar todas as inspeções gustativas") - void testGetAll() { - when(client.getAllGustatoryInspections()).thenReturn(List.of(outputDTO)); - - List result = assertDoesNotThrow(() -> service.getAllGustatoryInspections()); - assertNotNull(result); - assertEquals(1, result.size()); - assertEquals(outputDTO.getId(), result.get(0).getId()); - assertEquals(outputDTO.getTastingData(), result.get(0).getTastingData()); - assertEquals(outputDTO.getWineTasted(), result.get(0).getWineTasted()); - assertEquals(outputDTO.getBody(), result.get(0).getBody()); - assertEquals(outputDTO.getSweetness(), result.get(0).getSweetness()); - assertEquals(outputDTO.getTannin(), result.get(0).getTannin()); - assertEquals(outputDTO.getClassification(), result.get(0).getClassification()); - assertEquals(outputDTO.getAcidity(), result.get(0).getAcidity()); - assertEquals(outputDTO.getAlcohol(), result.get(0).getAlcohol()); - assertEquals(outputDTO.getPersistence(), result.get(0).getPersistence()); - assertEquals(outputDTO.getMaturity(), result.get(0).getMaturity()); - assertEquals(outputDTO.getTypicality(), result.get(0).getTypicality()); - assertEquals(outputDTO.getTastingCard(), result.get(0).getTastingCard()); - verify(client).getAllGustatoryInspections(); - } - - @Test - @DisplayName("Deve lançar NotFoundException ao listar todas as inspeções gustativas") - void testGetAllThrowNotFoundException() { - when(client.getAllGustatoryInspections()).thenReturn(List.of()); - - Exception exception = assertThrows(Exception.class, () -> service.getAllGustatoryInspections()); - assertEquals(MessagesConstants.NOT_FOUND, exception.getMessage()); - verify(client).getAllGustatoryInspections(); - } - - @Test - @DisplayName("Deve buscar uma inspeção gustativa pelo id") - void testGetById() { - when(client.getGustatoryInspectionById(outputDTO.getId().toString())).thenReturn(outputDTO); - - GustatoryInspectionOutputDTO result = assertDoesNotThrow(() -> service.getGustatoryInspectionById(outputDTO.getId().toString())); - assertNotNull(result); - assertEquals(outputDTO.getId(), result.getId()); - assertEquals(outputDTO.getTastingData(), result.getTastingData()); - assertEquals(outputDTO.getWineTasted(), result.getWineTasted()); - assertEquals(outputDTO.getBody(), result.getBody()); - assertEquals(outputDTO.getSweetness(), result.getSweetness()); - assertEquals(outputDTO.getTannin(), result.getTannin()); - assertEquals(outputDTO.getClassification(), result.getClassification()); - assertEquals(outputDTO.getAcidity(), result.getAcidity()); - assertEquals(outputDTO.getAlcohol(), result.getAlcohol()); - assertEquals(outputDTO.getPersistence(), result.getPersistence()); - assertEquals(outputDTO.getMaturity(), result.getMaturity()); - assertEquals(outputDTO.getTypicality(), result.getTypicality()); - assertEquals(outputDTO.getTastingCard(), result.getTastingCard()); - verify(client).getGustatoryInspectionById(outputDTO.getId().toString()); - } - - @Test - @DisplayName("Deve lançar NotFoundException ao buscar uma inspeção gustativa pelo id") - void testGetByIdThrowNotFoundException() { - when(client.getGustatoryInspectionById(outputDTO.getId().toString())).thenReturn(null); - - Exception exception = assertThrows(Exception.class, () -> service.getGustatoryInspectionById(outputDTO.getId().toString())); - assertEquals(MessagesConstants.NOT_FOUND, exception.getMessage()); - verify(client).getGustatoryInspectionById(outputDTO.getId().toString()); - } - - @Test - @DisplayName("Deve atualizar uma inspeção gustativa") - void testUpdate() { - when(client.updateGustatoryInspection(outputDTO.getId().toString(), inputDTO)).thenReturn(outputDTO); - - GustatoryInspectionOutputDTO result = assertDoesNotThrow(() -> service.updateGustatoryInspection(outputDTO.getId().toString(), inputDTO)); - assertNotNull(result); - assertEquals(outputDTO.getId(), result.getId()); - assertEquals(outputDTO.getTastingData(), result.getTastingData()); - assertEquals(outputDTO.getWineTasted(), result.getWineTasted()); - assertEquals(outputDTO.getBody(), result.getBody()); - assertEquals(outputDTO.getSweetness(), result.getSweetness()); - assertEquals(outputDTO.getTannin(), result.getTannin()); - assertEquals(outputDTO.getClassification(), result.getClassification()); - assertEquals(outputDTO.getAcidity(), result.getAcidity()); - assertEquals(outputDTO.getAlcohol(), result.getAlcohol()); - assertEquals(outputDTO.getPersistence(), result.getPersistence()); - assertEquals(outputDTO.getMaturity(), result.getMaturity()); - assertEquals(outputDTO.getTypicality(), result.getTypicality()); - assertEquals(outputDTO.getTastingCard(), result.getTastingCard()); - verify(client).updateGustatoryInspection(outputDTO.getId().toString(), inputDTO); - } - - @Test - @DisplayName("Deve lançar BadRequestException ao atualizar uma inspeção gustativa") - void testUpdateThrowBadRequestException() { - when(client.updateGustatoryInspection(outputDTO.getId().toString(), inputDTO)).thenThrow(new BadRequestException(MessagesConstants.ERROR_WHEN_UPDATING)); - - Exception exception = assertThrows(Exception.class, () -> service.updateGustatoryInspection(outputDTO.getId().toString(), inputDTO)); - assertEquals(MessagesConstants.ERROR_WHEN_UPDATING, exception.getMessage()); - verify(client).updateGustatoryInspection(outputDTO.getId().toString(), inputDTO); - } - - @Test - @DisplayName("Deve deletar uma inspeção gustativa") - void testDelete() { - assertDoesNotThrow(() -> service.deleteGustatoryInspection(outputDTO.getId().toString())); - verify(client).deleteGustatoryInspection(outputDTO.getId().toString()); - } - - @Test - @DisplayName("Deve lançar BadRequestException ao deletar uma inspeção gustativa") - void testDeleteThrowBadRequestException() { - doThrow(new BadRequestException(MessagesConstants.ERROR_WHEN_DELETING)) - .when(client).deleteGustatoryInspection(outputDTO.getId().toString()); - - Exception exception = assertThrows(Exception.class, () -> service.deleteGustatoryInspection(outputDTO.getId().toString())); - assertEquals(MessagesConstants.ERROR_WHEN_DELETING, exception.getMessage()); - verify(client).deleteGustatoryInspection(outputDTO.getId().toString()); - } - - private GustatoryInspectionInputDTO createGustatoryInspectionInputDTO() { - return GustatoryInspectionInputDTO.builder() - .tastingData(LocalDate.now()) - .wineTasted("Wine Tasted") - .body(EnumBodyType.FULL_BODIED.getCode()) - .sweetness(EnumSweetnessType.VERY_DRY.getCode()) - .tannin(EnumTanninType.LITTLE_TANIC.getCode()) - .classification(EnumClassificationType.LITTLE.getCode()) - .acidity(EnumAcidityType.LITTLE_ACID.getCode()) - .alcohol(EnumAlcoholType.LOW.getCode()) - .persistence(EnumPersistenceType.SHORT.getCode()) - .maturity(EnumMaturityType.MATURE.getCode()) - .typicality(EnumTypicalityType.NOT_TYPICAL.getCode()) - .build(); - } - - private GustatoryInspectionOutputDTO createGustatoryInspectionOutputDTO() { - return GustatoryInspectionOutputDTO.builder() - .id(UUID.fromString("f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e")) - .tastingData(LocalDate.now()) - .wineTasted("Wine Tasted") - .body(EnumBodyType.FULL_BODIED.getCode()) - .sweetness(EnumSweetnessType.VERY_DRY.getCode()) - .tannin(EnumTanninType.LITTLE_TANIC.getCode()) - .classification(EnumClassificationType.LITTLE.getCode()) - .acidity(EnumAcidityType.LITTLE_ACID.getCode()) - .alcohol(EnumAlcoholType.LOW.getCode()) - .persistence(EnumPersistenceType.SHORT.getCode()) - .maturity(EnumMaturityType.MATURE.getCode()) - .typicality(EnumTypicalityType.NOT_TYPICAL.getCode()) - .tastingCard(Mockito.mock(TastingCardOutputDTO.class)) - .build(); - } - -} +//package com.vinhonotas.bff.application.services.degustacao.impl; +// +//import com.vinhonotas.bff.application.services.exceptions.BadRequestException; +//import com.vinhonotas.bff.client.degustacao.GustatoryInspectionClient; +//import com.vinhonotas.bff.domain.enums.*; +//import com.vinhonotas.bff.interfaces.dtos.outputs.degustacao.TastingCardOutputDTO; +//import com.vinhonotas.bff.utils.MessagesConstants; +//import org.junit.jupiter.api.BeforeEach; +//import org.junit.jupiter.api.DisplayName; +//import org.junit.jupiter.api.Test; +//import org.junit.jupiter.api.extension.ExtendWith; +//import org.mockito.InjectMocks; +//import org.mockito.Mock; +//import org.mockito.Mockito; +//import org.mockito.junit.jupiter.MockitoExtension; +// +//import java.time.LocalDate; +//import java.util.List; +//import java.util.UUID; +// +//import static org.junit.jupiter.api.Assertions.*; +//import static org.mockito.Mockito.*; +// +//@ExtendWith(MockitoExtension.class) +//class GustatoryInspectionServiceImplTest { +// +// @InjectMocks +// private GustatoryInspectionServiceImpl service; +// +// @Mock +// private GustatoryInspectionClient client; +// +// private GustatoryInspectionInputDTO inputDTO; +// private GustatoryInspectionOutputDTO outputDTO; +// +// @BeforeEach +// void setUp() { +// inputDTO = createGustatoryInspectionInputDTO(); +// outputDTO = createGustatoryInspectionOutputDTO(); +// } +// +// @Test +// @DisplayName("Deve criar uma inspeção gustativa") +// void testCreate() { +// when(client.createGustatoryInspection(inputDTO)).thenReturn(outputDTO); +// +// GustatoryInspectionOutputDTO result = assertDoesNotThrow(() -> service.createGustatoryInspection(inputDTO)); +// assertNotNull(result); +// assertEquals(outputDTO.getId(), result.getId()); +// assertEquals(outputDTO.getTastingData(), result.getTastingData()); +// assertEquals(outputDTO.getWineTasted(), result.getWineTasted()); +// assertEquals(outputDTO.getBody(), result.getBody()); +// assertEquals(outputDTO.getSweetness(), result.getSweetness()); +// assertEquals(outputDTO.getTannin(), result.getTannin()); +// assertEquals(outputDTO.getClassification(), result.getClassification()); +// assertEquals(outputDTO.getAcidity(), result.getAcidity()); +// assertEquals(outputDTO.getAlcohol(), result.getAlcohol()); +// assertEquals(outputDTO.getPersistence(), result.getPersistence()); +// assertEquals(outputDTO.getMaturity(), result.getMaturity()); +// assertEquals(outputDTO.getTypicality(), result.getTypicality()); +// assertEquals(outputDTO.getTastingCard(), result.getTastingCard()); +// verify(client).createGustatoryInspection(inputDTO); +// } +// +// @Test +// @DisplayName("Deve lançar BadRequestException ao criar uma inspeção gustativa") +// void testCreateThrowBadRequestException() { +// when(client.createGustatoryInspection(inputDTO)).thenThrow(new BadRequestException(MessagesConstants.ERROR_WHEN_SAVING)); +// +// Exception exception = assertThrows(Exception.class, () -> service.createGustatoryInspection(inputDTO)); +// assertEquals(MessagesConstants.ERROR_WHEN_SAVING, exception.getMessage()); +// verify(client).createGustatoryInspection(inputDTO); +// } +// +// @Test +// @DisplayName("Deve listar todas as inspeções gustativas") +// void testGetAll() { +// when(client.getAllGustatoryInspections()).thenReturn(List.of(outputDTO)); +// +// List result = assertDoesNotThrow(() -> service.getAllGustatoryInspections()); +// assertNotNull(result); +// assertEquals(1, result.size()); +// assertEquals(outputDTO.getId(), result.get(0).getId()); +// assertEquals(outputDTO.getTastingData(), result.get(0).getTastingData()); +// assertEquals(outputDTO.getWineTasted(), result.get(0).getWineTasted()); +// assertEquals(outputDTO.getBody(), result.get(0).getBody()); +// assertEquals(outputDTO.getSweetness(), result.get(0).getSweetness()); +// assertEquals(outputDTO.getTannin(), result.get(0).getTannin()); +// assertEquals(outputDTO.getClassification(), result.get(0).getClassification()); +// assertEquals(outputDTO.getAcidity(), result.get(0).getAcidity()); +// assertEquals(outputDTO.getAlcohol(), result.get(0).getAlcohol()); +// assertEquals(outputDTO.getPersistence(), result.get(0).getPersistence()); +// assertEquals(outputDTO.getMaturity(), result.get(0).getMaturity()); +// assertEquals(outputDTO.getTypicality(), result.get(0).getTypicality()); +// assertEquals(outputDTO.getTastingCard(), result.get(0).getTastingCard()); +// verify(client).getAllGustatoryInspections(); +// } +// +// @Test +// @DisplayName("Deve lançar NotFoundException ao listar todas as inspeções gustativas") +// void testGetAllThrowNotFoundException() { +// when(client.getAllGustatoryInspections()).thenReturn(List.of()); +// +// Exception exception = assertThrows(Exception.class, () -> service.getAllGustatoryInspections()); +// assertEquals(MessagesConstants.NOT_FOUND, exception.getMessage()); +// verify(client).getAllGustatoryInspections(); +// } +// +// @Test +// @DisplayName("Deve buscar uma inspeção gustativa pelo id") +// void testGetById() { +// when(client.getGustatoryInspectionById(outputDTO.getId().toString())).thenReturn(outputDTO); +// +// GustatoryInspectionOutputDTO result = assertDoesNotThrow(() -> service.getGustatoryInspectionById(outputDTO.getId().toString())); +// assertNotNull(result); +// assertEquals(outputDTO.getId(), result.getId()); +// assertEquals(outputDTO.getTastingData(), result.getTastingData()); +// assertEquals(outputDTO.getWineTasted(), result.getWineTasted()); +// assertEquals(outputDTO.getBody(), result.getBody()); +// assertEquals(outputDTO.getSweetness(), result.getSweetness()); +// assertEquals(outputDTO.getTannin(), result.getTannin()); +// assertEquals(outputDTO.getClassification(), result.getClassification()); +// assertEquals(outputDTO.getAcidity(), result.getAcidity()); +// assertEquals(outputDTO.getAlcohol(), result.getAlcohol()); +// assertEquals(outputDTO.getPersistence(), result.getPersistence()); +// assertEquals(outputDTO.getMaturity(), result.getMaturity()); +// assertEquals(outputDTO.getTypicality(), result.getTypicality()); +// assertEquals(outputDTO.getTastingCard(), result.getTastingCard()); +// verify(client).getGustatoryInspectionById(outputDTO.getId().toString()); +// } +// +// @Test +// @DisplayName("Deve lançar NotFoundException ao buscar uma inspeção gustativa pelo id") +// void testGetByIdThrowNotFoundException() { +// when(client.getGustatoryInspectionById(outputDTO.getId().toString())).thenReturn(null); +// +// Exception exception = assertThrows(Exception.class, () -> service.getGustatoryInspectionById(outputDTO.getId().toString())); +// assertEquals(MessagesConstants.NOT_FOUND, exception.getMessage()); +// verify(client).getGustatoryInspectionById(outputDTO.getId().toString()); +// } +// +// @Test +// @DisplayName("Deve atualizar uma inspeção gustativa") +// void testUpdate() { +// when(client.updateGustatoryInspection(outputDTO.getId().toString(), inputDTO)).thenReturn(outputDTO); +// +// GustatoryInspectionOutputDTO result = assertDoesNotThrow(() -> service.updateGustatoryInspection(outputDTO.getId().toString(), inputDTO)); +// assertNotNull(result); +// assertEquals(outputDTO.getId(), result.getId()); +// assertEquals(outputDTO.getTastingData(), result.getTastingData()); +// assertEquals(outputDTO.getWineTasted(), result.getWineTasted()); +// assertEquals(outputDTO.getBody(), result.getBody()); +// assertEquals(outputDTO.getSweetness(), result.getSweetness()); +// assertEquals(outputDTO.getTannin(), result.getTannin()); +// assertEquals(outputDTO.getClassification(), result.getClassification()); +// assertEquals(outputDTO.getAcidity(), result.getAcidity()); +// assertEquals(outputDTO.getAlcohol(), result.getAlcohol()); +// assertEquals(outputDTO.getPersistence(), result.getPersistence()); +// assertEquals(outputDTO.getMaturity(), result.getMaturity()); +// assertEquals(outputDTO.getTypicality(), result.getTypicality()); +// assertEquals(outputDTO.getTastingCard(), result.getTastingCard()); +// verify(client).updateGustatoryInspection(outputDTO.getId().toString(), inputDTO); +// } +// +// @Test +// @DisplayName("Deve lançar BadRequestException ao atualizar uma inspeção gustativa") +// void testUpdateThrowBadRequestException() { +// when(client.updateGustatoryInspection(outputDTO.getId().toString(), inputDTO)).thenThrow(new BadRequestException(MessagesConstants.ERROR_WHEN_UPDATING)); +// +// Exception exception = assertThrows(Exception.class, () -> service.updateGustatoryInspection(outputDTO.getId().toString(), inputDTO)); +// assertEquals(MessagesConstants.ERROR_WHEN_UPDATING, exception.getMessage()); +// verify(client).updateGustatoryInspection(outputDTO.getId().toString(), inputDTO); +// } +// +// @Test +// @DisplayName("Deve deletar uma inspeção gustativa") +// void testDelete() { +// assertDoesNotThrow(() -> service.deleteGustatoryInspection(outputDTO.getId().toString())); +// verify(client).deleteGustatoryInspection(outputDTO.getId().toString()); +// } +// +// @Test +// @DisplayName("Deve lançar BadRequestException ao deletar uma inspeção gustativa") +// void testDeleteThrowBadRequestException() { +// doThrow(new BadRequestException(MessagesConstants.ERROR_WHEN_DELETING)) +// .when(client).deleteGustatoryInspection(outputDTO.getId().toString()); +// +// Exception exception = assertThrows(Exception.class, () -> service.deleteGustatoryInspection(outputDTO.getId().toString())); +// assertEquals(MessagesConstants.ERROR_WHEN_DELETING, exception.getMessage()); +// verify(client).deleteGustatoryInspection(outputDTO.getId().toString()); +// } +// +// private GustatoryInspectionInputDTO createGustatoryInspectionInputDTO() { +// return GustatoryInspectionInputDTO.builder() +// .tastingData(LocalDate.now()) +// .wineTasted("Wine Tasted") +// .body(EnumBodyType.FULL_BODIED.getCode()) +// .sweetness(EnumSweetnessType.VERY_DRY.getCode()) +// .tannin(EnumTanninType.LITTLE_TANIC.getCode()) +// .classification(EnumClassificationType.LITTLE.getCode()) +// .acidity(EnumAcidityType.LITTLE_ACID.getCode()) +// .alcohol(EnumAlcoholType.LOW.getCode()) +// .persistence(EnumPersistenceType.SHORT.getCode()) +// .maturity(EnumMaturityType.MATURE.getCode()) +// .typicality(EnumTypicalityType.NOT_TYPICAL.getCode()) +// .build(); +// } +// +// private GustatoryInspectionOutputDTO createGustatoryInspectionOutputDTO() { +// return GustatoryInspectionOutputDTO.builder() +// .id(UUID.fromString("f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e")) +// .tastingData(LocalDate.now()) +// .wineTasted("Wine Tasted") +// .body(EnumBodyType.FULL_BODIED.getCode()) +// .sweetness(EnumSweetnessType.VERY_DRY.getCode()) +// .tannin(EnumTanninType.LITTLE_TANIC.getCode()) +// .classification(EnumClassificationType.LITTLE.getCode()) +// .acidity(EnumAcidityType.LITTLE_ACID.getCode()) +// .alcohol(EnumAlcoholType.LOW.getCode()) +// .persistence(EnumPersistenceType.SHORT.getCode()) +// .maturity(EnumMaturityType.MATURE.getCode()) +// .typicality(EnumTypicalityType.NOT_TYPICAL.getCode()) +// .tastingCard(Mockito.mock(TastingCardOutputDTO.class)) +// .build(); +// } +// +//} diff --git a/bff/src/test/java/com/vinhonotas/bff/application/services/degustacao/impl/OlfactoryInspectionServiceImplTest.java b/bff/src/test/java/com/vinhonotas/bff/application/services/degustacao/impl/OlfactoryInspectionServiceImplTest.java index e1626b6f..30c56bd3 100644 --- a/bff/src/test/java/com/vinhonotas/bff/application/services/degustacao/impl/OlfactoryInspectionServiceImplTest.java +++ b/bff/src/test/java/com/vinhonotas/bff/application/services/degustacao/impl/OlfactoryInspectionServiceImplTest.java @@ -1,219 +1,215 @@ -package com.vinhonotas.bff.application.services.degustacao.impl; - -import com.vinhonotas.bff.application.services.exceptions.BadRequestException; -import com.vinhonotas.bff.client.degustacao.OlfactoryInspectionClient; -import com.vinhonotas.bff.domain.enums.EnumClassificationType; -import com.vinhonotas.bff.domain.enums.EnumIntensityType; -import com.vinhonotas.bff.domain.enums.EnumPersistenceType; -import com.vinhonotas.bff.domain.enums.EnumQualityType; -import com.vinhonotas.bff.interfaces.dtos.inputs.degustacao.AromasInputDTO; -import com.vinhonotas.bff.interfaces.dtos.inputs.degustacao.OlfactoryInspectionInputDTO; -import com.vinhonotas.bff.interfaces.dtos.outputs.degustacao.AromasOutputDTO; -import com.vinhonotas.bff.interfaces.dtos.outputs.degustacao.OlfactoryInspectionOutputDTO; -import com.vinhonotas.bff.utils.MessagesConstants; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.DisplayName; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; -import org.mockito.InjectMocks; -import org.mockito.Mock; -import org.mockito.Mockito; -import org.mockito.junit.jupiter.MockitoExtension; - -import java.time.LocalDate; -import java.util.List; -import java.util.UUID; - -import static org.junit.jupiter.api.Assertions.*; -import static org.mockito.Mockito.*; - -@ExtendWith(MockitoExtension.class) -class OlfactoryInspectionServiceImplTest { - - @InjectMocks - private OlfactoryInspectionServiceImpl olfactoryInspectionService; - - @Mock - private OlfactoryInspectionClient olfactoryInspectionClient; - - private OlfactoryInspectionOutputDTO olfactoryInspectionOutputDTO; - private OlfactoryInspectionInputDTO olfactoryInspectionInputDTO; - - @BeforeEach - void setUp() { - olfactoryInspectionOutputDTO = createOlfactoryInspectionOutputDTO(); - olfactoryInspectionInputDTO = createOlfactoryInspectionInputDTO(); - } - - @Test - @DisplayName("Deve criar uma inspeção olfativa") - void testCreate() { - when(olfactoryInspectionClient.createOlafactoryInspection(olfactoryInspectionInputDTO)).thenReturn(olfactoryInspectionOutputDTO); - - OlfactoryInspectionOutputDTO response = assertDoesNotThrow(() -> olfactoryInspectionService - .createOlfactoryInspection(olfactoryInspectionInputDTO)); - - assertNotNull(response); - assertEquals(olfactoryInspectionOutputDTO.getId(), response.getId()); - assertEquals(olfactoryInspectionOutputDTO.getTastingData(), response.getTastingData()); - assertEquals(olfactoryInspectionOutputDTO.getWineTasted(), response.getWineTasted()); - assertEquals(olfactoryInspectionOutputDTO.getIntensity(), response.getIntensity()); - assertEquals(olfactoryInspectionOutputDTO.getPersistence(), response.getPersistence()); - assertEquals(olfactoryInspectionOutputDTO.getQuality(), response.getQuality()); - assertEquals(olfactoryInspectionOutputDTO.getAromas(), response.getAromas()); - assertEquals(olfactoryInspectionOutputDTO.getClassification(), response.getClassification()); - verify(olfactoryInspectionClient).createOlafactoryInspection(olfactoryInspectionInputDTO); - } - - @Test - @DisplayName("Deve lançar BadRequestException ao criar uma inspeção olfativa") - void testCreateThrowBadRequestException() { - when(olfactoryInspectionClient.createOlafactoryInspection(olfactoryInspectionInputDTO)) - .thenThrow(new BadRequestException(MessagesConstants.ERROR_WHEN_SAVING)); - - Exception exception = assertThrows(Exception.class, () -> olfactoryInspectionService - .createOlfactoryInspection(olfactoryInspectionInputDTO)); - assertEquals(MessagesConstants.ERROR_WHEN_SAVING, exception.getMessage()); - verify(olfactoryInspectionClient).createOlafactoryInspection(olfactoryInspectionInputDTO); - } - - @Test - @DisplayName("Deve retornar uma lista de inspeções olfativas") - void testGetAll() { - when(olfactoryInspectionClient.getAllOlfactoryInspections()).thenReturn(List.of(olfactoryInspectionOutputDTO)); - - List list = assertDoesNotThrow(() -> olfactoryInspectionService.getAllOlfactoryInspections()); - assertNotNull(list); - assertFalse(list.isEmpty()); - assertEquals(1, list.size()); - assertEquals(olfactoryInspectionOutputDTO.getId(), list.get(0).getId()); - assertEquals(olfactoryInspectionOutputDTO.getTastingData(), list.get(0).getTastingData()); - assertEquals(olfactoryInspectionOutputDTO.getWineTasted(), list.get(0).getWineTasted()); - assertEquals(olfactoryInspectionOutputDTO.getIntensity(), list.get(0).getIntensity()); - assertEquals(olfactoryInspectionOutputDTO.getPersistence(), list.get(0).getPersistence()); - assertEquals(olfactoryInspectionOutputDTO.getQuality(), list.get(0).getQuality()); - assertEquals(olfactoryInspectionOutputDTO.getAromas(), list.get(0).getAromas()); - assertEquals(olfactoryInspectionOutputDTO.getClassification(), list.get(0).getClassification()); - verify(olfactoryInspectionClient).getAllOlfactoryInspections(); - } - - @Test - @DisplayName("Deve lançar BadRequestException ao retornar uma lista de inspeções olfativas") - void testGetAllThrowBadRequestException() { - when(olfactoryInspectionClient.getAllOlfactoryInspections()).thenReturn(List.of()); - - Exception exception = assertThrows(Exception.class, () -> olfactoryInspectionService.getAllOlfactoryInspections()); - assertEquals(MessagesConstants.NOT_FOUND, exception.getMessage()); - verify(olfactoryInspectionClient).getAllOlfactoryInspections(); - } - - @Test - @DisplayName("Deve retornar uma inspeção olfativa por id") - void testGetById() { - when(olfactoryInspectionClient.getOlfactoryInspectionById("f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e")) - .thenReturn(olfactoryInspectionOutputDTO); - - OlfactoryInspectionOutputDTO response = assertDoesNotThrow(() -> olfactoryInspectionService - .getOlfactoryInspectionById("f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e")); - assertNotNull(response); - assertEquals(olfactoryInspectionOutputDTO.getId(), response.getId()); - assertEquals(olfactoryInspectionOutputDTO.getTastingData(), response.getTastingData()); - assertEquals(olfactoryInspectionOutputDTO.getWineTasted(), response.getWineTasted()); - assertEquals(olfactoryInspectionOutputDTO.getIntensity(), response.getIntensity()); - assertEquals(olfactoryInspectionOutputDTO.getPersistence(), response.getPersistence()); - assertEquals(olfactoryInspectionOutputDTO.getQuality(), response.getQuality()); - assertEquals(olfactoryInspectionOutputDTO.getAromas(), response.getAromas()); - assertEquals(olfactoryInspectionOutputDTO.getClassification(), response.getClassification()); - verify(olfactoryInspectionClient).getOlfactoryInspectionById("f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e"); - } - - @Test - @DisplayName("Deve lançar BadRequestException ao retornar uma inspeção olfativa por id") - void testGetByIdThrowBadRequestException() { - when(olfactoryInspectionClient.getOlfactoryInspectionById("f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e")) - .thenReturn(null); - - Exception exception = assertThrows(Exception.class, () -> olfactoryInspectionService - .getOlfactoryInspectionById("f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e")); - assertEquals(MessagesConstants.NOT_FOUND, exception.getMessage()); - verify(olfactoryInspectionClient).getOlfactoryInspectionById("f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e"); - } - - @Test - @DisplayName("Deve atualizar uma inspeção olfativa") - void testUpdate() { - when(olfactoryInspectionClient.updateOlfactoryInspection("f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e", olfactoryInspectionInputDTO)) - .thenReturn(olfactoryInspectionOutputDTO); - - OlfactoryInspectionOutputDTO response = assertDoesNotThrow(() -> olfactoryInspectionService - .updateOlfactoryInspection("f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e", olfactoryInspectionInputDTO)); - assertNotNull(response); - assertEquals(olfactoryInspectionOutputDTO.getId(), response.getId()); - assertEquals(olfactoryInspectionOutputDTO.getTastingData(), response.getTastingData()); - assertEquals(olfactoryInspectionOutputDTO.getWineTasted(), response.getWineTasted()); - assertEquals(olfactoryInspectionOutputDTO.getIntensity(), response.getIntensity()); - assertEquals(olfactoryInspectionOutputDTO.getPersistence(), response.getPersistence()); - assertEquals(olfactoryInspectionOutputDTO.getQuality(), response.getQuality()); - assertEquals(olfactoryInspectionOutputDTO.getAromas(), response.getAromas()); - assertEquals(olfactoryInspectionOutputDTO.getClassification(), response.getClassification()); - verify(olfactoryInspectionClient).updateOlfactoryInspection("f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e", olfactoryInspectionInputDTO); - } - - @Test - @DisplayName("Deve lançar BadRequestException ao atualizar uma inspeção olfativa") - void testUpdateThrowBadRequestException() { - when(olfactoryInspectionClient.updateOlfactoryInspection("f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e", olfactoryInspectionInputDTO)) - .thenThrow(new BadRequestException(MessagesConstants.ERROR_WHEN_UPDATING)); - - Exception exception = assertThrows(Exception.class, () -> olfactoryInspectionService - .updateOlfactoryInspection("f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e", olfactoryInspectionInputDTO)); - assertEquals(MessagesConstants.ERROR_WHEN_UPDATING, exception.getMessage()); - verify(olfactoryInspectionClient).updateOlfactoryInspection("f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e", olfactoryInspectionInputDTO); - } - - @Test - @DisplayName("Deve deletar uma inspeção olfativa") - void testDelete() { - assertDoesNotThrow(() -> olfactoryInspectionService.deleteOlfactoryInspection("f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e")); - verify(olfactoryInspectionClient).deleteOlfactoryInspection("f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e"); - } - - @Test - @DisplayName("Deve lançar BadRequestException ao deletar uma inspeção olfativa") - void testDeleteThrowBadRequestException() { - doThrow(new BadRequestException(MessagesConstants.ERROR_WHEN_DELETING)) - .when(olfactoryInspectionClient).deleteOlfactoryInspection("f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e"); - - Exception exception = assertThrows(Exception.class, () -> olfactoryInspectionService - .deleteOlfactoryInspection("f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e")); - assertEquals(MessagesConstants.ERROR_WHEN_DELETING, exception.getMessage()); - verify(olfactoryInspectionClient).deleteOlfactoryInspection("f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e"); - - } - - private OlfactoryInspectionInputDTO createOlfactoryInspectionInputDTO() { - return OlfactoryInspectionInputDTO.builder() - .tastingData(LocalDate.now()) - .wineTasted("Wine Tasted") - .intensity(EnumIntensityType.INTENSE.getCode()) - .persistence(EnumPersistenceType.PERSISTENT.getCode()) - .quality(EnumQualityType.COMMON.getCode()) - .aromas(Mockito.mock(AromasInputDTO.class)) - .classification(EnumClassificationType.LITTLE.getCode()) - .build(); - } - - private OlfactoryInspectionOutputDTO createOlfactoryInspectionOutputDTO() { - return OlfactoryInspectionOutputDTO.builder() - .id(UUID.fromString("f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e")) - .tastingData(LocalDate.now()) - .wineTasted("Wine Tasted") - .intensity(EnumIntensityType.INTENSE.getCode()) - .persistence(EnumPersistenceType.PERSISTENT.getCode()) - .quality(EnumQualityType.COMMON.getCode()) - .aromas(Mockito.mock(AromasOutputDTO.class)) - .classification(EnumClassificationType.LITTLE.getCode()) - .build(); - } - -} \ No newline at end of file +//package com.vinhonotas.bff.application.services.degustacao.impl; +// +//import com.vinhonotas.bff.application.services.exceptions.BadRequestException; +//import com.vinhonotas.bff.client.degustacao.OlfactoryInspectionClient; +//import com.vinhonotas.bff.domain.enums.EnumClassificationType; +//import com.vinhonotas.bff.domain.enums.EnumIntensityType; +//import com.vinhonotas.bff.domain.enums.EnumPersistenceType; +//import com.vinhonotas.bff.domain.enums.EnumQualityType; +//import com.vinhonotas.bff.utils.MessagesConstants; +//import org.junit.jupiter.api.BeforeEach; +//import org.junit.jupiter.api.DisplayName; +//import org.junit.jupiter.api.Test; +//import org.junit.jupiter.api.extension.ExtendWith; +//import org.mockito.InjectMocks; +//import org.mockito.Mock; +//import org.mockito.Mockito; +//import org.mockito.junit.jupiter.MockitoExtension; +// +//import java.time.LocalDate; +//import java.util.List; +//import java.util.UUID; +// +//import static org.junit.jupiter.api.Assertions.*; +//import static org.mockito.Mockito.*; +// +//@ExtendWith(MockitoExtension.class) +//class OlfactoryInspectionServiceImplTest { +// +// @InjectMocks +// private OlfactoryInspectionServiceImpl olfactoryInspectionService; +// +// @Mock +// private OlfactoryInspectionClient olfactoryInspectionClient; +// +// private OlfactoryInspectionOutputDTO olfactoryInspectionOutputDTO; +// private OlfactoryInspectionInputDTO olfactoryInspectionInputDTO; +// +// @BeforeEach +// void setUp() { +// olfactoryInspectionOutputDTO = createOlfactoryInspectionOutputDTO(); +// olfactoryInspectionInputDTO = createOlfactoryInspectionInputDTO(); +// } +// +// @Test +// @DisplayName("Deve criar uma inspeção olfativa") +// void testCreate() { +// when(olfactoryInspectionClient.createOlafactoryInspection(olfactoryInspectionInputDTO)).thenReturn(olfactoryInspectionOutputDTO); +// +// OlfactoryInspectionOutputDTO response = assertDoesNotThrow(() -> olfactoryInspectionService +// .createOlfactoryInspection(olfactoryInspectionInputDTO)); +// +// assertNotNull(response); +// assertEquals(olfactoryInspectionOutputDTO.getId(), response.getId()); +// assertEquals(olfactoryInspectionOutputDTO.getTastingData(), response.getTastingData()); +// assertEquals(olfactoryInspectionOutputDTO.getWineTasted(), response.getWineTasted()); +// assertEquals(olfactoryInspectionOutputDTO.getIntensity(), response.getIntensity()); +// assertEquals(olfactoryInspectionOutputDTO.getPersistence(), response.getPersistence()); +// assertEquals(olfactoryInspectionOutputDTO.getQuality(), response.getQuality()); +// assertEquals(olfactoryInspectionOutputDTO.getAromas(), response.getAromas()); +// assertEquals(olfactoryInspectionOutputDTO.getClassification(), response.getClassification()); +// verify(olfactoryInspectionClient).createOlafactoryInspection(olfactoryInspectionInputDTO); +// } +// +// @Test +// @DisplayName("Deve lançar BadRequestException ao criar uma inspeção olfativa") +// void testCreateThrowBadRequestException() { +// when(olfactoryInspectionClient.createOlafactoryInspection(olfactoryInspectionInputDTO)) +// .thenThrow(new BadRequestException(MessagesConstants.ERROR_WHEN_SAVING)); +// +// Exception exception = assertThrows(Exception.class, () -> olfactoryInspectionService +// .createOlfactoryInspection(olfactoryInspectionInputDTO)); +// assertEquals(MessagesConstants.ERROR_WHEN_SAVING, exception.getMessage()); +// verify(olfactoryInspectionClient).createOlafactoryInspection(olfactoryInspectionInputDTO); +// } +// +// @Test +// @DisplayName("Deve retornar uma lista de inspeções olfativas") +// void testGetAll() { +// when(olfactoryInspectionClient.getAllOlfactoryInspections()).thenReturn(List.of(olfactoryInspectionOutputDTO)); +// +// List list = assertDoesNotThrow(() -> olfactoryInspectionService.getAllOlfactoryInspections()); +// assertNotNull(list); +// assertFalse(list.isEmpty()); +// assertEquals(1, list.size()); +// assertEquals(olfactoryInspectionOutputDTO.getId(), list.get(0).getId()); +// assertEquals(olfactoryInspectionOutputDTO.getTastingData(), list.get(0).getTastingData()); +// assertEquals(olfactoryInspectionOutputDTO.getWineTasted(), list.get(0).getWineTasted()); +// assertEquals(olfactoryInspectionOutputDTO.getIntensity(), list.get(0).getIntensity()); +// assertEquals(olfactoryInspectionOutputDTO.getPersistence(), list.get(0).getPersistence()); +// assertEquals(olfactoryInspectionOutputDTO.getQuality(), list.get(0).getQuality()); +// assertEquals(olfactoryInspectionOutputDTO.getAromas(), list.get(0).getAromas()); +// assertEquals(olfactoryInspectionOutputDTO.getClassification(), list.get(0).getClassification()); +// verify(olfactoryInspectionClient).getAllOlfactoryInspections(); +// } +// +// @Test +// @DisplayName("Deve lançar BadRequestException ao retornar uma lista de inspeções olfativas") +// void testGetAllThrowBadRequestException() { +// when(olfactoryInspectionClient.getAllOlfactoryInspections()).thenReturn(List.of()); +// +// Exception exception = assertThrows(Exception.class, () -> olfactoryInspectionService.getAllOlfactoryInspections()); +// assertEquals(MessagesConstants.NOT_FOUND, exception.getMessage()); +// verify(olfactoryInspectionClient).getAllOlfactoryInspections(); +// } +// +// @Test +// @DisplayName("Deve retornar uma inspeção olfativa por id") +// void testGetById() { +// when(olfactoryInspectionClient.getOlfactoryInspectionById("f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e")) +// .thenReturn(olfactoryInspectionOutputDTO); +// +// OlfactoryInspectionOutputDTO response = assertDoesNotThrow(() -> olfactoryInspectionService +// .getOlfactoryInspectionById("f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e")); +// assertNotNull(response); +// assertEquals(olfactoryInspectionOutputDTO.getId(), response.getId()); +// assertEquals(olfactoryInspectionOutputDTO.getTastingData(), response.getTastingData()); +// assertEquals(olfactoryInspectionOutputDTO.getWineTasted(), response.getWineTasted()); +// assertEquals(olfactoryInspectionOutputDTO.getIntensity(), response.getIntensity()); +// assertEquals(olfactoryInspectionOutputDTO.getPersistence(), response.getPersistence()); +// assertEquals(olfactoryInspectionOutputDTO.getQuality(), response.getQuality()); +// assertEquals(olfactoryInspectionOutputDTO.getAromas(), response.getAromas()); +// assertEquals(olfactoryInspectionOutputDTO.getClassification(), response.getClassification()); +// verify(olfactoryInspectionClient).getOlfactoryInspectionById("f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e"); +// } +// +// @Test +// @DisplayName("Deve lançar BadRequestException ao retornar uma inspeção olfativa por id") +// void testGetByIdThrowBadRequestException() { +// when(olfactoryInspectionClient.getOlfactoryInspectionById("f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e")) +// .thenReturn(null); +// +// Exception exception = assertThrows(Exception.class, () -> olfactoryInspectionService +// .getOlfactoryInspectionById("f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e")); +// assertEquals(MessagesConstants.NOT_FOUND, exception.getMessage()); +// verify(olfactoryInspectionClient).getOlfactoryInspectionById("f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e"); +// } +// +// @Test +// @DisplayName("Deve atualizar uma inspeção olfativa") +// void testUpdate() { +// when(olfactoryInspectionClient.updateOlfactoryInspection("f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e", olfactoryInspectionInputDTO)) +// .thenReturn(olfactoryInspectionOutputDTO); +// +// OlfactoryInspectionOutputDTO response = assertDoesNotThrow(() -> olfactoryInspectionService +// .updateOlfactoryInspection("f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e", olfactoryInspectionInputDTO)); +// assertNotNull(response); +// assertEquals(olfactoryInspectionOutputDTO.getId(), response.getId()); +// assertEquals(olfactoryInspectionOutputDTO.getTastingData(), response.getTastingData()); +// assertEquals(olfactoryInspectionOutputDTO.getWineTasted(), response.getWineTasted()); +// assertEquals(olfactoryInspectionOutputDTO.getIntensity(), response.getIntensity()); +// assertEquals(olfactoryInspectionOutputDTO.getPersistence(), response.getPersistence()); +// assertEquals(olfactoryInspectionOutputDTO.getQuality(), response.getQuality()); +// assertEquals(olfactoryInspectionOutputDTO.getAromas(), response.getAromas()); +// assertEquals(olfactoryInspectionOutputDTO.getClassification(), response.getClassification()); +// verify(olfactoryInspectionClient).updateOlfactoryInspection("f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e", olfactoryInspectionInputDTO); +// } +// +// @Test +// @DisplayName("Deve lançar BadRequestException ao atualizar uma inspeção olfativa") +// void testUpdateThrowBadRequestException() { +// when(olfactoryInspectionClient.updateOlfactoryInspection("f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e", olfactoryInspectionInputDTO)) +// .thenThrow(new BadRequestException(MessagesConstants.ERROR_WHEN_UPDATING)); +// +// Exception exception = assertThrows(Exception.class, () -> olfactoryInspectionService +// .updateOlfactoryInspection("f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e", olfactoryInspectionInputDTO)); +// assertEquals(MessagesConstants.ERROR_WHEN_UPDATING, exception.getMessage()); +// verify(olfactoryInspectionClient).updateOlfactoryInspection("f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e", olfactoryInspectionInputDTO); +// } +// +// @Test +// @DisplayName("Deve deletar uma inspeção olfativa") +// void testDelete() { +// assertDoesNotThrow(() -> olfactoryInspectionService.deleteOlfactoryInspection("f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e")); +// verify(olfactoryInspectionClient).deleteOlfactoryInspection("f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e"); +// } +// +// @Test +// @DisplayName("Deve lançar BadRequestException ao deletar uma inspeção olfativa") +// void testDeleteThrowBadRequestException() { +// doThrow(new BadRequestException(MessagesConstants.ERROR_WHEN_DELETING)) +// .when(olfactoryInspectionClient).deleteOlfactoryInspection("f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e"); +// +// Exception exception = assertThrows(Exception.class, () -> olfactoryInspectionService +// .deleteOlfactoryInspection("f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e")); +// assertEquals(MessagesConstants.ERROR_WHEN_DELETING, exception.getMessage()); +// verify(olfactoryInspectionClient).deleteOlfactoryInspection("f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e"); +// +// } +// +// private OlfactoryInspectionInputDTO createOlfactoryInspectionInputDTO() { +// return OlfactoryInspectionInputDTO.builder() +// .tastingData(LocalDate.now()) +// .wineTasted("Wine Tasted") +// .intensity(EnumIntensityType.INTENSE.getCode()) +// .persistence(EnumPersistenceType.PERSISTENT.getCode()) +// .quality(EnumQualityType.COMMON.getCode()) +// .aromas(Mockito.mock(AromasInputDTO.class)) +// .classification(EnumClassificationType.LITTLE.getCode()) +// .build(); +// } +// +// private OlfactoryInspectionOutputDTO createOlfactoryInspectionOutputDTO() { +// return OlfactoryInspectionOutputDTO.builder() +// .id(UUID.fromString("f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e")) +// .tastingData(LocalDate.now()) +// .wineTasted("Wine Tasted") +// .intensity(EnumIntensityType.INTENSE.getCode()) +// .persistence(EnumPersistenceType.PERSISTENT.getCode()) +// .quality(EnumQualityType.COMMON.getCode()) +// .aromas(Mockito.mock(AromasOutputDTO.class)) +// .classification(EnumClassificationType.LITTLE.getCode()) +// .build(); +// } +// +//} \ No newline at end of file diff --git a/bff/src/test/java/com/vinhonotas/bff/application/services/degustacao/impl/TastingCardServiceImplTest.java b/bff/src/test/java/com/vinhonotas/bff/application/services/degustacao/impl/TastingCardServiceImplTest.java index 3f1f2e66..4b48668f 100644 --- a/bff/src/test/java/com/vinhonotas/bff/application/services/degustacao/impl/TastingCardServiceImplTest.java +++ b/bff/src/test/java/com/vinhonotas/bff/application/services/degustacao/impl/TastingCardServiceImplTest.java @@ -1,229 +1,223 @@ -package com.vinhonotas.bff.application.services.degustacao.impl; - -import com.vinhonotas.bff.application.services.exceptions.BadRequestException; -import com.vinhonotas.bff.client.degustacao.TastingCardClient; -import com.vinhonotas.bff.domain.enums.EnumPointScale; -import com.vinhonotas.bff.interfaces.dtos.inputs.degustacao.GustatoryInspectionInputDTO; -import com.vinhonotas.bff.interfaces.dtos.inputs.degustacao.OlfactoryInspectionInputDTO; -import com.vinhonotas.bff.interfaces.dtos.inputs.degustacao.TastingCardInputDTO; -import com.vinhonotas.bff.interfaces.dtos.inputs.degustacao.VisualInspectionInputDTO; -import com.vinhonotas.bff.interfaces.dtos.outputs.degustacao.GustatoryInspectionOutputDTO; -import com.vinhonotas.bff.interfaces.dtos.outputs.degustacao.OlfactoryInspectionOutputDTO; -import com.vinhonotas.bff.interfaces.dtos.outputs.degustacao.TastingCardOutputDTO; -import com.vinhonotas.bff.interfaces.dtos.outputs.degustacao.VisualInspectionOutputDTO; -import com.vinhonotas.bff.utils.MessagesConstants; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.DisplayName; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; -import org.mockito.InjectMocks; -import org.mockito.Mock; -import org.mockito.Mockito; -import org.mockito.junit.jupiter.MockitoExtension; - -import java.time.LocalDate; -import java.util.List; -import java.util.UUID; - -import static org.junit.jupiter.api.Assertions.*; -import static org.mockito.Mockito.*; - -@ExtendWith(MockitoExtension.class) -class TastingCardServiceImplTest { - - @InjectMocks - private TastingCardServiceImpl service; - - @Mock - private TastingCardClient client; - - private TastingCardInputDTO inputDTO; - private TastingCardOutputDTO outputDTO; - - @BeforeEach - void setUp() { - inputDTO = createTastingCardInputDTO(); - outputDTO = createTastingCardOutputDTO(); - } - - @Test - @DisplayName("Deve criar uma ficha de degustação") - void testCreateTastingCard() { - when(client.createTastingCard(inputDTO)).thenReturn(outputDTO); - - TastingCardOutputDTO result = assertDoesNotThrow(() -> service.createTastingCard(inputDTO)); - assertNotNull(result); - assertEquals(outputDTO.getId(), result.getId()); - assertEquals(outputDTO.getTastingData(), result.getTastingData()); - assertEquals(outputDTO.getWineTasted(), result.getWineTasted()); - assertEquals(outputDTO.getHarvest(), result.getHarvest()); - assertEquals(outputDTO.getGrapes(), result.getGrapes()); - assertEquals(outputDTO.getCountry(), result.getCountry()); - assertEquals(outputDTO.getRegion(), result.getRegion()); - assertEquals(outputDTO.getVisualInspection(), result.getVisualInspection()); - assertEquals(outputDTO.getOlfactoryInspection(), result.getOlfactoryInspection()); - assertEquals(outputDTO.getGustatoryInspection(), result.getGustatoryInspection()); - assertEquals(outputDTO.getOpinion(), result.getOpinion()); - assertEquals(outputDTO.getPointScale(), result.getPointScale()); - verify(client).createTastingCard(inputDTO); - } - - @Test - @DisplayName("Deve lançar BadRequestException ao tentar criar uma ficha de degustação") - void testCreateTastingCardThrowBadRequestException() { - when(client.createTastingCard(inputDTO)).thenThrow(new BadRequestException(MessagesConstants.ERROR_WHEN_SAVING)); - - BadRequestException exception = assertThrows(BadRequestException.class, () -> service.createTastingCard(inputDTO)); - assertEquals(MessagesConstants.ERROR_WHEN_SAVING, exception.getMessage()); - verify(client).createTastingCard(inputDTO); - } - - @Test - @DisplayName("Deve listar todas as fichas de degustação") - void testGetAllTastingCards() { - when(client.getAllTastingCards()).thenReturn(List.of(outputDTO)); - - List result = assertDoesNotThrow(() -> service.getAllTastingCards()); - assertNotNull(result); - assertFalse(result.isEmpty()); - assertEquals(1, result.size()); - assertEquals(outputDTO.getId(), result.get(0).getId()); - assertEquals(outputDTO.getTastingData(), result.get(0).getTastingData()); - assertEquals(outputDTO.getWineTasted(), result.get(0).getWineTasted()); - assertEquals(outputDTO.getHarvest(), result.get(0).getHarvest()); - assertEquals(outputDTO.getGrapes(), result.get(0).getGrapes()); - assertEquals(outputDTO.getCountry(), result.get(0).getCountry()); - assertEquals(outputDTO.getRegion(), result.get(0).getRegion()); - assertEquals(outputDTO.getVisualInspection(), result.get(0).getVisualInspection()); - assertEquals(outputDTO.getOlfactoryInspection(), result.get(0).getOlfactoryInspection()); - assertEquals(outputDTO.getGustatoryInspection(), result.get(0).getGustatoryInspection()); - assertEquals(outputDTO.getOpinion(), result.get(0).getOpinion()); - assertEquals(outputDTO.getPointScale(), result.get(0).getPointScale()); - verify(client).getAllTastingCards(); - } - - @Test - @DisplayName("Deve lançar BadRequestException ao tentar listar todas as fichas de degustação") - void testGetAllTastingCardsThrowBadRequestException() { - when(client.getAllTastingCards()).thenThrow(new BadRequestException(MessagesConstants.NOT_FOUND)); - - BadRequestException exception = assertThrows(BadRequestException.class, () -> service.getAllTastingCards()); - assertEquals(MessagesConstants.NOT_FOUND, exception.getMessage()); - verify(client).getAllTastingCards(); - } - - @Test - @DisplayName("Deve buscar uma ficha de degustação pelo id") - void testGetTastingCardById() { - when(client.getTastingCardById("f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e")).thenReturn(outputDTO); - - TastingCardOutputDTO result = assertDoesNotThrow(() -> service.getTastingCardById("f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e")); - assertNotNull(result); - assertEquals(outputDTO.getId(), result.getId()); - assertEquals(outputDTO.getTastingData(), result.getTastingData()); - assertEquals(outputDTO.getWineTasted(), result.getWineTasted()); - assertEquals(outputDTO.getHarvest(), result.getHarvest()); - assertEquals(outputDTO.getGrapes(), result.getGrapes()); - assertEquals(outputDTO.getCountry(), result.getCountry()); - assertEquals(outputDTO.getRegion(), result.getRegion()); - assertEquals(outputDTO.getVisualInspection(), result.getVisualInspection()); - assertEquals(outputDTO.getOlfactoryInspection(), result.getOlfactoryInspection()); - assertEquals(outputDTO.getGustatoryInspection(), result.getGustatoryInspection()); - assertEquals(outputDTO.getOpinion(), result.getOpinion()); - assertEquals(outputDTO.getPointScale(), result.getPointScale()); - verify(client).getTastingCardById("f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e"); - } - - @Test - @DisplayName("Deve lançar BadRequestException ao tentar buscar uma ficha de degustação pelo id") - void testGetTastingCardByIdThrowBadRequestException() { - when(client.getTastingCardById("f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e")).thenThrow(new BadRequestException(MessagesConstants.NOT_FOUND)); - - BadRequestException exception = assertThrows(BadRequestException.class, () -> service.getTastingCardById("f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e")); - assertEquals(MessagesConstants.NOT_FOUND, exception.getMessage()); - verify(client).getTastingCardById("f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e"); - } - - @Test - @DisplayName("Deve atualizar uma ficha de degustação pelo id") - void testUpdateTastingCard() { - when(client.updateTastingCard("f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e", inputDTO)).thenReturn(outputDTO); - - TastingCardOutputDTO result = assertDoesNotThrow(() -> service.updateTastingCard("f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e", inputDTO)); - assertNotNull(result); - assertEquals(outputDTO.getId(), result.getId()); - assertEquals(outputDTO.getTastingData(), result.getTastingData()); - assertEquals(outputDTO.getWineTasted(), result.getWineTasted()); - assertEquals(outputDTO.getHarvest(), result.getHarvest()); - assertEquals(outputDTO.getGrapes(), result.getGrapes()); - assertEquals(outputDTO.getCountry(), result.getCountry()); - assertEquals(outputDTO.getRegion(), result.getRegion()); - assertEquals(outputDTO.getVisualInspection(), result.getVisualInspection()); - assertEquals(outputDTO.getOlfactoryInspection(), result.getOlfactoryInspection()); - assertEquals(outputDTO.getGustatoryInspection(), result.getGustatoryInspection()); - assertEquals(outputDTO.getOpinion(), result.getOpinion()); - assertEquals(outputDTO.getPointScale(), result.getPointScale()); - verify(client).updateTastingCard("f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e", inputDTO); - } - - @Test - @DisplayName("Deve lançar BadRequestException ao tentar atualizar uma ficha de degustação pelo id") - void testUpdateTastingCardThrowBadRequestException() { - when(client.updateTastingCard("f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e", inputDTO)).thenThrow(new BadRequestException(MessagesConstants.ERROR_WHEN_UPDATING)); - - BadRequestException exception = assertThrows(BadRequestException.class, () -> service.updateTastingCard("f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e", inputDTO)); - assertEquals(MessagesConstants.ERROR_WHEN_UPDATING, exception.getMessage()); - verify(client).updateTastingCard("f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e", inputDTO); - } - - @Test - @DisplayName("Deve deletar uma ficha de degustação pelo id") - void testDeleteTastingCard() { - assertDoesNotThrow(() -> service.deleteTastingCard("f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e")); - verify(client).deleteTastingCard("f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e"); - } - - @Test - @DisplayName("Deve lançar BadRequestException ao tentar deletar uma ficha de degustação pelo id") - void testDeleteTastingCardThrowBadRequestException() { - doThrow(new BadRequestException(MessagesConstants.ERROR_WHEN_DELETING)).when(client).deleteTastingCard("f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e"); - - BadRequestException exception = assertThrows(BadRequestException.class, () -> service.deleteTastingCard("f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e")); - assertEquals(MessagesConstants.ERROR_WHEN_DELETING, exception.getMessage()); - verify(client).deleteTastingCard("f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e"); - } - - private TastingCardInputDTO createTastingCardInputDTO() { - return TastingCardInputDTO.builder() - .tastingData(LocalDate.now()) - .wineTasted("Wine Tasted") - .harvest("2020") - .grapes("Grapes") - .country("Chile") - .region("Vale Central") - .visualInspection(Mockito.mock(VisualInspectionInputDTO.class)) - .olfactoryInspection(Mockito.mock(OlfactoryInspectionInputDTO.class)) - .gustatoryInspection(Mockito.mock(GustatoryInspectionInputDTO.class)) - .opinion("Opinion about the wine") - .pointScale(EnumPointScale.CLASSIC.getCode()) - .build(); - } - - private TastingCardOutputDTO createTastingCardOutputDTO() { - return TastingCardOutputDTO.builder() - .id(UUID.fromString("f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e")) - .tastingData(LocalDate.now()) - .wineTasted("Wine Tasted") - .harvest("2020") - .grapes("Grapes") - .country("Chile") - .region("Vale Central") - .visualInspection(Mockito.mock(VisualInspectionOutputDTO.class)) - .olfactoryInspection(Mockito.mock(OlfactoryInspectionOutputDTO.class)) - .gustatoryInspection(Mockito.mock(GustatoryInspectionOutputDTO.class)) - .opinion("Opinion about the wine") - .pointScale(EnumPointScale.CLASSIC.getCode()) - .build(); - } - -} \ No newline at end of file +//package com.vinhonotas.bff.application.services.degustacao.impl; +// +//import com.vinhonotas.bff.application.services.exceptions.BadRequestException; +//import com.vinhonotas.bff.client.degustacao.TastingCardClient; +//import com.vinhonotas.bff.domain.enums.EnumPointScale; +//import com.vinhonotas.bff.interfaces.dtos.inputs.degustacao.TastingCardInputDTO; +//import com.vinhonotas.bff.interfaces.dtos.outputs.degustacao.TastingCardOutputDTO; +//import com.vinhonotas.bff.utils.MessagesConstants; +//import org.junit.jupiter.api.BeforeEach; +//import org.junit.jupiter.api.DisplayName; +//import org.junit.jupiter.api.Test; +//import org.junit.jupiter.api.extension.ExtendWith; +//import org.mockito.InjectMocks; +//import org.mockito.Mock; +//import org.mockito.Mockito; +//import org.mockito.junit.jupiter.MockitoExtension; +// +//import java.time.LocalDate; +//import java.util.List; +//import java.util.UUID; +// +//import static org.junit.jupiter.api.Assertions.*; +//import static org.mockito.Mockito.*; +// +//@ExtendWith(MockitoExtension.class) +//class TastingCardServiceImplTest { +// +// @InjectMocks +// private TastingCardServiceImpl service; +// +// @Mock +// private TastingCardClient client; +// +// private TastingCardInputDTO inputDTO; +// private TastingCardOutputDTO outputDTO; +// +// @BeforeEach +// void setUp() { +// inputDTO = createTastingCardInputDTO(); +// outputDTO = createTastingCardOutputDTO(); +// } +// +// @Test +// @DisplayName("Deve criar uma ficha de degustação") +// void testCreateTastingCard() { +// when(client.createTastingCard(inputDTO)).thenReturn(outputDTO); +// +// TastingCardOutputDTO result = assertDoesNotThrow(() -> service.createTastingCard(inputDTO)); +// assertNotNull(result); +// assertEquals(outputDTO.getId(), result.getId()); +// assertEquals(outputDTO.getTastingData(), result.getTastingData()); +// assertEquals(outputDTO.getWineTasted(), result.getWineTasted()); +// assertEquals(outputDTO.getHarvest(), result.getHarvest()); +// assertEquals(outputDTO.getGrapes(), result.getGrapes()); +// assertEquals(outputDTO.getCountry(), result.getCountry()); +// assertEquals(outputDTO.getRegion(), result.getRegion()); +// assertEquals(outputDTO.getVisualInspection(), result.getVisualInspection()); +// assertEquals(outputDTO.getOlfactoryInspection(), result.getOlfactoryInspection()); +// assertEquals(outputDTO.getGustatoryInspection(), result.getGustatoryInspection()); +// assertEquals(outputDTO.getOpinion(), result.getOpinion()); +// assertEquals(outputDTO.getPointScale(), result.getPointScale()); +// verify(client).createTastingCard(inputDTO); +// } +// +// @Test +// @DisplayName("Deve lançar BadRequestException ao tentar criar uma ficha de degustação") +// void testCreateTastingCardThrowBadRequestException() { +// when(client.createTastingCard(inputDTO)).thenThrow(new BadRequestException(MessagesConstants.ERROR_WHEN_SAVING)); +// +// BadRequestException exception = assertThrows(BadRequestException.class, () -> service.createTastingCard(inputDTO)); +// assertEquals(MessagesConstants.ERROR_WHEN_SAVING, exception.getMessage()); +// verify(client).createTastingCard(inputDTO); +// } +// +// @Test +// @DisplayName("Deve listar todas as fichas de degustação") +// void testGetAllTastingCards() { +// when(client.getAllTastingCards()).thenReturn(List.of(outputDTO)); +// +// List result = assertDoesNotThrow(() -> service.getAllTastingCards()); +// assertNotNull(result); +// assertFalse(result.isEmpty()); +// assertEquals(1, result.size()); +// assertEquals(outputDTO.getId(), result.get(0).getId()); +// assertEquals(outputDTO.getTastingData(), result.get(0).getTastingData()); +// assertEquals(outputDTO.getWineTasted(), result.get(0).getWineTasted()); +// assertEquals(outputDTO.getHarvest(), result.get(0).getHarvest()); +// assertEquals(outputDTO.getGrapes(), result.get(0).getGrapes()); +// assertEquals(outputDTO.getCountry(), result.get(0).getCountry()); +// assertEquals(outputDTO.getRegion(), result.get(0).getRegion()); +// assertEquals(outputDTO.getVisualInspection(), result.get(0).getVisualInspection()); +// assertEquals(outputDTO.getOlfactoryInspection(), result.get(0).getOlfactoryInspection()); +// assertEquals(outputDTO.getGustatoryInspection(), result.get(0).getGustatoryInspection()); +// assertEquals(outputDTO.getOpinion(), result.get(0).getOpinion()); +// assertEquals(outputDTO.getPointScale(), result.get(0).getPointScale()); +// verify(client).getAllTastingCards(); +// } +// +// @Test +// @DisplayName("Deve lançar BadRequestException ao tentar listar todas as fichas de degustação") +// void testGetAllTastingCardsThrowBadRequestException() { +// when(client.getAllTastingCards()).thenThrow(new BadRequestException(MessagesConstants.NOT_FOUND)); +// +// BadRequestException exception = assertThrows(BadRequestException.class, () -> service.getAllTastingCards()); +// assertEquals(MessagesConstants.NOT_FOUND, exception.getMessage()); +// verify(client).getAllTastingCards(); +// } +// +// @Test +// @DisplayName("Deve buscar uma ficha de degustação pelo id") +// void testGetTastingCardById() { +// when(client.getTastingCardById("f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e")).thenReturn(outputDTO); +// +// TastingCardOutputDTO result = assertDoesNotThrow(() -> service.getTastingCardById("f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e")); +// assertNotNull(result); +// assertEquals(outputDTO.getId(), result.getId()); +// assertEquals(outputDTO.getTastingData(), result.getTastingData()); +// assertEquals(outputDTO.getWineTasted(), result.getWineTasted()); +// assertEquals(outputDTO.getHarvest(), result.getHarvest()); +// assertEquals(outputDTO.getGrapes(), result.getGrapes()); +// assertEquals(outputDTO.getCountry(), result.getCountry()); +// assertEquals(outputDTO.getRegion(), result.getRegion()); +// assertEquals(outputDTO.getVisualInspection(), result.getVisualInspection()); +// assertEquals(outputDTO.getOlfactoryInspection(), result.getOlfactoryInspection()); +// assertEquals(outputDTO.getGustatoryInspection(), result.getGustatoryInspection()); +// assertEquals(outputDTO.getOpinion(), result.getOpinion()); +// assertEquals(outputDTO.getPointScale(), result.getPointScale()); +// verify(client).getTastingCardById("f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e"); +// } +// +// @Test +// @DisplayName("Deve lançar BadRequestException ao tentar buscar uma ficha de degustação pelo id") +// void testGetTastingCardByIdThrowBadRequestException() { +// when(client.getTastingCardById("f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e")).thenThrow(new BadRequestException(MessagesConstants.NOT_FOUND)); +// +// BadRequestException exception = assertThrows(BadRequestException.class, () -> service.getTastingCardById("f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e")); +// assertEquals(MessagesConstants.NOT_FOUND, exception.getMessage()); +// verify(client).getTastingCardById("f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e"); +// } +// +// @Test +// @DisplayName("Deve atualizar uma ficha de degustação pelo id") +// void testUpdateTastingCard() { +// when(client.updateTastingCard("f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e", inputDTO)).thenReturn(outputDTO); +// +// TastingCardOutputDTO result = assertDoesNotThrow(() -> service.updateTastingCard("f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e", inputDTO)); +// assertNotNull(result); +// assertEquals(outputDTO.getId(), result.getId()); +// assertEquals(outputDTO.getTastingData(), result.getTastingData()); +// assertEquals(outputDTO.getWineTasted(), result.getWineTasted()); +// assertEquals(outputDTO.getHarvest(), result.getHarvest()); +// assertEquals(outputDTO.getGrapes(), result.getGrapes()); +// assertEquals(outputDTO.getCountry(), result.getCountry()); +// assertEquals(outputDTO.getRegion(), result.getRegion()); +// assertEquals(outputDTO.getVisualInspection(), result.getVisualInspection()); +// assertEquals(outputDTO.getOlfactoryInspection(), result.getOlfactoryInspection()); +// assertEquals(outputDTO.getGustatoryInspection(), result.getGustatoryInspection()); +// assertEquals(outputDTO.getOpinion(), result.getOpinion()); +// assertEquals(outputDTO.getPointScale(), result.getPointScale()); +// verify(client).updateTastingCard("f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e", inputDTO); +// } +// +// @Test +// @DisplayName("Deve lançar BadRequestException ao tentar atualizar uma ficha de degustação pelo id") +// void testUpdateTastingCardThrowBadRequestException() { +// when(client.updateTastingCard("f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e", inputDTO)).thenThrow(new BadRequestException(MessagesConstants.ERROR_WHEN_UPDATING)); +// +// BadRequestException exception = assertThrows(BadRequestException.class, () -> service.updateTastingCard("f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e", inputDTO)); +// assertEquals(MessagesConstants.ERROR_WHEN_UPDATING, exception.getMessage()); +// verify(client).updateTastingCard("f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e", inputDTO); +// } +// +// @Test +// @DisplayName("Deve deletar uma ficha de degustação pelo id") +// void testDeleteTastingCard() { +// assertDoesNotThrow(() -> service.deleteTastingCard("f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e")); +// verify(client).deleteTastingCard("f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e"); +// } +// +// @Test +// @DisplayName("Deve lançar BadRequestException ao tentar deletar uma ficha de degustação pelo id") +// void testDeleteTastingCardThrowBadRequestException() { +// doThrow(new BadRequestException(MessagesConstants.ERROR_WHEN_DELETING)).when(client).deleteTastingCard("f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e"); +// +// BadRequestException exception = assertThrows(BadRequestException.class, () -> service.deleteTastingCard("f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e")); +// assertEquals(MessagesConstants.ERROR_WHEN_DELETING, exception.getMessage()); +// verify(client).deleteTastingCard("f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e"); +// } +// +// private TastingCardInputDTO createTastingCardInputDTO() { +// return TastingCardInputDTO.builder() +// .tastingData(LocalDate.now()) +// .wineTasted("Wine Tasted") +// .harvest("2020") +// .grapes("Grapes") +// .country("Chile") +// .region("Vale Central") +// .visualInspection(Mockito.mock(VisualInspectionInputDTO.class)) +// .olfactoryInspection(Mockito.mock(OlfactoryInspectionInputDTO.class)) +// .gustatoryInspection(Mockito.mock(GustatoryInspectionInputDTO.class)) +// .opinion("Opinion about the wine") +// .pointScale(EnumPointScale.CLASSIC.getCode()) +// .build(); +// } +// +// private TastingCardOutputDTO createTastingCardOutputDTO() { +// return TastingCardOutputDTO.builder() +// .id(UUID.fromString("f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e")) +// .tastingData(LocalDate.now()) +// .wineTasted("Wine Tasted") +// .harvest("2020") +// .grapes("Grapes") +// .country("Chile") +// .region("Vale Central") +// .visualInspection(Mockito.mock(VisualInspectionOutputDTO.class)) +// .olfactoryInspection(Mockito.mock(OlfactoryInspectionOutputDTO.class)) +// .gustatoryInspection(Mockito.mock(GustatoryInspectionOutputDTO.class)) +// .opinion("Opinion about the wine") +// .pointScale(EnumPointScale.CLASSIC.getCode()) +// .build(); +// } +// +//} \ No newline at end of file diff --git a/bff/src/test/java/com/vinhonotas/bff/application/services/degustacao/impl/TastingServiceImplTest.java b/bff/src/test/java/com/vinhonotas/bff/application/services/degustacao/impl/TastingServiceImplTest.java index e5d227d1..856a47c4 100644 --- a/bff/src/test/java/com/vinhonotas/bff/application/services/degustacao/impl/TastingServiceImplTest.java +++ b/bff/src/test/java/com/vinhonotas/bff/application/services/degustacao/impl/TastingServiceImplTest.java @@ -1,182 +1,180 @@ -package com.vinhonotas.bff.application.services.degustacao.impl; - -import com.vinhonotas.bff.application.services.exceptions.BadRequestException; -import com.vinhonotas.bff.client.degustacao.TastingClient; -import com.vinhonotas.bff.domain.enums.EnumTastingType; -import com.vinhonotas.bff.interfaces.dtos.inputs.degustacao.TastingCardInputDTO; -import com.vinhonotas.bff.interfaces.dtos.inputs.degustacao.TastingInputDTO; -import com.vinhonotas.bff.interfaces.dtos.outputs.degustacao.TastingCardOutputDTO; -import com.vinhonotas.bff.interfaces.dtos.outputs.degustacao.TastingOutputDTO; -import com.vinhonotas.bff.utils.MessagesConstants; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.DisplayName; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; -import org.mockito.InjectMocks; -import org.mockito.Mock; -import org.mockito.Mockito; -import org.mockito.junit.jupiter.MockitoExtension; - -import java.time.LocalDate; -import java.util.List; -import java.util.Set; -import java.util.UUID; - -import static org.junit.jupiter.api.Assertions.*; -import static org.mockito.Mockito.*; - -@ExtendWith(MockitoExtension.class) -class TastingServiceImplTest { - - @InjectMocks - private TastingServiceImpl tastingService; - - @Mock - private TastingClient tastingClient; - - private TastingInputDTO tastingInputDTO; - private TastingOutputDTO tastingOutputDTO; - - @BeforeEach - void setUp() { - tastingInputDTO = createTastingInputDTO(); - tastingOutputDTO = createTastingOutputDTO(); - } - - @Test - @DisplayName("Deve criar uma degustação") - void testCreateTasting() { - when(tastingClient.createTasting(tastingInputDTO)).thenReturn(tastingOutputDTO); - - TastingOutputDTO result = assertDoesNotThrow(() -> tastingService.createTasting(tastingInputDTO)); - assertNotNull(result); - assertEquals(tastingOutputDTO.getId(), result.getId()); - assertEquals(tastingOutputDTO.getTastingData(), result.getTastingData()); - assertEquals(tastingOutputDTO.getTastingType(), result.getTastingType()); - assertEquals(tastingOutputDTO.getTastingCards(), result.getTastingCards()); - verify(tastingClient).createTasting(tastingInputDTO); - } - - @Test - @DisplayName("Deve lançar BadRequestException ao criar uma degustação") - void testCreateTastingThrowBadRequestException() { - when(tastingClient.createTasting(tastingInputDTO)).thenThrow(new BadRequestException(MessagesConstants.ERROR_WHEN_SAVING)); - - Exception exception = assertThrows(Exception.class, () -> tastingService.createTasting(tastingInputDTO)); - assertEquals(MessagesConstants.ERROR_WHEN_SAVING, exception.getMessage()); - verify(tastingClient).createTasting(tastingInputDTO); - } - - @Test - @DisplayName("Deve listar todas as degustações") - void testGetAllTastings() { - when(tastingClient.getAllTastings()).thenReturn(List.of(tastingOutputDTO)); - - List list = assertDoesNotThrow(() -> tastingService.getAllTastings()); - assertNotNull(list); - assertFalse(list.isEmpty()); - assertEquals(1, list.size()); - assertEquals(tastingOutputDTO.getId(), list.get(0).getId()); - assertEquals(tastingOutputDTO.getTastingData(), list.get(0).getTastingData()); - assertEquals(tastingOutputDTO.getTastingType(), list.get(0).getTastingType()); - assertEquals(tastingOutputDTO.getTastingCards(), list.get(0).getTastingCards()); - verify(tastingClient).getAllTastings(); - } - - @Test - @DisplayName("Deve lançar BadRequestException ao listar todas as degustações") - void testGetAllTastingsThrowBadRequestException() { - when(tastingClient.getAllTastings()).thenThrow(new BadRequestException(MessagesConstants.NOT_FOUND)); - - Exception exception = assertThrows(Exception.class, () -> tastingService.getAllTastings()); - assertEquals(MessagesConstants.NOT_FOUND, exception.getMessage()); - verify(tastingClient).getAllTastings(); - } - - @Test - @DisplayName("Deve buscar uma degustação pelo id") - void testGetTastingById() { - when(tastingClient.getTastingById("f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e")).thenReturn(tastingOutputDTO); - - TastingOutputDTO result = assertDoesNotThrow(() -> tastingService.getTastingById("f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e")); - assertNotNull(result); - assertEquals("f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e", result.getId().toString()); - assertEquals(tastingOutputDTO.getTastingData(), result.getTastingData()); - assertEquals(tastingOutputDTO.getTastingType(), result.getTastingType()); - assertEquals(tastingOutputDTO.getTastingCards(), result.getTastingCards()); - verify(tastingClient).getTastingById("f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e"); - } - - @Test - @DisplayName("Deve lançar BadRequestException ao buscar uma degustação pelo id") - void testGetTastingByIdThrowBadRequestException() { - when(tastingClient.getTastingById("f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e")) - .thenThrow(new BadRequestException(MessagesConstants.NOT_FOUND)); - - Exception exception = assertThrows(Exception.class, () -> tastingService.getTastingById("f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e")); - assertEquals(MessagesConstants.NOT_FOUND, exception.getMessage()); - verify(tastingClient).getTastingById("f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e"); - } - - @Test - @DisplayName("Deve atualizar uma degustação") - void testUpdateTasting() { - when(tastingClient.updateTasting("f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e", tastingInputDTO)).thenReturn(tastingOutputDTO); - - TastingOutputDTO result = assertDoesNotThrow(() -> tastingService.updateTasting("f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e", tastingInputDTO)); - assertNotNull(result); - assertEquals("f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e", result.getId().toString()); - assertEquals(tastingOutputDTO.getTastingData(), result.getTastingData()); - assertEquals(tastingOutputDTO.getTastingType(), result.getTastingType()); - assertEquals(tastingOutputDTO.getTastingCards(), result.getTastingCards()); - verify(tastingClient).updateTasting("f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e", tastingInputDTO); - } - - @Test - @DisplayName("Deve lançar BadRequestException ao atualizar uma degustação") - void testUpdateTastingThrowBadRequestException() { - when(tastingClient.updateTasting("f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e", tastingInputDTO)) - .thenThrow(new BadRequestException(MessagesConstants.ERROR_WHEN_UPDATING)); - - Exception exception = assertThrows(Exception.class, () -> tastingService.updateTasting("f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e", tastingInputDTO)); - assertEquals(MessagesConstants.ERROR_WHEN_UPDATING, exception.getMessage()); - verify(tastingClient).updateTasting("f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e", tastingInputDTO); - } - - @Test - @DisplayName("Deve deletar uma degustação") - void testDeleteTasting() { - assertDoesNotThrow(() -> tastingService.deleteTasting("f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e")); - - verify(tastingClient).deleteTasting("f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e"); - } - - @Test - @DisplayName("Deve lançar BadRequestException ao deletar uma degustação") - void testDeleteTastingThrowBadRequestException() { - doThrow(new BadRequestException(MessagesConstants.ERROR_WHEN_DELETING)) - .when(tastingClient).deleteTasting("f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e"); - - Exception exception = assertThrows(Exception.class, () -> tastingService.deleteTasting("f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e")); - assertEquals(MessagesConstants.ERROR_WHEN_DELETING, exception.getMessage()); - verify(tastingClient).deleteTasting("f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e"); - } - - private TastingInputDTO createTastingInputDTO() { - return TastingInputDTO.builder() - .tastingData(LocalDate.now()) - .tastingType(EnumTastingType.COMPARATIVE.getCode()) - .tastingCards(Set.of(Mockito.mock(TastingCardInputDTO.class))) - .build(); - } - - private TastingOutputDTO createTastingOutputDTO() { - return TastingOutputDTO.builder() - .id(UUID.fromString("f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e")) - .tastingData(LocalDate.now()) - .tastingType(EnumTastingType.COMPARATIVE.getCode()) - .tastingCards(Set.of(Mockito.mock(TastingCardOutputDTO.class))) - .build(); - } - -} +//package com.vinhonotas.bff.application.services.degustacao.impl; +// +//import com.vinhonotas.bff.application.services.exceptions.BadRequestException; +//import com.vinhonotas.bff.client.degustacao.TastingClient; +//import com.vinhonotas.bff.domain.enums.EnumTastingType; +//import com.vinhonotas.bff.interfaces.dtos.inputs.degustacao.TastingCardInputDTO; +//import com.vinhonotas.bff.interfaces.dtos.outputs.degustacao.TastingCardOutputDTO; +//import com.vinhonotas.bff.utils.MessagesConstants; +//import org.junit.jupiter.api.BeforeEach; +//import org.junit.jupiter.api.DisplayName; +//import org.junit.jupiter.api.Test; +//import org.junit.jupiter.api.extension.ExtendWith; +//import org.mockito.InjectMocks; +//import org.mockito.Mock; +//import org.mockito.Mockito; +//import org.mockito.junit.jupiter.MockitoExtension; +// +//import java.time.LocalDate; +//import java.util.List; +//import java.util.Set; +//import java.util.UUID; +// +//import static org.junit.jupiter.api.Assertions.*; +//import static org.mockito.Mockito.*; +// +//@ExtendWith(MockitoExtension.class) +//class TastingServiceImplTest { +// +// @InjectMocks +// private TastingServiceImpl tastingService; +// +// @Mock +// private TastingClient tastingClient; +// +// private TastingInputDTO tastingInputDTO; +// private TastingOutputDTO tastingOutputDTO; +// +// @BeforeEach +// void setUp() { +// tastingInputDTO = createTastingInputDTO(); +// tastingOutputDTO = createTastingOutputDTO(); +// } +// +// @Test +// @DisplayName("Deve criar uma degustação") +// void testCreateTasting() { +// when(tastingClient.createTasting(tastingInputDTO)).thenReturn(tastingOutputDTO); +// +// TastingOutputDTO result = assertDoesNotThrow(() -> tastingService.createTasting(tastingInputDTO)); +// assertNotNull(result); +// assertEquals(tastingOutputDTO.getId(), result.getId()); +// assertEquals(tastingOutputDTO.getTastingData(), result.getTastingData()); +// assertEquals(tastingOutputDTO.getTastingType(), result.getTastingType()); +// assertEquals(tastingOutputDTO.getTastingCards(), result.getTastingCards()); +// verify(tastingClient).createTasting(tastingInputDTO); +// } +// +// @Test +// @DisplayName("Deve lançar BadRequestException ao criar uma degustação") +// void testCreateTastingThrowBadRequestException() { +// when(tastingClient.createTasting(tastingInputDTO)).thenThrow(new BadRequestException(MessagesConstants.ERROR_WHEN_SAVING)); +// +// Exception exception = assertThrows(Exception.class, () -> tastingService.createTasting(tastingInputDTO)); +// assertEquals(MessagesConstants.ERROR_WHEN_SAVING, exception.getMessage()); +// verify(tastingClient).createTasting(tastingInputDTO); +// } +// +// @Test +// @DisplayName("Deve listar todas as degustações") +// void testGetAllTastings() { +// when(tastingClient.getAllTastings()).thenReturn(List.of(tastingOutputDTO)); +// +// List list = assertDoesNotThrow(() -> tastingService.getAllTastings()); +// assertNotNull(list); +// assertFalse(list.isEmpty()); +// assertEquals(1, list.size()); +// assertEquals(tastingOutputDTO.getId(), list.get(0).getId()); +// assertEquals(tastingOutputDTO.getTastingData(), list.get(0).getTastingData()); +// assertEquals(tastingOutputDTO.getTastingType(), list.get(0).getTastingType()); +// assertEquals(tastingOutputDTO.getTastingCards(), list.get(0).getTastingCards()); +// verify(tastingClient).getAllTastings(); +// } +// +// @Test +// @DisplayName("Deve lançar BadRequestException ao listar todas as degustações") +// void testGetAllTastingsThrowBadRequestException() { +// when(tastingClient.getAllTastings()).thenThrow(new BadRequestException(MessagesConstants.NOT_FOUND)); +// +// Exception exception = assertThrows(Exception.class, () -> tastingService.getAllTastings()); +// assertEquals(MessagesConstants.NOT_FOUND, exception.getMessage()); +// verify(tastingClient).getAllTastings(); +// } +// +// @Test +// @DisplayName("Deve buscar uma degustação pelo id") +// void testGetTastingById() { +// when(tastingClient.getTastingById("f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e")).thenReturn(tastingOutputDTO); +// +// TastingOutputDTO result = assertDoesNotThrow(() -> tastingService.getTastingById("f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e")); +// assertNotNull(result); +// assertEquals("f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e", result.getId().toString()); +// assertEquals(tastingOutputDTO.getTastingData(), result.getTastingData()); +// assertEquals(tastingOutputDTO.getTastingType(), result.getTastingType()); +// assertEquals(tastingOutputDTO.getTastingCards(), result.getTastingCards()); +// verify(tastingClient).getTastingById("f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e"); +// } +// +// @Test +// @DisplayName("Deve lançar BadRequestException ao buscar uma degustação pelo id") +// void testGetTastingByIdThrowBadRequestException() { +// when(tastingClient.getTastingById("f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e")) +// .thenThrow(new BadRequestException(MessagesConstants.NOT_FOUND)); +// +// Exception exception = assertThrows(Exception.class, () -> tastingService.getTastingById("f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e")); +// assertEquals(MessagesConstants.NOT_FOUND, exception.getMessage()); +// verify(tastingClient).getTastingById("f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e"); +// } +// +// @Test +// @DisplayName("Deve atualizar uma degustação") +// void testUpdateTasting() { +// when(tastingClient.updateTasting("f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e", tastingInputDTO)).thenReturn(tastingOutputDTO); +// +// TastingOutputDTO result = assertDoesNotThrow(() -> tastingService.updateTasting("f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e", tastingInputDTO)); +// assertNotNull(result); +// assertEquals("f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e", result.getId().toString()); +// assertEquals(tastingOutputDTO.getTastingData(), result.getTastingData()); +// assertEquals(tastingOutputDTO.getTastingType(), result.getTastingType()); +// assertEquals(tastingOutputDTO.getTastingCards(), result.getTastingCards()); +// verify(tastingClient).updateTasting("f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e", tastingInputDTO); +// } +// +// @Test +// @DisplayName("Deve lançar BadRequestException ao atualizar uma degustação") +// void testUpdateTastingThrowBadRequestException() { +// when(tastingClient.updateTasting("f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e", tastingInputDTO)) +// .thenThrow(new BadRequestException(MessagesConstants.ERROR_WHEN_UPDATING)); +// +// Exception exception = assertThrows(Exception.class, () -> tastingService.updateTasting("f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e", tastingInputDTO)); +// assertEquals(MessagesConstants.ERROR_WHEN_UPDATING, exception.getMessage()); +// verify(tastingClient).updateTasting("f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e", tastingInputDTO); +// } +// +// @Test +// @DisplayName("Deve deletar uma degustação") +// void testDeleteTasting() { +// assertDoesNotThrow(() -> tastingService.deleteTasting("f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e")); +// +// verify(tastingClient).deleteTasting("f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e"); +// } +// +// @Test +// @DisplayName("Deve lançar BadRequestException ao deletar uma degustação") +// void testDeleteTastingThrowBadRequestException() { +// doThrow(new BadRequestException(MessagesConstants.ERROR_WHEN_DELETING)) +// .when(tastingClient).deleteTasting("f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e"); +// +// Exception exception = assertThrows(Exception.class, () -> tastingService.deleteTasting("f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e")); +// assertEquals(MessagesConstants.ERROR_WHEN_DELETING, exception.getMessage()); +// verify(tastingClient).deleteTasting("f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e"); +// } +// +// private TastingInputDTO createTastingInputDTO() { +// return TastingInputDTO.builder() +// .tastingData(LocalDate.now()) +// .tastingType(EnumTastingType.COMPARATIVE.getCode()) +// .tastingCards(Set.of(Mockito.mock(TastingCardInputDTO.class))) +// .build(); +// } +// +// private TastingOutputDTO createTastingOutputDTO() { +// return TastingOutputDTO.builder() +// .id(UUID.fromString("f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e")) +// .tastingData(LocalDate.now()) +// .tastingType(EnumTastingType.COMPARATIVE.getCode()) +// .tastingCards(Set.of(Mockito.mock(TastingCardOutputDTO.class))) +// .build(); +// } +// +//} diff --git a/bff/src/test/java/com/vinhonotas/bff/application/services/degustacao/impl/VisualInspectionServiceImplTest.java b/bff/src/test/java/com/vinhonotas/bff/application/services/degustacao/impl/VisualInspectionServiceImplTest.java index 18b01120..c67a17b6 100644 --- a/bff/src/test/java/com/vinhonotas/bff/application/services/degustacao/impl/VisualInspectionServiceImplTest.java +++ b/bff/src/test/java/com/vinhonotas/bff/application/services/degustacao/impl/VisualInspectionServiceImplTest.java @@ -1,211 +1,209 @@ -package com.vinhonotas.bff.application.services.degustacao.impl; - -import com.vinhonotas.bff.application.services.exceptions.BadRequestException; -import com.vinhonotas.bff.application.services.exceptions.NotFoundException; -import com.vinhonotas.bff.client.degustacao.VisualInspectionClient; -import com.vinhonotas.bff.domain.enums.*; -import com.vinhonotas.bff.interfaces.dtos.inputs.degustacao.VisualInspectionInputDTO; -import com.vinhonotas.bff.interfaces.dtos.outputs.degustacao.VisualInspectionOutputDTO; -import com.vinhonotas.bff.utils.MessagesConstants; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.DisplayName; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; -import org.mockito.InjectMocks; -import org.mockito.Mock; -import org.mockito.junit.jupiter.MockitoExtension; - -import java.time.LocalDate; -import java.util.List; -import java.util.UUID; - -import static org.hibernate.validator.internal.util.Contracts.assertNotNull; -import static org.junit.jupiter.api.Assertions.*; -import static org.mockito.Mockito.*; - -@ExtendWith(MockitoExtension.class) -class VisualInspectionServiceImplTest { - - @InjectMocks - private VisualInspectionServiceImpl service; - - @Mock - private VisualInspectionClient client; - - private VisualInspectionInputDTO inputDTO; - private VisualInspectionOutputDTO outputDTO; - - @BeforeEach - void setUp() { - inputDTO = createVisualInspectionInputDTO(); - outputDTO = createVisualInspectionOutputDTO(); - } - - @Test - @DisplayName("Deve criar uma inspeção visual") - void testCreate() { - when(client.createVisualInspection(inputDTO)).thenReturn(outputDTO); - - VisualInspectionOutputDTO result = assertDoesNotThrow(() -> service.createVisualInspection(inputDTO)); - assertNotNull(result); - assertEquals(outputDTO.getId(), result.getId()); - assertEquals(outputDTO.getTastingData(), result.getTastingData()); - assertEquals(outputDTO.getWineTasted(), result.getWineTasted()); - assertEquals(outputDTO.getClarity(), result.getClarity()); - assertEquals(outputDTO.getBrightness(), result.getBrightness()); - assertEquals(outputDTO.getViscosity(), result.getViscosity()); - assertEquals(outputDTO.getColorRed(), result.getColorRed()); - assertEquals(outputDTO.getColorWhite(), result.getColorWhite()); - assertEquals(outputDTO.getColorRose(), result.getColorRose()); - assertEquals(outputDTO.getClassification(), result.getClassification()); - verify(client).createVisualInspection(inputDTO); - } - - @Test - @DisplayName("Deve lançar BadRequestException ao criar uma inspeção visual") - void testCreateThrowBadRequestException() { - when(client.createVisualInspection(inputDTO)).thenThrow(new BadRequestException(MessagesConstants.ERROR_WHEN_SAVING)); - - Exception exception = assertThrows(Exception.class, () -> service.createVisualInspection(inputDTO)); - assertEquals(MessagesConstants.ERROR_WHEN_SAVING, exception.getMessage()); - verify(client).createVisualInspection(inputDTO); - } - - @Test - @DisplayName("Deve listar todas as inspeções visuais") - void testGetAll() { - when(client.getAllVisualInspections()).thenReturn(List.of(outputDTO)); - - var result = assertDoesNotThrow(() -> service.getAllVisualInspections()); - assertNotNull(result); - assertEquals(1, result.size()); - assertEquals(outputDTO.getId(), result.get(0).getId()); - assertEquals(outputDTO.getTastingData(), result.get(0).getTastingData()); - assertEquals(outputDTO.getWineTasted(), result.get(0).getWineTasted()); - assertEquals(outputDTO.getClarity(), result.get(0).getClarity()); - assertEquals(outputDTO.getBrightness(), result.get(0).getBrightness()); - assertEquals(outputDTO.getViscosity(), result.get(0).getViscosity()); - assertEquals(outputDTO.getColorRed(), result.get(0).getColorRed()); - assertEquals(outputDTO.getColorWhite(), result.get(0).getColorWhite()); - assertEquals(outputDTO.getColorRose(), result.get(0).getColorRose()); - assertEquals(outputDTO.getClassification(), result.get(0).getClassification()); - verify(client).getAllVisualInspections(); - } - - @Test - @DisplayName("Deve lançar NotFoundException ao listar todas as inspeções visuais") - void testGetAllThrowNotFoundException() { - when(client.getAllVisualInspections()).thenThrow(new NotFoundException(MessagesConstants.NOT_FOUND)); - - Exception exception = assertThrows(Exception.class, () -> service.getAllVisualInspections()); - assertEquals(MessagesConstants.NOT_FOUND, exception.getMessage()); - verify(client).getAllVisualInspections(); - } - - @Test - @DisplayName("Deve buscar uma inspeção visual pelo id") - void testGetById() { - when(client.getVisualInspectionById(outputDTO.getId().toString())).thenReturn(outputDTO); - - var result = assertDoesNotThrow(() -> service.getVisualInspectionById(outputDTO.getId().toString())); - assertNotNull(result); - assertEquals(outputDTO.getId(), result.getId()); - assertEquals(outputDTO.getTastingData(), result.getTastingData()); - assertEquals(outputDTO.getWineTasted(), result.getWineTasted()); - assertEquals(outputDTO.getClarity(), result.getClarity()); - assertEquals(outputDTO.getBrightness(), result.getBrightness()); - assertEquals(outputDTO.getViscosity(), result.getViscosity()); - assertEquals(outputDTO.getColorRed(), result.getColorRed()); - assertEquals(outputDTO.getColorWhite(), result.getColorWhite()); - assertEquals(outputDTO.getColorRose(), result.getColorRose()); - assertEquals(outputDTO.getClassification(), result.getClassification()); - verify(client).getVisualInspectionById(outputDTO.getId().toString()); - } - - @Test - @DisplayName("Deve lançar NotFoundException ao buscar uma inspeção visual pelo id") - void testGetByIdThrowNotFoundException() { - when(client.getVisualInspectionById(outputDTO.getId().toString())).thenThrow(new NotFoundException(MessagesConstants.NOT_FOUND)); - - Exception exception = assertThrows(Exception.class, () -> service.getVisualInspectionById(outputDTO.getId().toString())); - assertEquals(MessagesConstants.NOT_FOUND, exception.getMessage()); - verify(client).getVisualInspectionById(outputDTO.getId().toString()); - } - - @Test - @DisplayName("Deve atualizar uma inspeção visual") - void testUpdate() { - when(client.updateVisualInspection(outputDTO.getId().toString(), inputDTO)).thenReturn(outputDTO); - - var result = assertDoesNotThrow(() -> service.updateVisualInspection(outputDTO.getId().toString(), inputDTO)); - assertNotNull(result); - assertEquals(outputDTO.getId(), result.getId()); - assertEquals(outputDTO.getTastingData(), result.getTastingData()); - assertEquals(outputDTO.getWineTasted(), result.getWineTasted()); - assertEquals(outputDTO.getClarity(), result.getClarity()); - assertEquals(outputDTO.getBrightness(), result.getBrightness()); - assertEquals(outputDTO.getViscosity(), result.getViscosity()); - assertEquals(outputDTO.getColorRed(), result.getColorRed()); - assertEquals(outputDTO.getColorWhite(), result.getColorWhite()); - assertEquals(outputDTO.getColorRose(), result.getColorRose()); - assertEquals(outputDTO.getClassification(), result.getClassification()); - verify(client).updateVisualInspection(outputDTO.getId().toString(), inputDTO); - } - - @Test - @DisplayName("Deve lançar BadRequestException ao atualizar uma inspeção visual") - void testUpdateThrowBadRequestException() { - when(client.updateVisualInspection(outputDTO.getId().toString(), inputDTO)).thenThrow(new BadRequestException(MessagesConstants.ERROR_WHEN_UPDATING)); - - Exception exception = assertThrows(Exception.class, () -> service.updateVisualInspection(outputDTO.getId().toString(), inputDTO)); - assertEquals(MessagesConstants.ERROR_WHEN_UPDATING, exception.getMessage()); - verify(client).updateVisualInspection(outputDTO.getId().toString(), inputDTO); - } - - @Test - @DisplayName("Deve deletar uma inspeção visual") - void testDelete() { - assertDoesNotThrow(() -> service.deleteVisualInspection(outputDTO.getId().toString())); - verify(client).deleteVisualInspection(outputDTO.getId().toString()); - } - - @Test - @DisplayName("Deve lançar BadRequestException ao deletar uma inspeção visual") - void testDeleteThrowBadRequestException() { - doThrow(new BadRequestException(MessagesConstants.ERROR_WHEN_DELETING)).when(client).deleteVisualInspection(outputDTO.getId().toString()); - - Exception exception = assertThrows(Exception.class, () -> service.deleteVisualInspection(outputDTO.getId().toString())); - assertEquals(MessagesConstants.ERROR_WHEN_DELETING, exception.getMessage()); - verify(client).deleteVisualInspection(outputDTO.getId().toString()); - } - - private VisualInspectionInputDTO createVisualInspectionInputDTO() { - return VisualInspectionInputDTO.builder() - .tastingData(LocalDate.now()) - .wineTasted("Wine Tasted") - .clarity(EnumClarityType.VERY_CLEAR.getCode()) - .brightness(EnumBrightnessType.VERY_BRIGHT.getCode()) - .viscosity(EnumViscosityType.SLIPPERY.getCode()) - .colorRed(EnumRedColorType.RUBY.getCode()) - .colorWhite(EnumWhiteColorType.STRAW_YELLOW.getCode()) - .colorRose(EnumRoseColorType.BROWN.getCode()) - .classification(EnumClassificationType.LITTLE.getCode()) - .build(); - } - - private VisualInspectionOutputDTO createVisualInspectionOutputDTO() { - return VisualInspectionOutputDTO.builder() - .id(UUID.fromString("f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e")) - .tastingData(LocalDate.now()) - .wineTasted("Wine Tasted") - .clarity(EnumClarityType.VERY_CLEAR.getCode()) - .brightness(EnumBrightnessType.VERY_BRIGHT.getCode()) - .viscosity(EnumViscosityType.SLIPPERY.getCode()) - .colorRed(EnumRedColorType.RUBY.getCode()) - .colorWhite(EnumWhiteColorType.STRAW_YELLOW.getCode()) - .colorRose(EnumRoseColorType.BROWN.getCode()) - .classification(EnumClassificationType.LITTLE.getCode()) - .build(); - } - -} +//package com.vinhonotas.bff.application.services.degustacao.impl; +// +//import com.vinhonotas.bff.application.services.exceptions.BadRequestException; +//import com.vinhonotas.bff.application.services.exceptions.NotFoundException; +//import com.vinhonotas.bff.client.degustacao.VisualInspectionClient; +//import com.vinhonotas.bff.domain.enums.*; +//import com.vinhonotas.bff.utils.MessagesConstants; +//import org.junit.jupiter.api.BeforeEach; +//import org.junit.jupiter.api.DisplayName; +//import org.junit.jupiter.api.Test; +//import org.junit.jupiter.api.extension.ExtendWith; +//import org.mockito.InjectMocks; +//import org.mockito.Mock; +//import org.mockito.junit.jupiter.MockitoExtension; +// +//import java.time.LocalDate; +//import java.util.List; +//import java.util.UUID; +// +//import static org.hibernate.validator.internal.util.Contracts.assertNotNull; +//import static org.junit.jupiter.api.Assertions.*; +//import static org.mockito.Mockito.*; +// +//@ExtendWith(MockitoExtension.class) +//class VisualInspectionServiceImplTest { +// +// @InjectMocks +// private VisualInspectionServiceImpl service; +// +// @Mock +// private VisualInspectionClient client; +// +// private VisualInspectionInputDTO inputDTO; +// private VisualInspectionOutputDTO outputDTO; +// +// @BeforeEach +// void setUp() { +// inputDTO = createVisualInspectionInputDTO(); +// outputDTO = createVisualInspectionOutputDTO(); +// } +// +// @Test +// @DisplayName("Deve criar uma inspeção visual") +// void testCreate() { +// when(client.createVisualInspection(inputDTO)).thenReturn(outputDTO); +// +// VisualInspectionOutputDTO result = assertDoesNotThrow(() -> service.createVisualInspection(inputDTO)); +// assertNotNull(result); +// assertEquals(outputDTO.getId(), result.getId()); +// assertEquals(outputDTO.getTastingData(), result.getTastingData()); +// assertEquals(outputDTO.getWineTasted(), result.getWineTasted()); +// assertEquals(outputDTO.getClarity(), result.getClarity()); +// assertEquals(outputDTO.getBrightness(), result.getBrightness()); +// assertEquals(outputDTO.getViscosity(), result.getViscosity()); +// assertEquals(outputDTO.getColorRed(), result.getColorRed()); +// assertEquals(outputDTO.getColorWhite(), result.getColorWhite()); +// assertEquals(outputDTO.getColorRose(), result.getColorRose()); +// assertEquals(outputDTO.getClassification(), result.getClassification()); +// verify(client).createVisualInspection(inputDTO); +// } +// +// @Test +// @DisplayName("Deve lançar BadRequestException ao criar uma inspeção visual") +// void testCreateThrowBadRequestException() { +// when(client.createVisualInspection(inputDTO)).thenThrow(new BadRequestException(MessagesConstants.ERROR_WHEN_SAVING)); +// +// Exception exception = assertThrows(Exception.class, () -> service.createVisualInspection(inputDTO)); +// assertEquals(MessagesConstants.ERROR_WHEN_SAVING, exception.getMessage()); +// verify(client).createVisualInspection(inputDTO); +// } +// +// @Test +// @DisplayName("Deve listar todas as inspeções visuais") +// void testGetAll() { +// when(client.getAllVisualInspections()).thenReturn(List.of(outputDTO)); +// +// var result = assertDoesNotThrow(() -> service.getAllVisualInspections()); +// assertNotNull(result); +// assertEquals(1, result.size()); +// assertEquals(outputDTO.getId(), result.get(0).getId()); +// assertEquals(outputDTO.getTastingData(), result.get(0).getTastingData()); +// assertEquals(outputDTO.getWineTasted(), result.get(0).getWineTasted()); +// assertEquals(outputDTO.getClarity(), result.get(0).getClarity()); +// assertEquals(outputDTO.getBrightness(), result.get(0).getBrightness()); +// assertEquals(outputDTO.getViscosity(), result.get(0).getViscosity()); +// assertEquals(outputDTO.getColorRed(), result.get(0).getColorRed()); +// assertEquals(outputDTO.getColorWhite(), result.get(0).getColorWhite()); +// assertEquals(outputDTO.getColorRose(), result.get(0).getColorRose()); +// assertEquals(outputDTO.getClassification(), result.get(0).getClassification()); +// verify(client).getAllVisualInspections(); +// } +// +// @Test +// @DisplayName("Deve lançar NotFoundException ao listar todas as inspeções visuais") +// void testGetAllThrowNotFoundException() { +// when(client.getAllVisualInspections()).thenThrow(new NotFoundException(MessagesConstants.NOT_FOUND)); +// +// Exception exception = assertThrows(Exception.class, () -> service.getAllVisualInspections()); +// assertEquals(MessagesConstants.NOT_FOUND, exception.getMessage()); +// verify(client).getAllVisualInspections(); +// } +// +// @Test +// @DisplayName("Deve buscar uma inspeção visual pelo id") +// void testGetById() { +// when(client.getVisualInspectionById(outputDTO.getId().toString())).thenReturn(outputDTO); +// +// var result = assertDoesNotThrow(() -> service.getVisualInspectionById(outputDTO.getId().toString())); +// assertNotNull(result); +// assertEquals(outputDTO.getId(), result.getId()); +// assertEquals(outputDTO.getTastingData(), result.getTastingData()); +// assertEquals(outputDTO.getWineTasted(), result.getWineTasted()); +// assertEquals(outputDTO.getClarity(), result.getClarity()); +// assertEquals(outputDTO.getBrightness(), result.getBrightness()); +// assertEquals(outputDTO.getViscosity(), result.getViscosity()); +// assertEquals(outputDTO.getColorRed(), result.getColorRed()); +// assertEquals(outputDTO.getColorWhite(), result.getColorWhite()); +// assertEquals(outputDTO.getColorRose(), result.getColorRose()); +// assertEquals(outputDTO.getClassification(), result.getClassification()); +// verify(client).getVisualInspectionById(outputDTO.getId().toString()); +// } +// +// @Test +// @DisplayName("Deve lançar NotFoundException ao buscar uma inspeção visual pelo id") +// void testGetByIdThrowNotFoundException() { +// when(client.getVisualInspectionById(outputDTO.getId().toString())).thenThrow(new NotFoundException(MessagesConstants.NOT_FOUND)); +// +// Exception exception = assertThrows(Exception.class, () -> service.getVisualInspectionById(outputDTO.getId().toString())); +// assertEquals(MessagesConstants.NOT_FOUND, exception.getMessage()); +// verify(client).getVisualInspectionById(outputDTO.getId().toString()); +// } +// +// @Test +// @DisplayName("Deve atualizar uma inspeção visual") +// void testUpdate() { +// when(client.updateVisualInspection(outputDTO.getId().toString(), inputDTO)).thenReturn(outputDTO); +// +// var result = assertDoesNotThrow(() -> service.updateVisualInspection(outputDTO.getId().toString(), inputDTO)); +// assertNotNull(result); +// assertEquals(outputDTO.getId(), result.getId()); +// assertEquals(outputDTO.getTastingData(), result.getTastingData()); +// assertEquals(outputDTO.getWineTasted(), result.getWineTasted()); +// assertEquals(outputDTO.getClarity(), result.getClarity()); +// assertEquals(outputDTO.getBrightness(), result.getBrightness()); +// assertEquals(outputDTO.getViscosity(), result.getViscosity()); +// assertEquals(outputDTO.getColorRed(), result.getColorRed()); +// assertEquals(outputDTO.getColorWhite(), result.getColorWhite()); +// assertEquals(outputDTO.getColorRose(), result.getColorRose()); +// assertEquals(outputDTO.getClassification(), result.getClassification()); +// verify(client).updateVisualInspection(outputDTO.getId().toString(), inputDTO); +// } +// +// @Test +// @DisplayName("Deve lançar BadRequestException ao atualizar uma inspeção visual") +// void testUpdateThrowBadRequestException() { +// when(client.updateVisualInspection(outputDTO.getId().toString(), inputDTO)).thenThrow(new BadRequestException(MessagesConstants.ERROR_WHEN_UPDATING)); +// +// Exception exception = assertThrows(Exception.class, () -> service.updateVisualInspection(outputDTO.getId().toString(), inputDTO)); +// assertEquals(MessagesConstants.ERROR_WHEN_UPDATING, exception.getMessage()); +// verify(client).updateVisualInspection(outputDTO.getId().toString(), inputDTO); +// } +// +// @Test +// @DisplayName("Deve deletar uma inspeção visual") +// void testDelete() { +// assertDoesNotThrow(() -> service.deleteVisualInspection(outputDTO.getId().toString())); +// verify(client).deleteVisualInspection(outputDTO.getId().toString()); +// } +// +// @Test +// @DisplayName("Deve lançar BadRequestException ao deletar uma inspeção visual") +// void testDeleteThrowBadRequestException() { +// doThrow(new BadRequestException(MessagesConstants.ERROR_WHEN_DELETING)).when(client).deleteVisualInspection(outputDTO.getId().toString()); +// +// Exception exception = assertThrows(Exception.class, () -> service.deleteVisualInspection(outputDTO.getId().toString())); +// assertEquals(MessagesConstants.ERROR_WHEN_DELETING, exception.getMessage()); +// verify(client).deleteVisualInspection(outputDTO.getId().toString()); +// } +// +// private VisualInspectionInputDTO createVisualInspectionInputDTO() { +// return VisualInspectionInputDTO.builder() +// .tastingData(LocalDate.now()) +// .wineTasted("Wine Tasted") +// .clarity(EnumClarityType.VERY_CLEAR.getCode()) +// .brightness(EnumBrightnessType.VERY_BRIGHT.getCode()) +// .viscosity(EnumViscosityType.SLIPPERY.getCode()) +// .colorRed(EnumRedColorType.RUBY.getCode()) +// .colorWhite(EnumWhiteColorType.STRAW_YELLOW.getCode()) +// .colorRose(EnumRoseColorType.BROWN.getCode()) +// .classification(EnumClassificationType.LITTLE.getCode()) +// .build(); +// } +// +// private VisualInspectionOutputDTO createVisualInspectionOutputDTO() { +// return VisualInspectionOutputDTO.builder() +// .id(UUID.fromString("f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e")) +// .tastingData(LocalDate.now()) +// .wineTasted("Wine Tasted") +// .clarity(EnumClarityType.VERY_CLEAR.getCode()) +// .brightness(EnumBrightnessType.VERY_BRIGHT.getCode()) +// .viscosity(EnumViscosityType.SLIPPERY.getCode()) +// .colorRed(EnumRedColorType.RUBY.getCode()) +// .colorWhite(EnumWhiteColorType.STRAW_YELLOW.getCode()) +// .colorRose(EnumRoseColorType.BROWN.getCode()) +// .classification(EnumClassificationType.LITTLE.getCode()) +// .build(); +// } +// +//} diff --git a/bff/src/test/java/com/vinhonotas/bff/interfaces/controllers/degustacao/AromasControllerTest.java b/bff/src/test/java/com/vinhonotas/bff/interfaces/controllers/degustacao/AromasControllerTest.java index 9e3cf82b..e8733478 100644 --- a/bff/src/test/java/com/vinhonotas/bff/interfaces/controllers/degustacao/AromasControllerTest.java +++ b/bff/src/test/java/com/vinhonotas/bff/interfaces/controllers/degustacao/AromasControllerTest.java @@ -1,212 +1,210 @@ -package com.vinhonotas.bff.interfaces.controllers.degustacao; - -import com.fasterxml.jackson.databind.ObjectMapper; -import com.vinhonotas.bff.application.services.degustacao.AromasService; -import com.vinhonotas.bff.application.services.exceptions.BadRequestException; -import com.vinhonotas.bff.application.services.exceptions.NotFoundException; -import com.vinhonotas.bff.domain.enums.*; -import com.vinhonotas.bff.interfaces.dtos.inputs.degustacao.AromasInputDTO; -import com.vinhonotas.bff.interfaces.dtos.outputs.degustacao.AromasOutputDTO; -import com.vinhonotas.bff.utils.MessagesConstants; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.DisplayName; -import org.junit.jupiter.api.Test; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; -import org.springframework.boot.test.mock.mockito.MockBean; -import org.springframework.http.MediaType; -import org.springframework.test.web.servlet.MockMvc; - -import java.time.LocalDate; -import java.util.List; -import java.util.UUID; - -import static org.mockito.Mockito.doThrow; -import static org.mockito.Mockito.when; -import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*; -import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; - -@WebMvcTest(controllers = AromasController.class) -class AromasControllerTest { - - @Autowired - private MockMvc mockMvc; - @Autowired - private ObjectMapper objectMapper; - - @MockBean - private AromasService aromasService; - - private AromasInputDTO aromasInputDTO; - private AromasOutputDTO aromasOutputDTO; - - @BeforeEach - void setUp() { - aromasInputDTO = createAromasInputDTO(); - aromasOutputDTO = createAromasOutputDTO(); - } - - @Test - @DisplayName("Deve criar um novo aroma") - void testCreateAromas() throws Exception { - when(aromasService.createAromas(aromasInputDTO)).thenReturn(aromasOutputDTO); - - mockMvc.perform(post("/api/v1/aromas") - .contentType(MediaType.APPLICATION_JSON) - .content(objectMapper.writeValueAsString(aromasInputDTO))) - .andDo(print()) - .andExpect(status().isOk()) - .andExpect(content().json(objectMapper.writeValueAsString(aromasOutputDTO))); - } - - @Test - @DisplayName("Deve retornar um erro ao criar um aroma") - void testCreateAromasError() throws Exception { - when(aromasService.createAromas(aromasInputDTO)).thenThrow(new BadRequestException(MessagesConstants.ERROR_WHEN_SAVING)); - - mockMvc.perform(post("/api/v1/aromas") - .contentType(MediaType.APPLICATION_JSON) - .content(objectMapper.writeValueAsString(aromasInputDTO))) - .andDo(print()) - .andExpect(status().isBadRequest()); - } - - @Test - @DisplayName("Deve retornar uma lista com todos os aromas cadastrados") - void testGetAllAromas() throws Exception { - List list = List.of(aromasOutputDTO); - when(aromasService.getAllAromas()).thenReturn(List.of(aromasOutputDTO)); - - mockMvc.perform(get("/api/v1/aromas") - .contentType(MediaType.APPLICATION_JSON)) - .andDo(print()) - .andExpect(status().isOk()) - .andExpect(content().json(objectMapper.writeValueAsString(list))); - } - - @Test - @DisplayName("Deve retornar uma erro ao buscar todos os aromas") - void testGetAllAromasError() throws Exception { - when(aromasService.getAllAromas()).thenThrow(new NotFoundException(MessagesConstants.NOT_FOUND)); - - mockMvc.perform(get("/api/v1/aromas") - .contentType(MediaType.APPLICATION_JSON)) - .andDo(print()) - .andExpect(status().isNotFound()); - } - - @Test - @DisplayName("Deve retornar um aroma pelo id") - void testGetAromasById() throws Exception { - when(aromasService.getAromasById("f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e")).thenReturn(aromasOutputDTO); - - mockMvc.perform(get("/api/v1/aromas/f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e") - .contentType(MediaType.APPLICATION_JSON)) - .andDo(print()) - .andExpect(status().isOk()) - .andExpect(content().json(objectMapper.writeValueAsString(aromasOutputDTO))); - } - - @Test - @DisplayName("Deve retornar um erro ao buscar um aroma pelo id") - void testGetAromasByIdError() throws Exception { - when(aromasService.getAromasById("f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e")) - .thenThrow(new NotFoundException(MessagesConstants.NOT_FOUND)); - - mockMvc.perform(get("/api/v1/aromas/f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e") - .contentType(MediaType.APPLICATION_JSON)) - .andDo(print()) - .andExpect(status().isNotFound()); - } - - @Test - @DisplayName("Deve atualizar um aroma pelo id") - void testUpdateAromas() throws Exception { - when(aromasService.updateAromas("f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e", aromasInputDTO)).thenReturn(aromasOutputDTO); - - aromasOutputDTO.setFruity(EnumFruityType.KIWI.getCode()); - - mockMvc.perform(put("/api/v1/aromas/f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e") - .contentType(MediaType.APPLICATION_JSON) - .content(objectMapper.writeValueAsString(aromasInputDTO))) - .andDo(print()) - .andExpect(status().isOk()) - .andExpect(content().json(objectMapper.writeValueAsString(aromasOutputDTO))) - .andExpect(content().json("{'fruity':'Kiwi'}")); - } - - @Test - @DisplayName("Deve retornar um erro ao atualizar um aroma pelo id") - void testUpdateAromasError() throws Exception { - when(aromasService.updateAromas("f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e", aromasInputDTO)) - .thenThrow(new BadRequestException(MessagesConstants.ERROR_WHEN_UPDATING)); - - mockMvc.perform(put("/api/v1/aromas/f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e") - .contentType(MediaType.APPLICATION_JSON) - .content(objectMapper.writeValueAsString(aromasInputDTO))) - .andDo(print()) - .andExpect(status().isBadRequest()); - } - - @Test - @DisplayName("Deve deletar um aroma pelo id") - void testDeleteAromas() throws Exception { - mockMvc.perform(delete("/api/v1/aromas/f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e") - .contentType(MediaType.APPLICATION_JSON)) - .andDo(print()) - .andExpect(status().isNoContent()); - } - - @Test - @DisplayName("Deve retornar um erro ao deletar um aroma pelo id") - void testDeleteAromasError() throws Exception { - doThrow(BadRequestException.class).when(aromasService).deleteAromas("f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e"); - - mockMvc.perform(delete("/api/v1/aromas/f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e") - .contentType(MediaType.APPLICATION_JSON)) - .andDo(print()) - .andExpect(status().isBadRequest()); - } - - private AromasOutputDTO createAromasOutputDTO() { - return AromasOutputDTO.builder() - .id(UUID.fromString("f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e")) - .tastingData(LocalDate.now()) - .wineTasted("Wine Tasted") - .fruity(EnumFruityType.RASPBERRY.getCode()) - .dryFruits(EnumDryFruitsType.BRUNETTE.getCode()) - .florals(EnumFloralsType.CLOVE.getCode()) - .vegetablesAndHerbs(EnumVegetablesAndHerbsType.FENNEL.getCode()) - .minerals(EnumMineralsType.EARTH.getCode()) - .spices(EnumSpicesType.INDIAN_CLOVE.getCode()) - .animals(EnumAnimalsType.LEATHER.getCode()) - .empireumatics(EnumEmpireumaticsType.CARAMEL.getCode()) - .wood(EnumWoodType.SAWDUST.getCode()) - .chemicals(EnumChemicalsAndEtherealType.ACETONE.getCode()) - .lacteal(EnumLactealType.BUTTER.getCode()) - .sweets(EnumSweetsType.BULLET.getCode()) - .build(); - } - - private AromasInputDTO createAromasInputDTO() { - return AromasInputDTO.builder() - .tastingData(LocalDate.now()) - .wineTasted("Wine Tasted") - .fruity(EnumFruityType.RASPBERRY.getCode()) - .dryFruits(EnumDryFruitsType.BRUNETTE.getCode()) - .florals(EnumFloralsType.CLOVE.getCode()) - .vegetablesAndHerbs(EnumVegetablesAndHerbsType.FENNEL.getCode()) - .minerals(EnumMineralsType.EARTH.getCode()) - .spices(EnumSpicesType.INDIAN_CLOVE.getCode()) - .animals(EnumAnimalsType.LEATHER.getCode()) - .empireumatics(EnumEmpireumaticsType.CARAMEL.getCode()) - .wood(EnumWoodType.SAWDUST.getCode()) - .chemicals(EnumChemicalsAndEtherealType.ACETONE.getCode()) - .lacteal(EnumLactealType.BUTTER.getCode()) - .sweets(EnumSweetsType.BULLET.getCode()) - .build(); - } - -} +//package com.vinhonotas.bff.interfaces.controllers.degustacao; +// +//import com.fasterxml.jackson.databind.ObjectMapper; +//import com.vinhonotas.bff.application.services.degustacao.AromasService; +//import com.vinhonotas.bff.application.services.exceptions.BadRequestException; +//import com.vinhonotas.bff.application.services.exceptions.NotFoundException; +//import com.vinhonotas.bff.domain.enums.*; +//import com.vinhonotas.bff.utils.MessagesConstants; +//import org.junit.jupiter.api.BeforeEach; +//import org.junit.jupiter.api.DisplayName; +//import org.junit.jupiter.api.Test; +//import org.springframework.beans.factory.annotation.Autowired; +//import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; +//import org.springframework.boot.test.mock.mockito.MockBean; +//import org.springframework.http.MediaType; +//import org.springframework.test.web.servlet.MockMvc; +// +//import java.time.LocalDate; +//import java.util.List; +//import java.util.UUID; +// +//import static org.mockito.Mockito.doThrow; +//import static org.mockito.Mockito.when; +//import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*; +//import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print; +//import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content; +//import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; +// +//@WebMvcTest(controllers = AromasController.class) +//class AromasControllerTest { +// +// @Autowired +// private MockMvc mockMvc; +// @Autowired +// private ObjectMapper objectMapper; +// +// @MockBean +// private AromasService aromasService; +// +// private AromasInputDTO aromasInputDTO; +// private AromasOutputDTO aromasOutputDTO; +// +// @BeforeEach +// void setUp() { +// aromasInputDTO = createAromasInputDTO(); +// aromasOutputDTO = createAromasOutputDTO(); +// } +// +// @Test +// @DisplayName("Deve criar um novo aroma") +// void testCreateAromas() throws Exception { +// when(aromasService.createAromas(aromasInputDTO)).thenReturn(aromasOutputDTO); +// +// mockMvc.perform(post("/api/v1/aromas") +// .contentType(MediaType.APPLICATION_JSON) +// .content(objectMapper.writeValueAsString(aromasInputDTO))) +// .andDo(print()) +// .andExpect(status().isOk()) +// .andExpect(content().json(objectMapper.writeValueAsString(aromasOutputDTO))); +// } +// +// @Test +// @DisplayName("Deve retornar um erro ao criar um aroma") +// void testCreateAromasError() throws Exception { +// when(aromasService.createAromas(aromasInputDTO)).thenThrow(new BadRequestException(MessagesConstants.ERROR_WHEN_SAVING)); +// +// mockMvc.perform(post("/api/v1/aromas") +// .contentType(MediaType.APPLICATION_JSON) +// .content(objectMapper.writeValueAsString(aromasInputDTO))) +// .andDo(print()) +// .andExpect(status().isBadRequest()); +// } +// +// @Test +// @DisplayName("Deve retornar uma lista com todos os aromas cadastrados") +// void testGetAllAromas() throws Exception { +// List list = List.of(aromasOutputDTO); +// when(aromasService.getAllAromas()).thenReturn(List.of(aromasOutputDTO)); +// +// mockMvc.perform(get("/api/v1/aromas") +// .contentType(MediaType.APPLICATION_JSON)) +// .andDo(print()) +// .andExpect(status().isOk()) +// .andExpect(content().json(objectMapper.writeValueAsString(list))); +// } +// +// @Test +// @DisplayName("Deve retornar uma erro ao buscar todos os aromas") +// void testGetAllAromasError() throws Exception { +// when(aromasService.getAllAromas()).thenThrow(new NotFoundException(MessagesConstants.NOT_FOUND)); +// +// mockMvc.perform(get("/api/v1/aromas") +// .contentType(MediaType.APPLICATION_JSON)) +// .andDo(print()) +// .andExpect(status().isNotFound()); +// } +// +// @Test +// @DisplayName("Deve retornar um aroma pelo id") +// void testGetAromasById() throws Exception { +// when(aromasService.getAromasById("f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e")).thenReturn(aromasOutputDTO); +// +// mockMvc.perform(get("/api/v1/aromas/f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e") +// .contentType(MediaType.APPLICATION_JSON)) +// .andDo(print()) +// .andExpect(status().isOk()) +// .andExpect(content().json(objectMapper.writeValueAsString(aromasOutputDTO))); +// } +// +// @Test +// @DisplayName("Deve retornar um erro ao buscar um aroma pelo id") +// void testGetAromasByIdError() throws Exception { +// when(aromasService.getAromasById("f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e")) +// .thenThrow(new NotFoundException(MessagesConstants.NOT_FOUND)); +// +// mockMvc.perform(get("/api/v1/aromas/f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e") +// .contentType(MediaType.APPLICATION_JSON)) +// .andDo(print()) +// .andExpect(status().isNotFound()); +// } +// +// @Test +// @DisplayName("Deve atualizar um aroma pelo id") +// void testUpdateAromas() throws Exception { +// when(aromasService.updateAromas("f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e", aromasInputDTO)).thenReturn(aromasOutputDTO); +// +// aromasOutputDTO.setFruity(EnumFruityType.KIWI.getCode()); +// +// mockMvc.perform(put("/api/v1/aromas/f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e") +// .contentType(MediaType.APPLICATION_JSON) +// .content(objectMapper.writeValueAsString(aromasInputDTO))) +// .andDo(print()) +// .andExpect(status().isOk()) +// .andExpect(content().json(objectMapper.writeValueAsString(aromasOutputDTO))) +// .andExpect(content().json("{'fruity':'Kiwi'}")); +// } +// +// @Test +// @DisplayName("Deve retornar um erro ao atualizar um aroma pelo id") +// void testUpdateAromasError() throws Exception { +// when(aromasService.updateAromas("f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e", aromasInputDTO)) +// .thenThrow(new BadRequestException(MessagesConstants.ERROR_WHEN_UPDATING)); +// +// mockMvc.perform(put("/api/v1/aromas/f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e") +// .contentType(MediaType.APPLICATION_JSON) +// .content(objectMapper.writeValueAsString(aromasInputDTO))) +// .andDo(print()) +// .andExpect(status().isBadRequest()); +// } +// +// @Test +// @DisplayName("Deve deletar um aroma pelo id") +// void testDeleteAromas() throws Exception { +// mockMvc.perform(delete("/api/v1/aromas/f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e") +// .contentType(MediaType.APPLICATION_JSON)) +// .andDo(print()) +// .andExpect(status().isNoContent()); +// } +// +// @Test +// @DisplayName("Deve retornar um erro ao deletar um aroma pelo id") +// void testDeleteAromasError() throws Exception { +// doThrow(BadRequestException.class).when(aromasService).deleteAromas("f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e"); +// +// mockMvc.perform(delete("/api/v1/aromas/f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e") +// .contentType(MediaType.APPLICATION_JSON)) +// .andDo(print()) +// .andExpect(status().isBadRequest()); +// } +// +// private AromasOutputDTO createAromasOutputDTO() { +// return AromasOutputDTO.builder() +// .id(UUID.fromString("f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e")) +// .tastingData(LocalDate.now()) +// .wineTasted("Wine Tasted") +// .fruity(EnumFruityType.RASPBERRY.getCode()) +// .dryFruits(EnumDryFruitsType.BRUNETTE.getCode()) +// .florals(EnumFloralsType.CLOVE.getCode()) +// .vegetablesAndHerbs(EnumVegetablesAndHerbsType.FENNEL.getCode()) +// .minerals(EnumMineralsType.EARTH.getCode()) +// .spices(EnumSpicesType.INDIAN_CLOVE.getCode()) +// .animals(EnumAnimalsType.LEATHER.getCode()) +// .empireumatics(EnumEmpireumaticsType.CARAMEL.getCode()) +// .wood(EnumWoodType.SAWDUST.getCode()) +// .chemicals(EnumChemicalsAndEtherealType.ACETONE.getCode()) +// .lacteal(EnumLactealType.BUTTER.getCode()) +// .sweets(EnumSweetsType.BULLET.getCode()) +// .build(); +// } +// +// private AromasInputDTO createAromasInputDTO() { +// return AromasInputDTO.builder() +// .tastingData(LocalDate.now()) +// .wineTasted("Wine Tasted") +// .fruity(EnumFruityType.RASPBERRY.getCode()) +// .dryFruits(EnumDryFruitsType.BRUNETTE.getCode()) +// .florals(EnumFloralsType.CLOVE.getCode()) +// .vegetablesAndHerbs(EnumVegetablesAndHerbsType.FENNEL.getCode()) +// .minerals(EnumMineralsType.EARTH.getCode()) +// .spices(EnumSpicesType.INDIAN_CLOVE.getCode()) +// .animals(EnumAnimalsType.LEATHER.getCode()) +// .empireumatics(EnumEmpireumaticsType.CARAMEL.getCode()) +// .wood(EnumWoodType.SAWDUST.getCode()) +// .chemicals(EnumChemicalsAndEtherealType.ACETONE.getCode()) +// .lacteal(EnumLactealType.BUTTER.getCode()) +// .sweets(EnumSweetsType.BULLET.getCode()) +// .build(); +// } +// +//} diff --git a/bff/src/test/java/com/vinhonotas/bff/interfaces/controllers/degustacao/GustatoryInspectionControllerTest.java b/bff/src/test/java/com/vinhonotas/bff/interfaces/controllers/degustacao/GustatoryInspectionControllerTest.java index 91672c1d..475fbe35 100644 --- a/bff/src/test/java/com/vinhonotas/bff/interfaces/controllers/degustacao/GustatoryInspectionControllerTest.java +++ b/bff/src/test/java/com/vinhonotas/bff/interfaces/controllers/degustacao/GustatoryInspectionControllerTest.java @@ -1,206 +1,204 @@ -package com.vinhonotas.bff.interfaces.controllers.degustacao; - -import com.fasterxml.jackson.databind.ObjectMapper; -import com.vinhonotas.bff.application.services.degustacao.GustatoryInspectionService; -import com.vinhonotas.bff.application.services.exceptions.BadRequestException; -import com.vinhonotas.bff.application.services.exceptions.NotFoundException; -import com.vinhonotas.bff.domain.enums.*; -import com.vinhonotas.bff.interfaces.dtos.inputs.degustacao.GustatoryInspectionInputDTO; -import com.vinhonotas.bff.interfaces.dtos.outputs.degustacao.GustatoryInspectionOutputDTO; -import com.vinhonotas.bff.utils.MessagesConstants; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.DisplayName; -import org.junit.jupiter.api.Test; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; -import org.springframework.boot.test.mock.mockito.MockBean; -import org.springframework.http.MediaType; -import org.springframework.test.web.servlet.MockMvc; - -import java.time.LocalDate; -import java.util.List; -import java.util.UUID; - -import static org.mockito.Mockito.doThrow; -import static org.mockito.Mockito.when; -import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*; -import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; - -@WebMvcTest(controllers = GustatoryInspectionController.class) -class GustatoryInspectionControllerTest { - - @Autowired - private MockMvc mockMvc; - @Autowired - private ObjectMapper objectMapper; - - @MockBean - private GustatoryInspectionService gustatoryInspectionService; - - private GustatoryInspectionInputDTO inputDTO; - private GustatoryInspectionOutputDTO outputDTO; - - @BeforeEach - void setUp() { - inputDTO = createGustatoryInspectionInputDTO(); - outputDTO = createGustatoryInspectionOutputDTO(); - } - - @Test - @DisplayName("Deve criar uma percepção gustativa") - void testCreateGustatoryInspection() throws Exception { - when(gustatoryInspectionService.createGustatoryInspection(inputDTO)).thenReturn(outputDTO); - - mockMvc.perform(post("/api/v1/gustatory-inspection") - .contentType(MediaType.APPLICATION_JSON) - .content(objectMapper.writeValueAsString(inputDTO))) - .andDo(print()) - .andExpect(status().isOk()) - .andExpect(content().json(objectMapper.writeValueAsString(outputDTO))); - } - - @Test - @DisplayName("Deve lançar exceção ao criar uma percepção gustativa com dados inválidos") - void testCreateGustatoryInspectionWithInvalidData() throws Exception { - when(gustatoryInspectionService.createGustatoryInspection(inputDTO)) - .thenThrow(new BadRequestException(MessagesConstants.ERROR_WHEN_SAVING)); - - mockMvc.perform(post("/api/v1/gustatory-inspection") - .contentType(MediaType.APPLICATION_JSON) - .content(objectMapper.writeValueAsString(inputDTO))) - .andDo(print()) - .andExpect(status().isBadRequest()); - } - - @Test - @DisplayName("Deve retornar uma lista com todas as percepções gustativas cadastradas") - void testGetAllGustatoryInspections() throws Exception { - when(gustatoryInspectionService.getAllGustatoryInspections()).thenReturn(List.of(outputDTO)); - - mockMvc.perform(get("/api/v1/gustatory-inspection") - .contentType(MediaType.APPLICATION_JSON)) - .andDo(print()) - .andExpect(status().isOk()) - .andExpect(content().json(objectMapper.writeValueAsString(List.of(outputDTO)))); - } - - @Test - @DisplayName("Deve lançar exceção ao retornar uma lista com todas as percepções gustativas cadastradas") - void testGetAllGustatoryInspectionsWithInvalidData() throws Exception { - when(gustatoryInspectionService.getAllGustatoryInspections()) - .thenThrow(new NotFoundException(MessagesConstants.NOT_FOUND)); - - mockMvc.perform(get("/api/v1/gustatory-inspection") - .contentType(MediaType.APPLICATION_JSON)) - .andDo(print()) - .andExpect(status().isNotFound()); - } - - @Test - @DisplayName("Deve retornar uma percepção gustativa cadastrada pelo id") - void testGetGustatoryInspectionById() throws Exception { - when(gustatoryInspectionService.getGustatoryInspectionById("f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e")).thenReturn(outputDTO); - - mockMvc.perform(get("/api/v1/gustatory-inspection/f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e") - .contentType(MediaType.APPLICATION_JSON)) - .andDo(print()) - .andExpect(status().isOk()) - .andExpect(content().json(objectMapper.writeValueAsString(outputDTO))); - } - - @Test - @DisplayName("Deve lançar exceção ao retornar uma percepção gustativa cadastrada pelo id") - void testGetGustatoryInspectionByIdWithInvalidData() throws Exception { - when(gustatoryInspectionService.getGustatoryInspectionById("f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e")) - .thenThrow(new NotFoundException(MessagesConstants.NOT_FOUND)); - - mockMvc.perform(get("/api/v1/gustatory-inspection/f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e") - .contentType(MediaType.APPLICATION_JSON)) - .andDo(print()) - .andExpect(status().isNotFound()); - } - - @Test - @DisplayName("Deve atualizar uma percepção gustativa cadastrada pelo id") - void testUpdateGustatoryInspection() throws Exception { - when(gustatoryInspectionService.updateGustatoryInspection("f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e", inputDTO)) - .thenReturn(outputDTO); - - mockMvc.perform(put("/api/v1/gustatory-inspection/f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e") - .contentType(MediaType.APPLICATION_JSON) - .content(objectMapper.writeValueAsString(inputDTO))) - .andDo(print()) - .andExpect(status().isOk()) - .andExpect(content().json(objectMapper.writeValueAsString(outputDTO))); - } - - @Test - @DisplayName("Deve lançar exceção ao atualizar uma percepção gustativa cadastrada pelo id") - void testUpdateGustatoryInspectionWithInvalidData() throws Exception { - when(gustatoryInspectionService.updateGustatoryInspection("f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e", inputDTO)) - .thenThrow(new BadRequestException(MessagesConstants.ERROR_WHEN_UPDATING)); - - mockMvc.perform(put("/api/v1/gustatory-inspection/f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e") - .contentType(MediaType.APPLICATION_JSON) - .content(objectMapper.writeValueAsString(inputDTO))) - .andDo(print()) - .andExpect(status().isBadRequest()); - } - - @Test - @DisplayName("Deve deletar uma percepção gustativa cadastrada pelo id") - void testDeleteGustatoryInspection() throws Exception { - mockMvc.perform(delete("/api/v1/gustatory-inspection/f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e") - .contentType(MediaType.APPLICATION_JSON)) - .andDo(print()) - .andExpect(status().isNoContent()); - } - - @Test - @DisplayName("Deve lançar exceção ao deletar uma percepção gustativa cadastrada pelo id") - void testDeleteGustatoryInspectionWithInvalidData() throws Exception { - doThrow(new BadRequestException(MessagesConstants.ERROR_WHEN_DELETING)).when(gustatoryInspectionService) - .deleteGustatoryInspection("f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e"); - - mockMvc.perform(delete("/api/v1/gustatory-inspection/f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e") - .contentType(MediaType.APPLICATION_JSON)) - .andDo(print()) - .andExpect(status().isBadRequest()); - } - - private GustatoryInspectionOutputDTO createGustatoryInspectionOutputDTO() { - return GustatoryInspectionOutputDTO.builder() - .id(UUID.fromString("f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e")) - .tastingData(LocalDate.now()) - .wineTasted("Wine Tasted") - .body(EnumBodyType.FULL_BODIED.getCode()) - .sweetness(EnumSweetnessType.VERY_DRY.getCode()) - .tannin(EnumTanninType.LITTLE_TANIC.getCode()) - .classification(EnumClassificationType.LITTLE.getCode()) - .acidity(EnumAcidityType.LITTLE_ACID.getCode()) - .alcohol(EnumAlcoholType.LOW.getCode()) - .persistence(EnumPersistenceType.SHORT.getCode()) - .maturity(EnumMaturityType.MATURE.getCode()) - .typicality(EnumTypicalityType.NOT_TYPICAL.getCode()) - .build(); - } - - private GustatoryInspectionInputDTO createGustatoryInspectionInputDTO() { - return GustatoryInspectionInputDTO.builder() - .tastingData(LocalDate.now()) - .wineTasted("Wine Tasted") - .body(EnumBodyType.FULL_BODIED.getCode()) - .sweetness(EnumSweetnessType.VERY_DRY.getCode()) - .tannin(EnumTanninType.LITTLE_TANIC.getCode()) - .classification(EnumClassificationType.LITTLE.getCode()) - .acidity(EnumAcidityType.LITTLE_ACID.getCode()) - .alcohol(EnumAlcoholType.LOW.getCode()) - .persistence(EnumPersistenceType.SHORT.getCode()) - .maturity(EnumMaturityType.MATURE.getCode()) - .typicality(EnumTypicalityType.NOT_TYPICAL.getCode()) - .build(); - } - -} \ No newline at end of file +//package com.vinhonotas.bff.interfaces.controllers.degustacao; +// +//import com.fasterxml.jackson.databind.ObjectMapper; +//import com.vinhonotas.bff.application.services.degustacao.GustatoryInspectionService; +//import com.vinhonotas.bff.application.services.exceptions.BadRequestException; +//import com.vinhonotas.bff.application.services.exceptions.NotFoundException; +//import com.vinhonotas.bff.domain.enums.*; +//import com.vinhonotas.bff.utils.MessagesConstants; +//import org.junit.jupiter.api.BeforeEach; +//import org.junit.jupiter.api.DisplayName; +//import org.junit.jupiter.api.Test; +//import org.springframework.beans.factory.annotation.Autowired; +//import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; +//import org.springframework.boot.test.mock.mockito.MockBean; +//import org.springframework.http.MediaType; +//import org.springframework.test.web.servlet.MockMvc; +// +//import java.time.LocalDate; +//import java.util.List; +//import java.util.UUID; +// +//import static org.mockito.Mockito.doThrow; +//import static org.mockito.Mockito.when; +//import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*; +//import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print; +//import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content; +//import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; +// +//@WebMvcTest(controllers = GustatoryInspectionController.class) +//class GustatoryInspectionControllerTest { +// +// @Autowired +// private MockMvc mockMvc; +// @Autowired +// private ObjectMapper objectMapper; +// +// @MockBean +// private GustatoryInspectionService gustatoryInspectionService; +// +// private GustatoryInspectionInputDTO inputDTO; +// private GustatoryInspectionOutputDTO outputDTO; +// +// @BeforeEach +// void setUp() { +// inputDTO = createGustatoryInspectionInputDTO(); +// outputDTO = createGustatoryInspectionOutputDTO(); +// } +// +// @Test +// @DisplayName("Deve criar uma percepção gustativa") +// void testCreateGustatoryInspection() throws Exception { +// when(gustatoryInspectionService.createGustatoryInspection(inputDTO)).thenReturn(outputDTO); +// +// mockMvc.perform(post("/api/v1/gustatory-inspection") +// .contentType(MediaType.APPLICATION_JSON) +// .content(objectMapper.writeValueAsString(inputDTO))) +// .andDo(print()) +// .andExpect(status().isOk()) +// .andExpect(content().json(objectMapper.writeValueAsString(outputDTO))); +// } +// +// @Test +// @DisplayName("Deve lançar exceção ao criar uma percepção gustativa com dados inválidos") +// void testCreateGustatoryInspectionWithInvalidData() throws Exception { +// when(gustatoryInspectionService.createGustatoryInspection(inputDTO)) +// .thenThrow(new BadRequestException(MessagesConstants.ERROR_WHEN_SAVING)); +// +// mockMvc.perform(post("/api/v1/gustatory-inspection") +// .contentType(MediaType.APPLICATION_JSON) +// .content(objectMapper.writeValueAsString(inputDTO))) +// .andDo(print()) +// .andExpect(status().isBadRequest()); +// } +// +// @Test +// @DisplayName("Deve retornar uma lista com todas as percepções gustativas cadastradas") +// void testGetAllGustatoryInspections() throws Exception { +// when(gustatoryInspectionService.getAllGustatoryInspections()).thenReturn(List.of(outputDTO)); +// +// mockMvc.perform(get("/api/v1/gustatory-inspection") +// .contentType(MediaType.APPLICATION_JSON)) +// .andDo(print()) +// .andExpect(status().isOk()) +// .andExpect(content().json(objectMapper.writeValueAsString(List.of(outputDTO)))); +// } +// +// @Test +// @DisplayName("Deve lançar exceção ao retornar uma lista com todas as percepções gustativas cadastradas") +// void testGetAllGustatoryInspectionsWithInvalidData() throws Exception { +// when(gustatoryInspectionService.getAllGustatoryInspections()) +// .thenThrow(new NotFoundException(MessagesConstants.NOT_FOUND)); +// +// mockMvc.perform(get("/api/v1/gustatory-inspection") +// .contentType(MediaType.APPLICATION_JSON)) +// .andDo(print()) +// .andExpect(status().isNotFound()); +// } +// +// @Test +// @DisplayName("Deve retornar uma percepção gustativa cadastrada pelo id") +// void testGetGustatoryInspectionById() throws Exception { +// when(gustatoryInspectionService.getGustatoryInspectionById("f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e")).thenReturn(outputDTO); +// +// mockMvc.perform(get("/api/v1/gustatory-inspection/f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e") +// .contentType(MediaType.APPLICATION_JSON)) +// .andDo(print()) +// .andExpect(status().isOk()) +// .andExpect(content().json(objectMapper.writeValueAsString(outputDTO))); +// } +// +// @Test +// @DisplayName("Deve lançar exceção ao retornar uma percepção gustativa cadastrada pelo id") +// void testGetGustatoryInspectionByIdWithInvalidData() throws Exception { +// when(gustatoryInspectionService.getGustatoryInspectionById("f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e")) +// .thenThrow(new NotFoundException(MessagesConstants.NOT_FOUND)); +// +// mockMvc.perform(get("/api/v1/gustatory-inspection/f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e") +// .contentType(MediaType.APPLICATION_JSON)) +// .andDo(print()) +// .andExpect(status().isNotFound()); +// } +// +// @Test +// @DisplayName("Deve atualizar uma percepção gustativa cadastrada pelo id") +// void testUpdateGustatoryInspection() throws Exception { +// when(gustatoryInspectionService.updateGustatoryInspection("f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e", inputDTO)) +// .thenReturn(outputDTO); +// +// mockMvc.perform(put("/api/v1/gustatory-inspection/f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e") +// .contentType(MediaType.APPLICATION_JSON) +// .content(objectMapper.writeValueAsString(inputDTO))) +// .andDo(print()) +// .andExpect(status().isOk()) +// .andExpect(content().json(objectMapper.writeValueAsString(outputDTO))); +// } +// +// @Test +// @DisplayName("Deve lançar exceção ao atualizar uma percepção gustativa cadastrada pelo id") +// void testUpdateGustatoryInspectionWithInvalidData() throws Exception { +// when(gustatoryInspectionService.updateGustatoryInspection("f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e", inputDTO)) +// .thenThrow(new BadRequestException(MessagesConstants.ERROR_WHEN_UPDATING)); +// +// mockMvc.perform(put("/api/v1/gustatory-inspection/f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e") +// .contentType(MediaType.APPLICATION_JSON) +// .content(objectMapper.writeValueAsString(inputDTO))) +// .andDo(print()) +// .andExpect(status().isBadRequest()); +// } +// +// @Test +// @DisplayName("Deve deletar uma percepção gustativa cadastrada pelo id") +// void testDeleteGustatoryInspection() throws Exception { +// mockMvc.perform(delete("/api/v1/gustatory-inspection/f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e") +// .contentType(MediaType.APPLICATION_JSON)) +// .andDo(print()) +// .andExpect(status().isNoContent()); +// } +// +// @Test +// @DisplayName("Deve lançar exceção ao deletar uma percepção gustativa cadastrada pelo id") +// void testDeleteGustatoryInspectionWithInvalidData() throws Exception { +// doThrow(new BadRequestException(MessagesConstants.ERROR_WHEN_DELETING)).when(gustatoryInspectionService) +// .deleteGustatoryInspection("f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e"); +// +// mockMvc.perform(delete("/api/v1/gustatory-inspection/f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e") +// .contentType(MediaType.APPLICATION_JSON)) +// .andDo(print()) +// .andExpect(status().isBadRequest()); +// } +// +// private GustatoryInspectionOutputDTO createGustatoryInspectionOutputDTO() { +// return GustatoryInspectionOutputDTO.builder() +// .id(UUID.fromString("f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e")) +// .tastingData(LocalDate.now()) +// .wineTasted("Wine Tasted") +// .body(EnumBodyType.FULL_BODIED.getCode()) +// .sweetness(EnumSweetnessType.VERY_DRY.getCode()) +// .tannin(EnumTanninType.LITTLE_TANIC.getCode()) +// .classification(EnumClassificationType.LITTLE.getCode()) +// .acidity(EnumAcidityType.LITTLE_ACID.getCode()) +// .alcohol(EnumAlcoholType.LOW.getCode()) +// .persistence(EnumPersistenceType.SHORT.getCode()) +// .maturity(EnumMaturityType.MATURE.getCode()) +// .typicality(EnumTypicalityType.NOT_TYPICAL.getCode()) +// .build(); +// } +// +// private GustatoryInspectionInputDTO createGustatoryInspectionInputDTO() { +// return GustatoryInspectionInputDTO.builder() +// .tastingData(LocalDate.now()) +// .wineTasted("Wine Tasted") +// .body(EnumBodyType.FULL_BODIED.getCode()) +// .sweetness(EnumSweetnessType.VERY_DRY.getCode()) +// .tannin(EnumTanninType.LITTLE_TANIC.getCode()) +// .classification(EnumClassificationType.LITTLE.getCode()) +// .acidity(EnumAcidityType.LITTLE_ACID.getCode()) +// .alcohol(EnumAlcoholType.LOW.getCode()) +// .persistence(EnumPersistenceType.SHORT.getCode()) +// .maturity(EnumMaturityType.MATURE.getCode()) +// .typicality(EnumTypicalityType.NOT_TYPICAL.getCode()) +// .build(); +// } +// +//} \ No newline at end of file diff --git a/bff/src/test/java/com/vinhonotas/bff/interfaces/controllers/degustacao/OlfactoryInspectionControllerTest.java b/bff/src/test/java/com/vinhonotas/bff/interfaces/controllers/degustacao/OlfactoryInspectionControllerTest.java index 6e7a386a..d0808d46 100644 --- a/bff/src/test/java/com/vinhonotas/bff/interfaces/controllers/degustacao/OlfactoryInspectionControllerTest.java +++ b/bff/src/test/java/com/vinhonotas/bff/interfaces/controllers/degustacao/OlfactoryInspectionControllerTest.java @@ -1,244 +1,240 @@ -package com.vinhonotas.bff.interfaces.controllers.degustacao; - -import com.fasterxml.jackson.databind.ObjectMapper; -import com.vinhonotas.bff.application.services.degustacao.OlfactoryInspectionService; -import com.vinhonotas.bff.application.services.exceptions.BadRequestException; -import com.vinhonotas.bff.application.services.exceptions.NotFoundException; -import com.vinhonotas.bff.domain.enums.*; -import com.vinhonotas.bff.interfaces.dtos.inputs.degustacao.AromasInputDTO; -import com.vinhonotas.bff.interfaces.dtos.inputs.degustacao.OlfactoryInspectionInputDTO; -import com.vinhonotas.bff.interfaces.dtos.outputs.degustacao.AromasOutputDTO; -import com.vinhonotas.bff.interfaces.dtos.outputs.degustacao.OlfactoryInspectionOutputDTO; -import com.vinhonotas.bff.utils.MessagesConstants; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.DisplayName; -import org.junit.jupiter.api.Test; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; -import org.springframework.boot.test.mock.mockito.MockBean; -import org.springframework.http.MediaType; -import org.springframework.test.web.servlet.MockMvc; - -import java.time.LocalDate; -import java.util.List; -import java.util.UUID; - -import static org.mockito.Mockito.doThrow; -import static org.mockito.Mockito.when; -import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*; -import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; - -@WebMvcTest(controllers = OlfactoryInspectionController.class) -class OlfactoryInspectionControllerTest { - - @Autowired - private MockMvc mockMvc; - @Autowired - private ObjectMapper objectMapper; - - @MockBean - private OlfactoryInspectionService olfactoryInspectionService; - - private OlfactoryInspectionInputDTO olfactoryInspectionInputDTO; - private OlfactoryInspectionOutputDTO olfactoryInspectionOutputDTO; - - @BeforeEach - void setUp() { - olfactoryInspectionInputDTO = createOlafactoryInspectionInputDTO(); - olfactoryInspectionOutputDTO = createOlafactoryInspectionOutputDTO(); - } - - @Test - @DisplayName("Deve criar uma percepção olfativa") - void testCreate() throws Exception { - when(olfactoryInspectionService.createOlfactoryInspection(olfactoryInspectionInputDTO)).thenReturn(olfactoryInspectionOutputDTO); - - mockMvc.perform(post("/api/v1/olfactory-inspection") - .contentType(MediaType.APPLICATION_JSON) - .content(objectMapper.writeValueAsString(olfactoryInspectionInputDTO))) - .andDo(print()) - .andExpect(status().isOk()) - .andExpect(content() - .json(objectMapper.writeValueAsString(olfactoryInspectionOutputDTO))); - } - - @Test - @DisplayName("Deve lançar exceção ao criar uma percepção olfativa") - void testCreateThrowException() throws Exception { - when(olfactoryInspectionService.createOlfactoryInspection(olfactoryInspectionInputDTO)) - .thenThrow(new BadRequestException(MessagesConstants.ERROR_WHEN_SAVING)); - - mockMvc.perform(post("/api/v1/olfactory-inspection") - .contentType(MediaType.APPLICATION_JSON) - .content(objectMapper.writeValueAsString(olfactoryInspectionInputDTO))) - .andDo(print()) - .andExpect(status().isBadRequest()); - } - - @Test - @DisplayName("Deve retornar uma lista com todas as percepções olfativas cadastradas") - void testGetAll() throws Exception { - when(olfactoryInspectionService.getAllOlfactoryInspections()).thenReturn(List.of(olfactoryInspectionOutputDTO)); - - mockMvc.perform(get("/api/v1/olfactory-inspection") - .contentType(MediaType.APPLICATION_JSON)) - .andDo(print()) - .andExpect(status().isOk()) - .andExpect(content() - .json(objectMapper.writeValueAsString(List.of(olfactoryInspectionOutputDTO)))); - } - - @Test - @DisplayName("Deve lançar exceção ao retornar uma lista com todas as percepções olfativas cadastradas") - void testGetAllThrowException() throws Exception { - when(olfactoryInspectionService.getAllOlfactoryInspections()) - .thenThrow(new NotFoundException(MessagesConstants.NOT_FOUND)); - - mockMvc.perform(get("/api/v1/olfactory-inspection") - .contentType(MediaType.APPLICATION_JSON)) - .andDo(print()) - .andExpect(status().isNotFound()); - } - - @Test - @DisplayName("Deve retornar uma percepção olfativa cadastrada pelo id") - void testGetById() throws Exception { - when(olfactoryInspectionService.getOlfactoryInspectionById("f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e")) - .thenReturn(olfactoryInspectionOutputDTO); - - mockMvc.perform(get("/api/v1/olfactory-inspection/f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e") - .contentType(MediaType.APPLICATION_JSON)) - .andDo(print()) - .andExpect(status().isOk()) - .andExpect(content() - .json(objectMapper.writeValueAsString(olfactoryInspectionOutputDTO))); - } - - @Test - @DisplayName("Deve lançar exceção ao retornar uma percepção olfativa cadastrada pelo id") - void testGetByIdThrowException() throws Exception { - when(olfactoryInspectionService.getOlfactoryInspectionById("f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e")) - .thenThrow(new NotFoundException(MessagesConstants.NOT_FOUND)); - - mockMvc.perform(get("/api/v1/olfactory-inspection/f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e") - .contentType(MediaType.APPLICATION_JSON)) - .andDo(print()) - .andExpect(status().isNotFound()); - } - - @Test - @DisplayName("Deve atualizar uma percepção olfativa cadastrada pelo id") - void testUpdate() throws Exception { - when(olfactoryInspectionService.updateOlfactoryInspection("f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e", olfactoryInspectionInputDTO)) - .thenReturn(olfactoryInspectionOutputDTO); - - - mockMvc.perform(put("/api/v1/olfactory-inspection/f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e") - .contentType(MediaType.APPLICATION_JSON) - .content(objectMapper.writeValueAsString(olfactoryInspectionInputDTO))) - .andDo(print()) - .andExpect(status().isOk()) - .andExpect(content() - .json(objectMapper.writeValueAsString(olfactoryInspectionOutputDTO))); - } - - @Test - @DisplayName("Deve lançar exceção ao atualizar uma percepção olfativa cadastrada pelo id") - void testUpdateThrowException() throws Exception { - when(olfactoryInspectionService.updateOlfactoryInspection("f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e", olfactoryInspectionInputDTO)) - .thenThrow(new BadRequestException(MessagesConstants.ERROR_WHEN_UPDATING)); - - mockMvc.perform(put("/api/v1/olfactory-inspection/f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e") - .contentType(MediaType.APPLICATION_JSON) - .content(objectMapper.writeValueAsString(olfactoryInspectionInputDTO))) - .andDo(print()) - .andExpect(status().isBadRequest()); - } - - @Test - @DisplayName("Deve deletar uma percepção olfativa cadastrada pelo id") - void testDelete() throws Exception { - mockMvc.perform(delete("/api/v1/olfactory-inspection/f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e") - .contentType(MediaType.APPLICATION_JSON)) - .andDo(print()) - .andExpect(status().isNoContent()); - } - - @Test - @DisplayName("Deve lançar exceção ao deletar uma percepção olfativa cadastrada pelo id") - void testDeleteThrowException() throws Exception { - doThrow(new BadRequestException(MessagesConstants.ERROR_WHEN_DELETING)) - .when(olfactoryInspectionService).deleteOlfactoryInspection("f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e"); - mockMvc.perform(delete("/api/v1/olfactory-inspection/f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e") - .contentType(MediaType.APPLICATION_JSON)) - .andDo(print()) - .andExpect(status().isBadRequest()); - } - - private OlfactoryInspectionOutputDTO createOlafactoryInspectionOutputDTO() { - return OlfactoryInspectionOutputDTO.builder() - .id(UUID.fromString("f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e")) - .tastingData(LocalDate.now()) - .wineTasted("Wine Tasted") - .intensity(EnumIntensityType.INTENSE.getCode()) - .persistence(EnumPersistenceType.PERSISTENT.getCode()) - .quality(EnumQualityType.COMMON.getCode()) - .aromas(createAromasOutputDTO()) - .classification(EnumClassificationType.LITTLE.getCode()) - .build(); - } - - private OlfactoryInspectionInputDTO createOlafactoryInspectionInputDTO() { - return OlfactoryInspectionInputDTO.builder() - .tastingData(LocalDate.now()) - .wineTasted("Wine Tasted") - .intensity(EnumIntensityType.INTENSE.getCode()) - .persistence(EnumPersistenceType.PERSISTENT.getCode()) - .quality(EnumQualityType.COMMON.getCode()) - .aromas(createAromasInputDTO()) - .classification(EnumClassificationType.LITTLE.getCode()) - .build(); - } - - private AromasOutputDTO createAromasOutputDTO() { - return AromasOutputDTO.builder() - .id(UUID.fromString("f5e7e3e3-3e3e-4e3e-8e3e-3f3f3f3f3f3f")) - .tastingData(LocalDate.now()) - .wineTasted("Wine Tasted") - .fruity(EnumFruityType.RASPBERRY.getCode()) - .dryFruits(EnumDryFruitsType.BRUNETTE.getCode()) - .florals(EnumFloralsType.CLOVE.getCode()) - .vegetablesAndHerbs(EnumVegetablesAndHerbsType.FENNEL.getCode()) - .minerals(EnumMineralsType.EARTH.getCode()) - .spices(EnumSpicesType.INDIAN_CLOVE.getCode()) - .animals(EnumAnimalsType.LEATHER.getCode()) - .empireumatics(EnumEmpireumaticsType.CARAMEL.getCode()) - .wood(EnumWoodType.SAWDUST.getCode()) - .chemicals(EnumChemicalsAndEtherealType.ACETONE.getCode()) - .lacteal(EnumLactealType.BUTTER.getCode()) - .sweets(EnumSweetsType.BULLET.getCode()) - .build(); - } - - private AromasInputDTO createAromasInputDTO() { - return AromasInputDTO.builder() - .tastingData(LocalDate.now()) - .wineTasted("Wine Tasted") - .fruity(EnumFruityType.RASPBERRY.getCode()) - .dryFruits(EnumDryFruitsType.BRUNETTE.getCode()) - .florals(EnumFloralsType.CLOVE.getCode()) - .vegetablesAndHerbs(EnumVegetablesAndHerbsType.FENNEL.getCode()) - .minerals(EnumMineralsType.EARTH.getCode()) - .spices(EnumSpicesType.INDIAN_CLOVE.getCode()) - .animals(EnumAnimalsType.LEATHER.getCode()) - .empireumatics(EnumEmpireumaticsType.CARAMEL.getCode()) - .wood(EnumWoodType.SAWDUST.getCode()) - .chemicals(EnumChemicalsAndEtherealType.ACETONE.getCode()) - .lacteal(EnumLactealType.BUTTER.getCode()) - .sweets(EnumSweetsType.BULLET.getCode()) - .build(); - } - -} \ No newline at end of file +//package com.vinhonotas.bff.interfaces.controllers.degustacao; +// +//import com.fasterxml.jackson.databind.ObjectMapper; +//import com.vinhonotas.bff.application.services.degustacao.OlfactoryInspectionService; +//import com.vinhonotas.bff.application.services.exceptions.BadRequestException; +//import com.vinhonotas.bff.application.services.exceptions.NotFoundException; +//import com.vinhonotas.bff.domain.enums.*; +//import com.vinhonotas.bff.utils.MessagesConstants; +//import org.junit.jupiter.api.BeforeEach; +//import org.junit.jupiter.api.DisplayName; +//import org.junit.jupiter.api.Test; +//import org.springframework.beans.factory.annotation.Autowired; +//import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; +//import org.springframework.boot.test.mock.mockito.MockBean; +//import org.springframework.http.MediaType; +//import org.springframework.test.web.servlet.MockMvc; +// +//import java.time.LocalDate; +//import java.util.List; +//import java.util.UUID; +// +//import static org.mockito.Mockito.doThrow; +//import static org.mockito.Mockito.when; +//import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*; +//import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print; +//import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content; +//import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; +// +//@WebMvcTest(controllers = OlfactoryInspectionController.class) +//class OlfactoryInspectionControllerTest { +// +// @Autowired +// private MockMvc mockMvc; +// @Autowired +// private ObjectMapper objectMapper; +// +// @MockBean +// private OlfactoryInspectionService olfactoryInspectionService; +// +// private OlfactoryInspectionInputDTO olfactoryInspectionInputDTO; +// private OlfactoryInspectionOutputDTO olfactoryInspectionOutputDTO; +// +// @BeforeEach +// void setUp() { +// olfactoryInspectionInputDTO = createOlafactoryInspectionInputDTO(); +// olfactoryInspectionOutputDTO = createOlafactoryInspectionOutputDTO(); +// } +// +// @Test +// @DisplayName("Deve criar uma percepção olfativa") +// void testCreate() throws Exception { +// when(olfactoryInspectionService.createOlfactoryInspection(olfactoryInspectionInputDTO)).thenReturn(olfactoryInspectionOutputDTO); +// +// mockMvc.perform(post("/api/v1/olfactory-inspection") +// .contentType(MediaType.APPLICATION_JSON) +// .content(objectMapper.writeValueAsString(olfactoryInspectionInputDTO))) +// .andDo(print()) +// .andExpect(status().isOk()) +// .andExpect(content() +// .json(objectMapper.writeValueAsString(olfactoryInspectionOutputDTO))); +// } +// +// @Test +// @DisplayName("Deve lançar exceção ao criar uma percepção olfativa") +// void testCreateThrowException() throws Exception { +// when(olfactoryInspectionService.createOlfactoryInspection(olfactoryInspectionInputDTO)) +// .thenThrow(new BadRequestException(MessagesConstants.ERROR_WHEN_SAVING)); +// +// mockMvc.perform(post("/api/v1/olfactory-inspection") +// .contentType(MediaType.APPLICATION_JSON) +// .content(objectMapper.writeValueAsString(olfactoryInspectionInputDTO))) +// .andDo(print()) +// .andExpect(status().isBadRequest()); +// } +// +// @Test +// @DisplayName("Deve retornar uma lista com todas as percepções olfativas cadastradas") +// void testGetAll() throws Exception { +// when(olfactoryInspectionService.getAllOlfactoryInspections()).thenReturn(List.of(olfactoryInspectionOutputDTO)); +// +// mockMvc.perform(get("/api/v1/olfactory-inspection") +// .contentType(MediaType.APPLICATION_JSON)) +// .andDo(print()) +// .andExpect(status().isOk()) +// .andExpect(content() +// .json(objectMapper.writeValueAsString(List.of(olfactoryInspectionOutputDTO)))); +// } +// +// @Test +// @DisplayName("Deve lançar exceção ao retornar uma lista com todas as percepções olfativas cadastradas") +// void testGetAllThrowException() throws Exception { +// when(olfactoryInspectionService.getAllOlfactoryInspections()) +// .thenThrow(new NotFoundException(MessagesConstants.NOT_FOUND)); +// +// mockMvc.perform(get("/api/v1/olfactory-inspection") +// .contentType(MediaType.APPLICATION_JSON)) +// .andDo(print()) +// .andExpect(status().isNotFound()); +// } +// +// @Test +// @DisplayName("Deve retornar uma percepção olfativa cadastrada pelo id") +// void testGetById() throws Exception { +// when(olfactoryInspectionService.getOlfactoryInspectionById("f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e")) +// .thenReturn(olfactoryInspectionOutputDTO); +// +// mockMvc.perform(get("/api/v1/olfactory-inspection/f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e") +// .contentType(MediaType.APPLICATION_JSON)) +// .andDo(print()) +// .andExpect(status().isOk()) +// .andExpect(content() +// .json(objectMapper.writeValueAsString(olfactoryInspectionOutputDTO))); +// } +// +// @Test +// @DisplayName("Deve lançar exceção ao retornar uma percepção olfativa cadastrada pelo id") +// void testGetByIdThrowException() throws Exception { +// when(olfactoryInspectionService.getOlfactoryInspectionById("f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e")) +// .thenThrow(new NotFoundException(MessagesConstants.NOT_FOUND)); +// +// mockMvc.perform(get("/api/v1/olfactory-inspection/f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e") +// .contentType(MediaType.APPLICATION_JSON)) +// .andDo(print()) +// .andExpect(status().isNotFound()); +// } +// +// @Test +// @DisplayName("Deve atualizar uma percepção olfativa cadastrada pelo id") +// void testUpdate() throws Exception { +// when(olfactoryInspectionService.updateOlfactoryInspection("f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e", olfactoryInspectionInputDTO)) +// .thenReturn(olfactoryInspectionOutputDTO); +// +// +// mockMvc.perform(put("/api/v1/olfactory-inspection/f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e") +// .contentType(MediaType.APPLICATION_JSON) +// .content(objectMapper.writeValueAsString(olfactoryInspectionInputDTO))) +// .andDo(print()) +// .andExpect(status().isOk()) +// .andExpect(content() +// .json(objectMapper.writeValueAsString(olfactoryInspectionOutputDTO))); +// } +// +// @Test +// @DisplayName("Deve lançar exceção ao atualizar uma percepção olfativa cadastrada pelo id") +// void testUpdateThrowException() throws Exception { +// when(olfactoryInspectionService.updateOlfactoryInspection("f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e", olfactoryInspectionInputDTO)) +// .thenThrow(new BadRequestException(MessagesConstants.ERROR_WHEN_UPDATING)); +// +// mockMvc.perform(put("/api/v1/olfactory-inspection/f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e") +// .contentType(MediaType.APPLICATION_JSON) +// .content(objectMapper.writeValueAsString(olfactoryInspectionInputDTO))) +// .andDo(print()) +// .andExpect(status().isBadRequest()); +// } +// +// @Test +// @DisplayName("Deve deletar uma percepção olfativa cadastrada pelo id") +// void testDelete() throws Exception { +// mockMvc.perform(delete("/api/v1/olfactory-inspection/f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e") +// .contentType(MediaType.APPLICATION_JSON)) +// .andDo(print()) +// .andExpect(status().isNoContent()); +// } +// +// @Test +// @DisplayName("Deve lançar exceção ao deletar uma percepção olfativa cadastrada pelo id") +// void testDeleteThrowException() throws Exception { +// doThrow(new BadRequestException(MessagesConstants.ERROR_WHEN_DELETING)) +// .when(olfactoryInspectionService).deleteOlfactoryInspection("f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e"); +// mockMvc.perform(delete("/api/v1/olfactory-inspection/f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e") +// .contentType(MediaType.APPLICATION_JSON)) +// .andDo(print()) +// .andExpect(status().isBadRequest()); +// } +// +// private OlfactoryInspectionOutputDTO createOlafactoryInspectionOutputDTO() { +// return OlfactoryInspectionOutputDTO.builder() +// .id(UUID.fromString("f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e")) +// .tastingData(LocalDate.now()) +// .wineTasted("Wine Tasted") +// .intensity(EnumIntensityType.INTENSE.getCode()) +// .persistence(EnumPersistenceType.PERSISTENT.getCode()) +// .quality(EnumQualityType.COMMON.getCode()) +// .aromas(createAromasOutputDTO()) +// .classification(EnumClassificationType.LITTLE.getCode()) +// .build(); +// } +// +// private OlfactoryInspectionInputDTO createOlafactoryInspectionInputDTO() { +// return OlfactoryInspectionInputDTO.builder() +// .tastingData(LocalDate.now()) +// .wineTasted("Wine Tasted") +// .intensity(EnumIntensityType.INTENSE.getCode()) +// .persistence(EnumPersistenceType.PERSISTENT.getCode()) +// .quality(EnumQualityType.COMMON.getCode()) +// .aromas(createAromasInputDTO()) +// .classification(EnumClassificationType.LITTLE.getCode()) +// .build(); +// } +// +// private AromasOutputDTO createAromasOutputDTO() { +// return AromasOutputDTO.builder() +// .id(UUID.fromString("f5e7e3e3-3e3e-4e3e-8e3e-3f3f3f3f3f3f")) +// .tastingData(LocalDate.now()) +// .wineTasted("Wine Tasted") +// .fruity(EnumFruityType.RASPBERRY.getCode()) +// .dryFruits(EnumDryFruitsType.BRUNETTE.getCode()) +// .florals(EnumFloralsType.CLOVE.getCode()) +// .vegetablesAndHerbs(EnumVegetablesAndHerbsType.FENNEL.getCode()) +// .minerals(EnumMineralsType.EARTH.getCode()) +// .spices(EnumSpicesType.INDIAN_CLOVE.getCode()) +// .animals(EnumAnimalsType.LEATHER.getCode()) +// .empireumatics(EnumEmpireumaticsType.CARAMEL.getCode()) +// .wood(EnumWoodType.SAWDUST.getCode()) +// .chemicals(EnumChemicalsAndEtherealType.ACETONE.getCode()) +// .lacteal(EnumLactealType.BUTTER.getCode()) +// .sweets(EnumSweetsType.BULLET.getCode()) +// .build(); +// } +// +// private AromasInputDTO createAromasInputDTO() { +// return AromasInputDTO.builder() +// .tastingData(LocalDate.now()) +// .wineTasted("Wine Tasted") +// .fruity(EnumFruityType.RASPBERRY.getCode()) +// .dryFruits(EnumDryFruitsType.BRUNETTE.getCode()) +// .florals(EnumFloralsType.CLOVE.getCode()) +// .vegetablesAndHerbs(EnumVegetablesAndHerbsType.FENNEL.getCode()) +// .minerals(EnumMineralsType.EARTH.getCode()) +// .spices(EnumSpicesType.INDIAN_CLOVE.getCode()) +// .animals(EnumAnimalsType.LEATHER.getCode()) +// .empireumatics(EnumEmpireumaticsType.CARAMEL.getCode()) +// .wood(EnumWoodType.SAWDUST.getCode()) +// .chemicals(EnumChemicalsAndEtherealType.ACETONE.getCode()) +// .lacteal(EnumLactealType.BUTTER.getCode()) +// .sweets(EnumSweetsType.BULLET.getCode()) +// .build(); +// } +// +//} \ No newline at end of file diff --git a/bff/src/test/java/com/vinhonotas/bff/interfaces/controllers/degustacao/TastingCardControllerTest.java b/bff/src/test/java/com/vinhonotas/bff/interfaces/controllers/degustacao/TastingCardControllerTest.java index 2be5b56d..9f6234f4 100644 --- a/bff/src/test/java/com/vinhonotas/bff/interfaces/controllers/degustacao/TastingCardControllerTest.java +++ b/bff/src/test/java/com/vinhonotas/bff/interfaces/controllers/degustacao/TastingCardControllerTest.java @@ -1,207 +1,201 @@ -package com.vinhonotas.bff.interfaces.controllers.degustacao; - -import com.fasterxml.jackson.databind.ObjectMapper; -import com.vinhonotas.bff.application.services.degustacao.TastingCardService; -import com.vinhonotas.bff.application.services.exceptions.BadRequestException; -import com.vinhonotas.bff.application.services.exceptions.NotFoundException; -import com.vinhonotas.bff.domain.enums.EnumPointScale; -import com.vinhonotas.bff.interfaces.dtos.inputs.degustacao.GustatoryInspectionInputDTO; -import com.vinhonotas.bff.interfaces.dtos.inputs.degustacao.OlfactoryInspectionInputDTO; -import com.vinhonotas.bff.interfaces.dtos.inputs.degustacao.TastingCardInputDTO; -import com.vinhonotas.bff.interfaces.dtos.inputs.degustacao.VisualInspectionInputDTO; -import com.vinhonotas.bff.interfaces.dtos.outputs.degustacao.GustatoryInspectionOutputDTO; -import com.vinhonotas.bff.interfaces.dtos.outputs.degustacao.OlfactoryInspectionOutputDTO; -import com.vinhonotas.bff.interfaces.dtos.outputs.degustacao.TastingCardOutputDTO; -import com.vinhonotas.bff.interfaces.dtos.outputs.degustacao.VisualInspectionOutputDTO; -import com.vinhonotas.bff.utils.MessagesConstants; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.DisplayName; -import org.junit.jupiter.api.Test; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; -import org.springframework.boot.test.mock.mockito.MockBean; -import org.springframework.http.MediaType; -import org.springframework.test.web.servlet.MockMvc; - -import java.time.LocalDate; -import java.util.List; -import java.util.UUID; - -import static org.mockito.Mockito.doThrow; -import static org.mockito.Mockito.when; -import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*; -import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; - -@WebMvcTest(controllers = TastingCardController.class) -class TastingCardControllerTest { - - @Autowired - private MockMvc mockMvc; - @Autowired - private ObjectMapper objectMapper; - - @MockBean - private TastingCardService tastingCardService; - - private TastingCardInputDTO inputDTO; - private TastingCardOutputDTO outputDTO; - - @BeforeEach - void setUp() { - inputDTO = createTastingCardInputDTO(); - outputDTO = createTastingCardOutputDTO(); - } - - @Test - @DisplayName("Deve criar uma ficha de degustação") - void testCreateTastingCard() throws Exception { - when(tastingCardService.createTastingCard(inputDTO)).thenReturn(outputDTO); - - mockMvc.perform(post("/api/v1/tasting-card") - .contentType(MediaType.APPLICATION_JSON) - .content(objectMapper.writeValueAsString(inputDTO))) - .andDo(print()) - .andExpect(status().isOk()) - .andExpect(content().json(objectMapper.writeValueAsString(outputDTO))); - } - - @Test - @DisplayName("Deve retornar erro ao criar uma ficha de degustação") - void testCreateTastingCardError() throws Exception { - when(tastingCardService.createTastingCard(inputDTO)).thenThrow(new BadRequestException(MessagesConstants.ERROR_WHEN_SAVING)); - - mockMvc.perform(post("/api/v1/tasting-card") - .contentType(MediaType.APPLICATION_JSON) - .content(objectMapper.writeValueAsString(inputDTO))) - .andDo(print()) - .andExpect(status().isBadRequest()); - } - - @Test - @DisplayName("Deve retornar uma lista com todas as fichas de degustação cadastradas") - void testGetAllTastingCards() throws Exception { - when(tastingCardService.getAllTastingCards()).thenReturn(List.of(outputDTO)); - - mockMvc.perform(get("/api/v1/tasting-card") - .contentType(MediaType.APPLICATION_JSON)) - .andDo(print()) - .andExpect(status().isOk()) - .andExpect(content().json(objectMapper.writeValueAsString(List.of(outputDTO)))); - } - - @Test - @DisplayName("Deve lançar erro ao retornar uma lista com todas as fichas de degustação cadastradas") - void testGetAllTastingCardsError() throws Exception { - when(tastingCardService.getAllTastingCards()).thenThrow(new NotFoundException(MessagesConstants.NOT_FOUND)); - - mockMvc.perform(get("/api/v1/tasting-card") - .contentType(MediaType.APPLICATION_JSON)) - .andDo(print()) - .andExpect(status().isNotFound()); - } - - @Test - @DisplayName("Deve retornar uma ficha de degustação cadastrada pelo id") - void testGetTastingCardById() throws Exception { - when(tastingCardService.getTastingCardById(outputDTO.getId().toString())).thenReturn(outputDTO); - - mockMvc.perform(get("/api/v1/tasting-card/" + outputDTO.getId()) - .contentType(MediaType.APPLICATION_JSON)) - .andDo(print()) - .andExpect(status().isOk()) - .andExpect(content().json(objectMapper.writeValueAsString(outputDTO))); - } - - @Test - @DisplayName("Deve lançar erro ao retornar uma ficha de degustação cadastrada pelo id") - void testGetTastingCardByIdError() throws Exception { - when(tastingCardService.getTastingCardById(outputDTO.getId().toString())).thenThrow(new NotFoundException(MessagesConstants.NOT_FOUND)); - - mockMvc.perform(get("/api/v1/tasting-card/" + outputDTO.getId()) - .contentType(MediaType.APPLICATION_JSON)) - .andDo(print()) - .andExpect(status().isNotFound()); - } - - @Test - @DisplayName("Deve atualizar uma ficha de degustação cadastrada pelo id") - void testUpdateTastingCard() throws Exception { - when(tastingCardService.updateTastingCard(outputDTO.getId().toString(), inputDTO)).thenReturn(outputDTO); - - mockMvc.perform(put("/api/v1/tasting-card/" + outputDTO.getId()) - .contentType(MediaType.APPLICATION_JSON) - .content(objectMapper.writeValueAsString(inputDTO))) - .andDo(print()) - .andExpect(status().isOk()) - .andExpect(content().json(objectMapper.writeValueAsString(outputDTO))); - } - - @Test - @DisplayName("Deve lançar erro ao atualizar uma ficha de degustação cadastrada pelo id") - void testUpdateTastingCardError() throws Exception { - when(tastingCardService.updateTastingCard(outputDTO.getId().toString(), inputDTO)) - .thenThrow(new BadRequestException(MessagesConstants.ERROR_WHEN_UPDATING)); - - mockMvc.perform(put("/api/v1/tasting-card/" + outputDTO.getId()) - .contentType(MediaType.APPLICATION_JSON) - .content(objectMapper.writeValueAsString(inputDTO))) - .andDo(print()) - .andExpect(status().isBadRequest()); - } - - @Test - @DisplayName("Deve deletar uma ficha de degustação cadastrada pelo id") - void testDeleteTastingCard() throws Exception { - mockMvc.perform(delete("/api/v1/tasting-card/" + outputDTO.getId()) - .contentType(MediaType.APPLICATION_JSON)) - .andDo(print()) - .andExpect(status().isNoContent()); - } - - @Test - @DisplayName("Deve lançar erro ao deletar uma ficha de degustação cadastrada pelo id") - void testDeleteTastingCardError() throws Exception { - doThrow(new BadRequestException(MessagesConstants.ERROR_WHEN_DELETING)).when(tastingCardService).deleteTastingCard(outputDTO.getId().toString()); - - mockMvc.perform(delete("/api/v1/tasting-card/" + outputDTO.getId()) - .contentType(MediaType.APPLICATION_JSON)) - .andDo(print()) - .andExpect(status().isBadRequest()); - } - - private TastingCardOutputDTO createTastingCardOutputDTO() { - return TastingCardOutputDTO.builder() - .id(UUID.fromString("f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e")) - .tastingData(LocalDate.now()) - .wineTasted("Wine Tasted") - .harvest("2020") - .grapes("Grapes") - .country("Chile") - .region("Vale Central") - .visualInspection(VisualInspectionOutputDTO.builder().build()) - .olfactoryInspection(OlfactoryInspectionOutputDTO.builder().build()) - .gustatoryInspection(GustatoryInspectionOutputDTO.builder().build()) - .opinion("Opinion about the wine") - .pointScale(EnumPointScale.CLASSIC.name()) - .build(); - } - - private TastingCardInputDTO createTastingCardInputDTO() { - return TastingCardInputDTO.builder() - .tastingData(LocalDate.now()) - .wineTasted("Wine Tasted") - .harvest("2020") - .grapes("Grapes") - .country("Chile") - .region("Vale Central") - .visualInspection(VisualInspectionInputDTO.builder().build()) - .olfactoryInspection(OlfactoryInspectionInputDTO.builder().build()) - .gustatoryInspection(GustatoryInspectionInputDTO.builder().build()) - .opinion("Opinion about the wine") - .pointScale(EnumPointScale.CLASSIC.getCode()) - .build(); - } - -} +//package com.vinhonotas.bff.interfaces.controllers.degustacao; +// +//import com.fasterxml.jackson.databind.ObjectMapper; +//import com.vinhonotas.bff.application.services.degustacao.TastingCardService; +//import com.vinhonotas.bff.application.services.exceptions.BadRequestException; +//import com.vinhonotas.bff.application.services.exceptions.NotFoundException; +//import com.vinhonotas.bff.domain.enums.EnumPointScale; +//import com.vinhonotas.bff.interfaces.dtos.inputs.degustacao.TastingCardInputDTO; +//import com.vinhonotas.bff.interfaces.dtos.outputs.degustacao.TastingCardOutputDTO; +//import com.vinhonotas.bff.utils.MessagesConstants; +//import org.junit.jupiter.api.BeforeEach; +//import org.junit.jupiter.api.DisplayName; +//import org.junit.jupiter.api.Test; +//import org.springframework.beans.factory.annotation.Autowired; +//import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; +//import org.springframework.boot.test.mock.mockito.MockBean; +//import org.springframework.http.MediaType; +//import org.springframework.test.web.servlet.MockMvc; +// +//import java.time.LocalDate; +//import java.util.List; +//import java.util.UUID; +// +//import static org.mockito.Mockito.doThrow; +//import static org.mockito.Mockito.when; +//import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*; +//import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print; +//import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content; +//import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; +// +//@WebMvcTest(controllers = TastingCardController.class) +//class TastingCardControllerTest { +// +// @Autowired +// private MockMvc mockMvc; +// @Autowired +// private ObjectMapper objectMapper; +// +// @MockBean +// private TastingCardService tastingCardService; +// +// private TastingCardInputDTO inputDTO; +// private TastingCardOutputDTO outputDTO; +// +// @BeforeEach +// void setUp() { +// inputDTO = createTastingCardInputDTO(); +// outputDTO = createTastingCardOutputDTO(); +// } +// +// @Test +// @DisplayName("Deve criar uma ficha de degustação") +// void testCreateTastingCard() throws Exception { +// when(tastingCardService.createTastingCard(inputDTO)).thenReturn(outputDTO); +// +// mockMvc.perform(post("/api/v1/tasting-card") +// .contentType(MediaType.APPLICATION_JSON) +// .content(objectMapper.writeValueAsString(inputDTO))) +// .andDo(print()) +// .andExpect(status().isOk()) +// .andExpect(content().json(objectMapper.writeValueAsString(outputDTO))); +// } +// +// @Test +// @DisplayName("Deve retornar erro ao criar uma ficha de degustação") +// void testCreateTastingCardError() throws Exception { +// when(tastingCardService.createTastingCard(inputDTO)).thenThrow(new BadRequestException(MessagesConstants.ERROR_WHEN_SAVING)); +// +// mockMvc.perform(post("/api/v1/tasting-card") +// .contentType(MediaType.APPLICATION_JSON) +// .content(objectMapper.writeValueAsString(inputDTO))) +// .andDo(print()) +// .andExpect(status().isBadRequest()); +// } +// +// @Test +// @DisplayName("Deve retornar uma lista com todas as fichas de degustação cadastradas") +// void testGetAllTastingCards() throws Exception { +// when(tastingCardService.getAllTastingCards()).thenReturn(List.of(outputDTO)); +// +// mockMvc.perform(get("/api/v1/tasting-card") +// .contentType(MediaType.APPLICATION_JSON)) +// .andDo(print()) +// .andExpect(status().isOk()) +// .andExpect(content().json(objectMapper.writeValueAsString(List.of(outputDTO)))); +// } +// +// @Test +// @DisplayName("Deve lançar erro ao retornar uma lista com todas as fichas de degustação cadastradas") +// void testGetAllTastingCardsError() throws Exception { +// when(tastingCardService.getAllTastingCards()).thenThrow(new NotFoundException(MessagesConstants.NOT_FOUND)); +// +// mockMvc.perform(get("/api/v1/tasting-card") +// .contentType(MediaType.APPLICATION_JSON)) +// .andDo(print()) +// .andExpect(status().isNotFound()); +// } +// +// @Test +// @DisplayName("Deve retornar uma ficha de degustação cadastrada pelo id") +// void testGetTastingCardById() throws Exception { +// when(tastingCardService.getTastingCardById(outputDTO.getId().toString())).thenReturn(outputDTO); +// +// mockMvc.perform(get("/api/v1/tasting-card/" + outputDTO.getId()) +// .contentType(MediaType.APPLICATION_JSON)) +// .andDo(print()) +// .andExpect(status().isOk()) +// .andExpect(content().json(objectMapper.writeValueAsString(outputDTO))); +// } +// +// @Test +// @DisplayName("Deve lançar erro ao retornar uma ficha de degustação cadastrada pelo id") +// void testGetTastingCardByIdError() throws Exception { +// when(tastingCardService.getTastingCardById(outputDTO.getId().toString())).thenThrow(new NotFoundException(MessagesConstants.NOT_FOUND)); +// +// mockMvc.perform(get("/api/v1/tasting-card/" + outputDTO.getId()) +// .contentType(MediaType.APPLICATION_JSON)) +// .andDo(print()) +// .andExpect(status().isNotFound()); +// } +// +// @Test +// @DisplayName("Deve atualizar uma ficha de degustação cadastrada pelo id") +// void testUpdateTastingCard() throws Exception { +// when(tastingCardService.updateTastingCard(outputDTO.getId().toString(), inputDTO)).thenReturn(outputDTO); +// +// mockMvc.perform(put("/api/v1/tasting-card/" + outputDTO.getId()) +// .contentType(MediaType.APPLICATION_JSON) +// .content(objectMapper.writeValueAsString(inputDTO))) +// .andDo(print()) +// .andExpect(status().isOk()) +// .andExpect(content().json(objectMapper.writeValueAsString(outputDTO))); +// } +// +// @Test +// @DisplayName("Deve lançar erro ao atualizar uma ficha de degustação cadastrada pelo id") +// void testUpdateTastingCardError() throws Exception { +// when(tastingCardService.updateTastingCard(outputDTO.getId().toString(), inputDTO)) +// .thenThrow(new BadRequestException(MessagesConstants.ERROR_WHEN_UPDATING)); +// +// mockMvc.perform(put("/api/v1/tasting-card/" + outputDTO.getId()) +// .contentType(MediaType.APPLICATION_JSON) +// .content(objectMapper.writeValueAsString(inputDTO))) +// .andDo(print()) +// .andExpect(status().isBadRequest()); +// } +// +// @Test +// @DisplayName("Deve deletar uma ficha de degustação cadastrada pelo id") +// void testDeleteTastingCard() throws Exception { +// mockMvc.perform(delete("/api/v1/tasting-card/" + outputDTO.getId()) +// .contentType(MediaType.APPLICATION_JSON)) +// .andDo(print()) +// .andExpect(status().isNoContent()); +// } +// +// @Test +// @DisplayName("Deve lançar erro ao deletar uma ficha de degustação cadastrada pelo id") +// void testDeleteTastingCardError() throws Exception { +// doThrow(new BadRequestException(MessagesConstants.ERROR_WHEN_DELETING)).when(tastingCardService).deleteTastingCard(outputDTO.getId().toString()); +// +// mockMvc.perform(delete("/api/v1/tasting-card/" + outputDTO.getId()) +// .contentType(MediaType.APPLICATION_JSON)) +// .andDo(print()) +// .andExpect(status().isBadRequest()); +// } +// +// private TastingCardOutputDTO createTastingCardOutputDTO() { +// return TastingCardOutputDTO.builder() +// .id(UUID.fromString("f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e")) +// .tastingData(LocalDate.now()) +// .wineTasted("Wine Tasted") +// .harvest("2020") +// .grapes("Grapes") +// .country("Chile") +// .region("Vale Central") +// .visualInspection(VisualInspectionOutputDTO.builder().build()) +// .olfactoryInspection(OlfactoryInspectionOutputDTO.builder().build()) +// .gustatoryInspection(GustatoryInspectionOutputDTO.builder().build()) +// .opinion("Opinion about the wine") +// .pointScale(EnumPointScale.CLASSIC.name()) +// .build(); +// } +// +// private TastingCardInputDTO createTastingCardInputDTO() { +// return TastingCardInputDTO.builder() +// .tastingData(LocalDate.now()) +// .wineTasted("Wine Tasted") +// .harvest("2020") +// .grapes("Grapes") +// .country("Chile") +// .region("Vale Central") +// .visualInspection(VisualInspectionInputDTO.builder().build()) +// .olfactoryInspection(OlfactoryInspectionInputDTO.builder().build()) +// .gustatoryInspection(GustatoryInspectionInputDTO.builder().build()) +// .opinion("Opinion about the wine") +// .pointScale(EnumPointScale.CLASSIC.getCode()) +// .build(); +// } +// +//} diff --git a/bff/src/test/java/com/vinhonotas/bff/interfaces/controllers/degustacao/TastingControllerTest.java b/bff/src/test/java/com/vinhonotas/bff/interfaces/controllers/degustacao/TastingControllerTest.java index e1719853..0eeebf6f 100644 --- a/bff/src/test/java/com/vinhonotas/bff/interfaces/controllers/degustacao/TastingControllerTest.java +++ b/bff/src/test/java/com/vinhonotas/bff/interfaces/controllers/degustacao/TastingControllerTest.java @@ -1,232 +1,232 @@ -package com.vinhonotas.bff.interfaces.controllers.degustacao; - -import com.fasterxml.jackson.databind.ObjectMapper; -import com.vinhonotas.bff.application.services.degustacao.TastingService; -import com.vinhonotas.bff.application.services.exceptions.BadRequestException; -import com.vinhonotas.bff.application.services.exceptions.NotFoundException; -import com.vinhonotas.bff.domain.enums.EnumPointScale; -import com.vinhonotas.bff.domain.enums.EnumTastingType; -import com.vinhonotas.bff.interfaces.dtos.inputs.degustacao.*; -import com.vinhonotas.bff.interfaces.dtos.outputs.degustacao.*; -import com.vinhonotas.bff.utils.MessagesConstants; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.DisplayName; -import org.junit.jupiter.api.Test; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; -import org.springframework.boot.test.mock.mockito.MockBean; -import org.springframework.http.MediaType; -import org.springframework.test.web.servlet.MockMvc; - -import java.time.LocalDate; -import java.util.List; -import java.util.Set; -import java.util.UUID; - -import static org.mockito.Mockito.doThrow; -import static org.mockito.Mockito.when; -import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*; -import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; - -@WebMvcTest(controllers = TastingController.class) -class TastingControllerTest { - - private static final String URL = "/api/v1/tasting"; - - @Autowired - private MockMvc mockMvc; - @Autowired - private ObjectMapper objectMapper; - - @MockBean - private TastingService tastingService; - - private TastingInputDTO inputDTO; - private TastingOutputDTO outputDTO; - - @BeforeEach - void setUp() { - inputDTO = createTastingInputDTO(); - outputDTO = createTastingOutputDTO(); - } - - @Test - @DisplayName("Deve criar uma degustação") - void testCreateTasting() throws Exception { - when(tastingService.createTasting(inputDTO)).thenReturn(outputDTO); - - mockMvc.perform(post(URL) - .contentType(MediaType.APPLICATION_JSON) - .content(objectMapper.writeValueAsString(inputDTO))) - .andDo(print()) - .andExpect(status().isOk()) - .andExpect(jsonPath("$.id").value(outputDTO.getId().toString())) - .andExpect(jsonPath("$.tastingData").value(outputDTO.getTastingData().toString())) - .andExpect(jsonPath("$.tastingType").value(outputDTO.getTastingType().toString())) - .andExpect(jsonPath("$.tastingCards").isArray()); - } - - @Test - @DisplayName("Deve retornar erro ao criar uma degustação") - void testCreateTastingThrowBadRequestException() throws Exception { - when(tastingService.createTasting(inputDTO)).thenThrow(new BadRequestException(MessagesConstants.ERROR_WHEN_SAVING)); - - mockMvc.perform(post(URL) - .contentType(MediaType.APPLICATION_JSON) - .content(objectMapper.writeValueAsString(inputDTO))) - .andDo(print()) - .andExpect(status().isBadRequest()); - } - - @Test - @DisplayName("Deve retornar uma lista de degustações") - void testGetAllTastings() throws Exception { - when(tastingService.getAllTastings()).thenReturn(List.of(outputDTO)); - - mockMvc.perform(get(URL) - .contentType(MediaType.APPLICATION_JSON)) - .andDo(print()) - .andExpect(status().isOk()) - .andExpect(jsonPath("$[0].id").value(outputDTO.getId().toString())) - .andExpect(jsonPath("$[0].tastingData").value(outputDTO.getTastingData().toString())) - .andExpect(jsonPath("$[0].tastingType").value(outputDTO.getTastingType().toString())) - .andExpect(jsonPath("$[0].tastingCards").isArray()); - } - - @Test - @DisplayName("Deve retornar um erro ao buscar uma lista de degustações") - void testGetAllTastingsThrowBadRequestException() throws Exception { - when(tastingService.getAllTastings()).thenThrow(new NotFoundException(MessagesConstants.NOT_FOUND)); - - mockMvc.perform(get(URL) - .contentType(MediaType.APPLICATION_JSON)) - .andDo(print()) - .andExpect(status().isNotFound()); - } - - @Test - @DisplayName("Deve retornar uma degustação pelo id") - void testGetTastingById() throws Exception { - when(tastingService.getTastingById(outputDTO.getId().toString())).thenReturn(outputDTO); - - mockMvc.perform(get(URL + "/" + outputDTO.getId()) - .contentType(MediaType.APPLICATION_JSON)) - .andDo(print()) - .andExpect(status().isOk()) - .andExpect(jsonPath("$.id").value(outputDTO.getId().toString())) - .andExpect(jsonPath("$.tastingData").value(outputDTO.getTastingData().toString())) - .andExpect(jsonPath("$.tastingType").value(outputDTO.getTastingType().toString())) - .andExpect(jsonPath("$.tastingCards").isArray()); - } - - @Test - @DisplayName("Deve retornar um erro ao buscar uma degustação pelo id") - void testGetTastingByIdThrowBadRequestException() throws Exception { - when(tastingService.getTastingById(outputDTO.getId().toString())).thenThrow(new NotFoundException(MessagesConstants.NOT_FOUND)); - - mockMvc.perform(get(URL + "/" + outputDTO.getId()) - .contentType(MediaType.APPLICATION_JSON)) - .andDo(print()) - .andExpect(status().isNotFound()); - } - - @Test - @DisplayName("Deve atualizar uma degustação pelo id") - void testUpdateTasting() throws Exception { - when(tastingService.updateTasting(outputDTO.getId().toString(), inputDTO)).thenReturn(outputDTO); - - mockMvc.perform(put(URL + "/" + outputDTO.getId()) - .contentType(MediaType.APPLICATION_JSON) - .content(objectMapper.writeValueAsString(inputDTO))) - .andDo(print()) - .andExpect(status().isOk()) - .andExpect(jsonPath("$.id").value(outputDTO.getId().toString())) - .andExpect(jsonPath("$.tastingData").value(outputDTO.getTastingData().toString())) - .andExpect(jsonPath("$.tastingType").value(outputDTO.getTastingType().toString())) - .andExpect(jsonPath("$.tastingCards").isArray()); - } - - @Test - @DisplayName("Deve retornar um erro ao atualizar uma degustação pelo id") - void testUpdateTastingThrowBadRequestException() throws Exception { - when(tastingService.updateTasting(outputDTO.getId().toString(), inputDTO)).thenThrow(new BadRequestException(MessagesConstants.ERROR_WHEN_UPDATING)); - - mockMvc.perform(put(URL + "/" + outputDTO.getId()) - .contentType(MediaType.APPLICATION_JSON) - .content(objectMapper.writeValueAsString(inputDTO))) - .andDo(print()) - .andExpect(status().isBadRequest()); - } - - @Test - @DisplayName("Deve deletar uma degustação pelo id") - void testDeleteTasting() throws Exception { - mockMvc.perform(delete(URL + "/" + outputDTO.getId()) - .contentType(MediaType.APPLICATION_JSON)) - .andDo(print()) - .andExpect(status().isNoContent()); - } - - @Test - @DisplayName("Deve retornar um erro ao deletar uma degustação pelo id") - void testDeleteTastingThrowBadRequestException() throws Exception { - doThrow(new BadRequestException(MessagesConstants.ERROR_WHEN_DELETING)).when(tastingService).deleteTasting(outputDTO.getId().toString()); - mockMvc.perform(delete(URL + "/" + outputDTO.getId()) - .contentType(MediaType.APPLICATION_JSON)) - .andDo(print()) - .andExpect(status().isBadRequest()); - } - - private TastingInputDTO createTastingInputDTO() { - return TastingInputDTO.builder() - .tastingData(LocalDate.now()) - .tastingType(EnumTastingType.COMPARATIVE.getCode()) - .tastingCards(Set.of(createTastingCardInputDTO())) - .build(); - } - - private TastingCardInputDTO createTastingCardInputDTO() { - return TastingCardInputDTO.builder() - .tastingData(LocalDate.now()) - .wineTasted("Wine Tasted") - .harvest("2020") - .grapes("Grapes") - .country("Chile") - .region("Vale Central") - .visualInspection(VisualInspectionInputDTO.builder().build()) - .olfactoryInspection(OlfactoryInspectionInputDTO.builder().build()) - .gustatoryInspection(GustatoryInspectionInputDTO.builder().build()) - .opinion("Opinion about the wine") - .pointScale(EnumPointScale.CLASSIC.getCode()) - .build(); - } - - private TastingOutputDTO createTastingOutputDTO() { - return TastingOutputDTO.builder() - .id(UUID.fromString("f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e")) - .tastingData(LocalDate.now()) - .tastingType(EnumTastingType.COMPARATIVE.getCode()) - .tastingCards(Set.of(createTastingCardOutputDTO())) - .build(); - } - - private TastingCardOutputDTO createTastingCardOutputDTO() { - return TastingCardOutputDTO.builder() - .id(UUID.fromString("f5e7e3e3-3e3e-4e3e-8e3e-3f3f3f3f3f3f")) - .tastingData(LocalDate.now()) - .wineTasted("Wine Tasted") - .harvest("2020") - .grapes("Grapes") - .country("Chile") - .region("Vale Central") - .visualInspection(VisualInspectionOutputDTO.builder().build()) - .olfactoryInspection(OlfactoryInspectionOutputDTO.builder().build()) - .gustatoryInspection(GustatoryInspectionOutputDTO.builder().build()) - .opinion("Opinion about the wine") - .pointScale(EnumPointScale.CLASSIC.name()) - .build(); - } - -} +//package com.vinhonotas.bff.interfaces.controllers.degustacao; +// +//import com.fasterxml.jackson.databind.ObjectMapper; +//import com.vinhonotas.bff.application.services.degustacao.TastingService; +//import com.vinhonotas.bff.application.services.exceptions.BadRequestException; +//import com.vinhonotas.bff.application.services.exceptions.NotFoundException; +//import com.vinhonotas.bff.domain.enums.EnumPointScale; +//import com.vinhonotas.bff.domain.enums.EnumTastingType; +//import com.vinhonotas.bff.interfaces.dtos.inputs.degustacao.*; +//import com.vinhonotas.bff.interfaces.dtos.outputs.degustacao.*; +//import com.vinhonotas.bff.utils.MessagesConstants; +//import org.junit.jupiter.api.BeforeEach; +//import org.junit.jupiter.api.DisplayName; +//import org.junit.jupiter.api.Test; +//import org.springframework.beans.factory.annotation.Autowired; +//import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; +//import org.springframework.boot.test.mock.mockito.MockBean; +//import org.springframework.http.MediaType; +//import org.springframework.test.web.servlet.MockMvc; +// +//import java.time.LocalDate; +//import java.util.List; +//import java.util.Set; +//import java.util.UUID; +// +//import static org.mockito.Mockito.doThrow; +//import static org.mockito.Mockito.when; +//import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*; +//import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print; +//import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; +//import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; +// +//@WebMvcTest(controllers = TastingController.class) +//class TastingControllerTest { +// +// private static final String URL = "/api/v1/tasting"; +// +// @Autowired +// private MockMvc mockMvc; +// @Autowired +// private ObjectMapper objectMapper; +// +// @MockBean +// private TastingService tastingService; +// +// private TastingInputDTO inputDTO; +// private TastingOutputDTO outputDTO; +// +// @BeforeEach +// void setUp() { +// inputDTO = createTastingInputDTO(); +// outputDTO = createTastingOutputDTO(); +// } +// +// @Test +// @DisplayName("Deve criar uma degustação") +// void testCreateTasting() throws Exception { +// when(tastingService.createTasting(inputDTO)).thenReturn(outputDTO); +// +// mockMvc.perform(post(URL) +// .contentType(MediaType.APPLICATION_JSON) +// .content(objectMapper.writeValueAsString(inputDTO))) +// .andDo(print()) +// .andExpect(status().isOk()) +// .andExpect(jsonPath("$.id").value(outputDTO.getId().toString())) +// .andExpect(jsonPath("$.tastingData").value(outputDTO.getTastingData().toString())) +// .andExpect(jsonPath("$.tastingType").value(outputDTO.getTastingType().toString())) +// .andExpect(jsonPath("$.tastingCards").isArray()); +// } +// +// @Test +// @DisplayName("Deve retornar erro ao criar uma degustação") +// void testCreateTastingThrowBadRequestException() throws Exception { +// when(tastingService.createTasting(inputDTO)).thenThrow(new BadRequestException(MessagesConstants.ERROR_WHEN_SAVING)); +// +// mockMvc.perform(post(URL) +// .contentType(MediaType.APPLICATION_JSON) +// .content(objectMapper.writeValueAsString(inputDTO))) +// .andDo(print()) +// .andExpect(status().isBadRequest()); +// } +// +// @Test +// @DisplayName("Deve retornar uma lista de degustações") +// void testGetAllTastings() throws Exception { +// when(tastingService.getAllTastings()).thenReturn(List.of(outputDTO)); +// +// mockMvc.perform(get(URL) +// .contentType(MediaType.APPLICATION_JSON)) +// .andDo(print()) +// .andExpect(status().isOk()) +// .andExpect(jsonPath("$[0].id").value(outputDTO.getId().toString())) +// .andExpect(jsonPath("$[0].tastingData").value(outputDTO.getTastingData().toString())) +// .andExpect(jsonPath("$[0].tastingType").value(outputDTO.getTastingType().toString())) +// .andExpect(jsonPath("$[0].tastingCards").isArray()); +// } +// +// @Test +// @DisplayName("Deve retornar um erro ao buscar uma lista de degustações") +// void testGetAllTastingsThrowBadRequestException() throws Exception { +// when(tastingService.getAllTastings()).thenThrow(new NotFoundException(MessagesConstants.NOT_FOUND)); +// +// mockMvc.perform(get(URL) +// .contentType(MediaType.APPLICATION_JSON)) +// .andDo(print()) +// .andExpect(status().isNotFound()); +// } +// +// @Test +// @DisplayName("Deve retornar uma degustação pelo id") +// void testGetTastingById() throws Exception { +// when(tastingService.getTastingById(outputDTO.getId().toString())).thenReturn(outputDTO); +// +// mockMvc.perform(get(URL + "/" + outputDTO.getId()) +// .contentType(MediaType.APPLICATION_JSON)) +// .andDo(print()) +// .andExpect(status().isOk()) +// .andExpect(jsonPath("$.id").value(outputDTO.getId().toString())) +// .andExpect(jsonPath("$.tastingData").value(outputDTO.getTastingData().toString())) +// .andExpect(jsonPath("$.tastingType").value(outputDTO.getTastingType().toString())) +// .andExpect(jsonPath("$.tastingCards").isArray()); +// } +// +// @Test +// @DisplayName("Deve retornar um erro ao buscar uma degustação pelo id") +// void testGetTastingByIdThrowBadRequestException() throws Exception { +// when(tastingService.getTastingById(outputDTO.getId().toString())).thenThrow(new NotFoundException(MessagesConstants.NOT_FOUND)); +// +// mockMvc.perform(get(URL + "/" + outputDTO.getId()) +// .contentType(MediaType.APPLICATION_JSON)) +// .andDo(print()) +// .andExpect(status().isNotFound()); +// } +// +// @Test +// @DisplayName("Deve atualizar uma degustação pelo id") +// void testUpdateTasting() throws Exception { +// when(tastingService.updateTasting(outputDTO.getId().toString(), inputDTO)).thenReturn(outputDTO); +// +// mockMvc.perform(put(URL + "/" + outputDTO.getId()) +// .contentType(MediaType.APPLICATION_JSON) +// .content(objectMapper.writeValueAsString(inputDTO))) +// .andDo(print()) +// .andExpect(status().isOk()) +// .andExpect(jsonPath("$.id").value(outputDTO.getId().toString())) +// .andExpect(jsonPath("$.tastingData").value(outputDTO.getTastingData().toString())) +// .andExpect(jsonPath("$.tastingType").value(outputDTO.getTastingType().toString())) +// .andExpect(jsonPath("$.tastingCards").isArray()); +// } +// +// @Test +// @DisplayName("Deve retornar um erro ao atualizar uma degustação pelo id") +// void testUpdateTastingThrowBadRequestException() throws Exception { +// when(tastingService.updateTasting(outputDTO.getId().toString(), inputDTO)).thenThrow(new BadRequestException(MessagesConstants.ERROR_WHEN_UPDATING)); +// +// mockMvc.perform(put(URL + "/" + outputDTO.getId()) +// .contentType(MediaType.APPLICATION_JSON) +// .content(objectMapper.writeValueAsString(inputDTO))) +// .andDo(print()) +// .andExpect(status().isBadRequest()); +// } +// +// @Test +// @DisplayName("Deve deletar uma degustação pelo id") +// void testDeleteTasting() throws Exception { +// mockMvc.perform(delete(URL + "/" + outputDTO.getId()) +// .contentType(MediaType.APPLICATION_JSON)) +// .andDo(print()) +// .andExpect(status().isNoContent()); +// } +// +// @Test +// @DisplayName("Deve retornar um erro ao deletar uma degustação pelo id") +// void testDeleteTastingThrowBadRequestException() throws Exception { +// doThrow(new BadRequestException(MessagesConstants.ERROR_WHEN_DELETING)).when(tastingService).deleteTasting(outputDTO.getId().toString()); +// mockMvc.perform(delete(URL + "/" + outputDTO.getId()) +// .contentType(MediaType.APPLICATION_JSON)) +// .andDo(print()) +// .andExpect(status().isBadRequest()); +// } +// +// private TastingInputDTO createTastingInputDTO() { +// return TastingInputDTO.builder() +// .tastingData(LocalDate.now()) +// .tastingType(EnumTastingType.COMPARATIVE.getCode()) +// .tastingCards(Set.of(createTastingCardInputDTO())) +// .build(); +// } +// +// private TastingCardInputDTO createTastingCardInputDTO() { +// return TastingCardInputDTO.builder() +// .tastingData(LocalDate.now()) +// .wineTasted("Wine Tasted") +// .harvest("2020") +// .grapes("Grapes") +// .country("Chile") +// .region("Vale Central") +// .visualInspection(VisualInspectionInputDTO.builder().build()) +// .olfactoryInspection(OlfactoryInspectionInputDTO.builder().build()) +// .gustatoryInspection(GustatoryInspectionInputDTO.builder().build()) +// .opinion("Opinion about the wine") +// .pointScale(EnumPointScale.CLASSIC.getCode()) +// .build(); +// } +// +// private TastingOutputDTO createTastingOutputDTO() { +// return TastingOutputDTO.builder() +// .id(UUID.fromString("f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e")) +// .tastingData(LocalDate.now()) +// .tastingType(EnumTastingType.COMPARATIVE.getCode()) +// .tastingCards(Set.of(createTastingCardOutputDTO())) +// .build(); +// } +// +// private TastingCardOutputDTO createTastingCardOutputDTO() { +// return TastingCardOutputDTO.builder() +// .id(UUID.fromString("f5e7e3e3-3e3e-4e3e-8e3e-3f3f3f3f3f3f")) +// .tastingData(LocalDate.now()) +// .wineTasted("Wine Tasted") +// .harvest("2020") +// .grapes("Grapes") +// .country("Chile") +// .region("Vale Central") +// .visualInspection(VisualInspectionOutputDTO.builder().build()) +// .olfactoryInspection(OlfactoryInspectionOutputDTO.builder().build()) +// .gustatoryInspection(GustatoryInspectionOutputDTO.builder().build()) +// .opinion("Opinion about the wine") +// .pointScale(EnumPointScale.CLASSIC.name()) +// .build(); +// } +// +//} diff --git a/bff/src/test/java/com/vinhonotas/bff/interfaces/controllers/degustacao/VisualInspectionControllerTest.java b/bff/src/test/java/com/vinhonotas/bff/interfaces/controllers/degustacao/VisualInspectionControllerTest.java index 3cbe13bb..95110f64 100644 --- a/bff/src/test/java/com/vinhonotas/bff/interfaces/controllers/degustacao/VisualInspectionControllerTest.java +++ b/bff/src/test/java/com/vinhonotas/bff/interfaces/controllers/degustacao/VisualInspectionControllerTest.java @@ -1,204 +1,202 @@ -package com.vinhonotas.bff.interfaces.controllers.degustacao; - -import com.fasterxml.jackson.databind.ObjectMapper; -import com.vinhonotas.bff.application.services.degustacao.VisualInspectionService; -import com.vinhonotas.bff.application.services.exceptions.BadRequestException; -import com.vinhonotas.bff.application.services.exceptions.NotFoundException; -import com.vinhonotas.bff.domain.enums.*; -import com.vinhonotas.bff.interfaces.dtos.inputs.degustacao.VisualInspectionInputDTO; -import com.vinhonotas.bff.interfaces.dtos.outputs.degustacao.VisualInspectionOutputDTO; -import com.vinhonotas.bff.utils.MessagesConstants; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.DisplayName; -import org.junit.jupiter.api.Test; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; -import org.springframework.boot.test.mock.mockito.MockBean; -import org.springframework.http.MediaType; -import org.springframework.test.web.servlet.MockMvc; - -import java.time.LocalDate; -import java.util.List; -import java.util.UUID; - -import static org.mockito.Mockito.doThrow; -import static org.mockito.Mockito.when; -import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*; -import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; - -@WebMvcTest(controllers = VisualInspectionController.class) -class VisualInspectionControllerTest { - - @Autowired - private MockMvc mockMvc; - @Autowired - private ObjectMapper objectMapper; - - @MockBean - private VisualInspectionService visualInspectionService; - - private VisualInspectionInputDTO inputDTO; - private VisualInspectionOutputDTO outputDTO; - - @BeforeEach - void setUp() { - inputDTO = createVisualInspectionInputDTO(); - outputDTO = createVisualInspectionOutputDTO(); - } - - @Test - @DisplayName("Deve criar uma percepção visual") - void testCreateVisualInspection() throws Exception { - when(visualInspectionService.createVisualInspection(inputDTO)).thenReturn(outputDTO); - - mockMvc.perform(post("/api/v1/visual-inspection") - .contentType(MediaType.APPLICATION_JSON) - .content(objectMapper.writeValueAsString(inputDTO))) - .andDo(print()) - .andExpect(status().isOk()) - .andExpect(content() - .json(objectMapper.writeValueAsString(outputDTO))); - } - - @Test - @DisplayName("Deve lançar BadRequestException ao criar uma percepção visual") - void testCreateVisualInspectionBadRequestException() throws Exception { - when(visualInspectionService.createVisualInspection(inputDTO)).thenThrow(new BadRequestException( - MessagesConstants.ERROR_WHEN_SAVING)); - - mockMvc.perform(post("/api/v1/visual-inspection") - .contentType(MediaType.APPLICATION_JSON) - .content(objectMapper.writeValueAsString(inputDTO))) - .andDo(print()) - .andExpect(status().isBadRequest()); - } - - @Test - @DisplayName("Deve retornar uma lista com todas as percepções visuais cadastradas") - void testGetAllVisualInspections() throws Exception { - when(visualInspectionService.getAllVisualInspections()).thenReturn(List.of(outputDTO)); - - mockMvc.perform(get("/api/v1/visual-inspection") - .contentType(MediaType.APPLICATION_JSON)) - .andDo(print()) - .andExpect(status().isOk()) - .andExpect(content() - .json(objectMapper.writeValueAsString(List.of(outputDTO)))); - } - - @Test - @DisplayName("Deve lançar BadRequestException ao retornar uma lista com todas as percepções visuais cadastradas") - void testGetAllVisualInspectionsBadRequestException() throws Exception { - when(visualInspectionService.getAllVisualInspections()).thenThrow(new NotFoundException(MessagesConstants.NOT_FOUND)); - - mockMvc.perform(get("/api/v1/visual-inspection") - .contentType(MediaType.APPLICATION_JSON)) - .andDo(print()) - .andExpect(status().isNotFound()); - } - - @Test - @DisplayName("Deve retornar uma percepção visual cadastrada pelo id") - void testGetVisualInspectionById() throws Exception { - when(visualInspectionService.getVisualInspectionById("f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e")).thenReturn(outputDTO); - - mockMvc.perform(get("/api/v1/visual-inspection/f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e") - .contentType(MediaType.APPLICATION_JSON)) - .andDo(print()) - .andExpect(status().isOk()) - .andExpect(content() - .json(objectMapper.writeValueAsString(outputDTO))); - } - - @Test - @DisplayName("Deve lançar BadRequestException ao retornar uma percepção visual cadastrada pelo id") - void testGetVisualInspectionByIdBadRequestException() throws Exception { - when(visualInspectionService.getVisualInspectionById("f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e")) - .thenThrow(new NotFoundException(MessagesConstants.NOT_FOUND)); - - mockMvc.perform(get("/api/v1/visual-inspection/f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e") - .contentType(MediaType.APPLICATION_JSON)) - .andDo(print()) - .andExpect(status().isNotFound()); - } - - @Test - @DisplayName("Deve atualizar uma percepção visual cadastrada pelo id") - void testUpdateVisualInspection() throws Exception { - when(visualInspectionService.updateVisualInspection("f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e", inputDTO)).thenReturn(outputDTO); - - mockMvc.perform(put("/api/v1/visual-inspection/f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e") - .contentType(MediaType.APPLICATION_JSON) - .content(objectMapper.writeValueAsString(inputDTO))) - .andDo(print()) - .andExpect(status().isOk()) - .andExpect(content() - .json(objectMapper.writeValueAsString(outputDTO))); - } - - @Test - @DisplayName("Deve lançar BadRequestException ao atualizar uma percepção visual cadastrada pelo id") - void testUpdateVisualInspectionBadRequestException() throws Exception { - when(visualInspectionService.updateVisualInspection("f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e", inputDTO)) - .thenThrow(new BadRequestException(MessagesConstants.ERROR_WHEN_UPDATING)); - - mockMvc.perform(put("/api/v1/visual-inspection/f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e") - .contentType(MediaType.APPLICATION_JSON) - .content(objectMapper.writeValueAsString(inputDTO))) - .andDo(print()) - .andExpect(status().isBadRequest()); - } - - @Test - @DisplayName("Deve deletar uma percepção visual cadastrada pelo id") - void testDeleteVisualInspection() throws Exception { - mockMvc.perform(delete("/api/v1/visual-inspection/f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e") - .contentType(MediaType.APPLICATION_JSON)) - .andDo(print()) - .andExpect(status().isNoContent()); - } - - @Test - @DisplayName("Deve lançar BadRequestException ao deletar uma percepção visual cadastrada pelo id") - void testDeleteVisualInspectionBadRequestException() throws Exception { - doThrow(new BadRequestException(MessagesConstants.ERROR_WHEN_DELETING)) - .when(visualInspectionService).deleteVisualInspection("f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e"); - - mockMvc.perform(delete("/api/v1/visual-inspection/f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e") - .contentType(MediaType.APPLICATION_JSON)) - .andDo(print()) - .andExpect(status().isBadRequest()); - } - - private VisualInspectionOutputDTO createVisualInspectionOutputDTO() { - return VisualInspectionOutputDTO.builder() - .id(UUID.fromString("f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e")) - .tastingData(LocalDate.now()) - .wineTasted("Wine Tasted") - .clarity(EnumClarityType.VERY_CLEAR.getCode()) - .brightness(EnumBrightnessType.VERY_BRIGHT.getCode()) - .viscosity(EnumViscosityType.SLIPPERY.getCode()) - .colorRed(EnumRedColorType.RUBY.getCode()) - .colorWhite(EnumWhiteColorType.STRAW_YELLOW.getCode()) - .colorRose(EnumRoseColorType.BROWN.getCode()) - .classification(EnumClassificationType.LITTLE.getCode()) - .build(); - } - - private VisualInspectionInputDTO createVisualInspectionInputDTO() { - return VisualInspectionInputDTO.builder() - .tastingData(LocalDate.now()) - .wineTasted("Wine Tasted") - .clarity(EnumClarityType.VERY_CLEAR.getCode()) - .brightness(EnumBrightnessType.VERY_BRIGHT.getCode()) - .viscosity(EnumViscosityType.SLIPPERY.getCode()) - .colorRed(EnumRedColorType.RUBY.getCode()) - .colorWhite(EnumWhiteColorType.STRAW_YELLOW.getCode()) - .colorRose(EnumRoseColorType.BROWN.getCode()) - .classification(EnumClassificationType.LITTLE.getCode()) - .build(); - } - -} +//package com.vinhonotas.bff.interfaces.controllers.degustacao; +// +//import com.fasterxml.jackson.databind.ObjectMapper; +//import com.vinhonotas.bff.application.services.degustacao.VisualInspectionService; +//import com.vinhonotas.bff.application.services.exceptions.BadRequestException; +//import com.vinhonotas.bff.application.services.exceptions.NotFoundException; +//import com.vinhonotas.bff.domain.enums.*; +//import com.vinhonotas.bff.utils.MessagesConstants; +//import org.junit.jupiter.api.BeforeEach; +//import org.junit.jupiter.api.DisplayName; +//import org.junit.jupiter.api.Test; +//import org.springframework.beans.factory.annotation.Autowired; +//import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; +//import org.springframework.boot.test.mock.mockito.MockBean; +//import org.springframework.http.MediaType; +//import org.springframework.test.web.servlet.MockMvc; +// +//import java.time.LocalDate; +//import java.util.List; +//import java.util.UUID; +// +//import static org.mockito.Mockito.doThrow; +//import static org.mockito.Mockito.when; +//import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*; +//import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print; +//import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content; +//import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; +// +//@WebMvcTest(controllers = VisualInspectionController.class) +//class VisualInspectionControllerTest { +// +// @Autowired +// private MockMvc mockMvc; +// @Autowired +// private ObjectMapper objectMapper; +// +// @MockBean +// private VisualInspectionService visualInspectionService; +// +// private VisualInspectionInputDTO inputDTO; +// private VisualInspectionOutputDTO outputDTO; +// +// @BeforeEach +// void setUp() { +// inputDTO = createVisualInspectionInputDTO(); +// outputDTO = createVisualInspectionOutputDTO(); +// } +// +// @Test +// @DisplayName("Deve criar uma percepção visual") +// void testCreateVisualInspection() throws Exception { +// when(visualInspectionService.createVisualInspection(inputDTO)).thenReturn(outputDTO); +// +// mockMvc.perform(post("/api/v1/visual-inspection") +// .contentType(MediaType.APPLICATION_JSON) +// .content(objectMapper.writeValueAsString(inputDTO))) +// .andDo(print()) +// .andExpect(status().isOk()) +// .andExpect(content() +// .json(objectMapper.writeValueAsString(outputDTO))); +// } +// +// @Test +// @DisplayName("Deve lançar BadRequestException ao criar uma percepção visual") +// void testCreateVisualInspectionBadRequestException() throws Exception { +// when(visualInspectionService.createVisualInspection(inputDTO)).thenThrow(new BadRequestException( +// MessagesConstants.ERROR_WHEN_SAVING)); +// +// mockMvc.perform(post("/api/v1/visual-inspection") +// .contentType(MediaType.APPLICATION_JSON) +// .content(objectMapper.writeValueAsString(inputDTO))) +// .andDo(print()) +// .andExpect(status().isBadRequest()); +// } +// +// @Test +// @DisplayName("Deve retornar uma lista com todas as percepções visuais cadastradas") +// void testGetAllVisualInspections() throws Exception { +// when(visualInspectionService.getAllVisualInspections()).thenReturn(List.of(outputDTO)); +// +// mockMvc.perform(get("/api/v1/visual-inspection") +// .contentType(MediaType.APPLICATION_JSON)) +// .andDo(print()) +// .andExpect(status().isOk()) +// .andExpect(content() +// .json(objectMapper.writeValueAsString(List.of(outputDTO)))); +// } +// +// @Test +// @DisplayName("Deve lançar BadRequestException ao retornar uma lista com todas as percepções visuais cadastradas") +// void testGetAllVisualInspectionsBadRequestException() throws Exception { +// when(visualInspectionService.getAllVisualInspections()).thenThrow(new NotFoundException(MessagesConstants.NOT_FOUND)); +// +// mockMvc.perform(get("/api/v1/visual-inspection") +// .contentType(MediaType.APPLICATION_JSON)) +// .andDo(print()) +// .andExpect(status().isNotFound()); +// } +// +// @Test +// @DisplayName("Deve retornar uma percepção visual cadastrada pelo id") +// void testGetVisualInspectionById() throws Exception { +// when(visualInspectionService.getVisualInspectionById("f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e")).thenReturn(outputDTO); +// +// mockMvc.perform(get("/api/v1/visual-inspection/f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e") +// .contentType(MediaType.APPLICATION_JSON)) +// .andDo(print()) +// .andExpect(status().isOk()) +// .andExpect(content() +// .json(objectMapper.writeValueAsString(outputDTO))); +// } +// +// @Test +// @DisplayName("Deve lançar BadRequestException ao retornar uma percepção visual cadastrada pelo id") +// void testGetVisualInspectionByIdBadRequestException() throws Exception { +// when(visualInspectionService.getVisualInspectionById("f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e")) +// .thenThrow(new NotFoundException(MessagesConstants.NOT_FOUND)); +// +// mockMvc.perform(get("/api/v1/visual-inspection/f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e") +// .contentType(MediaType.APPLICATION_JSON)) +// .andDo(print()) +// .andExpect(status().isNotFound()); +// } +// +// @Test +// @DisplayName("Deve atualizar uma percepção visual cadastrada pelo id") +// void testUpdateVisualInspection() throws Exception { +// when(visualInspectionService.updateVisualInspection("f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e", inputDTO)).thenReturn(outputDTO); +// +// mockMvc.perform(put("/api/v1/visual-inspection/f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e") +// .contentType(MediaType.APPLICATION_JSON) +// .content(objectMapper.writeValueAsString(inputDTO))) +// .andDo(print()) +// .andExpect(status().isOk()) +// .andExpect(content() +// .json(objectMapper.writeValueAsString(outputDTO))); +// } +// +// @Test +// @DisplayName("Deve lançar BadRequestException ao atualizar uma percepção visual cadastrada pelo id") +// void testUpdateVisualInspectionBadRequestException() throws Exception { +// when(visualInspectionService.updateVisualInspection("f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e", inputDTO)) +// .thenThrow(new BadRequestException(MessagesConstants.ERROR_WHEN_UPDATING)); +// +// mockMvc.perform(put("/api/v1/visual-inspection/f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e") +// .contentType(MediaType.APPLICATION_JSON) +// .content(objectMapper.writeValueAsString(inputDTO))) +// .andDo(print()) +// .andExpect(status().isBadRequest()); +// } +// +// @Test +// @DisplayName("Deve deletar uma percepção visual cadastrada pelo id") +// void testDeleteVisualInspection() throws Exception { +// mockMvc.perform(delete("/api/v1/visual-inspection/f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e") +// .contentType(MediaType.APPLICATION_JSON)) +// .andDo(print()) +// .andExpect(status().isNoContent()); +// } +// +// @Test +// @DisplayName("Deve lançar BadRequestException ao deletar uma percepção visual cadastrada pelo id") +// void testDeleteVisualInspectionBadRequestException() throws Exception { +// doThrow(new BadRequestException(MessagesConstants.ERROR_WHEN_DELETING)) +// .when(visualInspectionService).deleteVisualInspection("f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e"); +// +// mockMvc.perform(delete("/api/v1/visual-inspection/f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e") +// .contentType(MediaType.APPLICATION_JSON)) +// .andDo(print()) +// .andExpect(status().isBadRequest()); +// } +// +// private VisualInspectionOutputDTO createVisualInspectionOutputDTO() { +// return VisualInspectionOutputDTO.builder() +// .id(UUID.fromString("f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e")) +// .tastingData(LocalDate.now()) +// .wineTasted("Wine Tasted") +// .clarity(EnumClarityType.VERY_CLEAR.getCode()) +// .brightness(EnumBrightnessType.VERY_BRIGHT.getCode()) +// .viscosity(EnumViscosityType.SLIPPERY.getCode()) +// .colorRed(EnumRedColorType.RUBY.getCode()) +// .colorWhite(EnumWhiteColorType.STRAW_YELLOW.getCode()) +// .colorRose(EnumRoseColorType.BROWN.getCode()) +// .classification(EnumClassificationType.LITTLE.getCode()) +// .build(); +// } +// +// private VisualInspectionInputDTO createVisualInspectionInputDTO() { +// return VisualInspectionInputDTO.builder() +// .tastingData(LocalDate.now()) +// .wineTasted("Wine Tasted") +// .clarity(EnumClarityType.VERY_CLEAR.getCode()) +// .brightness(EnumBrightnessType.VERY_BRIGHT.getCode()) +// .viscosity(EnumViscosityType.SLIPPERY.getCode()) +// .colorRed(EnumRedColorType.RUBY.getCode()) +// .colorWhite(EnumWhiteColorType.STRAW_YELLOW.getCode()) +// .colorRose(EnumRoseColorType.BROWN.getCode()) +// .classification(EnumClassificationType.LITTLE.getCode()) +// .build(); +// } +// +//} From c0580ac7df7cfb10a534e8765f2a210bccdf4068 Mon Sep 17 00:00:00 2001 From: vanderleik Date: Sat, 13 Apr 2024 14:30:50 -0300 Subject: [PATCH 2/5] feat: VIN-441 - refazendo os DTOs --- .../services/degustacao/AromasService.java | 19 -- .../GustatoryInspectionService.java | 17 -- .../OlfactoryInspectionService.java | 17 -- .../services/degustacao/TastingService.java | 17 -- .../degustacao/VisualInspectionService.java | 17 -- .../degustacao/impl/AromasServiceImpl.java | 76 ------ .../impl/GustatoryInspectionServiceImpl.java | 76 ------ .../impl/OlfactoryInspectionServiceImpl.java | 77 ------ .../degustacao/impl/TastingServiceImpl.java | 77 ------ .../impl/VisualInspectionServiceImpl.java | 77 ------ .../bff/client/degustacao/AromasClient.java | 28 -- .../degustacao/GustatoryInspectionClient.java | 29 --- .../degustacao/OlfactoryInspectionClient.java | 28 -- .../bff/client/degustacao/TastingClient.java | 28 -- .../degustacao/VisualInspectionClient.java | 28 -- .../degustacao/AromasController.java | 45 ---- .../GustatoryInspectionController.java | 46 ---- .../OlfactoryInspectionController.java | 45 ---- .../degustacao/TastingController.java | 45 ---- .../VisualInspectionController.java | 45 ---- .../impl/AromasServiceImplTest.java | 234 ----------------- .../GustatoryInspectionServiceImplTest.java | 227 ----------------- .../OlfactoryInspectionServiceImplTest.java | 215 ---------------- .../impl/TastingServiceImplTest.java | 180 ------------- .../impl/VisualInspectionServiceImplTest.java | 209 --------------- .../degustacao/AromasControllerTest.java | 210 --------------- .../GustatoryInspectionControllerTest.java | 204 --------------- .../OlfactoryInspectionControllerTest.java | 240 ------------------ .../degustacao/TastingControllerTest.java | 232 ----------------- .../VisualInspectionControllerTest.java | 202 --------------- 30 files changed, 2990 deletions(-) delete mode 100644 bff/src/main/java/com/vinhonotas/bff/application/services/degustacao/AromasService.java delete mode 100644 bff/src/main/java/com/vinhonotas/bff/application/services/degustacao/GustatoryInspectionService.java delete mode 100644 bff/src/main/java/com/vinhonotas/bff/application/services/degustacao/OlfactoryInspectionService.java delete mode 100644 bff/src/main/java/com/vinhonotas/bff/application/services/degustacao/TastingService.java delete mode 100644 bff/src/main/java/com/vinhonotas/bff/application/services/degustacao/VisualInspectionService.java delete mode 100644 bff/src/main/java/com/vinhonotas/bff/application/services/degustacao/impl/AromasServiceImpl.java delete mode 100644 bff/src/main/java/com/vinhonotas/bff/application/services/degustacao/impl/GustatoryInspectionServiceImpl.java delete mode 100644 bff/src/main/java/com/vinhonotas/bff/application/services/degustacao/impl/OlfactoryInspectionServiceImpl.java delete mode 100644 bff/src/main/java/com/vinhonotas/bff/application/services/degustacao/impl/TastingServiceImpl.java delete mode 100644 bff/src/main/java/com/vinhonotas/bff/application/services/degustacao/impl/VisualInspectionServiceImpl.java delete mode 100644 bff/src/main/java/com/vinhonotas/bff/client/degustacao/AromasClient.java delete mode 100644 bff/src/main/java/com/vinhonotas/bff/client/degustacao/GustatoryInspectionClient.java delete mode 100644 bff/src/main/java/com/vinhonotas/bff/client/degustacao/OlfactoryInspectionClient.java delete mode 100644 bff/src/main/java/com/vinhonotas/bff/client/degustacao/TastingClient.java delete mode 100644 bff/src/main/java/com/vinhonotas/bff/client/degustacao/VisualInspectionClient.java delete mode 100644 bff/src/main/java/com/vinhonotas/bff/interfaces/controllers/degustacao/AromasController.java delete mode 100644 bff/src/main/java/com/vinhonotas/bff/interfaces/controllers/degustacao/GustatoryInspectionController.java delete mode 100644 bff/src/main/java/com/vinhonotas/bff/interfaces/controllers/degustacao/OlfactoryInspectionController.java delete mode 100644 bff/src/main/java/com/vinhonotas/bff/interfaces/controllers/degustacao/TastingController.java delete mode 100644 bff/src/main/java/com/vinhonotas/bff/interfaces/controllers/degustacao/VisualInspectionController.java delete mode 100644 bff/src/test/java/com/vinhonotas/bff/application/services/degustacao/impl/AromasServiceImplTest.java delete mode 100644 bff/src/test/java/com/vinhonotas/bff/application/services/degustacao/impl/GustatoryInspectionServiceImplTest.java delete mode 100644 bff/src/test/java/com/vinhonotas/bff/application/services/degustacao/impl/OlfactoryInspectionServiceImplTest.java delete mode 100644 bff/src/test/java/com/vinhonotas/bff/application/services/degustacao/impl/TastingServiceImplTest.java delete mode 100644 bff/src/test/java/com/vinhonotas/bff/application/services/degustacao/impl/VisualInspectionServiceImplTest.java delete mode 100644 bff/src/test/java/com/vinhonotas/bff/interfaces/controllers/degustacao/AromasControllerTest.java delete mode 100644 bff/src/test/java/com/vinhonotas/bff/interfaces/controllers/degustacao/GustatoryInspectionControllerTest.java delete mode 100644 bff/src/test/java/com/vinhonotas/bff/interfaces/controllers/degustacao/OlfactoryInspectionControllerTest.java delete mode 100644 bff/src/test/java/com/vinhonotas/bff/interfaces/controllers/degustacao/TastingControllerTest.java delete mode 100644 bff/src/test/java/com/vinhonotas/bff/interfaces/controllers/degustacao/VisualInspectionControllerTest.java diff --git a/bff/src/main/java/com/vinhonotas/bff/application/services/degustacao/AromasService.java b/bff/src/main/java/com/vinhonotas/bff/application/services/degustacao/AromasService.java deleted file mode 100644 index 5c7f5030..00000000 --- a/bff/src/main/java/com/vinhonotas/bff/application/services/degustacao/AromasService.java +++ /dev/null @@ -1,19 +0,0 @@ -package com.vinhonotas.bff.application.services.degustacao; - -import org.springframework.web.bind.annotation.PathVariable; - -import java.util.List; - -public interface AromasService { - - AromasOutputDTO createAromas(AromasInputDTO aromasInputDTO); - - List getAllAromas(); - - AromasOutputDTO getAromasById(String id); - - AromasOutputDTO updateAromas(String id, AromasInputDTO aromasInputDTO); - - void deleteAromas(@PathVariable ("id") String id); - -} diff --git a/bff/src/main/java/com/vinhonotas/bff/application/services/degustacao/GustatoryInspectionService.java b/bff/src/main/java/com/vinhonotas/bff/application/services/degustacao/GustatoryInspectionService.java deleted file mode 100644 index 54ecad90..00000000 --- a/bff/src/main/java/com/vinhonotas/bff/application/services/degustacao/GustatoryInspectionService.java +++ /dev/null @@ -1,17 +0,0 @@ -package com.vinhonotas.bff.application.services.degustacao; - -import java.util.List; - -public interface GustatoryInspectionService { - - GustatoryInspectionOutputDTO createGustatoryInspection(GustatoryInspectionInputDTO gustatoryInspectionInputDTO); - - List getAllGustatoryInspections(); - - GustatoryInspectionOutputDTO getGustatoryInspectionById(String id); - - GustatoryInspectionOutputDTO updateGustatoryInspection(String id, GustatoryInspectionInputDTO gustatoryInspectionInputDTO); - - void deleteGustatoryInspection(String id); - -} diff --git a/bff/src/main/java/com/vinhonotas/bff/application/services/degustacao/OlfactoryInspectionService.java b/bff/src/main/java/com/vinhonotas/bff/application/services/degustacao/OlfactoryInspectionService.java deleted file mode 100644 index 53af5a02..00000000 --- a/bff/src/main/java/com/vinhonotas/bff/application/services/degustacao/OlfactoryInspectionService.java +++ /dev/null @@ -1,17 +0,0 @@ -package com.vinhonotas.bff.application.services.degustacao; - -import java.util.List; - -public interface OlfactoryInspectionService { - - OlfactoryInspectionOutputDTO createOlfactoryInspection(OlfactoryInspectionInputDTO olfactoryInspectionInputDTO); - - List getAllOlfactoryInspections(); - - OlfactoryInspectionOutputDTO getOlfactoryInspectionById(String id); - - OlfactoryInspectionOutputDTO updateOlfactoryInspection(String id, OlfactoryInspectionInputDTO olfactoryInspectionInputDTO); - - void deleteOlfactoryInspection(String id); - -} diff --git a/bff/src/main/java/com/vinhonotas/bff/application/services/degustacao/TastingService.java b/bff/src/main/java/com/vinhonotas/bff/application/services/degustacao/TastingService.java deleted file mode 100644 index 39d2e484..00000000 --- a/bff/src/main/java/com/vinhonotas/bff/application/services/degustacao/TastingService.java +++ /dev/null @@ -1,17 +0,0 @@ -package com.vinhonotas.bff.application.services.degustacao; - -import java.util.List; - -public interface TastingService { - - TastingOutputDTO createTasting(TastingInputDTO tastingInputDTO); - - List getAllTastings(); - - TastingOutputDTO getTastingById(String id); - - TastingOutputDTO updateTasting(String id, TastingInputDTO tastingInputDTO); - - void deleteTasting(String id); - -} diff --git a/bff/src/main/java/com/vinhonotas/bff/application/services/degustacao/VisualInspectionService.java b/bff/src/main/java/com/vinhonotas/bff/application/services/degustacao/VisualInspectionService.java deleted file mode 100644 index e2a909b7..00000000 --- a/bff/src/main/java/com/vinhonotas/bff/application/services/degustacao/VisualInspectionService.java +++ /dev/null @@ -1,17 +0,0 @@ -package com.vinhonotas.bff.application.services.degustacao; - -import java.util.List; - -public interface VisualInspectionService { - - VisualInspectionOutputDTO createVisualInspection(VisualInspectionInputDTO visualInspectionInputDTO); - - List getAllVisualInspections(); - - VisualInspectionOutputDTO getVisualInspectionById(String id); - - VisualInspectionOutputDTO updateVisualInspection(String id, VisualInspectionInputDTO visualInspectionInputDTO); - - void deleteVisualInspection(String id); - -} diff --git a/bff/src/main/java/com/vinhonotas/bff/application/services/degustacao/impl/AromasServiceImpl.java b/bff/src/main/java/com/vinhonotas/bff/application/services/degustacao/impl/AromasServiceImpl.java deleted file mode 100644 index 7b5465ae..00000000 --- a/bff/src/main/java/com/vinhonotas/bff/application/services/degustacao/impl/AromasServiceImpl.java +++ /dev/null @@ -1,76 +0,0 @@ -package com.vinhonotas.bff.application.services.degustacao.impl; - -import com.vinhonotas.bff.application.services.degustacao.AromasService; -import com.vinhonotas.bff.application.services.exceptions.BadRequestException; -import com.vinhonotas.bff.application.services.exceptions.NotFoundException; -import com.vinhonotas.bff.client.degustacao.AromasClient; -import com.vinhonotas.bff.utils.MessagesConstants; -import lombok.RequiredArgsConstructor; -import lombok.extern.slf4j.Slf4j; -import org.springframework.stereotype.Service; - -import java.util.List; -import java.util.Objects; - -@Service -@RequiredArgsConstructor -@Slf4j -public class AromasServiceImpl implements AromasService { - - private final AromasClient aromasClient; - - @Override - public AromasOutputDTO createAromas(AromasInputDTO aromasInputDTO) { - log.info("createAromas :: Registrando um novo aroma com os dados: {}", aromasInputDTO.toString()); - try { - return aromasClient.createAromas(aromasInputDTO); - } catch (Exception e) { - log.error("createAromas :: Ocorreu um erro: {} ", MessagesConstants.ERROR_WHEN_SAVING, e); - throw new BadRequestException(MessagesConstants.ERROR_WHEN_SAVING); - } - } - - @Override - public List getAllAromas() { - log.info("getAllAromas :: Listando todos os aromas"); - List aromas = aromasClient.getAllAromas(); - if (aromas.isEmpty()) { - log.error("getAllAromas :: Ocorreu um erro ao listar os aromas: {} ", MessagesConstants.NOT_FOUND); - throw new NotFoundException(MessagesConstants.NOT_FOUND); - } - return aromas; - } - - @Override - public AromasOutputDTO getAromasById(String id) { - log.info("getAromasById :: Buscando aroma pelo id: {}", id); - AromasOutputDTO aroma = aromasClient.getAromasById(id); - if (Objects.isNull(aroma)) { - log.error("getAromasById :: Ocorreu um erro ao buscar o aroma: {} ", MessagesConstants.NOT_FOUND); - throw new NotFoundException(MessagesConstants.NOT_FOUND); - } - return aroma; - } - - @Override - public AromasOutputDTO updateAromas(String id, AromasInputDTO aromasInputDTO) { - log.info("updateAromas :: Atualizando aroma com os dados: {}", aromasInputDTO.toString()); - try { - return aromasClient.updateAromas(id, aromasInputDTO); - } catch (Exception e) { - log.error("updateAromas :: Ocorreu um erro: {} ", MessagesConstants.ERROR_WHEN_UPDATING, e); - throw new BadRequestException(MessagesConstants.ERROR_WHEN_UPDATING); - } - } - - @Override - public void deleteAromas(String id) { - log.info("deleteAromas :: Deletando aroma pelo id: {}", id); - try { - aromasClient.deleteAromas(id); - } catch (Exception e) { - log.error("deleteAromas :: Ocorreu um erro: {} ", MessagesConstants.ERROR_WHEN_DELETING, e); - throw new BadRequestException(MessagesConstants.ERROR_WHEN_DELETING); - } - } -} diff --git a/bff/src/main/java/com/vinhonotas/bff/application/services/degustacao/impl/GustatoryInspectionServiceImpl.java b/bff/src/main/java/com/vinhonotas/bff/application/services/degustacao/impl/GustatoryInspectionServiceImpl.java deleted file mode 100644 index 507d8496..00000000 --- a/bff/src/main/java/com/vinhonotas/bff/application/services/degustacao/impl/GustatoryInspectionServiceImpl.java +++ /dev/null @@ -1,76 +0,0 @@ -package com.vinhonotas.bff.application.services.degustacao.impl; - -import com.vinhonotas.bff.application.services.degustacao.GustatoryInspectionService; -import com.vinhonotas.bff.application.services.exceptions.BadRequestException; -import com.vinhonotas.bff.application.services.exceptions.NotFoundException; -import com.vinhonotas.bff.client.degustacao.GustatoryInspectionClient; -import com.vinhonotas.bff.utils.MessagesConstants; -import lombok.RequiredArgsConstructor; -import lombok.extern.slf4j.Slf4j; -import org.springframework.stereotype.Service; - -import java.util.List; -import java.util.Objects; - -@Service -@RequiredArgsConstructor -@Slf4j -public class GustatoryInspectionServiceImpl implements GustatoryInspectionService { - - private final GustatoryInspectionClient gustatoryInspectionClient; - - @Override - public GustatoryInspectionOutputDTO createGustatoryInspection(GustatoryInspectionInputDTO gustatoryInspectionInputDTO) { - log.info("createGustatoryInspection :: Registrando uma inspeção gustativa com os dados: {}", gustatoryInspectionInputDTO.toString()); - try { - return gustatoryInspectionClient.createGustatoryInspection(gustatoryInspectionInputDTO); - } catch (Exception e) { - log.error("createGustatoryInspection :: Ocorreu um erro: {} ", MessagesConstants.ERROR_WHEN_SAVING, e); - throw new BadRequestException(MessagesConstants.ERROR_WHEN_SAVING); - } - } - - @Override - public List getAllGustatoryInspections() { - log.info("getAllGustatoryInspections :: Listando todas as inspeções gustativas"); - List gustatoryInspectionList = gustatoryInspectionClient.getAllGustatoryInspections(); - if (gustatoryInspectionList.isEmpty()) { - log.error("getAllGustatoryInspections :: Ocorreu um erro ao listar as inspeções gustativas: {} ", MessagesConstants.NOT_FOUND); - throw new NotFoundException(MessagesConstants.NOT_FOUND); - } - return gustatoryInspectionList; - } - - @Override - public GustatoryInspectionOutputDTO getGustatoryInspectionById(String id) { - log.info("getGustatoryInspectionById :: Buscando uma inspeção gustativa pelo id: {}", id); - GustatoryInspectionOutputDTO gustatoryInspection = gustatoryInspectionClient.getGustatoryInspectionById(id); - if (Objects.isNull(gustatoryInspection)) { - log.error("getGustatoryInspectionById :: Ocorreu um erro ao buscar a inspeção gustativa: {} ", MessagesConstants.NOT_FOUND); - throw new NotFoundException(MessagesConstants.NOT_FOUND); - } - return gustatoryInspection; - } - - @Override - public GustatoryInspectionOutputDTO updateGustatoryInspection(String id, GustatoryInspectionInputDTO gustatoryInspectionInputDTO) { - log.info("updateGustatoryInspection :: Atualizando uma inspeção gustativa com os dados: {}", gustatoryInspectionInputDTO.toString()); - try { - return gustatoryInspectionClient.updateGustatoryInspection(id, gustatoryInspectionInputDTO); - } catch (Exception e) { - log.error("updateGustatoryInspection :: Ocorreu um erro: {} ", MessagesConstants.ERROR_WHEN_UPDATING, e); - throw new BadRequestException(MessagesConstants.ERROR_WHEN_UPDATING); - } - } - - @Override - public void deleteGustatoryInspection(String id) { - log.info("deleteGustatoryInspection :: Deletando uma inspeção gustativa pelo id: {}", id); - try { - gustatoryInspectionClient.deleteGustatoryInspection(id); - } catch (Exception e) { - log.error("deleteGustatoryInspection :: Ocorreu um erro: {} ", MessagesConstants.ERROR_WHEN_DELETING, e); - throw new BadRequestException(MessagesConstants.ERROR_WHEN_DELETING); - } - } -} diff --git a/bff/src/main/java/com/vinhonotas/bff/application/services/degustacao/impl/OlfactoryInspectionServiceImpl.java b/bff/src/main/java/com/vinhonotas/bff/application/services/degustacao/impl/OlfactoryInspectionServiceImpl.java deleted file mode 100644 index 02ef9a50..00000000 --- a/bff/src/main/java/com/vinhonotas/bff/application/services/degustacao/impl/OlfactoryInspectionServiceImpl.java +++ /dev/null @@ -1,77 +0,0 @@ -package com.vinhonotas.bff.application.services.degustacao.impl; - -import com.vinhonotas.bff.application.services.degustacao.OlfactoryInspectionService; -import com.vinhonotas.bff.application.services.exceptions.BadRequestException; -import com.vinhonotas.bff.application.services.exceptions.NotFoundException; -import com.vinhonotas.bff.client.degustacao.OlfactoryInspectionClient; -import com.vinhonotas.bff.utils.MessagesConstants; -import lombok.RequiredArgsConstructor; -import lombok.extern.slf4j.Slf4j; -import org.springframework.stereotype.Service; - -import java.util.List; -import java.util.Objects; - -@Service -@RequiredArgsConstructor -@Slf4j -public class OlfactoryInspectionServiceImpl implements OlfactoryInspectionService { - - private final OlfactoryInspectionClient olfactoryInspectionClient; - - @Override - public OlfactoryInspectionOutputDTO createOlfactoryInspection(OlfactoryInspectionInputDTO olfactoryInspectionInputDTO) { - log.info("createOlafactoryInspection :: Registrando uma nova inspeção olfativa com os dados: {}", olfactoryInspectionInputDTO.toString()); - try { - return olfactoryInspectionClient.createOlafactoryInspection(olfactoryInspectionInputDTO); - } catch (Exception e) { - log.error("createOlafactoryInspection :: Ocorreu um erro: {} ", MessagesConstants.ERROR_WHEN_SAVING, e); - throw new BadRequestException(MessagesConstants.ERROR_WHEN_SAVING); - } - } - - @Override - public List getAllOlfactoryInspections() { - log.info("getAllOlfactoryInspections :: Listando todas as inspeções olfativas"); - List allOlfactoryInspections = olfactoryInspectionClient.getAllOlfactoryInspections(); - if (allOlfactoryInspections.isEmpty()) { - log.error("getAllOlfactoryInspections :: Ocorreu um erro ao listar as inspeções olfativas: {} ", MessagesConstants.NOT_FOUND); - throw new NotFoundException(MessagesConstants.NOT_FOUND); - } - return allOlfactoryInspections; - } - - @Override - public OlfactoryInspectionOutputDTO getOlfactoryInspectionById(String id) { - log.info("getOlfactoryInspectionById :: Buscando inspeção olfativa pelo id: {}", id); - OlfactoryInspectionOutputDTO allOlfactoryInspection = olfactoryInspectionClient.getOlfactoryInspectionById(id); - if (Objects.isNull(allOlfactoryInspection)) { - log.error("getOlfactoryInspectionById :: Ocorreu um erro ao buscar a inspeção olfativa: {} ", MessagesConstants.NOT_FOUND); - throw new NotFoundException(MessagesConstants.NOT_FOUND); - } - return allOlfactoryInspection; - } - - @Override - public OlfactoryInspectionOutputDTO updateOlfactoryInspection(String id, OlfactoryInspectionInputDTO olfactoryInspectionInputDTO) { - log.info("updateOlfactoryInspection :: Atualizando inspeção olfativa com os dados: {}", olfactoryInspectionInputDTO.toString()); - try { - return olfactoryInspectionClient.updateOlfactoryInspection(id, olfactoryInspectionInputDTO); - } catch (Exception e) { - log.error("updateOlfactoryInspection :: Ocorreu um erro: {} ", MessagesConstants.ERROR_WHEN_UPDATING, e); - throw new BadRequestException(MessagesConstants.ERROR_WHEN_UPDATING); - } - } - - @Override - public void deleteOlfactoryInspection(String id) { - log.info("deleteOlfactoryInspection :: Deletando inspeção olfativa pelo id: {}", id); - try { - olfactoryInspectionClient.deleteOlfactoryInspection(id); - } catch (Exception e) { - log.error("deleteOlfactoryInspection :: Ocorreu um erro: {} ", MessagesConstants.ERROR_WHEN_DELETING, e); - throw new BadRequestException(MessagesConstants.ERROR_WHEN_DELETING); - } - } - -} diff --git a/bff/src/main/java/com/vinhonotas/bff/application/services/degustacao/impl/TastingServiceImpl.java b/bff/src/main/java/com/vinhonotas/bff/application/services/degustacao/impl/TastingServiceImpl.java deleted file mode 100644 index 49f1ee92..00000000 --- a/bff/src/main/java/com/vinhonotas/bff/application/services/degustacao/impl/TastingServiceImpl.java +++ /dev/null @@ -1,77 +0,0 @@ -package com.vinhonotas.bff.application.services.degustacao.impl; - -import com.vinhonotas.bff.application.services.degustacao.TastingService; -import com.vinhonotas.bff.application.services.exceptions.BadRequestException; -import com.vinhonotas.bff.application.services.exceptions.NotFoundException; -import com.vinhonotas.bff.client.degustacao.TastingClient; -import com.vinhonotas.bff.utils.MessagesConstants; -import lombok.RequiredArgsConstructor; -import lombok.extern.slf4j.Slf4j; -import org.springframework.stereotype.Service; - -import java.util.List; -import java.util.Objects; - -@Service -@RequiredArgsConstructor -@Slf4j -public class TastingServiceImpl implements TastingService { - - private final TastingClient tastingClient; - - @Override - public TastingOutputDTO createTasting(TastingInputDTO tastingInputDTO) { - log.info("createTasting :: Registrando uma degustação com os dados: {}", tastingInputDTO.toString()); - try { - return tastingClient.createTasting(tastingInputDTO); - } catch (Exception e) { - log.error("createTasting :: Ocorreu um erro: {} ", MessagesConstants.ERROR_WHEN_SAVING, e); - throw new BadRequestException(MessagesConstants.ERROR_WHEN_SAVING); - } - } - - @Override - public List getAllTastings() { - log.info("getAllTastings :: Listando todas as degustações"); - List tastings = tastingClient.getAllTastings(); - if (tastings.isEmpty()) { - log.error("getAllTastings :: Ocorreu um erro ao listar as degustações: {} ", MessagesConstants.NOT_FOUND); - throw new NotFoundException(MessagesConstants.NOT_FOUND); - } - return tastings; - } - - @Override - public TastingOutputDTO getTastingById(String id) { - log.info("getTastingById :: Buscando uma degustação pelo id: {}", id); - TastingOutputDTO tasting = tastingClient.getTastingById(id); - if (Objects.isNull(tasting)) { - log.error("getTastingById :: Ocorreu um erro ao buscar a degustação: {} ", MessagesConstants.NOT_FOUND); - throw new NotFoundException(MessagesConstants.NOT_FOUND); - } - return tasting; - } - - @Override - public TastingOutputDTO updateTasting(String id, TastingInputDTO tastingInputDTO) { - log.info("updateTasting :: Atualizando degustação com os dados: {}", tastingInputDTO.toString()); - try { - return tastingClient.updateTasting(id, tastingInputDTO); - } catch (Exception e) { - log.error("updateTasting :: Ocorreu um erro: {} ", MessagesConstants.ERROR_WHEN_UPDATING, e); - throw new BadRequestException(MessagesConstants.ERROR_WHEN_UPDATING); - } - } - - @Override - public void deleteTasting(String id) { - log.info("deleteTasting :: Deletando uma degustação pelo id: {}", id); - try { - tastingClient.deleteTasting(id); - } catch (Exception e) { - log.error("deleteTasting :: Ocorreu um erro: {} ", MessagesConstants.ERROR_WHEN_DELETING, e); - throw new BadRequestException(MessagesConstants.ERROR_WHEN_DELETING); - } - } - -} diff --git a/bff/src/main/java/com/vinhonotas/bff/application/services/degustacao/impl/VisualInspectionServiceImpl.java b/bff/src/main/java/com/vinhonotas/bff/application/services/degustacao/impl/VisualInspectionServiceImpl.java deleted file mode 100644 index 7d1b0daf..00000000 --- a/bff/src/main/java/com/vinhonotas/bff/application/services/degustacao/impl/VisualInspectionServiceImpl.java +++ /dev/null @@ -1,77 +0,0 @@ -package com.vinhonotas.bff.application.services.degustacao.impl; - -import com.vinhonotas.bff.application.services.degustacao.VisualInspectionService; -import com.vinhonotas.bff.application.services.exceptions.BadRequestException; -import com.vinhonotas.bff.application.services.exceptions.NotFoundException; -import com.vinhonotas.bff.client.degustacao.VisualInspectionClient; -import com.vinhonotas.bff.utils.MessagesConstants; -import lombok.RequiredArgsConstructor; -import lombok.extern.slf4j.Slf4j; -import org.springframework.stereotype.Service; - -import java.util.List; -import java.util.Objects; - -@Service -@RequiredArgsConstructor -@Slf4j -public class VisualInspectionServiceImpl implements VisualInspectionService { - - private final VisualInspectionClient visualInspectionClient; - - @Override - public VisualInspectionOutputDTO createVisualInspection(VisualInspectionInputDTO visualInspectionInputDTO) { - log.info("createVisualInspection :: Registrando uma inspeção visual com os dados: {}", visualInspectionInputDTO.toString()); - try { - return visualInspectionClient.createVisualInspection(visualInspectionInputDTO); - } catch (Exception e) { - log.error("createVisualInspection :: Ocorreu um erro: {} ", MessagesConstants.ERROR_WHEN_SAVING, e); - throw new BadRequestException(MessagesConstants.ERROR_WHEN_SAVING); - } - } - - @Override - public List getAllVisualInspections() { - log.info("getAllVisualInspections :: Listando todas as inspeções visuais"); - List visualInspectionList = visualInspectionClient.getAllVisualInspections(); - if (visualInspectionList.isEmpty()) { - log.error("getAllVisualInspections :: Ocorreu um erro ao listar as inspeções visuais: {} ", MessagesConstants.NOT_FOUND); - throw new NotFoundException(MessagesConstants.NOT_FOUND); - } - return visualInspectionList; - } - - @Override - public VisualInspectionOutputDTO getVisualInspectionById(String id) { - log.info("getVisualInspectionById :: Buscando uma inspeção visual pelo id: {}", id); - VisualInspectionOutputDTO visualInspection = visualInspectionClient.getVisualInspectionById(id); - if (Objects.isNull(visualInspection)) { - log.error("getVisualInspectionById :: Ocorreu um erro ao buscar a inspeção visual: {} ", MessagesConstants.NOT_FOUND); - throw new NotFoundException(MessagesConstants.NOT_FOUND); - } - return visualInspection; - } - - @Override - public VisualInspectionOutputDTO updateVisualInspection(String id, VisualInspectionInputDTO visualInspectionInputDTO) { - log.info("updateVisualInspection :: Atualizando a inspeção visual com os dados: {}", visualInspectionInputDTO.toString()); - try { - return visualInspectionClient.updateVisualInspection(id, visualInspectionInputDTO); - } catch (Exception e) { - log.error("updateVisualInspection :: Ocorreu um erro: {} ", MessagesConstants.ERROR_WHEN_UPDATING, e); - throw new BadRequestException(MessagesConstants.ERROR_WHEN_UPDATING); - } - } - - @Override - public void deleteVisualInspection(String id) { - log.info("deleteVisualInspection :: Deletando uma inspeção visual pelo id: {}", id); - try { - visualInspectionClient.deleteVisualInspection(id); - } catch (Exception e) { - log.error("deleteVisualInspection :: Ocorreu um erro: {} ", MessagesConstants.ERROR_WHEN_DELETING, e); - throw new BadRequestException(MessagesConstants.ERROR_WHEN_DELETING); - } - } - -} diff --git a/bff/src/main/java/com/vinhonotas/bff/client/degustacao/AromasClient.java b/bff/src/main/java/com/vinhonotas/bff/client/degustacao/AromasClient.java deleted file mode 100644 index 02a43f20..00000000 --- a/bff/src/main/java/com/vinhonotas/bff/client/degustacao/AromasClient.java +++ /dev/null @@ -1,28 +0,0 @@ -package com.vinhonotas.bff.client.degustacao; - -import com.vinhonotas.bff.configuration.FeignConfig; -import jakarta.validation.Valid; -import org.springframework.cloud.openfeign.FeignClient; -import org.springframework.web.bind.annotation.*; - -import java.util.List; - -@FeignClient(name = "aromas", url = "${degustacao-api.url}", configuration = FeignConfig.class) -public interface AromasClient { - - @PostMapping("/aromas") - AromasOutputDTO createAromas(@Valid @RequestBody AromasInputDTO aromasInputDTO); - - @GetMapping("/aromas") - List getAllAromas(); - - @GetMapping("/aromas/{id}") - AromasOutputDTO getAromasById(@PathVariable("id") String id); - - @PutMapping("/aromas/{id}") - AromasOutputDTO updateAromas(@PathVariable ("id") String id, @Valid @RequestBody AromasInputDTO aromasInputDTO); - - @DeleteMapping("/aromas/{id}") - void deleteAromas(@PathVariable ("id") String id); - -} diff --git a/bff/src/main/java/com/vinhonotas/bff/client/degustacao/GustatoryInspectionClient.java b/bff/src/main/java/com/vinhonotas/bff/client/degustacao/GustatoryInspectionClient.java deleted file mode 100644 index e6a73f9b..00000000 --- a/bff/src/main/java/com/vinhonotas/bff/client/degustacao/GustatoryInspectionClient.java +++ /dev/null @@ -1,29 +0,0 @@ -package com.vinhonotas.bff.client.degustacao; - -import com.vinhonotas.bff.configuration.FeignConfig; -import jakarta.validation.Valid; -import org.springframework.cloud.openfeign.FeignClient; -import org.springframework.web.bind.annotation.*; - -import java.util.List; - -@FeignClient(name = "gustatory-inspection", url = "${degustacao-api.url}", configuration = FeignConfig.class) -public interface GustatoryInspectionClient { - - @PostMapping("/gustatory-inspection") - GustatoryInspectionOutputDTO createGustatoryInspection(@Valid @RequestBody GustatoryInspectionInputDTO gustatoryInspectionInputDTO); - - @GetMapping("/gustatory-inspection") - List getAllGustatoryInspections(); - - @GetMapping("/gustatory-inspection/{id}") - GustatoryInspectionOutputDTO getGustatoryInspectionById(@PathVariable("id") String id); - - @PutMapping("/gustatory-inspection/{id}") - GustatoryInspectionOutputDTO updateGustatoryInspection(@PathVariable ("id") String id, - @Valid @RequestBody GustatoryInspectionInputDTO gustatoryInspectionInputDTO); - - @DeleteMapping("/gustatory-inspection/{id}") - void deleteGustatoryInspection(@PathVariable ("id") String id); - -} diff --git a/bff/src/main/java/com/vinhonotas/bff/client/degustacao/OlfactoryInspectionClient.java b/bff/src/main/java/com/vinhonotas/bff/client/degustacao/OlfactoryInspectionClient.java deleted file mode 100644 index d6ea76a4..00000000 --- a/bff/src/main/java/com/vinhonotas/bff/client/degustacao/OlfactoryInspectionClient.java +++ /dev/null @@ -1,28 +0,0 @@ -package com.vinhonotas.bff.client.degustacao; - -import com.vinhonotas.bff.configuration.FeignConfig; -import jakarta.validation.Valid; -import org.springframework.cloud.openfeign.FeignClient; -import org.springframework.web.bind.annotation.*; - -import java.util.List; - -@FeignClient(name = "olfactory-inspection", url = "${degustacao-api.url}", configuration = FeignConfig.class) -public interface OlfactoryInspectionClient { - - @PostMapping("/olfactory-inspection") - OlfactoryInspectionOutputDTO createOlafactoryInspection(@Valid @RequestBody OlfactoryInspectionInputDTO olfactoryInspectionInputDTO); - - @GetMapping("/olfactory-inspection") - List getAllOlfactoryInspections(); - - @GetMapping("/olfactory-inspection/{id}") - OlfactoryInspectionOutputDTO getOlfactoryInspectionById(@PathVariable("id") String id); - - @PutMapping("/olfactory-inspection/{id}") - OlfactoryInspectionOutputDTO updateOlfactoryInspection(@PathVariable ("id") String id, @Valid @RequestBody OlfactoryInspectionInputDTO olfactoryInspectionInputDTO); - - @DeleteMapping("/olfactory-inspection/{id}") - void deleteOlfactoryInspection(@PathVariable ("id") String id); - -} diff --git a/bff/src/main/java/com/vinhonotas/bff/client/degustacao/TastingClient.java b/bff/src/main/java/com/vinhonotas/bff/client/degustacao/TastingClient.java deleted file mode 100644 index 4b247bea..00000000 --- a/bff/src/main/java/com/vinhonotas/bff/client/degustacao/TastingClient.java +++ /dev/null @@ -1,28 +0,0 @@ -package com.vinhonotas.bff.client.degustacao; - -import com.vinhonotas.bff.configuration.FeignConfig; -import jakarta.validation.Valid; -import org.springframework.cloud.openfeign.FeignClient; -import org.springframework.web.bind.annotation.*; - -import java.util.List; - -@FeignClient(name = "tasting", url = "${degustacao-api.url}", configuration = FeignConfig.class) -public interface TastingClient { - - @PostMapping("/tasting") - TastingOutputDTO createTasting(@Valid @RequestBody TastingInputDTO tastingInputDTO); - - @GetMapping("/tasting") - List getAllTastings(); - - @GetMapping("/tasting/{id}") - TastingOutputDTO getTastingById(@PathVariable ("id") String id); - - @PutMapping("/tasting/{id}") - TastingOutputDTO updateTasting(@PathVariable ("id") String id, @Valid @RequestBody TastingInputDTO tastingInputDTO); - - @DeleteMapping("/tasting/{id}") - void deleteTasting(@PathVariable ("id") String id); - -} diff --git a/bff/src/main/java/com/vinhonotas/bff/client/degustacao/VisualInspectionClient.java b/bff/src/main/java/com/vinhonotas/bff/client/degustacao/VisualInspectionClient.java deleted file mode 100644 index 0a39c399..00000000 --- a/bff/src/main/java/com/vinhonotas/bff/client/degustacao/VisualInspectionClient.java +++ /dev/null @@ -1,28 +0,0 @@ -package com.vinhonotas.bff.client.degustacao; - -import com.vinhonotas.bff.configuration.FeignConfig; -import jakarta.validation.Valid; -import org.springframework.cloud.openfeign.FeignClient; -import org.springframework.web.bind.annotation.*; - -import java.util.List; - -@FeignClient(name = "visual-inspection", url = "${degustacao-api.url}", configuration = FeignConfig.class) -public interface VisualInspectionClient { - - @PostMapping("/visual-inspection") - VisualInspectionOutputDTO createVisualInspection(@Valid @RequestBody VisualInspectionInputDTO visualInspectionInputDTO); - - @GetMapping("/visual-inspection") - List getAllVisualInspections(); - - @GetMapping("/visual-inspection/{id}") - VisualInspectionOutputDTO getVisualInspectionById(@PathVariable("id") String id); - - @PutMapping("/visual-inspection/{id}") - VisualInspectionOutputDTO updateVisualInspection(@PathVariable ("id") String id, @Valid @RequestBody VisualInspectionInputDTO visualInspectionInputDTO); - - @DeleteMapping("/visual-inspection/{id}") - void deleteVisualInspection(@PathVariable ("id") String id); - -} diff --git a/bff/src/main/java/com/vinhonotas/bff/interfaces/controllers/degustacao/AromasController.java b/bff/src/main/java/com/vinhonotas/bff/interfaces/controllers/degustacao/AromasController.java deleted file mode 100644 index b9886e44..00000000 --- a/bff/src/main/java/com/vinhonotas/bff/interfaces/controllers/degustacao/AromasController.java +++ /dev/null @@ -1,45 +0,0 @@ -package com.vinhonotas.bff.interfaces.controllers.degustacao; - -import com.vinhonotas.bff.application.services.degustacao.AromasService; -import jakarta.validation.Valid; -import lombok.RequiredArgsConstructor; -import org.springframework.http.ResponseEntity; -import org.springframework.web.bind.annotation.*; - -import java.util.List; - -@RestController -@RequestMapping("/api/v1/aromas") -@RequiredArgsConstructor -@CrossOrigin(origins = "http://localhost:5173", maxAge = 3600) -public class AromasController { - - private final AromasService aromasService; - - @PostMapping - public ResponseEntity createAromas(@Valid @RequestBody AromasInputDTO aromasInputDTO) { - return ResponseEntity.ok(aromasService.createAromas(aromasInputDTO)); - } - - @GetMapping - public ResponseEntity> getAllAromas() { - return ResponseEntity.ok(aromasService.getAllAromas()); - } - - @GetMapping("/{id}") - public ResponseEntity getAromasById(@PathVariable("id") String id) { - return ResponseEntity.ok(aromasService.getAromasById(id)); - } - - @PutMapping("/{id}") - public ResponseEntity updateAromas(@PathVariable ("id") String id, @Valid @RequestBody AromasInputDTO aromasInputDTO) { - return ResponseEntity.ok(aromasService.updateAromas(id, aromasInputDTO)); - } - - @DeleteMapping("/{id}") - public ResponseEntity deleteAromas(@PathVariable ("id") String id) { - aromasService.deleteAromas(id); - return ResponseEntity.noContent().build(); - } - -} diff --git a/bff/src/main/java/com/vinhonotas/bff/interfaces/controllers/degustacao/GustatoryInspectionController.java b/bff/src/main/java/com/vinhonotas/bff/interfaces/controllers/degustacao/GustatoryInspectionController.java deleted file mode 100644 index 57473c53..00000000 --- a/bff/src/main/java/com/vinhonotas/bff/interfaces/controllers/degustacao/GustatoryInspectionController.java +++ /dev/null @@ -1,46 +0,0 @@ -package com.vinhonotas.bff.interfaces.controllers.degustacao; - -import com.vinhonotas.bff.application.services.degustacao.GustatoryInspectionService; -import jakarta.validation.Valid; -import lombok.RequiredArgsConstructor; -import org.springframework.http.ResponseEntity; -import org.springframework.web.bind.annotation.*; - -import java.util.List; - -@RestController -@RequestMapping("/api/v1/gustatory-inspection") -@RequiredArgsConstructor -@CrossOrigin(origins = "http://localhost:5173", maxAge = 3600) -public class GustatoryInspectionController { - - private final GustatoryInspectionService gustatoryInspectionService; - - @PostMapping - public ResponseEntity createGustatoryInspection(@Valid @RequestBody GustatoryInspectionInputDTO gustatoryInspectionInputDTO) { - return ResponseEntity.ok(gustatoryInspectionService.createGustatoryInspection(gustatoryInspectionInputDTO)); - } - - @GetMapping - public ResponseEntity> getAllGustatoryInspections() { - return ResponseEntity.ok(gustatoryInspectionService.getAllGustatoryInspections()); - } - - @GetMapping("/{id}") - public ResponseEntity getGustatoryInspectionById(@PathVariable("id") String id) { - return ResponseEntity.ok(gustatoryInspectionService.getGustatoryInspectionById(id)); - } - - @PutMapping("/{id}") - public ResponseEntity updateGustatoryInspection(@PathVariable ("id") String id, - @Valid @RequestBody GustatoryInspectionInputDTO gustatoryInspectionInputDTO) { - return ResponseEntity.ok(gustatoryInspectionService.updateGustatoryInspection(id, gustatoryInspectionInputDTO)); - } - - @DeleteMapping("/{id}") - public ResponseEntity deleteGustatoryInspection(@PathVariable ("id") String id) { - gustatoryInspectionService.deleteGustatoryInspection(id); - return ResponseEntity.noContent().build(); - } - -} diff --git a/bff/src/main/java/com/vinhonotas/bff/interfaces/controllers/degustacao/OlfactoryInspectionController.java b/bff/src/main/java/com/vinhonotas/bff/interfaces/controllers/degustacao/OlfactoryInspectionController.java deleted file mode 100644 index 007de081..00000000 --- a/bff/src/main/java/com/vinhonotas/bff/interfaces/controllers/degustacao/OlfactoryInspectionController.java +++ /dev/null @@ -1,45 +0,0 @@ -package com.vinhonotas.bff.interfaces.controllers.degustacao; - -import com.vinhonotas.bff.application.services.degustacao.OlfactoryInspectionService; -import jakarta.validation.Valid; -import lombok.RequiredArgsConstructor; -import org.springframework.http.ResponseEntity; -import org.springframework.web.bind.annotation.*; - -import java.util.List; - -@RestController -@RequiredArgsConstructor -@RequestMapping(value = "/api/v1/olfactory-inspection") -@CrossOrigin(origins = "http://localhost:5173", maxAge = 3600) -public class OlfactoryInspectionController { - - private final OlfactoryInspectionService olfactoryInspectionService; - - @PostMapping - public ResponseEntity createOlafactoryInspection(@Valid @RequestBody OlfactoryInspectionInputDTO olfactoryInspectionInputDTO) { - return ResponseEntity.ok(olfactoryInspectionService.createOlfactoryInspection(olfactoryInspectionInputDTO)); - } - - @GetMapping - public ResponseEntity> getAllOlfactoryInspections() { - return ResponseEntity.ok(olfactoryInspectionService.getAllOlfactoryInspections()); - } - - @GetMapping("/{id}") - public ResponseEntity getOlfactoryInspectionById(@PathVariable("id") String id) { - return ResponseEntity.ok(olfactoryInspectionService.getOlfactoryInspectionById(id)); - } - - @PutMapping("/{id}") - public ResponseEntity updateOlfactoryInspection(@PathVariable ("id") String id, @Valid @RequestBody OlfactoryInspectionInputDTO olfactoryInspectionInputDTO) { - return ResponseEntity.ok(olfactoryInspectionService.updateOlfactoryInspection(id, olfactoryInspectionInputDTO)); - } - - @DeleteMapping("/{id}") - public ResponseEntity deleteOlfactoryInspection(@PathVariable ("id") String id) { - olfactoryInspectionService.deleteOlfactoryInspection(id); - return ResponseEntity.noContent().build(); - } - -} diff --git a/bff/src/main/java/com/vinhonotas/bff/interfaces/controllers/degustacao/TastingController.java b/bff/src/main/java/com/vinhonotas/bff/interfaces/controllers/degustacao/TastingController.java deleted file mode 100644 index 1ab01a5c..00000000 --- a/bff/src/main/java/com/vinhonotas/bff/interfaces/controllers/degustacao/TastingController.java +++ /dev/null @@ -1,45 +0,0 @@ -package com.vinhonotas.bff.interfaces.controllers.degustacao; - -import com.vinhonotas.bff.application.services.degustacao.TastingService; -import jakarta.validation.Valid; -import lombok.RequiredArgsConstructor; -import org.springframework.http.ResponseEntity; -import org.springframework.web.bind.annotation.*; - -import java.util.List; - -@RestController -@RequestMapping("/api/v1/tasting") -@RequiredArgsConstructor -@CrossOrigin(origins = "http://localhost:5173", maxAge = 3600) -public class TastingController { - - private final TastingService tastingService; - - @PostMapping - public ResponseEntity createTasting(@Valid @RequestBody TastingInputDTO tastingInputDTO) { - return ResponseEntity.ok(tastingService.createTasting(tastingInputDTO)); - } - - @GetMapping - public ResponseEntity> getAllTastings() { - return ResponseEntity.ok(tastingService.getAllTastings()); - } - - @GetMapping("/{id}") - public ResponseEntity getTastingById(@PathVariable ("id") String id) { - return ResponseEntity.ok(tastingService.getTastingById(id)); - } - - @PutMapping("/{id}") - public ResponseEntity updateTasting(@PathVariable ("id") String id, @Valid @RequestBody TastingInputDTO tastingInputDTO) { - return ResponseEntity.ok(tastingService.updateTasting(id, tastingInputDTO)); - } - - @DeleteMapping("/{id}") - public ResponseEntity deleteTasting(@PathVariable String id) { - tastingService.deleteTasting(id); - return ResponseEntity.noContent().build(); - } - -} diff --git a/bff/src/main/java/com/vinhonotas/bff/interfaces/controllers/degustacao/VisualInspectionController.java b/bff/src/main/java/com/vinhonotas/bff/interfaces/controllers/degustacao/VisualInspectionController.java deleted file mode 100644 index 8adb668a..00000000 --- a/bff/src/main/java/com/vinhonotas/bff/interfaces/controllers/degustacao/VisualInspectionController.java +++ /dev/null @@ -1,45 +0,0 @@ -package com.vinhonotas.bff.interfaces.controllers.degustacao; - -import com.vinhonotas.bff.application.services.degustacao.VisualInspectionService; -import jakarta.validation.Valid; -import lombok.RequiredArgsConstructor; -import org.springframework.http.ResponseEntity; -import org.springframework.web.bind.annotation.*; - -import java.util.List; - -@RestController -@RequestMapping("/api/v1/visual-inspection") -@RequiredArgsConstructor -@CrossOrigin(origins = "http://localhost:5173", maxAge = 3600) -public class VisualInspectionController { - - private final VisualInspectionService visualInspectionService; - - @PostMapping - public ResponseEntity createVisualInspection(@Valid @RequestBody VisualInspectionInputDTO visualInspectionInputDTO) { - return ResponseEntity.ok(visualInspectionService.createVisualInspection(visualInspectionInputDTO)); - } - - @GetMapping - public ResponseEntity> getAllVisualInspections() { - return ResponseEntity.ok(visualInspectionService.getAllVisualInspections()); - } - - @GetMapping("/{id}") - public ResponseEntity getVisualInspectionById(@PathVariable("id") String id) { - return ResponseEntity.ok(visualInspectionService.getVisualInspectionById(id)); - } - - @PutMapping("/{id}") - public ResponseEntity updateVisualInspection(@PathVariable ("id") String id, @Valid @RequestBody VisualInspectionInputDTO visualInspectionInputDTO) { - return ResponseEntity.ok(visualInspectionService.updateVisualInspection(id, visualInspectionInputDTO)); - } - - @DeleteMapping("/{id}") - public ResponseEntity deleteVisualInspection(@PathVariable ("id") String id) { - visualInspectionService.deleteVisualInspection(id); - return ResponseEntity.noContent().build(); - } - -} diff --git a/bff/src/test/java/com/vinhonotas/bff/application/services/degustacao/impl/AromasServiceImplTest.java b/bff/src/test/java/com/vinhonotas/bff/application/services/degustacao/impl/AromasServiceImplTest.java deleted file mode 100644 index b26626f6..00000000 --- a/bff/src/test/java/com/vinhonotas/bff/application/services/degustacao/impl/AromasServiceImplTest.java +++ /dev/null @@ -1,234 +0,0 @@ -//package com.vinhonotas.bff.application.services.degustacao.impl; -// -//import com.vinhonotas.bff.application.services.exceptions.BadRequestException; -//import com.vinhonotas.bff.client.degustacao.AromasClient; -//import com.vinhonotas.bff.domain.enums.*; -//import com.vinhonotas.bff.utils.MessagesConstants; -//import org.junit.jupiter.api.BeforeEach; -//import org.junit.jupiter.api.DisplayName; -//import org.junit.jupiter.api.Test; -//import org.junit.jupiter.api.extension.ExtendWith; -//import org.mockito.InjectMocks; -//import org.mockito.Mock; -//import org.mockito.junit.jupiter.MockitoExtension; -// -//import java.time.LocalDate; -//import java.util.List; -//import java.util.UUID; -// -//import static org.junit.jupiter.api.Assertions.*; -//import static org.mockito.Mockito.*; -// -//@ExtendWith(MockitoExtension.class) -//class AromasServiceImplTest { -// -// @InjectMocks -// private AromasServiceImpl aromasService; -// -// @Mock -// private AromasClient aromasClient; -// -// private AromasOutputDTO aromasOutputDTO; -// private AromasInputDTO aromasInputDTO; -// -// @BeforeEach -// void setUp() { -// aromasOutputDTO = createAromasOutputDTO(); -// aromasInputDTO = createAromasInputDTO(); -// } -// -// @Test -// @DisplayName("Deve criar um novo registro de Aromas") -// void testCreate() { -// when(aromasClient.createAromas(aromasInputDTO)).thenReturn(aromasOutputDTO); -// -// AromasOutputDTO response = assertDoesNotThrow(() -> aromasService.createAromas(aromasInputDTO)); -// -// assertNotNull(response); -// assertEquals(aromasOutputDTO.getTastingData(), response.getTastingData()); -// assertEquals(aromasOutputDTO.getWineTasted(), response.getWineTasted()); -// assertEquals(aromasOutputDTO.getFruity(), response.getFruity()); -// assertEquals(aromasOutputDTO.getDryFruits(), response.getDryFruits()); -// assertEquals(aromasOutputDTO.getFlorals(), response.getFlorals()); -// assertEquals(aromasOutputDTO.getVegetablesAndHerbs(), response.getVegetablesAndHerbs()); -// assertEquals(aromasOutputDTO.getMinerals(), response.getMinerals()); -// assertEquals(aromasOutputDTO.getSpices(), response.getSpices()); -// assertEquals(aromasOutputDTO.getAnimals(), response.getAnimals()); -// assertEquals(aromasOutputDTO.getEmpireumatics(), response.getEmpireumatics()); -// assertEquals(aromasOutputDTO.getWood(), response.getWood()); -// assertEquals(aromasOutputDTO.getChemicals(), response.getChemicals()); -// assertEquals(aromasOutputDTO.getLacteal(), response.getLacteal()); -// assertEquals(aromasOutputDTO.getSweets(), response.getSweets()); -// verify(aromasClient).createAromas(aromasInputDTO); -// } -// -// @Test -// @DisplayName("Deve lançar BadRequestException ao tentar criar um novo registro de Aromas") -// void testCreateThrowsBadRequestException() { -// when(aromasClient.createAromas(aromasInputDTO)).thenThrow(new BadRequestException(MessagesConstants.ERROR_WHEN_SAVING)); -// -// Exception exception = assertThrows(Exception.class, () -> aromasService.createAromas(aromasInputDTO)); -// -// assertEquals(MessagesConstants.ERROR_WHEN_SAVING, exception.getMessage()); -// } -// -// @Test -// @DisplayName("Deve retornar uma lista de Aromas") -// void testGetAll() { -// when(aromasClient.getAllAromas()).thenReturn(List.of(aromasOutputDTO)); -// -// List list = assertDoesNotThrow(() -> aromasService.getAllAromas()); -// -// assertNotNull(list); -// assertFalse(list.isEmpty()); -// assertEquals(1, list.size()); -// assertEquals(aromasOutputDTO.getTastingData(), list.get(0).getTastingData()); -// assertEquals(aromasOutputDTO.getWineTasted(), list.get(0).getWineTasted()); -// assertEquals(aromasOutputDTO.getFruity(), list.get(0).getFruity()); -// assertEquals(aromasOutputDTO.getDryFruits(), list.get(0).getDryFruits()); -// assertEquals(aromasOutputDTO.getFlorals(), list.get(0).getFlorals()); -// assertEquals(aromasOutputDTO.getVegetablesAndHerbs(), list.get(0).getVegetablesAndHerbs()); -// assertEquals(aromasOutputDTO.getMinerals(), list.get(0).getMinerals()); -// assertEquals(aromasOutputDTO.getSpices(), list.get(0).getSpices()); -// assertEquals(aromasOutputDTO.getAnimals(), list.get(0).getAnimals()); -// assertEquals(aromasOutputDTO.getEmpireumatics(), list.get(0).getEmpireumatics()); -// assertEquals(aromasOutputDTO.getWood(), list.get(0).getWood()); -// assertEquals(aromasOutputDTO.getChemicals(), list.get(0).getChemicals()); -// assertEquals(aromasOutputDTO.getLacteal(), list.get(0).getLacteal()); -// assertEquals(aromasOutputDTO.getSweets(), list.get(0).getSweets()); -// verify(aromasClient).getAllAromas(); -// } -// -// @Test -// @DisplayName("Deve lançar BadRequestException ao tentar retornar uma lista de Aromas") -// void testGetAllThrowsBadRequestException() { -// when(aromasClient.getAllAromas()).thenReturn(List.of()); -// Exception exception = assertThrows(Exception.class, () -> aromasService.getAllAromas()); -// -// assertEquals(MessagesConstants.NOT_FOUND, exception.getMessage()); -// } -// -// @Test -// @DisplayName("Deve retornar um registro de Aromas") -// void testGetById() { -// when(aromasClient.getAromasById("f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e")).thenReturn(aromasOutputDTO); -// -// AromasOutputDTO entity = assertDoesNotThrow(() -> aromasService.getAromasById("f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e")); -// -// assertNotNull(entity); -// assertEquals(aromasOutputDTO.getTastingData(), entity.getTastingData()); -// assertEquals(aromasOutputDTO.getWineTasted(), entity.getWineTasted()); -// assertEquals(aromasOutputDTO.getFruity(), entity.getFruity()); -// assertEquals(aromasOutputDTO.getDryFruits(), entity.getDryFruits()); -// assertEquals(aromasOutputDTO.getFlorals(), entity.getFlorals()); -// assertEquals(aromasOutputDTO.getVegetablesAndHerbs(), entity.getVegetablesAndHerbs()); -// assertEquals(aromasOutputDTO.getMinerals(), entity.getMinerals()); -// assertEquals(aromasOutputDTO.getSpices(), entity.getSpices()); -// assertEquals(aromasOutputDTO.getAnimals(), entity.getAnimals()); -// assertEquals(aromasOutputDTO.getEmpireumatics(), entity.getEmpireumatics()); -// assertEquals(aromasOutputDTO.getWood(), entity.getWood()); -// assertEquals(aromasOutputDTO.getChemicals(), entity.getChemicals()); -// assertEquals(aromasOutputDTO.getLacteal(), entity.getLacteal()); -// assertEquals(aromasOutputDTO.getSweets(), entity.getSweets()); -// verify(aromasClient).getAromasById("f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e"); -// } -// -// @Test -// @DisplayName("Deve lançar BadRequestException ao tentar retornar um registro de Aromas") -// void testGetByIdThrowsBadRequestException() { -// when(aromasClient.getAromasById("f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e")).thenReturn(null); -// Exception exception = assertThrows(Exception.class, () -> aromasService.getAromasById("f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e")); -// -// assertEquals(MessagesConstants.NOT_FOUND, exception.getMessage()); -// } -// -// @Test -// @DisplayName("Deve atualizar um registro de Aromas") -// void testUpdate() { -// when(aromasClient.updateAromas("f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e", aromasInputDTO)).thenReturn(aromasOutputDTO); -// -// AromasOutputDTO aromasUpdated = assertDoesNotThrow(() -> aromasService.updateAromas("f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e", aromasInputDTO)); -// -// assertNotNull(aromasUpdated); -// assertEquals(aromasOutputDTO.getTastingData(), aromasUpdated.getTastingData()); -// assertEquals(aromasOutputDTO.getWineTasted(), aromasUpdated.getWineTasted()); -// assertEquals(aromasOutputDTO.getFruity(), aromasUpdated.getFruity()); -// assertEquals(aromasOutputDTO.getDryFruits(), aromasUpdated.getDryFruits()); -// assertEquals(aromasOutputDTO.getFlorals(), aromasUpdated.getFlorals()); -// assertEquals(aromasOutputDTO.getVegetablesAndHerbs(), aromasUpdated.getVegetablesAndHerbs()); -// assertEquals(aromasOutputDTO.getMinerals(), aromasUpdated.getMinerals()); -// assertEquals(aromasOutputDTO.getSpices(), aromasUpdated.getSpices()); -// assertEquals(aromasOutputDTO.getAnimals(), aromasUpdated.getAnimals()); -// assertEquals(aromasOutputDTO.getEmpireumatics(), aromasUpdated.getEmpireumatics()); -// assertEquals(aromasOutputDTO.getWood(), aromasUpdated.getWood()); -// assertEquals(aromasOutputDTO.getChemicals(), aromasUpdated.getChemicals()); -// assertEquals(aromasOutputDTO.getLacteal(), aromasUpdated.getLacteal()); -// assertEquals(aromasOutputDTO.getSweets(), aromasUpdated.getSweets()); -// verify(aromasClient).updateAromas("f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e", aromasInputDTO); -// } -// -// @Test -// @DisplayName("Deve lançar BadRequestException ao tentar atualizar um registro de Aromas") -// void testUpdateThrowsBadRequestException() { -// when(aromasClient.updateAromas("f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e", aromasInputDTO)).thenThrow(new BadRequestException(MessagesConstants.ERROR_WHEN_UPDATING)); -// Exception exception = assertThrows(Exception.class, () -> aromasService.updateAromas("f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e", aromasInputDTO)); -// -// assertEquals(MessagesConstants.ERROR_WHEN_UPDATING, exception.getMessage()); -// } -// -// @Test -// @DisplayName("Deve deletar um registro de Aromas") -// void testDelete() { -// assertDoesNotThrow(() -> aromasService.deleteAromas("f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e")); -// verify(aromasClient).deleteAromas("f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e"); -// } -// -// @Test -// @DisplayName("Deve lançar BadRequestException ao tentar deletar um registro de Aromas") -// void testDeleteThrowsBadRequestException() { -// doThrow(BadRequestException.class).when(aromasClient).deleteAromas("f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e"); -// -// Exception exception = assertThrows(Exception.class, () -> aromasService.deleteAromas("f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e")); -// assertEquals(MessagesConstants.ERROR_WHEN_DELETING, exception.getMessage()); -// } -// -// private AromasInputDTO createAromasInputDTO() { -// return AromasInputDTO.builder() -// .tastingData(LocalDate.now()) -// .wineTasted("Wine Tasted") -// .fruity(EnumFruityType.RASPBERRY.getCode()) -// .dryFruits(EnumDryFruitsType.BRUNETTE.getCode()) -// .florals(EnumFloralsType.CLOVE.getCode()) -// .vegetablesAndHerbs(EnumVegetablesAndHerbsType.FENNEL.getCode()) -// .minerals(EnumMineralsType.EARTH.getCode()) -// .spices(EnumSpicesType.INDIAN_CLOVE.getCode()) -// .animals(EnumAnimalsType.LEATHER.getCode()) -// .empireumatics(EnumEmpireumaticsType.CARAMEL.getCode()) -// .wood(EnumWoodType.SAWDUST.getCode()) -// .chemicals(EnumChemicalsAndEtherealType.ACETONE.getCode()) -// .lacteal(EnumLactealType.BUTTER.getCode()) -// .sweets(EnumSweetsType.BULLET.getCode()) -// .build(); -// } -// -// private AromasOutputDTO createAromasOutputDTO() { -// return AromasOutputDTO.builder() -// .id(UUID.fromString("f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e")) -// .tastingData(LocalDate.now()) -// .wineTasted("Wine Tasted") -// .fruity(EnumFruityType.RASPBERRY.getCode()) -// .dryFruits(EnumDryFruitsType.BRUNETTE.getCode()) -// .florals(EnumFloralsType.CLOVE.getCode()) -// .vegetablesAndHerbs(EnumVegetablesAndHerbsType.FENNEL.getCode()) -// .minerals(EnumMineralsType.EARTH.getCode()) -// .spices(EnumSpicesType.INDIAN_CLOVE.getCode()) -// .animals(EnumAnimalsType.LEATHER.getCode()) -// .empireumatics(EnumEmpireumaticsType.CARAMEL.getCode()) -// .wood(EnumWoodType.SAWDUST.getCode()) -// .chemicals(EnumChemicalsAndEtherealType.ACETONE.getCode()) -// .lacteal(EnumLactealType.BUTTER.getCode()) -// .sweets(EnumSweetsType.BULLET.getCode()) -// .build(); -// } -// -//} \ No newline at end of file diff --git a/bff/src/test/java/com/vinhonotas/bff/application/services/degustacao/impl/GustatoryInspectionServiceImplTest.java b/bff/src/test/java/com/vinhonotas/bff/application/services/degustacao/impl/GustatoryInspectionServiceImplTest.java deleted file mode 100644 index 105a4bcc..00000000 --- a/bff/src/test/java/com/vinhonotas/bff/application/services/degustacao/impl/GustatoryInspectionServiceImplTest.java +++ /dev/null @@ -1,227 +0,0 @@ -//package com.vinhonotas.bff.application.services.degustacao.impl; -// -//import com.vinhonotas.bff.application.services.exceptions.BadRequestException; -//import com.vinhonotas.bff.client.degustacao.GustatoryInspectionClient; -//import com.vinhonotas.bff.domain.enums.*; -//import com.vinhonotas.bff.interfaces.dtos.outputs.degustacao.TastingCardOutputDTO; -//import com.vinhonotas.bff.utils.MessagesConstants; -//import org.junit.jupiter.api.BeforeEach; -//import org.junit.jupiter.api.DisplayName; -//import org.junit.jupiter.api.Test; -//import org.junit.jupiter.api.extension.ExtendWith; -//import org.mockito.InjectMocks; -//import org.mockito.Mock; -//import org.mockito.Mockito; -//import org.mockito.junit.jupiter.MockitoExtension; -// -//import java.time.LocalDate; -//import java.util.List; -//import java.util.UUID; -// -//import static org.junit.jupiter.api.Assertions.*; -//import static org.mockito.Mockito.*; -// -//@ExtendWith(MockitoExtension.class) -//class GustatoryInspectionServiceImplTest { -// -// @InjectMocks -// private GustatoryInspectionServiceImpl service; -// -// @Mock -// private GustatoryInspectionClient client; -// -// private GustatoryInspectionInputDTO inputDTO; -// private GustatoryInspectionOutputDTO outputDTO; -// -// @BeforeEach -// void setUp() { -// inputDTO = createGustatoryInspectionInputDTO(); -// outputDTO = createGustatoryInspectionOutputDTO(); -// } -// -// @Test -// @DisplayName("Deve criar uma inspeção gustativa") -// void testCreate() { -// when(client.createGustatoryInspection(inputDTO)).thenReturn(outputDTO); -// -// GustatoryInspectionOutputDTO result = assertDoesNotThrow(() -> service.createGustatoryInspection(inputDTO)); -// assertNotNull(result); -// assertEquals(outputDTO.getId(), result.getId()); -// assertEquals(outputDTO.getTastingData(), result.getTastingData()); -// assertEquals(outputDTO.getWineTasted(), result.getWineTasted()); -// assertEquals(outputDTO.getBody(), result.getBody()); -// assertEquals(outputDTO.getSweetness(), result.getSweetness()); -// assertEquals(outputDTO.getTannin(), result.getTannin()); -// assertEquals(outputDTO.getClassification(), result.getClassification()); -// assertEquals(outputDTO.getAcidity(), result.getAcidity()); -// assertEquals(outputDTO.getAlcohol(), result.getAlcohol()); -// assertEquals(outputDTO.getPersistence(), result.getPersistence()); -// assertEquals(outputDTO.getMaturity(), result.getMaturity()); -// assertEquals(outputDTO.getTypicality(), result.getTypicality()); -// assertEquals(outputDTO.getTastingCard(), result.getTastingCard()); -// verify(client).createGustatoryInspection(inputDTO); -// } -// -// @Test -// @DisplayName("Deve lançar BadRequestException ao criar uma inspeção gustativa") -// void testCreateThrowBadRequestException() { -// when(client.createGustatoryInspection(inputDTO)).thenThrow(new BadRequestException(MessagesConstants.ERROR_WHEN_SAVING)); -// -// Exception exception = assertThrows(Exception.class, () -> service.createGustatoryInspection(inputDTO)); -// assertEquals(MessagesConstants.ERROR_WHEN_SAVING, exception.getMessage()); -// verify(client).createGustatoryInspection(inputDTO); -// } -// -// @Test -// @DisplayName("Deve listar todas as inspeções gustativas") -// void testGetAll() { -// when(client.getAllGustatoryInspections()).thenReturn(List.of(outputDTO)); -// -// List result = assertDoesNotThrow(() -> service.getAllGustatoryInspections()); -// assertNotNull(result); -// assertEquals(1, result.size()); -// assertEquals(outputDTO.getId(), result.get(0).getId()); -// assertEquals(outputDTO.getTastingData(), result.get(0).getTastingData()); -// assertEquals(outputDTO.getWineTasted(), result.get(0).getWineTasted()); -// assertEquals(outputDTO.getBody(), result.get(0).getBody()); -// assertEquals(outputDTO.getSweetness(), result.get(0).getSweetness()); -// assertEquals(outputDTO.getTannin(), result.get(0).getTannin()); -// assertEquals(outputDTO.getClassification(), result.get(0).getClassification()); -// assertEquals(outputDTO.getAcidity(), result.get(0).getAcidity()); -// assertEquals(outputDTO.getAlcohol(), result.get(0).getAlcohol()); -// assertEquals(outputDTO.getPersistence(), result.get(0).getPersistence()); -// assertEquals(outputDTO.getMaturity(), result.get(0).getMaturity()); -// assertEquals(outputDTO.getTypicality(), result.get(0).getTypicality()); -// assertEquals(outputDTO.getTastingCard(), result.get(0).getTastingCard()); -// verify(client).getAllGustatoryInspections(); -// } -// -// @Test -// @DisplayName("Deve lançar NotFoundException ao listar todas as inspeções gustativas") -// void testGetAllThrowNotFoundException() { -// when(client.getAllGustatoryInspections()).thenReturn(List.of()); -// -// Exception exception = assertThrows(Exception.class, () -> service.getAllGustatoryInspections()); -// assertEquals(MessagesConstants.NOT_FOUND, exception.getMessage()); -// verify(client).getAllGustatoryInspections(); -// } -// -// @Test -// @DisplayName("Deve buscar uma inspeção gustativa pelo id") -// void testGetById() { -// when(client.getGustatoryInspectionById(outputDTO.getId().toString())).thenReturn(outputDTO); -// -// GustatoryInspectionOutputDTO result = assertDoesNotThrow(() -> service.getGustatoryInspectionById(outputDTO.getId().toString())); -// assertNotNull(result); -// assertEquals(outputDTO.getId(), result.getId()); -// assertEquals(outputDTO.getTastingData(), result.getTastingData()); -// assertEquals(outputDTO.getWineTasted(), result.getWineTasted()); -// assertEquals(outputDTO.getBody(), result.getBody()); -// assertEquals(outputDTO.getSweetness(), result.getSweetness()); -// assertEquals(outputDTO.getTannin(), result.getTannin()); -// assertEquals(outputDTO.getClassification(), result.getClassification()); -// assertEquals(outputDTO.getAcidity(), result.getAcidity()); -// assertEquals(outputDTO.getAlcohol(), result.getAlcohol()); -// assertEquals(outputDTO.getPersistence(), result.getPersistence()); -// assertEquals(outputDTO.getMaturity(), result.getMaturity()); -// assertEquals(outputDTO.getTypicality(), result.getTypicality()); -// assertEquals(outputDTO.getTastingCard(), result.getTastingCard()); -// verify(client).getGustatoryInspectionById(outputDTO.getId().toString()); -// } -// -// @Test -// @DisplayName("Deve lançar NotFoundException ao buscar uma inspeção gustativa pelo id") -// void testGetByIdThrowNotFoundException() { -// when(client.getGustatoryInspectionById(outputDTO.getId().toString())).thenReturn(null); -// -// Exception exception = assertThrows(Exception.class, () -> service.getGustatoryInspectionById(outputDTO.getId().toString())); -// assertEquals(MessagesConstants.NOT_FOUND, exception.getMessage()); -// verify(client).getGustatoryInspectionById(outputDTO.getId().toString()); -// } -// -// @Test -// @DisplayName("Deve atualizar uma inspeção gustativa") -// void testUpdate() { -// when(client.updateGustatoryInspection(outputDTO.getId().toString(), inputDTO)).thenReturn(outputDTO); -// -// GustatoryInspectionOutputDTO result = assertDoesNotThrow(() -> service.updateGustatoryInspection(outputDTO.getId().toString(), inputDTO)); -// assertNotNull(result); -// assertEquals(outputDTO.getId(), result.getId()); -// assertEquals(outputDTO.getTastingData(), result.getTastingData()); -// assertEquals(outputDTO.getWineTasted(), result.getWineTasted()); -// assertEquals(outputDTO.getBody(), result.getBody()); -// assertEquals(outputDTO.getSweetness(), result.getSweetness()); -// assertEquals(outputDTO.getTannin(), result.getTannin()); -// assertEquals(outputDTO.getClassification(), result.getClassification()); -// assertEquals(outputDTO.getAcidity(), result.getAcidity()); -// assertEquals(outputDTO.getAlcohol(), result.getAlcohol()); -// assertEquals(outputDTO.getPersistence(), result.getPersistence()); -// assertEquals(outputDTO.getMaturity(), result.getMaturity()); -// assertEquals(outputDTO.getTypicality(), result.getTypicality()); -// assertEquals(outputDTO.getTastingCard(), result.getTastingCard()); -// verify(client).updateGustatoryInspection(outputDTO.getId().toString(), inputDTO); -// } -// -// @Test -// @DisplayName("Deve lançar BadRequestException ao atualizar uma inspeção gustativa") -// void testUpdateThrowBadRequestException() { -// when(client.updateGustatoryInspection(outputDTO.getId().toString(), inputDTO)).thenThrow(new BadRequestException(MessagesConstants.ERROR_WHEN_UPDATING)); -// -// Exception exception = assertThrows(Exception.class, () -> service.updateGustatoryInspection(outputDTO.getId().toString(), inputDTO)); -// assertEquals(MessagesConstants.ERROR_WHEN_UPDATING, exception.getMessage()); -// verify(client).updateGustatoryInspection(outputDTO.getId().toString(), inputDTO); -// } -// -// @Test -// @DisplayName("Deve deletar uma inspeção gustativa") -// void testDelete() { -// assertDoesNotThrow(() -> service.deleteGustatoryInspection(outputDTO.getId().toString())); -// verify(client).deleteGustatoryInspection(outputDTO.getId().toString()); -// } -// -// @Test -// @DisplayName("Deve lançar BadRequestException ao deletar uma inspeção gustativa") -// void testDeleteThrowBadRequestException() { -// doThrow(new BadRequestException(MessagesConstants.ERROR_WHEN_DELETING)) -// .when(client).deleteGustatoryInspection(outputDTO.getId().toString()); -// -// Exception exception = assertThrows(Exception.class, () -> service.deleteGustatoryInspection(outputDTO.getId().toString())); -// assertEquals(MessagesConstants.ERROR_WHEN_DELETING, exception.getMessage()); -// verify(client).deleteGustatoryInspection(outputDTO.getId().toString()); -// } -// -// private GustatoryInspectionInputDTO createGustatoryInspectionInputDTO() { -// return GustatoryInspectionInputDTO.builder() -// .tastingData(LocalDate.now()) -// .wineTasted("Wine Tasted") -// .body(EnumBodyType.FULL_BODIED.getCode()) -// .sweetness(EnumSweetnessType.VERY_DRY.getCode()) -// .tannin(EnumTanninType.LITTLE_TANIC.getCode()) -// .classification(EnumClassificationType.LITTLE.getCode()) -// .acidity(EnumAcidityType.LITTLE_ACID.getCode()) -// .alcohol(EnumAlcoholType.LOW.getCode()) -// .persistence(EnumPersistenceType.SHORT.getCode()) -// .maturity(EnumMaturityType.MATURE.getCode()) -// .typicality(EnumTypicalityType.NOT_TYPICAL.getCode()) -// .build(); -// } -// -// private GustatoryInspectionOutputDTO createGustatoryInspectionOutputDTO() { -// return GustatoryInspectionOutputDTO.builder() -// .id(UUID.fromString("f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e")) -// .tastingData(LocalDate.now()) -// .wineTasted("Wine Tasted") -// .body(EnumBodyType.FULL_BODIED.getCode()) -// .sweetness(EnumSweetnessType.VERY_DRY.getCode()) -// .tannin(EnumTanninType.LITTLE_TANIC.getCode()) -// .classification(EnumClassificationType.LITTLE.getCode()) -// .acidity(EnumAcidityType.LITTLE_ACID.getCode()) -// .alcohol(EnumAlcoholType.LOW.getCode()) -// .persistence(EnumPersistenceType.SHORT.getCode()) -// .maturity(EnumMaturityType.MATURE.getCode()) -// .typicality(EnumTypicalityType.NOT_TYPICAL.getCode()) -// .tastingCard(Mockito.mock(TastingCardOutputDTO.class)) -// .build(); -// } -// -//} diff --git a/bff/src/test/java/com/vinhonotas/bff/application/services/degustacao/impl/OlfactoryInspectionServiceImplTest.java b/bff/src/test/java/com/vinhonotas/bff/application/services/degustacao/impl/OlfactoryInspectionServiceImplTest.java deleted file mode 100644 index 30c56bd3..00000000 --- a/bff/src/test/java/com/vinhonotas/bff/application/services/degustacao/impl/OlfactoryInspectionServiceImplTest.java +++ /dev/null @@ -1,215 +0,0 @@ -//package com.vinhonotas.bff.application.services.degustacao.impl; -// -//import com.vinhonotas.bff.application.services.exceptions.BadRequestException; -//import com.vinhonotas.bff.client.degustacao.OlfactoryInspectionClient; -//import com.vinhonotas.bff.domain.enums.EnumClassificationType; -//import com.vinhonotas.bff.domain.enums.EnumIntensityType; -//import com.vinhonotas.bff.domain.enums.EnumPersistenceType; -//import com.vinhonotas.bff.domain.enums.EnumQualityType; -//import com.vinhonotas.bff.utils.MessagesConstants; -//import org.junit.jupiter.api.BeforeEach; -//import org.junit.jupiter.api.DisplayName; -//import org.junit.jupiter.api.Test; -//import org.junit.jupiter.api.extension.ExtendWith; -//import org.mockito.InjectMocks; -//import org.mockito.Mock; -//import org.mockito.Mockito; -//import org.mockito.junit.jupiter.MockitoExtension; -// -//import java.time.LocalDate; -//import java.util.List; -//import java.util.UUID; -// -//import static org.junit.jupiter.api.Assertions.*; -//import static org.mockito.Mockito.*; -// -//@ExtendWith(MockitoExtension.class) -//class OlfactoryInspectionServiceImplTest { -// -// @InjectMocks -// private OlfactoryInspectionServiceImpl olfactoryInspectionService; -// -// @Mock -// private OlfactoryInspectionClient olfactoryInspectionClient; -// -// private OlfactoryInspectionOutputDTO olfactoryInspectionOutputDTO; -// private OlfactoryInspectionInputDTO olfactoryInspectionInputDTO; -// -// @BeforeEach -// void setUp() { -// olfactoryInspectionOutputDTO = createOlfactoryInspectionOutputDTO(); -// olfactoryInspectionInputDTO = createOlfactoryInspectionInputDTO(); -// } -// -// @Test -// @DisplayName("Deve criar uma inspeção olfativa") -// void testCreate() { -// when(olfactoryInspectionClient.createOlafactoryInspection(olfactoryInspectionInputDTO)).thenReturn(olfactoryInspectionOutputDTO); -// -// OlfactoryInspectionOutputDTO response = assertDoesNotThrow(() -> olfactoryInspectionService -// .createOlfactoryInspection(olfactoryInspectionInputDTO)); -// -// assertNotNull(response); -// assertEquals(olfactoryInspectionOutputDTO.getId(), response.getId()); -// assertEquals(olfactoryInspectionOutputDTO.getTastingData(), response.getTastingData()); -// assertEquals(olfactoryInspectionOutputDTO.getWineTasted(), response.getWineTasted()); -// assertEquals(olfactoryInspectionOutputDTO.getIntensity(), response.getIntensity()); -// assertEquals(olfactoryInspectionOutputDTO.getPersistence(), response.getPersistence()); -// assertEquals(olfactoryInspectionOutputDTO.getQuality(), response.getQuality()); -// assertEquals(olfactoryInspectionOutputDTO.getAromas(), response.getAromas()); -// assertEquals(olfactoryInspectionOutputDTO.getClassification(), response.getClassification()); -// verify(olfactoryInspectionClient).createOlafactoryInspection(olfactoryInspectionInputDTO); -// } -// -// @Test -// @DisplayName("Deve lançar BadRequestException ao criar uma inspeção olfativa") -// void testCreateThrowBadRequestException() { -// when(olfactoryInspectionClient.createOlafactoryInspection(olfactoryInspectionInputDTO)) -// .thenThrow(new BadRequestException(MessagesConstants.ERROR_WHEN_SAVING)); -// -// Exception exception = assertThrows(Exception.class, () -> olfactoryInspectionService -// .createOlfactoryInspection(olfactoryInspectionInputDTO)); -// assertEquals(MessagesConstants.ERROR_WHEN_SAVING, exception.getMessage()); -// verify(olfactoryInspectionClient).createOlafactoryInspection(olfactoryInspectionInputDTO); -// } -// -// @Test -// @DisplayName("Deve retornar uma lista de inspeções olfativas") -// void testGetAll() { -// when(olfactoryInspectionClient.getAllOlfactoryInspections()).thenReturn(List.of(olfactoryInspectionOutputDTO)); -// -// List list = assertDoesNotThrow(() -> olfactoryInspectionService.getAllOlfactoryInspections()); -// assertNotNull(list); -// assertFalse(list.isEmpty()); -// assertEquals(1, list.size()); -// assertEquals(olfactoryInspectionOutputDTO.getId(), list.get(0).getId()); -// assertEquals(olfactoryInspectionOutputDTO.getTastingData(), list.get(0).getTastingData()); -// assertEquals(olfactoryInspectionOutputDTO.getWineTasted(), list.get(0).getWineTasted()); -// assertEquals(olfactoryInspectionOutputDTO.getIntensity(), list.get(0).getIntensity()); -// assertEquals(olfactoryInspectionOutputDTO.getPersistence(), list.get(0).getPersistence()); -// assertEquals(olfactoryInspectionOutputDTO.getQuality(), list.get(0).getQuality()); -// assertEquals(olfactoryInspectionOutputDTO.getAromas(), list.get(0).getAromas()); -// assertEquals(olfactoryInspectionOutputDTO.getClassification(), list.get(0).getClassification()); -// verify(olfactoryInspectionClient).getAllOlfactoryInspections(); -// } -// -// @Test -// @DisplayName("Deve lançar BadRequestException ao retornar uma lista de inspeções olfativas") -// void testGetAllThrowBadRequestException() { -// when(olfactoryInspectionClient.getAllOlfactoryInspections()).thenReturn(List.of()); -// -// Exception exception = assertThrows(Exception.class, () -> olfactoryInspectionService.getAllOlfactoryInspections()); -// assertEquals(MessagesConstants.NOT_FOUND, exception.getMessage()); -// verify(olfactoryInspectionClient).getAllOlfactoryInspections(); -// } -// -// @Test -// @DisplayName("Deve retornar uma inspeção olfativa por id") -// void testGetById() { -// when(olfactoryInspectionClient.getOlfactoryInspectionById("f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e")) -// .thenReturn(olfactoryInspectionOutputDTO); -// -// OlfactoryInspectionOutputDTO response = assertDoesNotThrow(() -> olfactoryInspectionService -// .getOlfactoryInspectionById("f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e")); -// assertNotNull(response); -// assertEquals(olfactoryInspectionOutputDTO.getId(), response.getId()); -// assertEquals(olfactoryInspectionOutputDTO.getTastingData(), response.getTastingData()); -// assertEquals(olfactoryInspectionOutputDTO.getWineTasted(), response.getWineTasted()); -// assertEquals(olfactoryInspectionOutputDTO.getIntensity(), response.getIntensity()); -// assertEquals(olfactoryInspectionOutputDTO.getPersistence(), response.getPersistence()); -// assertEquals(olfactoryInspectionOutputDTO.getQuality(), response.getQuality()); -// assertEquals(olfactoryInspectionOutputDTO.getAromas(), response.getAromas()); -// assertEquals(olfactoryInspectionOutputDTO.getClassification(), response.getClassification()); -// verify(olfactoryInspectionClient).getOlfactoryInspectionById("f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e"); -// } -// -// @Test -// @DisplayName("Deve lançar BadRequestException ao retornar uma inspeção olfativa por id") -// void testGetByIdThrowBadRequestException() { -// when(olfactoryInspectionClient.getOlfactoryInspectionById("f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e")) -// .thenReturn(null); -// -// Exception exception = assertThrows(Exception.class, () -> olfactoryInspectionService -// .getOlfactoryInspectionById("f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e")); -// assertEquals(MessagesConstants.NOT_FOUND, exception.getMessage()); -// verify(olfactoryInspectionClient).getOlfactoryInspectionById("f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e"); -// } -// -// @Test -// @DisplayName("Deve atualizar uma inspeção olfativa") -// void testUpdate() { -// when(olfactoryInspectionClient.updateOlfactoryInspection("f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e", olfactoryInspectionInputDTO)) -// .thenReturn(olfactoryInspectionOutputDTO); -// -// OlfactoryInspectionOutputDTO response = assertDoesNotThrow(() -> olfactoryInspectionService -// .updateOlfactoryInspection("f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e", olfactoryInspectionInputDTO)); -// assertNotNull(response); -// assertEquals(olfactoryInspectionOutputDTO.getId(), response.getId()); -// assertEquals(olfactoryInspectionOutputDTO.getTastingData(), response.getTastingData()); -// assertEquals(olfactoryInspectionOutputDTO.getWineTasted(), response.getWineTasted()); -// assertEquals(olfactoryInspectionOutputDTO.getIntensity(), response.getIntensity()); -// assertEquals(olfactoryInspectionOutputDTO.getPersistence(), response.getPersistence()); -// assertEquals(olfactoryInspectionOutputDTO.getQuality(), response.getQuality()); -// assertEquals(olfactoryInspectionOutputDTO.getAromas(), response.getAromas()); -// assertEquals(olfactoryInspectionOutputDTO.getClassification(), response.getClassification()); -// verify(olfactoryInspectionClient).updateOlfactoryInspection("f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e", olfactoryInspectionInputDTO); -// } -// -// @Test -// @DisplayName("Deve lançar BadRequestException ao atualizar uma inspeção olfativa") -// void testUpdateThrowBadRequestException() { -// when(olfactoryInspectionClient.updateOlfactoryInspection("f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e", olfactoryInspectionInputDTO)) -// .thenThrow(new BadRequestException(MessagesConstants.ERROR_WHEN_UPDATING)); -// -// Exception exception = assertThrows(Exception.class, () -> olfactoryInspectionService -// .updateOlfactoryInspection("f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e", olfactoryInspectionInputDTO)); -// assertEquals(MessagesConstants.ERROR_WHEN_UPDATING, exception.getMessage()); -// verify(olfactoryInspectionClient).updateOlfactoryInspection("f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e", olfactoryInspectionInputDTO); -// } -// -// @Test -// @DisplayName("Deve deletar uma inspeção olfativa") -// void testDelete() { -// assertDoesNotThrow(() -> olfactoryInspectionService.deleteOlfactoryInspection("f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e")); -// verify(olfactoryInspectionClient).deleteOlfactoryInspection("f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e"); -// } -// -// @Test -// @DisplayName("Deve lançar BadRequestException ao deletar uma inspeção olfativa") -// void testDeleteThrowBadRequestException() { -// doThrow(new BadRequestException(MessagesConstants.ERROR_WHEN_DELETING)) -// .when(olfactoryInspectionClient).deleteOlfactoryInspection("f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e"); -// -// Exception exception = assertThrows(Exception.class, () -> olfactoryInspectionService -// .deleteOlfactoryInspection("f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e")); -// assertEquals(MessagesConstants.ERROR_WHEN_DELETING, exception.getMessage()); -// verify(olfactoryInspectionClient).deleteOlfactoryInspection("f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e"); -// -// } -// -// private OlfactoryInspectionInputDTO createOlfactoryInspectionInputDTO() { -// return OlfactoryInspectionInputDTO.builder() -// .tastingData(LocalDate.now()) -// .wineTasted("Wine Tasted") -// .intensity(EnumIntensityType.INTENSE.getCode()) -// .persistence(EnumPersistenceType.PERSISTENT.getCode()) -// .quality(EnumQualityType.COMMON.getCode()) -// .aromas(Mockito.mock(AromasInputDTO.class)) -// .classification(EnumClassificationType.LITTLE.getCode()) -// .build(); -// } -// -// private OlfactoryInspectionOutputDTO createOlfactoryInspectionOutputDTO() { -// return OlfactoryInspectionOutputDTO.builder() -// .id(UUID.fromString("f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e")) -// .tastingData(LocalDate.now()) -// .wineTasted("Wine Tasted") -// .intensity(EnumIntensityType.INTENSE.getCode()) -// .persistence(EnumPersistenceType.PERSISTENT.getCode()) -// .quality(EnumQualityType.COMMON.getCode()) -// .aromas(Mockito.mock(AromasOutputDTO.class)) -// .classification(EnumClassificationType.LITTLE.getCode()) -// .build(); -// } -// -//} \ No newline at end of file diff --git a/bff/src/test/java/com/vinhonotas/bff/application/services/degustacao/impl/TastingServiceImplTest.java b/bff/src/test/java/com/vinhonotas/bff/application/services/degustacao/impl/TastingServiceImplTest.java deleted file mode 100644 index 856a47c4..00000000 --- a/bff/src/test/java/com/vinhonotas/bff/application/services/degustacao/impl/TastingServiceImplTest.java +++ /dev/null @@ -1,180 +0,0 @@ -//package com.vinhonotas.bff.application.services.degustacao.impl; -// -//import com.vinhonotas.bff.application.services.exceptions.BadRequestException; -//import com.vinhonotas.bff.client.degustacao.TastingClient; -//import com.vinhonotas.bff.domain.enums.EnumTastingType; -//import com.vinhonotas.bff.interfaces.dtos.inputs.degustacao.TastingCardInputDTO; -//import com.vinhonotas.bff.interfaces.dtos.outputs.degustacao.TastingCardOutputDTO; -//import com.vinhonotas.bff.utils.MessagesConstants; -//import org.junit.jupiter.api.BeforeEach; -//import org.junit.jupiter.api.DisplayName; -//import org.junit.jupiter.api.Test; -//import org.junit.jupiter.api.extension.ExtendWith; -//import org.mockito.InjectMocks; -//import org.mockito.Mock; -//import org.mockito.Mockito; -//import org.mockito.junit.jupiter.MockitoExtension; -// -//import java.time.LocalDate; -//import java.util.List; -//import java.util.Set; -//import java.util.UUID; -// -//import static org.junit.jupiter.api.Assertions.*; -//import static org.mockito.Mockito.*; -// -//@ExtendWith(MockitoExtension.class) -//class TastingServiceImplTest { -// -// @InjectMocks -// private TastingServiceImpl tastingService; -// -// @Mock -// private TastingClient tastingClient; -// -// private TastingInputDTO tastingInputDTO; -// private TastingOutputDTO tastingOutputDTO; -// -// @BeforeEach -// void setUp() { -// tastingInputDTO = createTastingInputDTO(); -// tastingOutputDTO = createTastingOutputDTO(); -// } -// -// @Test -// @DisplayName("Deve criar uma degustação") -// void testCreateTasting() { -// when(tastingClient.createTasting(tastingInputDTO)).thenReturn(tastingOutputDTO); -// -// TastingOutputDTO result = assertDoesNotThrow(() -> tastingService.createTasting(tastingInputDTO)); -// assertNotNull(result); -// assertEquals(tastingOutputDTO.getId(), result.getId()); -// assertEquals(tastingOutputDTO.getTastingData(), result.getTastingData()); -// assertEquals(tastingOutputDTO.getTastingType(), result.getTastingType()); -// assertEquals(tastingOutputDTO.getTastingCards(), result.getTastingCards()); -// verify(tastingClient).createTasting(tastingInputDTO); -// } -// -// @Test -// @DisplayName("Deve lançar BadRequestException ao criar uma degustação") -// void testCreateTastingThrowBadRequestException() { -// when(tastingClient.createTasting(tastingInputDTO)).thenThrow(new BadRequestException(MessagesConstants.ERROR_WHEN_SAVING)); -// -// Exception exception = assertThrows(Exception.class, () -> tastingService.createTasting(tastingInputDTO)); -// assertEquals(MessagesConstants.ERROR_WHEN_SAVING, exception.getMessage()); -// verify(tastingClient).createTasting(tastingInputDTO); -// } -// -// @Test -// @DisplayName("Deve listar todas as degustações") -// void testGetAllTastings() { -// when(tastingClient.getAllTastings()).thenReturn(List.of(tastingOutputDTO)); -// -// List list = assertDoesNotThrow(() -> tastingService.getAllTastings()); -// assertNotNull(list); -// assertFalse(list.isEmpty()); -// assertEquals(1, list.size()); -// assertEquals(tastingOutputDTO.getId(), list.get(0).getId()); -// assertEquals(tastingOutputDTO.getTastingData(), list.get(0).getTastingData()); -// assertEquals(tastingOutputDTO.getTastingType(), list.get(0).getTastingType()); -// assertEquals(tastingOutputDTO.getTastingCards(), list.get(0).getTastingCards()); -// verify(tastingClient).getAllTastings(); -// } -// -// @Test -// @DisplayName("Deve lançar BadRequestException ao listar todas as degustações") -// void testGetAllTastingsThrowBadRequestException() { -// when(tastingClient.getAllTastings()).thenThrow(new BadRequestException(MessagesConstants.NOT_FOUND)); -// -// Exception exception = assertThrows(Exception.class, () -> tastingService.getAllTastings()); -// assertEquals(MessagesConstants.NOT_FOUND, exception.getMessage()); -// verify(tastingClient).getAllTastings(); -// } -// -// @Test -// @DisplayName("Deve buscar uma degustação pelo id") -// void testGetTastingById() { -// when(tastingClient.getTastingById("f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e")).thenReturn(tastingOutputDTO); -// -// TastingOutputDTO result = assertDoesNotThrow(() -> tastingService.getTastingById("f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e")); -// assertNotNull(result); -// assertEquals("f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e", result.getId().toString()); -// assertEquals(tastingOutputDTO.getTastingData(), result.getTastingData()); -// assertEquals(tastingOutputDTO.getTastingType(), result.getTastingType()); -// assertEquals(tastingOutputDTO.getTastingCards(), result.getTastingCards()); -// verify(tastingClient).getTastingById("f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e"); -// } -// -// @Test -// @DisplayName("Deve lançar BadRequestException ao buscar uma degustação pelo id") -// void testGetTastingByIdThrowBadRequestException() { -// when(tastingClient.getTastingById("f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e")) -// .thenThrow(new BadRequestException(MessagesConstants.NOT_FOUND)); -// -// Exception exception = assertThrows(Exception.class, () -> tastingService.getTastingById("f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e")); -// assertEquals(MessagesConstants.NOT_FOUND, exception.getMessage()); -// verify(tastingClient).getTastingById("f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e"); -// } -// -// @Test -// @DisplayName("Deve atualizar uma degustação") -// void testUpdateTasting() { -// when(tastingClient.updateTasting("f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e", tastingInputDTO)).thenReturn(tastingOutputDTO); -// -// TastingOutputDTO result = assertDoesNotThrow(() -> tastingService.updateTasting("f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e", tastingInputDTO)); -// assertNotNull(result); -// assertEquals("f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e", result.getId().toString()); -// assertEquals(tastingOutputDTO.getTastingData(), result.getTastingData()); -// assertEquals(tastingOutputDTO.getTastingType(), result.getTastingType()); -// assertEquals(tastingOutputDTO.getTastingCards(), result.getTastingCards()); -// verify(tastingClient).updateTasting("f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e", tastingInputDTO); -// } -// -// @Test -// @DisplayName("Deve lançar BadRequestException ao atualizar uma degustação") -// void testUpdateTastingThrowBadRequestException() { -// when(tastingClient.updateTasting("f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e", tastingInputDTO)) -// .thenThrow(new BadRequestException(MessagesConstants.ERROR_WHEN_UPDATING)); -// -// Exception exception = assertThrows(Exception.class, () -> tastingService.updateTasting("f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e", tastingInputDTO)); -// assertEquals(MessagesConstants.ERROR_WHEN_UPDATING, exception.getMessage()); -// verify(tastingClient).updateTasting("f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e", tastingInputDTO); -// } -// -// @Test -// @DisplayName("Deve deletar uma degustação") -// void testDeleteTasting() { -// assertDoesNotThrow(() -> tastingService.deleteTasting("f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e")); -// -// verify(tastingClient).deleteTasting("f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e"); -// } -// -// @Test -// @DisplayName("Deve lançar BadRequestException ao deletar uma degustação") -// void testDeleteTastingThrowBadRequestException() { -// doThrow(new BadRequestException(MessagesConstants.ERROR_WHEN_DELETING)) -// .when(tastingClient).deleteTasting("f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e"); -// -// Exception exception = assertThrows(Exception.class, () -> tastingService.deleteTasting("f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e")); -// assertEquals(MessagesConstants.ERROR_WHEN_DELETING, exception.getMessage()); -// verify(tastingClient).deleteTasting("f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e"); -// } -// -// private TastingInputDTO createTastingInputDTO() { -// return TastingInputDTO.builder() -// .tastingData(LocalDate.now()) -// .tastingType(EnumTastingType.COMPARATIVE.getCode()) -// .tastingCards(Set.of(Mockito.mock(TastingCardInputDTO.class))) -// .build(); -// } -// -// private TastingOutputDTO createTastingOutputDTO() { -// return TastingOutputDTO.builder() -// .id(UUID.fromString("f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e")) -// .tastingData(LocalDate.now()) -// .tastingType(EnumTastingType.COMPARATIVE.getCode()) -// .tastingCards(Set.of(Mockito.mock(TastingCardOutputDTO.class))) -// .build(); -// } -// -//} diff --git a/bff/src/test/java/com/vinhonotas/bff/application/services/degustacao/impl/VisualInspectionServiceImplTest.java b/bff/src/test/java/com/vinhonotas/bff/application/services/degustacao/impl/VisualInspectionServiceImplTest.java deleted file mode 100644 index c67a17b6..00000000 --- a/bff/src/test/java/com/vinhonotas/bff/application/services/degustacao/impl/VisualInspectionServiceImplTest.java +++ /dev/null @@ -1,209 +0,0 @@ -//package com.vinhonotas.bff.application.services.degustacao.impl; -// -//import com.vinhonotas.bff.application.services.exceptions.BadRequestException; -//import com.vinhonotas.bff.application.services.exceptions.NotFoundException; -//import com.vinhonotas.bff.client.degustacao.VisualInspectionClient; -//import com.vinhonotas.bff.domain.enums.*; -//import com.vinhonotas.bff.utils.MessagesConstants; -//import org.junit.jupiter.api.BeforeEach; -//import org.junit.jupiter.api.DisplayName; -//import org.junit.jupiter.api.Test; -//import org.junit.jupiter.api.extension.ExtendWith; -//import org.mockito.InjectMocks; -//import org.mockito.Mock; -//import org.mockito.junit.jupiter.MockitoExtension; -// -//import java.time.LocalDate; -//import java.util.List; -//import java.util.UUID; -// -//import static org.hibernate.validator.internal.util.Contracts.assertNotNull; -//import static org.junit.jupiter.api.Assertions.*; -//import static org.mockito.Mockito.*; -// -//@ExtendWith(MockitoExtension.class) -//class VisualInspectionServiceImplTest { -// -// @InjectMocks -// private VisualInspectionServiceImpl service; -// -// @Mock -// private VisualInspectionClient client; -// -// private VisualInspectionInputDTO inputDTO; -// private VisualInspectionOutputDTO outputDTO; -// -// @BeforeEach -// void setUp() { -// inputDTO = createVisualInspectionInputDTO(); -// outputDTO = createVisualInspectionOutputDTO(); -// } -// -// @Test -// @DisplayName("Deve criar uma inspeção visual") -// void testCreate() { -// when(client.createVisualInspection(inputDTO)).thenReturn(outputDTO); -// -// VisualInspectionOutputDTO result = assertDoesNotThrow(() -> service.createVisualInspection(inputDTO)); -// assertNotNull(result); -// assertEquals(outputDTO.getId(), result.getId()); -// assertEquals(outputDTO.getTastingData(), result.getTastingData()); -// assertEquals(outputDTO.getWineTasted(), result.getWineTasted()); -// assertEquals(outputDTO.getClarity(), result.getClarity()); -// assertEquals(outputDTO.getBrightness(), result.getBrightness()); -// assertEquals(outputDTO.getViscosity(), result.getViscosity()); -// assertEquals(outputDTO.getColorRed(), result.getColorRed()); -// assertEquals(outputDTO.getColorWhite(), result.getColorWhite()); -// assertEquals(outputDTO.getColorRose(), result.getColorRose()); -// assertEquals(outputDTO.getClassification(), result.getClassification()); -// verify(client).createVisualInspection(inputDTO); -// } -// -// @Test -// @DisplayName("Deve lançar BadRequestException ao criar uma inspeção visual") -// void testCreateThrowBadRequestException() { -// when(client.createVisualInspection(inputDTO)).thenThrow(new BadRequestException(MessagesConstants.ERROR_WHEN_SAVING)); -// -// Exception exception = assertThrows(Exception.class, () -> service.createVisualInspection(inputDTO)); -// assertEquals(MessagesConstants.ERROR_WHEN_SAVING, exception.getMessage()); -// verify(client).createVisualInspection(inputDTO); -// } -// -// @Test -// @DisplayName("Deve listar todas as inspeções visuais") -// void testGetAll() { -// when(client.getAllVisualInspections()).thenReturn(List.of(outputDTO)); -// -// var result = assertDoesNotThrow(() -> service.getAllVisualInspections()); -// assertNotNull(result); -// assertEquals(1, result.size()); -// assertEquals(outputDTO.getId(), result.get(0).getId()); -// assertEquals(outputDTO.getTastingData(), result.get(0).getTastingData()); -// assertEquals(outputDTO.getWineTasted(), result.get(0).getWineTasted()); -// assertEquals(outputDTO.getClarity(), result.get(0).getClarity()); -// assertEquals(outputDTO.getBrightness(), result.get(0).getBrightness()); -// assertEquals(outputDTO.getViscosity(), result.get(0).getViscosity()); -// assertEquals(outputDTO.getColorRed(), result.get(0).getColorRed()); -// assertEquals(outputDTO.getColorWhite(), result.get(0).getColorWhite()); -// assertEquals(outputDTO.getColorRose(), result.get(0).getColorRose()); -// assertEquals(outputDTO.getClassification(), result.get(0).getClassification()); -// verify(client).getAllVisualInspections(); -// } -// -// @Test -// @DisplayName("Deve lançar NotFoundException ao listar todas as inspeções visuais") -// void testGetAllThrowNotFoundException() { -// when(client.getAllVisualInspections()).thenThrow(new NotFoundException(MessagesConstants.NOT_FOUND)); -// -// Exception exception = assertThrows(Exception.class, () -> service.getAllVisualInspections()); -// assertEquals(MessagesConstants.NOT_FOUND, exception.getMessage()); -// verify(client).getAllVisualInspections(); -// } -// -// @Test -// @DisplayName("Deve buscar uma inspeção visual pelo id") -// void testGetById() { -// when(client.getVisualInspectionById(outputDTO.getId().toString())).thenReturn(outputDTO); -// -// var result = assertDoesNotThrow(() -> service.getVisualInspectionById(outputDTO.getId().toString())); -// assertNotNull(result); -// assertEquals(outputDTO.getId(), result.getId()); -// assertEquals(outputDTO.getTastingData(), result.getTastingData()); -// assertEquals(outputDTO.getWineTasted(), result.getWineTasted()); -// assertEquals(outputDTO.getClarity(), result.getClarity()); -// assertEquals(outputDTO.getBrightness(), result.getBrightness()); -// assertEquals(outputDTO.getViscosity(), result.getViscosity()); -// assertEquals(outputDTO.getColorRed(), result.getColorRed()); -// assertEquals(outputDTO.getColorWhite(), result.getColorWhite()); -// assertEquals(outputDTO.getColorRose(), result.getColorRose()); -// assertEquals(outputDTO.getClassification(), result.getClassification()); -// verify(client).getVisualInspectionById(outputDTO.getId().toString()); -// } -// -// @Test -// @DisplayName("Deve lançar NotFoundException ao buscar uma inspeção visual pelo id") -// void testGetByIdThrowNotFoundException() { -// when(client.getVisualInspectionById(outputDTO.getId().toString())).thenThrow(new NotFoundException(MessagesConstants.NOT_FOUND)); -// -// Exception exception = assertThrows(Exception.class, () -> service.getVisualInspectionById(outputDTO.getId().toString())); -// assertEquals(MessagesConstants.NOT_FOUND, exception.getMessage()); -// verify(client).getVisualInspectionById(outputDTO.getId().toString()); -// } -// -// @Test -// @DisplayName("Deve atualizar uma inspeção visual") -// void testUpdate() { -// when(client.updateVisualInspection(outputDTO.getId().toString(), inputDTO)).thenReturn(outputDTO); -// -// var result = assertDoesNotThrow(() -> service.updateVisualInspection(outputDTO.getId().toString(), inputDTO)); -// assertNotNull(result); -// assertEquals(outputDTO.getId(), result.getId()); -// assertEquals(outputDTO.getTastingData(), result.getTastingData()); -// assertEquals(outputDTO.getWineTasted(), result.getWineTasted()); -// assertEquals(outputDTO.getClarity(), result.getClarity()); -// assertEquals(outputDTO.getBrightness(), result.getBrightness()); -// assertEquals(outputDTO.getViscosity(), result.getViscosity()); -// assertEquals(outputDTO.getColorRed(), result.getColorRed()); -// assertEquals(outputDTO.getColorWhite(), result.getColorWhite()); -// assertEquals(outputDTO.getColorRose(), result.getColorRose()); -// assertEquals(outputDTO.getClassification(), result.getClassification()); -// verify(client).updateVisualInspection(outputDTO.getId().toString(), inputDTO); -// } -// -// @Test -// @DisplayName("Deve lançar BadRequestException ao atualizar uma inspeção visual") -// void testUpdateThrowBadRequestException() { -// when(client.updateVisualInspection(outputDTO.getId().toString(), inputDTO)).thenThrow(new BadRequestException(MessagesConstants.ERROR_WHEN_UPDATING)); -// -// Exception exception = assertThrows(Exception.class, () -> service.updateVisualInspection(outputDTO.getId().toString(), inputDTO)); -// assertEquals(MessagesConstants.ERROR_WHEN_UPDATING, exception.getMessage()); -// verify(client).updateVisualInspection(outputDTO.getId().toString(), inputDTO); -// } -// -// @Test -// @DisplayName("Deve deletar uma inspeção visual") -// void testDelete() { -// assertDoesNotThrow(() -> service.deleteVisualInspection(outputDTO.getId().toString())); -// verify(client).deleteVisualInspection(outputDTO.getId().toString()); -// } -// -// @Test -// @DisplayName("Deve lançar BadRequestException ao deletar uma inspeção visual") -// void testDeleteThrowBadRequestException() { -// doThrow(new BadRequestException(MessagesConstants.ERROR_WHEN_DELETING)).when(client).deleteVisualInspection(outputDTO.getId().toString()); -// -// Exception exception = assertThrows(Exception.class, () -> service.deleteVisualInspection(outputDTO.getId().toString())); -// assertEquals(MessagesConstants.ERROR_WHEN_DELETING, exception.getMessage()); -// verify(client).deleteVisualInspection(outputDTO.getId().toString()); -// } -// -// private VisualInspectionInputDTO createVisualInspectionInputDTO() { -// return VisualInspectionInputDTO.builder() -// .tastingData(LocalDate.now()) -// .wineTasted("Wine Tasted") -// .clarity(EnumClarityType.VERY_CLEAR.getCode()) -// .brightness(EnumBrightnessType.VERY_BRIGHT.getCode()) -// .viscosity(EnumViscosityType.SLIPPERY.getCode()) -// .colorRed(EnumRedColorType.RUBY.getCode()) -// .colorWhite(EnumWhiteColorType.STRAW_YELLOW.getCode()) -// .colorRose(EnumRoseColorType.BROWN.getCode()) -// .classification(EnumClassificationType.LITTLE.getCode()) -// .build(); -// } -// -// private VisualInspectionOutputDTO createVisualInspectionOutputDTO() { -// return VisualInspectionOutputDTO.builder() -// .id(UUID.fromString("f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e")) -// .tastingData(LocalDate.now()) -// .wineTasted("Wine Tasted") -// .clarity(EnumClarityType.VERY_CLEAR.getCode()) -// .brightness(EnumBrightnessType.VERY_BRIGHT.getCode()) -// .viscosity(EnumViscosityType.SLIPPERY.getCode()) -// .colorRed(EnumRedColorType.RUBY.getCode()) -// .colorWhite(EnumWhiteColorType.STRAW_YELLOW.getCode()) -// .colorRose(EnumRoseColorType.BROWN.getCode()) -// .classification(EnumClassificationType.LITTLE.getCode()) -// .build(); -// } -// -//} diff --git a/bff/src/test/java/com/vinhonotas/bff/interfaces/controllers/degustacao/AromasControllerTest.java b/bff/src/test/java/com/vinhonotas/bff/interfaces/controllers/degustacao/AromasControllerTest.java deleted file mode 100644 index e8733478..00000000 --- a/bff/src/test/java/com/vinhonotas/bff/interfaces/controllers/degustacao/AromasControllerTest.java +++ /dev/null @@ -1,210 +0,0 @@ -//package com.vinhonotas.bff.interfaces.controllers.degustacao; -// -//import com.fasterxml.jackson.databind.ObjectMapper; -//import com.vinhonotas.bff.application.services.degustacao.AromasService; -//import com.vinhonotas.bff.application.services.exceptions.BadRequestException; -//import com.vinhonotas.bff.application.services.exceptions.NotFoundException; -//import com.vinhonotas.bff.domain.enums.*; -//import com.vinhonotas.bff.utils.MessagesConstants; -//import org.junit.jupiter.api.BeforeEach; -//import org.junit.jupiter.api.DisplayName; -//import org.junit.jupiter.api.Test; -//import org.springframework.beans.factory.annotation.Autowired; -//import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; -//import org.springframework.boot.test.mock.mockito.MockBean; -//import org.springframework.http.MediaType; -//import org.springframework.test.web.servlet.MockMvc; -// -//import java.time.LocalDate; -//import java.util.List; -//import java.util.UUID; -// -//import static org.mockito.Mockito.doThrow; -//import static org.mockito.Mockito.when; -//import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*; -//import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print; -//import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content; -//import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; -// -//@WebMvcTest(controllers = AromasController.class) -//class AromasControllerTest { -// -// @Autowired -// private MockMvc mockMvc; -// @Autowired -// private ObjectMapper objectMapper; -// -// @MockBean -// private AromasService aromasService; -// -// private AromasInputDTO aromasInputDTO; -// private AromasOutputDTO aromasOutputDTO; -// -// @BeforeEach -// void setUp() { -// aromasInputDTO = createAromasInputDTO(); -// aromasOutputDTO = createAromasOutputDTO(); -// } -// -// @Test -// @DisplayName("Deve criar um novo aroma") -// void testCreateAromas() throws Exception { -// when(aromasService.createAromas(aromasInputDTO)).thenReturn(aromasOutputDTO); -// -// mockMvc.perform(post("/api/v1/aromas") -// .contentType(MediaType.APPLICATION_JSON) -// .content(objectMapper.writeValueAsString(aromasInputDTO))) -// .andDo(print()) -// .andExpect(status().isOk()) -// .andExpect(content().json(objectMapper.writeValueAsString(aromasOutputDTO))); -// } -// -// @Test -// @DisplayName("Deve retornar um erro ao criar um aroma") -// void testCreateAromasError() throws Exception { -// when(aromasService.createAromas(aromasInputDTO)).thenThrow(new BadRequestException(MessagesConstants.ERROR_WHEN_SAVING)); -// -// mockMvc.perform(post("/api/v1/aromas") -// .contentType(MediaType.APPLICATION_JSON) -// .content(objectMapper.writeValueAsString(aromasInputDTO))) -// .andDo(print()) -// .andExpect(status().isBadRequest()); -// } -// -// @Test -// @DisplayName("Deve retornar uma lista com todos os aromas cadastrados") -// void testGetAllAromas() throws Exception { -// List list = List.of(aromasOutputDTO); -// when(aromasService.getAllAromas()).thenReturn(List.of(aromasOutputDTO)); -// -// mockMvc.perform(get("/api/v1/aromas") -// .contentType(MediaType.APPLICATION_JSON)) -// .andDo(print()) -// .andExpect(status().isOk()) -// .andExpect(content().json(objectMapper.writeValueAsString(list))); -// } -// -// @Test -// @DisplayName("Deve retornar uma erro ao buscar todos os aromas") -// void testGetAllAromasError() throws Exception { -// when(aromasService.getAllAromas()).thenThrow(new NotFoundException(MessagesConstants.NOT_FOUND)); -// -// mockMvc.perform(get("/api/v1/aromas") -// .contentType(MediaType.APPLICATION_JSON)) -// .andDo(print()) -// .andExpect(status().isNotFound()); -// } -// -// @Test -// @DisplayName("Deve retornar um aroma pelo id") -// void testGetAromasById() throws Exception { -// when(aromasService.getAromasById("f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e")).thenReturn(aromasOutputDTO); -// -// mockMvc.perform(get("/api/v1/aromas/f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e") -// .contentType(MediaType.APPLICATION_JSON)) -// .andDo(print()) -// .andExpect(status().isOk()) -// .andExpect(content().json(objectMapper.writeValueAsString(aromasOutputDTO))); -// } -// -// @Test -// @DisplayName("Deve retornar um erro ao buscar um aroma pelo id") -// void testGetAromasByIdError() throws Exception { -// when(aromasService.getAromasById("f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e")) -// .thenThrow(new NotFoundException(MessagesConstants.NOT_FOUND)); -// -// mockMvc.perform(get("/api/v1/aromas/f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e") -// .contentType(MediaType.APPLICATION_JSON)) -// .andDo(print()) -// .andExpect(status().isNotFound()); -// } -// -// @Test -// @DisplayName("Deve atualizar um aroma pelo id") -// void testUpdateAromas() throws Exception { -// when(aromasService.updateAromas("f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e", aromasInputDTO)).thenReturn(aromasOutputDTO); -// -// aromasOutputDTO.setFruity(EnumFruityType.KIWI.getCode()); -// -// mockMvc.perform(put("/api/v1/aromas/f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e") -// .contentType(MediaType.APPLICATION_JSON) -// .content(objectMapper.writeValueAsString(aromasInputDTO))) -// .andDo(print()) -// .andExpect(status().isOk()) -// .andExpect(content().json(objectMapper.writeValueAsString(aromasOutputDTO))) -// .andExpect(content().json("{'fruity':'Kiwi'}")); -// } -// -// @Test -// @DisplayName("Deve retornar um erro ao atualizar um aroma pelo id") -// void testUpdateAromasError() throws Exception { -// when(aromasService.updateAromas("f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e", aromasInputDTO)) -// .thenThrow(new BadRequestException(MessagesConstants.ERROR_WHEN_UPDATING)); -// -// mockMvc.perform(put("/api/v1/aromas/f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e") -// .contentType(MediaType.APPLICATION_JSON) -// .content(objectMapper.writeValueAsString(aromasInputDTO))) -// .andDo(print()) -// .andExpect(status().isBadRequest()); -// } -// -// @Test -// @DisplayName("Deve deletar um aroma pelo id") -// void testDeleteAromas() throws Exception { -// mockMvc.perform(delete("/api/v1/aromas/f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e") -// .contentType(MediaType.APPLICATION_JSON)) -// .andDo(print()) -// .andExpect(status().isNoContent()); -// } -// -// @Test -// @DisplayName("Deve retornar um erro ao deletar um aroma pelo id") -// void testDeleteAromasError() throws Exception { -// doThrow(BadRequestException.class).when(aromasService).deleteAromas("f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e"); -// -// mockMvc.perform(delete("/api/v1/aromas/f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e") -// .contentType(MediaType.APPLICATION_JSON)) -// .andDo(print()) -// .andExpect(status().isBadRequest()); -// } -// -// private AromasOutputDTO createAromasOutputDTO() { -// return AromasOutputDTO.builder() -// .id(UUID.fromString("f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e")) -// .tastingData(LocalDate.now()) -// .wineTasted("Wine Tasted") -// .fruity(EnumFruityType.RASPBERRY.getCode()) -// .dryFruits(EnumDryFruitsType.BRUNETTE.getCode()) -// .florals(EnumFloralsType.CLOVE.getCode()) -// .vegetablesAndHerbs(EnumVegetablesAndHerbsType.FENNEL.getCode()) -// .minerals(EnumMineralsType.EARTH.getCode()) -// .spices(EnumSpicesType.INDIAN_CLOVE.getCode()) -// .animals(EnumAnimalsType.LEATHER.getCode()) -// .empireumatics(EnumEmpireumaticsType.CARAMEL.getCode()) -// .wood(EnumWoodType.SAWDUST.getCode()) -// .chemicals(EnumChemicalsAndEtherealType.ACETONE.getCode()) -// .lacteal(EnumLactealType.BUTTER.getCode()) -// .sweets(EnumSweetsType.BULLET.getCode()) -// .build(); -// } -// -// private AromasInputDTO createAromasInputDTO() { -// return AromasInputDTO.builder() -// .tastingData(LocalDate.now()) -// .wineTasted("Wine Tasted") -// .fruity(EnumFruityType.RASPBERRY.getCode()) -// .dryFruits(EnumDryFruitsType.BRUNETTE.getCode()) -// .florals(EnumFloralsType.CLOVE.getCode()) -// .vegetablesAndHerbs(EnumVegetablesAndHerbsType.FENNEL.getCode()) -// .minerals(EnumMineralsType.EARTH.getCode()) -// .spices(EnumSpicesType.INDIAN_CLOVE.getCode()) -// .animals(EnumAnimalsType.LEATHER.getCode()) -// .empireumatics(EnumEmpireumaticsType.CARAMEL.getCode()) -// .wood(EnumWoodType.SAWDUST.getCode()) -// .chemicals(EnumChemicalsAndEtherealType.ACETONE.getCode()) -// .lacteal(EnumLactealType.BUTTER.getCode()) -// .sweets(EnumSweetsType.BULLET.getCode()) -// .build(); -// } -// -//} diff --git a/bff/src/test/java/com/vinhonotas/bff/interfaces/controllers/degustacao/GustatoryInspectionControllerTest.java b/bff/src/test/java/com/vinhonotas/bff/interfaces/controllers/degustacao/GustatoryInspectionControllerTest.java deleted file mode 100644 index 475fbe35..00000000 --- a/bff/src/test/java/com/vinhonotas/bff/interfaces/controllers/degustacao/GustatoryInspectionControllerTest.java +++ /dev/null @@ -1,204 +0,0 @@ -//package com.vinhonotas.bff.interfaces.controllers.degustacao; -// -//import com.fasterxml.jackson.databind.ObjectMapper; -//import com.vinhonotas.bff.application.services.degustacao.GustatoryInspectionService; -//import com.vinhonotas.bff.application.services.exceptions.BadRequestException; -//import com.vinhonotas.bff.application.services.exceptions.NotFoundException; -//import com.vinhonotas.bff.domain.enums.*; -//import com.vinhonotas.bff.utils.MessagesConstants; -//import org.junit.jupiter.api.BeforeEach; -//import org.junit.jupiter.api.DisplayName; -//import org.junit.jupiter.api.Test; -//import org.springframework.beans.factory.annotation.Autowired; -//import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; -//import org.springframework.boot.test.mock.mockito.MockBean; -//import org.springframework.http.MediaType; -//import org.springframework.test.web.servlet.MockMvc; -// -//import java.time.LocalDate; -//import java.util.List; -//import java.util.UUID; -// -//import static org.mockito.Mockito.doThrow; -//import static org.mockito.Mockito.when; -//import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*; -//import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print; -//import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content; -//import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; -// -//@WebMvcTest(controllers = GustatoryInspectionController.class) -//class GustatoryInspectionControllerTest { -// -// @Autowired -// private MockMvc mockMvc; -// @Autowired -// private ObjectMapper objectMapper; -// -// @MockBean -// private GustatoryInspectionService gustatoryInspectionService; -// -// private GustatoryInspectionInputDTO inputDTO; -// private GustatoryInspectionOutputDTO outputDTO; -// -// @BeforeEach -// void setUp() { -// inputDTO = createGustatoryInspectionInputDTO(); -// outputDTO = createGustatoryInspectionOutputDTO(); -// } -// -// @Test -// @DisplayName("Deve criar uma percepção gustativa") -// void testCreateGustatoryInspection() throws Exception { -// when(gustatoryInspectionService.createGustatoryInspection(inputDTO)).thenReturn(outputDTO); -// -// mockMvc.perform(post("/api/v1/gustatory-inspection") -// .contentType(MediaType.APPLICATION_JSON) -// .content(objectMapper.writeValueAsString(inputDTO))) -// .andDo(print()) -// .andExpect(status().isOk()) -// .andExpect(content().json(objectMapper.writeValueAsString(outputDTO))); -// } -// -// @Test -// @DisplayName("Deve lançar exceção ao criar uma percepção gustativa com dados inválidos") -// void testCreateGustatoryInspectionWithInvalidData() throws Exception { -// when(gustatoryInspectionService.createGustatoryInspection(inputDTO)) -// .thenThrow(new BadRequestException(MessagesConstants.ERROR_WHEN_SAVING)); -// -// mockMvc.perform(post("/api/v1/gustatory-inspection") -// .contentType(MediaType.APPLICATION_JSON) -// .content(objectMapper.writeValueAsString(inputDTO))) -// .andDo(print()) -// .andExpect(status().isBadRequest()); -// } -// -// @Test -// @DisplayName("Deve retornar uma lista com todas as percepções gustativas cadastradas") -// void testGetAllGustatoryInspections() throws Exception { -// when(gustatoryInspectionService.getAllGustatoryInspections()).thenReturn(List.of(outputDTO)); -// -// mockMvc.perform(get("/api/v1/gustatory-inspection") -// .contentType(MediaType.APPLICATION_JSON)) -// .andDo(print()) -// .andExpect(status().isOk()) -// .andExpect(content().json(objectMapper.writeValueAsString(List.of(outputDTO)))); -// } -// -// @Test -// @DisplayName("Deve lançar exceção ao retornar uma lista com todas as percepções gustativas cadastradas") -// void testGetAllGustatoryInspectionsWithInvalidData() throws Exception { -// when(gustatoryInspectionService.getAllGustatoryInspections()) -// .thenThrow(new NotFoundException(MessagesConstants.NOT_FOUND)); -// -// mockMvc.perform(get("/api/v1/gustatory-inspection") -// .contentType(MediaType.APPLICATION_JSON)) -// .andDo(print()) -// .andExpect(status().isNotFound()); -// } -// -// @Test -// @DisplayName("Deve retornar uma percepção gustativa cadastrada pelo id") -// void testGetGustatoryInspectionById() throws Exception { -// when(gustatoryInspectionService.getGustatoryInspectionById("f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e")).thenReturn(outputDTO); -// -// mockMvc.perform(get("/api/v1/gustatory-inspection/f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e") -// .contentType(MediaType.APPLICATION_JSON)) -// .andDo(print()) -// .andExpect(status().isOk()) -// .andExpect(content().json(objectMapper.writeValueAsString(outputDTO))); -// } -// -// @Test -// @DisplayName("Deve lançar exceção ao retornar uma percepção gustativa cadastrada pelo id") -// void testGetGustatoryInspectionByIdWithInvalidData() throws Exception { -// when(gustatoryInspectionService.getGustatoryInspectionById("f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e")) -// .thenThrow(new NotFoundException(MessagesConstants.NOT_FOUND)); -// -// mockMvc.perform(get("/api/v1/gustatory-inspection/f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e") -// .contentType(MediaType.APPLICATION_JSON)) -// .andDo(print()) -// .andExpect(status().isNotFound()); -// } -// -// @Test -// @DisplayName("Deve atualizar uma percepção gustativa cadastrada pelo id") -// void testUpdateGustatoryInspection() throws Exception { -// when(gustatoryInspectionService.updateGustatoryInspection("f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e", inputDTO)) -// .thenReturn(outputDTO); -// -// mockMvc.perform(put("/api/v1/gustatory-inspection/f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e") -// .contentType(MediaType.APPLICATION_JSON) -// .content(objectMapper.writeValueAsString(inputDTO))) -// .andDo(print()) -// .andExpect(status().isOk()) -// .andExpect(content().json(objectMapper.writeValueAsString(outputDTO))); -// } -// -// @Test -// @DisplayName("Deve lançar exceção ao atualizar uma percepção gustativa cadastrada pelo id") -// void testUpdateGustatoryInspectionWithInvalidData() throws Exception { -// when(gustatoryInspectionService.updateGustatoryInspection("f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e", inputDTO)) -// .thenThrow(new BadRequestException(MessagesConstants.ERROR_WHEN_UPDATING)); -// -// mockMvc.perform(put("/api/v1/gustatory-inspection/f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e") -// .contentType(MediaType.APPLICATION_JSON) -// .content(objectMapper.writeValueAsString(inputDTO))) -// .andDo(print()) -// .andExpect(status().isBadRequest()); -// } -// -// @Test -// @DisplayName("Deve deletar uma percepção gustativa cadastrada pelo id") -// void testDeleteGustatoryInspection() throws Exception { -// mockMvc.perform(delete("/api/v1/gustatory-inspection/f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e") -// .contentType(MediaType.APPLICATION_JSON)) -// .andDo(print()) -// .andExpect(status().isNoContent()); -// } -// -// @Test -// @DisplayName("Deve lançar exceção ao deletar uma percepção gustativa cadastrada pelo id") -// void testDeleteGustatoryInspectionWithInvalidData() throws Exception { -// doThrow(new BadRequestException(MessagesConstants.ERROR_WHEN_DELETING)).when(gustatoryInspectionService) -// .deleteGustatoryInspection("f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e"); -// -// mockMvc.perform(delete("/api/v1/gustatory-inspection/f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e") -// .contentType(MediaType.APPLICATION_JSON)) -// .andDo(print()) -// .andExpect(status().isBadRequest()); -// } -// -// private GustatoryInspectionOutputDTO createGustatoryInspectionOutputDTO() { -// return GustatoryInspectionOutputDTO.builder() -// .id(UUID.fromString("f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e")) -// .tastingData(LocalDate.now()) -// .wineTasted("Wine Tasted") -// .body(EnumBodyType.FULL_BODIED.getCode()) -// .sweetness(EnumSweetnessType.VERY_DRY.getCode()) -// .tannin(EnumTanninType.LITTLE_TANIC.getCode()) -// .classification(EnumClassificationType.LITTLE.getCode()) -// .acidity(EnumAcidityType.LITTLE_ACID.getCode()) -// .alcohol(EnumAlcoholType.LOW.getCode()) -// .persistence(EnumPersistenceType.SHORT.getCode()) -// .maturity(EnumMaturityType.MATURE.getCode()) -// .typicality(EnumTypicalityType.NOT_TYPICAL.getCode()) -// .build(); -// } -// -// private GustatoryInspectionInputDTO createGustatoryInspectionInputDTO() { -// return GustatoryInspectionInputDTO.builder() -// .tastingData(LocalDate.now()) -// .wineTasted("Wine Tasted") -// .body(EnumBodyType.FULL_BODIED.getCode()) -// .sweetness(EnumSweetnessType.VERY_DRY.getCode()) -// .tannin(EnumTanninType.LITTLE_TANIC.getCode()) -// .classification(EnumClassificationType.LITTLE.getCode()) -// .acidity(EnumAcidityType.LITTLE_ACID.getCode()) -// .alcohol(EnumAlcoholType.LOW.getCode()) -// .persistence(EnumPersistenceType.SHORT.getCode()) -// .maturity(EnumMaturityType.MATURE.getCode()) -// .typicality(EnumTypicalityType.NOT_TYPICAL.getCode()) -// .build(); -// } -// -//} \ No newline at end of file diff --git a/bff/src/test/java/com/vinhonotas/bff/interfaces/controllers/degustacao/OlfactoryInspectionControllerTest.java b/bff/src/test/java/com/vinhonotas/bff/interfaces/controllers/degustacao/OlfactoryInspectionControllerTest.java deleted file mode 100644 index d0808d46..00000000 --- a/bff/src/test/java/com/vinhonotas/bff/interfaces/controllers/degustacao/OlfactoryInspectionControllerTest.java +++ /dev/null @@ -1,240 +0,0 @@ -//package com.vinhonotas.bff.interfaces.controllers.degustacao; -// -//import com.fasterxml.jackson.databind.ObjectMapper; -//import com.vinhonotas.bff.application.services.degustacao.OlfactoryInspectionService; -//import com.vinhonotas.bff.application.services.exceptions.BadRequestException; -//import com.vinhonotas.bff.application.services.exceptions.NotFoundException; -//import com.vinhonotas.bff.domain.enums.*; -//import com.vinhonotas.bff.utils.MessagesConstants; -//import org.junit.jupiter.api.BeforeEach; -//import org.junit.jupiter.api.DisplayName; -//import org.junit.jupiter.api.Test; -//import org.springframework.beans.factory.annotation.Autowired; -//import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; -//import org.springframework.boot.test.mock.mockito.MockBean; -//import org.springframework.http.MediaType; -//import org.springframework.test.web.servlet.MockMvc; -// -//import java.time.LocalDate; -//import java.util.List; -//import java.util.UUID; -// -//import static org.mockito.Mockito.doThrow; -//import static org.mockito.Mockito.when; -//import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*; -//import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print; -//import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content; -//import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; -// -//@WebMvcTest(controllers = OlfactoryInspectionController.class) -//class OlfactoryInspectionControllerTest { -// -// @Autowired -// private MockMvc mockMvc; -// @Autowired -// private ObjectMapper objectMapper; -// -// @MockBean -// private OlfactoryInspectionService olfactoryInspectionService; -// -// private OlfactoryInspectionInputDTO olfactoryInspectionInputDTO; -// private OlfactoryInspectionOutputDTO olfactoryInspectionOutputDTO; -// -// @BeforeEach -// void setUp() { -// olfactoryInspectionInputDTO = createOlafactoryInspectionInputDTO(); -// olfactoryInspectionOutputDTO = createOlafactoryInspectionOutputDTO(); -// } -// -// @Test -// @DisplayName("Deve criar uma percepção olfativa") -// void testCreate() throws Exception { -// when(olfactoryInspectionService.createOlfactoryInspection(olfactoryInspectionInputDTO)).thenReturn(olfactoryInspectionOutputDTO); -// -// mockMvc.perform(post("/api/v1/olfactory-inspection") -// .contentType(MediaType.APPLICATION_JSON) -// .content(objectMapper.writeValueAsString(olfactoryInspectionInputDTO))) -// .andDo(print()) -// .andExpect(status().isOk()) -// .andExpect(content() -// .json(objectMapper.writeValueAsString(olfactoryInspectionOutputDTO))); -// } -// -// @Test -// @DisplayName("Deve lançar exceção ao criar uma percepção olfativa") -// void testCreateThrowException() throws Exception { -// when(olfactoryInspectionService.createOlfactoryInspection(olfactoryInspectionInputDTO)) -// .thenThrow(new BadRequestException(MessagesConstants.ERROR_WHEN_SAVING)); -// -// mockMvc.perform(post("/api/v1/olfactory-inspection") -// .contentType(MediaType.APPLICATION_JSON) -// .content(objectMapper.writeValueAsString(olfactoryInspectionInputDTO))) -// .andDo(print()) -// .andExpect(status().isBadRequest()); -// } -// -// @Test -// @DisplayName("Deve retornar uma lista com todas as percepções olfativas cadastradas") -// void testGetAll() throws Exception { -// when(olfactoryInspectionService.getAllOlfactoryInspections()).thenReturn(List.of(olfactoryInspectionOutputDTO)); -// -// mockMvc.perform(get("/api/v1/olfactory-inspection") -// .contentType(MediaType.APPLICATION_JSON)) -// .andDo(print()) -// .andExpect(status().isOk()) -// .andExpect(content() -// .json(objectMapper.writeValueAsString(List.of(olfactoryInspectionOutputDTO)))); -// } -// -// @Test -// @DisplayName("Deve lançar exceção ao retornar uma lista com todas as percepções olfativas cadastradas") -// void testGetAllThrowException() throws Exception { -// when(olfactoryInspectionService.getAllOlfactoryInspections()) -// .thenThrow(new NotFoundException(MessagesConstants.NOT_FOUND)); -// -// mockMvc.perform(get("/api/v1/olfactory-inspection") -// .contentType(MediaType.APPLICATION_JSON)) -// .andDo(print()) -// .andExpect(status().isNotFound()); -// } -// -// @Test -// @DisplayName("Deve retornar uma percepção olfativa cadastrada pelo id") -// void testGetById() throws Exception { -// when(olfactoryInspectionService.getOlfactoryInspectionById("f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e")) -// .thenReturn(olfactoryInspectionOutputDTO); -// -// mockMvc.perform(get("/api/v1/olfactory-inspection/f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e") -// .contentType(MediaType.APPLICATION_JSON)) -// .andDo(print()) -// .andExpect(status().isOk()) -// .andExpect(content() -// .json(objectMapper.writeValueAsString(olfactoryInspectionOutputDTO))); -// } -// -// @Test -// @DisplayName("Deve lançar exceção ao retornar uma percepção olfativa cadastrada pelo id") -// void testGetByIdThrowException() throws Exception { -// when(olfactoryInspectionService.getOlfactoryInspectionById("f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e")) -// .thenThrow(new NotFoundException(MessagesConstants.NOT_FOUND)); -// -// mockMvc.perform(get("/api/v1/olfactory-inspection/f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e") -// .contentType(MediaType.APPLICATION_JSON)) -// .andDo(print()) -// .andExpect(status().isNotFound()); -// } -// -// @Test -// @DisplayName("Deve atualizar uma percepção olfativa cadastrada pelo id") -// void testUpdate() throws Exception { -// when(olfactoryInspectionService.updateOlfactoryInspection("f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e", olfactoryInspectionInputDTO)) -// .thenReturn(olfactoryInspectionOutputDTO); -// -// -// mockMvc.perform(put("/api/v1/olfactory-inspection/f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e") -// .contentType(MediaType.APPLICATION_JSON) -// .content(objectMapper.writeValueAsString(olfactoryInspectionInputDTO))) -// .andDo(print()) -// .andExpect(status().isOk()) -// .andExpect(content() -// .json(objectMapper.writeValueAsString(olfactoryInspectionOutputDTO))); -// } -// -// @Test -// @DisplayName("Deve lançar exceção ao atualizar uma percepção olfativa cadastrada pelo id") -// void testUpdateThrowException() throws Exception { -// when(olfactoryInspectionService.updateOlfactoryInspection("f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e", olfactoryInspectionInputDTO)) -// .thenThrow(new BadRequestException(MessagesConstants.ERROR_WHEN_UPDATING)); -// -// mockMvc.perform(put("/api/v1/olfactory-inspection/f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e") -// .contentType(MediaType.APPLICATION_JSON) -// .content(objectMapper.writeValueAsString(olfactoryInspectionInputDTO))) -// .andDo(print()) -// .andExpect(status().isBadRequest()); -// } -// -// @Test -// @DisplayName("Deve deletar uma percepção olfativa cadastrada pelo id") -// void testDelete() throws Exception { -// mockMvc.perform(delete("/api/v1/olfactory-inspection/f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e") -// .contentType(MediaType.APPLICATION_JSON)) -// .andDo(print()) -// .andExpect(status().isNoContent()); -// } -// -// @Test -// @DisplayName("Deve lançar exceção ao deletar uma percepção olfativa cadastrada pelo id") -// void testDeleteThrowException() throws Exception { -// doThrow(new BadRequestException(MessagesConstants.ERROR_WHEN_DELETING)) -// .when(olfactoryInspectionService).deleteOlfactoryInspection("f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e"); -// mockMvc.perform(delete("/api/v1/olfactory-inspection/f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e") -// .contentType(MediaType.APPLICATION_JSON)) -// .andDo(print()) -// .andExpect(status().isBadRequest()); -// } -// -// private OlfactoryInspectionOutputDTO createOlafactoryInspectionOutputDTO() { -// return OlfactoryInspectionOutputDTO.builder() -// .id(UUID.fromString("f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e")) -// .tastingData(LocalDate.now()) -// .wineTasted("Wine Tasted") -// .intensity(EnumIntensityType.INTENSE.getCode()) -// .persistence(EnumPersistenceType.PERSISTENT.getCode()) -// .quality(EnumQualityType.COMMON.getCode()) -// .aromas(createAromasOutputDTO()) -// .classification(EnumClassificationType.LITTLE.getCode()) -// .build(); -// } -// -// private OlfactoryInspectionInputDTO createOlafactoryInspectionInputDTO() { -// return OlfactoryInspectionInputDTO.builder() -// .tastingData(LocalDate.now()) -// .wineTasted("Wine Tasted") -// .intensity(EnumIntensityType.INTENSE.getCode()) -// .persistence(EnumPersistenceType.PERSISTENT.getCode()) -// .quality(EnumQualityType.COMMON.getCode()) -// .aromas(createAromasInputDTO()) -// .classification(EnumClassificationType.LITTLE.getCode()) -// .build(); -// } -// -// private AromasOutputDTO createAromasOutputDTO() { -// return AromasOutputDTO.builder() -// .id(UUID.fromString("f5e7e3e3-3e3e-4e3e-8e3e-3f3f3f3f3f3f")) -// .tastingData(LocalDate.now()) -// .wineTasted("Wine Tasted") -// .fruity(EnumFruityType.RASPBERRY.getCode()) -// .dryFruits(EnumDryFruitsType.BRUNETTE.getCode()) -// .florals(EnumFloralsType.CLOVE.getCode()) -// .vegetablesAndHerbs(EnumVegetablesAndHerbsType.FENNEL.getCode()) -// .minerals(EnumMineralsType.EARTH.getCode()) -// .spices(EnumSpicesType.INDIAN_CLOVE.getCode()) -// .animals(EnumAnimalsType.LEATHER.getCode()) -// .empireumatics(EnumEmpireumaticsType.CARAMEL.getCode()) -// .wood(EnumWoodType.SAWDUST.getCode()) -// .chemicals(EnumChemicalsAndEtherealType.ACETONE.getCode()) -// .lacteal(EnumLactealType.BUTTER.getCode()) -// .sweets(EnumSweetsType.BULLET.getCode()) -// .build(); -// } -// -// private AromasInputDTO createAromasInputDTO() { -// return AromasInputDTO.builder() -// .tastingData(LocalDate.now()) -// .wineTasted("Wine Tasted") -// .fruity(EnumFruityType.RASPBERRY.getCode()) -// .dryFruits(EnumDryFruitsType.BRUNETTE.getCode()) -// .florals(EnumFloralsType.CLOVE.getCode()) -// .vegetablesAndHerbs(EnumVegetablesAndHerbsType.FENNEL.getCode()) -// .minerals(EnumMineralsType.EARTH.getCode()) -// .spices(EnumSpicesType.INDIAN_CLOVE.getCode()) -// .animals(EnumAnimalsType.LEATHER.getCode()) -// .empireumatics(EnumEmpireumaticsType.CARAMEL.getCode()) -// .wood(EnumWoodType.SAWDUST.getCode()) -// .chemicals(EnumChemicalsAndEtherealType.ACETONE.getCode()) -// .lacteal(EnumLactealType.BUTTER.getCode()) -// .sweets(EnumSweetsType.BULLET.getCode()) -// .build(); -// } -// -//} \ No newline at end of file diff --git a/bff/src/test/java/com/vinhonotas/bff/interfaces/controllers/degustacao/TastingControllerTest.java b/bff/src/test/java/com/vinhonotas/bff/interfaces/controllers/degustacao/TastingControllerTest.java deleted file mode 100644 index 0eeebf6f..00000000 --- a/bff/src/test/java/com/vinhonotas/bff/interfaces/controllers/degustacao/TastingControllerTest.java +++ /dev/null @@ -1,232 +0,0 @@ -//package com.vinhonotas.bff.interfaces.controllers.degustacao; -// -//import com.fasterxml.jackson.databind.ObjectMapper; -//import com.vinhonotas.bff.application.services.degustacao.TastingService; -//import com.vinhonotas.bff.application.services.exceptions.BadRequestException; -//import com.vinhonotas.bff.application.services.exceptions.NotFoundException; -//import com.vinhonotas.bff.domain.enums.EnumPointScale; -//import com.vinhonotas.bff.domain.enums.EnumTastingType; -//import com.vinhonotas.bff.interfaces.dtos.inputs.degustacao.*; -//import com.vinhonotas.bff.interfaces.dtos.outputs.degustacao.*; -//import com.vinhonotas.bff.utils.MessagesConstants; -//import org.junit.jupiter.api.BeforeEach; -//import org.junit.jupiter.api.DisplayName; -//import org.junit.jupiter.api.Test; -//import org.springframework.beans.factory.annotation.Autowired; -//import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; -//import org.springframework.boot.test.mock.mockito.MockBean; -//import org.springframework.http.MediaType; -//import org.springframework.test.web.servlet.MockMvc; -// -//import java.time.LocalDate; -//import java.util.List; -//import java.util.Set; -//import java.util.UUID; -// -//import static org.mockito.Mockito.doThrow; -//import static org.mockito.Mockito.when; -//import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*; -//import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print; -//import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; -//import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; -// -//@WebMvcTest(controllers = TastingController.class) -//class TastingControllerTest { -// -// private static final String URL = "/api/v1/tasting"; -// -// @Autowired -// private MockMvc mockMvc; -// @Autowired -// private ObjectMapper objectMapper; -// -// @MockBean -// private TastingService tastingService; -// -// private TastingInputDTO inputDTO; -// private TastingOutputDTO outputDTO; -// -// @BeforeEach -// void setUp() { -// inputDTO = createTastingInputDTO(); -// outputDTO = createTastingOutputDTO(); -// } -// -// @Test -// @DisplayName("Deve criar uma degustação") -// void testCreateTasting() throws Exception { -// when(tastingService.createTasting(inputDTO)).thenReturn(outputDTO); -// -// mockMvc.perform(post(URL) -// .contentType(MediaType.APPLICATION_JSON) -// .content(objectMapper.writeValueAsString(inputDTO))) -// .andDo(print()) -// .andExpect(status().isOk()) -// .andExpect(jsonPath("$.id").value(outputDTO.getId().toString())) -// .andExpect(jsonPath("$.tastingData").value(outputDTO.getTastingData().toString())) -// .andExpect(jsonPath("$.tastingType").value(outputDTO.getTastingType().toString())) -// .andExpect(jsonPath("$.tastingCards").isArray()); -// } -// -// @Test -// @DisplayName("Deve retornar erro ao criar uma degustação") -// void testCreateTastingThrowBadRequestException() throws Exception { -// when(tastingService.createTasting(inputDTO)).thenThrow(new BadRequestException(MessagesConstants.ERROR_WHEN_SAVING)); -// -// mockMvc.perform(post(URL) -// .contentType(MediaType.APPLICATION_JSON) -// .content(objectMapper.writeValueAsString(inputDTO))) -// .andDo(print()) -// .andExpect(status().isBadRequest()); -// } -// -// @Test -// @DisplayName("Deve retornar uma lista de degustações") -// void testGetAllTastings() throws Exception { -// when(tastingService.getAllTastings()).thenReturn(List.of(outputDTO)); -// -// mockMvc.perform(get(URL) -// .contentType(MediaType.APPLICATION_JSON)) -// .andDo(print()) -// .andExpect(status().isOk()) -// .andExpect(jsonPath("$[0].id").value(outputDTO.getId().toString())) -// .andExpect(jsonPath("$[0].tastingData").value(outputDTO.getTastingData().toString())) -// .andExpect(jsonPath("$[0].tastingType").value(outputDTO.getTastingType().toString())) -// .andExpect(jsonPath("$[0].tastingCards").isArray()); -// } -// -// @Test -// @DisplayName("Deve retornar um erro ao buscar uma lista de degustações") -// void testGetAllTastingsThrowBadRequestException() throws Exception { -// when(tastingService.getAllTastings()).thenThrow(new NotFoundException(MessagesConstants.NOT_FOUND)); -// -// mockMvc.perform(get(URL) -// .contentType(MediaType.APPLICATION_JSON)) -// .andDo(print()) -// .andExpect(status().isNotFound()); -// } -// -// @Test -// @DisplayName("Deve retornar uma degustação pelo id") -// void testGetTastingById() throws Exception { -// when(tastingService.getTastingById(outputDTO.getId().toString())).thenReturn(outputDTO); -// -// mockMvc.perform(get(URL + "/" + outputDTO.getId()) -// .contentType(MediaType.APPLICATION_JSON)) -// .andDo(print()) -// .andExpect(status().isOk()) -// .andExpect(jsonPath("$.id").value(outputDTO.getId().toString())) -// .andExpect(jsonPath("$.tastingData").value(outputDTO.getTastingData().toString())) -// .andExpect(jsonPath("$.tastingType").value(outputDTO.getTastingType().toString())) -// .andExpect(jsonPath("$.tastingCards").isArray()); -// } -// -// @Test -// @DisplayName("Deve retornar um erro ao buscar uma degustação pelo id") -// void testGetTastingByIdThrowBadRequestException() throws Exception { -// when(tastingService.getTastingById(outputDTO.getId().toString())).thenThrow(new NotFoundException(MessagesConstants.NOT_FOUND)); -// -// mockMvc.perform(get(URL + "/" + outputDTO.getId()) -// .contentType(MediaType.APPLICATION_JSON)) -// .andDo(print()) -// .andExpect(status().isNotFound()); -// } -// -// @Test -// @DisplayName("Deve atualizar uma degustação pelo id") -// void testUpdateTasting() throws Exception { -// when(tastingService.updateTasting(outputDTO.getId().toString(), inputDTO)).thenReturn(outputDTO); -// -// mockMvc.perform(put(URL + "/" + outputDTO.getId()) -// .contentType(MediaType.APPLICATION_JSON) -// .content(objectMapper.writeValueAsString(inputDTO))) -// .andDo(print()) -// .andExpect(status().isOk()) -// .andExpect(jsonPath("$.id").value(outputDTO.getId().toString())) -// .andExpect(jsonPath("$.tastingData").value(outputDTO.getTastingData().toString())) -// .andExpect(jsonPath("$.tastingType").value(outputDTO.getTastingType().toString())) -// .andExpect(jsonPath("$.tastingCards").isArray()); -// } -// -// @Test -// @DisplayName("Deve retornar um erro ao atualizar uma degustação pelo id") -// void testUpdateTastingThrowBadRequestException() throws Exception { -// when(tastingService.updateTasting(outputDTO.getId().toString(), inputDTO)).thenThrow(new BadRequestException(MessagesConstants.ERROR_WHEN_UPDATING)); -// -// mockMvc.perform(put(URL + "/" + outputDTO.getId()) -// .contentType(MediaType.APPLICATION_JSON) -// .content(objectMapper.writeValueAsString(inputDTO))) -// .andDo(print()) -// .andExpect(status().isBadRequest()); -// } -// -// @Test -// @DisplayName("Deve deletar uma degustação pelo id") -// void testDeleteTasting() throws Exception { -// mockMvc.perform(delete(URL + "/" + outputDTO.getId()) -// .contentType(MediaType.APPLICATION_JSON)) -// .andDo(print()) -// .andExpect(status().isNoContent()); -// } -// -// @Test -// @DisplayName("Deve retornar um erro ao deletar uma degustação pelo id") -// void testDeleteTastingThrowBadRequestException() throws Exception { -// doThrow(new BadRequestException(MessagesConstants.ERROR_WHEN_DELETING)).when(tastingService).deleteTasting(outputDTO.getId().toString()); -// mockMvc.perform(delete(URL + "/" + outputDTO.getId()) -// .contentType(MediaType.APPLICATION_JSON)) -// .andDo(print()) -// .andExpect(status().isBadRequest()); -// } -// -// private TastingInputDTO createTastingInputDTO() { -// return TastingInputDTO.builder() -// .tastingData(LocalDate.now()) -// .tastingType(EnumTastingType.COMPARATIVE.getCode()) -// .tastingCards(Set.of(createTastingCardInputDTO())) -// .build(); -// } -// -// private TastingCardInputDTO createTastingCardInputDTO() { -// return TastingCardInputDTO.builder() -// .tastingData(LocalDate.now()) -// .wineTasted("Wine Tasted") -// .harvest("2020") -// .grapes("Grapes") -// .country("Chile") -// .region("Vale Central") -// .visualInspection(VisualInspectionInputDTO.builder().build()) -// .olfactoryInspection(OlfactoryInspectionInputDTO.builder().build()) -// .gustatoryInspection(GustatoryInspectionInputDTO.builder().build()) -// .opinion("Opinion about the wine") -// .pointScale(EnumPointScale.CLASSIC.getCode()) -// .build(); -// } -// -// private TastingOutputDTO createTastingOutputDTO() { -// return TastingOutputDTO.builder() -// .id(UUID.fromString("f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e")) -// .tastingData(LocalDate.now()) -// .tastingType(EnumTastingType.COMPARATIVE.getCode()) -// .tastingCards(Set.of(createTastingCardOutputDTO())) -// .build(); -// } -// -// private TastingCardOutputDTO createTastingCardOutputDTO() { -// return TastingCardOutputDTO.builder() -// .id(UUID.fromString("f5e7e3e3-3e3e-4e3e-8e3e-3f3f3f3f3f3f")) -// .tastingData(LocalDate.now()) -// .wineTasted("Wine Tasted") -// .harvest("2020") -// .grapes("Grapes") -// .country("Chile") -// .region("Vale Central") -// .visualInspection(VisualInspectionOutputDTO.builder().build()) -// .olfactoryInspection(OlfactoryInspectionOutputDTO.builder().build()) -// .gustatoryInspection(GustatoryInspectionOutputDTO.builder().build()) -// .opinion("Opinion about the wine") -// .pointScale(EnumPointScale.CLASSIC.name()) -// .build(); -// } -// -//} diff --git a/bff/src/test/java/com/vinhonotas/bff/interfaces/controllers/degustacao/VisualInspectionControllerTest.java b/bff/src/test/java/com/vinhonotas/bff/interfaces/controllers/degustacao/VisualInspectionControllerTest.java deleted file mode 100644 index 95110f64..00000000 --- a/bff/src/test/java/com/vinhonotas/bff/interfaces/controllers/degustacao/VisualInspectionControllerTest.java +++ /dev/null @@ -1,202 +0,0 @@ -//package com.vinhonotas.bff.interfaces.controllers.degustacao; -// -//import com.fasterxml.jackson.databind.ObjectMapper; -//import com.vinhonotas.bff.application.services.degustacao.VisualInspectionService; -//import com.vinhonotas.bff.application.services.exceptions.BadRequestException; -//import com.vinhonotas.bff.application.services.exceptions.NotFoundException; -//import com.vinhonotas.bff.domain.enums.*; -//import com.vinhonotas.bff.utils.MessagesConstants; -//import org.junit.jupiter.api.BeforeEach; -//import org.junit.jupiter.api.DisplayName; -//import org.junit.jupiter.api.Test; -//import org.springframework.beans.factory.annotation.Autowired; -//import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; -//import org.springframework.boot.test.mock.mockito.MockBean; -//import org.springframework.http.MediaType; -//import org.springframework.test.web.servlet.MockMvc; -// -//import java.time.LocalDate; -//import java.util.List; -//import java.util.UUID; -// -//import static org.mockito.Mockito.doThrow; -//import static org.mockito.Mockito.when; -//import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*; -//import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print; -//import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content; -//import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; -// -//@WebMvcTest(controllers = VisualInspectionController.class) -//class VisualInspectionControllerTest { -// -// @Autowired -// private MockMvc mockMvc; -// @Autowired -// private ObjectMapper objectMapper; -// -// @MockBean -// private VisualInspectionService visualInspectionService; -// -// private VisualInspectionInputDTO inputDTO; -// private VisualInspectionOutputDTO outputDTO; -// -// @BeforeEach -// void setUp() { -// inputDTO = createVisualInspectionInputDTO(); -// outputDTO = createVisualInspectionOutputDTO(); -// } -// -// @Test -// @DisplayName("Deve criar uma percepção visual") -// void testCreateVisualInspection() throws Exception { -// when(visualInspectionService.createVisualInspection(inputDTO)).thenReturn(outputDTO); -// -// mockMvc.perform(post("/api/v1/visual-inspection") -// .contentType(MediaType.APPLICATION_JSON) -// .content(objectMapper.writeValueAsString(inputDTO))) -// .andDo(print()) -// .andExpect(status().isOk()) -// .andExpect(content() -// .json(objectMapper.writeValueAsString(outputDTO))); -// } -// -// @Test -// @DisplayName("Deve lançar BadRequestException ao criar uma percepção visual") -// void testCreateVisualInspectionBadRequestException() throws Exception { -// when(visualInspectionService.createVisualInspection(inputDTO)).thenThrow(new BadRequestException( -// MessagesConstants.ERROR_WHEN_SAVING)); -// -// mockMvc.perform(post("/api/v1/visual-inspection") -// .contentType(MediaType.APPLICATION_JSON) -// .content(objectMapper.writeValueAsString(inputDTO))) -// .andDo(print()) -// .andExpect(status().isBadRequest()); -// } -// -// @Test -// @DisplayName("Deve retornar uma lista com todas as percepções visuais cadastradas") -// void testGetAllVisualInspections() throws Exception { -// when(visualInspectionService.getAllVisualInspections()).thenReturn(List.of(outputDTO)); -// -// mockMvc.perform(get("/api/v1/visual-inspection") -// .contentType(MediaType.APPLICATION_JSON)) -// .andDo(print()) -// .andExpect(status().isOk()) -// .andExpect(content() -// .json(objectMapper.writeValueAsString(List.of(outputDTO)))); -// } -// -// @Test -// @DisplayName("Deve lançar BadRequestException ao retornar uma lista com todas as percepções visuais cadastradas") -// void testGetAllVisualInspectionsBadRequestException() throws Exception { -// when(visualInspectionService.getAllVisualInspections()).thenThrow(new NotFoundException(MessagesConstants.NOT_FOUND)); -// -// mockMvc.perform(get("/api/v1/visual-inspection") -// .contentType(MediaType.APPLICATION_JSON)) -// .andDo(print()) -// .andExpect(status().isNotFound()); -// } -// -// @Test -// @DisplayName("Deve retornar uma percepção visual cadastrada pelo id") -// void testGetVisualInspectionById() throws Exception { -// when(visualInspectionService.getVisualInspectionById("f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e")).thenReturn(outputDTO); -// -// mockMvc.perform(get("/api/v1/visual-inspection/f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e") -// .contentType(MediaType.APPLICATION_JSON)) -// .andDo(print()) -// .andExpect(status().isOk()) -// .andExpect(content() -// .json(objectMapper.writeValueAsString(outputDTO))); -// } -// -// @Test -// @DisplayName("Deve lançar BadRequestException ao retornar uma percepção visual cadastrada pelo id") -// void testGetVisualInspectionByIdBadRequestException() throws Exception { -// when(visualInspectionService.getVisualInspectionById("f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e")) -// .thenThrow(new NotFoundException(MessagesConstants.NOT_FOUND)); -// -// mockMvc.perform(get("/api/v1/visual-inspection/f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e") -// .contentType(MediaType.APPLICATION_JSON)) -// .andDo(print()) -// .andExpect(status().isNotFound()); -// } -// -// @Test -// @DisplayName("Deve atualizar uma percepção visual cadastrada pelo id") -// void testUpdateVisualInspection() throws Exception { -// when(visualInspectionService.updateVisualInspection("f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e", inputDTO)).thenReturn(outputDTO); -// -// mockMvc.perform(put("/api/v1/visual-inspection/f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e") -// .contentType(MediaType.APPLICATION_JSON) -// .content(objectMapper.writeValueAsString(inputDTO))) -// .andDo(print()) -// .andExpect(status().isOk()) -// .andExpect(content() -// .json(objectMapper.writeValueAsString(outputDTO))); -// } -// -// @Test -// @DisplayName("Deve lançar BadRequestException ao atualizar uma percepção visual cadastrada pelo id") -// void testUpdateVisualInspectionBadRequestException() throws Exception { -// when(visualInspectionService.updateVisualInspection("f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e", inputDTO)) -// .thenThrow(new BadRequestException(MessagesConstants.ERROR_WHEN_UPDATING)); -// -// mockMvc.perform(put("/api/v1/visual-inspection/f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e") -// .contentType(MediaType.APPLICATION_JSON) -// .content(objectMapper.writeValueAsString(inputDTO))) -// .andDo(print()) -// .andExpect(status().isBadRequest()); -// } -// -// @Test -// @DisplayName("Deve deletar uma percepção visual cadastrada pelo id") -// void testDeleteVisualInspection() throws Exception { -// mockMvc.perform(delete("/api/v1/visual-inspection/f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e") -// .contentType(MediaType.APPLICATION_JSON)) -// .andDo(print()) -// .andExpect(status().isNoContent()); -// } -// -// @Test -// @DisplayName("Deve lançar BadRequestException ao deletar uma percepção visual cadastrada pelo id") -// void testDeleteVisualInspectionBadRequestException() throws Exception { -// doThrow(new BadRequestException(MessagesConstants.ERROR_WHEN_DELETING)) -// .when(visualInspectionService).deleteVisualInspection("f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e"); -// -// mockMvc.perform(delete("/api/v1/visual-inspection/f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e") -// .contentType(MediaType.APPLICATION_JSON)) -// .andDo(print()) -// .andExpect(status().isBadRequest()); -// } -// -// private VisualInspectionOutputDTO createVisualInspectionOutputDTO() { -// return VisualInspectionOutputDTO.builder() -// .id(UUID.fromString("f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e")) -// .tastingData(LocalDate.now()) -// .wineTasted("Wine Tasted") -// .clarity(EnumClarityType.VERY_CLEAR.getCode()) -// .brightness(EnumBrightnessType.VERY_BRIGHT.getCode()) -// .viscosity(EnumViscosityType.SLIPPERY.getCode()) -// .colorRed(EnumRedColorType.RUBY.getCode()) -// .colorWhite(EnumWhiteColorType.STRAW_YELLOW.getCode()) -// .colorRose(EnumRoseColorType.BROWN.getCode()) -// .classification(EnumClassificationType.LITTLE.getCode()) -// .build(); -// } -// -// private VisualInspectionInputDTO createVisualInspectionInputDTO() { -// return VisualInspectionInputDTO.builder() -// .tastingData(LocalDate.now()) -// .wineTasted("Wine Tasted") -// .clarity(EnumClarityType.VERY_CLEAR.getCode()) -// .brightness(EnumBrightnessType.VERY_BRIGHT.getCode()) -// .viscosity(EnumViscosityType.SLIPPERY.getCode()) -// .colorRed(EnumRedColorType.RUBY.getCode()) -// .colorWhite(EnumWhiteColorType.STRAW_YELLOW.getCode()) -// .colorRose(EnumRoseColorType.BROWN.getCode()) -// .classification(EnumClassificationType.LITTLE.getCode()) -// .build(); -// } -// -//} From e45146453dc1e7801b982b25dfc2948d36d17735 Mon Sep 17 00:00:00 2001 From: vanderleik Date: Sat, 13 Apr 2024 14:40:12 -0300 Subject: [PATCH 3/5] feat: VIN-442 - refazendo as exceptions --- .../TastingCardExceptionHandler.java | 25 +++++++++++++++++++ .../exceptions/BadRequestException.java | 9 +++++++ .../TastingCardNotFoundException.java | 9 +++++++ 3 files changed, 43 insertions(+) create mode 100644 bff/src/main/java/com/vinhonotas/bff/configuration/TastingCardExceptionHandler.java create mode 100644 bff/src/main/java/com/vinhonotas/bff/domain/entities/exceptions/BadRequestException.java create mode 100644 bff/src/main/java/com/vinhonotas/bff/domain/entities/exceptions/TastingCardNotFoundException.java diff --git a/bff/src/main/java/com/vinhonotas/bff/configuration/TastingCardExceptionHandler.java b/bff/src/main/java/com/vinhonotas/bff/configuration/TastingCardExceptionHandler.java new file mode 100644 index 00000000..41512b2e --- /dev/null +++ b/bff/src/main/java/com/vinhonotas/bff/configuration/TastingCardExceptionHandler.java @@ -0,0 +1,25 @@ +package com.vinhonotas.bff.configuration; + +import com.vinhonotas.bff.domain.entities.exceptions.BadRequestException; +import com.vinhonotas.bff.domain.entities.exceptions.TastingCardNotFoundException; +import com.vinhonotas.bff.interfaces.dtos.general.ErrorResponseDTO; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.ControllerAdvice; +import org.springframework.web.bind.annotation.ExceptionHandler; + +@ControllerAdvice +public class TastingCardExceptionHandler { + + @ExceptionHandler(TastingCardNotFoundException.class) + public ResponseEntity handleTastingCardNotFoundException(TastingCardNotFoundException exception) { + return ResponseEntity.status(HttpStatus.NOT_FOUND).body(new ErrorResponseDTO(exception.getMessage())); + } + + @ExceptionHandler(BadRequestException.class) + public ResponseEntity handleBadRequestException(BadRequestException exception) { + return ResponseEntity.badRequest().body(new ErrorResponseDTO(exception.getMessage())); + } + + +} diff --git a/bff/src/main/java/com/vinhonotas/bff/domain/entities/exceptions/BadRequestException.java b/bff/src/main/java/com/vinhonotas/bff/domain/entities/exceptions/BadRequestException.java new file mode 100644 index 00000000..a44af955 --- /dev/null +++ b/bff/src/main/java/com/vinhonotas/bff/domain/entities/exceptions/BadRequestException.java @@ -0,0 +1,9 @@ +package com.vinhonotas.bff.domain.entities.exceptions; + +public class BadRequestException extends RuntimeException { + + public BadRequestException(String message) { + super(message); + } + +} diff --git a/bff/src/main/java/com/vinhonotas/bff/domain/entities/exceptions/TastingCardNotFoundException.java b/bff/src/main/java/com/vinhonotas/bff/domain/entities/exceptions/TastingCardNotFoundException.java new file mode 100644 index 00000000..5f10a107 --- /dev/null +++ b/bff/src/main/java/com/vinhonotas/bff/domain/entities/exceptions/TastingCardNotFoundException.java @@ -0,0 +1,9 @@ +package com.vinhonotas.bff.domain.entities.exceptions; + +public class TastingCardNotFoundException extends RuntimeException { + + public TastingCardNotFoundException(String message) { + super(message); + } + +} From 4a514a5307d25ac3a905729354204a837da4ef6d Mon Sep 17 00:00:00 2001 From: vanderleik Date: Sat, 13 Apr 2024 14:49:13 -0300 Subject: [PATCH 4/5] feat: VIN-438 - refazendo o Service --- .../impl/TastingCardServiceImplTest.java | 494 ++++++++++-------- 1 file changed, 271 insertions(+), 223 deletions(-) diff --git a/bff/src/test/java/com/vinhonotas/bff/application/services/degustacao/impl/TastingCardServiceImplTest.java b/bff/src/test/java/com/vinhonotas/bff/application/services/degustacao/impl/TastingCardServiceImplTest.java index 4b48668f..0ab49da5 100644 --- a/bff/src/test/java/com/vinhonotas/bff/application/services/degustacao/impl/TastingCardServiceImplTest.java +++ b/bff/src/test/java/com/vinhonotas/bff/application/services/degustacao/impl/TastingCardServiceImplTest.java @@ -1,223 +1,271 @@ -//package com.vinhonotas.bff.application.services.degustacao.impl; -// -//import com.vinhonotas.bff.application.services.exceptions.BadRequestException; -//import com.vinhonotas.bff.client.degustacao.TastingCardClient; -//import com.vinhonotas.bff.domain.enums.EnumPointScale; -//import com.vinhonotas.bff.interfaces.dtos.inputs.degustacao.TastingCardInputDTO; -//import com.vinhonotas.bff.interfaces.dtos.outputs.degustacao.TastingCardOutputDTO; -//import com.vinhonotas.bff.utils.MessagesConstants; -//import org.junit.jupiter.api.BeforeEach; -//import org.junit.jupiter.api.DisplayName; -//import org.junit.jupiter.api.Test; -//import org.junit.jupiter.api.extension.ExtendWith; -//import org.mockito.InjectMocks; -//import org.mockito.Mock; -//import org.mockito.Mockito; -//import org.mockito.junit.jupiter.MockitoExtension; -// -//import java.time.LocalDate; -//import java.util.List; -//import java.util.UUID; -// -//import static org.junit.jupiter.api.Assertions.*; -//import static org.mockito.Mockito.*; -// -//@ExtendWith(MockitoExtension.class) -//class TastingCardServiceImplTest { -// -// @InjectMocks -// private TastingCardServiceImpl service; -// -// @Mock -// private TastingCardClient client; -// -// private TastingCardInputDTO inputDTO; -// private TastingCardOutputDTO outputDTO; -// -// @BeforeEach -// void setUp() { -// inputDTO = createTastingCardInputDTO(); -// outputDTO = createTastingCardOutputDTO(); -// } -// -// @Test -// @DisplayName("Deve criar uma ficha de degustação") -// void testCreateTastingCard() { -// when(client.createTastingCard(inputDTO)).thenReturn(outputDTO); -// -// TastingCardOutputDTO result = assertDoesNotThrow(() -> service.createTastingCard(inputDTO)); -// assertNotNull(result); -// assertEquals(outputDTO.getId(), result.getId()); -// assertEquals(outputDTO.getTastingData(), result.getTastingData()); -// assertEquals(outputDTO.getWineTasted(), result.getWineTasted()); -// assertEquals(outputDTO.getHarvest(), result.getHarvest()); -// assertEquals(outputDTO.getGrapes(), result.getGrapes()); -// assertEquals(outputDTO.getCountry(), result.getCountry()); -// assertEquals(outputDTO.getRegion(), result.getRegion()); -// assertEquals(outputDTO.getVisualInspection(), result.getVisualInspection()); -// assertEquals(outputDTO.getOlfactoryInspection(), result.getOlfactoryInspection()); -// assertEquals(outputDTO.getGustatoryInspection(), result.getGustatoryInspection()); -// assertEquals(outputDTO.getOpinion(), result.getOpinion()); -// assertEquals(outputDTO.getPointScale(), result.getPointScale()); -// verify(client).createTastingCard(inputDTO); -// } -// -// @Test -// @DisplayName("Deve lançar BadRequestException ao tentar criar uma ficha de degustação") -// void testCreateTastingCardThrowBadRequestException() { -// when(client.createTastingCard(inputDTO)).thenThrow(new BadRequestException(MessagesConstants.ERROR_WHEN_SAVING)); -// -// BadRequestException exception = assertThrows(BadRequestException.class, () -> service.createTastingCard(inputDTO)); -// assertEquals(MessagesConstants.ERROR_WHEN_SAVING, exception.getMessage()); -// verify(client).createTastingCard(inputDTO); -// } -// -// @Test -// @DisplayName("Deve listar todas as fichas de degustação") -// void testGetAllTastingCards() { -// when(client.getAllTastingCards()).thenReturn(List.of(outputDTO)); -// -// List result = assertDoesNotThrow(() -> service.getAllTastingCards()); -// assertNotNull(result); -// assertFalse(result.isEmpty()); -// assertEquals(1, result.size()); -// assertEquals(outputDTO.getId(), result.get(0).getId()); -// assertEquals(outputDTO.getTastingData(), result.get(0).getTastingData()); -// assertEquals(outputDTO.getWineTasted(), result.get(0).getWineTasted()); -// assertEquals(outputDTO.getHarvest(), result.get(0).getHarvest()); -// assertEquals(outputDTO.getGrapes(), result.get(0).getGrapes()); -// assertEquals(outputDTO.getCountry(), result.get(0).getCountry()); -// assertEquals(outputDTO.getRegion(), result.get(0).getRegion()); -// assertEquals(outputDTO.getVisualInspection(), result.get(0).getVisualInspection()); -// assertEquals(outputDTO.getOlfactoryInspection(), result.get(0).getOlfactoryInspection()); -// assertEquals(outputDTO.getGustatoryInspection(), result.get(0).getGustatoryInspection()); -// assertEquals(outputDTO.getOpinion(), result.get(0).getOpinion()); -// assertEquals(outputDTO.getPointScale(), result.get(0).getPointScale()); -// verify(client).getAllTastingCards(); -// } -// -// @Test -// @DisplayName("Deve lançar BadRequestException ao tentar listar todas as fichas de degustação") -// void testGetAllTastingCardsThrowBadRequestException() { -// when(client.getAllTastingCards()).thenThrow(new BadRequestException(MessagesConstants.NOT_FOUND)); -// -// BadRequestException exception = assertThrows(BadRequestException.class, () -> service.getAllTastingCards()); -// assertEquals(MessagesConstants.NOT_FOUND, exception.getMessage()); -// verify(client).getAllTastingCards(); -// } -// -// @Test -// @DisplayName("Deve buscar uma ficha de degustação pelo id") -// void testGetTastingCardById() { -// when(client.getTastingCardById("f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e")).thenReturn(outputDTO); -// -// TastingCardOutputDTO result = assertDoesNotThrow(() -> service.getTastingCardById("f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e")); -// assertNotNull(result); -// assertEquals(outputDTO.getId(), result.getId()); -// assertEquals(outputDTO.getTastingData(), result.getTastingData()); -// assertEquals(outputDTO.getWineTasted(), result.getWineTasted()); -// assertEquals(outputDTO.getHarvest(), result.getHarvest()); -// assertEquals(outputDTO.getGrapes(), result.getGrapes()); -// assertEquals(outputDTO.getCountry(), result.getCountry()); -// assertEquals(outputDTO.getRegion(), result.getRegion()); -// assertEquals(outputDTO.getVisualInspection(), result.getVisualInspection()); -// assertEquals(outputDTO.getOlfactoryInspection(), result.getOlfactoryInspection()); -// assertEquals(outputDTO.getGustatoryInspection(), result.getGustatoryInspection()); -// assertEquals(outputDTO.getOpinion(), result.getOpinion()); -// assertEquals(outputDTO.getPointScale(), result.getPointScale()); -// verify(client).getTastingCardById("f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e"); -// } -// -// @Test -// @DisplayName("Deve lançar BadRequestException ao tentar buscar uma ficha de degustação pelo id") -// void testGetTastingCardByIdThrowBadRequestException() { -// when(client.getTastingCardById("f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e")).thenThrow(new BadRequestException(MessagesConstants.NOT_FOUND)); -// -// BadRequestException exception = assertThrows(BadRequestException.class, () -> service.getTastingCardById("f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e")); -// assertEquals(MessagesConstants.NOT_FOUND, exception.getMessage()); -// verify(client).getTastingCardById("f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e"); -// } -// -// @Test -// @DisplayName("Deve atualizar uma ficha de degustação pelo id") -// void testUpdateTastingCard() { -// when(client.updateTastingCard("f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e", inputDTO)).thenReturn(outputDTO); -// -// TastingCardOutputDTO result = assertDoesNotThrow(() -> service.updateTastingCard("f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e", inputDTO)); -// assertNotNull(result); -// assertEquals(outputDTO.getId(), result.getId()); -// assertEquals(outputDTO.getTastingData(), result.getTastingData()); -// assertEquals(outputDTO.getWineTasted(), result.getWineTasted()); -// assertEquals(outputDTO.getHarvest(), result.getHarvest()); -// assertEquals(outputDTO.getGrapes(), result.getGrapes()); -// assertEquals(outputDTO.getCountry(), result.getCountry()); -// assertEquals(outputDTO.getRegion(), result.getRegion()); -// assertEquals(outputDTO.getVisualInspection(), result.getVisualInspection()); -// assertEquals(outputDTO.getOlfactoryInspection(), result.getOlfactoryInspection()); -// assertEquals(outputDTO.getGustatoryInspection(), result.getGustatoryInspection()); -// assertEquals(outputDTO.getOpinion(), result.getOpinion()); -// assertEquals(outputDTO.getPointScale(), result.getPointScale()); -// verify(client).updateTastingCard("f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e", inputDTO); -// } -// -// @Test -// @DisplayName("Deve lançar BadRequestException ao tentar atualizar uma ficha de degustação pelo id") -// void testUpdateTastingCardThrowBadRequestException() { -// when(client.updateTastingCard("f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e", inputDTO)).thenThrow(new BadRequestException(MessagesConstants.ERROR_WHEN_UPDATING)); -// -// BadRequestException exception = assertThrows(BadRequestException.class, () -> service.updateTastingCard("f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e", inputDTO)); -// assertEquals(MessagesConstants.ERROR_WHEN_UPDATING, exception.getMessage()); -// verify(client).updateTastingCard("f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e", inputDTO); -// } -// -// @Test -// @DisplayName("Deve deletar uma ficha de degustação pelo id") -// void testDeleteTastingCard() { -// assertDoesNotThrow(() -> service.deleteTastingCard("f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e")); -// verify(client).deleteTastingCard("f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e"); -// } -// -// @Test -// @DisplayName("Deve lançar BadRequestException ao tentar deletar uma ficha de degustação pelo id") -// void testDeleteTastingCardThrowBadRequestException() { -// doThrow(new BadRequestException(MessagesConstants.ERROR_WHEN_DELETING)).when(client).deleteTastingCard("f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e"); -// -// BadRequestException exception = assertThrows(BadRequestException.class, () -> service.deleteTastingCard("f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e")); -// assertEquals(MessagesConstants.ERROR_WHEN_DELETING, exception.getMessage()); -// verify(client).deleteTastingCard("f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e"); -// } -// -// private TastingCardInputDTO createTastingCardInputDTO() { -// return TastingCardInputDTO.builder() -// .tastingData(LocalDate.now()) -// .wineTasted("Wine Tasted") -// .harvest("2020") -// .grapes("Grapes") -// .country("Chile") -// .region("Vale Central") -// .visualInspection(Mockito.mock(VisualInspectionInputDTO.class)) -// .olfactoryInspection(Mockito.mock(OlfactoryInspectionInputDTO.class)) -// .gustatoryInspection(Mockito.mock(GustatoryInspectionInputDTO.class)) -// .opinion("Opinion about the wine") -// .pointScale(EnumPointScale.CLASSIC.getCode()) -// .build(); -// } -// -// private TastingCardOutputDTO createTastingCardOutputDTO() { -// return TastingCardOutputDTO.builder() -// .id(UUID.fromString("f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e")) -// .tastingData(LocalDate.now()) -// .wineTasted("Wine Tasted") -// .harvest("2020") -// .grapes("Grapes") -// .country("Chile") -// .region("Vale Central") -// .visualInspection(Mockito.mock(VisualInspectionOutputDTO.class)) -// .olfactoryInspection(Mockito.mock(OlfactoryInspectionOutputDTO.class)) -// .gustatoryInspection(Mockito.mock(GustatoryInspectionOutputDTO.class)) -// .opinion("Opinion about the wine") -// .pointScale(EnumPointScale.CLASSIC.getCode()) -// .build(); -// } -// -//} \ No newline at end of file +package com.vinhonotas.bff.application.services.degustacao.impl; + +import com.vinhonotas.bff.application.services.exceptions.BadRequestException; +import com.vinhonotas.bff.client.degustacao.TastingCardClient; +import com.vinhonotas.bff.domain.enums.*; +import com.vinhonotas.bff.interfaces.dtos.inputs.degustacao.TastingCardInputDTO; +import com.vinhonotas.bff.interfaces.dtos.outputs.degustacao.TastingCardOutputDTO; +import com.vinhonotas.bff.utils.MessagesConstants; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.junit.jupiter.MockitoExtension; + +import java.time.LocalDate; +import java.time.LocalDateTime; +import java.util.List; +import java.util.UUID; + +import static org.junit.jupiter.api.Assertions.*; +import static org.mockito.Mockito.*; + +@ExtendWith(MockitoExtension.class) +class TastingCardServiceImplTest { + + @InjectMocks + private TastingCardServiceImpl service; + + @Mock + private TastingCardClient client; + + private TastingCardInputDTO inputDTO; + private TastingCardOutputDTO outputDTO; + + @BeforeEach + void setUp() { + inputDTO = createTastingCardInputDTO(); + outputDTO = createTastingCardOutputDTO(); + } + + @Test + @DisplayName("Deve criar uma ficha de degustação") + void testCreateTastingCard() { + when(client.createTastingCard(inputDTO)).thenReturn(outputDTO); + + TastingCardOutputDTO result = assertDoesNotThrow(() -> service.createTastingCard(inputDTO)); + assertNotNull(result); + assertEquals(outputDTO.getId(), result.getId()); + assertEquals(outputDTO.getTastingData(), result.getTastingData()); + assertEquals(outputDTO.getWineTasted(), result.getWineTasted()); + assertEquals(outputDTO.getHarvest(), result.getHarvest()); + assertEquals(outputDTO.getGrapes(), result.getGrapes()); + assertEquals(outputDTO.getCountry(), result.getCountry()); + assertEquals(outputDTO.getRegion(), result.getRegion()); + assertEquals(outputDTO.getOpinion(), result.getOpinion()); + assertEquals(outputDTO.getPointScale(), result.getPointScale()); + verify(client).createTastingCard(inputDTO); + } + + @Test + @DisplayName("Deve lançar BadRequestException ao tentar criar uma ficha de degustação") + void testCreateTastingCardThrowBadRequestException() { + when(client.createTastingCard(inputDTO)).thenThrow(new BadRequestException(MessagesConstants.ERROR_WHEN_SAVING)); + + BadRequestException exception = assertThrows(BadRequestException.class, () -> service.createTastingCard(inputDTO)); + assertEquals(MessagesConstants.ERROR_WHEN_SAVING, exception.getMessage()); + verify(client).createTastingCard(inputDTO); + } + + @Test + @DisplayName("Deve listar todas as fichas de degustação") + void testGetAllTastingCards() { + when(client.getAllTastingCards()).thenReturn(List.of(outputDTO)); + + List result = assertDoesNotThrow(() -> service.getAllTastingCards()); + assertNotNull(result); + assertFalse(result.isEmpty()); + assertEquals(1, result.size()); + assertEquals(outputDTO.getId(), result.get(0).getId()); + assertEquals(outputDTO.getTastingData(), result.get(0).getTastingData()); + assertEquals(outputDTO.getWineTasted(), result.get(0).getWineTasted()); + assertEquals(outputDTO.getHarvest(), result.get(0).getHarvest()); + assertEquals(outputDTO.getGrapes(), result.get(0).getGrapes()); + assertEquals(outputDTO.getCountry(), result.get(0).getCountry()); + assertEquals(outputDTO.getRegion(), result.get(0).getRegion()); + assertEquals(outputDTO.getOpinion(), result.get(0).getOpinion()); + assertEquals(outputDTO.getPointScale(), result.get(0).getPointScale()); + verify(client).getAllTastingCards(); + } + + @Test + @DisplayName("Deve lançar BadRequestException ao tentar listar todas as fichas de degustação") + void testGetAllTastingCardsThrowBadRequestException() { + when(client.getAllTastingCards()).thenThrow(new BadRequestException(MessagesConstants.NOT_FOUND)); + + BadRequestException exception = assertThrows(BadRequestException.class, () -> service.getAllTastingCards()); + assertEquals(MessagesConstants.NOT_FOUND, exception.getMessage()); + verify(client).getAllTastingCards(); + } + + @Test + @DisplayName("Deve buscar uma ficha de degustação pelo id") + void testGetTastingCardById() { + when(client.getTastingCardById("f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e")).thenReturn(outputDTO); + + TastingCardOutputDTO result = assertDoesNotThrow(() -> service.getTastingCardById("f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e")); + assertNotNull(result); + assertEquals(outputDTO.getId(), result.getId()); + assertEquals(outputDTO.getTastingData(), result.getTastingData()); + assertEquals(outputDTO.getWineTasted(), result.getWineTasted()); + assertEquals(outputDTO.getHarvest(), result.getHarvest()); + assertEquals(outputDTO.getGrapes(), result.getGrapes()); + assertEquals(outputDTO.getCountry(), result.getCountry()); + assertEquals(outputDTO.getRegion(), result.getRegion()); + assertEquals(outputDTO.getOpinion(), result.getOpinion()); + assertEquals(outputDTO.getPointScale(), result.getPointScale()); + verify(client).getTastingCardById("f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e"); + } + + @Test + @DisplayName("Deve lançar BadRequestException ao tentar buscar uma ficha de degustação pelo id") + void testGetTastingCardByIdThrowBadRequestException() { + when(client.getTastingCardById("f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e")).thenThrow(new BadRequestException(MessagesConstants.NOT_FOUND)); + + BadRequestException exception = assertThrows(BadRequestException.class, () -> service.getTastingCardById("f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e")); + assertEquals(MessagesConstants.NOT_FOUND, exception.getMessage()); + verify(client).getTastingCardById("f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e"); + } + + @Test + @DisplayName("Deve atualizar uma ficha de degustação pelo id") + void testUpdateTastingCard() { + when(client.updateTastingCard("f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e", inputDTO)).thenReturn(outputDTO); + + TastingCardOutputDTO result = assertDoesNotThrow(() -> service.updateTastingCard("f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e", inputDTO)); + assertNotNull(result); + assertEquals(outputDTO.getId(), result.getId()); + assertEquals(outputDTO.getTastingData(), result.getTastingData()); + assertEquals(outputDTO.getWineTasted(), result.getWineTasted()); + assertEquals(outputDTO.getHarvest(), result.getHarvest()); + assertEquals(outputDTO.getGrapes(), result.getGrapes()); + assertEquals(outputDTO.getCountry(), result.getCountry()); + assertEquals(outputDTO.getRegion(), result.getRegion()); + assertEquals(outputDTO.getOpinion(), result.getOpinion()); + assertEquals(outputDTO.getPointScale(), result.getPointScale()); + verify(client).updateTastingCard("f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e", inputDTO); + } + + @Test + @DisplayName("Deve lançar BadRequestException ao tentar atualizar uma ficha de degustação pelo id") + void testUpdateTastingCardThrowBadRequestException() { + when(client.updateTastingCard("f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e", inputDTO)).thenThrow(new BadRequestException(MessagesConstants.ERROR_WHEN_UPDATING)); + + BadRequestException exception = assertThrows(BadRequestException.class, () -> service.updateTastingCard("f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e", inputDTO)); + assertEquals(MessagesConstants.ERROR_WHEN_UPDATING, exception.getMessage()); + verify(client).updateTastingCard("f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e", inputDTO); + } + + @Test + @DisplayName("Deve deletar uma ficha de degustação pelo id") + void testDeleteTastingCard() { + assertDoesNotThrow(() -> service.deleteTastingCard("f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e")); + verify(client).deleteTastingCard("f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e"); + } + + @Test + @DisplayName("Deve lançar BadRequestException ao tentar deletar uma ficha de degustação pelo id") + void testDeleteTastingCardThrowBadRequestException() { + doThrow(new BadRequestException(MessagesConstants.ERROR_WHEN_DELETING)).when(client).deleteTastingCard("f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e"); + + BadRequestException exception = assertThrows(BadRequestException.class, () -> service.deleteTastingCard("f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e")); + assertEquals(MessagesConstants.ERROR_WHEN_DELETING, exception.getMessage()); + verify(client).deleteTastingCard("f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e"); + } + + private TastingCardInputDTO createTastingCardInputDTO() { + return TastingCardInputDTO.builder() + .wineTasted("Wine Tasted") + .tastingData(LocalDate.now()) + .harvest("2021") + .grapes("Grapes") + .country("Country") + .region("Region") + .clarity(EnumClarityType.CLEAR.getCode()) + .brightness(EnumBrightnessType.BRIGHT.getCode()) + .viscosity(EnumViscosityType.VISCOUS.getCode()) + .colorRed(EnumRedColorType.RUBY.getCode()) + .colorWhite(EnumWhiteColorType.GOLDEN.getCode()) + .colorRose(EnumRoseColorType.BROWN.getCode()) + .visualInspectionClassification(EnumClassificationType.LITTLE.getCode()) + .intensity(EnumIntensityType.INTENSE.getCode()) + .olfactoryInspectionPersistence(EnumPersistenceType.PERSISTENT.getCode()) + .quality(EnumQualityType.COMMON.getCode()) + .fruity(EnumFruityType.BANANA.getCode()) + .dryFruits(EnumDryFruitsType.ALMODN.getCode()) + .florals(EnumFloralsType.ACACIA.getCode()) + .vegetablesAndHerbs(EnumVegetablesAndHerbsType.FENNEL.getCode()) + .minerals(EnumMineralsType.CHALK.getCode()) + .spices(EnumSpicesType.ANISE.getCode()) + .animals(EnumAnimalsType.HUNTING.getCode()) + .empireumatics(EnumEmpireumaticsType.CARAMEL.getCode()) + .wood(EnumWoodType.SAWDUST.getCode()) + .chemicals(EnumChemicalsAndEtherealType.ACETONE.getCode()) + .lacteal(EnumLactealType.BUTTER.getCode()) + .sweets(EnumSweetsType.BULLET.getCode()) + .olfactoryInspectionClassification(EnumClassificationType.EXCELLENT.getCode()) + .body(EnumBodyType.LITTLE_BODY.getCode()) + .sweetness(EnumSweetnessType.SWEET.getCode()) + .tannin(EnumTanninType.LITTLE_TANIC.getCode()) + .acidity(EnumAcidityType.LITTLE_ACID.getCode()) + .alcohol(EnumAlcoholType.LOW.getCode()) + .gustatoryInspectionPersistence(EnumPersistenceType.PERSISTENT.getCode()) + .maturity(EnumMaturityType.MATURE.getCode()) + .typicality(EnumTypicalityType.TYPICAL.getCode()) + .gustatoryInspectionClassification(EnumClassificationType.LITTLE.getCode()) + .opinion("Opinion") + .pointScale(EnumPointScale.VERYGOOD.getCode()) + .dthreg(LocalDateTime.now()) + .userreg("User Reg") + .build(); + } + + private TastingCardOutputDTO createTastingCardOutputDTO() { + return TastingCardOutputDTO.builder() + .id(UUID.fromString("f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e")) + .wineTasted("Wine Tasted") + .tastingData(LocalDate.now()) + .harvest("2021") + .grapes("Grapes") + .country("Country") + .region("Region") + .clarity(EnumClarityType.CLEAR.getCode()) + .brightness(EnumBrightnessType.BRIGHT.getCode()) + .viscosity(EnumViscosityType.VISCOUS.getCode()) + .colorRed(EnumRedColorType.RUBY.getCode()) + .colorWhite(EnumWhiteColorType.GOLDEN.getCode()) + .colorRose(EnumRoseColorType.BROWN.getCode()) + .visualInspectionClassification(EnumClassificationType.LITTLE.getCode()) + .intensity(EnumIntensityType.INTENSE.getCode()) + .olfactoryInspectionPersistence(EnumPersistenceType.PERSISTENT.getCode()) + .quality(EnumQualityType.COMMON.getCode()) + .fruity(EnumFruityType.BANANA.getCode()) + .dryFruits(EnumDryFruitsType.ALMODN.getCode()) + .florals(EnumFloralsType.ACACIA.getCode()) + .vegetablesAndHerbs(EnumVegetablesAndHerbsType.FENNEL.getCode()) + .minerals(EnumMineralsType.CHALK.getCode()) + .spices(EnumSpicesType.ANISE.getCode()) + .animals(EnumAnimalsType.HUNTING.getCode()) + .empireumatics(EnumEmpireumaticsType.CARAMEL.getCode()) + .wood(EnumWoodType.SAWDUST.getCode()) + .chemicals(EnumChemicalsAndEtherealType.ACETONE.getCode()) + .lacteal(EnumLactealType.BUTTER.getCode()) + .sweets(EnumSweetsType.BULLET.getCode()) + .olfactoryInspectionClassification(EnumClassificationType.EXCELLENT.getCode()) + .body(EnumBodyType.LITTLE_BODY.getCode()) + .sweetness(EnumSweetnessType.SWEET.getCode()) + .tannin(EnumTanninType.LITTLE_TANIC.getCode()) + .acidity(EnumAcidityType.LITTLE_ACID.getCode()) + .alcohol(EnumAlcoholType.LOW.getCode()) + .gustatoryInspectionPersistence(EnumPersistenceType.PERSISTENT.getCode()) + .maturity(EnumMaturityType.MATURE.getCode()) + .typicality(EnumTypicalityType.TYPICAL.getCode()) + .gustatoryInspectionClassification(EnumClassificationType.LITTLE.getCode()) + .opinion("Opinion") + .pointScale(EnumPointScale.VERYGOOD.getCode()) + .build(); + } + +} \ No newline at end of file From c68f935ac74bd86a80585cde6cf85c052bcdcfd6 Mon Sep 17 00:00:00 2001 From: vanderleik Date: Sun, 14 Apr 2024 07:39:53 -0300 Subject: [PATCH 5/5] feat: VIN-440 - refazendo o controller --- .../impl/TastingCardServiceImpl.java | 1 + .../impl/TastingCardServiceImplTest.java | 5 +- .../degustacao/TastingCardControllerTest.java | 463 ++++++++++-------- 3 files changed, 266 insertions(+), 203 deletions(-) diff --git a/bff/src/main/java/com/vinhonotas/bff/application/services/degustacao/impl/TastingCardServiceImpl.java b/bff/src/main/java/com/vinhonotas/bff/application/services/degustacao/impl/TastingCardServiceImpl.java index 5b763808..6cd65f87 100644 --- a/bff/src/main/java/com/vinhonotas/bff/application/services/degustacao/impl/TastingCardServiceImpl.java +++ b/bff/src/main/java/com/vinhonotas/bff/application/services/degustacao/impl/TastingCardServiceImpl.java @@ -70,6 +70,7 @@ public TastingCardOutputDTO updateTastingCard(String id, TastingCardInputDTO tas public void deleteTastingCard(String id) { log.info("deleteTastingCard :: Deletando uma ficha degustação pelo id: {}", id); try { + this.getTastingCardById(id); tastingCardClient.deleteTastingCard(id); } catch (Exception e) { log.error("deleteTastingCard :: Ocorreu um erro: {} ", MessagesConstants.ERROR_WHEN_DELETING, e); diff --git a/bff/src/test/java/com/vinhonotas/bff/application/services/degustacao/impl/TastingCardServiceImplTest.java b/bff/src/test/java/com/vinhonotas/bff/application/services/degustacao/impl/TastingCardServiceImplTest.java index 0ab49da5..e9a7d4d1 100644 --- a/bff/src/test/java/com/vinhonotas/bff/application/services/degustacao/impl/TastingCardServiceImplTest.java +++ b/bff/src/test/java/com/vinhonotas/bff/application/services/degustacao/impl/TastingCardServiceImplTest.java @@ -161,6 +161,7 @@ void testUpdateTastingCardThrowBadRequestException() { @Test @DisplayName("Deve deletar uma ficha de degustação pelo id") void testDeleteTastingCard() { + when(client.getTastingCardById(anyString())).thenReturn(outputDTO);; assertDoesNotThrow(() -> service.deleteTastingCard("f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e")); verify(client).deleteTastingCard("f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e"); } @@ -168,11 +169,11 @@ void testDeleteTastingCard() { @Test @DisplayName("Deve lançar BadRequestException ao tentar deletar uma ficha de degustação pelo id") void testDeleteTastingCardThrowBadRequestException() { - doThrow(new BadRequestException(MessagesConstants.ERROR_WHEN_DELETING)).when(client).deleteTastingCard("f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e"); + when(client.getTastingCardById(anyString())).thenThrow(new BadRequestException(MessagesConstants.NOT_FOUND)); BadRequestException exception = assertThrows(BadRequestException.class, () -> service.deleteTastingCard("f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e")); assertEquals(MessagesConstants.ERROR_WHEN_DELETING, exception.getMessage()); - verify(client).deleteTastingCard("f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e"); + verify(client, times(0)).deleteTastingCard("f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e"); } private TastingCardInputDTO createTastingCardInputDTO() { diff --git a/bff/src/test/java/com/vinhonotas/bff/interfaces/controllers/degustacao/TastingCardControllerTest.java b/bff/src/test/java/com/vinhonotas/bff/interfaces/controllers/degustacao/TastingCardControllerTest.java index 9f6234f4..87662f3c 100644 --- a/bff/src/test/java/com/vinhonotas/bff/interfaces/controllers/degustacao/TastingCardControllerTest.java +++ b/bff/src/test/java/com/vinhonotas/bff/interfaces/controllers/degustacao/TastingCardControllerTest.java @@ -1,201 +1,262 @@ -//package com.vinhonotas.bff.interfaces.controllers.degustacao; -// -//import com.fasterxml.jackson.databind.ObjectMapper; -//import com.vinhonotas.bff.application.services.degustacao.TastingCardService; -//import com.vinhonotas.bff.application.services.exceptions.BadRequestException; -//import com.vinhonotas.bff.application.services.exceptions.NotFoundException; -//import com.vinhonotas.bff.domain.enums.EnumPointScale; -//import com.vinhonotas.bff.interfaces.dtos.inputs.degustacao.TastingCardInputDTO; -//import com.vinhonotas.bff.interfaces.dtos.outputs.degustacao.TastingCardOutputDTO; -//import com.vinhonotas.bff.utils.MessagesConstants; -//import org.junit.jupiter.api.BeforeEach; -//import org.junit.jupiter.api.DisplayName; -//import org.junit.jupiter.api.Test; -//import org.springframework.beans.factory.annotation.Autowired; -//import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; -//import org.springframework.boot.test.mock.mockito.MockBean; -//import org.springframework.http.MediaType; -//import org.springframework.test.web.servlet.MockMvc; -// -//import java.time.LocalDate; -//import java.util.List; -//import java.util.UUID; -// -//import static org.mockito.Mockito.doThrow; -//import static org.mockito.Mockito.when; -//import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*; -//import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print; -//import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content; -//import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; -// -//@WebMvcTest(controllers = TastingCardController.class) -//class TastingCardControllerTest { -// -// @Autowired -// private MockMvc mockMvc; -// @Autowired -// private ObjectMapper objectMapper; -// -// @MockBean -// private TastingCardService tastingCardService; -// -// private TastingCardInputDTO inputDTO; -// private TastingCardOutputDTO outputDTO; -// -// @BeforeEach -// void setUp() { -// inputDTO = createTastingCardInputDTO(); -// outputDTO = createTastingCardOutputDTO(); -// } -// -// @Test -// @DisplayName("Deve criar uma ficha de degustação") -// void testCreateTastingCard() throws Exception { -// when(tastingCardService.createTastingCard(inputDTO)).thenReturn(outputDTO); -// -// mockMvc.perform(post("/api/v1/tasting-card") -// .contentType(MediaType.APPLICATION_JSON) -// .content(objectMapper.writeValueAsString(inputDTO))) -// .andDo(print()) -// .andExpect(status().isOk()) -// .andExpect(content().json(objectMapper.writeValueAsString(outputDTO))); -// } -// -// @Test -// @DisplayName("Deve retornar erro ao criar uma ficha de degustação") -// void testCreateTastingCardError() throws Exception { -// when(tastingCardService.createTastingCard(inputDTO)).thenThrow(new BadRequestException(MessagesConstants.ERROR_WHEN_SAVING)); -// -// mockMvc.perform(post("/api/v1/tasting-card") -// .contentType(MediaType.APPLICATION_JSON) -// .content(objectMapper.writeValueAsString(inputDTO))) -// .andDo(print()) -// .andExpect(status().isBadRequest()); -// } -// -// @Test -// @DisplayName("Deve retornar uma lista com todas as fichas de degustação cadastradas") -// void testGetAllTastingCards() throws Exception { -// when(tastingCardService.getAllTastingCards()).thenReturn(List.of(outputDTO)); -// -// mockMvc.perform(get("/api/v1/tasting-card") -// .contentType(MediaType.APPLICATION_JSON)) -// .andDo(print()) -// .andExpect(status().isOk()) -// .andExpect(content().json(objectMapper.writeValueAsString(List.of(outputDTO)))); -// } -// -// @Test -// @DisplayName("Deve lançar erro ao retornar uma lista com todas as fichas de degustação cadastradas") -// void testGetAllTastingCardsError() throws Exception { -// when(tastingCardService.getAllTastingCards()).thenThrow(new NotFoundException(MessagesConstants.NOT_FOUND)); -// -// mockMvc.perform(get("/api/v1/tasting-card") -// .contentType(MediaType.APPLICATION_JSON)) -// .andDo(print()) -// .andExpect(status().isNotFound()); -// } -// -// @Test -// @DisplayName("Deve retornar uma ficha de degustação cadastrada pelo id") -// void testGetTastingCardById() throws Exception { -// when(tastingCardService.getTastingCardById(outputDTO.getId().toString())).thenReturn(outputDTO); -// -// mockMvc.perform(get("/api/v1/tasting-card/" + outputDTO.getId()) -// .contentType(MediaType.APPLICATION_JSON)) -// .andDo(print()) -// .andExpect(status().isOk()) -// .andExpect(content().json(objectMapper.writeValueAsString(outputDTO))); -// } -// -// @Test -// @DisplayName("Deve lançar erro ao retornar uma ficha de degustação cadastrada pelo id") -// void testGetTastingCardByIdError() throws Exception { -// when(tastingCardService.getTastingCardById(outputDTO.getId().toString())).thenThrow(new NotFoundException(MessagesConstants.NOT_FOUND)); -// -// mockMvc.perform(get("/api/v1/tasting-card/" + outputDTO.getId()) -// .contentType(MediaType.APPLICATION_JSON)) -// .andDo(print()) -// .andExpect(status().isNotFound()); -// } -// -// @Test -// @DisplayName("Deve atualizar uma ficha de degustação cadastrada pelo id") -// void testUpdateTastingCard() throws Exception { -// when(tastingCardService.updateTastingCard(outputDTO.getId().toString(), inputDTO)).thenReturn(outputDTO); -// -// mockMvc.perform(put("/api/v1/tasting-card/" + outputDTO.getId()) -// .contentType(MediaType.APPLICATION_JSON) -// .content(objectMapper.writeValueAsString(inputDTO))) -// .andDo(print()) -// .andExpect(status().isOk()) -// .andExpect(content().json(objectMapper.writeValueAsString(outputDTO))); -// } -// -// @Test -// @DisplayName("Deve lançar erro ao atualizar uma ficha de degustação cadastrada pelo id") -// void testUpdateTastingCardError() throws Exception { -// when(tastingCardService.updateTastingCard(outputDTO.getId().toString(), inputDTO)) -// .thenThrow(new BadRequestException(MessagesConstants.ERROR_WHEN_UPDATING)); -// -// mockMvc.perform(put("/api/v1/tasting-card/" + outputDTO.getId()) -// .contentType(MediaType.APPLICATION_JSON) -// .content(objectMapper.writeValueAsString(inputDTO))) -// .andDo(print()) -// .andExpect(status().isBadRequest()); -// } -// -// @Test -// @DisplayName("Deve deletar uma ficha de degustação cadastrada pelo id") -// void testDeleteTastingCard() throws Exception { -// mockMvc.perform(delete("/api/v1/tasting-card/" + outputDTO.getId()) -// .contentType(MediaType.APPLICATION_JSON)) -// .andDo(print()) -// .andExpect(status().isNoContent()); -// } -// -// @Test -// @DisplayName("Deve lançar erro ao deletar uma ficha de degustação cadastrada pelo id") -// void testDeleteTastingCardError() throws Exception { -// doThrow(new BadRequestException(MessagesConstants.ERROR_WHEN_DELETING)).when(tastingCardService).deleteTastingCard(outputDTO.getId().toString()); -// -// mockMvc.perform(delete("/api/v1/tasting-card/" + outputDTO.getId()) -// .contentType(MediaType.APPLICATION_JSON)) -// .andDo(print()) -// .andExpect(status().isBadRequest()); -// } -// -// private TastingCardOutputDTO createTastingCardOutputDTO() { -// return TastingCardOutputDTO.builder() -// .id(UUID.fromString("f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e")) -// .tastingData(LocalDate.now()) -// .wineTasted("Wine Tasted") -// .harvest("2020") -// .grapes("Grapes") -// .country("Chile") -// .region("Vale Central") -// .visualInspection(VisualInspectionOutputDTO.builder().build()) -// .olfactoryInspection(OlfactoryInspectionOutputDTO.builder().build()) -// .gustatoryInspection(GustatoryInspectionOutputDTO.builder().build()) -// .opinion("Opinion about the wine") -// .pointScale(EnumPointScale.CLASSIC.name()) -// .build(); -// } -// -// private TastingCardInputDTO createTastingCardInputDTO() { -// return TastingCardInputDTO.builder() -// .tastingData(LocalDate.now()) -// .wineTasted("Wine Tasted") -// .harvest("2020") -// .grapes("Grapes") -// .country("Chile") -// .region("Vale Central") -// .visualInspection(VisualInspectionInputDTO.builder().build()) -// .olfactoryInspection(OlfactoryInspectionInputDTO.builder().build()) -// .gustatoryInspection(GustatoryInspectionInputDTO.builder().build()) -// .opinion("Opinion about the wine") -// .pointScale(EnumPointScale.CLASSIC.getCode()) -// .build(); -// } -// -//} +package com.vinhonotas.bff.interfaces.controllers.degustacao; + +import com.fasterxml.jackson.databind.ObjectMapper; +import com.vinhonotas.bff.application.services.degustacao.TastingCardService; +import com.vinhonotas.bff.application.services.exceptions.BadRequestException; +import com.vinhonotas.bff.application.services.exceptions.NotFoundException; +import com.vinhonotas.bff.domain.enums.*; +import com.vinhonotas.bff.interfaces.dtos.inputs.degustacao.TastingCardInputDTO; +import com.vinhonotas.bff.interfaces.dtos.outputs.degustacao.TastingCardOutputDTO; +import com.vinhonotas.bff.utils.MessagesConstants; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; +import org.springframework.boot.test.mock.mockito.MockBean; +import org.springframework.http.MediaType; +import org.springframework.test.web.servlet.MockMvc; + +import java.time.LocalDate; +import java.time.LocalDateTime; +import java.util.List; +import java.util.UUID; + +import static org.mockito.Mockito.doThrow; +import static org.mockito.Mockito.when; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*; +import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; + +@WebMvcTest(controllers = TastingCardController.class) +class TastingCardControllerTest { + + @Autowired + private MockMvc mockMvc; + @Autowired + private ObjectMapper objectMapper; + + @MockBean + private TastingCardService tastingCardService; + + private TastingCardInputDTO inputDTO; + private TastingCardOutputDTO outputDTO; + + @BeforeEach + void setUp() { + inputDTO = createTastingCardInputDTO(); + outputDTO = createTastingCardOutputDTO(); + } + + @Test + @DisplayName("Deve criar uma ficha de degustação") + void testCreateTastingCard() throws Exception { + when(tastingCardService.createTastingCard(inputDTO)).thenReturn(outputDTO); + + mockMvc.perform(post("/api/v1/tasting-card") + .contentType(MediaType.APPLICATION_JSON) + .content(objectMapper.writeValueAsString(inputDTO))) + .andDo(print()) + .andExpect(status().isOk()) + .andExpect(content().json(objectMapper.writeValueAsString(outputDTO))); + } + + @Test + @DisplayName("Deve retornar erro ao criar uma ficha de degustação") + void testCreateTastingCardError() throws Exception { + when(tastingCardService.createTastingCard(inputDTO)).thenThrow(new BadRequestException(MessagesConstants.ERROR_WHEN_SAVING)); + + mockMvc.perform(post("/api/v1/tasting-card") + .contentType(MediaType.APPLICATION_JSON) + .content(objectMapper.writeValueAsString(inputDTO))) + .andDo(print()) + .andExpect(status().isBadRequest()); + } + + @Test + @DisplayName("Deve retornar uma lista com todas as fichas de degustação cadastradas") + void testGetAllTastingCards() throws Exception { + when(tastingCardService.getAllTastingCards()).thenReturn(List.of(outputDTO)); + + mockMvc.perform(get("/api/v1/tasting-card") + .contentType(MediaType.APPLICATION_JSON)) + .andDo(print()) + .andExpect(status().isOk()) + .andExpect(content().json(objectMapper.writeValueAsString(List.of(outputDTO)))); + } + + @Test + @DisplayName("Deve lançar erro ao retornar uma lista com todas as fichas de degustação cadastradas") + void testGetAllTastingCardsError() throws Exception { + when(tastingCardService.getAllTastingCards()).thenThrow(new NotFoundException(MessagesConstants.NOT_FOUND)); + + mockMvc.perform(get("/api/v1/tasting-card") + .contentType(MediaType.APPLICATION_JSON)) + .andDo(print()) + .andExpect(status().isNotFound()); + } + + @Test + @DisplayName("Deve retornar uma ficha de degustação cadastrada pelo id") + void testGetTastingCardById() throws Exception { + when(tastingCardService.getTastingCardById(outputDTO.getId().toString())).thenReturn(outputDTO); + + mockMvc.perform(get("/api/v1/tasting-card/" + outputDTO.getId()) + .contentType(MediaType.APPLICATION_JSON)) + .andDo(print()) + .andExpect(status().isOk()) + .andExpect(content().json(objectMapper.writeValueAsString(outputDTO))); + } + + @Test + @DisplayName("Deve lançar erro ao retornar uma ficha de degustação cadastrada pelo id") + void testGetTastingCardByIdError() throws Exception { + when(tastingCardService.getTastingCardById(outputDTO.getId().toString())).thenThrow(new NotFoundException(MessagesConstants.NOT_FOUND)); + + mockMvc.perform(get("/api/v1/tasting-card/" + outputDTO.getId()) + .contentType(MediaType.APPLICATION_JSON)) + .andDo(print()) + .andExpect(status().isNotFound()); + } + + @Test + @DisplayName("Deve atualizar uma ficha de degustação cadastrada pelo id") + void testUpdateTastingCard() throws Exception { + when(tastingCardService.updateTastingCard(outputDTO.getId().toString(), inputDTO)).thenReturn(outputDTO); + + mockMvc.perform(put("/api/v1/tasting-card/" + outputDTO.getId()) + .contentType(MediaType.APPLICATION_JSON) + .content(objectMapper.writeValueAsString(inputDTO))) + .andDo(print()) + .andExpect(status().isOk()) + .andExpect(content().json(objectMapper.writeValueAsString(outputDTO))); + } + + @Test + @DisplayName("Deve lançar erro ao atualizar uma ficha de degustação cadastrada pelo id") + void testUpdateTastingCardError() throws Exception { + when(tastingCardService.updateTastingCard(outputDTO.getId().toString(), inputDTO)) + .thenThrow(new BadRequestException(MessagesConstants.ERROR_WHEN_UPDATING)); + + mockMvc.perform(put("/api/v1/tasting-card/" + outputDTO.getId()) + .contentType(MediaType.APPLICATION_JSON) + .content(objectMapper.writeValueAsString(inputDTO))) + .andDo(print()) + .andExpect(status().isBadRequest()); + } + + @Test + @DisplayName("Deve deletar uma ficha de degustação cadastrada pelo id") + void testDeleteTastingCard() throws Exception { + mockMvc.perform(delete("/api/v1/tasting-card/" + outputDTO.getId()) + .contentType(MediaType.APPLICATION_JSON)) + .andDo(print()) + .andExpect(status().isNoContent()); + } + + @Test + @DisplayName("Deve lançar erro ao deletar uma ficha de degustação cadastrada pelo id") + void testDeleteTastingCardError() throws Exception { + doThrow(new BadRequestException(MessagesConstants.ERROR_WHEN_DELETING)).when(tastingCardService).deleteTastingCard(outputDTO.getId().toString()); + + mockMvc.perform(delete("/api/v1/tasting-card/" + outputDTO.getId()) + .contentType(MediaType.APPLICATION_JSON)) + .andDo(print()) + .andExpect(status().isBadRequest()); + } + + private TastingCardOutputDTO createTastingCardOutputDTO() { + return TastingCardOutputDTO.builder() + .id(UUID.fromString("f5e7e3e3-3e3e-4e3e-8e3e-3e3e3e3e3e3e")) + .wineTasted("Wine Tasted") + .tastingData(LocalDate.now()) + .harvest("2021") + .grapes("Grapes") + .country("Country") + .region("Region") + .clarity(EnumClarityType.CLEAR.getCode()) + .brightness(EnumBrightnessType.BRIGHT.getCode()) + .viscosity(EnumViscosityType.VISCOUS.getCode()) + .colorRed(EnumRedColorType.RUBY.getCode()) + .colorWhite(EnumWhiteColorType.GOLDEN.getCode()) + .colorRose(EnumRoseColorType.BROWN.getCode()) + .visualInspectionClassification(EnumClassificationType.LITTLE.getCode()) + .intensity(EnumIntensityType.INTENSE.getCode()) + .olfactoryInspectionPersistence(EnumPersistenceType.PERSISTENT.getCode()) + .quality(EnumQualityType.COMMON.getCode()) + .fruity(EnumFruityType.BANANA.getCode()) + .dryFruits(EnumDryFruitsType.ALMODN.getCode()) + .florals(EnumFloralsType.ACACIA.getCode()) + .vegetablesAndHerbs(EnumVegetablesAndHerbsType.FENNEL.getCode()) + .minerals(EnumMineralsType.CHALK.getCode()) + .spices(EnumSpicesType.ANISE.getCode()) + .animals(EnumAnimalsType.HUNTING.getCode()) + .empireumatics(EnumEmpireumaticsType.CARAMEL.getCode()) + .wood(EnumWoodType.SAWDUST.getCode()) + .chemicals(EnumChemicalsAndEtherealType.ACETONE.getCode()) + .lacteal(EnumLactealType.BUTTER.getCode()) + .sweets(EnumSweetsType.BULLET.getCode()) + .olfactoryInspectionClassification(EnumClassificationType.EXCELLENT.getCode()) + .body(EnumBodyType.LITTLE_BODY.getCode()) + .sweetness(EnumSweetnessType.SWEET.getCode()) + .tannin(EnumTanninType.LITTLE_TANIC.getCode()) + .acidity(EnumAcidityType.LITTLE_ACID.getCode()) + .alcohol(EnumAlcoholType.LOW.getCode()) + .gustatoryInspectionPersistence(EnumPersistenceType.PERSISTENT.getCode()) + .maturity(EnumMaturityType.MATURE.getCode()) + .typicality(EnumTypicalityType.TYPICAL.getCode()) + .gustatoryInspectionClassification(EnumClassificationType.LITTLE.getCode()) + .opinion("Opinion") + .pointScale(EnumPointScale.VERYGOOD.getCode()) + .build(); + } + + private TastingCardInputDTO createTastingCardInputDTO() { + return TastingCardInputDTO.builder() + .wineTasted("Wine Tasted") + .tastingData(LocalDate.now()) + .harvest("2021") + .grapes("Grapes") + .country("Country") + .region("Region") + .clarity(EnumClarityType.CLEAR.getCode()) + .brightness(EnumBrightnessType.BRIGHT.getCode()) + .viscosity(EnumViscosityType.VISCOUS.getCode()) + .colorRed(EnumRedColorType.RUBY.getCode()) + .colorWhite(EnumWhiteColorType.GOLDEN.getCode()) + .colorRose(EnumRoseColorType.BROWN.getCode()) + .visualInspectionClassification(EnumClassificationType.LITTLE.getCode()) + .intensity(EnumIntensityType.INTENSE.getCode()) + .olfactoryInspectionPersistence(EnumPersistenceType.PERSISTENT.getCode()) + .quality(EnumQualityType.COMMON.getCode()) + .fruity(EnumFruityType.BANANA.getCode()) + .dryFruits(EnumDryFruitsType.ALMODN.getCode()) + .florals(EnumFloralsType.ACACIA.getCode()) + .vegetablesAndHerbs(EnumVegetablesAndHerbsType.FENNEL.getCode()) + .minerals(EnumMineralsType.CHALK.getCode()) + .spices(EnumSpicesType.ANISE.getCode()) + .animals(EnumAnimalsType.HUNTING.getCode()) + .empireumatics(EnumEmpireumaticsType.CARAMEL.getCode()) + .wood(EnumWoodType.SAWDUST.getCode()) + .chemicals(EnumChemicalsAndEtherealType.ACETONE.getCode()) + .lacteal(EnumLactealType.BUTTER.getCode()) + .sweets(EnumSweetsType.BULLET.getCode()) + .olfactoryInspectionClassification(EnumClassificationType.EXCELLENT.getCode()) + .body(EnumBodyType.LITTLE_BODY.getCode()) + .sweetness(EnumSweetnessType.SWEET.getCode()) + .tannin(EnumTanninType.LITTLE_TANIC.getCode()) + .acidity(EnumAcidityType.LITTLE_ACID.getCode()) + .alcohol(EnumAlcoholType.LOW.getCode()) + .gustatoryInspectionPersistence(EnumPersistenceType.PERSISTENT.getCode()) + .maturity(EnumMaturityType.MATURE.getCode()) + .typicality(EnumTypicalityType.TYPICAL.getCode()) + .gustatoryInspectionClassification(EnumClassificationType.LITTLE.getCode()) + .opinion("Opinion") + .pointScale(EnumPointScale.VERYGOOD.getCode()) + .dthreg(LocalDateTime.now()) + .userreg("User Reg") + .build(); + } + +}