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

com.arextest.storage.mock.MatchKeyFactory Maven / Gradle / Ivy

There is a newer version: 2.0.2
Show newest version
package com.arextest.storage.mock;

import com.arextest.model.mock.MockCategoryType;
import com.arextest.model.mock.Mocker;
import java.util.Collections;
import java.util.List;
import javax.validation.constraints.NotNull;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.stereotype.Component;

@Slf4j
@Component
public final class MatchKeyFactory {

  private final List matchKeyBuilders;

  public MatchKeyFactory(List matchKeyBuilders) {
    this.matchKeyBuilders = matchKeyBuilders;
  }

  private MatchKeyBuilder find(MockCategoryType categoryType) {
    if (CollectionUtils.isNotEmpty(this.matchKeyBuilders)) {
      for (MatchKeyBuilder matchKeyBuilder : this.matchKeyBuilders) {
        if (matchKeyBuilder.isSupported(categoryType)) {
          return matchKeyBuilder;
        }
      }
    }
    return null;
  }

  public List build(@NotNull Mocker instance) {
    MatchKeyBuilder matchKeyBuilder = find(instance.getCategoryType());
    if (matchKeyBuilder == null) {
      LOGGER.warn("Could not found replay result match key builder for {}", instance);
      return Collections.emptyList();
    }
    return matchKeyBuilder.build(instance);
  }

  public String getEigenBody(@NotNull Mocker instance) {
    MatchKeyBuilder matchKeyBuilder = find(instance.getCategoryType());
    if (matchKeyBuilder == null) {
      LOGGER.warn("Could not get eigen body for {}", instance);
      return null;
    }

    if (instance.getTargetRequest() == null) {
      LOGGER.warn("failed to get eigen body, recordId: {}, category: {}", instance.getRecordId(), instance.getCategoryType());
      return null;
    }
    return matchKeyBuilder.getEigenBody(instance);
  }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy