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.RestaurantsRepository;
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 = "Restaurants")
26
@RequestMapping("/api/restaurants")
27
@RestController
28
@Slf4j
29
public class RestaurantsController extends ApiController {
30
31
    @Autowired
32
    RestaurantsRepository restaurantsRepository;
33
34
    @ApiOperation(value = "List all restaurants")
35
    @PreAuthorize("hasRole('ROLE_USER')")
36
    @GetMapping("/all")
37
    public Iterable<Restaurant> allRestaurants() {
38
        Iterable<Restaurant> restaurants = restaurantsRepository.findAll();
39 1 1. allRestaurants : replaced return value with null for edu/ucsb/cs156/example/controllers/RestaurantsController::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 restaurants = restaurantsRepository.findById(id)
48 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));
49
50 1 1. getById : replaced return value with null for edu/ucsb/cs156/example/controllers/RestaurantsController::getById → KILLED
        return restaurants;
51
    }
52
53
    @ApiOperation(value = "Create a new restaurant")
54
    @PreAuthorize("hasRole('ROLE_ADMIN')")
55
    @PostMapping("/post")
56
    public Restaurant postRestaurants(
57
        @ApiParam("name") @RequestParam String name,
58
        @ApiParam("specialty") @RequestParam String description,
59
        @ApiParam("address") @RequestParam String address
60
        )
61
        {
62
63
        Restaurant restaurants = new Restaurant();
64 1 1. postRestaurants : removed call to edu/ucsb/cs156/example/entities/Restaurant::setName → KILLED
        restaurants.setName(name);
65 1 1. postRestaurants : removed call to edu/ucsb/cs156/example/entities/Restaurant::setDescription → KILLED
        restaurants.setDescription(description);
66 1 1. postRestaurants : removed call to edu/ucsb/cs156/example/entities/Restaurant::setAddress → KILLED
        restaurants.setAddress(address);
67
        
68
69
        Restaurant savedRestaurants = restaurantsRepository.save(restaurants);
70
71 1 1. postRestaurants : replaced return value with null for edu/ucsb/cs156/example/controllers/RestaurantsController::postRestaurants → KILLED
        return savedRestaurants;
72
    }
73
74
    @ApiOperation(value = "Delete a Restaurant")
75
    @PreAuthorize("hasRole('ROLE_ADMIN')")
76
    @DeleteMapping("")
77
    public Object deleteRestaurants(
78
            @ApiParam("id") @RequestParam Long id) {
79
        Restaurant restaurants = restaurantsRepository.findById(id)
80 1 1. lambda$deleteRestaurants$1 : replaced return value with null for edu/ucsb/cs156/example/controllers/RestaurantsController::lambda$deleteRestaurants$1 → KILLED
                .orElseThrow(() -> new EntityNotFoundException(Restaurant.class, id));
81
82 1 1. deleteRestaurants : removed call to edu/ucsb/cs156/example/repositories/RestaurantsRepository::delete → KILLED
        restaurantsRepository.delete(restaurants);
83 1 1. deleteRestaurants : replaced return value with null for edu/ucsb/cs156/example/controllers/RestaurantsController::deleteRestaurants → KILLED
        return genericMessage("Restaurant with id %s deleted".formatted(id));
84
    }
85
86
    @ApiOperation(value = "Update a single restaurant")
87
    @PreAuthorize("hasRole('ROLE_ADMIN')")
88
    @PutMapping("")
89
    public Restaurant updateRestaurants(
90
            @ApiParam("id") @RequestParam Long id,
91
            @RequestBody @Valid Restaurant incoming) {
92
93
        Restaurant restaurants = restaurantsRepository.findById(id)
94 1 1. lambda$updateRestaurants$2 : replaced return value with null for edu/ucsb/cs156/example/controllers/RestaurantsController::lambda$updateRestaurants$2 → KILLED
                .orElseThrow(() -> new EntityNotFoundException(Restaurant.class, id));
95
96
97 1 1. updateRestaurants : removed call to edu/ucsb/cs156/example/entities/Restaurant::setName → KILLED
        restaurants.setName(incoming.getName());
98 1 1. updateRestaurants : removed call to edu/ucsb/cs156/example/entities/Restaurant::setDescription → KILLED
        restaurants.setDescription(incoming.getDescription());
99 1 1. updateRestaurants : removed call to edu/ucsb/cs156/example/entities/Restaurant::setAddress → KILLED
        restaurants.setAddress(incoming.getAddress());
100
101
        restaurantsRepository.save(restaurants);
102
103 1 1. updateRestaurants : replaced return value with null for edu/ucsb/cs156/example/controllers/RestaurantsController::updateRestaurants → KILLED
        return restaurants;
104
    }
105
}

Mutations

39

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

48

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

50

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 : postRestaurants
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 : postRestaurants
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::setDescription → KILLED

66

1.1
Location : postRestaurants
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::setAddress → KILLED

71

1.1
Location : postRestaurants
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::postRestaurants → KILLED

80

1.1
Location : lambda$deleteRestaurants$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$deleteRestaurants$1 → KILLED

82

1.1
Location : deleteRestaurants
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/RestaurantsRepository::delete → KILLED

83

1.1
Location : deleteRestaurants
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::deleteRestaurants → KILLED

94

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

97

1.1
Location : updateRestaurants
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

98

1.1
Location : updateRestaurants
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::setDescription → KILLED

99

1.1
Location : updateRestaurants
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::setAddress → KILLED

103

1.1
Location : updateRestaurants
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::updateRestaurants → KILLED

Active mutators

Tests examined


Report generated by PIT 1.7.3