DogController.java

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

Mutations

38

1.1
Location : allDogs
Killed by : edu.ucsb.cs156.example.controllers.DogControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.DogControllerTests]/[method:logged_in_user_can_get_all_dogs()]
replaced return value with null for edu/ucsb/cs156/example/controllers/DogController::allDogs → KILLED

47

1.1
Location : lambda$getById$0
Killed by : edu.ucsb.cs156.example.controllers.DogControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.DogControllerTests]/[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/DogController::lambda$getById$0 → KILLED

49

1.1
Location : getById
Killed by : edu.ucsb.cs156.example.controllers.DogControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.DogControllerTests]/[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/DogController::getById → KILLED

61

1.1
Location : postDog
Killed by : edu.ucsb.cs156.example.controllers.DogControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.DogControllerTests]/[method:an_admin_user_can_post_a_new_dog()]
removed call to edu/ucsb/cs156/example/entities/Dog::setName → KILLED

62

1.1
Location : postDog
Killed by : edu.ucsb.cs156.example.controllers.DogControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.DogControllerTests]/[method:an_admin_user_can_post_a_new_dog()]
removed call to edu/ucsb/cs156/example/entities/Dog::setBreed → KILLED

66

1.1
Location : postDog
Killed by : edu.ucsb.cs156.example.controllers.DogControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.DogControllerTests]/[method:an_admin_user_can_post_a_new_dog()]
replaced return value with null for edu/ucsb/cs156/example/controllers/DogController::postDog → KILLED

75

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

77

1.1
Location : deleteDog
Killed by : edu.ucsb.cs156.example.controllers.DogControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.DogControllerTests]/[method:admin_can_delete_a_dog()]
removed call to edu/ucsb/cs156/example/repositories/DogRepository::delete → KILLED

78

1.1
Location : deleteDog
Killed by : edu.ucsb.cs156.example.controllers.DogControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.DogControllerTests]/[method:admin_can_delete_a_dog()]
replaced return value with null for edu/ucsb/cs156/example/controllers/DogController::deleteDog → KILLED

89

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

91

1.1
Location : updateDog
Killed by : edu.ucsb.cs156.example.controllers.DogControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.DogControllerTests]/[method:admin_can_edit_an_existing_dog()]
removed call to edu/ucsb/cs156/example/entities/Dog::updateFrom → KILLED

95

1.1
Location : updateDog
Killed by : edu.ucsb.cs156.example.controllers.DogControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.DogControllerTests]/[method:admin_can_edit_an_existing_dog()]
replaced return value with null for edu/ucsb/cs156/example/controllers/DogController::updateDog → KILLED

Active mutators

Tests examined


Report generated by PIT 1.7.3