JobsController.java

1
package edu.ucsb.cs156.organic.controllers;
2
3
import com.fasterxml.jackson.databind.ObjectMapper;
4
5
import io.swagger.v3.oas.annotations.tags.Tag;
6
import io.swagger.v3.oas.annotations.Operation;
7
import io.swagger.v3.oas.annotations.Parameter;
8
9
import org.springframework.beans.factory.annotation.Autowired;
10
import org.springframework.data.domain.Page;
11
import org.springframework.data.domain.PageRequest;
12
import org.springframework.data.domain.Sort;
13
import org.springframework.security.access.prepost.PreAuthorize;
14
import org.springframework.web.bind.annotation.GetMapping;
15
import org.springframework.web.bind.annotation.PostMapping;
16
import org.springframework.web.bind.annotation.RequestMapping;
17
import org.springframework.web.bind.annotation.RequestParam;
18
import org.springframework.web.bind.annotation.RestController;
19
20
21
import edu.ucsb.cs156.organic.entities.jobs.Job;
22
import edu.ucsb.cs156.organic.jobs.TestJob;
23
import edu.ucsb.cs156.organic.repositories.jobs.JobsRepository;
24
import edu.ucsb.cs156.organic.services.jobs.JobService;
25
26
27
@Tag(name = "Jobs")
28
@RequestMapping("/api/jobs")
29
@RestController
30
public class JobsController extends ApiController {
31
    @Autowired
32
    private JobsRepository jobsRepository;
33
34
    @Autowired
35
    private JobService jobService;
36
37
38
    @Autowired
39
    ObjectMapper mapper;
40
41
42
    @Operation(summary = "List all jobs")
43
    @PreAuthorize("hasRole('ROLE_ADMIN')")
44
    @GetMapping("/all")
45
    public Iterable<Job> allJobs() {
46
        Iterable<Job> jobs = jobsRepository.findAll();
47 1 1. allJobs : replaced return value with null for edu/ucsb/cs156/organic/controllers/JobsController::allJobs → KILLED
        return jobs;
48
    }
49
50
    @Operation(summary = "List all jobs")
51
    @PreAuthorize("hasRole('ROLE_ADMIN')")
52
    @GetMapping("/all/pageable")
53
    public Page<Job> allJobsPaged(
54
         @Parameter(name="page") @RequestParam int page,
55
         @Parameter(name="size") @RequestParam int size
56
    ) {
57
        Page<Job> jobs = jobsRepository.findAll(PageRequest.of(page, size, Sort.by("id").descending()));
58 1 1. allJobsPaged : replaced return value with null for edu/ucsb/cs156/organic/controllers/JobsController::allJobsPaged → KILLED
        return jobs;
59
    }
60
61
    @Operation(summary = "Launch Test Job (click fail if you want to test exception handling)")
62
    @PreAuthorize("hasRole('ROLE_ADMIN')")
63
    @PostMapping("/launch/testjob")
64
    public Job launchTestJob(
65
        @Parameter(name="fail") @RequestParam Boolean fail, 
66
        @Parameter(name="sleepMs") @RequestParam Integer sleepMs,
67
        @Parameter(name="id") @RequestParam Integer id
68
    ) {
69
        TestJob testJob = TestJob.builder()
70
        .fail(fail)
71
        .sleepMs(sleepMs)
72
        .build();
73
74
        // Reference: frontend/src/components/Jobs/TestJobForm.js
75 4 1. launchTestJob : changed conditional boundary → KILLED
2. launchTestJob : changed conditional boundary → KILLED
3. launchTestJob : negated conditional → KILLED
4. launchTestJob : negated conditional → KILLED
        if (sleepMs < 0 || sleepMs > 60000) {
76
            throw new IllegalArgumentException("sleepMs must be between 0 and 60000");
77
        }
78
79 1 1. launchTestJob : replaced return value with null for edu/ucsb/cs156/organic/controllers/JobsController::launchTestJob → KILLED
        return jobService.runAsJob(testJob, id);
80
    }
81
}

Mutations

47

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

58

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

75

1.1
Location : launchTestJob
Killed by : edu.ucsb.cs156.organic.controllers.JobsControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.organic.controllers.JobsControllerTests]/[method:admin_launch_test_job_with_boundary_parameter_0()]
changed conditional boundary → KILLED

2.2
Location : launchTestJob
Killed by : edu.ucsb.cs156.organic.controllers.JobsControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.organic.controllers.JobsControllerTests]/[method:admin_launch_test_job_with_boundary_parameter_60000()]
changed conditional boundary → KILLED

3.3
Location : launchTestJob
Killed by : edu.ucsb.cs156.organic.controllers.JobsControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.organic.controllers.JobsControllerTests]/[method:admin_launch_test_job_with_invalid_parameter_minus_1()]
negated conditional → KILLED

4.4
Location : launchTestJob
Killed by : edu.ucsb.cs156.organic.controllers.JobsControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.organic.controllers.JobsControllerTests]/[method:admin_launch_test_job_with_invalid_parameter_60001()]
negated conditional → KILLED

79

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

Active mutators

Tests examined


Report generated by PIT 1.7.3