RateLimitInterceptorImpl.java

1
package edu.ucsb.cs156.frontiers.interceptors;
2
3
import edu.ucsb.cs156.frontiers.entities.RateLimitDataPoint;
4
import edu.ucsb.cs156.frontiers.repositories.RateLimitDataPointRepository;
5
import java.io.IOException;
6
import java.util.List;
7
import org.springframework.http.HttpRequest;
8
import org.springframework.http.client.ClientHttpRequestExecution;
9
import org.springframework.http.client.ClientHttpResponse;
10
import org.springframework.stereotype.Component;
11
12
@Component
13
public class RateLimitInterceptorImpl implements RateLimitInterceptor {
14
15
  private final RateLimitDataPointRepository rateLimitDataPointRepository;
16
17
  public RateLimitInterceptorImpl(RateLimitDataPointRepository rateLimitDataPointRepository) {
18
    this.rateLimitDataPointRepository = rateLimitDataPointRepository;
19
  }
20
21
  @Override
22
  public ClientHttpResponse intercept(
23
      HttpRequest request, byte[] body, ClientHttpRequestExecution execution) throws IOException {
24
25 1 1. intercept : negated conditional → KILLED
    if (!request.getURI().getHost().equals("api.github.com")) {
26 1 1. intercept : replaced return value with null for edu/ucsb/cs156/frontiers/interceptors/RateLimitInterceptorImpl::intercept → KILLED
      return execution.execute(request, body);
27
    }
28
29 1 1. intercept : negated conditional → KILLED
    if (!request.getURI().getPath().contains("/app/installations/")) {
30 1 1. intercept : replaced return value with null for edu/ucsb/cs156/frontiers/interceptors/RateLimitInterceptorImpl::intercept → KILLED
      return execution.execute(request, body);
31
    }
32
33
    String installationId =
34
        request.getURI().getPath().replace("/app/installations/", "").replace("/access_tokens", "");
35
36
    ClientHttpResponse response = execution.execute(request, body);
37
    RateLimitDataPoint newPoint =
38
        RateLimitDataPoint.builder().installationId(installationId).build();
39
40
    List<String> headers = response.getHeaders().get("X-RateLimit-Remaining");
41
42 2 1. intercept : negated conditional → KILLED
2. intercept : negated conditional → KILLED
    if (headers == null || headers.isEmpty()) {
43 1 1. intercept : replaced return value with null for edu/ucsb/cs156/frontiers/interceptors/RateLimitInterceptorImpl::intercept → KILLED
      return response;
44
    }
45
    try {
46
      long remaining = Long.parseLong(headers.getFirst());
47 1 1. intercept : removed call to edu/ucsb/cs156/frontiers/entities/RateLimitDataPoint::setRemaining → KILLED
      newPoint.setRemaining(remaining);
48
      rateLimitDataPointRepository.save(newPoint);
49
    } catch (NumberFormatException e) {
50 1 1. intercept : replaced return value with null for edu/ucsb/cs156/frontiers/interceptors/RateLimitInterceptorImpl::intercept → KILLED
      return response;
51
    }
52 1 1. intercept : replaced return value with null for edu/ucsb/cs156/frontiers/interceptors/RateLimitInterceptorImpl::intercept → KILLED
    return response;
53
  }
54
}

Mutations

25

1.1
Location : intercept
Killed by : edu.ucsb.cs156.frontiers.interceptors.RateLimitInterceptorImplTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.frontiers.interceptors.RateLimitInterceptorImplTests]/[method:properly_saves_data()]
negated conditional → KILLED

26

1.1
Location : intercept
Killed by : edu.ucsb.cs156.frontiers.interceptors.RateLimitInterceptorImplTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.frontiers.interceptors.RateLimitInterceptorImplTests]/[method:does_not_interfere()]
replaced return value with null for edu/ucsb/cs156/frontiers/interceptors/RateLimitInterceptorImpl::intercept → KILLED

29

1.1
Location : intercept
Killed by : edu.ucsb.cs156.frontiers.interceptors.RateLimitInterceptorImplTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.frontiers.interceptors.RateLimitInterceptorImplTests]/[method:properly_saves_data()]
negated conditional → KILLED

30

1.1
Location : intercept
Killed by : edu.ucsb.cs156.frontiers.interceptors.RateLimitInterceptorImplTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.frontiers.interceptors.RateLimitInterceptorImplTests]/[method:on_implosion_not_app_installations()]
replaced return value with null for edu/ucsb/cs156/frontiers/interceptors/RateLimitInterceptorImpl::intercept → KILLED

42

1.1
Location : intercept
Killed by : edu.ucsb.cs156.frontiers.interceptors.RateLimitInterceptorImplTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.frontiers.interceptors.RateLimitInterceptorImplTests]/[method:no_implosion_on_no_header()]
negated conditional → KILLED

2.2
Location : intercept
Killed by : edu.ucsb.cs156.frontiers.interceptors.RateLimitInterceptorImplTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.frontiers.interceptors.RateLimitInterceptorImplTests]/[method:properly_saves_data()]
negated conditional → KILLED

43

1.1
Location : intercept
Killed by : edu.ucsb.cs156.frontiers.interceptors.RateLimitInterceptorImplTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.frontiers.interceptors.RateLimitInterceptorImplTests]/[method:no_implosion_on_no_header()]
replaced return value with null for edu/ucsb/cs156/frontiers/interceptors/RateLimitInterceptorImpl::intercept → KILLED

47

1.1
Location : intercept
Killed by : edu.ucsb.cs156.frontiers.interceptors.RateLimitInterceptorImplTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.frontiers.interceptors.RateLimitInterceptorImplTests]/[method:properly_saves_data()]
removed call to edu/ucsb/cs156/frontiers/entities/RateLimitDataPoint::setRemaining → KILLED

50

1.1
Location : intercept
Killed by : edu.ucsb.cs156.frontiers.interceptors.RateLimitInterceptorImplTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.frontiers.interceptors.RateLimitInterceptorImplTests]/[method:no_implosion_on_not_number()]
replaced return value with null for edu/ucsb/cs156/frontiers/interceptors/RateLimitInterceptorImpl::intercept → KILLED

52

1.1
Location : intercept
Killed by : edu.ucsb.cs156.frontiers.interceptors.RateLimitInterceptorImplTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.frontiers.interceptors.RateLimitInterceptorImplTests]/[method:properly_saves_data()]
replaced return value with null for edu/ucsb/cs156/frontiers/interceptors/RateLimitInterceptorImpl::intercept → KILLED

Active mutators

Tests examined


Report generated by PIT 1.17.0