MenuItemReviewController.java

1
package edu.ucsb.cs156.example.controllers;
2
3
import edu.ucsb.cs156.example.entities.MenuItemReviews;
4
import edu.ucsb.cs156.example.errors.EntityNotFoundException;
5
import edu.ucsb.cs156.example.repositories.MenuItemReviewsRepository;
6
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
12
import com.fasterxml.jackson.core.JsonProcessingException;
13
14
import org.springframework.beans.factory.annotation.Autowired;
15
import org.springframework.format.annotation.DateTimeFormat;
16
import org.springframework.security.access.prepost.PreAuthorize;
17
import org.springframework.web.bind.annotation.DeleteMapping;
18
import org.springframework.web.bind.annotation.GetMapping;
19
import org.springframework.web.bind.annotation.PostMapping;
20
import org.springframework.web.bind.annotation.PutMapping;
21
import org.springframework.web.bind.annotation.RequestBody;
22
import org.springframework.web.bind.annotation.RequestMapping;
23
import org.springframework.web.bind.annotation.RequestParam;
24
import org.springframework.web.bind.annotation.RestController;
25
26
import jakarta.validation.Valid;
27
28
import java.time.LocalDateTime;
29
30
@Slf4j
31
@RestController
32
@Tag(name = "MenuItemReview")
33
@RequestMapping("/api/menuitemreview")
34
public class MenuItemReviewController extends ApiController {
35
36
    @Autowired
37
    MenuItemReviewsRepository menuItemReviewsRepository;
38
39
40
    @Operation(summary= "List all")
41
    @PreAuthorize("hasRole('ROLE_USER')")
42
    @GetMapping("/all")
43
    public Iterable<MenuItemReviews> getAllMenuItemReviews() {
44
        Iterable<MenuItemReviews> menuItemReviews = menuItemReviewsRepository.findAll();
45 1 1. getAllMenuItemReviews : replaced return value with Collections.emptyList for edu/ucsb/cs156/example/controllers/MenuItemReviewController::getAllMenuItemReviews → KILLED
        return menuItemReviews;
46
    }
47
48
49
50
51
    @Operation(summary= "Create new")
52
    @PreAuthorize("hasRole('ROLE_ADMIN')")
53
    @PostMapping("/post")
54
55
    public MenuItemReviews createMenuItemReview(
56
            //@Parameter(name="id") @RequestParam long id,
57
            @Parameter(name="itemId") @RequestParam long itemId,
58
            @Parameter(name="reviewEmail") @RequestParam String reviewEmail,
59
            @Parameter(name="stars") @RequestParam int stars,
60
            @Parameter(name="dateReviewed", description="date (in iso format, e.g. YYYY-mm-ddTHH:MM:SS; see https://en.wikipedia.org/wiki/ISO_8601)") @RequestParam("dateReviewed") @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) LocalDateTime dateReviewed,
61
            @Parameter(name="comments") @RequestParam String comments )
62
            throws JsonProcessingException {
63
64
65
66
67
        MenuItemReviews menuItemReviewRequest = new MenuItemReviews();
68
        //menuItemReviewRequest.setId(id);
69 1 1. createMenuItemReview : removed call to edu/ucsb/cs156/example/entities/MenuItemReviews::setItemId → KILLED
        menuItemReviewRequest.setItemId(itemId);
70 1 1. createMenuItemReview : removed call to edu/ucsb/cs156/example/entities/MenuItemReviews::setReviewEmail → KILLED
        menuItemReviewRequest.setReviewEmail(reviewEmail);
71 1 1. createMenuItemReview : removed call to edu/ucsb/cs156/example/entities/MenuItemReviews::setStars → KILLED
        menuItemReviewRequest.setStars(stars);
72 1 1. createMenuItemReview : removed call to edu/ucsb/cs156/example/entities/MenuItemReviews::setDateReviewed → KILLED
        menuItemReviewRequest.setDateReviewed(dateReviewed);
73 1 1. createMenuItemReview : removed call to edu/ucsb/cs156/example/entities/MenuItemReviews::setComments → KILLED
        menuItemReviewRequest.setComments(comments);
74
75
76
77
78
        MenuItemReviews createdReviews = menuItemReviewsRepository.save(menuItemReviewRequest);
79 1 1. createMenuItemReview : replaced return value with null for edu/ucsb/cs156/example/controllers/MenuItemReviewController::createMenuItemReview → KILLED
        return createdReviews;
80
    }
81
82
83
84
85
86
    @Operation(summary = "Get a single menu item review by id")
87
    @PreAuthorize("hasRole('ROLE_USER')")
88
    @GetMapping("")
