RecommendationRequestController.java

1
package edu.ucsb.cs156.example.controllers;
2
3
import edu.ucsb.cs156.example.entities.RecommendationRequest;
4
import edu.ucsb.cs156.example.errors.EntityNotFoundException;
5
import edu.ucsb.cs156.example.repositories.RecommendationRequestRepository;
6
import io.swagger.v3.oas.annotations.Operation;
7
import io.swagger.v3.oas.annotations.Parameter;
8
import io.swagger.v3.oas.annotations.tags.Tag;
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
@Tag(name = "RecommendationRequest")
30
@RequestMapping("/api/RecommendationRequest")
31
@RestController
32
@Slf4j
33
public class RecommendationRequestController extends ApiController{
34
  @Autowired
35
    RecommendationRequestRepository recommendationRequestRepository;
36
37
    @Operation(summary= "List all recomendation requests")
38
    @PreAuthorize("hasRole('ROLE_USER')")
39
    @GetMapping("/all")
40
    public Iterable<RecommendationRequest> allRecommendationRequests() {
41
        Iterable<RecommendationRequest> requests = recommendationRequestRepository.findAll();
42 1 1. allRecommendationRequests : replaced return value with null for edu/ucsb/cs156/example/controllers/RecommendationRequestController::allRecommendationRequests → KILLED
        return requests;
43
    }
44
45
    @Operation(summary= "Create a new recommendation request")
46
    @PreAuthorize("hasRole('ROLE_ADMIN')")
47
    @PostMapping("/post")
48
    public RecommendationRequest postRecommendationRequest(
49
            @Parameter(name="requesterEmail") @RequestParam String requesterEmail,
50
            @Parameter(name="professorEmail") @RequestParam String professorEmail,
51
            @Parameter(name="explanation") @RequestParam String explanation,
52
            @Parameter(name="dateRequested") @RequestParam("dateRequested") @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) LocalDateTime dateRequested,
53
            @Parameter(name="dateNeeded") @RequestParam("dateNeeded") @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) LocalDateTime dateNeeded,
54
            @Parameter(name="done") @RequestParam boolean done)
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("dateRequested={}", dateRequested);
61
62
        RecommendationRequest recommendationRequest = new RecommendationRequest();
63 1 1. postRecommendationRequest : removed call to edu/ucsb/cs156/example/entities/RecommendationRequest::setRequesterEmail → KILLED
        recommendationRequest.setRequesterEmail(requesterEmail);
64 1 1. postRecommendationRequest : removed call to edu/ucsb/cs156/example/entities/RecommendationRequest::setProfessorEmail → KILLED
        recommendationRequest.setProfessorEmail(professorEmail);
65 1 1. postRecommendationRequest : removed call to edu/ucsb/cs156/example/entities/RecommendationRequest::setExplanation → KILLED
        recommendationRequest.setExplanation(explanation);
66 1 1. postRecommendationRequest : removed call to edu/ucsb/cs156/example/entities/RecommendationRequest::setDateRequested → KILLED
        recommendationRequest.setDateRequested(dateRequested);
67 1 1. postRecommendationRequest : removed call to edu/ucsb/cs156/example/entities/RecommendationRequest::setDateNeeded → KILLED
        recommendationRequest.setDateNeeded(dateNeeded);
68 1 1. postRecommendationRequest : removed call to edu/ucsb/cs156/example/entities/RecommendationRequest::setDone → KILLED
        recommendationRequest.setDone(done);
69
70
        RecommendationRequest savedRecommendationRequest = recommendationRequestRepository.save(recommendationRequest);
71
72 1 1. postRecommendationRequest : replaced return value with null for edu/ucsb/cs156/example/controllers/RecommendationRequestController::postRecommendationRequest → KILLED
        return savedRecommendationRequest;
73
    }
74
75
    @Operation(summary= "Get a single recommendation request")
76
    @PreAuthorize("hasRole('ROLE_USER')")
77
    @GetMapping("")
78
    public RecommendationRequest getById(
79
            @Parameter(name="id") @RequestParam Long id) {
80
        RecommendationRequest recommendationRequest = recommendationRequestRepository.findById(id)
81 1 1. lambda$getById$0 : replaced return value with null for edu/ucsb/cs156/example/controllers/RecommendationRequestController::lambda$getById$0 → KILLED
                .orElseThrow(() -> new EntityNotFoundException(RecommendationRequest.class, id));
82
83 1 1. getById : replaced return value with null for edu/ucsb/cs156/example/controllers/RecommendationRequestController::getById → KILLED
        return recommendationRequest;
84
    }
85
86
    @Operation(summary= "Update a single recommendation request")
87
    @PreAuthorize("hasRole('ROLE_ADMIN')")
88
    @PutMapping("")
89
    public RecommendationRequest updateRecommendationRequest(
90
            @Parameter(name="id") @RequestParam Long id,
91
            @RequestBody @Valid RecommendationRequest incoming) {
92
93
        RecommendationRequest recommendationRequest = recommendationRequestRepository.findById(id)
94 1 1. lambda$updateRecommendationRequest$1 : replaced return value with null for edu/ucsb/cs156/example/controllers/RecommendationRequestController::lambda$updateRecommendationRequest$1 → KILLED
                .orElseThrow(() -> new EntityNotFoundException(RecommendationRequest.class, id));
95
96 1 1. updateRecommendationRequest : removed call to edu/ucsb/cs156/example/entities/RecommendationRequest::setProfessorEmail → KILLED
        recommendationRequest.setProfessorEmail(incoming.getProfessorEmail());
97 1 1. updateRecommendationRequest : removed call to edu/ucsb/cs156/example/entities/RecommendationRequest::setRequesterEmail → KILLED
        recommendationRequest.setRequesterEmail(incoming.getRequesterEmail());
98 1 1. updateRecommendationRequest : removed call to edu/ucsb/cs156/example/entities/RecommendationRequest::setExplanation → KILLED
        recommendationRequest.setExplanation(incoming.getExplanation());
99 1 1. updateRecommendationRequest : removed call to edu/ucsb/cs156/example/entities/RecommendationRequest::setDateRequested → KILLED
        recommendationRequest.setDateRequested(incoming.getDateRequested());
100 1 1. updateRecommendationRequest : removed call to edu/ucsb/cs156/example/entities/RecommendationRequest::setDateNeeded → KILLED
        recommendationRequest.setDateNeeded(incoming.getDateNeeded());
101 1 1. updateRecommendationRequest : removed call to edu/ucsb/cs156/example/entities/RecommendationRequest::setDone → KILLED
        recommendationRequest.setDone(incoming.getDone());
102
103
        recommendationRequestRepository.save(recommendationRequest);
104
105 1 1. updateRecommendationRequest : replaced return value with null for edu/ucsb/cs156/example/controllers/RecommendationRequestController::updateRecommendationRequest → KILLED
        return recommendationRequest;
106
    }
107
108
    @Operation(summary= "Delete a RecomendationRequest")
109
    @PreAuthorize("hasRole('ROLE_ADMIN')")
110
    @DeleteMapping("")
111
    public Object deleteRecommendationRequest(
112
            @Parameter(name="id") @RequestParam Long id) {
113
        RecommendationRequest recommendationRequest = recommendationRequestRepository.findById(id)
114 1 1. lambda$deleteRecommendationRequest$2 : replaced return value with null for edu/ucsb/cs156/example/controllers/RecommendationRequestController::lambda$deleteRecommendationRequest$2 → KILLED
                .orElseThrow(() -> new EntityNotFoundException(RecommendationRequest.class, id));
115
116 1 1. deleteRecommendationRequest : removed call to edu/ucsb/cs156/example/repositories/RecommendationRequestRepository::delete → KILLED
        recommendationRequestRepository.delete(recommendationRequest);
117 1 1. deleteRecommendationRequest : replaced return value with null for edu/ucsb/cs156/example/controllers/RecommendationRequestController::deleteRecommendationRequest → KILLED
        return genericMessage("RecommendationRequest with id %s deleted".formatted(id));
118
    }
119
120
121
}

Mutations

42

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

63

1.1
Location : postRecommendationRequest
Killed by : edu.ucsb.cs156.example.controllers.RecommendationRequestControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.RecommendationRequestControllerTests]/[method:an_admin_user_can_post_a_new_recommendationrequest()]
removed call to edu/ucsb/cs156/example/entities/RecommendationRequest::setRequesterEmail → KILLED

64

1.1
Location : postRecommendationRequest
Killed by : edu.ucsb.cs156.example.controllers.RecommendationRequestControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.RecommendationRequestControllerTests]/[method:an_admin_user_can_post_a_new_recommendationrequest()]
removed call to edu/ucsb/cs156/example/entities/RecommendationRequest::setProfessorEmail → KILLED

