Test Report CND0034742 PRF0004839
Test Report CND0034742 PRF0004839
Notes:
N/A
Similarity Check
Status: not found
No similar solutions have been detected.
Test score
52%
Tasks in test Score
1 McqJava1 60%
Submitted in: Multiple-choice questions
2 SpringHealthcheck 44%
Submitted in: Java 8
Canvas Details
The canvas board was not used during that session.
Tasks Details
SOL0005150 PRF0004839 (Desarrollador Backend SpringBoot) – CND0034742 PRF0004839 – task 1 of 2
Task description
1.
The following questions concern the Java language.
Assuming that Superclass1 and Superclass2 are valid abstract classes, Interface1 and Interface2 are both valid interfaces, given code:
2.
Output of given code will be:
System.out.println(a == b);
System.out.println(a == c);
System.out.println(b.equals(c));
}
}
3.
If a local variable of some type is declared without defining its value and we referred to it afterwards, then:
4.
If a class parameter of some type is declared without defining its value and there is only a default constructor then:
5.
Given code will print:
6.
What is the difference between given class attributes' accessibility:
7.
Which method needs to be implemented in the Rectangle class in order to make the main() function to produce the meaningful output:
A) Rectangle()
B) toString()
C) toLine()
D) stringFormat()
8.
Which Foo class definition will ensure that it won’t be ever inherited:
9.
Which interface allows to save an object and reconstruct it at separate JVM:
A) Cloneable
B) Readable
C) Serializable
D) Constructable
10.
To ensure that some function foo() of class Bar, will be implemented separately in every subclass it should be declared as:
A) abstract foo()
B) public synchronized foo()
C) protected abstract foo()
D) protected foo()
Copyright 2009-2024 by Codility Limited. All Rights Reserved. Unauthorized copying, publication or disclosure prohibited.
Solution See Live Version
Task description
You are given a part of Spring MVC application and your task is to build new RESTful web controller.
You should implement two variants of reading the /healthcheck resource using JSON as the response data format:
{ "status": "OK" }
2. Your service is expected to handle only GET method. Other methods should return 405 status.
3. If parameters' values do not match the specified possible values or if no parameter is present, you should return HTTP status code 400 ("Bad
Request").
5. If you need to create multiple classes, you can use nested classes or define multiple classes in one source file.
6. You can use only the following libraries (and their dependencies):
Copyright 2009–2024 by Codility Limited. All Rights Reserved. Unauthorized copying, publication or disclosure prohibited.
Source code
1package com.codility.tasks.spring.healthcheck;
2
3import org.springframework.web.bind.annotation.*;
4import org.springframework.web.bind.annotation.RestController;
5import org.springframework.http.MediaType;
6import java.util.HashMap;
7import java.util.Map;
8import java.time.ZonedDateTime;
9import org.springframework.http.HttpStatus;
10import org.springframework.http.ResponseEntity;
11
12@RestController
13class HealthcheckController {
14
15 // Your solution
16
17 @GetMapping(value = "/healthcheck")
18 public ResponseEntity<Map<String,String>> healthcheck(@PathVariable("format") Integer format) {
19 System.out.println("data " + format);
20 Map<String,String> data = new HashMap<>();
21 if(format!= null){
22 data.put("status","OK");
23 if(format.equals("full")){
24 data.put("currentTime","2018-06-06T21:59:36Z");
25
26 }
27 return new ResponseEntity(data, HttpStatus.OK);
28 }else{
29 return new ResponseEntity(HttpStatus.BAD_REQUEST);
30 }
31
32 }
33
34 @PutMapping(value = "/healthcheck")
35 public ResponseEntity<Map<String,String>> healthcheckPut() {
36 return new ResponseEntity(HttpStatus.METHOD_NOT_ALLOWED);
37 }
38
39 @PostMapping(value = "/healthcheck")
40 public ResponseEntity<Map<String,String>> healthcheckPost() {
41 return new ResponseEntity(HttpStatus.METHOD_NOT_ALLOWED);
42 }
43
44
45 @DeleteMapping(value = "/healthcheck")
46 public void healthcheckDelete() {
47 return;
48 }
49
50}
Analysis summary
The following issues have been detected: wrong answers, runtime errors.
Analysis
Correctness tests
com.codility.tasks.spring.healthcheck.SolutionTest - ✔ OK
should_return_405_for_PUT_method
com.codility.tasks.spring.healthcheck.SolutionTest - ✔ OK
should_return_correct_ContentType_header_for_simple_healthcheck
com.codility.tasks.spring.healthcheck.SolutionTest - ✔ OK
should_return_405_for_POST_method
com.codility.tasks.spring.healthcheck.SolutionTest - ✘ WRONG ANSWER
should_return_400_for_invalid_format_query_param_value
com.codility.tasks.spring.healthcheck.SolutionTest - ✘ RUNTIME ERROR
should_return_correct_response_body_for_detailed_healthcheck
com.codility.tasks.spring.healthcheck.SolutionTest - ✘ WRONG ANSWER
should_return_400_for_no_format_query_param_value
com.codility.tasks.spring.healthcheck.SolutionTest - ✘ WRONG ANSWER
should_return_405_for_DELETE_method
com.codility.tasks.spring.healthcheck.SolutionTest - ✘ WRONG ANSWER
should_return_correct_response_body_for_simple_healthcheck
com.codility.tasks.spring.healthcheck.SolutionTest - ✔ OK
should_return_correct_ContentType_header_for_detailed_healthcheck