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

Mutations

41

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

57

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

59

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

81

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

82

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

83

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

84

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

88

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

108

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

110

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

111

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

112

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

116

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

132

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

134

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

135

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