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 java.util.Map;
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/ucsborganizations")
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
    Iterable<UCSBOrganization> orgs = ucsbOrganizationRepository.findAll();
35 1 1. allOrganizations : replaced return value with Collections.emptyList for edu/ucsb/cs156/example/controllers/UCSBOrganizationController::allOrganizations → KILLED
    return orgs;
36
  }
37
38
  @Operation(summary = "Create a new UCSBOrganization")
39
  @PreAuthorize("hasRole('ROLE_ADMIN')")
40
  @PostMapping("/post")
41
  public UCSBOrganization postOrganization(
42
      @Parameter(name = "orgCode") @RequestParam String orgCode,
43
      @Parameter(name = "orgTranslationShort") @RequestParam String orgTranslationShort,
44
      @Parameter(name = "orgTranslation") @RequestParam String orgTranslation,
45
      @Parameter(name = "inactive") @RequestParam boolean inactive) {
46
47
    UCSBOrganization org = new UCSBOrganization();
48 1 1. postOrganization : removed call to edu/ucsb/cs156/example/entities/UCSBOrganization::setOrgCode → KILLED
    org.setOrgCode(orgCode);
49 1 1. postOrganization : removed call to edu/ucsb/cs156/example/entities/UCSBOrganization::setOrgTranslationShort → KILLED
    org.setOrgTranslationShort(orgTranslationShort);
50 1 1. postOrganization : removed call to edu/ucsb/cs156/example/entities/UCSBOrganization::setOrgTranslation → KILLED
    org.setOrgTranslation(orgTranslation);
51 1 1. postOrganization : removed call to edu/ucsb/cs156/example/entities/UCSBOrganization::setInactive → KILLED
    org.setInactive(inactive);
52
53
    UCSBOrganization saved = ucsbOrganizationRepository.save(org);
54 1 1. postOrganization : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBOrganizationController::postOrganization → KILLED
    return saved;
55
  }
56
57
  // get addtionals
58
  @Operation(summary = "Get a single organization by orgCode")
59
  @PreAuthorize("hasRole('ROLE_USER')")
60
  @GetMapping("")
61
  public UCSBOrganization getById(@Parameter(name = "orgCode") @RequestParam String orgCode) {
62 1 1. getById : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBOrganizationController::getById → KILLED
    return ucsbOrganizationRepository
63
        .findById(orgCode)
64 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));
65
  }
66
67
  // put endpoint
68
  @Operation(summary = "Update a single organization")
69
  @PreAuthorize("hasRole('ROLE_ADMIN')")
70
  @PutMapping("")
71
  public UCSBOrganization updateOrganization(
72
      @Parameter(name = "orgCode") @RequestParam String orgCode,
73
      @RequestBody UCSBOrganization incoming) {
74
    UCSBOrganization org =
75
        ucsbOrganizationRepository
76
            .findById(orgCode)
77 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));
78 1 1. updateOrganization : removed call to edu/ucsb/cs156/example/entities/UCSBOrganization::setOrgTranslationShort → KILLED
    org.setOrgTranslationShort(incoming.getOrgTranslationShort());
79 1 1. updateOrganization : removed call to edu/ucsb/cs156/example/entities/UCSBOrganization::setOrgTranslation → KILLED
    org.setOrgTranslation(incoming.getOrgTranslation());
80 1 1. updateOrganization : removed call to edu/ucsb/cs156/example/entities/UCSBOrganization::setInactive → KILLED
    org.setInactive(incoming.getInactive());
81
    UCSBOrganization saved = ucsbOrganizationRepository.save(org);
82 1 1. updateOrganization : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBOrganizationController::updateOrganization → KILLED
    return saved;
83
  }
84
85
  // delete endpoint
86
  @Operation(summary = "Delete a single organization by orgCode")
87
  @PreAuthorize("hasRole('ROLE_ADMIN')")
88
  @DeleteMapping("")
89
  public Object deleteOrganization(@Parameter(name = "orgCode") @RequestParam String orgCode) {
90
91
    UCSBOrganization org =
92
        ucsbOrganizationRepository
93
            .findById(orgCode)
94 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));
95 1 1. deleteOrganization : removed call to edu/ucsb/cs156/example/repositories/UCSBOrganizationRepository::delete → KILLED
    ucsbOrganizationRepository.delete(org);
96 1 1. deleteOrganization : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBOrganizationController::deleteOrganization → KILLED
    return Map.of("message", String.format("UCSBOrganization with id %s deleted", orgCode));
97
  }
98
}

Mutations

35

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

48

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

49

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

50

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

51

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

54

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

62

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

64

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

77

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

78

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

79

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

80

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

82

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

94

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

95

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

96

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