89
    public MenuItemReviews getMenuItemReviewById(
90
        @Parameter(name = "id") @RequestParam long id) {
91
92
        MenuItemReviews menuItemReview = menuItemReviewsRepository.findById(id)
93 1 1. lambda$getMenuItemReviewById$0 : replaced return value with null for edu/ucsb/cs156/example/controllers/MenuItemReviewController::lambda$getMenuItemReviewById$0 → KILLED
            .orElseThrow(() -> new EntityNotFoundException(MenuItemReviews.class, id));
94
95 1 1. getMenuItemReviewById : replaced return value with null for edu/ucsb/cs156/example/controllers/MenuItemReviewController::getMenuItemReviewById → KILLED
        return menuItemReview;
96
    }
97
98
99
100
101
102
103
104
105
    @Operation(summary = "Update a menu item review by id")
106
    @PreAuthorize("hasRole('ROLE_ADMIN')")
107
    @PutMapping("")
108
    public MenuItemReviews updateMenuItemReview(
109
            @Parameter(name = "id") @RequestParam long id,
110
            @RequestBody @Valid MenuItemReviews updatedReview) {
111
112
        MenuItemReviews existingReview = menuItemReviewsRepository.findById(id)
113 1 1. lambda$updateMenuItemReview$1 : replaced return value with null for edu/ucsb/cs156/example/controllers/MenuItemReviewController::lambda$updateMenuItemReview$1 → KILLED
                .orElseThrow(() -> new EntityNotFoundException(MenuItemReviews.class, id));
114
115
116 1 1. updateMenuItemReview : removed call to edu/ucsb/cs156/example/entities/MenuItemReviews::setItemId → KILLED
        existingReview.setItemId(updatedReview.getItemId());
117 1 1. updateMenuItemReview : removed call to edu/ucsb/cs156/example/entities/MenuItemReviews::setReviewEmail → KILLED
        existingReview.setReviewEmail(updatedReview.getReviewEmail());
118 1 1. updateMenuItemReview : removed call to edu/ucsb/cs156/example/entities/MenuItemReviews::setStars → KILLED
        existingReview.setStars(updatedReview.getStars());
119 1 1. updateMenuItemReview : removed call to edu/ucsb/cs156/example/entities/MenuItemReviews::setDateReviewed → KILLED
        existingReview.setDateReviewed(updatedReview.getDateReviewed());
120 1 1. updateMenuItemReview : removed call to edu/ucsb/cs156/example/entities/MenuItemReviews::setComments → KILLED
        existingReview.setComments(updatedReview.getComments());
121
122
123
        menuItemReviewsRepository.save(existingReview);
124
125 1 1. updateMenuItemReview : replaced return value with null for edu/ucsb/cs156/example/controllers/MenuItemReviewController::updateMenuItemReview → KILLED
        return existingReview;
126
    }
127
128
129
130
131
132
@DeleteMapping("")
133
@PreAuthorize("hasRole('ROLE_ADMIN')")
134
@Operation(summary = "Delete a menu item review by id")
135
public String deleteMenuItemReview(@RequestParam long id) throws EntityNotFoundException {
136
    MenuItemReviews menuItemReview = menuItemReviewsRepository.findById(id)
137 1 1. lambda$deleteMenuItemReview$2 : replaced return value with null for edu/ucsb/cs156/example/controllers/MenuItemReviewController::lambda$deleteMenuItemReview$2 → KILLED
            .orElseThrow(() -> new EntityNotFoundException(MenuItemReviews.class, id));
138
139 1 1. deleteMenuItemReview : removed call to edu/ucsb/cs156/example/repositories/MenuItemReviewsRepository::delete → KILLED
    menuItemReviewsRepository.delete(menuItemReview);
140
141 1 1. deleteMenuItemReview : replaced return value with "" for edu/ucsb/cs156/example/controllers/MenuItemReviewController::deleteMenuItemReview → KILLED
    return "MenuItemReview with id " + id + " deleted";
142
}
143
144
145
146
147
148
149
150
}

Mutations

45

1.1
Location : getAllMenuItemReviews
Killed by : edu.ucsb.cs156.example.controllers.MenuItemReviewControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.MenuItemReviewControllerTests]/[method:logged_in_user_can_get_all_menu_item_reviews()]
replaced return value with Collections.emptyList for edu/ucsb/cs156/example/controllers/MenuItemReviewController::getAllMenuItemReviews → KILLED

69

1.1
Location : createMenuItemReview
Killed by : edu.ucsb.cs156.example.controllers.MenuItemReviewControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.MenuItemReviewControllerTests]/[method:admin_can_post_a_new_review()]
removed call to edu/ucsb/cs156/example/entities/MenuItemReviews::setItemId → KILLED

70

1.1
Location : createMenuItemReview
Killed by : edu.ucsb.cs156.example.controllers.MenuItemReviewControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.MenuItemReviewControllerTests]/[method:admin_can_post_a_new_review()]
removed call to edu/ucsb/cs156/example/entities/MenuItemReviews::setReviewEmail → KILLED

71

