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

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

73

1.1
Location : postOrganizations
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_organizations()]
removed call to edu/ucsb/cs156/example/entities/UCSBOrganization::setOrgCode → KILLED

74

1.1
Location : postOrganizations
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_organizations()]
removed call to edu/ucsb/cs156/example/entities/UCSBOrganization::setOrgTranslationShort → KILLED

75

1.1
Location : postOrganizations
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_organizations()]
removed call to edu/ucsb/cs156/example/entities/UCSBOrganization::setOrgTranslation → KILLED

76

1.1
Location : postOrganizations
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_organizations()]
removed call to edu/ucsb/cs156/example/entities/UCSBOrganization::setInactive → KILLED

80

1.1
Location : postOrganizations
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_organizations()]
replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBOrganizationController::postOrganizations → KILLED

94

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

96

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

114

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

117

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

118

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

119

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

120

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

124

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

138

1.1
Location : lambda$deleteOrganizations$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_organizations_and_gets_right_error_message()]
replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBOrganizationController::lambda$deleteOrganizations$2 → KILLED

140

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

141

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

Active mutators

Tests examined


Report generated by PIT 1.17.0