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 jakarta.validation.Valid;
27
28
import java.time.LocalDateTime;
29
30
/**
31
 * This is a REST controller for UCSBDates
32
 */
33
34
@Tag(name = "UCSBDates")
35
@RequestMapping("/api/ucsbdates")
36
@RestController
37
@Slf4j
38
public class UCSBDatesController extends ApiController {
39
40
    @Autowired
41
    UCSBDateRepository ucsbDateRepository;
42
43
    /**
44
     * List all UCSB dates
45
     * 
46
     * @return an iterable of UCSBDate
47
     */
48
    @Operation(summary= "List all ucsb dates")
49
    @PreAuthorize("hasRole('ROLE_USER')")
50
    @GetMapping("/all")
51
    public Iterable<UCSBDate> allUCSBDates() {
52
        Iterable<UCSBDate> dates = ucsbDateRepository.findAll();
53 1 1. allUCSBDates : replaced return value with Collections.emptyList for edu/ucsb/cs156/example/controllers/UCSBDatesController::allUCSBDates → KILLED
        return dates;
54
    }
55
56
    /**
57
     * Get a single date by id
58
     * 
59
     * @param id the id of the date
60
     * @return a UCSBDate
61
     */
62
    @Operation(summary= "Get a single date")
63
    @PreAuthorize("hasRole('ROLE_USER')")
64
    @GetMapping("")
65
    public UCSBDate getById(
66
            @Parameter(name="id") @RequestParam Long id) {
67
        UCSBDate ucsbDate = ucsbDateRepository.findById(id)
68 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));
69
70 1 1. getById : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBDatesController::getById → KILLED
        return ucsbDate;
71
    }
72
73
    /**
74
     * Create a new date
75
     * 
76
     * @param quarterYYYYQ  the quarter in the format YYYYQ
77
     * @param name          the name of the date
78
     * @param localDateTime the date
79
     * @return the saved ucsbdate
80
     */
81
    @Operation(summary= "Create a new date")
82
    @PreAuthorize("hasRole('ROLE_ADMIN')")
83
    @PostMapping("/post")
84
    public UCSBDate postUCSBDate(
85
            @Parameter(name="quarterYYYYQ") @RequestParam String quarterYYYYQ,
86
            @Parameter(name="name") @RequestParam String name,
87
            @Parameter(name="localDateTime", description="(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)
88
            throws JsonProcessingException {
89
90
        // For an explanation of @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME)
91
        // See: https://www.baeldung.com/spring-date-parameters
92
93
        log.info("localDateTime={}", localDateTime);
94
95
        UCSBDate ucsbDate = new UCSBDate();
96 1 1. postUCSBDate : removed call to edu/ucsb/cs156/example/entities/UCSBDate::setQuarterYYYYQ → KILLED
        ucsbDate.setQuarterYYYYQ(quarterYYYYQ);
97 1 1. postUCSBDate : removed call to edu/ucsb/cs156/example/entities/UCSBDate::setName → KILLED
        ucsbDate.setName(name);
98 1 1. postUCSBDate : removed call to edu/ucsb/cs156/example/entities/UCSBDate::setLocalDateTime → KILLED
        ucsbDate.setLocalDateTime(localDateTime);
99
100
        UCSBDate savedUcsbDate = ucsbDateRepository.save(ucsbDate);
101
102 1 1. postUCSBDate : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBDatesController::postUCSBDate → KILLED
        return savedUcsbDate;
103
    }
104
105
    @Operation(summary= "Delete a UCSBDate")
106
    @PreAuthorize("hasRole('ROLE_ADMIN')")
107
    @DeleteMapping("")
108
    public Object deleteUCSBDate(
109
            @Parameter(name="id") @RequestParam Long id) {
110
        UCSBDate ucsbDate = ucsbDateRepository.findById(id)
111 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));
112
113 1 1. deleteUCSBDate : removed call to edu/ucsb/cs156/example/repositories/UCSBDateRepository::delete → KILLED
        ucsbDateRepository.delete(ucsbDate);
114 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));
115
    }
116
117
    /**
118
     * Update a single date
119
     * 
120
     * @param id       id of the date to update
121
     * @param incoming the new date
122
     * @return the updated date object
123
     */
124
    @Operation(summary= "Update a single date")
125
    @PreAuthorize("hasRole('ROLE_ADMIN')")
126
    @PutMapping("")
127
    public UCSBDate updateUCSBDate(
128
            @Parameter(name="id") @RequestParam Long id,
129
            @RequestBody @Valid UCSBDate incoming) {
130
131
        UCSBDate ucsbDate = ucsbDateRepository.findById(id)
132 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));
133
134 1 1. updateUCSBDate : removed call to edu/ucsb/cs156/example/entities/UCSBDate::setQuarterYYYYQ → KILLED
        ucsbDate.setQuarterYYYYQ(incoming.getQuarterYYYYQ());
135 1 1. updateUCSBDate : removed call to edu/ucsb/cs156/example/entities/UCSBDate::setName → KILLED
        ucsbDate.setName(incoming.getName());
136 1 1. updateUCSBDate : removed call to edu/ucsb/cs156/example/entities/UCSBDate::setLocalDateTime → KILLED
        ucsbDate.setLocalDateTime(incoming.getLocalDateTime());
137
138
        ucsbDateRepository.save(ucsbDate);
139
140 1 1. updateUCSBDate : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBDatesController::updateUCSBDate → KILLED
        return ucsbDate;
141
    }
142
}

Mutations

53

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 Collections.emptyList for edu/ucsb/cs156/example/controllers/UCSBDatesController::allUCSBDates → KILLED

68

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

70

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

96

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

97

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

98

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

102

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

111

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

113

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

114

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

132

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

134

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

135

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

136

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

140

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.17.0