From bb5d625b831bf02439f520b11b969daaa521c1bd Mon Sep 17 00:00:00 2001 From: Shazam Date: Thu, 18 May 2023 13:16:31 -0300 Subject: [PATCH] bugfix: condition uk placa --- README.md | 2 +- .../MessagingSenderConfig.java | 2 +- .../app/domain/veiculo/VeiculoService.java | 7 +++++-- .../{ => model}/VeiculoRequestedSender.java | 2 +- .../veiculo/VeiculoIntegrationTest.java | 2 +- .../veiculo/VeiculoControllerTest.java | 2 +- src/test/resources/application-test.properties | 18 +++--------------- 7 files changed, 13 insertions(+), 22 deletions(-) rename src/main/java/core/demo/app/{infrastucture/messaging => config}/MessagingSenderConfig.java (96%) rename src/main/java/core/demo/app/domain/veiculo/{ => model}/VeiculoRequestedSender.java (94%) diff --git a/README.md b/README.md index cb834bf..e49f2a0 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ # API Car with FIPE integration -![coverag](https://img.shields.io/badge/coverage-85%25-darkgreen) +![coverag](https://img.shields.io/badge/coverage-92%25-darkgreen) API register vehicle indexed by brand and model with external client app price search. ![alt text][8] diff --git a/src/main/java/core/demo/app/infrastucture/messaging/MessagingSenderConfig.java b/src/main/java/core/demo/app/config/MessagingSenderConfig.java similarity index 96% rename from src/main/java/core/demo/app/infrastucture/messaging/MessagingSenderConfig.java rename to src/main/java/core/demo/app/config/MessagingSenderConfig.java index e391cf8..7f94472 100644 --- a/src/main/java/core/demo/app/infrastucture/messaging/MessagingSenderConfig.java +++ b/src/main/java/core/demo/app/config/MessagingSenderConfig.java @@ -1,4 +1,4 @@ -package core.demo.app.infrastucture.messaging; +package core.demo.app.config; import org.springframework.amqp.core.*; import org.springframework.beans.factory.annotation.Value; diff --git a/src/main/java/core/demo/app/domain/veiculo/VeiculoService.java b/src/main/java/core/demo/app/domain/veiculo/VeiculoService.java index d77f51d..66a3180 100644 --- a/src/main/java/core/demo/app/domain/veiculo/VeiculoService.java +++ b/src/main/java/core/demo/app/domain/veiculo/VeiculoService.java @@ -10,6 +10,7 @@ import core.demo.app.domain.veiculo.exceptions.VeiculoAlreadyExistException; import core.demo.app.domain.veiculo.model.VeiculoEntity; import core.demo.app.domain.veiculo.model.VeiculoRepository; +import core.demo.app.domain.veiculo.model.VeiculoRequestedSender; import core.demo.app.infrastucture.clients.FipeClient; import core.demo.app.infrastucture.clients.FipePriceRequest; import core.demo.app.interfaces.veiculo.VeiculoRequest; @@ -42,8 +43,10 @@ public class VeiculoService { public VeiculoEntity scheduleCreation(final VeiculoRequest veiculoRequest) { log.trace("action=veiculo-creation status=start placa={}", veiculoRequest.getPlaca()); - this.veiculoRepository.findByPlaca(veiculoRequest.getPlaca()) - .orElseThrow(() -> new VeiculoAlreadyExistException(veiculoRequest.getPlaca())); + final var veiculoByPlacaFoundOpt = this.veiculoRepository.findByPlaca(veiculoRequest.getPlaca()); + if (veiculoByPlacaFoundOpt.isPresent()) { + throw new VeiculoAlreadyExistException(veiculoRequest.getPlaca()); + } final MarcaEntity marca = marcaRepository.findByFipeId(veiculoRequest.getMarcaId()) .orElseThrow(() -> new EntityNotFoundException("Not found marca=" + veiculoRequest.getMarcaId())); diff --git a/src/main/java/core/demo/app/domain/veiculo/VeiculoRequestedSender.java b/src/main/java/core/demo/app/domain/veiculo/model/VeiculoRequestedSender.java similarity index 94% rename from src/main/java/core/demo/app/domain/veiculo/VeiculoRequestedSender.java rename to src/main/java/core/demo/app/domain/veiculo/model/VeiculoRequestedSender.java index b1957a6..fe0f76b 100644 --- a/src/main/java/core/demo/app/domain/veiculo/VeiculoRequestedSender.java +++ b/src/main/java/core/demo/app/domain/veiculo/model/VeiculoRequestedSender.java @@ -1,4 +1,4 @@ -package core.demo.app.domain.veiculo; +package core.demo.app.domain.veiculo.model; import core.demo.app.domain.utils.JsonUtils; import core.demo.app.domain.veiculo.model.VeiculoEntity; diff --git a/src/test/java/core/demo/app/integration/veiculo/VeiculoIntegrationTest.java b/src/test/java/core/demo/app/integration/veiculo/VeiculoIntegrationTest.java index 4b56e80..3bb6bb1 100644 --- a/src/test/java/core/demo/app/integration/veiculo/VeiculoIntegrationTest.java +++ b/src/test/java/core/demo/app/integration/veiculo/VeiculoIntegrationTest.java @@ -55,7 +55,7 @@ void setUp() { @Sql("classpath:/truncate-database.sql") @Sql("classpath:/mocks/db/setup-schema.sql") @Sql("classpath:/mocks/db/setup-vehicle.sql") - void mustIntegrateVeihicleCreationAndReadSavedValue() throws JsonProcessingException { + void mustIntegrateVehicleCreationAndReadSavedValue() throws JsonProcessingException { VeiculoRequest request = VeiculoRequestTemplates .defaultBuilder() .placa("NEW-1234") diff --git a/src/test/java/core/demo/app/interfaces/veiculo/VeiculoControllerTest.java b/src/test/java/core/demo/app/interfaces/veiculo/VeiculoControllerTest.java index b203338..27b1753 100644 --- a/src/test/java/core/demo/app/interfaces/veiculo/VeiculoControllerTest.java +++ b/src/test/java/core/demo/app/interfaces/veiculo/VeiculoControllerTest.java @@ -54,7 +54,7 @@ void setUp() { @Test @Sql("classpath:/truncate-database.sql") @Sql("classpath:/mocks/db/setup-schema.sql") - void mustValidadeAndProduceVeiculoCreationRequested() { + void mustValidateAndProduceVeiculoCreationRequested() { // arrange VeiculoRequest request = VeiculoRequestTemplates.build(); diff --git a/src/test/resources/application-test.properties b/src/test/resources/application-test.properties index 220c9c9..1b7c8c6 100644 --- a/src/test/resources/application-test.properties +++ b/src/test/resources/application-test.properties @@ -15,21 +15,9 @@ logging.level.core.chapadaguides=TRACE #spring.jpa.properties.hibernate.format_sql=true #logging.level.org.hibernate.SQL=DEBUG #logging.level.org.hibernate.type.descriptor.sql.BasicBinder=TRACE -logging.level.org.springframework.jdbc.core.JdbcTemplate=DEBUG -logging.level.org.springframework.jdbc.core.StatementCreatorUtils=TRACE -spring.jpa.properties.hibernate.hbm2ddl.import_files_sql_extractor=org.hibernate.tool.hbm2ddl.MultipleLinesSqlCommandExtractor -# Storage -google.credential.file=123 -google.storage.projectId=chapada-guides -storage.bucket.profiles=profiles -storage.bucket.guide-documents=guide-documents -# Email -source.host=http://localhost:8080 -source.front.host=http://localhost:5173 -# Payment -payment.mercado-pago.access-token="" -## Testing Scheduled (Last probable) -bcg.job.cron.disable-guide-plan=1 1 1 1 1 ? +#logging.level.org.springframework.jdbc.core.JdbcTemplate=DEBUG +#logging.level.org.springframework.jdbc.core.StatementCreatorUtils=TRACE +#spring.jpa.properties.hibernate.hbm2ddl.import_files_sql_extractor=org.hibernate.tool.hbm2ddl.MultipleLinesSqlCommandExtractor ## Clients spring.cloud.loadbalancer.ribbon.enable=false # Wiremock Client