Answered step by step
Verified Expert Solution
Link Copied!

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:
1: expected not found error instead of warning with text:
com.codility.tasks.hibernate.solution.HibernateTaskApplicationTests - should_return_not_found_message_when_id_not_exist
Output (stderr):
java.lang.AssertionError: No value at JSON path "$.message"
at com.codility.tasks.hibernate.solution.HibernateTaskApplicationTests.should_return_not_found_message_when_id_not_exist(HibernateTaskApplicationTests.java:106)
Caused by: java.lang.IllegalArgumentException: json can not be null or empty
at com.codility.tasks.hibernate.solution.HibernateTaskApplicationTests.should_return_not_found_message_when_id_not_exist(HibernateTaskApplicationTests.java:106)
Output:
[WARN]
MockHttpServletRequest:
HTTP Method = PUT
Request URI =/tasks/10
Parameters ={}
Headers ={Content-Type=[application/json;charset=UTF-8]}
Body ={"description":"new description","priority":15}
Session Attrs ={}
Handler:
Type = com.codility.tasks.hibernate.solution.TaskController
Method = public org.springframework.http.ResponseEntity com.codility.tasks.hibernate.solution.TaskController.updateTask(java.lang.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 =404
Error message = null
Headers ={}
Content type = null
Body =
Forwarded URL = null
Redirected URL = null
Cookies =[]
WRONG ANSWER
2: Not handling empty description exception:
com.codility.tasks.hibernate.solution.HibernateTaskApplicationTests - should_return_bad_request_status_when_description_is_empty
Output (stderr):
org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.springframework.dao.DataIntegrityViolationException: could not execute statement; SQL [n/a]; constraint [null]; nested exception is org.hibernate.exception.ConstraintViolationException: could not execute statement
at com.codility.tasks.hibernate.solution.HibernateTaskApplicationTests.should_return_bad_request_status_when_description_is_empty(HibernateTaskApplicationTests.java:119)
Caused by: org.springframework.dao.DataIntegrityViolationException: could not execute statement; SQL [n/a]; constraint [null]; nested exception is org.hibernate.exception.ConstraintViolationException: could not execute statement
at com.codility.tasks.hibernate.solution.HibernateTaskApplicationTests.should_return_bad_request_status_when_description_is_empty(HibernateTaskApplicationTests.java:119)
Caused by: org.hibernate.exception.ConstraintViolationException: could not execute statement
at com.codility.tasks.hibernate.solution.HibernateTaskApplicationTests.should_return_bad_request_status_when_description_is_empty(HibernateTaskApplicationTests.java:119)
Caused by: org.h2.jdbc.JdbcSQLException:
NULL not allowed for column "DESCRIPTION"; SQL statement:
update task set description=?, priority=? where id=?[23502-197]
at com.codility.tasks.hibernate.solution.HibernateTaskApplicationTests.should_return_bad_request_status_when_description_is_empty(HibernateTaskApplicationTests.java:119)
Output:
[WARN] org.hibernate.engine.jdbc.spi.SqlExceptionHelper - SQL Error: 23502, SQLState: 23502
[ERROR] org.hibernate.engine.jdbc.spi.SqlExceptionHelper - NULL not allowed for column "DESCRIPTION"; SQL statement:
update task set description=?, priority=? where id=?[23502-197]
[ERROR] org.hibernate.internal.ExceptionMapperStandardImpl - HHH000346: Error during managed flush [org.hibernate.exception.ConstraintViolationException: could not execute statement]
MockHttpServletRequest:
HTTP Method = PUT
Request URI =/tasks/10
Parameters ={}
Headers ={Content-Type=[application/json;charset=UTF-8]}
Body ={"description":"new description","priority":15}
Session Attrs ={}
Handler:
Type = com.codility.tasks.hibernate.solution.TaskController
Method = public org.springframework.http.ResponseEntity com.codility.tasks.hibernate.solution.TaskController.updateTask(java.lang.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
image text in transcribed

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Expert Performance Indexing In SQL Server

Authors: Jason Strate, Grant Fritchey

2nd Edition

1484211189, 9781484211182

More Books

Students also viewed these Databases questions