Solucionado (ver solução)
Solucionado
(ver solução)
7
respostas

Teste falho: Erro 500 sendo retornado

Esta retornando erro 500

Insira aqui a descrição dessa imagem para ajudar na acessibilidade

ConsultaControllerTeste

Insira aqui a descrição dessa imagem para ajudar na acessibilidade

7 respostas

Oi Edilberto!

Posta aqui o logo do erro completo

:: Spring Boot :: (v3.0.6)

2023-05-15T16:47:08.750-03:00 INFO 55543 --- [ main] m.v.a.controller.ConsultaControllerTest : Starting ConsultaControllerTest using Java 17.0.7 with PID 55543 (started by edilberto in /home/edilberto/projetos/api) 2023-05-15T16:47:08.752-03:00 INFO 55543 --- [ main] m.v.a.controller.ConsultaControllerTest : No active profile set, falling back to 1 default profile: "default" 2023-05-15T16:47:09.264-03:00 INFO 55543 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data JPA repositories in DEFAULT mode. 2023-05-15T16:47:09.305-03:00 INFO 55543 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 36 ms. Found 4 JPA repository interfaces. 2023-05-15T16:47:09.682-03:00 INFO 55543 --- [ main] o.f.c.internal.license.VersionPrinter : Flyway Community Edition 9.5.1 by Redgate 2023-05-15T16:47:09.682-03:00 INFO 55543 --- [ main] o.f.c.internal.license.VersionPrinter : See what's new here: https://flywaydb.org/documentation/learnmore/releaseNotes#9.5.1 2023-05-15T16:47:09.682-03:00 INFO 55543 --- [ main] o.f.c.internal.license.VersionPrinter : 2023-05-15T16:47:09.688-03:00 INFO 55543 --- [ main] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Starting... 2023-05-15T16:47:09.941-03:00 INFO 55543 --- [ main] com.zaxxer.hikari.pool.HikariPool : HikariPool-1 - Added connection com.mysql.cj.jdbc.ConnectionImpl@629075f4 2023-05-15T16:47:09.942-03:00 INFO 55543 --- [ main] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Start completed. 2023-05-15T16:47:09.966-03:00 INFO 55543 --- [ main] o.f.c.i.database.base.BaseDatabaseType : Database: jdbc:mysql://localhost/vollmed_api (MySQL 8.0) 2023-05-15T16:47:10.009-03:00 INFO 55543 --- [ main] o.f.core.internal.command.DbValidate : Successfully validated 7 migrations (execution time 00:00.019s) 2023-05-15T16:47:10.022-03:00 INFO 55543 --- [ main] o.f.core.internal.command.DbMigrate : Current version of schema vollmed_api: 7 2023-05-15T16:47:10.023-03:00 INFO 55543 --- [ main] o.f.core.internal.command.DbMigrate : Schema vollmed_api is up to date. No migration necessary. 2023-05-15T16:47:10.117-03:00 INFO 55543 --- [ main] o.hibernate.jpa.internal.util.LogHelper : HHH000204: Processing PersistenceUnitInfo [name: default] 2023-05-15T16:47:10.151-03:00 INFO 55543 --- [ main] org.hibernate.Version : HHH000412: Hibernate ORM core version 6.1.7.Final 2023-05-15T16:47:10.366-03:00 INFO 55543 --- [ main] SQL dialect : HHH000400: Using dialect: org.hibernate.dialect.MySQLDialect 2023-05-15T16:47:10.856-03:00 INFO 55543 --- [ main] o.h.e.t.j.p.i.JtaPlatformInitiator : HHH000490: Using JtaPlatform implementation: [org.hibernate.engine.transaction.jta.platform.internal.NoJtaPlatform] 2023-05-15T16:47:10.862-03:00 INFO 55543 --- [ main] j.LocalContainerEntityManagerFactoryBean : Initialized JPA EntityManagerFactory for persistence unit 'default' 2023-05-15T16:47:11.454-03:00 WARN 55543 --- [ main] JpaBaseConfiguration$JpaWebConfiguration : spring.jpa.open-in-view is enabled by default. Therefore, database queries may be performed during view rendering. Explicitly configure spring.jpa.open-in-view to disable this warning 2023-05-15T16:47:11.671-03:00 INFO 55543 --- [ main] o.s.s.web.DefaultSecurityFilterChain : Will secure any request with