1.1
Location : createMenuItemReview
Killed by : edu.ucsb.cs156.example.controllers.MenuItemReviewControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.MenuItemReviewControllerTests]/[method:admin_can_post_a_new_review()]
removed call to edu/ucsb/cs156/example/entities/MenuItemReviews::setStars → KILLED

72

1.1
Location : createMenuItemReview
Killed by : edu.ucsb.cs156.example.controllers.MenuItemReviewControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.MenuItemReviewControllerTests]/[method:admin_can_post_a_new_review()]
removed call to edu/ucsb/cs156/example/entities/MenuItemReviews::setDateReviewed → KILLED

73

1.1
Location : createMenuItemReview
Killed by : edu.ucsb.cs156.example.controllers.MenuItemReviewControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.MenuItemReviewControllerTests]/[method:admin_can_post_a_new_review()]
removed call to edu/ucsb/cs156/example/entities/MenuItemReviews::setComments → KILLED

79

1.1
Location : createMenuItemReview
Killed by : edu.ucsb.cs156.example.controllers.MenuItemReviewControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.MenuItemReviewControllerTests]/[method:admin_can_post_a_new_review()]
replaced return value with null for edu/ucsb/cs156/example/controllers/MenuItemReviewController::createMenuItemReview → KILLED

93

1.1
Location : lambda$getMenuItemReviewById$0
Killed by : edu.ucsb.cs156.example.controllers.MenuItemReviewControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.MenuItemReviewControllerTests]/[method:logged_in_user_cannot_get_nonexistent_menu_item_review_by_id()]
replaced return value with null for edu/ucsb/cs156/example/controllers/MenuItemReviewController::lambda$getMenuItemReviewById$0 → KILLED

95

1.1
Location : getMenuItemReviewById
Killed by : edu.ucsb.cs156.example.controllers.MenuItemReviewControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.MenuItemReviewControllerTests]/[method:logged_in_user_can_get_single_menu_item_review_by_id()]
replaced return value with null for edu/ucsb/cs156/example/controllers/MenuItemReviewController::getMenuItemReviewById → KILLED

113

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

116

1.1
Location : updateMenuItemReview
Killed by : edu.ucsb.cs156.example.controllers.MenuItemReviewControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.MenuItemReviewControllerTests]/[method:admin_can_edit_an_existing_menu_item_review()]
removed call to edu/ucsb/cs156/example/entities/MenuItemReviews::setItemId → KILLED

117

1.1
Location : updateMenuItemReview
Killed by : edu.ucsb.cs156.example.controllers.MenuItemReviewControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.MenuItemReviewControllerTests]/[method:admin_can_edit_an_existing_menu_item_review()]
removed call to edu/ucsb/cs156/example/entities/MenuItemReviews::setReviewEmail → KILLED

118

1.1
Location : updateMenuItemReview
Killed by : edu.ucsb.cs156.example.controllers.MenuItemReviewControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.MenuItemReviewControllerTests]/[method:admin_can_edit_an_existing_menu_item_review()]
removed call to edu/ucsb/cs156/example/entities/MenuItemReviews::setStars → KILLED

119

1.1
Location : updateMenuItemReview
Killed by : edu.ucsb.cs156.example.controllers.MenuItemReviewControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.MenuItemReviewControllerTests]/[method:admin_can_edit_an_existing_menu_item_review()]
removed call to edu/ucsb/cs156/example/entities/MenuItemReviews::setDateReviewed → KILLED

120

1.1
Location : updateMenuItemReview
Killed by : edu.ucsb.cs156.example.controllers.MenuItemReviewControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.MenuItemReviewControllerTests]/[method:admin_can_edit_an_existing_menu_item_review()]
removed call to edu/ucsb/cs156/example/entities/MenuItemReviews::setComments → KILLED

125

1.1
Location : updateMenuItemReview
Killed by : edu.ucsb.cs156.example.controllers.MenuItemReviewControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.MenuItemReviewControllerTests]/[method:admin_can_edit_an_existing_menu_item_review()]
replaced return value with null for edu/ucsb/cs156/example/controllers/MenuItemReviewController::updateMenuItemReview → KILLED

137

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

139

1.1
Location : deleteMenuItemReview
Killed by : edu.ucsb.cs156.example.controllers.MenuItemReviewControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.MenuItemReviewControllerTests]/[method:admin_can_delete_existing_menu_item_review()]
removed call to edu/ucsb/cs156/example/repositories/MenuItemReviewsRepository::delete → KILLED

141

1.1
Location : deleteMenuItemReview
Killed by : edu.ucsb.cs156.example.controllers.MenuItemReviewControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.MenuItemReviewControllerTests]/[method:admin_can_delete_existing_menu_item_review()]
replaced return value with "" for edu/ucsb/cs156/example/controllers/MenuItemReviewController::deleteMenuItemReview → KILLED

Active mutators

Tests examined


Report generated by PIT 1.17.0