LocationQueryService.java

1
package edu.ucsb.cs156.spring.backenddemo.services;
2
3
4
import org.springframework.boot.web.client.RestTemplateBuilder;
5
import org.springframework.stereotype.Service;
6
import org.springframework.web.client.HttpClientErrorException;
7
import org.springframework.web.client.RestTemplate;
8
import com.fasterxml.jackson.core.JsonProcessingException;
9
import java.util.*;
10
import org.springframework.boot.web.client.RestTemplateBuilder;
11
import org.springframework.http.HttpEntity;
12
import org.springframework.http.HttpHeaders;
13
import org.springframework.http.HttpMethod;
14
import org.springframework.http.MediaType;
15
import org.springframework.http.ResponseEntity;
16
import org.springframework.stereotype.Service;
17
import org.springframework.web.client.HttpClientErrorException;
18
19
@Service
20
public class LocationQueryService {
21
22
    private final RestTemplate restTemplate;
23
24
    public LocationQueryService(RestTemplateBuilder restTemplateBuilder) {
25
        restTemplate = restTemplateBuilder.build();
26
    }
27
28
    public static final String ENDPOINT = "https://nominatim.openstreetmap.org/search.php?q={location}&format=jsonv2";
29
30
    public String getJSON(String location) throws HttpClientErrorException, JsonProcessingException {
31
        HttpHeaders headers = new HttpHeaders();
32 1 1. getJSON : removed call to org/springframework/http/HttpHeaders::setAccept → KILLED
        headers.setAccept(List.of(MediaType.APPLICATION_JSON));
33 1 1. getJSON : removed call to org/springframework/http/HttpHeaders::setContentType → KILLED
        headers.setContentType(MediaType.APPLICATION_JSON);
34
35
        HttpEntity<String> entity = new HttpEntity<>(headers);
36
        Map<String, String> uriVariables = Map.of("location", location);
37
38
        ResponseEntity<String> re = restTemplate.exchange(ENDPOINT, HttpMethod.GET, entity, String.class,
39
                uriVariables);
40
41 1 1. getJSON : replaced return value with "" for edu/ucsb/cs156/spring/backenddemo/services/LocationQueryService::getJSON → KILLED
        return re.getBody();
42
    }
43
}

Mutations

32

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

33

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

41

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

Active mutators

Tests examined


Report generated by PIT 1.7.3