UCSBOrganizationsController.java

1
package edu.ucsb.cs156.example.controllers;
2
3
import edu.ucsb.cs156.example.entities.UCSBOrganization;
4
import edu.ucsb.cs156.example.errors.EntityNotFoundException;
5
import edu.ucsb.cs156.example.repositories.UCSBOrganizationRepository;
6
7
import io.swagger.v3.oas.annotations.Operation;
8
import io.swagger.v3.oas.annotations.Parameter;
9
import io.swagger.v3.oas.annotations.tags.Tag;
10
import lombok.extern.slf4j.Slf4j;
11
12
import org.springframework.beans.factory.annotation.Autowired;
13
import org.springframework.security.access.prepost.PreAuthorize;
14
import org.springframework.web.bind.annotation.*;
15
16
import jakarta.validation.Valid;
17
18
/**
19
 * REST controller (pluralized) for UCSB Organizations
20
 */
21
@Tag(name = "UCSBOrganizations")
22
@RequestMapping("/api/ucsborganizations")
23
@RestController
24
@Slf4j
25
public class UCSBOrganizationsController extends ApiController {
26
27
    @Autowired
28
    UCSBOrganizationRepository ucsbOrganizationRepository;
29
30
    // ===== LIST ALL =====
31
    @Operation(summary = "List all UCSB organizations")
32
    @PreAuthorize("hasRole('ROLE_USER')")
33
    @GetMapping("/all")
34
    public Iterable<UCSBOrganization> allOrganizations() {
35
        Iterable<UCSBOrganization> orgs = ucsbOrganizationRepository.findAll();
36 1 1. allOrganizations : replaced return value with Collections.emptyList for edu/ucsb/cs156/example/controllers/UCSBOrganizationsController::allOrganizations → KILLED
        return orgs;
37
    }
38
39
    // ===== CREATE =====
40
    @Operation(summary = "Create a new UCSB organization")
41
    @PreAuthorize("hasRole('ROLE_ADMIN')")
42
    @PostMapping("/post")
43
    public UCSBOrganization create(
44
            @Parameter(name = "orgCode") @RequestParam String orgCode,
45
            @Parameter(name = "orgTranslationShort") @RequestParam String orgTranslationShort,
46
            @Parameter(name = "orgTranslation") @RequestParam String orgTranslation,
47
            @Parameter(name = "inactive") @RequestParam Boolean inactive) {
48
49
        UCSBOrganization org = new UCSBOrganization();
50 1 1. create : removed call to edu/ucsb/cs156/example/entities/UCSBOrganization::setOrgCode → KILLED
        org.setOrgCode(orgCode);
51 1 1. create : removed call to edu/ucsb/cs156/example/entities/UCSBOrganization::setOrgTranslationShort → KILLED
        org.setOrgTranslationShort(orgTranslationShort);
52 1 1. create : removed call to edu/ucsb/cs156/example/entities/UCSBOrganization::setOrgTranslation → KILLED
        org.setOrgTranslation(orgTranslation);
53 1 1. create : removed call to edu/ucsb/cs156/example/entities/UCSBOrganization::setInactive → KILLED
        org.setInactive(inactive);
54 1 1. create : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBOrganizationsController::create → KILLED
        return ucsbOrganizationRepository.save(org);
55
    }
56
57
    // ===== READ =====
58
    @Operation(summary = "Get a UCSB organization by orgCode")
59
    @PreAuthorize("hasRole('ROLE_USER')")
60
    @GetMapping("")
61
    public UCSBOrganization getByOrgCode(@Parameter(name = "orgCode") @RequestParam String orgCode) {
62 1 1. getByOrgCode : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBOrganizationsController::getByOrgCode → KILLED
        return ucsbOrganizationRepository.findById(orgCode)
63 1 1. lambda$getByOrgCode$0 : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBOrganizationsController::lambda$getByOrgCode$0 → KILLED
                .orElseThrow(() -> new EntityNotFoundException(UCSBOrganization.class, orgCode));
64
    }
65
66
    // ===== UPDATE =====
67
    @Operation(summary = "Update a UCSB organization")
68
    @PreAuthorize("hasRole('ROLE_ADMIN')")
69
    @PutMapping("")
70
    public UCSBOrganization update(
71
            @Parameter(name = "orgCode") @RequestParam String orgCode,
72
            @RequestBody @Valid UCSBOrganization incoming) {
73
74
        UCSBOrganization org = ucsbOrganizationRepository.findById(orgCode)
75 1 1. lambda$update$1 : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBOrganizationsController::lambda$update$1 → KILLED
                .orElseThrow(() -> new EntityNotFoundException(UCSBOrganization.class, orgCode));
76
77 1 1. update : removed call to edu/ucsb/cs156/example/entities/UCSBOrganization::setOrgTranslationShort → KILLED
        org.setOrgTranslationShort(incoming.getOrgTranslationShort());
78 1 1. update : removed call to edu/ucsb/cs156/example/entities/UCSBOrganization::setOrgTranslation → KILLED
        org.setOrgTranslation(incoming.getOrgTranslation());
79 1 1. update : removed call to edu/ucsb/cs156/example/entities/UCSBOrganization::setInactive → KILLED
        org.setInactive(incoming.getInactive());
80
        ucsbOrganizationRepository.save(org);
81
82 1 1. update : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBOrganizationsController::update → KILLED
        return org;
83
    }
84
85
    // ===== DELETE =====
86
    @Operation(summary = "Delete a UCSB organization")
87
    @PreAuthorize("hasRole('ROLE_ADMIN')")
88
    @DeleteMapping("")
89
    public Object delete(@Parameter(name = "orgCode") @RequestParam String orgCode) {
90
        UCSBOrganization org = ucsbOrganizationRepository.findById(orgCode)
91 1 1. lambda$delete$2 : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBOrganizationsController::lambda$delete$2 → KILLED
                .orElseThrow(() -> new EntityNotFoundException(UCSBOrganization.class, orgCode));
92 1 1. delete : removed call to edu/ucsb/cs156/example/repositories/UCSBOrganizationRepository::delete → KILLED
        ucsbOrganizationRepository.delete(org);
93 1 1. delete : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBOrganizationsController::delete → KILLED
        return genericMessage("UCSB Organization with id %s deleted".formatted(orgCode));
94
    }
95
}

