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
import io.swagger.v3.oas.annotations.Operation;
7
import io.swagger.v3.oas.annotations.Parameter;
8
import io.swagger.v3.oas.annotations.tags.Tag;
9
import jakarta.validation.Valid;
10
import lombok.extern.slf4j.Slf4j;
11
import org.springframework.beans.factory.annotation.Autowired;
12
import org.springframework.security.access.prepost.PreAuthorize;
13
import org.springframework.web.bind.annotation.DeleteMapping;
14
import org.springframework.web.bind.annotation.GetMapping;
15
import org.springframework.web.bind.annotation.PostMapping;
16
import org.springframework.web.bind.annotation.PutMapping;
17
import org.springframework.web.bind.annotation.RequestBody;
18
import org.springframework.web.bind.annotation.RequestMapping;
19
import org.springframework.web.bind.annotation.RequestParam;
20
import org.springframework.web.bind.annotation.RestController;
21
22
/** This is a REST controller for UCSBOrganization */
23
@Tag(name = "UCSBOrganization")
24
@RequestMapping("/api/UCSBOrganization")
25
@RestController
26
@Slf4j
27
public class UCSBOrganizationController extends ApiController {
28
29
  @Autowired UCSBOrganizationRepository ucsbOrganizationRepository;
30
31
  /**
32
   * List all UCSBOrganizations
33
   *
34
   * @return an iterable of UCSBOrganizations
35
   */
36
  @Operation(summary = "List all ucsb organizations")
37
  @PreAuthorize("hasRole('ROLE_USER')")
38
  @GetMapping("/all")
39
  public Iterable<UCSBOrganization> allUCSBOrganizations() {
40 1 1. allUCSBOrganizations : replaced return value with Collections.emptyList for edu/ucsb/cs156/example/controllers/UCSBOrganizationController::allUCSBOrganizations → KILLED
    return ucsbOrganizationRepository.findAll();
41
  }
42
43
  /**
44
   * Update a single UCSBOrganization. Accessible only to users with the role "ROLE_ADMIN".
45
   *
46
   * @param orgCode organization code (primary key)
47
   * @param incoming the new organization contents (orgCode is ignored)
48
   * @return the updated organization object
49
   */
50
  @Operation(summary = "Update a single ucsb organization")
51
  @PreAuthorize("hasRole('ROLE_ADMIN')")
52
  @PutMapping("")
53
  public UCSBOrganization updateUCSBOrganization(
54
      @Parameter(name = "orgCode") @RequestParam(name = "orgCode") String orgCode,
55
      @RequestBody @Valid UCSBOrganization incoming) {
56
57
    UCSBOrganization org =
58
        ucsbOrganizationRepository
59
            .findById(orgCode)
60 1 1. lambda$updateUCSBOrganization$0 : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBOrganizationController::lambda$updateUCSBOrganization$0 → KILLED
            .orElseThrow(() -> new EntityNotFoundException(UCSBOrganization.class, orgCode));
61
62 1 1. updateUCSBOrganization : removed call to edu/ucsb/cs156/example/entities/UCSBOrganization::setOrgTranslationShort → KILLED
    org.setOrgTranslationShort(incoming.getOrgTranslationShort());
63 1 1. updateUCSBOrganization : removed call to edu/ucsb/cs156/example/entities/UCSBOrganization::setOrgTranslation → KILLED
    org.setOrgTranslation(incoming.getOrgTranslation());
64 1 1. updateUCSBOrganization : removed call to edu/ucsb/cs156/example/entities/UCSBOrganization::setInactive → KILLED
    org.setInactive(incoming.getInactive());
65
66
    ucsbOrganizationRepository.save(org);
67
68 1 1. updateUCSBOrganization : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBOrganizationController::updateUCSBOrganization → KILLED
    return org;
69
  }
70
71
  /**
72
   * Get a single UCSBOrganization by id
73
   *
74
   * @param orgCode organization code (primary key)
75
   * @return the UCSBOrganization with the given code
76
   */
77
  @Operation(summary = "Get a single ucsb organization")
78
  @PreAuthorize("hasRole('ROLE_USER')")
79
  @GetMapping("")
80
  public UCSBOrganization getById(
81
      @Parameter(name = "orgCode") @RequestParam(name = "orgCode") String orgCode) {
82
    UCSBOrganization org =
83
        ucsbOrganizationRepository
84
            .findById(orgCode)
85 1 1. lambda$getById$1 : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBOrganizationController::lambda$getById$1 → KILLED
            .orElseThrow(() -> new EntityNotFoundException(UCSBOrganization.class, orgCode));
86 1 1. getById : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBOrganizationController::getById → KILLED
    return org;
87
  }
88
89
  /**
90
   * Delete a UCSBOrganization. Accessible only to users with the role "ROLE_ADMIN".
91
   *
92
   * @param orgCode organization code (primary key)
93
   * @return a message indicating the organization was deleted
94
   */
95
  @Operation(summary = "Delete a UCSBOrganization")
96
  @PreAuthorize("hasRole('ROLE_ADMIN')")
97
  @DeleteMapping("")
98
  public Object deleteUCSBOrganization(
99
      @Parameter(name = "orgCode") @RequestParam(name = "orgCode") String orgCode) {
100
    UCSBOrganization org =
101
        ucsbOrganizationRepository
102
            .findById(orgCode)
103 1 1. lambda$deleteUCSBOrganization$2 : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBOrganizationController::lambda$deleteUCSBOrganization$2 → KILLED
            .orElseThrow(() -> new EntityNotFoundException(UCSBOrganization.class, orgCode));
104 1 1. deleteUCSBOrganization : removed call to edu/ucsb/cs156/example/repositories/UCSBOrganizationRepository::delete → KILLED
    ucsbOrganizationRepository.delete(org);
105 1 1. deleteUCSBOrganization : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBOrganizationController::deleteUCSBOrganization → KILLED
    return genericMessage("UCSBOrganization with id %s deleted".formatted(orgCode));
106
  }
107
108
  /**
109
   * Create a new UCSBOrganization
110
   *
111
   * @param orgCode organization code (primary key)
112
   * @param orgTranslationShort short translation for organization name
113
   * @param orgTranslation full translation for organization name
114
   * @param inactive whether the organization is inactive
115
   * @return the saved UCSBOrganization
116
   */
117
  @Operation(summary = "Create a new ucsb organization")
118
  @PreAuthorize("hasRole('ROLE_ADMIN')")
119
  @PostMapping("/post")
120
  public UCSBOrganization postUCSBOrganization(
121
      @Parameter(name = "orgCode") @RequestParam String orgCode,
122
      @Parameter(name = "orgTranslationShort") @RequestParam String orgTranslationShort,
123
      @Parameter(name = "orgTranslation") @RequestParam String orgTranslation,
124
      @Parameter(name = "inactive") @RequestParam boolean inactive) {
125
126
    UCSBOrganization org = new UCSBOrganization();
127 1 1. postUCSBOrganization : removed call to edu/ucsb/cs156/example/entities/UCSBOrganization::setOrgCode → KILLED
    org.setOrgCode(orgCode);
128 1 1. postUCSBOrganization : removed call to edu/ucsb/cs156/example/entities/UCSBOrganization::setOrgTranslationShort → KILLED
    org.setOrgTranslationShort(orgTranslationShort);
129 1 1. postUCSBOrganization : removed call to edu/ucsb/cs156/example/entities/UCSBOrganization::setOrgTranslation → KILLED
    org.setOrgTranslation(orgTranslation);
130 1 1. postUCSBOrganization : removed call to edu/ucsb/cs156/example/entities/UCSBOrganization::setInactive → KILLED
    org.setInactive(inactive);
131
132 1 1. postUCSBOrganization : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBOrganizationController::postUCSBOrganization → KILLED
    return ucsbOrganizationRepository.save(org);
133
  }
134
}

Mutations

40

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

60

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

62

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

63

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

64

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

68

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

85

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

86

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

103

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

104

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

105

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

127

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

128

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

129

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

130

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

132

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

Active mutators

Tests examined


Report generated by PIT 1.17.0