IceCreamShopController.java

1
package edu.ucsb.cs156.example.controllers;
2
3
import edu.ucsb.cs156.example.entities.IceCreamShop;
4
import edu.ucsb.cs156.example.errors.EntityNotFoundException;
5
import edu.ucsb.cs156.example.repositories.IceCreamShopRepository;
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 = "IceCreamShop")
26
@RequestMapping("/api/icecreamshop")
27
@RestController
28
@Slf4j
29
public class IceCreamShopController extends ApiController {
30
31
    @Autowired
32
    IceCreamShopRepository iceCreamShopRepository;
33
34
    @ApiOperation(value = "List all ice cream shops")
35
    @PreAuthorize("hasRole('ROLE_USER')")
36
    @GetMapping("/all")
37
    public Iterable<IceCreamShop> allIceCreamShop() {
38
        Iterable<IceCreamShop> iceCreamShop = iceCreamShopRepository.findAll();
39 1 1. allIceCreamShop : replaced return value with null for edu/ucsb/cs156/example/controllers/IceCreamShopController::allIceCreamShop → KILLED
        return iceCreamShop;
40
    }
41
42
    @ApiOperation(value = "Get a single iceCreamShop")
43
    @PreAuthorize("hasRole('ROLE_USER')")
44
    @GetMapping("")
45
    public IceCreamShop getById(
46
            @ApiParam("id") @RequestParam Long id) {
47
        IceCreamShop iceCreamShop = iceCreamShopRepository.findById(id)
48 1 1. lambda$getById$0 : replaced return value with null for edu/ucsb/cs156/example/controllers/IceCreamShopController::lambda$getById$0 → KILLED
                .orElseThrow(() -> new EntityNotFoundException(IceCreamShop.class, id));
49
50 1 1. getById : replaced return value with null for edu/ucsb/cs156/example/controllers/IceCreamShopController::getById → KILLED
        return iceCreamShop;
51
    }
52
53
    @ApiOperation(value = "Create a new iceCreamShop")
54
    @PreAuthorize("hasRole('ROLE_ADMIN')")
55
    @PostMapping("/post")
56
    public IceCreamShop postIceCreamShop(
57
        @ApiParam("name") @RequestParam String name,
58
        @ApiParam("flavor") @RequestParam String flavor,
59
        @ApiParam("description") @RequestParam String description
60
        )
61
        {
62
63
        IceCreamShop iceCreamShop = new IceCreamShop();
64 1 1. postIceCreamShop : removed call to edu/ucsb/cs156/example/entities/IceCreamShop::setName → KILLED
        iceCreamShop.setName(name);
65 1 1. postIceCreamShop : removed call to edu/ucsb/cs156/example/entities/IceCreamShop::setFlavor → KILLED
        iceCreamShop.setFlavor(flavor);
66 1 1. postIceCreamShop : removed call to edu/ucsb/cs156/example/entities/IceCreamShop::setDescription → KILLED
        iceCreamShop.setDescription(description);
67
68
        IceCreamShop savedIceCreamShop = iceCreamShopRepository.save(iceCreamShop);
69
70 1 1. postIceCreamShop : replaced return value with null for edu/ucsb/cs156/example/controllers/IceCreamShopController::postIceCreamShop → KILLED
        return savedIceCreamShop;
71
    }
72
73
    @ApiOperation(value = "Delete a IceCreamShop")
74
    @PreAuthorize("hasRole('ROLE_ADMIN')")
75
    @DeleteMapping("")
76
    public Object deleteIceCreamShop(
77
            @ApiParam("id") @RequestParam Long id) {
78
        IceCreamShop iceCreamShop = iceCreamShopRepository.findById(id)
79 1 1. lambda$deleteIceCreamShop$1 : replaced return value with null for edu/ucsb/cs156/example/controllers/IceCreamShopController::lambda$deleteIceCreamShop$1 → KILLED
                .orElseThrow(() -> new EntityNotFoundException(IceCreamShop.class, id));
80
81 1 1. deleteIceCreamShop : removed call to edu/ucsb/cs156/example/repositories/IceCreamShopRepository::delete → KILLED
        iceCreamShopRepository.delete(iceCreamShop);
82 1 1. deleteIceCreamShop : replaced return value with null for edu/ucsb/cs156/example/controllers/IceCreamShopController::deleteIceCreamShop → KILLED
        return genericMessage("IceCreamShop with id %s deleted".formatted(id));
83
    }
84
85
    @ApiOperation(value = "Update a single iceCreamShop")
86
    @PreAuthorize("hasRole('ROLE_ADMIN')")
87
    @PutMapping("")
88
    public IceCreamShop updateCommons(
89
            @ApiParam("id") @RequestParam Long id,
90
            @RequestBody @Valid IceCreamShop incoming) {
91
92
        IceCreamShop iceCreamShop = iceCreamShopRepository.findById(id)
93 1 1. lambda$updateCommons$2 : replaced return value with null for edu/ucsb/cs156/example/controllers/IceCreamShopController::lambda$updateCommons$2 → KILLED
                .orElseThrow(() -> new EntityNotFoundException(IceCreamShop.class, id));
94
95
96 1 1. updateCommons : removed call to edu/ucsb/cs156/example/entities/IceCreamShop::setName → KILLED
        iceCreamShop.setName(incoming.getName());  
97 1 1. updateCommons : removed call to edu/ucsb/cs156/example/entities/IceCreamShop::setFlavor → KILLED
        iceCreamShop.setFlavor(incoming.getFlavor());
98 1 1. updateCommons : removed call to edu/ucsb/cs156/example/entities/IceCreamShop::setDescription → KILLED
        iceCreamShop.setDescription(incoming.getDescription());
99
100
101
        iceCreamShopRepository.save(iceCreamShop);
102
103 1 1. updateCommons : replaced return value with null for edu/ucsb/cs156/example/controllers/IceCreamShopController::updateCommons → KILLED
        return iceCreamShop;
104
    }
105
}

