JobsController.java

1
package edu.ucsb.cs156.happiercows.controllers;
2
3
import edu.ucsb.cs156.happiercows.jobs.InstructorReportJob;
4
import edu.ucsb.cs156.happiercows.jobs.InstructorReportJobFactory;
5
import edu.ucsb.cs156.happiercows.jobs.InstructorReportJobSingleCommons;
6
import edu.ucsb.cs156.happiercows.jobs.InstructorReportJobSingleCommonsFactory;
7
import edu.ucsb.cs156.happiercows.jobs.MilkTheCowsJobFactory;
8
import edu.ucsb.cs156.happiercows.jobs.MilkTheCowsJobFactoryInd;
9
import edu.ucsb.cs156.happiercows.jobs.RecordCommonStatsJob;
10
import edu.ucsb.cs156.happiercows.jobs.RecordCommonStatsJobFactory;
11
import edu.ucsb.cs156.happiercows.jobs.SetCowHealthJobFactory;
12
import edu.ucsb.cs156.happiercows.jobs.TestJob;
13
import edu.ucsb.cs156.happiercows.jobs.UpdateCowHealthJobFactory;
14
import edu.ucsb.cs156.happiercows.jobs.UpdateCowHealthJobFactoryInd;
15
import edu.ucsb.cs156.jobs.entities.Job;
16
import edu.ucsb.cs156.jobs.services.JobContextConsumer;
17
import edu.ucsb.cs156.jobs.services.JobService;
18
import io.swagger.v3.oas.annotations.Operation;
19
import io.swagger.v3.oas.annotations.Parameter;
20
import io.swagger.v3.oas.annotations.tags.Tag;
21
import org.springframework.beans.factory.annotation.Autowired;
22
import org.springframework.security.access.prepost.PreAuthorize;
23
import org.springframework.web.bind.annotation.PostMapping;
24
import org.springframework.web.bind.annotation.RequestMapping;
25
import org.springframework.web.bind.annotation.RequestParam;
26
import org.springframework.web.bind.annotation.RestController;
27
28
/**
29
 * Launch endpoints for this app's concrete jobs. The generic admin endpoints (list jobs, get
30
 * paginated jobs, get logs, delete jobs) come from the lib-jobs library's own controller.
31
 */
