JobsController.java

1
package edu.ucsb.cs156.example.controllers;
2
3
import com.fasterxml.jackson.core.JsonProcessingException;
4
import com.fasterxml.jackson.databind.ObjectMapper;
5
import edu.ucsb.cs156.example.entities.Job;
6
import edu.ucsb.cs156.example.errors.EntityNotFoundException;
7
import edu.ucsb.cs156.example.repositories.JobsRepository;
8
import edu.ucsb.cs156.example.services.jobs.JobService;
9
import io.swagger.v3.oas.annotations.Operation;
10
import io.swagger.v3.oas.annotations.Parameter;
11
import io.swagger.v3.oas.annotations.tags.Tag;
12
import java.util.Map;
13
import lombok.extern.slf4j.Slf4j;
14
import org.springframework.beans.factory.annotation.Autowired;
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.PathVariable;
19
import org.springframework.web.bind.annotation.RequestMapping;
20
import org.springframework.web.bind.annotation.RequestParam;
21
import org.springframework.web.bind.annotation.RestController;
22
23
@Tag(name = "Jobs")
24
@RequestMapping("/api/jobs")
25
@RestController
26
@Slf4j
27
public class JobsController extends ApiController {
28
  @Autowired private JobsRepository jobsRepository;
29
30
  @Autowired private JobService jobService;
31
32
  @Autowired ObjectMapper mapper;
33
34
  @Operation(summary = "List all jobs")
35
  @PreAuthorize("hasRole('ROLE_ADMIN')")
36
  @GetMapping("/all")
37
  public Iterable<Job> allJobs() {
38
    Iterable<Job> jobs = jobsRepository.findAll();
39 1 1. allJobs : replaced return value with Collections.emptyList for edu/ucsb/cs156/example/controllers/JobsController::allJobs → KILLED
    return jobs;
40
  }
41
42
  @Operation(summary = "Delete all job records")
43
  @PreAuthorize("hasRole('ROLE_ADMIN')")
44
  @DeleteMapping("/all")
45
  public Map<String, String> deleteAllJobs() {
46 1 1. deleteAllJobs : removed call to edu/ucsb/cs156/example/repositories/JobsRepository::deleteAll → KILLED
    jobsRepository.deleteAll();
47 1 1. deleteAllJobs : replaced return value with Collections.emptyMap for edu/ucsb/cs156/example/controllers/JobsController::deleteAllJobs → KILLED
    return Map.of("message", "All jobs deleted");
48
  }
49
50
  @Operation(summary = "Get a specific Job Log by ID if it is in the database")
51
  @PreAuthorize("hasRole('ROLE_ADMIN')")
52
  @GetMapping("")
53
  public Job getJobLogById(
54
      @Parameter(name = "id", description = "ID of the job") @RequestParam Long id)
55
      throws JsonProcessingException {
56
57
    Job job =
58 1 1. lambda$getJobLogById$0 : replaced return value with null for edu/ucsb/cs156/example/controllers/JobsController::lambda$getJobLogById$0 → KILLED
        jobsRepository.findById(id).orElseThrow(() -> new EntityNotFoundException(Job.class, id));
59
60 1 1. getJobLogById : replaced return value with null for edu/ucsb/cs156/example/controllers/JobsController::getJobLogById → KILLED
    return job;
61
  }
62
63
  @Operation(summary = "Delete specific job record")
64
  @PreAuthorize("hasRole('ROLE_ADMIN')")
65
  @DeleteMapping("")
66
  public Map<String, String> deleteAllJobs(@Parameter(name = "id") @RequestParam Long id) {
67 1 1. deleteAllJobs : negated conditional → KILLED
    if (!jobsRepository.existsById(id)) {
68 1 1. deleteAllJobs : replaced return value with Collections.emptyMap for edu/ucsb/cs156/example/controllers/JobsController::deleteAllJobs → KILLED
      return Map.of("message", String.format("Job with id %d not found", id));
69
    }
70 1 1. deleteAllJobs : removed call to edu/ucsb/cs156/example/repositories/JobsRepository::deleteById → KILLED
    jobsRepository.deleteById(id);
71 1 1. deleteAllJobs : replaced return value with Collections.emptyMap for edu/ucsb/cs156/example/controllers/JobsController::deleteAllJobs → KILLED
    return Map.of("message", String.format("Job with id %d deleted", id));
72
  }
73
74
  @Operation(summary = "Get long job logs")
75
  @PreAuthorize("hasRole('ROLE_ADMIN')")
76
  @GetMapping("/logs/{id}")
77
  public String getJobLogs(@Parameter(name = "id", description = "Job ID") @PathVariable Long id) {
78
79 1 1. getJobLogs : replaced return value with "" for edu/ucsb/cs156/example/controllers/JobsController::getJobLogs → KILLED
    return jobService.getJobLogs(id);
80
  }
81
}

