UCSBDiningCommonsMenuItemController.java

1
package edu.ucsb.cs156.example.controllers;
2
3
import edu.ucsb.cs156.example.entities.DiningCommonsMenuItem;
4
import edu.ucsb.cs156.example.errors.EntityNotFoundException;
5
import edu.ucsb.cs156.example.repositories.DiningCommonsMenuItemRepository;
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 org.springframework.security.access.prepost.PreAuthorize;
11
import org.springframework.web.bind.annotation.DeleteMapping;
12
import org.springframework.web.bind.annotation.GetMapping;
13
import org.springframework.web.bind.annotation.PostMapping;
14
import org.springframework.web.bind.annotation.PutMapping;
15
import org.springframework.web.bind.annotation.RequestBody;
16
import org.springframework.web.bind.annotation.RequestMapping;
17
import org.springframework.web.bind.annotation.RequestParam;
18
import org.springframework.web.bind.annotation.RestController;
19
20
@Tag(name = "UCSBDiningCommonsMenuItem")
21
@RestController
22
@RequestMapping("/api/ucsbdiningcommonsmenuitem")
23
public class UCSBDiningCommonsMenuItemController extends ApiController {
24
25
  private final DiningCommonsMenuItemRepository diningCommonsMenuItemRepository;
26
27
  public UCSBDiningCommonsMenuItemController(
28
      DiningCommonsMenuItemRepository diningCommonsMenuItemRepository) {
29
    this.diningCommonsMenuItemRepository = diningCommonsMenuItemRepository;
30
  }
31
32
  /**
33
   * Post a new Menu Item
34
   *
35
   * @param diningCommonsCode the code of the dining commons
36
   * @param name the name of the menu item
37
   * @param station the station where the menu item is located
38
   * @return the created {@link DiningCommonsMenuItem}
39
   */
40
  @PostMapping("/post")
41
  @PreAuthorize("hasRole('ROLE_ADMIN')")
42
  public DiningCommonsMenuItem postMenuItem(
43
      @RequestParam String diningCommonsCode,
44
      @RequestParam String name,
45
      @RequestParam String station) {
46
    DiningCommonsMenuItem item =
47
        DiningCommonsMenuItem.builder()
48
            .station(station)
49
            .name(name)
50
            .diningCommonsCode(diningCommonsCode)
51
            .build();
52
53 1 1. postMenuItem : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBDiningCommonsMenuItemController::postMenuItem → KILLED
    return diningCommonsMenuItemRepository.save(item);
54
  }
55
56
  /**
57
   * Get all Menu Items
58
   *
59
   * @return a list of all {@link DiningCommonsMenuItem}
60
   */
61
  @GetMapping("/all")
62
  @PreAuthorize("hasRole('ROLE_USER')")
63
  public Iterable<DiningCommonsMenuItem> allMenuItems() {
64 1 1. allMenuItems : replaced return value with Collections.emptyList for edu/ucsb/cs156/example/controllers/UCSBDiningCommonsMenuItemController::allMenuItems → KILLED
    return diningCommonsMenuItemRepository.findAll();
65
  }
66
67
  /**
68
   * Get a single Menu Item by id
69
   *
70
   * @param id the id of the Menu Item
71
   * @return a {@link DiningCommonsMenuItem}
72
   */
73
  @Operation(summary = "Get a single Menu Item")
74
  @PreAuthorize("hasRole('ROLE_USER')")
75
  @GetMapping("")
76
  public DiningCommonsMenuItem getById(@Parameter(name = "id") @RequestParam Long id) {
77
    DiningCommonsMenuItem menuItem =
78
        diningCommonsMenuItemRepository
79
            .findById(id)
80 1 1. lambda$getById$0 : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBDiningCommonsMenuItemController::lambda$getById$0 → KILLED
            .orElseThrow(() -> new EntityNotFoundException(DiningCommonsMenuItem.class, id));
81 1 1. getById : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBDiningCommonsMenuItemController::getById → KILLED
    return menuItem;
82
  }
83
84
  /**
85
   * Update a Menu Item
86
   *
87
   * @param id id of the Menu Item to update
88
   * @param incoming the new Menu Item
89
   * @return the updated Menu Item
90
   */
91
  @Operation(summary = "Update a single Menu Item")
92
  @PreAuthorize("hasRole('ROLE_ADMIN')")
93
  @PutMapping("")
94
  public DiningCommonsMenuItem updateMenuItem(
95
      @Parameter(name = "id") @RequestParam Long id,
96
      @RequestBody @Valid DiningCommonsMenuItem incoming) {
97
98
    DiningCommonsMenuItem menuItem =
99
        diningCommonsMenuItemRepository
100
            .findById(id)
101 1 1. lambda$updateMenuItem$1 : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBDiningCommonsMenuItemController::lambda$updateMenuItem$1 → KILLED
            .orElseThrow(() -> new EntityNotFoundException(DiningCommonsMenuItem.class, id));
102
103 1 1. updateMenuItem : removed call to edu/ucsb/cs156/example/entities/DiningCommonsMenuItem::setName → KILLED
    menuItem.setName(incoming.getName());
104 1 1. updateMenuItem : removed call to edu/ucsb/cs156/example/entities/DiningCommonsMenuItem::setStation → KILLED
    menuItem.setStation(incoming.getStation());
105 1 1. updateMenuItem : removed call to edu/ucsb/cs156/example/entities/DiningCommonsMenuItem::setDiningCommonsCode → KILLED
    menuItem.setDiningCommonsCode(incoming.getDiningCommonsCode());
106
107
    diningCommonsMenuItemRepository.save(menuItem);
108 1 1. updateMenuItem : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBDiningCommonsMenuItemController::updateMenuItem → KILLED
    return menuItem;
109
  }
110
111
  /**
112
   * Delete a {@link DiningCommonsMenuItem}
113
   *
114
   * @param id the id of the DiningCommonsMenuItem to delete
115
   * @return a message indicating the DiningCommonsMenuItem was deleted
116
   */
117
  @Operation(summary = "Delete a DiningCommonsMenuItem")
118
  @PreAuthorize("hasRole('ROLE_ADMIN')")
119
  @DeleteMapping("")
120
  public Object deleteDiningCommonsMenuItem(@Parameter(name = "id") @RequestParam Long id) {
121
    DiningCommonsMenuItem item =
122
        diningCommonsMenuItemRepository
123
            .findById(id)
124 1 1. lambda$deleteDiningCommonsMenuItem$2 : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBDiningCommonsMenuItemController::lambda$deleteDiningCommonsMenuItem$2 → KILLED
            .orElseThrow(() -> new EntityNotFoundException(DiningCommonsMenuItem.class, id));
125
126 1 1. deleteDiningCommonsMenuItem : removed call to edu/ucsb/cs156/example/repositories/DiningCommonsMenuItemRepository::delete → KILLED
    diningCommonsMenuItemRepository.delete(item);
127 1 1. deleteDiningCommonsMenuItem : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBDiningCommonsMenuItemController::deleteDiningCommonsMenuItem → KILLED
    return genericMessage("DiningCommonsMenuItem with id %s deleted".formatted(id));
128
  }
129
}

Mutations

53

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

64

1.1
Location : allMenuItems
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_menu_items()]
replaced return value with Collections.emptyList for edu/ucsb/cs156/example/controllers/UCSBDiningCommonsMenuItemController::allMenuItems → KILLED

80

1.1
Location : lambda$getById$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$getById$0 → KILLED

81

1.1
Location : getById
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::getById → KILLED

101

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

103

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

104

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

105

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

108

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

124

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

126

1.1
Location : deleteDiningCommonsMenuItem
Killed by : edu.ucsb.cs156.example.controllers.UCSBDiningCommonsMenuItemControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.UCSBDiningCommonsMenuItemControllerTests]/[method:admin_can_delete_a_menu_item()]
removed call to edu/ucsb/cs156/example/repositories/DiningCommonsMenuItemRepository::delete → KILLED

127

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

Active mutators

Tests examined


Report generated by PIT 1.17.0