JobsController.java

1
package edu.ucsb.cs156.happiercows.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.happiercows.entities.jobs.Job;
22
import edu.ucsb.cs156.happiercows.jobs.InstructorReportJob;
23
import edu.ucsb.cs156.happiercows.jobs.InstructorReportJobFactory;
24
import edu.ucsb.cs156.happiercows.jobs.InstructorReportJobSingleCommons;
25
import edu.ucsb.cs156.happiercows.jobs.InstructorReportJobSingleCommonsFactory;
26
import edu.ucsb.cs156.happiercows.jobs.MilkTheCowsJobFactory;
27
import edu.ucsb.cs156.happiercows.jobs.MilkTheCowsJobFactoryInd;
28
import edu.ucsb.cs156.happiercows.jobs.SetCowHealthJobFactory;
29
import edu.ucsb.cs156.happiercows.jobs.UpdateCowHealthJobFactoryInd;
30
import edu.ucsb.cs156.happiercows.jobs.TestJob;
31
import edu.ucsb.cs156.happiercows.jobs.UpdateCowHealthJobFactory;
32
import edu.ucsb.cs156.happiercows.jobs.RecordCommonStatsJob;
33
import edu.ucsb.cs156.happiercows.jobs.RecordCommonStatsJobFactory;
34
import edu.ucsb.cs156.happiercows.repositories.jobs.JobsRepository;
35
import edu.ucsb.cs156.happiercows.services.jobs.JobContextConsumer;
36
import edu.ucsb.cs156.happiercows.services.jobs.JobService;
37
import edu.ucsb.cs156.happiercows.services.CommonsPlusBuilderService;
38
39
40
@Tag(name = "Jobs")
41
@RequestMapping("/api/jobs")
42
@RestController
43
public class JobsController extends ApiController {
44
    @Autowired
45
    private JobsRepository jobsRepository;
46
47
    @Autowired
48
    private JobService jobService;
49
50
    @Autowired
51
    private CommonsPlusBuilderService commonsPlusBuilderService;
52
53
    @Autowired
54
    ObjectMapper mapper;
55
56
    @Autowired
57
    UpdateCowHealthJobFactory updateCowHealthJobFactory;
58
59
    @Autowired
60
    MilkTheCowsJobFactory milkTheCowsJobFactory;
61
62
    @Autowired
63
    MilkTheCowsJobFactoryInd milkTheCowsJobFactoryInd;
64
65
    @Autowired
66
    SetCowHealthJobFactory setCowHealthJobFactory;
67
68
    @Autowired
69
    InstructorReportJobFactory instructorReportJobFactory;
70
71
    @Autowired
72
    InstructorReportJobSingleCommonsFactory instructorReportJobSingleCommonsFactory;
73
74
    @Autowired
75
    UpdateCowHealthJobFactoryInd updateCowHealthJobFactoryInd;
76
77
    @Autowired
78
    RecordCommonStatsJobFactory recordCommonStatsJobFactory;
79
80
    @Operation(summary = "List all jobs")
81
    @PreAuthorize("hasRole('ROLE_ADMIN')")
82
    @GetMapping("/all")
83
    public Iterable<Job> allJobs() {
84
        Iterable<Job> jobs = jobsRepository.findAll();
85 1 1. allJobs : replaced return value with null for edu/ucsb/cs156/happiercows/controllers/JobsController::allJobs → KILLED
        return jobs;
86
    }
87
88
    @Operation(summary = "List all jobs")
89
    @PreAuthorize("hasRole('ROLE_ADMIN')")
90
    @GetMapping("/all/pageable")
91
    public Page<Job> allJobsPaged(
92
         @Parameter(name="page") @RequestParam int page,
93
         @Parameter(name="size") @RequestParam int size
94
    ) {
95
        Page<Job> jobs = jobsRepository.findAll(PageRequest.of(page, size, Sort.by("id").descending()));
96 1 1. allJobsPaged : replaced return value with null for edu/ucsb/cs156/happiercows/controllers/JobsController::allJobsPaged → KILLED
        return jobs;
97
    }
98
99
    @Operation(summary = "Launch Test Job (click fail if you want to test exception handling)")
100
    @PreAuthorize("hasRole('ROLE_ADMIN')")
101
    @PostMapping("/launch/testjob")
102
    public Job launchTestJob(
103
        @Parameter(name="fail") @RequestParam Boolean fail, 
104
        @Parameter(name="sleepMs") @RequestParam Integer sleepMs
105
    ) {
106
        TestJob testJob = TestJob.builder()
107
        .fail(fail)
108
        .sleepMs(sleepMs)
109
        .build();
110
111
        // Reference: frontend/src/components/Jobs/TestJobForm.js
112 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) {
113
            throw new IllegalArgumentException("sleepMs must be between 0 and 60000");
114
        }
115
116 1 1. launchTestJob : replaced return value with null for edu/ucsb/cs156/happiercows/controllers/JobsController::launchTestJob → KILLED
        return jobService.runAsJob(testJob);
117
    }
118
119
    @Operation(summary = "Launch Job to Milk the Cows (click fail if you want to test exception handling)")
120
    @PreAuthorize("hasRole('ROLE_ADMIN')")
121
    @PostMapping("/launch/milkthecowjob")
122
    public Job launchTestJob(
123
    ) {
124
        JobContextConsumer milkTheCowsJob = milkTheCowsJobFactory.create();
125 1 1. launchTestJob : replaced return value with null for edu/ucsb/cs156/happiercows/controllers/JobsController::launchTestJob → KILLED
        return jobService.runAsJob(milkTheCowsJob);
126
    }