Mutations

36

1.1
Location : allOrganizations
Killed by : edu.ucsb.cs156.example.controllers.UCSBOrganizationsControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.UCSBOrganizationsControllerTests]/[method:logged_in_user_can_get_all_ucsbdiningcommons()]
replaced return value with Collections.emptyList for edu/ucsb/cs156/example/controllers/UCSBOrganizationsController::allOrganizations → KILLED

50

1.1
Location : create
Killed by : edu.ucsb.cs156.example.controllers.UCSBOrganizationsControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.UCSBOrganizationsControllerTests]/[method:admin_can_post_new_org()]
removed call to edu/ucsb/cs156/example/entities/UCSBOrganization::setOrgCode → KILLED

51

1.1
Location : create
Killed by : edu.ucsb.cs156.example.controllers.UCSBOrganizationsControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.UCSBOrganizationsControllerTests]/[method:admin_can_post_new_org()]
removed call to edu/ucsb/cs156/example/entities/UCSBOrganization::setOrgTranslationShort → KILLED

52

1.1
Location : create
Killed by : edu.ucsb.cs156.example.controllers.UCSBOrganizationsControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.UCSBOrganizationsControllerTests]/[method:admin_can_post_new_org()]
removed call to edu/ucsb/cs156/example/entities/UCSBOrganization::setOrgTranslation → KILLED

53

1.1
Location : create
Killed by : edu.ucsb.cs156.example.controllers.UCSBOrganizationsControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.UCSBOrganizationsControllerTests]/[method:admin_can_post_new_org()]
removed call to edu/ucsb/cs156/example/entities/UCSBOrganization::setInactive → KILLED

54

1.1
Location : create
Killed by : edu.ucsb.cs156.example.controllers.UCSBOrganizationsControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.UCSBOrganizationsControllerTests]/[method:admin_can_post_new_org()]
replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBOrganizationsController::create → KILLED

62

1.1
Location : getByOrgCode
Killed by : edu.ucsb.cs156.example.controllers.UCSBOrganizationsControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.UCSBOrganizationsControllerTests]/[method:user_get_by_id_success()]
replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBOrganizationsController::getByOrgCode → KILLED

63

1.1
Location : lambda$getByOrgCode$0
Killed by : edu.ucsb.cs156.example.controllers.UCSBOrganizationsControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.UCSBOrganizationsControllerTests]/[method:user_get_by_id_not_found()]
replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBOrganizationsController::lambda$getByOrgCode$0 → KILLED

75

1.1
Location : lambda$update$1
Killed by : edu.ucsb.cs156.example.controllers.UCSBOrganizationsControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.UCSBOrganizationsControllerTests]/[method:admin_cannot_edit_nonexistent_org()]
replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBOrganizationsController::lambda$update$1 → KILLED

77

1.1
Location : update
Killed by : edu.ucsb.cs156.example.controllers.UCSBOrganizationsControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.UCSBOrganizationsControllerTests]/[method:admin_can_edit_org_success()]
removed call to edu/ucsb/cs156/example/entities/UCSBOrganization::setOrgTranslationShort → KILLED

78

1.1
Location : update
Killed by : edu.ucsb.cs156.example.controllers.UCSBOrganizationsControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.UCSBOrganizationsControllerTests]/[method:admin_can_edit_org_success()]
removed call to edu/ucsb/cs156/example/entities/UCSBOrganization::setOrgTranslation → KILLED

79

1.1
Location : update
Killed by : edu.ucsb.cs156.example.controllers.UCSBOrganizationsControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.UCSBOrganizationsControllerTests]/[method:admin_can_edit_org_success()]
removed call to edu/ucsb/cs156/example/entities/UCSBOrganization::setInactive → KILLED

82

1.1
Location : update
Killed by : edu.ucsb.cs156.example.controllers.UCSBOrganizationsControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.UCSBOrganizationsControllerTests]/[method:admin_can_edit_org_success()]
replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBOrganizationsController::update → KILLED

91

1.1
Location : lambda$delete$2
Killed by : edu.ucsb.cs156.example.controllers.UCSBOrganizationsControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.UCSBOrganizationsControllerTests]/[method:admin_delete_org_not_found()]
replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBOrganizationsController::lambda$delete$2 → KILLED

92

1.1
Location : delete
Killed by : edu.ucsb.cs156.example.controllers.UCSBOrganizationsControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.UCSBOrganizationsControllerTests]/[method:admin_can_delete_org_success()]
removed call to edu/ucsb/cs156/example/repositories/UCSBOrganizationRepository::delete → KILLED

93

1.1
Location : delete
Killed by : edu.ucsb.cs156.example.controllers.UCSBOrganizationsControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.UCSBOrganizationsControllerTests]/[method:admin_can_delete_org_success()]
replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBOrganizationsController::delete → KILLED

Active mutators

Tests examined


Report generated by PIT 1.17.0