EarthquakeQueryService.java

1
package edu.ucsb.cs156.spring.backenddemo.services;
2
3
import java.util.List;
4
import java.util.Map;
5
6
import com.fasterxml.jackson.databind.ObjectMapper;
7
8
import org.springframework.web.client.RestTemplate;
9
10
import lombok.extern.slf4j.Slf4j;
11
12
import org.springframework.boot.web.client.RestTemplateBuilder;
13
import org.springframework.http.HttpEntity;
14
import org.springframework.http.HttpHeaders;
15
import org.springframework.http.HttpMethod;
16
import org.springframework.http.MediaType;
17
import org.springframework.http.ResponseEntity;
18
import org.springframework.stereotype.Service;
19
import org.springframework.web.client.HttpClientErrorException;
20
21
@Slf4j
22
@Service
23
public class EarthquakeQueryService {
24
25
    ObjectMapper mapper = new ObjectMapper();
26
27
    private final RestTemplate restTemplate;
28
29
    public EarthquakeQueryService(RestTemplateBuilder restTemplateBuilder) {
30
        restTemplate = restTemplateBuilder.build();
31
    }
32
33
    public static final String ENDPOINT = "https://earthquake.usgs.gov/fdsnws/event/1/query?format=geojson&minmagnitude={minMag}&maxradiuskm={distance}&latitude={latitude}&longitude={longitude}";
34
35
    public String getJSON(String distance, String minMag) throws HttpClientErrorException {
36
        log.info("distance={}, minMag={}", distance, minMag);
37
        HttpHeaders headers = new HttpHeaders();
38 1 1. getJSON : removed call to org/springframework/http/HttpHeaders::setAccept → KILLED
        headers.setAccept(List.of(MediaType.APPLICATION_JSON));
39 1 1. getJSON : removed call to org/springframework/http/HttpHeaders::setContentType → KILLED
        headers.setContentType(MediaType.APPLICATION_JSON);
40
41
        HttpEntity<String> entity = new HttpEntity<>(headers);
42
43
        String ucsbLat = "34.4140"; // hard coded params for Storke Tower
44
        String ucsbLong = "-119.8489";
45
        Map<String, String> uriVariables = Map.of("minMag", minMag, "distance", distance, "latitude", ucsbLat,
46
                "longitude", ucsbLong);
47
48
        ResponseEntity<String> re = restTemplate.exchange(ENDPOINT, HttpMethod.GET, entity, String.class,
49
                uriVariables);
50 1 1. getJSON : replaced return value with "" for edu/ucsb/cs156/spring/backenddemo/services/EarthquakeQueryService::getJSON → KILLED
        return re.getBody();
51
    }
52
53
   
54
55
}

Mutations

38

1.1
Location : getJSON
Killed by : edu.ucsb.cs156.spring.backenddemo.services.EarthquakeQueryServiceTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.spring.backenddemo.services.EarthquakeQueryServiceTests]/[method:test_getJSON()]
removed call to org/springframework/http/HttpHeaders::setAccept → KILLED

39

1.1
Location : getJSON
Killed by : edu.ucsb.cs156.spring.backenddemo.services.EarthquakeQueryServiceTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.spring.backenddemo.services.EarthquakeQueryServiceTests]/[method:test_getJSON()]
removed call to org/springframework/http/HttpHeaders::setContentType → KILLED

50

1.1
Location : getJSON
Killed by : edu.ucsb.cs156.spring.backenddemo.services.EarthquakeQueryServiceTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.spring.backenddemo.services.EarthquakeQueryServiceTests]/[method:test_getJSON()]
replaced return value with "" for edu/ucsb/cs156/spring/backenddemo/services/EarthquakeQueryService::getJSON → KILLED

Active mutators

Tests examined


Report generated by PIT 1.7.3