UCSBDiningCommonsMenuItemController.java

1
package edu.ucsb.cs156.example.controllers;
2
3
import com.fasterxml.jackson.core.JsonProcessingException;
4
import edu.ucsb.cs156.example.entities.UCSBDiningCommonsMenuItem;
5
import edu.ucsb.cs156.example.errors.EntityNotFoundException;
6
import edu.ucsb.cs156.example.repositories.UCSBDiningCommonsMenuItemRepository;
7
import io.swagger.v3.oas.annotations.Operation;
8
import io.swagger.v3.oas.annotations.Parameter;
9
import io.swagger.v3.oas.annotations.tags.Tag;
10
import jakarta.validation.Valid;
11
import lombok.extern.slf4j.Slf4j;
12
import org.springframework.beans.factory.annotation.Autowired;
13
import org.springframework.security.access.prepost.PreAuthorize;
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 = "UCSBDiningCommonsMenuItems")
23
@RequestMapping("/api/ucsb-dining-commons-menu-items")
24
@RestController
25
@Slf4j
26
public class UCSBDiningCommonsMenuItemController extends ApiController {
27
28
  @Autowired UCSBDiningCommonsMenuItemRepository ucsbDiningCommonsMenuItemRepository;
29
30
  @Operation(summary = "Get all UCSB Dining Commons Menu Items")
31
  @PreAuthorize("hasRole('ROLE_USER')")
32
  @GetMapping("/all")
33
  public Iterable<UCSBDiningCommonsMenuItem> allUCSBDiningCommonsMenuItems() {
34
    Iterable<UCSBDiningCommonsMenuItem> items = ucsbDiningCommonsMenuItemRepository.findAll();
35 1 1. allUCSBDiningCommonsMenuItems : replaced return value with Collections.emptyList for edu/ucsb/cs156/example/controllers/UCSBDiningCommonsMenuItemController::allUCSBDiningCommonsMenuItems → KILLED
    return items;
36
  }
37
38
  @Operation(summary = "Get a single UCSB Dining Commons Menu Item by id")
39
  @PreAuthorize("hasRole('ROLE_USER')")
40
  @GetMapping("")
41
  public UCSBDiningCommonsMenuItem getUCSBDiningCommonsMenuItemById(
42
      @Parameter(name = "id") @RequestParam Long id) {
43
    UCSBDiningCommonsMenuItem ucsbDiningCommonsMenuItem =
44
        ucsbDiningCommonsMenuItemRepository
45
            .findById(id)
46 1 1. lambda$getUCSBDiningCommonsMenuItemById$0 : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBDiningCommonsMenuItemController::lambda$getUCSBDiningCommonsMenuItemById$0 → KILLED
            .orElseThrow(() -> new EntityNotFoundException(UCSBDiningCommonsMenuItem.class, id));
47 1 1. getUCSBDiningCommonsMenuItemById : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBDiningCommonsMenuItemController::getUCSBDiningCommonsMenuItemById → KILLED
    return ucsbDiningCommonsMenuItem;
48
  }
49
50
  @Operation(summary = "Create a new UCSB Dining Commons Menu Item")
51
  @PreAuthorize("hasRole('ROLE_ADMIN')")
52
  @PostMapping("/post")
53
  public UCSBDiningCommonsMenuItem postUCSBDiningCommonsMenuItem(
54
      @Parameter(name = "name") @RequestParam String name,
55
      @Parameter(name = "diningCommonsCode") @RequestParam String diningCommonsCode,
56
      @Parameter(name = "station") @RequestParam String station)
57
      throws JsonProcessingException {
58
59
    UCSBDiningCommonsMenuItem ucsbDiningCommonsMenuItem = new UCSBDiningCommonsMenuItem();
60 1 1. postUCSBDiningCommonsMenuItem : removed call to edu/ucsb/cs156/example/entities/UCSBDiningCommonsMenuItem::setName → KILLED
    ucsbDiningCommonsMenuItem.setName(name);
61 1 1. postUCSBDiningCommonsMenuItem : removed call to edu/ucsb/cs156/example/entities/UCSBDiningCommonsMenuItem::setDiningCommonsCode → KILLED
    ucsbDiningCommonsMenuItem.setDiningCommonsCode(diningCommonsCode);
62 1 1. postUCSBDiningCommonsMenuItem : removed call to edu/ucsb/cs156/example/entities/UCSBDiningCommonsMenuItem::setStation → KILLED
    ucsbDiningCommonsMenuItem.setStation(station);
63
64
    UCSBDiningCommonsMenuItem savedUcsbDiningCommonsMenuItem =
65
        ucsbDiningCommonsMenuItemRepository.save(ucsbDiningCommonsMenuItem);
66
67 1 1. postUCSBDiningCommonsMenuItem : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBDiningCommonsMenuItemController::postUCSBDiningCommonsMenuItem → KILLED
    return savedUcsbDiningCommonsMenuItem;
68
  }
69
70
  /**
71
   * Update a single UCSB Dining Commons Menu Item
72
   *
73
   * @param id id of the menu item to update
74
   * @param incoming the new menu item
75
   * @return the updated menu item object
76
   */
77
  @Operation(summary = "Update a single UCSB Dining Commons Menu Item")
78
  @PreAuthorize("hasRole('ROLE_ADMIN')")
79
  @PutMapping("")
80
  public UCSBDiningCommonsMenuItem updateUCSBDiningCommonsMenuItem(
81
      @Parameter(name = "id") @RequestParam Long id,
82
      @RequestBody @Valid UCSBDiningCommonsMenuItem incoming) {
83
84
    UCSBDiningCommonsMenuItem ucsbDiningCommonsMenuItem =
85
        ucsbDiningCommonsMenuItemRepository
86
            .findById(id)
87 1 1. lambda$updateUCSBDiningCommonsMenuItem$1 : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBDiningCommonsMenuItemController::lambda$updateUCSBDiningCommonsMenuItem$1 → KILLED
            .orElseThrow(() -> new EntityNotFoundException(UCSBDiningCommonsMenuItem.class, id));
88
89 1 1. updateUCSBDiningCommonsMenuItem : removed call to edu/ucsb/cs156/example/entities/UCSBDiningCommonsMenuItem::setName → KILLED
    ucsbDiningCommonsMenuItem.setName(incoming.getName());
90 1 1. updateUCSBDiningCommonsMenuItem : removed call to edu/ucsb/cs156/example/entities/UCSBDiningCommonsMenuItem::setDiningCommonsCode → KILLED
    ucsbDiningCommonsMenuItem.setDiningCommonsCode(incoming.getDiningCommonsCode());
91 1 1. updateUCSBDiningCommonsMenuItem : removed call to edu/ucsb/cs156/example/entities/UCSBDiningCommonsMenuItem::setStation → KILLED
    ucsbDiningCommonsMenuItem.setStation(incoming.getStation());
92
93
    ucsbDiningCommonsMenuItemRepository.save(ucsbDiningCommonsMenuItem);
94
95 1 1. updateUCSBDiningCommonsMenuItem : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBDiningCommonsMenuItemController::updateUCSBDiningCommonsMenuItem → KILLED
    return ucsbDiningCommonsMenuItem;
96
  }
97
}

