CourseOverTimeController.java

1
package edu.ucsb.cs156.courses.controllers;
2
3
import com.fasterxml.jackson.core.JsonProcessingException;
4
import com.fasterxml.jackson.databind.ObjectMapper;
5
import edu.ucsb.cs156.courses.collections.ConvertedSectionCollection;
6
import edu.ucsb.cs156.courses.documents.ConvertedSection;
7
import io.swagger.v3.oas.annotations.Operation;
8
import io.swagger.v3.oas.annotations.Parameter;
9
import java.util.List;
10
import lombok.extern.slf4j.Slf4j;
11
import org.springframework.beans.factory.annotation.Autowired;
12
import org.springframework.http.ResponseEntity;
13
import org.springframework.web.bind.annotation.GetMapping;
14
import org.springframework.web.bind.annotation.RequestMapping;
15
import org.springframework.web.bind.annotation.RequestParam;
16
import org.springframework.web.bind.annotation.RestController;
17
18
@Slf4j
19
@RestController
20
@RequestMapping("/api/public/courseovertime")
21
public class CourseOverTimeController {
22
23
  private ObjectMapper mapper = new ObjectMapper();
24
25
  @Autowired ConvertedSectionCollection convertedSectionCollection;
26
27
  @Operation(summary = "Get a list of courses over time")
28
  @GetMapping(value = "/search", produces = "application/json")
29
  public ResponseEntity<String> search(
30
      @Parameter(
31
              name = "startQtr",
32
              description =
33
                  "starting quarter in yyyyq format, e.g. 20231 for W23, 20232 for S23, etc. (1=Winter, 2=Spring, 3=Summer, 4=Fall)",
34
              example = "20231",
35
              required = true)
36
          @RequestParam
37
          String startQtr,
38
      @Parameter(
39
              name = "endQtr",
40
              description =
41
                  "ending quarter in yyyyq format, e.g. 20231 for W23, 20232 for S23, etc. (1=Winter, 2=Spring, 3=Summer, 4=Fall)",
42
              example = "20231",
43
              required = true)
44
          @RequestParam
45
          String endQtr,
46
      @Parameter(
47
              name = "subjectArea",
48
              description = "simplified area name, e.g. CMPSC for computer science",
49
              example = "CMPSC",
50
              required = true)
51
          @RequestParam
52
          String subjectArea,
53
      @Parameter(
54
              name = "courseNumber",
55
              description = "the specific course number, e.g. 130A for CS130A",
56
              example = "130A",
57
              required = true)
58
          @RequestParam
59
          String courseNumber)
60
      throws JsonProcessingException {
61
    List<ConvertedSection> courseResults =
62
        convertedSectionCollection.findByQuarterRangeAndCourseId(
63
            startQtr, endQtr, makeFormattedCourseId(subjectArea, courseNumber));
64
    String body = mapper.writeValueAsString(courseResults);
65 1 1. search : replaced return value with null for edu/ucsb/cs156/courses/controllers/CourseOverTimeController::search → KILLED
    return ResponseEntity.ok().body(body);
66
  }
67
68
  String makeFormattedCourseId(String subjectArea, String courseNumber) {
69
    String[] nums = courseNumber.split("[a-zA-Z]+");
70
    String[] suffs = courseNumber.split("[0-9]+");
71 2 1. makeFormattedCourseId : changed conditional boundary → KILLED
2. makeFormattedCourseId : negated conditional → KILLED
    if (suffs.length < 2) { // no suffix
72 1 1. makeFormattedCourseId : replaced return value with "" for edu/ucsb/cs156/courses/controllers/CourseOverTimeController::makeFormattedCourseId → KILLED
      return String.format("%-8s", subjectArea) // 'CMPSC   '
73
          + String.format("%3s", nums[0]) // '  8'
74
      ;
75
    }
76 1 1. makeFormattedCourseId : replaced return value with "" for edu/ucsb/cs156/courses/controllers/CourseOverTimeController::makeFormattedCourseId → KILLED
    return String.format("%-8s", subjectArea) // 'CMPSC   '
77
        + String.format("%3s", nums[0]) // '  8'
78
        + String.format("%-2s", suffs[1]) // 'A '
79
    ;
80
  }
81
}

Mutations

65

1.1
Location : search
Killed by : edu.ucsb.cs156.courses.controllers.CourseOverTimeControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.courses.controllers.CourseOverTimeControllerTests]/[method:test_search_emptyRequest()]
replaced return value with null for edu/ucsb/cs156/courses/controllers/CourseOverTimeController::search → KILLED

71

1.1
Location : makeFormattedCourseId
Killed by : edu.ucsb.cs156.courses.controllers.CourseOverTimeControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.courses.controllers.CourseOverTimeControllerTests]/[method:test_search_validRequestWithSuffix()]
changed conditional boundary → KILLED

2.2
Location : makeFormattedCourseId
Killed by : edu.ucsb.cs156.courses.controllers.CourseOverTimeControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.courses.controllers.CourseOverTimeControllerTests]/[method:test_search_validRequestWithoutSuffix()]
negated conditional → KILLED

72

1.1
Location : makeFormattedCourseId
Killed by : edu.ucsb.cs156.courses.controllers.CourseOverTimeControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.courses.controllers.CourseOverTimeControllerTests]/[method:test_search_validRequestWithoutSuffix()]
replaced return value with "" for edu/ucsb/cs156/courses/controllers/CourseOverTimeController::makeFormattedCourseId → KILLED

76

1.1
Location : makeFormattedCourseId
Killed by : edu.ucsb.cs156.courses.controllers.CourseOverTimeControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.courses.controllers.CourseOverTimeControllerTests]/[method:test_search_validRequestWithSuffix()]
replaced return value with "" for edu/ucsb/cs156/courses/controllers/CourseOverTimeController::makeFormattedCourseId → KILLED

Active mutators

Tests examined


Report generated by PIT 1.7.3