CachedEndpointsController.java

1
package edu.ucsb.cs156.diningcachingproxy.controller;
2
3
import edu.ucsb.cs156.diningcachingproxy.collections.CachedResponse;
4
import edu.ucsb.cs156.diningcachingproxy.collections.CachedResponseRepository;
5
import io.swagger.v3.oas.annotations.Operation;
6
import io.swagger.v3.oas.annotations.tags.Tag;
7
import java.time.Instant;
8
import java.util.List;
9
import org.springframework.beans.factory.annotation.Autowired;
10
import org.springframework.http.HttpStatus;
11
import org.springframework.security.access.prepost.PreAuthorize;
12
import org.springframework.web.bind.annotation.DeleteMapping;
13
import org.springframework.web.bind.annotation.GetMapping;
14
import org.springframework.web.bind.annotation.PathVariable;
15
import org.springframework.web.bind.annotation.RequestMapping;
16
import org.springframework.web.bind.annotation.ResponseStatus;
17
import org.springframework.web.bind.annotation.RestController;
18
import org.springframework.web.server.ResponseStatusException;
19
20
@Tag(name = "Admin - Cached Endpoints")
21
@RequestMapping("/api/admin/endpoints")
22
@RestController
23
public class CachedEndpointsController {
24
25
  @Autowired private CachedResponseRepository cachedResponseRepository;
26
27
  public record CachedEndpointDTO(
28
      String id,
29
      String requestPath,
30
      long hitCount,
31
      int responseStatus,
32
      String responseBody,
33
      Instant cachedAt) {
34
35
    public CachedEndpointDTO(CachedResponse cachedResponse) {
36
      this(
37
          cachedResponse.getId(),
38
          cachedResponse.getRequestPath(),
39
          cachedResponse.getHitCount(),
40
          cachedResponse.getResponseStatus(),
41
          cachedResponse.getResponseBody(),
42
          cachedResponse.getCachedAt());
43
    }
44
  }
45
46
  @Operation(summary = "List all cached API endpoints with response details")
47
  @PreAuthorize("hasRole('ROLE_ADMIN')")
48
  @GetMapping("")
49
  public List<CachedEndpointDTO> allEndpoints() {
50 1 1. allEndpoints : replaced return value with Collections.emptyList for edu/ucsb/cs156/diningcachingproxy/controller/CachedEndpointsController::allEndpoints → KILLED
    return cachedResponseRepository.findAll().stream().map(CachedEndpointDTO::new).toList();
51
  }
52
53
  @Operation(summary = "Delete a single cached response by ID")
54
  @PreAuthorize("hasRole('ROLE_ADMIN')")
55
  @DeleteMapping("/{id}")
56
  @ResponseStatus(HttpStatus.NO_CONTENT)
57
  public void deleteEndpoint(@PathVariable String id) {
58 1 1. deleteEndpoint : negated conditional → KILLED
    if (!cachedResponseRepository.existsById(id)) {
59
      throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Cached response not found");
60
    }
61
62 1 1. deleteEndpoint : removed call to edu/ucsb/cs156/diningcachingproxy/collections/CachedResponseRepository::deleteById → KILLED
    cachedResponseRepository.deleteById(id);
63
  }
64
}

Mutations

50

1.1
Location : allEndpoints
Killed by : edu.ucsb.cs156.diningcachingproxy.controller.CachedEndpointsControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.diningcachingproxy.controller.CachedEndpointsControllerTests]/[method:admin_can_list_cached_endpoints_with_hit_counts()]
replaced return value with Collections.emptyList for edu/ucsb/cs156/diningcachingproxy/controller/CachedEndpointsController::allEndpoints → KILLED

58

1.1
Location : deleteEndpoint
Killed by : edu.ucsb.cs156.diningcachingproxy.controller.CachedEndpointsControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.diningcachingproxy.controller.CachedEndpointsControllerTests]/[method:deleting_nonexistent_endpoint_returns_404()]
negated conditional → KILLED

62

1.1
Location : deleteEndpoint
Killed by : edu.ucsb.cs156.diningcachingproxy.controller.CachedEndpointsControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.diningcachingproxy.controller.CachedEndpointsControllerTests]/[method:admin_can_delete_cached_endpoint()]
removed call to edu/ucsb/cs156/diningcachingproxy/collections/CachedResponseRepository::deleteById → KILLED

Active mutators

Tests examined


Report generated by PIT 1.22.1