MenuItemReviewsController.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.MenuItemsReviewsRepository;
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 lombok.extern.slf4j.Slf4j;
10
11
import com.fasterxml.jackson.core.JsonProcessingException;
12
13
import org.springframework.beans.factory.annotation.Autowired;
14
import org.springframework.format.annotation.DateTimeFormat;
15
import org.springframework.security.access.prepost.PreAuthorize;
16
import org.springframework.web.bind.annotation.DeleteMapping;
17
import org.springframework.web.bind.annotation.GetMapping;
18
import org.springframework.web.bind.annotation.PostMapping;
19
import org.springframework.web.bind.annotation.PutMapping;
20
import org.springframework.web.bind.annotation.RequestBody;
21
import org.springframework.web.bind.annotation.RequestMapping;
22
import org.springframework.web.bind.annotation.RequestParam;
23
import org.springframework.web.bind.annotation.RestController;
24
25
import jakarta.validation.Valid;
26
27
import java.time.LocalDateTime;
28
29
30
@Tag(name = "MenuItemReviews")
31
@RequestMapping("/api/menuitemreviews")
32
@RestController
33
@Slf4j
34
public class MenuItemReviewsController extends ApiController {
35
    //please take into account id is the primary key of the entity and then the other fields
36
37
    @Autowired
38
    MenuItemsReviewsRepository menuItemsReviewsRepository;
39
40
    /**
41
     * List all MenuItemReviews
42
     * 
43
     * @return an iterable of MenuItemReviews
44
     */
45
    @Operation(summary= "List all menu item reviews")
46
    @PreAuthorize("hasRole('ROLE_USER')")
47
    @GetMapping("/all")
48
    public Iterable<MenuItemReviews> allMenuItemReviews() {
49
        Iterable<MenuItemReviews> reviews = menuItemsReviewsRepository.findAll();
50 1 1. allMenuItemReviews : replaced return value with Collections.emptyList for edu/ucsb/cs156/example/controllers/MenuItemReviewsController::allMenuItemReviews → KILLED
        return reviews;
51
    }
52
53
    @Operation(summary= "Create a new menu item review")
54
    @PreAuthorize("hasRole('ROLE_USER')")
55
    @PostMapping("/post")
56
57
    //Create a new menu item review
58
    public MenuItemReviews postMenuItemReview(
59
            @Parameter(name="itemId") @RequestParam long itemId,
60
            @Parameter(name="reviewerEmail") @RequestParam String reviewerEmail,
61
            @Parameter(name="stars") @RequestParam int stars,
62
            @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,
63
            @Parameter(name="comments") @RequestParam String comments)
64
            throws JsonProcessingException {
65
66
        // For an explanation of @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME)
67
        // See: https://www.baeldung.com/spring-date-parameters
68
69
        log.info("dateReviewed={}", dateReviewed);
70
71
        MenuItemReviews menuItemReview = new MenuItemReviews();
72 1 1. postMenuItemReview : removed call to edu/ucsb/cs156/example/entities/MenuItemReviews::setItemId → KILLED
        menuItemReview.setItemId(itemId);
73 1 1. postMenuItemReview : removed call to edu/ucsb/cs156/example/entities/MenuItemReviews::setReviewerEmail → KILLED
        menuItemReview.setReviewerEmail(reviewerEmail);
74 1 1. postMenuItemReview : removed call to edu/ucsb/cs156/example/entities/MenuItemReviews::setStars → KILLED
        menuItemReview.setStars(stars);
75 1 1. postMenuItemReview : removed call to edu/ucsb/cs156/example/entities/MenuItemReviews::setDateReviewed → KILLED
        menuItemReview.setDateReviewed(dateReviewed);
76 1 1. postMenuItemReview : removed call to edu/ucsb/cs156/example/entities/MenuItemReviews::setComments → KILLED
        menuItemReview.setComments(comments);
77
78
        MenuItemReviews savedMenuItemReview = menuItemsReviewsRepository.save(menuItemReview);
79
80 1 1. postMenuItemReview : replaced return value with null for edu/ucsb/cs156/example/controllers/MenuItemReviewsController::postMenuItemReview → KILLED
        return savedMenuItemReview;
81
    }
82
83
    @Operation(summary="get a single menu item review")
84
    @PreAuthorize("hasRole('ROLE_USER')")
85
    @GetMapping("")
86
87
    //Get a single menu item review by id
88
    public MenuItemReviews getById(
89
            @Parameter(name="id") @RequestParam Long id) {
90
        MenuItemReviews menuItemReview = menuItemsReviewsRepository.findById(id)
91 1 1. lambda$getById$0 : replaced return value with null for edu/ucsb/cs156/example/controllers/MenuItemReviewsController::lambda$getById$0 → KILLED
                .orElseThrow(() -> new EntityNotFoundException(MenuItemReviews.class, id));
92
93 1 1. getById : replaced return value with null for edu/ucsb/cs156/example/controllers/MenuItemReviewsController::getById → KILLED
        return menuItemReview;
94
    }
95
96
    @Operation(summary="Delete a menu item review by id")
97
    @PreAuthorize("hasRole('ROLE_USER')")
98
    @DeleteMapping("")
99
100
    //Delete a menu item review by id(not itemId)
101
102
    public Object deleteMenuItemReview(
103
            @Parameter(name="id") @RequestParam Long id) {
104
        MenuItemReviews menuItemReview = menuItemsReviewsRepository.findById(id)
105 1 1. lambda$deleteMenuItemReview$1 : replaced return value with null for edu/ucsb/cs156/example/controllers/MenuItemReviewsController::lambda$deleteMenuItemReview$1 → KILLED
                .orElseThrow(() -> new EntityNotFoundException(MenuItemReviews.class, id));
106
107 1 1. deleteMenuItemReview : removed call to edu/ucsb/cs156/example/repositories/MenuItemsReviewsRepository::delete → KILLED
        menuItemsReviewsRepository.delete(menuItemReview);
108 1 1. deleteMenuItemReview : replaced return value with null for edu/ucsb/cs156/example/controllers/MenuItemReviewsController::deleteMenuItemReview → KILLED
        return genericMessage("MenuItemReview with id %s deleted".formatted(id));
109
    }
110
111
    @Operation(summary="Update a single menu item review")
112
    @PreAuthorize("hasRole('ROLE_USER')")
113
    @PutMapping("")
114
115
    //Update a single menu item review by id
116
    public MenuItemReviews updateMenuItemReview(
117
            @Parameter(name="id") @RequestParam Long id,
118
            @RequestBody @Valid MenuItemReviews incoming) {
119
120
        MenuItemReviews menuItemReview = menuItemsReviewsRepository.findById(id)
121 1 1. lambda$updateMenuItemReview$2 : replaced return value with null for edu/ucsb/cs156/example/controllers/MenuItemReviewsController::lambda$updateMenuItemReview$2 → KILLED
                .orElseThrow(() -> new EntityNotFoundException(MenuItemReviews.class, id));
122
123 1 1. updateMenuItemReview : removed call to edu/ucsb/cs156/example/entities/MenuItemReviews::setItemId → KILLED
        menuItemReview.setItemId(incoming.getItemId());
124 1 1. updateMenuItemReview : removed call to edu/ucsb/cs156/example/entities/MenuItemReviews::setReviewerEmail → KILLED
        menuItemReview.setReviewerEmail(incoming.getReviewerEmail());
125 1 1. updateMenuItemReview : removed call to edu/ucsb/cs156/example/entities/MenuItemReviews::setStars → KILLED
        menuItemReview.setStars(incoming.getStars());
126 1 1. updateMenuItemReview : removed call to edu/ucsb/cs156/example/entities/MenuItemReviews::setDateReviewed → KILLED
        menuItemReview.setDateReviewed(incoming.getDateReviewed());
127 1 1. updateMenuItemReview : removed call to edu/ucsb/cs156/example/entities/MenuItemReviews::setComments → KILLED
        menuItemReview.setComments(incoming.getComments());
128
129
        menuItemsReviewsRepository.save(menuItemReview);
130
131 1 1. updateMenuItemReview : replaced return value with null for edu/ucsb/cs156/example/controllers/MenuItemReviewsController::updateMenuItemReview → KILLED
        return menuItemReview;
132
    }
133
}

