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
@Api(description = "Park")
28
@RequestMapping("/api/parks")
29
@RestController
30
@Slf4j
31
public class ParksController extends ApiController {
32
33
    @Autowired
34
    ParkRepository parkRepository;
35
36
    @ApiOperation(value = "List all parks")
37
    @PreAuthorize("hasRole('ROLE_USER')")
38
    @GetMapping("/all")
39
    public Iterable<Park> allParks() {
40
        Iterable<Park> parks = parkRepository.findAll();
41 1 1. allParks : replaced return value with null for edu/ucsb/cs156/example/controllers/ParksController::allParks → KILLED
        return parks;
42
    }
43
44
    @ApiOperation(value = "Get a single park")
45
    @PreAuthorize("hasRole('ROLE_USER')")
46
    @GetMapping("")
47
    public Park getById(
48
            @ApiParam("id") @RequestParam Long id) {
49
        Park park = parkRepository.findById(id)
50 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));
51
52 1 1. getById : replaced return value with null for edu/ucsb/cs156/example/controllers/ParksController::getById → KILLED
        return park;
53
    }
54
55
    @ApiOperation(value = "Create a new park")
56
    @PreAuthorize("hasRole('ROLE_ADMIN')")
57
    @PostMapping("/post")
58
    public Park postPark(
59
            @ApiParam("name") @RequestParam String name,
60
            @ApiParam("state") @RequestParam String state,
61
            @ApiParam("acres") @RequestParam int acres)
62
            throws JsonProcessingException {
63
64
        Park park = new Park();
65 1 1. postPark : removed call to edu/ucsb/cs156/example/entities/Park::setName → KILLED
        park.setName(name);
66 1 1. postPark : removed call to edu/ucsb/cs156/example/entities/Park::setState → KILLED
        park.setState(state);
67 1 1. postPark : removed call to edu/ucsb/cs156/example/entities/Park::setAcres → KILLED
        park.setAcres(acres);
68
69
        Park savedPark = parkRepository.save(park);
70
71 1 1. postPark : replaced return value with null for edu/ucsb/cs156/example/controllers/ParksController::postPark → KILLED
        return savedPark;
72
    }
73
74
    @ApiOperation(value = "Delete a Park")
75
    @PreAuthorize("hasRole('ROLE_ADMIN')")
76
    @DeleteMapping("")
77
    public Object deletePark(
78
            @ApiParam("id") @RequestParam Long id) {
79
        Park park = parkRepository.findById(id)
80 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));
81
82 1 1. deletePark : removed call to edu/ucsb/cs156/example/repositories/ParkRepository::delete → KILLED
        parkRepository.delete(park);
83 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));
84
    }
85
86
    @ApiOperation(value = "Update a single park")
87
    @PreAuthorize("hasRole('ROLE_ADMIN')")
88
    @PutMapping("")
89
    public Park updatePark(
90
            @ApiParam("id") @RequestParam Long id,
91
            @RequestBody @Valid Park incoming) {
92
93
        Park park = parkRepository.findById(id)
94 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));
95
96 1 1. updatePark : removed call to edu/ucsb/cs156/example/entities/Park::setName → KILLED
        park.setName(incoming.getName());
97 1 1. updatePark : removed call to edu/ucsb/cs156/example/entities/Park::setState → KILLED
        park.setState(incoming.getState());
98 1 1. updatePark : removed call to edu/ucsb/cs156/example/entities/Park::setAcres → KILLED
        park.setAcres(incoming.getAcres());
99
100
        parkRepository.save(park);
101
102 1 1. updatePark : replaced return value with null for edu/ucsb/cs156/example/controllers/ParksController::updatePark → KILLED
        return park;
103
    }
104
}

Mutations

41

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_parks()]
replaced return value with null for edu/ucsb/cs156/example/controllers/ParksController::allParks → KILLED

50

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

52

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

65

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_park()]
removed call to edu/ucsb/cs156/example/entities/Park::setName → KILLED

66

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_park()]
removed call to edu/ucsb/cs156/example/entities/Park::setState → 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_park()]
removed call to edu/ucsb/cs156/example/entities/Park::setAcres → KILLED

71

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_park()]
replaced return value with null for edu/ucsb/cs156/example/controllers/ParksController::postPark → KILLED

80

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_park_and_gets_right_error_message()]
replaced return value with null for edu/ucsb/cs156/example/controllers/ParksController::lambda$deletePark$1 → KILLED

82

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_park()]
removed call to edu/ucsb/cs156/example/repositories/ParkRepository::delete → KILLED

83

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_park()]
replaced return value with null for edu/ucsb/cs156/example/controllers/ParksController::deletePark → KILLED

94

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_park_that_does_not_exist()]
replaced return value with null for edu/ucsb/cs156/example/controllers/ParksController::lambda$updatePark$2 → KILLED

96

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_park()]
removed call to edu/ucsb/cs156/example/entities/Park::setName → KILLED

97

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_park()]
removed call to edu/ucsb/cs156/example/entities/Park::setState → 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_park()]
removed call to edu/ucsb/cs156/example/entities/Park::setAcres → KILLED

102

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_park()]
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