[org.springframework.security.web.session.DisableEncodeUrlFilter@5f160341, org.springframework.security.web.context.request.async.WebAsyncManagerIntegrationFilter@31f5580b, org.springframework.security.web.context.SecurityContextHolderFilter@108a7fff, org.springframework.security.web.header.HeaderWriterFilter@2100b770, org.springframework.security.web.authentication.logout.LogoutFilter@3de4f936, med.voll.api.infra.security.SecurityFilter@73c6ae15, org.springframework.security.web.savedrequest.RequestCacheAwareFilter@652855c4, org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter@619dc070, org.springframework.security.web.authentication.AnonymousAuthenticationFilter@56a8b19f, org.springframework.security.web.session.SessionManagementFilter@47e02a89, org.springframework.security.web.access.ExceptionTranslationFilter@c32908c, org.springframework.security.web.access.intercept.AuthorizationFilter@5d267575] 2023-05-15T16:47:11.933-03:00 INFO 55543 --- [ main] o.s.b.t.m.w.SpringBootMockServletContext : Initializing Spring TestDispatcherServlet '' 2023-05-15T16:47:11.933-03:00 INFO 55543 --- [ main] o.s.t.web.servlet.TestDispatcherServlet : Initializing Servlet '' 2023-05-15T16:47:11.934-03:00 INFO 55543 --- [ main] o.s.t.web.servlet.TestDispatcherServlet : Completed initialization in 1 ms 2023-05-15T16:47:11.957-03:00 INFO 55543 --- [ main] m.v.a.controller.ConsultaControllerTest : Started ConsultaControllerTest in 3.361 seconds (process running for 4.038)

MockHttpServletRequest: HTTP Method = POST Request URI = /consultas Parameters = {} Headers = [] Body = null Session Attrs = {}

Handler: Type = med.voll.api.controller.ConsultaController Method = med.voll.api.controller.ConsultaController#agendar(DadosAgendamentoConsulta)

Async: Async started = false Async result = null

Resolved Exception: Type = org.springframework.http.converter.HttpMessageNotReadableException

ModelAndView: View name = null View = null Model = null

FlashMap: Attributes = null

MockHttpServletResponse: Status = 500 Error message = null Headers = [Content-Type:"text/plain;charset=UTF-8", Content-Length:"192", X-Content-Type-Options:"nosniff", X-XSS-Protection:"0", Cache-Control:"no-cache, no-store, max-age=0, must-revalidate", Pragma:"no-cache", Expires:"0", X-Frame-Options:"DENY"] Content type = text/plain;charset=UTF-8 Body = Erro: Required request body is missing: public org.springframework.http.ResponseEntity med.voll.api.controller.ConsultaController.agendar(med.voll.api.domain.consulta.DadosAgendamentoConsulta) Forwarded URL = null Redirected URL = null Cookies = []

org.opentest4j.AssertionFailedError: expected: 400 but was: 500 Expected :400 Actual :500

at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:77)
at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.base/java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:499)
at med.voll.api.controller.ConsultaControllerTest.agendar_cenario1(ConsultaControllerTest.java:30)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:568)
at org.junit.platform.commons.util.ReflectionUtils.invokeMethod(ReflectionUtils.java:727)
at org.junit.jupiter.engine.execution.MethodInvocation.proceed(MethodInvocation.java:60)
at org.junit.jupiter.engine.execution.InvocationInterceptorChain$ValidatingInvocation.proceed(InvocationInterceptorChain.java:131)
at org.junit.jupiter.engine.extension.TimeoutExtension.intercept(TimeoutExtension.java:156)
at org.junit.jupiter.engine.extension.TimeoutExtension.interceptTestableMethod(TimeoutExtension.java:147)
at org.junit.jupiter.engine.extension.TimeoutExtension.interceptTestMethod(TimeoutExtension.java:86)
at org.junit.jupiter.engine.execution.InterceptingExecutableInvoker$ReflectiveInterceptorCall.lambda$ofVoidMethod$0(InterceptingExecutableInvoker.java:103)
at org.junit.jupiter.engine.execution.InterceptingExecutableInvoker.lambda$invoke$0(InterceptingExecutableInvoker.java:93)
at org.junit.jupiter.engine.execution.InvocationInterceptorChain$InterceptedInvocation.proceed(InvocationInterceptorChain.java:106)
at org.junit.jupiter.engine.execution.InvocationInterceptorChain.proceed(InvocationInterceptorChain.java:64)
at org.junit.jupiter.engine.execution.InvocationInterceptorChain.chainAndInvoke(InvocationInterceptorChain.java:45)
at org.junit.jupiter.engine.execution.InvocationInterceptorChain.invoke(InvocationInterceptorChain.java:37)
at org.junit.jupiter.engine.execution.InterceptingExecutableInvoker.invoke(InterceptingExecutableInvoker.java:92)
at org.junit.jupiter.engine.execution.InterceptingExecutableInvoker.invoke(InterceptingExecutableInvoker.java:86)
at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.lambda$invokeTestMethod$7(TestMethodTestDescriptor.java:217)
at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.invokeTestMethod(TestMethodTestDescriptor.java:213)
at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.execute(TestMethodTestDescriptor.java:138)
at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.execute(TestMethodTestDescriptor.java:68)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$6(NodeTestTask.java:151)
at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$8(NodeTestTask.java:141)
at org.junit.platform.engine.support.hierarchical.Node.around(Node.java:137)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$9(NodeTestTask.java:139)
at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTask.java:138)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:95)
at java.base/java.util.ArrayList.forEach(ArrayList.java:1511)
at 