Mutations

39

1.1
Location : allJobs
Killed by : edu.ucsb.cs156.example.controllers.JobsControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.JobsControllerTests]/[method:admin_can_get_all_jobs()]
replaced return value with Collections.emptyList for edu/ucsb/cs156/example/controllers/JobsController::allJobs → KILLED

46

1.1
Location : deleteAllJobs
Killed by : edu.ucsb.cs156.example.controllers.JobsControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.JobsControllerTests]/[method:admin_can_delete_all_jobs()]
removed call to edu/ucsb/cs156/example/repositories/JobsRepository::deleteAll → KILLED

47

1.1
Location : deleteAllJobs
Killed by : edu.ucsb.cs156.example.controllers.JobsControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.JobsControllerTests]/[method:admin_can_delete_all_jobs()]
replaced return value with Collections.emptyMap for edu/ucsb/cs156/example/controllers/JobsController::deleteAllJobs → KILLED

58

1.1
Location : lambda$getJobLogById$0
Killed by : edu.ucsb.cs156.example.controllers.JobsControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.JobsControllerTests]/[method:api_getJobLogById__admin_logged_in__returns_not_found_for_missing_job()]
replaced return value with null for edu/ucsb/cs156/example/controllers/JobsController::lambda$getJobLogById$0 → KILLED

60

1.1
Location : getJobLogById
Killed by : edu.ucsb.cs156.example.controllers.JobsControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.JobsControllerTests]/[method:api_getJobLogById__admin_logged_in__returns_job_by_id()]
replaced return value with null for edu/ucsb/cs156/example/controllers/JobsController::getJobLogById → KILLED

67

1.1
Location : deleteAllJobs
Killed by : edu.ucsb.cs156.example.controllers.JobsControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.JobsControllerTests]/[method:admin_can_delete_specific_job()]
negated conditional → KILLED

68

1.1
Location : deleteAllJobs
Killed by : edu.ucsb.cs156.example.controllers.JobsControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.JobsControllerTests]/[method:admin_gets_reasonable_error_when_deleting_non_existing_job()]
replaced return value with Collections.emptyMap for edu/ucsb/cs156/example/controllers/JobsController::deleteAllJobs → KILLED

70

1.1
Location : deleteAllJobs
Killed by : edu.ucsb.cs156.example.controllers.JobsControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.JobsControllerTests]/[method:admin_can_delete_specific_job()]
removed call to edu/ucsb/cs156/example/repositories/JobsRepository::deleteById → KILLED

71

1.1
Location : deleteAllJobs
Killed by : edu.ucsb.cs156.example.controllers.JobsControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.JobsControllerTests]/[method:admin_can_delete_specific_job()]
replaced return value with Collections.emptyMap for edu/ucsb/cs156/example/controllers/JobsController::deleteAllJobs → KILLED

79

1.1
Location : getJobLogs
Killed by : edu.ucsb.cs156.example.controllers.JobsControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.JobsControllerTests]/[method:test_getJobLogs_admin_can_get_job_log()]
replaced return value with "" for edu/ucsb/cs156/example/controllers/JobsController::getJobLogs → KILLED

Active mutators

Tests examined


Report generated by PIT 1.17.0