UCSBOrganizationController.java

1
package edu.ucsb.cs156.example.controllers;
2
3
import edu.ucsb.cs156.example.entities.UCSBDate;
4
import edu.ucsb.cs156.example.entities.UCSBDiningCommons;
5
import edu.ucsb.cs156.example.entities.UCSBOrganization;
6
import edu.ucsb.cs156.example.errors.EntityNotFoundException;
7
import edu.ucsb.cs156.example.repositories.UCSBDiningCommonsRepository;
8
import edu.ucsb.cs156.example.repositories.UCSBOrganizationRepository;
9
import io.swagger.v3.oas.annotations.Operation;
10
import io.swagger.v3.oas.annotations.Parameter;
11
import io.swagger.v3.oas.annotations.tags.Tag;
12
import lombok.extern.slf4j.Slf4j;
13
14
import org.springframework.beans.factory.annotation.Autowired;
15
import org.springframework.security.access.prepost.PreAuthorize;
16
import org.springframework.web.bind.annotation.DeleteMapping;
17
import org.springframework.web.bind.annotation.GetMapping;
18
import org.springframework.web.bind.annotation.PostMapping;
19
import org.springframework.web.bind.annotation.PutMapping;
20
import org.springframework.web.bind.annotation.RequestBody;
21
import org.springframework.web.bind.annotation.RequestMapping;
22
import org.springframework.web.bind.annotation.RequestParam;
23
import org.springframework.web.bind.annotation.RestController;
24
25
import jakarta.validation.Valid;
26
27
@Tag(name = "UCSBOrganization")
28
@RequestMapping("/api/ucsborganization")
29
@RestController
30
@Slf4j
31
public class UCSBOrganizationController extends ApiController {
32
33
    @Autowired
34
    UCSBOrganizationRepository ucsbOrganizationRepository;
35
36
    /**
37
     * List all UCSB organizations
38
     * 
39
     * @return an iterable of UCSBOrganization
40
     */
41
42
    @Operation(summary = "List all UCSB organizations")
43
    @PreAuthorize("hasRole('ROLE_USER')")
44
    @GetMapping("/all")
45
    public Iterable<UCSBOrganization> allOrganizations() {
46
        Iterable<UCSBOrganization> organizations = ucsbOrganizationRepository.findAll();
47 1 1. allOrganizations : replaced return value with Collections.emptyList for edu/ucsb/cs156/example/controllers/UCSBOrganizationController::allOrganizations → KILLED
        return organizations;
48
    }
49
50
    @Operation(summary = "Create a new organization")
51
    @PreAuthorize("hasRole('ROLE_ADMIN')")
52
    @PostMapping("/post")
53
    public UCSBOrganization postOrganization(
54
            @Parameter(name = "orgCode") @RequestParam String orgCode,
55
            @Parameter(name = "orgTranslationShort") @RequestParam String orgTranslationShort,
56
            @Parameter(name = "orgTranslation") @RequestParam String orgTranslation,
57
            @Parameter(name = "inactive") @RequestParam boolean inactive) {
58
59
        UCSBOrganization organization = new UCSBOrganization();
60 1 1. postOrganization : removed call to edu/ucsb/cs156/example/entities/UCSBOrganization::setOrgCode → KILLED
        organization.setOrgCode(orgCode);
61 1 1. postOrganization : removed call to edu/ucsb/cs156/example/entities/UCSBOrganization::setOrgTranslationShort → KILLED
        organization.setOrgTranslationShort(orgTranslationShort);
62 1 1. postOrganization : removed call to edu/ucsb/cs156/example/entities/UCSBOrganization::setOrgTranslation → KILLED
        organization.setOrgTranslation(orgTranslation);
63 1 1. postOrganization : removed call to edu/ucsb/cs156/example/entities/UCSBOrganization::setInactive → KILLED
        organization.setInactive(inactive);
64
65
        UCSBOrganization savedOrganization = ucsbOrganizationRepository.save(organization);
66
67 1 1. postOrganization : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBOrganizationController::postOrganization → KILLED
        return savedOrganization;
68
    }
69
70
    @Operation(summary = "Get a single UCSB organization by id (@Id)")
71
    @PreAuthorize("hasRole('ROLE_USER')")
72
    @GetMapping("")
73
    public UCSBOrganization getById(
74
            @Parameter(name = "id") @RequestParam String id) {
75
        UCSBOrganization organization = ucsbOrganizationRepository
76
                .findById(id)
77 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, id));
78 1 1. getById : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBOrganizationController::getById → KILLED
        return organization;
79
    }
80
81
    @Operation(summary = "Update a single organization")
82
    @PreAuthorize("hasRole('ROLE_ADMIN')")
83
    @PutMapping("")
84
    public UCSBOrganization updateOrganization(
85
            @Parameter(name = "id") @RequestParam String id,
86
            @RequestBody @Valid UCSBOrganization incoming) {
87
88
        UCSBOrganization organization = ucsbOrganizationRepository.findById(id)
89 1 1. lambda$updateOrganization$1 : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBOrganizationController::lambda$updateOrganization$1 → KILLED
                .orElseThrow(() -> new EntityNotFoundException(UCSBOrganization.class, id));
90
91
        // Remove this line since we don't want to change the ID
92
        // organization.setOrgCode(incoming.getOrgCode());
93
94 1 1. updateOrganization : removed call to edu/ucsb/cs156/example/entities/UCSBOrganization::setOrgTranslationShort → KILLED
        organization.setOrgTranslationShort(incoming.getOrgTranslationShort());
95 1 1. updateOrganization : removed call to edu/ucsb/cs156/example/entities/UCSBOrganization::setOrgTranslation → KILLED
        organization.setOrgTranslation(incoming.getOrgTranslation());
96 1 1. updateOrganization : removed call to edu/ucsb/cs156/example/entities/UCSBOrganization::setInactive → KILLED
        organization.setInactive(incoming.getInactive());
97
98
        ucsbOrganizationRepository.save(organization);
99
100 1 1. updateOrganization : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBOrganizationController::updateOrganization → KILLED
        return organization;
101
    }
102
103
    @Operation(summary = "Delete a UCSB Organization")
104
    @PreAuthorize("hasRole('ROLE_ADMIN')")
105
    @DeleteMapping("")
106
    public Object deleteOrganization(
107
            @Parameter(name = "id") @RequestParam String id) {
108
        UCSBOrganization organization = ucsbOrganizationRepository.findById(id)
109 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, id));
110
111 1 1. deleteOrganization : removed call to edu/ucsb/cs156/example/repositories/UCSBOrganizationRepository::delete → KILLED
        ucsbOrganizationRepository.delete(organization);
112 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(id));
113
    }
114
115
}

Mutations

47

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

60

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

61

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

62

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

63

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

67

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

77

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_get_organization_that_does_not_exist()]
replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBOrganizationController::lambda$getById$0 → KILLED

78

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

89

1.1
Location : lambda$updateOrganization$1
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$updateOrganization$1 → KILLED

94

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

95

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

96

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

100

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

109

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

111

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

112

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

Active mutators

Tests examined


Report generated by PIT 1.17.0