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

Mutations

40

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

56

1.1
Location : lambda$getById$0
Killed by : edu.ucsb.cs156.example.controllers.UCSBOrganizationControllerTest.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.UCSBOrganizationControllerTest]/[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

58

1.1
Location : getById
Killed by : edu.ucsb.cs156.example.controllers.UCSBOrganizationControllerTest.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.UCSBOrganizationControllerTest]/[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

80

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

81

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

82

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

83

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

87

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

103

1.1
Location : lambda$deleteOrganization$1
Killed by : edu.ucsb.cs156.example.controllers.UCSBOrganizationControllerTest.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.UCSBOrganizationControllerTest]/[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$1 → KILLED

105

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

106

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

126

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

128

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

129

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

130

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

131

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

135

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

Active mutators

Tests examined


Report generated by PIT 1.17.0