127
128
    @Operation(summary = "Launch Job to Milk the Cows for a single commons")
129
    @PreAuthorize("hasRole('ROLE_ADMIN')")
130
    @PostMapping("/launch/milkthecowjobsinglecommons")
131
    public Job launchTestJob(
132
         @Parameter(name="commonsId") @RequestParam Long commonsId
133
    ) {
134
        JobContextConsumer milkTheCowsJobInd = milkTheCowsJobFactoryInd.create(commonsId);
135 1 1. launchTestJob : replaced return value with null for edu/ucsb/cs156/happiercows/controllers/JobsController::launchTestJob → KILLED
        return jobService.runAsJob(milkTheCowsJobInd);
136
    }
137
138
    @Operation(summary = "Launch Job to Update Cow Health")
139
    @PreAuthorize("hasRole('ROLE_ADMIN')")
140
    @PostMapping("/launch/updatecowhealth")
141
    public Job updateCowHealth(
142
    ) { 
143
        JobContextConsumer updateCowHealthJob = updateCowHealthJobFactory.create();
144 1 1. updateCowHealth : replaced return value with null for edu/ucsb/cs156/happiercows/controllers/JobsController::updateCowHealth → KILLED
        return jobService.runAsJob(updateCowHealthJob);
145
    }
146
147
    @Operation(summary = "Launch Job to Update Cow Health for a single commons")
148
    @PreAuthorize("hasRole('ROLE_ADMIN')")
149
    @PostMapping("/launch/updatecowhealthsinglecommons")
150
    public Job updateCowHealth(
151
         @Parameter(name="commonsId") @RequestParam Long commonsId
152
    ) { 
153
        JobContextConsumer updateCowHealthJobInd = updateCowHealthJobFactoryInd.create(commonsId);
154 1 1. updateCowHealth : replaced return value with null for edu/ucsb/cs156/happiercows/controllers/JobsController::updateCowHealth → KILLED
        return jobService.runAsJob(updateCowHealthJobInd);
155
    }
156
157
    @Operation(summary = "Launch Job to Set Cow Health")
158
    @PreAuthorize("hasRole('ROLE_ADMIN')")
159
    @PostMapping("/launch/setcowhealth")
160
    public Job setCowHealth( 
161
        @Parameter(name="commonsID") @RequestParam Long commonsID, 
162
        @Parameter(name="health") @RequestParam double health
163
    ) { 
164
        JobContextConsumer setCowHealthJob = setCowHealthJobFactory.create(commonsID, health);
165
166
        // Reference: frontend/src/components/Jobs/SetCowHealthForm.js
167 4 1. setCowHealth : changed conditional boundary → KILLED
2. setCowHealth : changed conditional boundary → KILLED
3. setCowHealth : negated conditional → KILLED
4. setCowHealth : negated conditional → KILLED
        if (health < 0 || health > 100) {
168
            throw new IllegalArgumentException("health must be between 0 and 100");
169
        }
170
171 1 1. setCowHealth : replaced return value with null for edu/ucsb/cs156/happiercows/controllers/JobsController::setCowHealth → KILLED
        return jobService.runAsJob(setCowHealthJob);
172
    }
173
174
    @Operation(summary = "Launch Job to Produce Instructor Report")
175
    @PreAuthorize("hasRole('ROLE_ADMIN')")
176
    @PostMapping("/launch/instructorreport")
177
    public Job instructorReport(
178
    ) { 
179
        InstructorReportJob instructorReportJob = (InstructorReportJob) instructorReportJobFactory.create();
180 1 1. instructorReport : replaced return value with null for edu/ucsb/cs156/happiercows/controllers/JobsController::instructorReport → KILLED
        return jobService.runAsJob(instructorReportJob);
181
    }
182
183
    @Operation(summary = "Launch Job to Produce Instructor Report for a single commons")
184
    @PreAuthorize("hasRole('ROLE_ADMIN')")
185
    @PostMapping("/launch/instructorreportsinglecommons")
186
    public Job instructorReportSingleCommons(
187
         @Parameter(name="commonsId") @RequestParam Long commonsId
188
    ) { 
189
190
        InstructorReportJobSingleCommons instructorReportJobSingleCommons = (InstructorReportJobSingleCommons) instructorReportJobSingleCommonsFactory.create(commonsId);
191 1 1. instructorReportSingleCommons : replaced return value with null for edu/ucsb/cs156/happiercows/controllers/JobsController::instructorReportSingleCommons → KILLED
        return jobService.runAsJob(instructorReportJobSingleCommons);
192
    }
193
194
    @Operation(summary = "Launch Job to Record the Stats of all Commons")
195
    @PreAuthorize("hasRole('ROLE_ADMIN')")
196
    @PostMapping("/launch/recordcommonstats")
197
    public Job recordCommonStats(
198
    ) { 
199
200
        RecordCommonStatsJob recordCommonStatsJob = (RecordCommonStatsJob) recordCommonStatsJobFactory.create();
201 1 1. recordCommonStats : replaced return value with null for edu/ucsb/cs156/happiercows/controllers/JobsController::recordCommonStats → KILLED
        return jobService.runAsJob(recordCommonStatsJob);
202
    }
203
}

Mutations

85

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

96

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

112

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

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

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

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

116

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

125

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

135

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_individual_job()]
replaced return value with null for edu/ucsb/cs156/happiercows/controllers/JobsController::launchTestJob → KILLED

144

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

154

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_individual()]
replaced return value with null for edu/ucsb/cs156/happiercows/controllers/JobsController::updateCowHealth → KILLED

167

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

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

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

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

171

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

180

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

191

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

201

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

Active mutators

Tests examined


Report generated by PIT 1.7.3