UCSBDatesController.java

1
package edu.ucsb.cs156.example.controllers;
2
3
import edu.ucsb.cs156.example.entities.UCSBDate;
4
import edu.ucsb.cs156.example.errors.EntityNotFoundException;
5
import edu.ucsb.cs156.example.repositories.UCSBDateRepository;
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.format.annotation.DateTimeFormat;
15
import org.springframework.security.access.prepost.PreAuthorize;
16
import org.springframework.web.bind.annotation.DeleteMapping;
17
import org.springframework.web.bind.annotation.GetMapping;
18
import org.springframework.web.bind.annotation.PostMapping;
19
import org.springframework.web.bind.annotation.PutMapping;
20
import org.springframework.web.bind.annotation.RequestBody;
21
import org.springframework.web.bind.annotation.RequestMapping;
22
import org.springframework.web.bind.annotation.RequestParam;
23
import org.springframework.web.bind.annotation.RestController;
24
25
import javax.validation.Valid;
26
27
import java.time.LocalDateTime;
28
29
@Api(description = "UCSBDates")
30
@RequestMapping("/api/ucsbdates")
31
@RestController
32
@Slf4j
33
public class UCSBDatesController extends ApiController {
34
35
    @Autowired
36
    UCSBDateRepository ucsbDateRepository;
37
38
    @ApiOperation(value = "List all ucsb dates")
39
    @PreAuthorize("hasRole('ROLE_USER')")
40
    @GetMapping("/all")
41
    public Iterable<UCSBDate> allUCSBDates() {
42
        Iterable<UCSBDate> dates = ucsbDateRepository.findAll();
43 1 1. allUCSBDates : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBDatesController::allUCSBDates → KILLED
        return dates;
44
    }
45
46
    @ApiOperation(value = "Get a single date")
47
    @PreAuthorize("hasRole('ROLE_USER')")
48
    @GetMapping("")
49
    public UCSBDate getById(
50
            @ApiParam("id") @RequestParam Long id) {
51
        UCSBDate ucsbDate = ucsbDateRepository.findById(id)
52 1 1. lambda$getById$0 : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBDatesController::lambda$getById$0 → KILLED
                .orElseThrow(() -> new EntityNotFoundException(UCSBDate.class, id));
53
54 1 1. getById : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBDatesController::getById → KILLED
        return ucsbDate;
55
    }
56
57
    @ApiOperation(value = "Create a new date")
58
    @PreAuthorize("hasRole('ROLE_ADMIN')")
59
    @PostMapping("/post")
60
    public UCSBDate postUCSBDate(
61
            @ApiParam("quarterYYYYQ") @RequestParam String quarterYYYYQ,
62
            @ApiParam("name") @RequestParam String name,
63
            @ApiParam("date (in iso format, e.g. YYYY-mm-ddTHH:MM:SS; see https://en.wikipedia.org/wiki/ISO_8601)") @RequestParam("localDateTime") @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) LocalDateTime localDateTime)
64
            throws JsonProcessingException {
65
66
        // For an explanation of @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME)
67
        // See: https://www.baeldung.com/spring-date-parameters
68
69
        log.info("localDateTime={}", localDateTime);
70
71
        UCSBDate ucsbDate = new UCSBDate();
72 1 1. postUCSBDate : removed call to edu/ucsb/cs156/example/entities/UCSBDate::setQuarterYYYYQ → KILLED
        ucsbDate.setQuarterYYYYQ(quarterYYYYQ);
73 1 1. postUCSBDate : removed call to edu/ucsb/cs156/example/entities/UCSBDate::setName → KILLED
        ucsbDate.setName(name);
74 1 1. postUCSBDate : removed call to edu/ucsb/cs156/example/entities/UCSBDate::setLocalDateTime → KILLED
        ucsbDate.setLocalDateTime(localDateTime);
75
76
        UCSBDate savedUcsbDate = ucsbDateRepository.save(ucsbDate);
77
78 1 1. postUCSBDate : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBDatesController::postUCSBDate → KILLED
        return savedUcsbDate;
79
    }
80
81
    @ApiOperation(value = "Delete a UCSBDate")
82
    @PreAuthorize("hasRole('ROLE_ADMIN')")
83
    @DeleteMapping("")
84
    public Object deleteUCSBDate(
85
            @ApiParam("id") @RequestParam Long id) {
86
        UCSBDate ucsbDate = ucsbDateRepository.findById(id)
87 1 1. lambda$deleteUCSBDate$1 : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBDatesController::lambda$deleteUCSBDate$1 → KILLED
                .orElseThrow(() -> new EntityNotFoundException(UCSBDate.class, id));
88
89 1 1. deleteUCSBDate : removed call to edu/ucsb/cs156/example/repositories/UCSBDateRepository::delete → KILLED
        ucsbDateRepository.delete(ucsbDate);
90 1 1. deleteUCSBDate : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBDatesController::deleteUCSBDate → KILLED
        return genericMessage("UCSBDate with id %s deleted".formatted(id));
91
    }
