Answered step by step
Verified Expert Solution
Question
1 Approved Answer
you're working on a system that helps to manage tasks on a todo list. Your job is to implement an endpoint that allows these tasks
you're working on a system that helps to manage tasks on a todo list. Your job is to implement an endpoint that allows these tasks to be updated. with java and spring boot.
Although the solution posted here on cheggis valid, there are three unit tests that are not handled as expected:
: expected not found error instead of warning with text:
com.codility.tasks.hibernate.solution.HibernateTaskApplicationTests shouldreturnnotfoundmessagewhenidnotexist
Output stderr:
java.lang.AssertionError: No value at JSON path $message"
at com.codility.tasks.hibernate.solution.HibernateTaskApplicationTests.shouldreturnnotfoundmessagewhenidnotexistHibernateTaskApplicationTestsjava:
Caused by: java.lang.IllegalArgumentException: json can not be null or empty
at com.codility.tasks.hibernate.solution.HibernateTaskApplicationTests.shouldreturnnotfoundmessagewhenidnotexistHibernateTaskApplicationTestsjava:
Output:
WARN
MockHttpServletRequest:
HTTP Method PUT
Request URI tasks
Parameters
Headers ContentTypeapplicationjson;charsetUTF
Body description:"new description","priority":
Session Attrs
Handler:
Type com.codility.tasks.hibernate.solution.TaskController
Method public org.springframework.httpResponseEntity com.codility.tasks.hibernate.solution.TaskController.updateTaskjavalang.Long,com.codility.tasks.hibernate.solution.Task
Async:
Async started false
Async result null
Resolved Exception:
Type null
ModelAndView:
View name null
View null
Model null
FlashMap:
Attributes null
MockHttpServletResponse:
Status
Error message null
Headers
Content type null
Body
Forwarded URL null
Redirected URL null
Cookies
WRONG ANSWER
: Not handling empty description exception:
com.codility.tasks.hibernate.solution.HibernateTaskApplicationTests shouldreturnbadrequeststatuswhendescriptionisempty
Output stderr:
org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.springframework.dao.DataIntegrityViolationException: could not execute statement; SQL na; constraint null; nested exception is org.hibernate.exception.ConstraintViolationException: could not execute statement
at com.codility.tasks.hibernate.solution.HibernateTaskApplicationTests.shouldreturnbadrequeststatuswhendescriptionisemptyHibernateTaskApplicationTestsjava:
Caused by: org.springframework.dao.DataIntegrityViolationException: could not execute statement; SQL na; constraint null; nested exception is org.hibernate.exception.ConstraintViolationException: could not execute statement
at com.codility.tasks.hibernate.solution.HibernateTaskApplicationTests.shouldreturnbadrequeststatuswhendescriptionisemptyHibernateTaskApplicationTestsjava:
Caused by: org.hibernate.exception.ConstraintViolationException: could not execute statement
at com.codility.tasks.hibernate.solution.HibernateTaskApplicationTests.shouldreturnbadrequeststatuswhendescriptionisemptyHibernateTaskApplicationTestsjava:
Caused by: org.hjdbcJdbcSQLException:
NULL not allowed for column "DESCRIPTION"; SQL statement:
update task set description priority where id
at com.codility.tasks.hibernate.solution.HibernateTaskApplicationTests.shouldreturnbadrequeststatuswhendescriptionisemptyHibernateTaskApplicationTestsjava:
Output:
WARN org.hibernate.engine.jdbcspi.SqlExceptionHelper SQL Error: SQLState:
ERROR org.hibernate.engine.jdbcspi.SqlExceptionHelper NULL not allowed for column "DESCRIPTION"; SQL statement:
update task set description priority where id
ERROR org.hibernate.internal.ExceptionMapperStandardImpl HHH: Error during managed flush orghibernate.exception.ConstraintViolationException: could not execute statement
MockHttpServletRequest:
HTTP Method PUT
Request URI tasks
Parameters
Headers ContentTypeapplicationjson;charsetUTF
Body description:"new description","priority":
Session Attrs
Handler:
Type com.codility.tasks.hibernate.solution.TaskController
Method public org.springframework.httpResponseEntity com.codility.tasks.hibernate.solution.TaskController.updateTaskjavalang.Long,com.codility.tasks.hibernate.solution.Task
Async:
Async started false
Async result null
Resolved Exception:
Type null
ModelAndView:
View name null
View null
Model null
FlashMap:
Attributes null
MockHttpServletRespon
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started