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

Mutations

44

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

63

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

64

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

65

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

69

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

78

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

80

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

89

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

91

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

92

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

103

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

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::setQuarterYYYYQ → KILLED

106

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

107

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

111

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