All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.arextest.schedule.model.config.ReplayComparisonConfig Maven / Gradle / Ivy

There is a newer version: 2.0.4
Show newest version
package com.arextest.schedule.model.config;


import com.arextest.model.mock.MockCategoryType;
import com.arextest.web.model.contract.contracts.compare.CategoryDetail;
import com.arextest.web.model.contract.contracts.compare.TransformDetail;
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.KeyDeserializer;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializerProvider;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import java.io.IOException;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import lombok.Data;

/**
 * Created by wang_yc on 2021/10/14
 */
@Data
public class ReplayComparisonConfig {

  private String operationName;
  private List operationTypes;
  private List ignoreCategoryTypes;
  private Set> exclusionList;
  private Set> inclusionList;

  @JsonDeserialize(keyUsing = MapKeyDeserializerUtils.class)
  @JsonSerialize(keyUsing = MapKeySerializerUtils.class)
  private Map, List> referenceMap;

  @JsonDeserialize(keyUsing = MapKeyDeserializerUtils.class)
  @JsonSerialize(keyUsing = MapKeySerializerUtils.class)
  private Map, List>> listSortMap;

  private List transformDetails;

  /**
   * Custom config
   *
   * @see com.arextest.schedule.comparer.CustomComparisonConfigurationHandler
   */
  private Map additionalConfig;

  public final boolean checkIgnoreMockMessageType(String type) {
    // [b_yu] 2022-10-11 Dynamic type does not compare
    if (Objects.equals(type, MockCategoryType.DYNAMIC_CLASS.getName())) {
      return true;
    }
    if (Objects.equals(type, MockCategoryType.REDIS.getName())) {
      return true;
    }
    if (Objects.equals(type, MockCategoryType.Q_MESSAGE_CONSUMER.getName())) {
      return true;
    }
    return false;
  }

  public void fillCommonFields() {
    this.setExclusionList(Collections.emptySet());
    this.setInclusionList(Collections.emptySet());
    this.setListSortMap(Collections.emptyMap());
    this.setReferenceMap(Collections.emptyMap());
    this.setAdditionalConfig(Collections.emptyMap());
    this.setIgnoreCategoryTypes(Collections.emptyList());
  }

  private static class MapKeyDeserializerUtils extends KeyDeserializer {

    @Override
    public Object deserializeKey(String s, DeserializationContext deserializationContext)
        throws IOException {
      ObjectMapper objectMapper = new ObjectMapper();
      return objectMapper.readValue(s, new TypeReference>() {
      });
    }
  }

  private static class MapKeySerializerUtils extends JsonSerializer> {

    @Override
    public void serialize(List stringList,
        JsonGenerator jsonGenerator,
        SerializerProvider serializerProvider) throws IOException {
      ObjectMapper objectMapper = new ObjectMapper();
      String string = objectMapper.writeValueAsString(stringList);
      jsonGenerator.writeFieldName(string);
    }
  }

  public static ReplayComparisonConfig empty() {
    ReplayComparisonConfig config = new ReplayComparisonConfig();
    config.fillCommonFields();
    return config;
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy