MetadataCIP20Utils.java

1
package org.cardanofoundation.explorer.api.util;
2
3
import java.util.*;
4
5
import lombok.AccessLevel;
6
import lombok.NoArgsConstructor;
7
import lombok.extern.slf4j.Slf4j;
8
9
import com.fasterxml.jackson.core.type.TypeReference;
10
import com.fasterxml.jackson.databind.ObjectMapper;
11
12
import org.cardanofoundation.explorer.api.common.enumeration.FormatFieldType;
13
import org.cardanofoundation.explorer.api.common.enumeration.MetadataField;
14
import org.cardanofoundation.explorer.api.model.metadatastandard.BaseProperty;
15
16
@NoArgsConstructor(access = AccessLevel.PRIVATE)
17
@Slf4j
18
public class MetadataCIP20Utils {
19
  private static final String FIELD_REQUIRED_PROPERTIES = "requiredProperties";
20
  private static final String FIELD_VALID = "valid";
21
22
  @SuppressWarnings("unchecked")
23
  public static Map<String, Object> standard(String jsonMetadata) {
24
    Map<String, Object> metadataCIP = new HashMap<>();
25
    List<BaseProperty> requiredProperties = new ArrayList<>();
26
27
    try {
28
      ObjectMapper objectMapper = new ObjectMapper();
29
      Map<Object, Object> metadataMap =
30
          objectMapper.readValue(jsonMetadata, new TypeReference<>() {});
31
32
      var msg = metadataMap.get(MetadataField.MSG.getName());
33
      requiredProperties.add(msg(msg, "1"));
34
35
    } catch (Exception ex) {
36
      log.error("Error: structure incorrect, message=" + ex.getMessage());
37
      log.error("Check standard CIP-20 fail");
38
    }
39
40
    metadataCIP.put(FIELD_REQUIRED_PROPERTIES, requiredProperties);
41
    metadataCIP.put(FIELD_VALID, isCIPValid(requiredProperties));
42 1 1. standard : replaced return value with Collections.emptyMap for org/cardanofoundation/explorer/api/util/MetadataCIP20Utils::standard → NO_COVERAGE
    return metadataCIP;
43
  }
44
45
  public static BaseProperty msg(Object msg, String index) {
46
    FormatFieldType formatFieldType = MetadataFieldUtils.getFormatTypeByObject(msg);
47 2 1. msg : negated conditional → NO_COVERAGE
2. msg : negated conditional → NO_COVERAGE
    boolean isValid = FormatFieldType.ARRAY_STRING.equals(formatFieldType) && isMsgValid(msg);
48 1 1. msg : replaced return value with null for org/cardanofoundation/explorer/api/util/MetadataCIP20Utils::msg → NO_COVERAGE
    return BaseProperty.builder()
49
        .index(index)
50
        .property(MetadataField.MSG.getName())
51
        .format(FormatFieldType.ARRAY_STRING.getValue())
52
        .valid(isValid)
53
        .valueFormat(formatFieldType.getValue())
54
        .value(msg)
55
        .build();
56
  }
57
58
  public static boolean isMsgValid(Object msg) {
59 2 1. isMsgValid : negated conditional → NO_COVERAGE
2. isMsgValid : negated conditional → NO_COVERAGE
    if (Objects.nonNull(msg) && msg instanceof ArrayList<?>) {
60
      List<?> messages = (ArrayList<?>) msg;
61 6 1. lambda$isMsgValid$0 : negated conditional → NO_COVERAGE
2. lambda$isMsgValid$0 : negated conditional → NO_COVERAGE
3. lambda$isMsgValid$0 : replaced boolean return with true for org/cardanofoundation/explorer/api/util/MetadataCIP20Utils::lambda$isMsgValid$0 → NO_COVERAGE
4. isMsgValid : replaced boolean return with true for org/cardanofoundation/explorer/api/util/MetadataCIP20Utils::isMsgValid → NO_COVERAGE
5. lambda$isMsgValid$0 : changed conditional boundary → NO_COVERAGE
6. isMsgValid : replaced boolean return with false for org/cardanofoundation/explorer/api/util/MetadataCIP20Utils::isMsgValid → NO_COVERAGE
      return messages.stream().allMatch(m -> m instanceof String && ((String) m).length() <= 64);
62
    }
63 1 1. isMsgValid : replaced boolean return with true for org/cardanofoundation/explorer/api/util/MetadataCIP20Utils::isMsgValid → NO_COVERAGE
    return false;
64
  }
65
66
  public static boolean isCIPValid(List<BaseProperty> baseProperties) {
67 1 1. isCIPValid : negated conditional → NO_COVERAGE
    if (baseProperties.isEmpty()) {
68 1 1. isCIPValid : replaced boolean return with true for org/cardanofoundation/explorer/api/util/MetadataCIP20Utils::isCIPValid → NO_COVERAGE
      return false;
69
    }
70 2 1. isCIPValid : replaced boolean return with false for org/cardanofoundation/explorer/api/util/MetadataCIP20Utils::isCIPValid → NO_COVERAGE
2. isCIPValid : replaced boolean return with true for org/cardanofoundation/explorer/api/util/MetadataCIP20Utils::isCIPValid → NO_COVERAGE
    return baseProperties.stream()
71 2 1. lambda$isCIPValid$1 : replaced boolean return with false for org/cardanofoundation/explorer/api/util/MetadataCIP20Utils::lambda$isCIPValid$1 → NO_COVERAGE
2. lambda$isCIPValid$1 : replaced boolean return with true for org/cardanofoundation/explorer/api/util/MetadataCIP20Utils::lambda$isCIPValid$1 → NO_COVERAGE
        .allMatch(baseProperty -> baseProperty.getValid().equals(Boolean.TRUE));
72
  }
73
}

