InstructorsController.java

1
package edu.ucsb.cs.scaffold.controller;
2
3
import edu.ucsb.cs.scaffold.entity.Instructor;
4
import edu.ucsb.cs.scaffold.repository.InstructorRepository;
5
import edu.ucsb.cs.scaffold.utilities.CanonicalFormConverter;
6
import io.swagger.v3.oas.annotations.Operation;
7
import io.swagger.v3.oas.annotations.tags.Tag;
8
import lombok.extern.slf4j.Slf4j;
9
import org.springframework.beans.factory.annotation.Autowired;
10
import org.springframework.http.ResponseEntity;
11
import org.springframework.security.access.prepost.PreAuthorize;
12
import org.springframework.web.bind.annotation.DeleteMapping;
13
import org.springframework.web.bind.annotation.GetMapping;
14
import org.springframework.web.bind.annotation.PostMapping;
15
import org.springframework.web.bind.annotation.RequestMapping;
16
import org.springframework.web.bind.annotation.RequestParam;
17
import org.springframework.web.bind.annotation.RestController;
18
19
@Tag(name = "Instructors")
20
@RequestMapping("/api/admin/instructors")
21
@RestController
22
@Slf4j
23
public class InstructorsController extends ApiController {
24
25
  @Autowired InstructorRepository instructorRepository;
26
27
  @Operation(summary = "Create a new Instructor")
28
  @PreAuthorize("hasRole('ROLE_ADMIN')")
29
  @PostMapping("/post")
30
  public Instructor postInstructor(@RequestParam String email) {
31
    String convertedEmail = CanonicalFormConverter.convertToValidEmail(email).strip();
32
    Instructor instructor = Instructor.builder().email(convertedEmail).build();
33
    instructorRepository.save(instructor);
34 1 1. postInstructor : replaced return value with null for edu/ucsb/cs/scaffold/controller/InstructorsController::postInstructor → KILLED
    return instructor;
35
  }
36
37
  @Operation(summary = "List all Instructors")
38
  @PreAuthorize("hasRole('ROLE_ADMIN')")
39
  @GetMapping("/get")
40
  public Iterable<Instructor> allInstructors() {
41 1 1. allInstructors : replaced return value with Collections.emptyList for edu/ucsb/cs/scaffold/controller/InstructorsController::allInstructors → KILLED
    return instructorRepository.findAll();
42
  }
43
44
  @Operation(summary = "Delete an Instructor by email")
45
  @PreAuthorize("hasRole('ROLE_ADMIN')")
46
  @DeleteMapping("/delete")
47
  public ResponseEntity<String> deleteInstructor(@RequestParam String email) {
48
    Instructor instructor = instructorRepository.findById(email).orElse(null);
49 1 1. deleteInstructor : negated conditional → KILLED
    if (instructor == null) {
50 1 1. deleteInstructor : replaced return value with null for edu/ucsb/cs/scaffold/controller/InstructorsController::deleteInstructor → KILLED
      return ResponseEntity.status(404)
51
          .body(String.format("Instructor with email %s not found.", email));
52
    }
53 1 1. deleteInstructor : removed call to edu/ucsb/cs/scaffold/repository/InstructorRepository::delete → KILLED
    instructorRepository.delete(instructor);
54 1 1. deleteInstructor : replaced return value with null for edu/ucsb/cs/scaffold/controller/InstructorsController::deleteInstructor → KILLED
    return ResponseEntity.status(200)
55
        .body(String.format("Instructor with email %s deleted.", email));
56
  }
57
}

Mutations

34

1.1
Location : postInstructor
Killed by : edu.ucsb.cs.scaffold.controllers.InstructorsControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs.scaffold.controllers.InstructorsControllerTests]/[method:logged_in_admins_can_post()]
replaced return value with null for edu/ucsb/cs/scaffold/controller/InstructorsController::postInstructor → KILLED

41

1.1
Location : allInstructors
Killed by : edu.ucsb.cs.scaffold.controllers.InstructorsControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs.scaffold.controllers.InstructorsControllerTests]/[method:logged_in_admins_can_get()]
replaced return value with Collections.emptyList for edu/ucsb/cs/scaffold/controller/InstructorsController::allInstructors → KILLED

49

1.1
Location : deleteInstructor
Killed by : edu.ucsb.cs.scaffold.controllers.InstructorsControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs.scaffold.controllers.InstructorsControllerTests]/[method:admin_try_to_delete_a_instructor_not_found()]
negated conditional → KILLED

50

1.1
Location : deleteInstructor
Killed by : edu.ucsb.cs.scaffold.controllers.InstructorsControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs.scaffold.controllers.InstructorsControllerTests]/[method:admin_try_to_delete_a_instructor_not_found()]
replaced return value with null for edu/ucsb/cs/scaffold/controller/InstructorsController::deleteInstructor → KILLED

53

1.1
Location : deleteInstructor
Killed by : edu.ucsb.cs.scaffold.controllers.InstructorsControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs.scaffold.controllers.InstructorsControllerTests]/[method:logged_in_admins_can_delete()]
removed call to edu/ucsb/cs/scaffold/repository/InstructorRepository::delete → KILLED

54

1.1
Location : deleteInstructor
Killed by : edu.ucsb.cs.scaffold.controllers.InstructorsControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs.scaffold.controllers.InstructorsControllerTests]/[method:logged_in_admins_can_delete()]
replaced return value with null for edu/ucsb/cs/scaffold/controller/InstructorsController::deleteInstructor → KILLED

Active mutators

Tests examined


Report generated by PIT 1.17.0