SchoolsController.java

1
package edu.ucsb.cs156.example.controllers;
2
3
import edu.ucsb.cs156.example.entities.Schools;
4
import edu.ucsb.cs156.example.errors.EntityNotFoundException;
5
import edu.ucsb.cs156.example.repositories.SchoolsRepository;
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 com.fasterxml.jackson.core.JsonProcessingException;
12
13
import org.springframework.beans.factory.annotation.Autowired;
14
import org.springframework.security.access.prepost.PreAuthorize;
15
import org.springframework.web.bind.annotation.DeleteMapping;
16
import org.springframework.web.bind.annotation.GetMapping;
17
import org.springframework.web.bind.annotation.PostMapping;
18
import org.springframework.web.bind.annotation.PutMapping;
19
import org.springframework.web.bind.annotation.RequestBody;
20
import org.springframework.web.bind.annotation.RequestMapping;
21
import org.springframework.web.bind.annotation.RequestParam;
22
import org.springframework.web.bind.annotation.RestController;
23
24
import javax.validation.Valid;
25
26
27
@Api(description = "Schools")
28
@RequestMapping("/api/schools")
29
@RestController
30
@Slf4j
31
public class SchoolsController extends ApiController {
32
33
    @Autowired
34
    SchoolsRepository schoolsRepository;
35
36
    @ApiOperation(value = "List all schools")
37
    @PreAuthorize("hasRole('ROLE_USER')")
38
    @GetMapping("/all")
39
    public Iterable<Schools> allSchools() {
40
        Iterable<Schools> schools = schoolsRepository.findAll();
41 1 1. allSchools : replaced return value with null for edu/ucsb/cs156/example/controllers/SchoolsController::allSchools → KILLED
        return schools;
42
    }
43
44
    @ApiOperation(value = "Get a single school")
45
    @PreAuthorize("hasRole('ROLE_USER')")
46
    @GetMapping("")
47
    public Schools getById(
48
            @ApiParam("id") @RequestParam Long id) {
49
        Schools school = schoolsRepository.findById(id)
50 1 1. lambda$getById$0 : replaced return value with null for edu/ucsb/cs156/example/controllers/SchoolsController::lambda$getById$0 → KILLED
                .orElseThrow(() -> new EntityNotFoundException(Schools.class, id));
51
52 1 1. getById : replaced return value with null for edu/ucsb/cs156/example/controllers/SchoolsController::getById → KILLED
        return school;
53
    }
54
55
    @ApiOperation(value = "Create a new school")
56
    @PreAuthorize("hasRole('ROLE_ADMIN')")
57
    @PostMapping("/post")
58
    public Schools postSchool(
59
            @ApiParam("name") @RequestParam String name,
60
            @ApiParam("district") @RequestParam String district,
61
            @ApiParam("grade range") @RequestParam String gradeRange)
62
            throws JsonProcessingException {
63
64
65
        Schools school = new Schools();
66 1 1. postSchool : removed call to edu/ucsb/cs156/example/entities/Schools::setName → KILLED
        school.setName(name);
67 1 1. postSchool : removed call to edu/ucsb/cs156/example/entities/Schools::setDistrict → KILLED
        school.setDistrict(district);
68 1 1. postSchool : removed call to edu/ucsb/cs156/example/entities/Schools::setGradeRange → KILLED
        school.setGradeRange(gradeRange);
69
70
        Schools savedSchools = schoolsRepository.save(school);
71
72 1 1. postSchool : replaced return value with null for edu/ucsb/cs156/example/controllers/SchoolsController::postSchool → KILLED
        return savedSchools;
73
    }
74
75
    @ApiOperation(value = "Delete a School")
76
    @PreAuthorize("hasRole('ROLE_ADMIN')")
77
    @DeleteMapping("")
78
    public Object deleteSchool(
79
            @ApiParam("id") @RequestParam Long id) {
80
        Schools school = schoolsRepository.findById(id)
81 1 1. lambda$deleteSchool$1 : replaced return value with null for edu/ucsb/cs156/example/controllers/SchoolsController::lambda$deleteSchool$1 → KILLED
                .orElseThrow(() -> new EntityNotFoundException(Schools.class, id));
82
83 1 1. deleteSchool : removed call to edu/ucsb/cs156/example/repositories/SchoolsRepository::delete → KILLED
        schoolsRepository.delete(school);
84 1 1. deleteSchool : replaced return value with null for edu/ucsb/cs156/example/controllers/SchoolsController::deleteSchool → KILLED
        return genericMessage("School with id %s deleted".formatted(id));
85
    }
86
87
    @ApiOperation(value = "Update a single school")
88
    @PreAuthorize("hasRole('ROLE_ADMIN')")
89
    @PutMapping("")
90
    public Schools updateSchool(
91
            @ApiParam("id") @RequestParam Long id,
92
            @RequestBody @Valid Schools incoming) {
93
94
        Schools school = schoolsRepository.findById(id)
95 1 1. lambda$updateSchool$2 : replaced return value with null for edu/ucsb/cs156/example/controllers/SchoolsController::lambda$updateSchool$2 → KILLED
                .orElseThrow(() -> new EntityNotFoundException(Schools.class, id));
96
97 1 1. updateSchool : removed call to edu/ucsb/cs156/example/entities/Schools::setName → KILLED
        school.setName(incoming.getName());
98 1 1. updateSchool : removed call to edu/ucsb/cs156/example/entities/Schools::setDistrict → KILLED
        school.setDistrict(incoming.getDistrict());
99 1 1. updateSchool : removed call to edu/ucsb/cs156/example/entities/Schools::setGradeRange → KILLED
        school.setGradeRange(incoming.getGradeRange());
100
101
        schoolsRepository.save(school);
102
103 1 1. updateSchool : replaced return value with null for edu/ucsb/cs156/example/controllers/SchoolsController::updateSchool → KILLED
        return school;
104
    }
105
}

