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.util.List;
8
import org.springframework.beans.factory.annotation.Autowired;
9
import org.springframework.security.access.prepost.PreAuthorize;
10
import org.springframework.web.bind.annotation.GetMapping;
11
import org.springframework.web.bind.annotation.RequestMapping;
12
import org.springframework.web.bind.annotation.RestController;
13
14
/**
15
 * Lets an admin see every API endpoint the proxy has cached so far, with a hit count for each — the
16
 * observation-only groundwork for per-endpoint TTL policy (see issue #2).
17
 */
18
@Tag(name = "Admin - Cached Endpoints")
19
@RequestMapping("/api/admin/endpoints")
20
@RestController
21
public class CachedEndpointsController {
22
23
  @Autowired private CachedResponseRepository cachedResponseRepository;
24
25
  public record CachedEndpointDTO(String requestPath, long hitCount, long missCount) {
26
    public CachedEndpointDTO(CachedResponse cachedResponse) {
27
      this(
28
          cachedResponse.getRequestPath(),
29
          cachedResponse.getHitCount(),
30
          cachedResponse.getMissCount());
31
    }
32
  }
33
34
  @Operation(summary = "List all API endpoints the proxy has cached, with hit and miss counts")
35
  @PreAuthorize("hasRole('ROLE_ADMIN')")
36
  @GetMapping("")
37
  public List<CachedEndpointDTO> allEndpoints() {
38 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();
39
  }
40
}

Mutations

38

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_and_miss_counts()]
replaced return value with Collections.emptyList for edu/ucsb/cs156/diningcachingproxy/controller/CachedEndpointsController::allEndpoints → KILLED

Active mutators

Tests examined


Report generated by PIT 1.22.1