Mutations

35

1.1
Location : allUCSBDiningCommonsMenuItems
Killed by : edu.ucsb.cs156.example.controllers.UCSBDiningCommonsMenuItemControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.UCSBDiningCommonsMenuItemControllerTests]/[method:logged_in_user_can_get_all_ucsbmenuitems()]
replaced return value with Collections.emptyList for edu/ucsb/cs156/example/controllers/UCSBDiningCommonsMenuItemController::allUCSBDiningCommonsMenuItems → KILLED

46

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

47

1.1
Location : getUCSBDiningCommonsMenuItemById
Killed by : edu.ucsb.cs156.example.controllers.UCSBDiningCommonsMenuItemControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.UCSBDiningCommonsMenuItemControllerTests]/[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/UCSBDiningCommonsMenuItemController::getUCSBDiningCommonsMenuItemById → KILLED

60

1.1
Location : postUCSBDiningCommonsMenuItem
Killed by : edu.ucsb.cs156.example.controllers.UCSBDiningCommonsMenuItemControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.UCSBDiningCommonsMenuItemControllerTests]/[method:an_admin_user_can_post_a_new_menuitem()]
removed call to edu/ucsb/cs156/example/entities/UCSBDiningCommonsMenuItem::setName → KILLED

61

1.1
Location : postUCSBDiningCommonsMenuItem
Killed by : edu.ucsb.cs156.example.controllers.UCSBDiningCommonsMenuItemControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.UCSBDiningCommonsMenuItemControllerTests]/[method:an_admin_user_can_post_a_new_menuitem()]
removed call to edu/ucsb/cs156/example/entities/UCSBDiningCommonsMenuItem::setDiningCommonsCode → KILLED