92
93
    @ApiOperation(value = "Update a single date")
94
    @PreAuthorize("hasRole('ROLE_ADMIN')")
95
    @PutMapping("")
96
    public UCSBDate updateUCSBDate(
97
            @ApiParam("id") @RequestParam Long id,
98
            @RequestBody @Valid UCSBDate incoming) {
99
100
        UCSBDate ucsbDate = ucsbDateRepository.findById(id)
101 1 1. lambda$updateUCSBDate$2 : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBDatesController::lambda$updateUCSBDate$2 → KILLED
                .orElseThrow(() -> new EntityNotFoundException(UCSBDate.class, id));
102
103 1 1. updateUCSBDate : removed call to edu/ucsb/cs156/example/entities/UCSBDate::setQuarterYYYYQ → KILLED
        ucsbDate.setQuarterYYYYQ(incoming.getQuarterYYYYQ());
104 1 1. updateUCSBDate : removed call to edu/ucsb/cs156/example/entities/UCSBDate::setName → KILLED
        ucsbDate.setName(incoming.getName());
105 1 1. updateUCSBDate : removed call to edu/ucsb/cs156/example/entities/UCSBDate::setLocalDateTime → KILLED
        ucsbDate.setLocalDateTime(incoming.getLocalDateTime());
106
107
        ucsbDateRepository.save(ucsbDate);
108
109 1 1. updateUCSBDate : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBDatesController::updateUCSBDate → KILLED
        return ucsbDate;
110
    }
111
}

Mutations

43

1.1
Location : allUCSBDates
Killed by : edu.ucsb.cs156.example.controllers.UCSBDatesControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.UCSBDatesControllerTests]/[method:logged_in_user_can_get_all_ucsbdates()]
replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBDatesController::allUCSBDates → KILLED

52

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

54

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

72

1.1
Location : postUCSBDate
Killed by : edu.ucsb.cs156.example.controllers.UCSBDatesControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.UCSBDatesControllerTests]/[method:an_admin_user_can_post_a_new_ucsbdate()]
removed call to edu/ucsb/cs156/example/entities/UCSBDate::setQuarterYYYYQ → KILLED

73

1.1
Location : postUCSBDate
Killed by : edu.ucsb.cs156.example.controllers.UCSBDatesControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.UCSBDatesControllerTests]/[method:an_admin_user_can_post_a_new_ucsbdate()]
removed call to edu/ucsb/cs156/example/entities/UCSBDate::setName → KILLED

74

1.1
Location : postUCSBDate
Killed by : edu.ucsb.cs156.example.controllers.UCSBDatesControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.UCSBDatesControllerTests]/[method:an_admin_user_can_post_a_new_ucsbdate()]
removed call to edu/ucsb/cs156/example/entities/UCSBDate::setLocalDateTime → KILLED

78

1.1
Location : postUCSBDate
Killed by : edu.ucsb.cs156.example.controllers.UCSBDatesControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.UCSBDatesControllerTests]/[method:an_admin_user_can_post_a_new_ucsbdate()]
replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBDatesController::postUCSBDate → KILLED

87

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

89

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

90

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

101

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

103

1.1
Location : updateUCSBDate
Killed by : edu.ucsb.cs156.example.controllers.UCSBDatesControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.UCSBDatesControllerTests]/[method:admin_can_edit_an_existing_ucsbdate()]
removed call to edu/ucsb/cs156/example/entities/UCSBDate::setQuarterYYYYQ → KILLED

104

1.1
Location : updateUCSBDate
Killed by : edu.ucsb.cs156.example.controllers.UCSBDatesControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.UCSBDatesControllerTests]/[method:admin_can_edit_an_existing_ucsbdate()]
removed call to edu/ucsb/cs156/example/entities/UCSBDate::setName → KILLED

105

1.1
Location : updateUCSBDate
Killed by : edu.ucsb.cs156.example.controllers.UCSBDatesControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.UCSBDatesControllerTests]/[method:admin_can_edit_an_existing_ucsbdate()]
removed call to edu/ucsb/cs156/example/entities/UCSBDate::setLocalDateTime → KILLED

109

1.1
Location : updateUCSBDate
Killed by : edu.ucsb.cs156.example.controllers.UCSBDatesControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.UCSBDatesControllerTests]/[method:admin_can_edit_an_existing_ucsbdate()]
replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBDatesController::updateUCSBDate → KILLED

Active mutators

Tests examined


Report generated by PIT 1.7.3