UCSBOrganizationsController.java

1
package edu.ucsb.cs156.example.controllers;
2
3
import edu.ucsb.cs156.example.entities.UCSBOrganizations;
4
import edu.ucsb.cs156.example.errors.EntityNotFoundException;
5
import edu.ucsb.cs156.example.repositories.UCSBOrganizationsRepository;
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.DeleteMapping;
15
import org.springframework.web.bind.annotation.GetMapping;
16
import org.springframework.web.bind.annotation.PostMapping;
17
import org.springframework.web.bind.annotation.PutMapping;
18
import org.springframework.web.bind.annotation.RequestBody;
19
import org.springframework.web.bind.annotation.RequestMapping;
20
import org.springframework.web.bind.annotation.RequestParam;
21
import org.springframework.web.bind.annotation.RestController;
22
23
import jakarta.validation.Valid;
24
25
@Tag(name = "UCSBOrganizations")
26
@RequestMapping("/api/ucsborganizations")
27
@RestController
28
@Slf4j
29
30
public class UCSBOrganizationsController extends ApiController {
31
    @Autowired
32
    UCSBOrganizationsRepository ucsbOrganizationsRepository;
33
34
    /**
35
     * List all UCSB Orgs
36
     *
37
     * @return an iterable of UCSBOrganizations
38
     */
39
    @Operation(summary = "List all ucsb organizations")
40
    @PreAuthorize("hasRole('ROLE_USER')")
41
    @GetMapping("/all")
42
    public Iterable<UCSBOrganizations> allOrganizations() {
43
        Iterable<UCSBOrganizations> organizations = ucsbOrganizationsRepository.findAll();
44 1 1. allOrganizations : replaced return value with Collections.emptyList for edu/ucsb/cs156/example/controllers/UCSBOrganizationsController::allOrganizations → KILLED
        return organizations;
45
    }
46
47
    /**
48
     * Get a single org by id
49
     *
50
     * @param orgCode the id of the date
51
     * @return a UCSBOrg
52
     */
53
    @Operation(summary = "Get a single org from the table")
54
    @PreAuthorize("hasRole('ROLE_USER')")
55
    @GetMapping("")
56
    public UCSBOrganizations getById(@RequestParam String orgCode) {
57 1 1. getById : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBOrganizationsController::getById → KILLED
        return ucsbOrganizationsRepository.findById(orgCode)
58 1 1. lambda$getById$0 : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBOrganizationsController::lambda$getById$0 → KILLED
                .orElseThrow(() -> new EntityNotFoundException(UCSBOrganizations.class, orgCode));
59
    }
60
61
    /**
62
     * Update a single org. Accessible only to users with the role "ROLE_ADMIN".
63
     * 
64
     * @param orgCode  code of the org
65
     * @param incoming the new org contents
66
     * @return the updated org object
67
     */
68
    @Operation(summary = "Update a single organization")
69
    @PreAuthorize("hasRole('ROLE_ADMIN')")
70
    @PutMapping("")
71
    public UCSBOrganizations updateOrganizations(
72
            @Parameter(name = "orgCode") @RequestParam String orgCode,
73
            @RequestBody @Valid UCSBOrganizations incoming) {
74
75
        UCSBOrganizations organization = ucsbOrganizationsRepository.findById(orgCode)
76 1 1. lambda$updateOrganizations$1 : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBOrganizationsController::lambda$updateOrganizations$1 → KILLED
                .orElseThrow(() -> new EntityNotFoundException(UCSBOrganizations.class, orgCode));
77
78
        // organization.setOrgCode(incoming.getOrgCode());
79 1 1. updateOrganizations : removed call to edu/ucsb/cs156/example/entities/UCSBOrganizations::setOrgTranslationShort → KILLED
        organization.setOrgTranslationShort(incoming.getOrgTranslationShort());
80 1 1. updateOrganizations : removed call to edu/ucsb/cs156/example/entities/UCSBOrganizations::setOrgTranslation → KILLED
        organization.setOrgTranslation(incoming.getOrgTranslation());
81 1 1. updateOrganizations : removed call to edu/ucsb/cs156/example/entities/UCSBOrganizations::setInactive → KILLED
        organization.setInactive(incoming.getInactive());
82
83
        ucsbOrganizationsRepository.save(organization);
84
85 1 1. updateOrganizations : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBOrganizationsController::updateOrganizations → KILLED
        return organization;
86
    }
87
88
    @Operation(summary = "Create a new organization")
89
    @PreAuthorize("hasRole('ROLE_ADMIN')")
90
    @PostMapping("/post")
91
92
    public UCSBOrganizations postOrganization(
93
            @Parameter(name = "orgCode") @RequestParam String orgCode,
94
            @Parameter(name = "orgTranslationShort") @RequestParam String orgTranslationShort,
95
            @Parameter(name = "orgTranslation") @RequestParam String orgTranslation,
96
            @Parameter(name = "inactive") @RequestParam boolean inactive) {
97
98
        UCSBOrganizations organization = new UCSBOrganizations();
99 1 1. postOrganization : removed call to edu/ucsb/cs156/example/entities/UCSBOrganizations::setOrgCode → KILLED
        organization.setOrgCode(orgCode);
100 1 1. postOrganization : removed call to edu/ucsb/cs156/example/entities/UCSBOrganizations::setOrgTranslationShort → KILLED
        organization.setOrgTranslationShort(orgTranslationShort);
101 1 1. postOrganization : removed call to edu/ucsb/cs156/example/entities/UCSBOrganizations::setOrgTranslation → KILLED
        organization.setOrgTranslation(orgTranslation);
102 1 1. postOrganization : removed call to edu/ucsb/cs156/example/entities/UCSBOrganizations::setInactive → KILLED
        organization.setInactive(inactive);
103
        UCSBOrganizations savedOrganizations = ucsbOrganizationsRepository.save(organization);
104
105 1 1. postOrganization : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBOrganizationsController::postOrganization → KILLED
        return savedOrganizations;
106
    }
107
108
    @Operation(summary = "Delete a UCSBDOrganizations")
109
    @PreAuthorize("hasRole('ROLE_ADMIN')")
110
    @DeleteMapping("")
111
    public Object deleteOrganizations(
112
            @Parameter(name = "orgCode") @RequestParam String orgCode) {
113
        UCSBOrganizations organizations = ucsbOrganizationsRepository.findById(orgCode)
114 1 1. lambda$deleteOrganizations$2 : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBOrganizationsController::lambda$deleteOrganizations$2 → KILLED
                .orElseThrow(() -> new EntityNotFoundException(UCSBOrganizations.class, orgCode));
115
116 1 1. deleteOrganizations : removed call to edu/ucsb/cs156/example/repositories/UCSBOrganizationsRepository::delete → KILLED
        ucsbOrganizationsRepository.delete(organizations);
117 1 1. deleteOrganizations : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBOrganizationsController::deleteOrganizations → KILLED
        return genericMessage("UCSBOrganizations with id %s deleted".formatted(orgCode));
118
    }
119
}

Mutations

44

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_ucsborganizations()]
replaced return value with Collections.emptyList for edu/ucsb/cs156/example/controllers/UCSBOrganizationsController::allOrganizations → KILLED

57

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

58

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

76

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

79

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

80

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

81

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

85

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

99

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

100

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

101

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

102

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

105

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

114

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

116

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

117

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

Active mutators

Tests examined


Report generated by PIT 1.17.0