Mutations

39

1.1
Location : allIceCreamShop
Killed by : edu.ucsb.cs156.example.controllers.IceCreamShopControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.IceCreamShopControllerTests]/[method:logged_in_user_can_get_all_icecreamshop()]
replaced return value with null for edu/ucsb/cs156/example/controllers/IceCreamShopController::allIceCreamShop → KILLED

48

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

50

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

64

1.1
Location : postIceCreamShop
Killed by : edu.ucsb.cs156.example.controllers.IceCreamShopControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.IceCreamShopControllerTests]/[method:an_admin_user_can_post_a_new_iceCreamShop()]
removed call to edu/ucsb/cs156/example/entities/IceCreamShop::setName → KILLED

65

1.1
Location : postIceCreamShop
Killed by : edu.ucsb.cs156.example.controllers.IceCreamShopControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.IceCreamShopControllerTests]/[method:an_admin_user_can_post_a_new_iceCreamShop()]
removed call to edu/ucsb/cs156/example/entities/IceCreamShop::setFlavor → KILLED

66

1.1
Location : postIceCreamShop
Killed by : edu.ucsb.cs156.example.controllers.IceCreamShopControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.IceCreamShopControllerTests]/[method:an_admin_user_can_post_a_new_iceCreamShop()]
removed call to edu/ucsb/cs156/example/entities/IceCreamShop::setDescription → KILLED

70

1.1
Location : postIceCreamShop
Killed by : edu.ucsb.cs156.example.controllers.IceCreamShopControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.IceCreamShopControllerTests]/[method:an_admin_user_can_post_a_new_iceCreamShop()]
replaced return value with null for edu/ucsb/cs156/example/controllers/IceCreamShopController::postIceCreamShop → KILLED

79

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

81

1.1
Location : deleteIceCreamShop
Killed by : edu.ucsb.cs156.example.controllers.IceCreamShopControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.IceCreamShopControllerTests]/[method:admin_can_delete_a_iceCreamShop()]
removed call to edu/ucsb/cs156/example/repositories/IceCreamShopRepository::delete → KILLED

82

1.1
Location : deleteIceCreamShop
Killed by : edu.ucsb.cs156.example.controllers.IceCreamShopControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.IceCreamShopControllerTests]/[method:admin_can_delete_a_iceCreamShop()]
replaced return value with null for edu/ucsb/cs156/example/controllers/IceCreamShopController::deleteIceCreamShop → KILLED

93

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

96

1.1
Location : updateCommons
Killed by : edu.ucsb.cs156.example.controllers.IceCreamShopControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.IceCreamShopControllerTests]/[method:admin_can_edit_an_existing_iceCreamShop()]
removed call to edu/ucsb/cs156/example/entities/IceCreamShop::setName → KILLED

97

1.1
Location : updateCommons
Killed by : edu.ucsb.cs156.example.controllers.IceCreamShopControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.IceCreamShopControllerTests]/[method:admin_can_edit_an_existing_iceCreamShop()]
removed call to edu/ucsb/cs156/example/entities/IceCreamShop::setFlavor → KILLED

98

1.1
Location : updateCommons
Killed by : edu.ucsb.cs156.example.controllers.IceCreamShopControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.IceCreamShopControllerTests]/[method:admin_can_edit_an_existing_iceCreamShop()]
removed call to edu/ucsb/cs156/example/entities/IceCreamShop::setDescription → KILLED

103

1.1
Location : updateCommons
Killed by : edu.ucsb.cs156.example.controllers.IceCreamShopControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.IceCreamShopControllerTests]/[method:admin_can_edit_an_existing_iceCreamShop()]
replaced return value with null for edu/ucsb/cs156/example/controllers/IceCreamShopController::updateCommons → KILLED

Active mutators

Tests examined


Report generated by PIT 1.7.3