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

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

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

import com.arextest.common.utils.JsonTraverseUtils;
import com.arextest.model.mock.AREXMocker;
import com.arextest.model.mock.Mocker;
import com.arextest.storage.utils.JsonUtil;
import com.fasterxml.jackson.core.JsonProcessingException;
import java.util.List;
import java.util.Optional;

public class MockerPostProcessor {

  public static void desensitize(List allReadableResult)
      throws JsonProcessingException {
    for (AREXMocker arexMocker : allReadableResult) {
      Mocker.Target request = arexMocker.getTargetRequest();
      Mocker.Target response = arexMocker.getTargetResponse();

      if (JsonUtil.isJsonStr(request.getBody())) {
        request.setBody(JsonTraverseUtils.trimAllLeaves(request.getBody()));
      }
      if (JsonUtil.isJsonStr(response.getBody())) {
        response.setBody(JsonTraverseUtils.trimAllLeaves(response.getBody()));
      }
      Optional.ofNullable(response.getAttributes())
          .ifPresent(attributes -> attributes.entrySet().forEach(entry -> entry.setValue(null)));
      Optional.ofNullable(request.getAttributes())
          .ifPresent(attributes -> attributes.entrySet().forEach(entry -> entry.setValue(null)));
    }
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy