CartController.java

1
package edu.ucsb.cs156.gauchoride.controllers;
2
3
import com.fasterxml.jackson.core.JsonProcessingException;
4
5
import edu.ucsb.cs156.gauchoride.entities.Cart;
6
import edu.ucsb.cs156.gauchoride.repositories.CartRepository;
7
8
import edu.ucsb.cs156.gauchoride.errors.EntityNotFoundException;
9
10
11
import org.springframework.beans.factory.annotation.Autowired;
12
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
19
import org.springframework.web.bind.annotation.RequestMapping;
20
import org.springframework.web.bind.annotation.RequestBody;
21
import org.springframework.web.bind.annotation.RequestParam;
22
import org.springframework.web.bind.annotation.RestController;
23
24
import io.swagger.annotations.Api;
25
import io.swagger.annotations.ApiOperation;
26
import io.swagger.annotations.ApiParam;
27
import javax.validation.Valid;
28
29
30
@Api(description = "Cart")
31
@RequestMapping("/api/carts")
32
@RestController
33
34
public class CartController extends ApiController {
35
36
    @Autowired
37
    CartRepository cartRepository;
38
39
    @ApiOperation(value = "List all carts")
40
    @PreAuthorize("hasRole('ROLE_ADMIN') || hasRole('ROLE_DRIVER')")
41
    @GetMapping("/all")
42
    public Iterable<Cart> allCart() {
43
        Iterable<Cart> carts = cartRepository.findAll();
44 1 1. allCart : replaced return value with null for edu/ucsb/cs156/gauchoride/controllers/CartController::allCart → KILLED
        return carts;
45
    }
46
47
    @ApiOperation(value = "Get a single cart")
48
    @PreAuthorize("hasRole('ROLE_ADMIN') || hasRole('ROLE_DRIVER')")
49
    @GetMapping("")
50
    public Cart getById(
51
            @ApiParam("id") @RequestParam Long id) {
52
        Cart cart = cartRepository.findById(id)
53 1 1. lambda$getById$0 : replaced return value with null for edu/ucsb/cs156/gauchoride/controllers/CartController::lambda$getById$0 → KILLED
                .orElseThrow(() -> new EntityNotFoundException(Cart.class, id));
54
55 1 1. getById : replaced return value with null for edu/ucsb/cs156/gauchoride/controllers/CartController::getById → KILLED
        return cart;
56
    }
57
58
    
59
    @ApiOperation(value = "Create a new cart")
60
    @PreAuthorize("hasRole('ROLE_ADMIN')")
61
    @PostMapping("/post")
62
    public Cart postCart(
63
        @ApiParam(name = "name", type = "String", value = "name of the cart", example = "Cart1", required = true) 
64
        @RequestParam String name,
65
        @ApiParam(name = "capacityPeople", type = "Int", value = "Capacity of the Cart to fit People (e.g. 2 for 2 people)", example = "2", required = true ) 
66
        @RequestParam int capacityPeople, 
67
        @ApiParam(name = "capacityWheelchair", type = "Int", value = "Capacity of the Cart to fit Wheelchairs (e.g. 1 for 1 wheelchair)", example = "1", required = true )
68
        @RequestParam int capacityWheelchair
69
    ) throws JsonProcessingException {
70
        
71
        Cart cart = new Cart();
72 1 1. postCart : removed call to edu/ucsb/cs156/gauchoride/entities/Cart::setName → KILLED
        cart.setName(name);
73 1 1. postCart : removed call to edu/ucsb/cs156/gauchoride/entities/Cart::setCapacityPeople → KILLED
        cart.setCapacityPeople(capacityPeople);
74 1 1. postCart : removed call to edu/ucsb/cs156/gauchoride/entities/Cart::setCapacityWheelchair → KILLED
        cart.setCapacityWheelchair(capacityWheelchair);
75
76
        Cart savedCart = cartRepository.save(cart);
77 1 1. postCart : replaced return value with null for edu/ucsb/cs156/gauchoride/controllers/CartController::postCart → KILLED
        return savedCart;
78
    }
79
80
    @ApiOperation(value = "Delete a Cart")
81
    @PreAuthorize("hasRole('ROLE_ADMIN')")
82
    @DeleteMapping("")
83
    public Object deleteCart(
84
            @ApiParam(name = "id", type = "Long", value = "ID value of Cart wanting to be deleted (e.g. 4 for cart with ID of 4)", example = "4", required = true ) 
85
            @RequestParam Long id) {
86
        Cart cart = cartRepository.findById(id)
87 1 1. lambda$deleteCart$1 : replaced return value with null for edu/ucsb/cs156/gauchoride/controllers/CartController::lambda$deleteCart$1 → KILLED
                .orElseThrow(() -> new EntityNotFoundException(Cart.class, id));
88
89 1 1. deleteCart : removed call to edu/ucsb/cs156/gauchoride/repositories/CartRepository::delete → KILLED
        cartRepository.delete(cart);
90 1 1. deleteCart : replaced return value with null for edu/ucsb/cs156/gauchoride/controllers/CartController::deleteCart → KILLED
        return genericMessage("Cart with id %s deleted".formatted(id));
91
    }
92
93
    @ApiOperation(value = "Update a single cart")
94
    @PreAuthorize("hasRole('ROLE_ADMIN')")
95
    @PutMapping("")
96
    public Cart updateCart(
97
            @ApiParam(name = "id", type = "Long", value = "ID value of Cart wanting to be updated (e.g. 4 for cart with ID of 4)", example = "4", required = true )  
98
            @RequestParam Long id,
99
            @RequestBody @Valid Cart incoming) {
100
101
        Cart cart = cartRepository.findById(id)
102 1 1. lambda$updateCart$2 : replaced return value with null for edu/ucsb/cs156/gauchoride/controllers/CartController::lambda$updateCart$2 → KILLED
                .orElseThrow(() -> new EntityNotFoundException(Cart.class, id));
103
104 1 1. updateCart : removed call to edu/ucsb/cs156/gauchoride/entities/Cart::setName → KILLED
        cart.setName(incoming.getName());
105 1 1. updateCart : removed call to edu/ucsb/cs156/gauchoride/entities/Cart::setCapacityPeople → KILLED
        cart.setCapacityPeople(incoming.getCapacityPeople());
106 1 1. updateCart : removed call to edu/ucsb/cs156/gauchoride/entities/Cart::setCapacityWheelchair → KILLED
        cart.setCapacityWheelchair(incoming.getCapacityWheelchair());
107
108
        cartRepository.save(cart);
109
110 1 1. updateCart : replaced return value with null for edu/ucsb/cs156/gauchoride/controllers/CartController::updateCart → KILLED
        return cart;
111
    }
112
}