65

1.1
Location : postRecommendationRequest
Killed by : edu.ucsb.cs156.example.controllers.RecommendationRequestControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.RecommendationRequestControllerTests]/[method:an_admin_user_can_post_a_new_recommendationrequest()]
removed call to edu/ucsb/cs156/example/entities/RecommendationRequest::setExplanation → KILLED

66

1.1
Location : postRecommendationRequest
Killed by : edu.ucsb.cs156.example.controllers.RecommendationRequestControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.RecommendationRequestControllerTests]/[method:an_admin_user_can_post_a_new_recommendationrequest()]
removed call to edu/ucsb/cs156/example/entities/RecommendationRequest::setDateRequested → KILLED

67

1.1
Location : postRecommendationRequest
Killed by : edu.ucsb.cs156.example.controllers.RecommendationRequestControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.RecommendationRequestControllerTests]/[method:an_admin_user_can_post_a_new_recommendationrequest()]
removed call to edu/ucsb/cs156/example/entities/RecommendationRequest::setDateNeeded → KILLED

68

1.1
Location : postRecommendationRequest
Killed by : edu.ucsb.cs156.example.controllers.RecommendationRequestControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.RecommendationRequestControllerTests]/[method:an_admin_user_can_post_a_new_recommendationrequest()]
removed call to edu/ucsb/cs156/example/entities/RecommendationRequest::setDone → KILLED

72

1.1
Location : postRecommendationRequest
Killed by : edu.ucsb.cs156.example.controllers.RecommendationRequestControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.RecommendationRequestControllerTests]/[method:an_admin_user_can_post_a_new_recommendationrequest()]
replaced return value with null for edu/ucsb/cs156/example/controllers/RecommendationRequestController::postRecommendationRequest → KILLED

81

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

83

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

94

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

96

1.1
Location : updateRecommendationRequest
Killed by : edu.ucsb.cs156.example.controllers.RecommendationRequestControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.RecommendationRequestControllerTests]/[method:admin_can_edit_an_existing_recommendationrequest()]
removed call to edu/ucsb/cs156/example/entities/RecommendationRequest::setProfessorEmail → KILLED

97

1.1
Location : updateRecommendationRequest
Killed by : edu.ucsb.cs156.example.controllers.RecommendationRequestControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.RecommendationRequestControllerTests]/[method:admin_can_edit_an_existing_recommendationrequest()]
removed call to edu/ucsb/cs156/example/entities/RecommendationRequest::setRequesterEmail → KILLED

98

1.1
Location : updateRecommendationRequest
Killed by : edu.ucsb.cs156.example.controllers.RecommendationRequestControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.RecommendationRequestControllerTests]/[method:admin_can_edit_an_existing_recommendationrequest()]
removed call to edu/ucsb/cs156/example/entities/RecommendationRequest::setExplanation → KILLED

99

1.1
Location : updateRecommendationRequest
Killed by : edu.ucsb.cs156.example.controllers.RecommendationRequestControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.RecommendationRequestControllerTests]/[method:admin_can_edit_an_existing_recommendationrequest()]
removed call to edu/ucsb/cs156/example/entities/RecommendationRequest::setDateRequested → KILLED

100

1.1
Location : updateRecommendationRequest
Killed by : edu.ucsb.cs156.example.controllers.RecommendationRequestControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.RecommendationRequestControllerTests]/[method:admin_can_edit_an_existing_recommendationrequest()]
removed call to edu/ucsb/cs156/example/entities/RecommendationRequest::setDateNeeded → KILLED

101

1.1
Location : updateRecommendationRequest
Killed by : edu.ucsb.cs156.example.controllers.RecommendationRequestControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.RecommendationRequestControllerTests]/[method:admin_can_edit_an_existing_recommendationrequest()]
removed call to edu/ucsb/cs156/example/entities/RecommendationRequest::setDone → KILLED

105

1.1
Location : updateRecommendationRequest
Killed by : edu.ucsb.cs156.example.controllers.RecommendationRequestControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.RecommendationRequestControllerTests]/[method:admin_can_edit_an_existing_recommendationrequest()]
replaced return value with null for edu/ucsb/cs156/example/controllers/RecommendationRequestController::updateRecommendationRequest → KILLED

114

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

116

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

117

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

Active mutators

Tests examined


Report generated by PIT 1.7.3