Mutations

42

1.1
Location : standard
Killed by : none
replaced return value with Collections.emptyMap for org/cardanofoundation/explorer/api/util/MetadataCIP20Utils::standard → NO_COVERAGE

47

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

2.2
Location : msg
Killed by : none
negated conditional → NO_COVERAGE

48

1.1
Location : msg
Killed by : none
replaced return value with null for org/cardanofoundation/explorer/api/util/MetadataCIP20Utils::msg → NO_COVERAGE

59

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

2.2
Location : isMsgValid
Killed by : none
negated conditional → NO_COVERAGE

61

1.1
Location : lambda$isMsgValid$0
Killed by : none
negated conditional → NO_COVERAGE

2.2
Location : lambda$isMsgValid$0
Killed by : none
negated conditional → NO_COVERAGE

3.3
Location : lambda$isMsgValid$0
Killed by : none
replaced boolean return with true for org/cardanofoundation/explorer/api/util/MetadataCIP20Utils::lambda$isMsgValid$0 → NO_COVERAGE

4.4
Location : isMsgValid
Killed by : none
replaced boolean return with true for org/cardanofoundation/explorer/api/util/MetadataCIP20Utils::isMsgValid → NO_COVERAGE

5.5
Location : lambda$isMsgValid$0
Killed by : none
changed conditional boundary → NO_COVERAGE

6.6
Location : isMsgValid
Killed by : none
replaced boolean return with false for org/cardanofoundation/explorer/api/util/MetadataCIP20Utils::isMsgValid → NO_COVERAGE

63

1.1
Location : isMsgValid
Killed by : none
replaced boolean return with true for org/cardanofoundation/explorer/api/util/MetadataCIP20Utils::isMsgValid → NO_COVERAGE

67

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

68

1.1
Location : isCIPValid
Killed by : none
replaced boolean return with true for org/cardanofoundation/explorer/api/util/MetadataCIP20Utils::isCIPValid → NO_COVERAGE

70

1.1
Location : isCIPValid
Killed by : none
replaced boolean return with false for org/cardanofoundation/explorer/api/util/MetadataCIP20Utils::isCIPValid → NO_COVERAGE

2.2
Location : isCIPValid
Killed by : none
replaced boolean return with true for org/cardanofoundation/explorer/api/util/MetadataCIP20Utils::isCIPValid → NO_COVERAGE

71

1.1
Location : lambda$isCIPValid$1
Killed by : none
replaced boolean return with false for org/cardanofoundation/explorer/api/util/MetadataCIP20Utils::lambda$isCIPValid$1 → NO_COVERAGE

2.2
Location : lambda$isCIPValid$1
Killed by : none
replaced boolean return with true for org/cardanofoundation/explorer/api/util/MetadataCIP20Utils::lambda$isCIPValid$1 → NO_COVERAGE

Active mutators

Tests examined


Report generated by PIT 1.14.2