UCSBDiningCommonsController.java

1
package edu.ucsb.cs156.example.controllers;
2
3
import edu.ucsb.cs156.example.entities.UCSBDiningCommons;
4
import edu.ucsb.cs156.example.errors.EntityNotFoundException;
5
import edu.ucsb.cs156.example.repositories.UCSBDiningCommonsRepository;
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 = "UCSBDiningCommons")
26
@RequestMapping("/api/ucsbdiningcommons")
27
@RestController
28
@Slf4j
29
public class UCSBDiningCommonsController extends ApiController {
30
31
    @Autowired
32
    UCSBDiningCommonsRepository ucsbDiningCommonsRepository;
33
34
    @ApiOperation(value = "List all ucsb dining commons")
35
    @PreAuthorize("hasRole('ROLE_USER')")
36
    @GetMapping("/all")
37
    public Iterable<UCSBDiningCommons> allCommonss() {
38
        Iterable<UCSBDiningCommons> commons = ucsbDiningCommonsRepository.findAll();
39 1 1. allCommonss : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBDiningCommonsController::allCommonss → KILLED
        return commons;
40
    }
41
42
    @ApiOperation(value = "Get a single commons")
43
    @PreAuthorize("hasRole('ROLE_USER')")
44
    @GetMapping("")
45
    public UCSBDiningCommons getById(
46
            @ApiParam("code") @RequestParam String code) {
47
        UCSBDiningCommons commons = ucsbDiningCommonsRepository.findById(code)
48 1 1. lambda$getById$0 : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBDiningCommonsController::lambda$getById$0 → KILLED
                .orElseThrow(() -> new EntityNotFoundException(UCSBDiningCommons.class, code));
49
50 1 1. getById : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBDiningCommonsController::getById → KILLED
        return commons;
51
    }
52
53
    @ApiOperation(value = "Create a new commons")
54
    @PreAuthorize("hasRole('ROLE_ADMIN')")
55
    @PostMapping("/post")
56
    public UCSBDiningCommons postCommons(
57
        @ApiParam("code") @RequestParam String code,
58
        @ApiParam("name") @RequestParam String name,
59
        @ApiParam("hasSackMeal") @RequestParam boolean hasSackMeal,
60
        @ApiParam("hasTakeOutMeal") @RequestParam boolean hasTakeOutMeal,
61
        @ApiParam("hasDiningCam") @RequestParam boolean hasDiningCam,
62
        @ApiParam("latitude") @RequestParam double latitude,
63
        @ApiParam("longitude") @RequestParam double longitude
64
        )
65
        {
66
67
        UCSBDiningCommons commons = new UCSBDiningCommons();
68 1 1. postCommons : removed call to edu/ucsb/cs156/example/entities/UCSBDiningCommons::setCode → KILLED
        commons.setCode(code);
69 1 1. postCommons : removed call to edu/ucsb/cs156/example/entities/UCSBDiningCommons::setName → KILLED
        commons.setName(name);
70 1 1. postCommons : removed call to edu/ucsb/cs156/example/entities/UCSBDiningCommons::setHasSackMeal → KILLED
        commons.setHasSackMeal(hasSackMeal);
71 1 1. postCommons : removed call to edu/ucsb/cs156/example/entities/UCSBDiningCommons::setHasTakeOutMeal → KILLED
        commons.setHasTakeOutMeal(hasTakeOutMeal);
72 1 1. postCommons : removed call to edu/ucsb/cs156/example/entities/UCSBDiningCommons::setHasDiningCam → KILLED
        commons.setHasDiningCam(hasDiningCam);
73 1 1. postCommons : removed call to edu/ucsb/cs156/example/entities/UCSBDiningCommons::setLatitude → KILLED
        commons.setLatitude(latitude);
74 1 1. postCommons : removed call to edu/ucsb/cs156/example/entities/UCSBDiningCommons::setLongitude → KILLED
        commons.setLongitude(longitude);
75
76
        UCSBDiningCommons savedCommons = ucsbDiningCommonsRepository.save(commons);
77
78 1 1. postCommons : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBDiningCommonsController::postCommons → KILLED
        return savedCommons;
79
    }
80
81
    @ApiOperation(value = "Delete a UCSBDiningCommons")
82
    @PreAuthorize("hasRole('ROLE_ADMIN')")
83
    @DeleteMapping("")
84
    public Object deleteCommons(
85
            @ApiParam("code") @RequestParam String code) {
86
        UCSBDiningCommons commons = ucsbDiningCommonsRepository.findById(code)
87 1 1. lambda$deleteCommons$1 : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBDiningCommonsController::lambda$deleteCommons$1 → KILLED
                .orElseThrow(() -> new EntityNotFoundException(UCSBDiningCommons.class, code));
88
89 1 1. deleteCommons : removed call to edu/ucsb/cs156/example/repositories/UCSBDiningCommonsRepository::delete → KILLED
        ucsbDiningCommonsRepository.delete(commons);
90 1 1. deleteCommons : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBDiningCommonsController::deleteCommons → KILLED
        return genericMessage("UCSBDiningCommons with id %s deleted".formatted(code));
91
    }
92
93
    @ApiOperation(value = "Update a single commons")
94
    @PreAuthorize("hasRole('ROLE_ADMIN')")
95
    @PutMapping("")
96
    public UCSBDiningCommons updateCommons(
97
            @ApiParam("code") @RequestParam String code,
98
            @RequestBody @Valid UCSBDiningCommons incoming) {
99
100
        UCSBDiningCommons commons = ucsbDiningCommonsRepository.findById(code)
101 1 1. lambda$updateCommons$2 : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBDiningCommonsController::lambda$updateCommons$2 → KILLED
                .orElseThrow(() -> new EntityNotFoundException(UCSBDiningCommons.class, code));
102
103
104 1 1. updateCommons : removed call to edu/ucsb/cs156/example/entities/UCSBDiningCommons::setName → KILLED
        commons.setName(incoming.getName());  
105 1 1. updateCommons : removed call to edu/ucsb/cs156/example/entities/UCSBDiningCommons::setHasSackMeal → KILLED
        commons.setHasSackMeal(incoming.getHasSackMeal());
106 1 1. updateCommons : removed call to edu/ucsb/cs156/example/entities/UCSBDiningCommons::setHasTakeOutMeal → KILLED
        commons.setHasTakeOutMeal(incoming.getHasTakeOutMeal());
107 1 1. updateCommons : removed call to edu/ucsb/cs156/example/entities/UCSBDiningCommons::setHasDiningCam → KILLED
        commons.setHasDiningCam(incoming.getHasDiningCam());
108 1 1. updateCommons : removed call to edu/ucsb/cs156/example/entities/UCSBDiningCommons::setLatitude → KILLED
        commons.setLatitude(incoming.getLatitude());
109 1 1. updateCommons : removed call to edu/ucsb/cs156/example/entities/UCSBDiningCommons::setLongitude → KILLED
        commons.setLongitude(incoming.getLongitude());
110
111
        ucsbDiningCommonsRepository.save(commons);
112
113 1 1. updateCommons : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBDiningCommonsController::updateCommons → KILLED
        return commons;
114
    }
115
}

