UsersController.java

1
package edu.ucsb.cs156.example.controllers;
2
3
import com.fasterxml.jackson.core.JsonProcessingException;
4
import com.fasterxml.jackson.databind.ObjectMapper;
5
6
import org.springframework.beans.factory.annotation.Autowired;
7
import org.springframework.http.ResponseEntity;
8
import org.springframework.security.access.prepost.PreAuthorize;
9
import org.springframework.web.bind.annotation.GetMapping;
10
import org.springframework.web.bind.annotation.RequestMapping;
11
import org.springframework.web.bind.annotation.RestController;
12
13
import edu.ucsb.cs156.example.entities.User;
14
import edu.ucsb.cs156.example.repositories.UserRepository;
15
import io.swagger.v3.oas.annotations.Operation;
16
import io.swagger.v3.oas.annotations.tags.Tag;
17
18
19
@Tag(name="User information (admin only)")
20
@RequestMapping("/api/admin/users")
21
@RestController
22
public class UsersController extends ApiController {
23
    @Autowired
24
    UserRepository userRepository;
25
26
    @Autowired
27
    ObjectMapper mapper;
28
29
    @Operation(summary= "Get a list of all users")
30
    @PreAuthorize("hasRole('ROLE_ADMIN')")
31
    @GetMapping("")
32
    public ResponseEntity<String> users()
33
            throws JsonProcessingException {
34
        Iterable<User> users = userRepository.findAll();
35
        String body = mapper.writeValueAsString(users);
36 1 1. users : replaced return value with null for edu/ucsb/cs156/example/controllers/UsersController::users → KILLED
        return ResponseEntity.ok().body(body);
37
    }
38
}

Mutations

36

1.1
Location : users
Killed by : edu.ucsb.cs156.example.controllers.UsersControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.UsersControllerTests]/[method:users__admin_logged_in()]
replaced return value with null for edu/ucsb/cs156/example/controllers/UsersController::users → KILLED

Active mutators

Tests examined


Report generated by PIT 1.7.3