UniversityQueryService.java

1
package edu.ucsb.cs156.spring.backenddemo.services;
2
3
4
5
// import com.fasterxml.jackson.databind.ObjectMapper;
6
7
import org.springframework.web.client.RestTemplate;
8
9
import lombok.extern.slf4j.Slf4j;
10
11
import java.util.List;
12
import java.util.Map;
13
14
import org.springframework.boot.web.client.RestTemplateBuilder;
15
import org.springframework.http.HttpEntity;
16
import org.springframework.http.HttpHeaders;
17
import org.springframework.http.HttpMethod;
18
import org.springframework.http.MediaType;
19
import org.springframework.http.ResponseEntity;
20
import org.springframework.stereotype.Service;
21
import org.springframework.web.client.HttpClientErrorException;
22
23
@Slf4j
24
@Service
25
public class UniversityQueryService {
26
27
28
    private final RestTemplate restTemplate;
29
30
    public UniversityQueryService(RestTemplateBuilder restTemplateBuilder) {
31
        restTemplate = restTemplateBuilder.build();
32
    }
33
34
    public static final String ENDPOINT = "http://universities.hipolabs.com/search?name={name}";
35
36
    public String getJSON(String name) throws HttpClientErrorException {
37
        log.info("name={}", name);
38
        HttpHeaders headers = new HttpHeaders();
39 1 1. getJSON : removed call to org/springframework/http/HttpHeaders::setAccept → KILLED
        headers.setAccept(List.of(MediaType.APPLICATION_JSON));
40 1 1. getJSON : removed call to org/springframework/http/HttpHeaders::setContentType → KILLED
        headers.setContentType(MediaType.APPLICATION_JSON);
41
42
        Map<String, String> uriVariables = Map.of("name", name);
43
44
        HttpEntity<String> entity = new HttpEntity<>("body", headers);
45
46
        ResponseEntity<String> re = restTemplate.exchange(ENDPOINT, HttpMethod.GET, entity, String.class,
47
                uriVariables);
48
    
49
50 1 1. getJSON : replaced return value with "" for edu/ucsb/cs156/spring/backenddemo/services/UniversityQueryService::getJSON → KILLED
       return re.getBody();
51
    }
52
}

Mutations

39

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

40

1.1
Location : getJSON
Killed by : edu.ucsb.cs156.spring.backenddemo.services.UniversityQueryServiceTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.spring.backenddemo.services.UniversityQueryServiceTests]/[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.UniversityQueryServiceTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.spring.backenddemo.services.UniversityQueryServiceTests]/[method:test_getJSON()]
replaced return value with "" for edu/ucsb/cs156/spring/backenddemo/services/UniversityQueryService::getJSON → KILLED

Active mutators

Tests examined


Report generated by PIT 1.7.3