Mutations

39

1.1
Location : allCommonss
Killed by : edu.ucsb.cs156.example.controllers.UCSBDiningCommonsControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.UCSBDiningCommonsControllerTests]/[method:logged_in_user_can_get_all_ucsbdiningcommons()]
replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBDiningCommonsController::allCommonss → KILLED

48

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

50

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

68

1.1
Location : postCommons
Killed by : edu.ucsb.cs156.example.controllers.UCSBDiningCommonsControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.UCSBDiningCommonsControllerTests]/[method:an_admin_user_can_post_a_new_commons()]
removed call to edu/ucsb/cs156/example/entities/UCSBDiningCommons::setCode → KILLED

69

1.1
Location : postCommons
Killed by : edu.ucsb.cs156.example.controllers.UCSBDiningCommonsControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.UCSBDiningCommonsControllerTests]/[method:an_admin_user_can_post_a_new_commons()]
removed call to edu/ucsb/cs156/example/entities/UCSBDiningCommons::setName → KILLED

70

1.1
Location : postCommons
Killed by : edu.ucsb.cs156.example.controllers.UCSBDiningCommonsControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.UCSBDiningCommonsControllerTests]/[method:an_admin_user_can_post_a_new_commons()]
removed call to edu/ucsb/cs156/example/entities/UCSBDiningCommons::setHasSackMeal → KILLED

