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

Mutations

39

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

48

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

50

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

67

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

68

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

69

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

70

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

71

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

72

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

76

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

85

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

87

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

88

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

99

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

101

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

102

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

103

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

104

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

105

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

106

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

110

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

Active mutators

Tests examined


Report generated by PIT 1.7.3