Mutations

41

1.1
Location : allSchools
Killed by : edu.ucsb.cs156.example.controllers.SchoolsControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.SchoolsControllerTests]/[method:logged_in_user_can_get_all_schools()]
replaced return value with null for edu/ucsb/cs156/example/controllers/SchoolsController::allSchools → KILLED

50

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

52

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

66

1.1
Location : postSchool
Killed by : edu.ucsb.cs156.example.controllers.SchoolsControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.SchoolsControllerTests]/[method:an_admin_user_can_post_a_new_school()]
removed call to edu/ucsb/cs156/example/entities/Schools::setName → KILLED

67

1.1
Location : postSchool
Killed by : edu.ucsb.cs156.example.controllers.SchoolsControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.SchoolsControllerTests]/[method:an_admin_user_can_post_a_new_school()]
removed call to edu/ucsb/cs156/example/entities/Schools::setDistrict → KILLED

68

1.1
Location : postSchool
Killed by : edu.ucsb.cs156.example.controllers.SchoolsControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.SchoolsControllerTests]/[method:an_admin_user_can_post_a_new_school()]
removed call to edu/ucsb/cs156/example/entities/Schools::setGradeRange → KILLED

72

1.1
Location : postSchool
Killed by : edu.ucsb.cs156.example.controllers.SchoolsControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.SchoolsControllerTests]/[method:an_admin_user_can_post_a_new_school()]
replaced return value with null for edu/ucsb/cs156/example/controllers/SchoolsController::postSchool → KILLED

81

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

83

1.1
Location : deleteSchool
Killed by : edu.ucsb.cs156.example.controllers.SchoolsControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.SchoolsControllerTests]/[method:admin_can_delete_a_school()]
removed call to edu/ucsb/cs156/example/repositories/SchoolsRepository::delete → KILLED

84

1.1
Location : deleteSchool
Killed by : edu.ucsb.cs156.example.controllers.SchoolsControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.SchoolsControllerTests]/[method:admin_can_delete_a_school()]
replaced return value with null for edu/ucsb/cs156/example/controllers/SchoolsController::deleteSchool → KILLED

95

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

97

1.1
Location : updateSchool
Killed by : edu.ucsb.cs156.example.controllers.SchoolsControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.SchoolsControllerTests]/[method:admin_can_edit_an_existing_school()]
removed call to edu/ucsb/cs156/example/entities/Schools::setName → KILLED

98

1.1
Location : updateSchool
Killed by : edu.ucsb.cs156.example.controllers.SchoolsControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.SchoolsControllerTests]/[method:admin_can_edit_an_existing_school()]
removed call to edu/ucsb/cs156/example/entities/Schools::setDistrict → KILLED

99

1.1
Location : updateSchool
Killed by : edu.ucsb.cs156.example.controllers.SchoolsControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.SchoolsControllerTests]/[method:admin_can_edit_an_existing_school()]
removed call to edu/ucsb/cs156/example/entities/Schools::setGradeRange → KILLED

103

1.1
Location : updateSchool
Killed by : edu.ucsb.cs156.example.controllers.SchoolsControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.SchoolsControllerTests]/[method:admin_can_edit_an_existing_school()]
replaced return value with null for edu/ucsb/cs156/example/controllers/SchoolsController::updateSchool → KILLED

Active mutators

Tests examined


Report generated by PIT 1.7.3