ApiController.java

1
package edu.ucsb.cs156.frontiers.controllers;
2
3
import edu.ucsb.cs156.frontiers.errors.NoLinkedOrganizationException;
4
5
import org.apache.coyote.BadRequestException;
6
import org.springframework.beans.factory.annotation.Autowired;
7
8
import lombok.extern.slf4j.Slf4j;
9
import org.springframework.http.HttpStatus;
10
import org.springframework.web.bind.annotation.ExceptionHandler;
11
import org.springframework.web.bind.annotation.ResponseStatus;
12
13
import edu.ucsb.cs156.frontiers.errors.EntityNotFoundException;
14
import edu.ucsb.cs156.frontiers.models.CurrentUser;
15
import edu.ucsb.cs156.frontiers.services.CurrentUserService;
16
17
import java.util.Map;
18
19
/**
20
 * This is an abstract class that provides common functionality for all API controllers.
21
 */
22
23
@Slf4j
24
public abstract class ApiController {
25
  @Autowired
26
  private CurrentUserService currentUserService;
27
28
  /**
29
   * This method returns the current user.
30
   * @return the current user
31
   */
32
  protected CurrentUser getCurrentUser() {
33 1 1. getCurrentUser : replaced return value with null for edu/ucsb/cs156/frontiers/controllers/ApiController::getCurrentUser → KILLED
    return currentUserService.getCurrentUser();
34
  }
35
36
  /**
37
   * This method returns a generic message.
38
   * @param message the message
39
   * @return a map with the message
40
   */
41
  protected Object genericMessage(String message) {
42 1 1. genericMessage : replaced return value with null for edu/ucsb/cs156/frontiers/controllers/ApiController::genericMessage → KILLED
    return Map.of("message", message);
43
  }
44
45
  /**
46
   * This method handles the EntityNotFoundException.
47
   * @param e the exception
48
   * @return a map with the type and message of the exception
49
   */
50
  @ExceptionHandler({ EntityNotFoundException.class })
51
  @ResponseStatus(HttpStatus.NOT_FOUND)
52
  public Object handleEntityNotFoundException(Throwable e) {
53 1 1. handleEntityNotFoundException : replaced return value with null for edu/ucsb/cs156/frontiers/controllers/ApiController::handleEntityNotFoundException → KILLED
    return Map.of(
54
      "type", e.getClass().getSimpleName(),
55
      "message", e.getMessage()
56
    );
57
  }
58
59
  /**
60
   * This method handles the NoLinkedOrganizationException.
61
   * @param e the exception
62
   * @return a map with the type and message of the exception
63
   */
64
  @ExceptionHandler({ NoLinkedOrganizationException.class })
65
  @ResponseStatus(HttpStatus.BAD_REQUEST)
66
  public Object handleNoLinkedOrgException(Throwable e) {
67 1 1. handleNoLinkedOrgException : replaced return value with null for edu/ucsb/cs156/frontiers/controllers/ApiController::handleNoLinkedOrgException → KILLED
    return Map.of(
68
            "type", e.getClass().getSimpleName(),
69
            "message", e.getMessage()
70
    );
71
  }
72
73
  @ExceptionHandler(UnsupportedOperationException.class)
74
    @ResponseStatus(HttpStatus.FORBIDDEN)
75
    public Map<String, String> handleUnsupportedOperation(UnsupportedOperationException ex) {
76 1 1. handleUnsupportedOperation : replaced return value with Collections.emptyMap for edu/ucsb/cs156/frontiers/controllers/ApiController::handleUnsupportedOperation → KILLED
        return Map.of("message", ex.getMessage());
77
    }
78
79
      /**
80
     * This method handles BadRequestException.
81
     * @param e the exception
82
     * @return a map with the type and message of the exception
83
     */
84
    @ExceptionHandler({ BadRequestException.class })
85
    @ResponseStatus(HttpStatus.BAD_REQUEST)
86
    public Object handleBadRequestException(Throwable e) {
87 1 1. handleBadRequestException : replaced return value with null for edu/ucsb/cs156/frontiers/controllers/ApiController::handleBadRequestException → KILLED
      return Map.of(
88
        "type",    e.getClass().getSimpleName(),
89
        "message", e.getMessage()
90
      );
91
    }
92
}

Mutations

33

1.1
Location : getCurrentUser
Killed by : edu.ucsb.cs156.frontiers.controllers.CoursesControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.frontiers.controllers.CoursesControllerTests]/[method:testGetCoursesForStudent_Forbidden()]
replaced return value with null for edu/ucsb/cs156/frontiers/controllers/ApiController::getCurrentUser → KILLED

42

1.1
Location : genericMessage
Killed by : edu.ucsb.cs156.frontiers.controllers.ApiControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.frontiers.controllers.ApiControllerTests]/[method:generic_message_test()]
replaced return value with null for edu/ucsb/cs156/frontiers/controllers/ApiController::genericMessage → KILLED

53

1.1
Location : handleEntityNotFoundException
Killed by : edu.ucsb.cs156.frontiers.controllers.ApiControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.frontiers.controllers.ApiControllerTests]/[method:test_that_dummy_controller_returns_Exception_when_1_is_not_passed()]
replaced return value with null for edu/ucsb/cs156/frontiers/controllers/ApiController::handleEntityNotFoundException → KILLED

67

1.1
Location : handleNoLinkedOrgException
Killed by : edu.ucsb.cs156.frontiers.controllers.ApiControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.frontiers.controllers.ApiControllerTests]/[method:test_dummy_controller_returns_no_linked_org()]
replaced return value with null for edu/ucsb/cs156/frontiers/controllers/ApiController::handleNoLinkedOrgException → KILLED

76

1.1
Location : handleUnsupportedOperation
Killed by : edu.ucsb.cs156.frontiers.controllers.AdminControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.frontiers.controllers.AdminControllerTests]/[method:admin_cannot_delete_protected_admin_email()]
replaced return value with Collections.emptyMap for edu/ucsb/cs156/frontiers/controllers/ApiController::handleUnsupportedOperation → KILLED

87

1.1
Location : handleBadRequestException
Killed by : edu.ucsb.cs156.frontiers.controllers.ApiControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.frontiers.controllers.ApiControllerTests]/[method:handleBadRequestException_returnsTypeAndMessage()]
replaced return value with null for edu/ucsb/cs156/frontiers/controllers/ApiController::handleBadRequestException → KILLED

Active mutators

Tests examined


Report generated by PIT 1.17.0