Mutations

50

1.1
Location : allMenuItemReviews
Killed by : edu.ucsb.cs156.example.controllers.MenuItemReviewsControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.MenuItemReviewsControllerTests]/[method:logged_in_users_can_get_all_menuitemreviews()]
replaced return value with Collections.emptyList for edu/ucsb/cs156/example/controllers/MenuItemReviewsController::allMenuItemReviews → KILLED

72

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

73

1.1
Location : postMenuItemReview
Killed by : edu.ucsb.cs156.example.controllers.MenuItemReviewsControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.MenuItemReviewsControllerTests]/[method:an_admin_user_can_post_a_new_menuitemreview()]
removed call to edu/ucsb/cs156/example/entities/MenuItemReviews::setReviewerEmail → KILLED

74

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

75

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

76

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

80

1.1
Location : postMenuItemReview
Killed by : edu.ucsb.cs156.example.controllers.MenuItemReviewsControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.MenuItemReviewsControllerTests]/[method:an_admin_user_can_post_a_new_menuitemreview()]
replaced return value with null for edu/ucsb/cs156/example/controllers/MenuItemReviewsController::postMenuItemReview → KILLED

91

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

93

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

105

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

107

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

108

1.1
Location : deleteMenuItemReview
Killed by : edu.ucsb.cs156.example.controllers.MenuItemReviewsControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.MenuItemReviewsControllerTests]/[method:admin_can_delete_a_menuitemreview()]
replaced return value with null for edu/ucsb/cs156/example/controllers/MenuItemReviewsController::deleteMenuItemReview → KILLED

121

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

123

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

124

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

125

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

126

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

127

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

131

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

Active mutators

Tests examined


Report generated by PIT 1.17.0