62

1.1
Location : postUCSBDiningCommonsMenuItem
Killed by : edu.ucsb.cs156.example.controllers.UCSBDiningCommonsMenuItemControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.UCSBDiningCommonsMenuItemControllerTests]/[method:an_admin_user_can_post_a_new_menuitem()]
removed call to edu/ucsb/cs156/example/entities/UCSBDiningCommonsMenuItem::setStation → KILLED

67

1.1
Location : postUCSBDiningCommonsMenuItem
Killed by : edu.ucsb.cs156.example.controllers.UCSBDiningCommonsMenuItemControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.UCSBDiningCommonsMenuItemControllerTests]/[method:an_admin_user_can_post_a_new_menuitem()]
replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBDiningCommonsMenuItemController::postUCSBDiningCommonsMenuItem → KILLED

87

1.1
Location : lambda$updateUCSBDiningCommonsMenuItem$1
Killed by : edu.ucsb.cs156.example.controllers.UCSBDiningCommonsMenuItemControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.UCSBDiningCommonsMenuItemControllerTests]/[method:admin_cannot_edit_ucsb_menu_item_that_does_not_exist()]
replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBDiningCommonsMenuItemController::lambda$updateUCSBDiningCommonsMenuItem$1 → KILLED

89

1.1
Location : updateUCSBDiningCommonsMenuItem
Killed by : edu.ucsb.cs156.example.controllers.UCSBDiningCommonsMenuItemControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.UCSBDiningCommonsMenuItemControllerTests]/[method:admin_can_edit_an_existing_ucsb_menu_item()]
removed call to edu/ucsb/cs156/example/entities/UCSBDiningCommonsMenuItem::setName → KILLED

90

1.1
Location : updateUCSBDiningCommonsMenuItem
Killed by : edu.ucsb.cs156.example.controllers.UCSBDiningCommonsMenuItemControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.UCSBDiningCommonsMenuItemControllerTests]/[method:admin_can_edit_an_existing_ucsb_menu_item()]
removed call to edu/ucsb/cs156/example/entities/UCSBDiningCommonsMenuItem::setDiningCommonsCode → KILLED

91

1.1
Location : updateUCSBDiningCommonsMenuItem
Killed by : edu.ucsb.cs156.example.controllers.UCSBDiningCommonsMenuItemControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.UCSBDiningCommonsMenuItemControllerTests]/[method:admin_can_edit_an_existing_ucsb_menu_item()]
removed call to edu/ucsb/cs156/example/entities/UCSBDiningCommonsMenuItem::setStation → KILLED

95

1.1
Location : updateUCSBDiningCommonsMenuItem
Killed by : edu.ucsb.cs156.example.controllers.UCSBDiningCommonsMenuItemControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.UCSBDiningCommonsMenuItemControllerTests]/[method:admin_can_edit_an_existing_ucsb_menu_item()]
replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBDiningCommonsMenuItemController::updateUCSBDiningCommonsMenuItem → KILLED

Active mutators

Tests examined


Report generated by PIT 1.17.0