JobsController.java

1
package edu.ucsb.cs156.happiercows.controllers;
2
3
import com.fasterxml.jackson.databind.ObjectMapper;
4
5
import io.swagger.annotations.Api;
6
import io.swagger.annotations.ApiOperation;
7
import io.swagger.annotations.ApiParam;
8
import lombok.extern.slf4j.Slf4j;
9
10
import org.springframework.beans.factory.annotation.Autowired;
11
import org.springframework.context.annotation.Import;
12
import org.springframework.security.access.prepost.PreAuthorize;
13
import org.springframework.web.bind.annotation.GetMapping;
14
import org.springframework.web.bind.annotation.PostMapping;
15
16
17
import org.springframework.web.bind.annotation.RequestMapping;
18
import org.springframework.web.bind.annotation.RequestParam;
19
import org.springframework.web.bind.annotation.RestController;
20
21
import edu.ucsb.cs156.happiercows.entities.jobs.Job;
22
import edu.ucsb.cs156.happiercows.jobs.InstructorReportJob;
23
import edu.ucsb.cs156.happiercows.jobs.MilkTheCowsJob;
24
import edu.ucsb.cs156.happiercows.jobs.MilkTheCowsJobFactory;
25
import edu.ucsb.cs156.happiercows.jobs.TestJob;
26
import edu.ucsb.cs156.happiercows.jobs.UpdateCowHealthJob;
27
import edu.ucsb.cs156.happiercows.jobs.UpdateCowHealthJobFactory;
28
import edu.ucsb.cs156.happiercows.repositories.jobs.JobsRepository;
29
import edu.ucsb.cs156.happiercows.services.jobs.JobContextConsumer;
30
import edu.ucsb.cs156.happiercows.services.jobs.JobService;
31
32
33
34
@Slf4j
35
@Api(description = "Jobs")
36
@RequestMapping("/api/jobs")
37
@RestController
38
public class JobsController extends ApiController {
39
    @Autowired
40
    private JobsRepository jobsRepository;
41
42
    @Autowired
43
    private JobService jobService;
44
45
    @Autowired
46
    ObjectMapper mapper;
47
48
    @Autowired
49
    UpdateCowHealthJobFactory updateCowHealthJobFactory;
50
51
    @Autowired
52
    MilkTheCowsJobFactory milkTheCowsJobFactory;
53
54
    @ApiOperation(value = "List all jobs")
55
    @PreAuthorize("hasRole('ROLE_ADMIN')")
56
    @GetMapping("/all")
57
    public Iterable<Job> allJobs() {
58
        Iterable<Job> jobs = jobsRepository.findAll();
59 1 1. allJobs : replaced return value with null for edu/ucsb/cs156/happiercows/controllers/JobsController::allJobs → KILLED
        return jobs;
60
    }
61
62
    @ApiOperation(value = "Launch Test Job (click fail if you want to test exception handling)")
63
    @PreAuthorize("hasRole('ROLE_ADMIN')")
64
    @PostMapping("/launch/testjob")
65
    public Job launchTestJob(
66
        @ApiParam("fail") @RequestParam Boolean fail, 
67
        @ApiParam("sleepMs") @RequestParam Integer sleepMs
68
    ) {
69
        TestJob testJob = TestJob.builder()
70
        .fail(fail)
71
        .sleepMs(sleepMs)
72
        .build();
73
74 1 1. launchTestJob : replaced return value with null for edu/ucsb/cs156/happiercows/controllers/JobsController::launchTestJob → KILLED
        return jobService.runAsJob(testJob);
75
    }
76
77
    @ApiOperation(value = "Launch Job to Milk the Cows (click fail if you want to test exception handling)")
78
    @PreAuthorize("hasRole('ROLE_ADMIN')")
79
    @PostMapping("/launch/milkthecowjob")
80
    public Job launchTestJob(
81
    ) {
82
        JobContextConsumer milkTheCowsJob = milkTheCowsJobFactory.create();
83 1 1. launchTestJob : replaced return value with null for edu/ucsb/cs156/happiercows/controllers/JobsController::launchTestJob → KILLED
        return jobService.runAsJob(milkTheCowsJob);
84
    }
85
86
    @ApiOperation(value = "Launch Job to Update Cow Health")
87
    @PreAuthorize("hasRole('ROLE_ADMIN')")
88
    @PostMapping("/launch/updatecowhealth")
89
    public Job updateCowHealth(
90
    ) { 
91
        JobContextConsumer updateCowHealthJob = updateCowHealthJobFactory.create();
92 1 1. updateCowHealth : replaced return value with null for edu/ucsb/cs156/happiercows/controllers/JobsController::updateCowHealth → KILLED
        return jobService.runAsJob(updateCowHealthJob);
93
    }
94
95
    @ApiOperation(value = "Launch Job to Produce Instructor Report")
96
    @PreAuthorize("hasRole('ROLE_ADMIN')")
97
    @PostMapping("/launch/instructorreport")
98
    public Job instructorReport(
99
    ) { 
100
        InstructorReportJob instructorReportJob = 
101
            InstructorReportJob.builder().build();
102
       
103 1 1. instructorReport : replaced return value with null for edu/ucsb/cs156/happiercows/controllers/JobsController::instructorReport → KILLED
        return jobService.runAsJob(instructorReportJob);
104
    }
105
}

Mutations

59

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

74

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

83

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

92

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

103

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

Active mutators

Tests examined


Report generated by PIT 1.7.3