UCSBOrganizationController.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.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
/**
26
 * This is a REST controller for UCSBOrganizations
27
 */
28
29
@Tag(name = "UCSBOrganization")
30
@RequestMapping("/api/ucsborganizations")
31
@RestController
32
@Slf4j 
33
34
public class UCSBOrganizationController extends ApiController{
35
36
    @Autowired
37
    UCSBOrganizationRepository ucsbOrganizationRepository;
38
39
    /**
40
     * THis method returns a list of all ucsborganizations.
41
     * @return a list of all ucsborganizations
42
     */
43
    @Operation(summary= "List all ucsb organizations")
44
    @PreAuthorize("hasRole('ROLE_USER')")
45
    @GetMapping("/all")
46
    public Iterable<UCSBOrganization> allOrganizations() {
47
        Iterable<UCSBOrganization> organizations = ucsbOrganizationRepository.findAll();
48 1 1. allOrganizations : replaced return value with Collections.emptyList for edu/ucsb/cs156/example/controllers/UCSBOrganizationController::allOrganizations → KILLED
        return organizations;
49
    }
50
51
    /**
52
     * This method creates a new organization. Accessible only to users with the role "ROLE_ADMIN".
53
     * @param orgCode code of the the ucsborganization
54
     * @param orgTranslationShort the short string of the ucsborganization
55
     * @param orgTranslation the whole string(name) of the ucsborganization
56
     * @param inactive whether or not the ucsborganization is inactive 
57
     * @return the save ucsborganization
58
     */
59
    @Operation(summary= "Create a new organization")
60
    @PreAuthorize("hasRole('ROLE_ADMIN')")
61
    @PostMapping("/post")
62
    public UCSBOrganization postOrganization(
63
        @Parameter(name="orgCode") @RequestParam String orgCode,
64
        @Parameter(name="orgTranslationShort") @RequestParam String orgTranslationShort,
65
        @Parameter(name="orgTranslation") @RequestParam String orgTranslation,
66
        @Parameter(name="inactive") @RequestParam boolean inactive
67
        )
68
        {
69
70
        UCSBOrganization organization = new UCSBOrganization();
71 1 1. postOrganization : removed call to edu/ucsb/cs156/example/entities/UCSBOrganization::setOrgCode → KILLED
        organization.setOrgCode(orgCode);
72 1 1. postOrganization : removed call to edu/ucsb/cs156/example/entities/UCSBOrganization::setOrgTranslationShort → KILLED
        organization.setOrgTranslationShort(orgTranslationShort);
73 1 1. postOrganization : removed call to edu/ucsb/cs156/example/entities/UCSBOrganization::setOrgTranslation → KILLED
        organization.setOrgTranslation(orgTranslation);
74 1 1. postOrganization : removed call to edu/ucsb/cs156/example/entities/UCSBOrganization::setInactive → KILLED
        organization.setInactive(inactive);
75
76
        UCSBOrganization savedOrganization = ucsbOrganizationRepository.save(organization);
77
78 1 1. postOrganization : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBOrganizationController::postOrganization → KILLED
        return savedOrganization;
79
    }
80
81
    /**
82
     * This method returns a single organization.
83
     * @param orgCode code of the organization
84
     * @return a single diningcommons
85
     */
86
    @Operation(summary= "Get a single organization")
87
    @PreAuthorize("hasRole('ROLE_USER')")
88
    @GetMapping("")
89
    public UCSBOrganization getById(
90
            @Parameter(name="orgCode") @RequestParam String orgCode) {
91
        UCSBOrganization organizations = ucsbOrganizationRepository.findById(orgCode)
92 1 1. lambda$getById$0 : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBOrganizationController::lambda$getById$0 → KILLED
                .orElseThrow(() -> new EntityNotFoundException(UCSBOrganization.class, orgCode));
93
94 1 1. getById : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBOrganizationController::getById → KILLED
        return organizations;
95
    }
96
97
    /**
98
     * Update a single organization. Accessible only to users with the role "ROLE_ADMIN".
99
     * @param orgCode code of the organization
100
     * @param incoming the new organization contents
101
     * @return the updated commons object
102
     */
103
    @Operation(summary= "Update a single organization")
104
    @PreAuthorize("hasRole('ROLE_ADMIN')")
105
    @PutMapping("")
106
    public UCSBOrganization updateOrg(
107
            @Parameter(name="orgCode") @RequestParam String orgCode,
108
            @RequestBody @Valid UCSBOrganization incoming) {
109
110
        UCSBOrganization organization = ucsbOrganizationRepository.findById(orgCode)
111 1 1. lambda$updateOrg$1 : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBOrganizationController::lambda$updateOrg$1 → KILLED
                .orElseThrow(() -> new EntityNotFoundException(UCSBOrganization.class, orgCode));
112
113
  
114 1 1. updateOrg : removed call to edu/ucsb/cs156/example/entities/UCSBOrganization::setOrgTranslationShort → KILLED
        organization.setOrgTranslationShort(incoming.getOrgTranslationShort());
115 1 1. updateOrg : removed call to edu/ucsb/cs156/example/entities/UCSBOrganization::setOrgTranslation → KILLED
        organization.setOrgTranslation(incoming.getOrgTranslation());
116 1 1. updateOrg : removed call to edu/ucsb/cs156/example/entities/UCSBOrganization::setInactive → KILLED
        organization.setInactive(incoming.getInactive());
117
        ucsbOrganizationRepository.save(organization);
118
119 1 1. updateOrg : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBOrganizationController::updateOrg → KILLED
        return organization;
120
    }
121
122
    /**
123
     * Delete an organization. Accessible only to users with the role "ROLE_ADMIN".
124
     * @param orgCode code of the organization
125
     * @return a message indiciating the organization was deleted
126
     */
127
    @Operation(summary= "Delete a UCSBOrganization")
128
    @PreAuthorize("hasRole('ROLE_ADMIN')")
129
    @DeleteMapping("")
130
    public Object deleteOrganization(
131
            @Parameter(name="orgCode") @RequestParam String orgCode) {
132
        UCSBOrganization organization = ucsbOrganizationRepository.findById(orgCode)
133 1 1. lambda$deleteOrganization$2 : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBOrganizationController::lambda$deleteOrganization$2 → KILLED
                .orElseThrow(() -> new EntityNotFoundException(UCSBOrganization.class, orgCode));
134
135 1 1. deleteOrganization : removed call to edu/ucsb/cs156/example/repositories/UCSBOrganizationRepository::delete → KILLED
        ucsbOrganizationRepository.delete(organization);
136 1 1. deleteOrganization : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBOrganizationController::deleteOrganization → KILLED
        return genericMessage("UCSBOrganization with id %s deleted".formatted(orgCode));
137
    }
138
139
140
141
}

Mutations

48

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

71

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

72

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

73

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

74

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

78

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

92

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

94

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

111

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

114

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

115

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

116

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

119

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

133

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

135

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

136

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

Active mutators

Tests examined


Report generated by PIT 1.17.0