ParksController.java

1
package edu.ucsb.cs156.example.controllers;
2
3
import edu.ucsb.cs156.example.entities.Park;
4
import edu.ucsb.cs156.example.errors.EntityNotFoundException;
5
import edu.ucsb.cs156.example.repositories.ParkRepository;
6
import io.swagger.annotations.Api;
7
import io.swagger.annotations.ApiOperation;
8
import io.swagger.annotations.ApiParam;
9
import lombok.extern.slf4j.Slf4j;
10
11
import com.fasterxml.jackson.core.JsonProcessingException;
12
13
import org.springframework.beans.factory.annotation.Autowired;
14
import org.springframework.format.annotation.DateTimeFormat;
15
import org.springframework.security.access.prepost.PreAuthorize;
16
import org.springframework.web.bind.annotation.DeleteMapping;
17
import org.springframework.web.bind.annotation.GetMapping;
18
import org.springframework.web.bind.annotation.PostMapping;
19
import org.springframework.web.bind.annotation.PutMapping;
20
import org.springframework.web.bind.annotation.RequestBody;
21
import org.springframework.web.bind.annotation.RequestMapping;
22
import org.springframework.web.bind.annotation.RequestParam;
23
import org.springframework.web.bind.annotation.RestController;
24
25
import javax.validation.Valid;
26
27
import java.time.LocalDateTime;
28
29
@Api(description = "Parks")
30
@RequestMapping("/api/parks")
31
@RestController
32
@Slf4j
33
public class ParksController extends ApiController {
34
35
    @Autowired
36
    ParkRepository parkRepository;
37
38
    @ApiOperation(value = "List all parks")
39
    @PreAuthorize("hasRole('ROLE_USER')")
40
    @GetMapping("/all")
41
    public Iterable<Park> allParks() {
42
        Iterable<Park> parks = parkRepository.findAll();
43 1 1. allParks : replaced return value with null for edu/ucsb/cs156/example/controllers/ParksController::allParks → KILLED
        return parks;
44
    }
45
46
    @ApiOperation(value = "Get a single park")
47
    @PreAuthorize("hasRole('ROLE_USER')")
48
    @GetMapping("")
49
    public Park getById(
50
            @ApiParam("id") @RequestParam Long id) {
51
        Park park = parkRepository.findById(id)
52 1 1. lambda$getById$0 : replaced return value with null for edu/ucsb/cs156/example/controllers/ParksController::lambda$getById$0 → KILLED
                .orElseThrow(() -> new EntityNotFoundException(Park.class, id));
53
54 1 1. getById : replaced return value with null for edu/ucsb/cs156/example/controllers/ParksController::getById → KILLED
        return park;
55
    }
56
57
    @ApiOperation(value = "Create a new park")
58
    @PreAuthorize("hasRole('ROLE_ADMIN')")
59
    @PostMapping("/post")
60
    public Park postPark(
61
            @ApiParam("name") @RequestParam String name,
62
            @ApiParam("address") @RequestParam String address,
63
            @ApiParam("rating") @RequestParam String rating)
64
            throws JsonProcessingException {
65
66
        Park park = new Park();
67 1 1. postPark : removed call to edu/ucsb/cs156/example/entities/Park::setName → KILLED
        park.setName(name);
68 1 1. postPark : removed call to edu/ucsb/cs156/example/entities/Park::setAddress → KILLED
        park.setAddress(address);
69 1 1. postPark : removed call to edu/ucsb/cs156/example/entities/Park::setRating → KILLED
        park.setRating(rating);
70
71
        Park savedPark = parkRepository.save(park);
72
73 1 1. postPark : replaced return value with null for edu/ucsb/cs156/example/controllers/ParksController::postPark → KILLED
        return savedPark;
74
    }
75
76
    @ApiOperation(value = "Delete a Park")
77
    @PreAuthorize("hasRole('ROLE_ADMIN')")
78
    @DeleteMapping("")
79
    public Object deletePark(
80
            @ApiParam("id") @RequestParam Long id) {
81
        Park park = parkRepository.findById(id)
82 1 1. lambda$deletePark$1 : replaced return value with null for edu/ucsb/cs156/example/controllers/ParksController::lambda$deletePark$1 → KILLED
                .orElseThrow(() -> new EntityNotFoundException(Park.class, id));
83
84 1 1. deletePark : removed call to edu/ucsb/cs156/example/repositories/ParkRepository::delete → KILLED
        parkRepository.delete(park);
85 1 1. deletePark : replaced return value with null for edu/ucsb/cs156/example/controllers/ParksController::deletePark → KILLED
        return genericMessage("Park with id %s deleted".formatted(id));
86
    }
87
88
    @ApiOperation(value = "Update a single park")
89
    @PreAuthorize("hasRole('ROLE_ADMIN')")
90
    @PutMapping("")
91
    public Park updatePark(
92
            @ApiParam("id") @RequestParam Long id,
93
            @RequestBody @Valid Park incoming) {
94
95
        Park park = parkRepository.findById(id)
96 1 1. lambda$updatePark$2 : replaced return value with null for edu/ucsb/cs156/example/controllers/ParksController::lambda$updatePark$2 → KILLED
                .orElseThrow(() -> new EntityNotFoundException(Park.class, id));
97
98 1 1. updatePark : removed call to edu/ucsb/cs156/example/entities/Park::setName → KILLED
        park.setName(incoming.getName());
99 1 1. updatePark : removed call to edu/ucsb/cs156/example/entities/Park::setAddress → KILLED
        park.setAddress(incoming.getAddress());
100 1 1. updatePark : removed call to edu/ucsb/cs156/example/entities/Park::setRating → KILLED
        park.setRating(incoming.getRating());
101
102
        parkRepository.save(park);
103
104 1 1. updatePark : replaced return value with null for edu/ucsb/cs156/example/controllers/ParksController::updatePark → KILLED
        return park;
105
    }
106
}

