UCSBDiningMenuItemsService.java

1
package edu.ucsb.cs156.dining.services;
2
3
import com.fasterxml.jackson.core.JsonProcessingException;
4
import com.fasterxml.jackson.core.type.TypeReference;
5
import com.fasterxml.jackson.databind.ObjectMapper;
6
import edu.ucsb.cs156.dining.models.Entree;
7
import java.util.List;
8
import lombok.extern.slf4j.Slf4j;
9
import org.springframework.beans.factory.annotation.Autowired;
10
import org.springframework.beans.factory.annotation.Value;
11
import org.springframework.boot.web.client.RestTemplateBuilder;
12
import org.springframework.http.HttpEntity;
13
import org.springframework.http.HttpHeaders;
14
import org.springframework.http.HttpMethod;
15
import org.springframework.http.MediaType;
16
import org.springframework.http.ResponseEntity;
17
import org.springframework.stereotype.Service;
18
import org.springframework.web.client.RestTemplate;
19
20
@Service
21
@Slf4j
22
public class UCSBDiningMenuItemsService {
23
24
  @Autowired private ObjectMapper objectMapper;
25
26
  @Value("${app.ucsb.api.consumer_key}")
27
  private String apiKey;
28
29
  private RestTemplate restTemplate = new RestTemplate();
30
31
  public UCSBDiningMenuItemsService(RestTemplateBuilder restTemplateBuilder) throws Exception {
32
    restTemplate = restTemplateBuilder.build();
33
  }
34
35
  public static final String ALL_MEAL_ITEMS_AT_A_DINING_COMMON_ENDPOINT =
36
      "https://api.ucsb.edu/dining/menu/v1/{date-time}/{dining-common-code}/{meal-code}";
37
38
  /**
39
   * Create a List of Entree from json representation
40
   *
41
   * @param dateTime String of date in iso format
42
   * @param diningCommonCode String of dining common
43
   * @param mealCode String of meal code
44
   * @return a list of menu items
45
   */
46
  public List<Entree> get(String dateTime, String diningCommonCode, String mealCode)
47
      throws JsonProcessingException {
48
49
    HttpHeaders headers = new HttpHeaders();
50 1 1. get : removed call to org/springframework/http/HttpHeaders::setAccept → KILLED
    headers.setAccept(List.of(MediaType.APPLICATION_JSON));
51 1 1. get : removed call to org/springframework/http/HttpHeaders::setContentType → KILLED
    headers.setContentType(MediaType.APPLICATION_JSON);
52 1 1. get : removed call to org/springframework/http/HttpHeaders::set → KILLED
    headers.set("ucsb-api-key", this.apiKey);
53
54
    HttpEntity<String> entity = new HttpEntity<>(headers);
55
    String url = ALL_MEAL_ITEMS_AT_A_DINING_COMMON_ENDPOINT;
56
    url = url.replace("{date-time}", dateTime);
57
    url = url.replace("{dining-common-code}", diningCommonCode);
58
    url = url.replace("{meal-code}", mealCode);
59
60
    ResponseEntity<String> re = restTemplate.exchange(url, HttpMethod.GET, entity, String.class);
61
    String retBody = re.getBody();
62
63
    List<Entree> menuItems = objectMapper.readValue(retBody, new TypeReference<List<Entree>>() {});
64
65 1 1. get : replaced return value with Collections.emptyList for edu/ucsb/cs156/dining/services/UCSBDiningMenuItemsService::get → KILLED
    return menuItems;
66
  }
67
}

Mutations

50

1.1
Location : get
Killed by : edu.ucsb.cs156.dining.services.UCSBDiningMenuItemsServiceTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.dining.services.UCSBDiningMenuItemsServiceTests]/[method:test_get_success()]
removed call to org/springframework/http/HttpHeaders::setAccept → KILLED

51

1.1
Location : get
Killed by : edu.ucsb.cs156.dining.services.UCSBDiningMenuItemsServiceTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.dining.services.UCSBDiningMenuItemsServiceTests]/[method:test_get_success()]
removed call to org/springframework/http/HttpHeaders::setContentType → KILLED

52

1.1
Location : get
Killed by : edu.ucsb.cs156.dining.services.UCSBDiningMenuItemsServiceTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.dining.services.UCSBDiningMenuItemsServiceTests]/[method:test_get_success()]
removed call to org/springframework/http/HttpHeaders::set → KILLED

65

1.1
Location : get
Killed by : edu.ucsb.cs156.dining.services.UCSBDiningMenuItemsServiceTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.dining.services.UCSBDiningMenuItemsServiceTests]/[method:test_get_success()]
replaced return value with Collections.emptyList for edu/ucsb/cs156/dining/services/UCSBDiningMenuItemsService::get → KILLED

Active mutators

Tests examined


Report generated by PIT 1.17.0