RestaurantsController.java

1
package edu.ucsb.cs156.example.controllers;
2
3
import edu.ucsb.cs156.example.entities.Restaurant;
4
import edu.ucsb.cs156.example.errors.EntityNotFoundException;
5
import edu.ucsb.cs156.example.repositories.RestaurantRepository;
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.security.access.prepost.PreAuthorize;
15
import org.springframework.web.bind.annotation.DeleteMapping;
16
import org.springframework.web.bind.annotation.GetMapping;
17
import org.springframework.web.bind.annotation.PostMapping;
18
import org.springframework.web.bind.annotation.PutMapping;
19
import org.springframework.web.bind.annotation.RequestBody;
20
import org.springframework.web.bind.annotation.RequestMapping;
21
import org.springframework.web.bind.annotation.RequestParam;
22
import org.springframework.web.bind.annotation.RestController;
23
24
import javax.validation.Valid;
25
26
@Api(description = "Restaurants")
27
@RequestMapping("/api/restaurants")
28
@RestController
29
@Slf4j
30
public class RestaurantsController extends ApiController {
31
32
    @Autowired
33
    RestaurantRepository restaurantRepository;
34
35
    @ApiOperation(value = "List all restaurants")
36
    @PreAuthorize("hasRole('ROLE_USER')")
37
    @GetMapping("/all")
38
    public Iterable<Restaurant> allRestaurants() {
39
        Iterable<Restaurant> restaurants = restaurantRepository.findAll();
40 1 1. allRestaurants : replaced return value with null for edu/ucsb/cs156/example/controllers/RestaurantsController::allRestaurants → KILLED
        return restaurants;
41
    }
42
43
    @ApiOperation(value = "Get a single restaurant")
44
    @PreAuthorize("hasRole('ROLE_USER')")
45
    @GetMapping("")
46
    public Restaurant getById(
47
            @ApiParam("id") @RequestParam Long id) {
48
        Restaurant restaurant = restaurantRepository.findById(id)
49 1 1. lambda$getById$0 : replaced return value with null for edu/ucsb/cs156/example/controllers/RestaurantsController::lambda$getById$0 → KILLED
                .orElseThrow(() -> new EntityNotFoundException(Restaurant.class, id));
50
51 1 1. getById : replaced return value with null for edu/ucsb/cs156/example/controllers/RestaurantsController::getById → KILLED
        return restaurant;
52
    }
53
54
    @ApiOperation(value = "Create a new restaurant")
55
    @PreAuthorize("hasRole('ROLE_ADMIN')")
56
    @PostMapping("/post")
57
    public Restaurant postRestaurant(
58
            @ApiParam("name") @RequestParam String name,
59
            @ApiParam("cuisine") @RequestParam String cuisine,
60
            @ApiParam("roachCounter") @RequestParam int roachCounter)
61
            throws JsonProcessingException {
62
63
        Restaurant restaurant = new Restaurant();
64 1 1. postRestaurant : removed call to edu/ucsb/cs156/example/entities/Restaurant::setName → KILLED
        restaurant.setName(name);
65 1 1. postRestaurant : removed call to edu/ucsb/cs156/example/entities/Restaurant::setCuisine → KILLED
        restaurant.setCuisine(cuisine);
66 1 1. postRestaurant : removed call to edu/ucsb/cs156/example/entities/Restaurant::setRoachCounter → KILLED
        restaurant.setRoachCounter(roachCounter);
67
68
        Restaurant savedRestaurant = restaurantRepository.save(restaurant);
69
70 1 1. postRestaurant : replaced return value with null for edu/ucsb/cs156/example/controllers/RestaurantsController::postRestaurant → KILLED
        return savedRestaurant;
71
    }
72
73
    @ApiOperation(value = "Delete a Restaurant")
74
    @PreAuthorize("hasRole('ROLE_ADMIN')")
75
    @DeleteMapping("")
76
    public Object deleteRestaurant(
77
            @ApiParam("id") @RequestParam Long id) {
78
        Restaurant restaurant = restaurantRepository.findById(id)
79 1 1. lambda$deleteRestaurant$1 : replaced return value with null for edu/ucsb/cs156/example/controllers/RestaurantsController::lambda$deleteRestaurant$1 → KILLED
                .orElseThrow(() -> new EntityNotFoundException(Restaurant.class, id));
80
81 1 1. deleteRestaurant : removed call to edu/ucsb/cs156/example/repositories/RestaurantRepository::delete → KILLED
        restaurantRepository.delete(restaurant);
82 1 1. deleteRestaurant : replaced return value with null for edu/ucsb/cs156/example/controllers/RestaurantsController::deleteRestaurant → KILLED
        return genericMessage("Restaurant with id %s deleted".formatted(id));
83
    }
84
85
    @ApiOperation(value = "Update a single restaurant")
86
    @PreAuthorize("hasRole('ROLE_ADMIN')")
87
    @PutMapping("")
88
    public Restaurant updateRestaurant(
89
            @ApiParam("id") @RequestParam Long id,
90
            @RequestBody @Valid Restaurant incoming) {
91
92
        Restaurant restaurant = restaurantRepository.findById(id)
93 1 1. lambda$updateRestaurant$2 : replaced return value with null for edu/ucsb/cs156/example/controllers/RestaurantsController::lambda$updateRestaurant$2 → KILLED
                .orElseThrow(() -> new EntityNotFoundException(Restaurant.class, id));
94
95
        
96 1 1. updateRestaurant : removed call to edu/ucsb/cs156/example/entities/Restaurant::setName → KILLED
        restaurant.setName(incoming.getName());
97 1 1. updateRestaurant : removed call to edu/ucsb/cs156/example/entities/Restaurant::setCuisine → KILLED
        restaurant.setCuisine(incoming.getCuisine());
98 1 1. updateRestaurant : removed call to edu/ucsb/cs156/example/entities/Restaurant::setRoachCounter → KILLED
        restaurant.setRoachCounter(incoming.getRoachCounter());
99
100
        restaurantRepository.save(restaurant);
101
102 1 1. updateRestaurant : replaced return value with null for edu/ucsb/cs156/example/controllers/RestaurantsController::updateRestaurant → KILLED
        return restaurant;
103
    }
104
}

Mutations

40

1.1
Location : allRestaurants
Killed by : edu.ucsb.cs156.example.controllers.RestaurantsControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.RestaurantsControllerTests]/[method:logged_in_user_can_get_all_restaurants()]
replaced return value with null for edu/ucsb/cs156/example/controllers/RestaurantsController::allRestaurants → KILLED

49

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

51

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

64

1.1
Location : postRestaurant
Killed by : edu.ucsb.cs156.example.controllers.RestaurantsControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.RestaurantsControllerTests]/[method:an_admin_user_can_post_a_new_restaurant()]
removed call to edu/ucsb/cs156/example/entities/Restaurant::setName → KILLED

65

1.1
Location : postRestaurant
Killed by : edu.ucsb.cs156.example.controllers.RestaurantsControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.RestaurantsControllerTests]/[method:an_admin_user_can_post_a_new_restaurant()]
removed call to edu/ucsb/cs156/example/entities/Restaurant::setCuisine → KILLED

66

1.1
Location : postRestaurant
Killed by : edu.ucsb.cs156.example.controllers.RestaurantsControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.RestaurantsControllerTests]/[method:an_admin_user_can_post_a_new_restaurant()]
removed call to edu/ucsb/cs156/example/entities/Restaurant::setRoachCounter → KILLED

70

1.1
Location : postRestaurant
Killed by : edu.ucsb.cs156.example.controllers.RestaurantsControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.RestaurantsControllerTests]/[method:an_admin_user_can_post_a_new_restaurant()]
replaced return value with null for edu/ucsb/cs156/example/controllers/RestaurantsController::postRestaurant → KILLED

79

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

81

1.1
Location : deleteRestaurant
Killed by : edu.ucsb.cs156.example.controllers.RestaurantsControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.RestaurantsControllerTests]/[method:admin_can_delete_a_restaurant()]
removed call to edu/ucsb/cs156/example/repositories/RestaurantRepository::delete → KILLED

82

1.1
Location : deleteRestaurant
Killed by : edu.ucsb.cs156.example.controllers.RestaurantsControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.RestaurantsControllerTests]/[method:admin_can_delete_a_restaurant()]
replaced return value with null for edu/ucsb/cs156/example/controllers/RestaurantsController::deleteRestaurant → KILLED

93

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

96

1.1
Location : updateRestaurant
Killed by : edu.ucsb.cs156.example.controllers.RestaurantsControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.RestaurantsControllerTests]/[method:admin_can_edit_an_existing_restaurant()]
removed call to edu/ucsb/cs156/example/entities/Restaurant::setName → KILLED

97

1.1
Location : updateRestaurant
Killed by : edu.ucsb.cs156.example.controllers.RestaurantsControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.RestaurantsControllerTests]/[method:admin_can_edit_an_existing_restaurant()]
removed call to edu/ucsb/cs156/example/entities/Restaurant::setCuisine → KILLED

98

1.1
Location : updateRestaurant
Killed by : edu.ucsb.cs156.example.controllers.RestaurantsControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.RestaurantsControllerTests]/[method:admin_can_edit_an_existing_restaurant()]
removed call to edu/ucsb/cs156/example/entities/Restaurant::setRoachCounter → KILLED

102

1.1
Location : updateRestaurant
Killed by : edu.ucsb.cs156.example.controllers.RestaurantsControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.RestaurantsControllerTests]/[method:admin_can_edit_an_existing_restaurant()]
replaced return value with null for edu/ucsb/cs156/example/controllers/RestaurantsController::updateRestaurant → KILLED

Active mutators

Tests examined


Report generated by PIT 1.7.3