32
@Tag(name = "Jobs")
33
@RequestMapping("/api/jobs")
34
@RestController
35
public class JobsController extends ApiController {
36
37
  @Autowired private JobService jobService;
38
39
  @Autowired UpdateCowHealthJobFactory updateCowHealthJobFactory;
40
41
  @Autowired MilkTheCowsJobFactory milkTheCowsJobFactory;
42
43
  @Autowired MilkTheCowsJobFactoryInd milkTheCowsJobFactoryInd;
44
45
  @Autowired SetCowHealthJobFactory setCowHealthJobFactory;
46
47
  @Autowired InstructorReportJobFactory instructorReportJobFactory;
48
49
  @Autowired InstructorReportJobSingleCommonsFactory instructorReportJobSingleCommonsFactory;
50
51
  @Autowired UpdateCowHealthJobFactoryInd updateCowHealthJobFactoryInd;
52
53
  @Autowired RecordCommonStatsJobFactory recordCommonStatsJobFactory;
54
55
  @Operation(summary = "Launch Test Job (click fail if you want to test exception handling)")
56
  @PreAuthorize("hasRole('ROLE_ADMIN')")
57
  @PostMapping("/launch/testjob")
58
  public Job launchTestJob(
59
      @Parameter(name = "fail") @RequestParam Boolean fail,
60
      @Parameter(name = "sleepMs") @RequestParam Integer sleepMs) {
61
    TestJob testJob = TestJob.builder().fail(fail).sleepMs(sleepMs).build();
62
63
    // Reference: frontend/src/components/Jobs/TestJobForm.js
64 4 1. launchTestJob : negated conditional → KILLED
2. launchTestJob : negated conditional → KILLED
3. launchTestJob : changed conditional boundary → KILLED
4. launchTestJob : changed conditional boundary → KILLED
    if (sleepMs < 0 || sleepMs > 60000) {
65
      throw new IllegalArgumentException("sleepMs must be between 0 and 60000");
66
    }
67
68 1 1. launchTestJob : replaced return value with null for edu/ucsb/cs156/happiercows/controllers/JobsController::launchTestJob → KILLED
    return jobService.runAsJob(testJob);
69
  }
70
71
  @Operation(summary = "Launch Job to Milk the Cows (click fail if you want to test exception handling)")
72
  @PreAuthorize("hasRole('ROLE_ADMIN')")
73
  @PostMapping("/launch/milkthecowjob")
74
  public Job launchMilkTheCowsJob() {
75
    JobContextConsumer milkTheCowsJob = milkTheCowsJobFactory.create();
76 1 1. launchMilkTheCowsJob : replaced return value with null for edu/ucsb/cs156/happiercows/controllers/JobsController::launchMilkTheCowsJob → KILLED
    return jobService.runAsJob(milkTheCowsJob);
77
  }
78
79
  @Operation(summary = "Launch Job to Milk the Cows for a single commons")
80
  @PreAuthorize("hasRole('ROLE_ADMIN')")
81
  @PostMapping("/launch/milkthecowjobsinglecommons")
82
  public Job launchMilkTheCowsJobSingleCommons(
83
      @Parameter(name = "commonsId") @RequestParam Long commonsId) {
84
    JobContextConsumer milkTheCowsJobInd = milkTheCowsJobFactoryInd.create(commonsId);
85 1 1. launchMilkTheCowsJobSingleCommons : replaced return value with null for edu/ucsb/cs156/happiercows/controllers/JobsController::launchMilkTheCowsJobSingleCommons → KILLED
    return jobService.runAsJob(milkTheCowsJobInd);
86
  }
87
88
  @Operation(summary = "Launch Job to Update Cow Health")
89
  @PreAuthorize("hasRole('ROLE_ADMIN')")
90
  @PostMapping("/launch/updatecowhealth")
91
  public Job updateCowHealth() {
92
    JobContextConsumer updateCowHealthJob = updateCowHealthJobFactory.create();
93 1 1. updateCowHealth : replaced return value with null for edu/ucsb/cs156/happiercows/controllers/JobsController::updateCowHealth → KILLED
    return jobService.runAsJob(updateCowHealthJob);
94
  }
95
96
  @Operation(summary = "Launch Job to Update Cow Health for a single commons")
97
  @PreAuthorize("hasRole('ROLE_ADMIN')")
98
  @PostMapping("/launch/updatecowhealthsinglecommons")
99
  public Job updateCowHealthSingleCommons(
100
      @Parameter(name = "commonsId") @RequestParam Long commonsId) {
101
    JobContextConsumer updateCowHealthJobInd = updateCowHealthJobFactoryInd.create(commonsId);
102 1 1. updateCowHealthSingleCommons : replaced return value with null for edu/ucsb/cs156/happiercows/controllers/JobsController::updateCowHealthSingleCommons → KILLED
    return jobService.runAsJob(updateCowHealthJobInd);
103
  }
104
105
  @Operation(summary = "Launch Job to Set Cow Health")
106
  @PreAuthorize("hasRole('ROLE_ADMIN')")
107
  @PostMapping("/launch/setcowhealth")
108
  public Job setCowHealth(
109
      @Parameter(name = "commonsID") @RequestParam Long commonsID,
110
      @Parameter(name = "health") @RequestParam double health) {
111
    JobContextConsumer setCowHealthJob = setCowHealthJobFactory.create(commonsID, health);
112
113
    // Reference: frontend/src/components/Jobs/SetCowHealthForm.js
114 4 1. setCowHealth : negated conditional → KILLED
2. setCowHealth : changed conditional boundary → KILLED
3. setCowHealth : negated conditional → KILLED
4. setCowHealth : changed conditional boundary → KILLED
    if (health < 0 || health > 100) {
115
      throw new IllegalArgumentException("health must be between 0 and 100");
116
    }
117
118 1 1. setCowHealth : replaced return value with null for edu/ucsb/cs156/happiercows/controllers/JobsController::setCowHealth → KILLED
    return jobService.runAsJob(setCowHealthJob);
119
  }
120
121
  @Operation(summary = "Launch Job to Produce Instructor Report")
122
  @PreAuthorize("hasRole('ROLE_ADMIN')")
123
  @PostMapping("/launch/instructorreport")
124
  public Job instructorReport() {
125
    InstructorReportJob instructorReportJob =
126
        (InstructorReportJob) instructorReportJobFactory.create();
127 1 1. instructorReport : replaced return value with null for edu/ucsb/cs156/happiercows/controllers/JobsController::instructorReport → KILLED
    return jobService.runAsJob(instructorReportJob);
128
  }
129
130
  @Operation(summary = "Launch Job to Produce Instructor Report for a single commons")
131
  @PreAuthorize("hasRole('ROLE_ADMIN')")
132
  @PostMapping("/launch/instructorreportsinglecommons")
133
  public Job instructorReportSingleCommons(
134
      @Parameter(name = "commonsId") @RequestParam Long commonsId) {
135
136
    InstructorReportJobSingleCommons instructorReportJobSingleCommons =
137
        (InstructorReportJobSingleCommons) instructorReportJobSingleCommonsFactory.create(commonsId);
138 1 1. instructorReportSingleCommons : replaced return value with null for edu/ucsb/cs156/happiercows/controllers/JobsController::instructorReportSingleCommons → KILLED
    return jobService.runAsJob(instructorReportJobSingleCommons);
139
  }
140
141
  @Operation(summary = "Launch Job to Record the Stats of all Commons")
142
  @PreAuthorize("hasRole('ROLE_ADMIN')")
143
  @PostMapping("/launch/recordcommonstats")
144
  public Job recordCommonStats() {
145
146
    RecordCommonStatsJob recordCommonStatsJob =
147
        (RecordCommonStatsJob) recordCommonStatsJobFactory.create();
148 1 1. recordCommonStats : replaced return value with null for edu/ucsb/cs156/happiercows/controllers/JobsController::recordCommonStats → KILLED
    return jobService.runAsJob(recordCommonStatsJob);
149
  }
150
}

Mutations

64

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_that_fails()]
negated conditional → 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_can_launch_test_job_that_fails()]
negated conditional → 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()]
changed conditional boundary → 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()]
changed conditional boundary → KILLED

68

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

76

1.1
Location : launchMilkTheCowsJob
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::launchMilkTheCowsJob → KILLED

85

1.1
Location : launchMilkTheCowsJobSingleCommons
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::launchMilkTheCowsJobSingleCommons → KILLED

93

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

102

1.1
Location : updateCowHealthSingleCommons
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::updateCowHealthSingleCommons → KILLED

114

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()]
negated conditional → 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_can_launch_set_cow_health_job()]
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_boundary_parameter()]
changed conditional boundary → KILLED

118

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

127

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

138

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

148

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.17.0