71

1.1
Location : postCommons
Killed by : edu.ucsb.cs156.example.controllers.UCSBDiningCommonsControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.UCSBDiningCommonsControllerTests]/[method:an_admin_user_can_post_a_new_commons()]
removed call to edu/ucsb/cs156/example/entities/UCSBDiningCommons::setHasTakeOutMeal → KILLED

72

1.1
Location : postCommons
Killed by : edu.ucsb.cs156.example.controllers.UCSBDiningCommonsControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.UCSBDiningCommonsControllerTests]/[method:an_admin_user_can_post_a_new_commons()]
removed call to edu/ucsb/cs156/example/entities/UCSBDiningCommons::setHasDiningCam → KILLED

73

1.1
Location : postCommons
Killed by : edu.ucsb.cs156.example.controllers.UCSBDiningCommonsControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.UCSBDiningCommonsControllerTests]/[method:an_admin_user_can_post_a_new_commons()]
removed call to edu/ucsb/cs156/example/entities/UCSBDiningCommons::setLatitude → KILLED

74

1.1
Location : postCommons
Killed by : edu.ucsb.cs156.example.controllers.UCSBDiningCommonsControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.UCSBDiningCommonsControllerTests]/[method:an_admin_user_can_post_a_new_commons()]
removed call to edu/ucsb/cs156/example/entities/UCSBDiningCommons::setLongitude → KILLED

78

1.1
Location : postCommons
Killed by : edu.ucsb.cs156.example.controllers.UCSBDiningCommonsControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.UCSBDiningCommonsControllerTests]/[method:an_admin_user_can_post_a_new_commons()]
replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBDiningCommonsController::postCommons → KILLED

87

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

89

1.1
Location : deleteCommons
Killed by : edu.ucsb.cs156.example.controllers.UCSBDiningCommonsControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.UCSBDiningCommonsControllerTests]/[method:admin_can_delete_a_date()]
removed call to edu/ucsb/cs156/example/repositories/UCSBDiningCommonsRepository::delete → KILLED

90

1.1
Location : deleteCommons
Killed by : edu.ucsb.cs156.example.controllers.UCSBDiningCommonsControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.UCSBDiningCommonsControllerTests]/[method:admin_can_delete_a_date()]
replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBDiningCommonsController::deleteCommons → KILLED

101

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

104

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

105

1.1
Location : updateCommons
Killed by : edu.ucsb.cs156.example.controllers.UCSBDiningCommonsControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.UCSBDiningCommonsControllerTests]/[method:admin_can_edit_an_existing_commons()]
removed call to edu/ucsb/cs156/example/entities/UCSBDiningCommons::setHasSackMeal → KILLED

106

1.1
Location : updateCommons
Killed by : edu.ucsb.cs156.example.controllers.UCSBDiningCommonsControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.UCSBDiningCommonsControllerTests]/[method:admin_can_edit_an_existing_commons()]
removed call to edu/ucsb/cs156/example/entities/UCSBDiningCommons::setHasTakeOutMeal → KILLED

107

1.1
Location : updateCommons
Killed by : edu.ucsb.cs156.example.controllers.UCSBDiningCommonsControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.UCSBDiningCommonsControllerTests]/[method:admin_can_edit_an_existing_commons()]
removed call to edu/ucsb/cs156/example/entities/UCSBDiningCommons::setHasDiningCam → KILLED

108

1.1
Location : updateCommons
Killed by : edu.ucsb.cs156.example.controllers.UCSBDiningCommonsControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.UCSBDiningCommonsControllerTests]/[method:admin_can_edit_an_existing_commons()]
removed call to edu/ucsb/cs156/example/entities/UCSBDiningCommons::setLatitude → KILLED

109

1.1
Location : updateCommons
Killed by : edu.ucsb.cs156.example.controllers.UCSBDiningCommonsControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.UCSBDiningCommonsControllerTests]/[method:admin_can_edit_an_existing_commons()]
removed call to edu/ucsb/cs156/example/entities/UCSBDiningCommons::setLongitude → KILLED

113

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

Active mutators

Tests examined


Report generated by PIT 1.7.3