UCSBOrganizationController.java

1
package edu.ucsb.cs156.example.controllers;
2
3
import edu.ucsb.cs156.example.entities.UCSBDiningCommons;
4
import edu.ucsb.cs156.example.entities.UCSBOrganization;
5
import edu.ucsb.cs156.example.errors.EntityNotFoundException;
6
import edu.ucsb.cs156.example.repositories.UCSBDiningCommonsRepository;
7
import edu.ucsb.cs156.example.repositories.UCSBOrganizationRepository;
8
import io.swagger.v3.oas.annotations.Operation;
9
import io.swagger.v3.oas.annotations.Parameter;
10
import io.swagger.v3.oas.annotations.tags.Tag;
11
import lombok.extern.slf4j.Slf4j;
12
13
import java.util.Collections;
14
15
import org.springframework.beans.factory.annotation.Autowired;
16
import org.springframework.security.access.prepost.PreAuthorize;
17
import org.springframework.web.bind.annotation.DeleteMapping;
18
import org.springframework.web.bind.annotation.GetMapping;
19
import org.springframework.web.bind.annotation.PostMapping;
20
import org.springframework.web.bind.annotation.PutMapping;
21
import org.springframework.web.bind.annotation.RequestBody;
22
import org.springframework.web.bind.annotation.RequestMapping;
23
import org.springframework.web.bind.annotation.RequestParam;
24
import org.springframework.web.bind.annotation.RestController;
25
26
import jakarta.validation.Valid;
27
28
@Tag(name = "UCSBOrganizations")
29
@RequestMapping("/api/ucsborganizations")
30
@RestController
31
@Slf4j
32
public class UCSBOrganizationController extends ApiController {
33
    
34
    @Autowired
35
    UCSBOrganizationRepository ucsbOrganizationRepository;
36
37
    // GET request for all organizations in the database
38
    @Operation(summary= "List all ucsb organizations")
39
    @PreAuthorize("hasRole('ROLE_USER')")
40
    @GetMapping("/all")
41
    public Iterable<UCSBOrganization> allOrganizations() {
42
        Iterable<UCSBOrganization> organizations = ucsbOrganizationRepository.findAll();
43 1 1. allOrganizations : replaced return value with Collections.emptyList for edu/ucsb/cs156/example/controllers/UCSBOrganizationController::allOrganizations → KILLED
        return organizations;
44
    }
45
46
    // GET request for specific organization by org field (id)
47
    @Operation(summary= "Get a single organization")
48
    @PreAuthorize("hasRole('ROLE_USER')")
49
    @GetMapping("")
50
    public UCSBOrganization getById(
51
            @Parameter(name="orgField") @RequestParam String orgField) {
52
        UCSBOrganization organization = ucsbOrganizationRepository.findById(orgField)
53 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, orgField));
54
55 1 1. getById : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBOrganizationController::getById → KILLED
        return organization;
56
    }
57
58
    // POST request to add a new organization to the database
59
    @Operation(summary="Create a new organization")
60
    @PreAuthorize("hasRole('ROLE_ADMIN')")
61
    @PostMapping("/post")
62
    public UCSBOrganization postOrganization(
63
        @Parameter(name="orgField") @RequestParam String orgField,
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::setOrgField → KILLED
        organization.setOrgField(orgField);
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
    // DELETE request to delete a single record by id
82
    @Operation(summary= "Delete a UCSBOrganization")
83
    @PreAuthorize("hasRole('ROLE_ADMIN')")
84
    @DeleteMapping("")
85
    public Object deleteOrganization(
86
            @Parameter(name="orgField") @RequestParam String orgField) {
87
        UCSBOrganization organization = ucsbOrganizationRepository.findById(orgField)
88 1 1. lambda$deleteOrganization$1 : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBOrganizationController::lambda$deleteOrganization$1 → KILLED
                .orElseThrow(() -> new EntityNotFoundException(UCSBOrganization.class, orgField));
89
90 1 1. deleteOrganization : removed call to edu/ucsb/cs156/example/repositories/UCSBOrganizationRepository::delete → KILLED
        ucsbOrganizationRepository.delete(organization);
91 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(orgField));
92
    }
93
94
    // PUT request to update single organization record
95
    @Operation(summary= "Update a single organization")
96
    @PreAuthorize("hasRole('ROLE_ADMIN')")
97
    @PutMapping("")
98
    public UCSBOrganization updateCommons(
99
            @Parameter(name="orgField") @RequestParam String orgField,
100
            @RequestBody @Valid UCSBOrganization incoming) {
101
102
        UCSBOrganization organization = ucsbOrganizationRepository.findById(orgField)
103 1 1. lambda$updateCommons$2 : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBOrganizationController::lambda$updateCommons$2 → KILLED
                .orElseThrow(() -> new EntityNotFoundException(UCSBOrganization.class, orgField));
104
105 1 1. updateCommons : removed call to edu/ucsb/cs156/example/entities/UCSBOrganization::setOrgField → KILLED
        organization.setOrgField(incoming.getOrgField());
106 1 1. updateCommons : removed call to edu/ucsb/cs156/example/entities/UCSBOrganization::setOrgTranslationShort → KILLED
        organization.setOrgTranslationShort(incoming.getOrgTranslationShort());
107 1 1. updateCommons : removed call to edu/ucsb/cs156/example/entities/UCSBOrganization::setOrgTranslation → KILLED
        organization.setOrgTranslation(incoming.getOrgTranslation());
108 1 1. updateCommons : removed call to edu/ucsb/cs156/example/entities/UCSBOrganization::setInactive → KILLED
        organization.setInactive(incoming.getInactive());
109
110
        ucsbOrganizationRepository.save(organization);
111
112 1 1. updateCommons : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBOrganizationController::updateCommons → KILLED
        return organization;
113
    }
114
}

Mutations

43

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

53

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

55

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

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::setOrgField → 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_a_new_organization()]
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

88

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

90

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_an_organization()]
removed call to edu/ucsb/cs156/example/repositories/UCSBOrganizationRepository::delete → KILLED

91

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

103

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

105

1.1
Location : updateCommons
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::setOrgField → KILLED

106

1.1
Location : updateCommons
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

107

1.1
Location : updateCommons
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

108

1.1
Location : updateCommons
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

112

1.1
Location : updateCommons
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::updateCommons → KILLED

Active mutators

Tests examined


Report generated by PIT 1.17.0