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 lombok.extern.slf4j.Slf4j;
11
import org.springframework.beans.factory.annotation.Autowired;
12
import org.springframework.http.ResponseEntity;
13
import org.springframework.security.access.prepost.PreAuthorize;
14
import org.springframework.web.bind.annotation.*;
15
16
/** This is a REST controller for UCSBDiningCommonsMenuItem */
17
@Tag(name = "UCSBDiningCommonsMenuItem")
18
@RequestMapping("/api/ucsbdiningcommonsmenuitem")
19
@RestController
20
@Slf4j
21
public class UCSBDiningCommonsMenuItemController extends ApiController {
22
23
  @Autowired UCSBDiningCommonsMenuItemRepository ucsbDiningCommonsMenuItemRepository;
24
25
  /**
26
   * List all UCSBDiningCommonsMenuItems
27
   *
28
   * @return all menu items
29
   */
30
  @Operation(summary = "List all UCSB Dining Commons Menu Items")
31
  @PreAuthorize("hasRole('ROLE_USER')")
32
  @GetMapping("/all")
33
  public Iterable<UCSBDiningCommonsMenuItem> allMenuItems() {
34
    Iterable<UCSBDiningCommonsMenuItem> items = ucsbDiningCommonsMenuItemRepository.findAll();
35 1 1. allMenuItems : replaced return value with Collections.emptyList for edu/ucsb/cs156/example/controllers/UCSBDiningCommonsMenuItemController::allMenuItems → KILLED
    return items;
36
  }
37
38
  /**
39
   * Create a new UCSBDiningCommonsMenuItem
40
   *
41
   * @param diningCommonsCode the dining commons code (e.g. 'ortega')
42
   * @param name the name of the menu item (e.g. 'Pancakes')
43
   * @param station the station name (e.g. 'Breakfast')
44
   * @return the saved menu item
45
   */
46
  @Operation(summary = "Create a new UCSB Dining Commons Menu Item")
47
  @PreAuthorize("hasRole('ROLE_USER')")
48
  @PostMapping("/post")
49
  public UCSBDiningCommonsMenuItem postMenuItem(
50
      @Parameter(name = "diningCommonsCode") @RequestParam String diningCommonsCode,
51
      @Parameter(name = "name") @RequestParam String name,
52
      @Parameter(name = "station") @RequestParam String station)
53
      throws JsonProcessingException {
54
55
    log.info("Creating menu item: {}, {}, {}", diningCommonsCode, name, station);
56
57
    UCSBDiningCommonsMenuItem menuItem = new UCSBDiningCommonsMenuItem();
58 1 1. postMenuItem : removed call to edu/ucsb/cs156/example/entities/UCSBDiningCommonsMenuItem::setDiningCommonsCode → KILLED
    menuItem.setDiningCommonsCode(diningCommonsCode);
59 1 1. postMenuItem : removed call to edu/ucsb/cs156/example/entities/UCSBDiningCommonsMenuItem::setName → KILLED
    menuItem.setName(name);
60 1 1. postMenuItem : removed call to edu/ucsb/cs156/example/entities/UCSBDiningCommonsMenuItem::setStation → KILLED
    menuItem.setStation(station);
61
62
    UCSBDiningCommonsMenuItem savedItem = ucsbDiningCommonsMenuItemRepository.save(menuItem);
63
64 1 1. postMenuItem : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBDiningCommonsMenuItemController::postMenuItem → KILLED
    return savedItem;
65
  }
66
67
  /**
68
   * Get a single UCSBDiningCommonsMenuItem by id
69
   *
70
   * @param id the id of the menu item
71
   * @return the menu item with that id, or 404 if not found
72
   */
73
  @Operation(summary = "Get a single UCSB Dining Commons Menu Item by id")
74
  @PreAuthorize("hasRole('ROLE_USER')")
75
  @GetMapping("")
76
  public UCSBDiningCommonsMenuItem getById(@Parameter(name = "id") @RequestParam Long id) {
77
78
    UCSBDiningCommonsMenuItem menuItem =
79
        ucsbDiningCommonsMenuItemRepository
80
            .findById(id)
81 1 1. lambda$getById$0 : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBDiningCommonsMenuItemController::lambda$getById$0 → KILLED
            .orElseThrow(() -> new EntityNotFoundException(UCSBDiningCommonsMenuItem.class, id));
82
83 1 1. getById : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBDiningCommonsMenuItemController::getById → KILLED
    return menuItem;
84
  }
85
86
  /**
87
   * Update a UCSBDiningCommonsMenuItem by id
88
   *
89
   * @param id the id of the menu item to update
90
   * @param incoming the updated menu item data
91
   * @return the updated menu item
92
   */
93
  @Operation(summary = "Update a UCSB Dining Commons Menu Item by id")
94
  @PreAuthorize("hasRole('ROLE_USER')")
95
  @PutMapping("")
96
  public UCSBDiningCommonsMenuItem updateMenuItem(
97
      @Parameter(name = "id") @RequestParam Long id,
98
      @RequestBody UCSBDiningCommonsMenuItem incoming) {
99
100
    UCSBDiningCommonsMenuItem existing =
101
        ucsbDiningCommonsMenuItemRepository
102
            .findById(id)
103 1 1. lambda$updateMenuItem$1 : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBDiningCommonsMenuItemController::lambda$updateMenuItem$1 → KILLED
            .orElseThrow(() -> new EntityNotFoundException(UCSBDiningCommonsMenuItem.class, id));
104
105 1 1. updateMenuItem : removed call to edu/ucsb/cs156/example/entities/UCSBDiningCommonsMenuItem::setDiningCommonsCode → KILLED
    existing.setDiningCommonsCode(incoming.getDiningCommonsCode());
106 1 1. updateMenuItem : removed call to edu/ucsb/cs156/example/entities/UCSBDiningCommonsMenuItem::setName → KILLED
    existing.setName(incoming.getName());
107 1 1. updateMenuItem : removed call to edu/ucsb/cs156/example/entities/UCSBDiningCommonsMenuItem::setStation → KILLED
    existing.setStation(incoming.getStation());
108
109
    UCSBDiningCommonsMenuItem updated = ucsbDiningCommonsMenuItemRepository.save(existing);
110 1 1. updateMenuItem : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBDiningCommonsMenuItemController::updateMenuItem → KILLED
    return updated;
111
  }
112
113
  /**
114
   * Delete a UCSBDiningCommonsMenuItem by id
115
   *
116
   * @param id the id of the menu item to delete
117
   * @return a message indicating success or not found
118
   */
119
  @Operation(summary = "Delete a UCSB Dining Commons Menu Item by id")
120
  @PreAuthorize("hasRole('ROLE_USER')")
121
  @DeleteMapping("")
122
  public ResponseEntity<String> deleteMenuItem(@Parameter(name = "id") @RequestParam Long id) {
123
124
    UCSBDiningCommonsMenuItem item =
125
        ucsbDiningCommonsMenuItemRepository
126
            .findById(id)
127 1 1. lambda$deleteMenuItem$2 : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBDiningCommonsMenuItemController::lambda$deleteMenuItem$2 → KILLED
            .orElseThrow(() -> new EntityNotFoundException(UCSBDiningCommonsMenuItem.class, id));
128
129 1 1. deleteMenuItem : removed call to edu/ucsb/cs156/example/repositories/UCSBDiningCommonsMenuItemRepository::delete → KILLED
    ucsbDiningCommonsMenuItemRepository.delete(item);
130 1 1. deleteMenuItem : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBDiningCommonsMenuItemController::deleteMenuItem → KILLED
    return ResponseEntity.ok("record " + id + " deleted");
131
  }
132
}

Mutations

35

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

58

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

59

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

60

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

64

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

81

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

83

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

103

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:test_put_menu_item_not_found()]
replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBDiningCommonsMenuItemController::lambda$updateMenuItem$1 → 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:test_put_menu_item_success()]
removed call to edu/ucsb/cs156/example/entities/UCSBDiningCommonsMenuItem::setDiningCommonsCode → KILLED

106

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

107

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

110

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

127

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

129

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

130

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

Active mutators

Tests examined


Report generated by PIT 1.17.0