Mutations

44

1.1
Location : allCart
Killed by : edu.ucsb.cs156.gauchoride.controllers.CartControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.gauchoride.controllers.CartControllerTests]/[method:logged_in_user_can_get_all_cart()]
replaced return value with null for edu/ucsb/cs156/gauchoride/controllers/CartController::allCart → KILLED

53

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

55

1.1
Location : getById
Killed by : edu.ucsb.cs156.gauchoride.controllers.CartControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.gauchoride.controllers.CartControllerTests]/[method:test_that_logged_in_user_can_get_by_id_when_the_id_exists()]
replaced return value with null for edu/ucsb/cs156/gauchoride/controllers/CartController::getById → KILLED

72

1.1
Location : postCart
Killed by : edu.ucsb.cs156.gauchoride.controllers.CartControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.gauchoride.controllers.CartControllerTests]/[method:an_admin_user_can_post_a_new_cart()]
removed call to edu/ucsb/cs156/gauchoride/entities/Cart::setName → KILLED

73

1.1
Location : postCart
Killed by : edu.ucsb.cs156.gauchoride.controllers.CartControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.gauchoride.controllers.CartControllerTests]/[method:an_admin_user_can_post_a_new_cart()]
removed call to edu/ucsb/cs156/gauchoride/entities/Cart::setCapacityPeople → KILLED

74

1.1
Location : postCart
Killed by : edu.ucsb.cs156.gauchoride.controllers.CartControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.gauchoride.controllers.CartControllerTests]/[method:an_admin_user_can_post_a_new_cart()]
removed call to edu/ucsb/cs156/gauchoride/entities/Cart::setCapacityWheelchair → KILLED

77

1.1
Location : postCart
Killed by : edu.ucsb.cs156.gauchoride.controllers.CartControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.gauchoride.controllers.CartControllerTests]/[method:an_admin_user_can_post_a_new_cart()]
replaced return value with null for edu/ucsb/cs156/gauchoride/controllers/CartController::postCart → KILLED

87

1.1
Location : lambda$deleteCart$1
Killed by : edu.ucsb.cs156.gauchoride.controllers.CartControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.gauchoride.controllers.CartControllerTests]/[method:admin_tries_to_delete_non_existant_cart_and_gets_right_error_message()]
replaced return value with null for edu/ucsb/cs156/gauchoride/controllers/CartController::lambda$deleteCart$1 → KILLED

89

1.1
Location : deleteCart
Killed by : edu.ucsb.cs156.gauchoride.controllers.CartControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.gauchoride.controllers.CartControllerTests]/[method:admin_can_delete_a_cart()]
removed call to edu/ucsb/cs156/gauchoride/repositories/CartRepository::delete → KILLED

90

1.1
Location : deleteCart
Killed by : edu.ucsb.cs156.gauchoride.controllers.CartControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.gauchoride.controllers.CartControllerTests]/[method:admin_can_delete_a_cart()]
replaced return value with null for edu/ucsb/cs156/gauchoride/controllers/CartController::deleteCart → KILLED

102

1.1
Location : lambda$updateCart$2
Killed by : edu.ucsb.cs156.gauchoride.controllers.CartControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.gauchoride.controllers.CartControllerTests]/[method:admin_cannot_edit_cart_that_does_not_exist()]
replaced return value with null for edu/ucsb/cs156/gauchoride/controllers/CartController::lambda$updateCart$2 → KILLED

104

1.1
Location : updateCart
Killed by : edu.ucsb.cs156.gauchoride.controllers.CartControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.gauchoride.controllers.CartControllerTests]/[method:admin_can_edit_an_existing_cart()]
removed call to edu/ucsb/cs156/gauchoride/entities/Cart::setName → KILLED

105

1.1
Location : updateCart
Killed by : edu.ucsb.cs156.gauchoride.controllers.CartControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.gauchoride.controllers.CartControllerTests]/[method:admin_can_edit_an_existing_cart()]
removed call to edu/ucsb/cs156/gauchoride/entities/Cart::setCapacityPeople → KILLED

106

1.1
Location : updateCart
Killed by : edu.ucsb.cs156.gauchoride.controllers.CartControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.gauchoride.controllers.CartControllerTests]/[method:admin_can_edit_an_existing_cart()]
removed call to edu/ucsb/cs156/gauchoride/entities/Cart::setCapacityWheelchair → KILLED

110

1.1
Location : updateCart
Killed by : edu.ucsb.cs156.gauchoride.controllers.CartControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.gauchoride.controllers.CartControllerTests]/[method:admin_can_edit_an_existing_cart()]
replaced return value with null for edu/ucsb/cs156/gauchoride/controllers/CartController::updateCart → KILLED

Active mutators

Tests examined


Report generated by PIT 1.7.3