Mutations

43

1.1
Location : allParks
Killed by : edu.ucsb.cs156.example.controllers.ParksControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.ParksControllerTests]/[method:logged_in_user_can_get_all_ucsbdates()]
replaced return value with null for edu/ucsb/cs156/example/controllers/ParksController::allParks → KILLED

52

1.1
Location : lambda$getById$0
Killed by : edu.ucsb.cs156.example.controllers.ParksControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.ParksControllerTests]/[method:test_that_logged_in_user_can_get_by_id_when_the_id_does_not_exist()]
replaced return value with null for edu/ucsb/cs156/example/controllers/ParksController::lambda$getById$0 → KILLED

54

1.1
Location : getById
Killed by : edu.ucsb.cs156.example.controllers.ParksControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.ParksControllerTests]/[method:test_that_logged_in_user_can_get_by_id_when_the_id_exists()]
replaced return value with null for edu/ucsb/cs156/example/controllers/ParksController::getById → KILLED

67

1.1
Location : postPark
Killed by : edu.ucsb.cs156.example.controllers.ParksControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.ParksControllerTests]/[method:an_admin_user_can_post_a_new_ucsbdate()]
removed call to edu/ucsb/cs156/example/entities/Park::setName → KILLED

68

1.1
Location : postPark
Killed by : edu.ucsb.cs156.example.controllers.ParksControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.ParksControllerTests]/[method:an_admin_user_can_post_a_new_ucsbdate()]
removed call to edu/ucsb/cs156/example/entities/Park::setAddress → KILLED

69

1.1
Location : postPark
Killed by : edu.ucsb.cs156.example.controllers.ParksControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.ParksControllerTests]/[method:an_admin_user_can_post_a_new_ucsbdate()]
removed call to edu/ucsb/cs156/example/entities/Park::setRating → KILLED

73

1.1
Location : postPark
Killed by : edu.ucsb.cs156.example.controllers.ParksControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.ParksControllerTests]/[method:an_admin_user_can_post_a_new_ucsbdate()]
replaced return value with null for edu/ucsb/cs156/example/controllers/ParksController::postPark → KILLED

82

1.1
Location : lambda$deletePark$1
Killed by : edu.ucsb.cs156.example.controllers.ParksControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.ParksControllerTests]/[method:admin_tries_to_delete_non_existant_ucsbdate_and_gets_right_error_message()]
replaced return value with null for edu/ucsb/cs156/example/controllers/ParksController::lambda$deletePark$1 → KILLED

84

1.1
Location : deletePark
Killed by : edu.ucsb.cs156.example.controllers.ParksControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.ParksControllerTests]/[method:admin_can_delete_a_date()]
removed call to edu/ucsb/cs156/example/repositories/ParkRepository::delete → KILLED

85

1.1
Location : deletePark
Killed by : edu.ucsb.cs156.example.controllers.ParksControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.ParksControllerTests]/[method:admin_can_delete_a_date()]
replaced return value with null for edu/ucsb/cs156/example/controllers/ParksController::deletePark → KILLED

96

1.1
Location : lambda$updatePark$2
Killed by : edu.ucsb.cs156.example.controllers.ParksControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.ParksControllerTests]/[method:admin_cannot_edit_ucsbdate_that_does_not_exist()]
replaced return value with null for edu/ucsb/cs156/example/controllers/ParksController::lambda$updatePark$2 → KILLED

98

1.1
Location : updatePark
Killed by : edu.ucsb.cs156.example.controllers.ParksControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.ParksControllerTests]/[method:admin_can_edit_an_existing_ucsbdate()]
removed call to edu/ucsb/cs156/example/entities/Park::setName → KILLED

99

1.1
Location : updatePark
Killed by : edu.ucsb.cs156.example.controllers.ParksControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.ParksControllerTests]/[method:admin_can_edit_an_existing_ucsbdate()]
removed call to edu/ucsb/cs156/example/entities/Park::setAddress → KILLED

100

1.1
Location : updatePark
Killed by : edu.ucsb.cs156.example.controllers.ParksControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.ParksControllerTests]/[method:admin_can_edit_an_existing_ucsbdate()]
removed call to edu/ucsb/cs156/example/entities/Park::setRating → KILLED

104

1.1
Location : updatePark
Killed by : edu.ucsb.cs156.example.controllers.ParksControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.ParksControllerTests]/[method:admin_can_edit_an_existing_ucsbdate()]
replaced return value with null for edu/ucsb/cs156/example/controllers/ParksController::updatePark → KILLED

Active mutators

Tests examined


Report generated by PIT 1.7.3