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.InstructorReportJobSingleGame;
6
import edu.ucsb.cs156.happiercows.jobs.InstructorReportJobSingleGameFactory;
7
import edu.ucsb.cs156.happiercows.jobs.MilkTheCowsJobFactory;
8
import edu.ucsb.cs156.happiercows.jobs.MilkTheCowsJobFactoryInd;
9
import edu.ucsb.cs156.happiercows.jobs.RecordGameStatsJob;
10
import edu.ucsb.cs156.happiercows.jobs.RecordGameStatsJobFactory;
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 InstructorReportJobSingleGameFactory instructorReportJobSingleGameFactory;
50
51
  @Autowired UpdateCowHealthJobFactoryInd updateCowHealthJobFactoryInd;
52
53
  @Autowired RecordGameStatsJobFactory recordGameStatsJobFactory;
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 game")
80
  @PreAuthorize("hasRole('ROLE_ADMIN')")
81
  @PostMapping("/launch/milkthecowjobsinglegame")
82
  public Job launchMilkTheCowsJobSingleGame(
83
      @Parameter(name = "gameId") @RequestParam Long gameId) {
84
    JobContextConsumer milkTheCowsJobInd = milkTheCowsJobFactoryInd.create(gameId);
85 1 1. launchMilkTheCowsJobSingleGame : replaced return value with null for edu/ucsb/cs156/happiercows/controllers/JobsController::launchMilkTheCowsJobSingleGame → 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 game")
97
  @PreAuthorize("hasRole('ROLE_ADMIN')")
98
  @PostMapping("/launch/updatecowhealthsinglegame")
99
  public Job updateCowHealthSingleGame(
100
      @Parameter(name = "gameId") @RequestParam Long gameId) {
101
    JobContextConsumer updateCowHealthJobInd = updateCowHealthJobFactoryInd.create(gameId);
102 1 1. updateCowHealthSingleGame : replaced return value with null for edu/ucsb/cs156/happiercows/controllers/JobsController::updateCowHealthSingleGame → 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 = "gameID") @RequestParam Long gameID,
110
      @Parameter(name = "health") @RequestParam double health) {
111
    JobContextConsumer setCowHealthJob = setCowHealthJobFactory.create(gameID, 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 game")
131
  @PreAuthorize("hasRole('ROLE_ADMIN')")
132
  @PostMapping("/launch/instructorreportsinglegame")
133
  public Job instructorReportSingleGame(
134
      @Parameter(name = "gameId") @RequestParam Long gameId) {
135
136
    InstructorReportJobSingleGame instructorReportJobSingleGame =
137
        (InstructorReportJobSingleGame) instructorReportJobSingleGameFactory.create(gameId);
138 1 1. instructorReportSingleGame : replaced return value with null for edu/ucsb/cs156/happiercows/controllers/JobsController::instructorReportSingleGame → KILLED
    return jobService.runAsJob(instructorReportJobSingleGame);
139
  }
140
141
  @Operation(summary = "Launch Job to Record the Stats of all Game")
142
  @PreAuthorize("hasRole('ROLE_ADMIN')")
143
  @PostMapping("/launch/recordgamestats")
144
  public Job recordGameStats() {
145
146
    RecordGameStatsJob recordGameStatsJob =
147
        (RecordGameStatsJob) recordGameStatsJobFactory.create();
148 1 1. recordGameStats : replaced return value with null for edu/ucsb/cs156/happiercows/controllers/JobsController::recordGameStats → KILLED
    return jobService.runAsJob(recordGameStatsJob);
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()]
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()]
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()]
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 : launchMilkTheCowsJobSingleGame
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::launchMilkTheCowsJobSingleGame → 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 : updateCowHealthSingleGame
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::updateCowHealthSingleGame → 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 : instructorReportSingleGame
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_game_job()]
replaced return value with null for edu/ucsb/cs156/happiercows/controllers/JobsController::instructorReportSingleGame → KILLED

148

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

Active mutators

Tests examined


Report generated by PIT 1.22.1