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

Mutations

48

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

49

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

57

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