TidesQueryService.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
import org.springframework.http.HttpEntity;
8
9
import org.springframework.web.client.RestTemplate;
10
import org.springframework.http.ResponseEntity;
11
import org.springframework.http.HttpMethod;
12
13
import lombok.extern.slf4j.Slf4j;
14
15
import org.springframework.http.MediaType;
16
17
import org.springframework.boot.web.client.RestTemplateBuilder;
18
import org.springframework.http.HttpHeaders;
19
20
import org.springframework.stereotype.Service;
21
import org.springframework.web.client.HttpClientErrorException;
22
23
@Slf4j
24
@Service
25
public class TidesQueryService {
26
27
28
    private final RestTemplate restTemplate;
29
30
    public TidesQueryService(RestTemplateBuilder restTemplateBuilder) {
31
        restTemplate = restTemplateBuilder.build();
32
    }
33
34
    // Documentation for endpoint is at: https://api.tidesandcurrents.noaa.gov/api/prod/
35
    public static final String ENDPOINT = "https://api.tidesandcurrents.noaa.gov/api/prod/datagetter?application=ucsb-cs156&begin_date={beginDate}&end_date={endDate}&station={station}&product=predictions&datum=mllw&units=english&time_zone=lst_ldt&interval=hilo&format=json";
36
37
    public String getJSON(String beginDate, String endDate, String station) throws HttpClientErrorException {
38
        log.info("beginDate={}, endDate={}, station={}", beginDate, endDate, station);
39
        HttpHeaders headers = new HttpHeaders();
40 1 1. getJSON : removed call to org/springframework/http/HttpHeaders::setAccept → KILLED
        headers.setAccept(List.of(MediaType.APPLICATION_JSON));
41 1 1. getJSON : removed call to org/springframework/http/HttpHeaders::setContentType → KILLED
        headers.setContentType(MediaType.APPLICATION_JSON);
42
43
        Map<String, String> uriVariables = Map.of("beginDate", beginDate, "endDate", endDate, "station", station);
44
45
        HttpEntity<String> entity = new HttpEntity<>("body", headers);
46
47
        ResponseEntity<String> re = restTemplate.exchange(ENDPOINT, HttpMethod.GET, entity, String.class,
48
                uriVariables);
49 1 1. getJSON : replaced return value with "" for edu/ucsb/cs156/spring/backenddemo/services/TidesQueryService::getJSON → KILLED
        return re.getBody();
50
    }
51
}

Mutations

40

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

41

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

49

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

Active mutators

Tests examined


Report generated by PIT 1.7.3