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 lombok.extern.slf4j.Slf4j;
10
import org.springframework.beans.factory.annotation.Autowired;
11
import org.springframework.security.access.prepost.PreAuthorize;
12
import org.springframework.web.bind.annotation.DeleteMapping;
13
import org.springframework.web.bind.annotation.GetMapping;
14
import org.springframework.web.bind.annotation.PostMapping;
15
import org.springframework.web.bind.annotation.PutMapping;
16
import org.springframework.web.bind.annotation.RequestBody;
17
import org.springframework.web.bind.annotation.RequestMapping;
18
import org.springframework.web.bind.annotation.RequestParam;
19
import org.springframework.web.bind.annotation.RestController;
20
21
/** This is a REST controller for UCSBOrganization */
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
  @Operation(summary = "List all ucsb organizations")
31
  @PreAuthorize("hasRole('ROLE_USER')")
32
  @GetMapping("/all")
33
  public Iterable<UCSBOrganization> allOrganizations() {
34 1 1. allOrganizations : replaced return value with Collections.emptyList for edu/ucsb/cs156/example/controllers/UCSBOrganizationController::allOrganizations → KILLED
    return ucsbOrganizationRepository.findAll();
35
  }
36
37
  @Operation(summary = "Get a single record from the table")
38
  @PreAuthorize("hasRole('ROLE_USER')")
39
  @GetMapping("")
40
  public UCSBOrganization getById(
41
      @Parameter(name = "orgCode", description = "The unique organization code, e.g. 'ZPR'")
42
          @RequestParam
43
          String orgCode) {
44
    UCSBOrganization organization =
45
        ucsbOrganizationRepository
46
            .findById(orgCode)
47 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));
48
49 1 1. getById : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBOrganizationController::getById → KILLED
    return organization;
50
  }
51
52
  @Operation(summary = "Create a new organization")
53
  @PreAuthorize("hasRole('ROLE_ADMIN')")
54
  @PostMapping("/post")
55
  public UCSBOrganization postOrganization(
56
      @Parameter(name = "orgCode") @RequestParam String orgCode,
57
      @Parameter(name = "orgTranslationShort") @RequestParam String orgTranslationShort,
58
      @Parameter(name = "orgTranslation") @RequestParam String orgTranslation,
59
      @Parameter(name = "inactive") @RequestParam boolean inactive) {
60
61
    UCSBOrganization organization = new UCSBOrganization();
62 1 1. postOrganization : removed call to edu/ucsb/cs156/example/entities/UCSBOrganization::setOrgCode → KILLED
    organization.setOrgCode(orgCode);
63 1 1. postOrganization : removed call to edu/ucsb/cs156/example/entities/UCSBOrganization::setOrgTranslationShort → KILLED
    organization.setOrgTranslationShort(orgTranslationShort);
64 1 1. postOrganization : removed call to edu/ucsb/cs156/example/entities/UCSBOrganization::setOrgTranslation → KILLED
    organization.setOrgTranslation(orgTranslation);
65 1 1. postOrganization : removed call to edu/ucsb/cs156/example/entities/UCSBOrganization::setInactive → KILLED
    organization.setInactive(inactive);
66
67 1 1. postOrganization : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBOrganizationController::postOrganization → KILLED
    return ucsbOrganizationRepository.save(organization);
68
  }
69
70
  @Operation(summary = "Update a single organization")
71
  @PreAuthorize("hasRole('ROLE_ADMIN')")
72
  @PutMapping("")
73
  public UCSBOrganization updateUCSBOrganization(
74
      @Parameter(name = "orgCode") @RequestParam String orgCode,
75
      @RequestBody UCSBOrganization incoming) {
76
77
    UCSBOrganization org =
78
        ucsbOrganizationRepository
79
            .findById(orgCode)
80 1 1. lambda$updateUCSBOrganization$1 : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBOrganizationController::lambda$updateUCSBOrganization$1 → KILLED
            .orElseThrow(() -> new EntityNotFoundException(UCSBOrganization.class, orgCode));
81
82 1 1. updateUCSBOrganization : removed call to edu/ucsb/cs156/example/entities/UCSBOrganization::setOrgTranslationShort → KILLED
    org.setOrgTranslationShort(incoming.getOrgTranslationShort());
83 1 1. updateUCSBOrganization : removed call to edu/ucsb/cs156/example/entities/UCSBOrganization::setOrgTranslation → KILLED
    org.setOrgTranslation(incoming.getOrgTranslation());
84 1 1. updateUCSBOrganization : removed call to edu/ucsb/cs156/example/entities/UCSBOrganization::setInactive → KILLED
    org.setInactive(incoming.getInactive());
85
86
    ucsbOrganizationRepository.save(org);
87
88 1 1. updateUCSBOrganization : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBOrganizationController::updateUCSBOrganization → KILLED
    return org;
89
  }
90
91
  @Operation(summary = "Delete a UCSBOrganization")
92
  @PreAuthorize("hasRole('ROLE_ADMIN')")
93
  @DeleteMapping("")
94
  public Object deleteUCSBOrganization(@Parameter(name = "orgCode") @RequestParam String orgCode) {
95
    UCSBOrganization org =
96
        ucsbOrganizationRepository
97
            .findById(orgCode)
98 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));
99
100 1 1. deleteUCSBOrganization : removed call to edu/ucsb/cs156/example/repositories/UCSBOrganizationRepository::delete → KILLED
    ucsbOrganizationRepository.delete(org);
101 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));
102
  }
103
}

Mutations

34

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

47

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

49

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_by_id_exists()]
replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBOrganizationController::getById → 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::setOrgCode → 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()]
removed call to edu/ucsb/cs156/example/entities/UCSBOrganization::setOrgTranslationShort → KILLED

64

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

65

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

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

80

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

82

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

83

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

84

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

88

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

98

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

100

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

101

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

Active mutators

Tests examined


Report generated by PIT 1.17.0