org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.invokeAll(SameThreadHierarchicalTestExecutorService.java:41) at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$6(NodeTestTask.java:155) at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73) at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$8(NodeTestTask.java:141) at org.junit.platform.engine.support.hierarchical.Node.around(Node.java:137) at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$9(NodeTestTask.java:139) at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73) at org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTask.java:138) at org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:95) at java.base/java.util.ArrayList.forEach(ArrayList.java:1511) at org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.invokeAll(SameThreadHierarchicalTestExecutorService.java:41) at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$6(NodeTestTask.java:155) at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73) at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$8(NodeTestTask.java:141) at org.junit.platform.engine.support.hierarchical.Node.around(Node.java:137) at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$9(NodeTestTask.java:139) at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73) at org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTask.java:138) at org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:95) at org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.submit(SameThreadHierarchicalTestExecutorService.java:35) at org.junit.platform.engine.support.hierarchical.HierarchicalTestExecutor.execute(HierarchicalTestExecutor.java:57) at org.junit.platform.engine.support.hierarchical.HierarchicalTestEngine.execute(HierarchicalTestEngine.java:54) at org.junit.platform.launcher.core.EngineExecutionOrchestrator.execute(EngineExecutionOrchestrator.java:147) at org.junit.platform.launcher.core.EngineExecutionOrchestrator.execute(EngineExecutionOrchestrator.java:127) at org.junit.platform.launcher.core.EngineExecutionOrchestrator.execute(EngineExecutionOrchestrator.java:90) at org.junit.platform.launcher.core.EngineExecutionOrchestrator.lambda$execute$0(EngineExecutionOrchestrator.java:55) at org.junit.platform.launcher.core.EngineExecutionOrchestrator.withInterceptedStreams(EngineExecutionOrchestrator.java:102) at org.junit.platform.launcher.core.EngineExecutionOrchestrator.execute(EngineExecutionOrchestrator.java:54) at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:114) at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:86) at org.junit.platform.launcher.core.DefaultLauncherSession$DelegatingLauncher.execute(DefaultLauncherSession.java:86) at org.junit.platform.launcher.core.SessionPerRequestLauncher.execute(SessionPerRequestLauncher.java:53) at com.intellij.junit5.JUnit5IdeaTestRunner.startRunnerWithArgs(JUnit5IdeaTestRunner.java:57) at com.intellij.rt.junit.IdeaTestRunner$Repeater$1.execute(IdeaTestRunner.java:38) at com.intellij.rt.execution.junit.TestsRepeater.repeat(TestsRepeater.java:11) at com.intellij.rt.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:35) at com.intellij.rt.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:232) at com.intellij.rt.junit.JUnitStarter.main(JUnitStarter.java:55)

2023-05-15T16:47:12.149-03:00 INFO 55543 --- [ionShutdownHook] j.LocalContainerEntityManagerFactoryBean : Closing JPA EntityManagerFactory for persistence unit 'default' 2023-05-15T16:47:12.151-03:00 INFO 55543 --- [ionShutdownHook] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Shutdown initiated... 2023-05-15T16:47:12.156-03:00 INFO 55543 --- [ionShutdownHook] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Shutdown completed.

Process finished with exit code 255

solução!

Se eu deixar o codigo com o .content().contentType ai funciona:

Insira aqui a descrição dessa imagem para ajudar na acessibilidade Insira aqui a descrição dessa imagem para ajudar na acessibilidade

Resolvido. Faltava adicionar um json vazio no corpo da requisição.