RoleConfiguration.java

1
package org.cardanofoundation.explorer.api.interceptor.utility;
2
3
import java.io.FileNotFoundException;
4
import java.io.IOException;
5
6
import lombok.Getter;
7
import lombok.Setter;
8
import lombok.extern.log4j.Log4j2;
9
10
import org.springframework.beans.factory.annotation.Value;
11
import org.springframework.context.annotation.Bean;
12
import org.springframework.stereotype.Component;
13
import org.springframework.util.ResourceUtils;
14
15
import com.fasterxml.jackson.databind.ObjectMapper;
16
17
import org.cardanofoundation.explorer.api.interceptor.auth.RoleFilterMapper;
18
import org.cardanofoundation.explorer.common.utils.FileUtils;
19
20
@Component
21
@Getter
22
@Setter
23
@Log4j2
24
public class RoleConfiguration {
25
26
  @Value("${keycloak.role.path}")
27 1 1. getPath : replaced return value with "" for org/cardanofoundation/explorer/api/interceptor/utility/RoleConfiguration::getPath → NO_COVERAGE
  private String path;
28
29
  @Bean
30
  public RoleFilterMapper getRoleConfiguration() throws IOException {
31
    String content = getStringContent();
32
    ObjectMapper objectMapper = new ObjectMapper();
33 1 1. getRoleConfiguration : replaced return value with null for org/cardanofoundation/explorer/api/interceptor/utility/RoleConfiguration::getRoleConfiguration → NO_COVERAGE
    return objectMapper.readValue(content, RoleFilterMapper.class);
34
  }
35
36
  private String getStringContent() {
37
    try {
38 1 1. getStringContent : negated conditional → NO_COVERAGE
      if (path.startsWith("classpath:")) {
39 1 1. getStringContent : replaced return value with "" for org/cardanofoundation/explorer/api/interceptor/utility/RoleConfiguration::getStringContent → NO_COVERAGE
        return FileUtils.readFileFromClasspath(path.substring(10));
40
      } else {
41 1 1. getStringContent : replaced return value with "" for org/cardanofoundation/explorer/api/interceptor/utility/RoleConfiguration::getStringContent → NO_COVERAGE
        return FileUtils.readFileFromUrl(ResourceUtils.getFile(path).getAbsolutePath());
42
      }
43
    } catch (FileNotFoundException e) {
44 1 1. getStringContent : removed call to java/io/FileNotFoundException::printStackTrace → NO_COVERAGE
      e.printStackTrace();
45
      log.error("exception {} with url {}", e.getMessage(), path);
46
      throw new IllegalStateException("can't load file " + path);
47
    }
48
  }
49
}

Mutations

27

1.1
Location : getPath
Killed by : none
replaced return value with "" for org/cardanofoundation/explorer/api/interceptor/utility/RoleConfiguration::getPath → NO_COVERAGE

33

1.1
Location : getRoleConfiguration
Killed by : none
replaced return value with null for org/cardanofoundation/explorer/api/interceptor/utility/RoleConfiguration::getRoleConfiguration → NO_COVERAGE

38

1.1
Location : getStringContent
Killed by : none
negated conditional → NO_COVERAGE

39

1.1
Location : getStringContent
Killed by : none
replaced return value with "" for org/cardanofoundation/explorer/api/interceptor/utility/RoleConfiguration::getStringContent → NO_COVERAGE

41

1.1
Location : getStringContent
Killed by : none
replaced return value with "" for org/cardanofoundation/explorer/api/interceptor/utility/RoleConfiguration::getStringContent → NO_COVERAGE

44

1.1
Location : getStringContent
Killed by : none
removed call to java/io/FileNotFoundException::printStackTrace → NO_COVERAGE

Active mutators

Tests examined


Report generated by PIT 1.14.2