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

com.arextest.schedule.plan.builder.impl.RollingCaseSourceReplayPlanBuilder Maven / Gradle / Ivy

There is a newer version: 2.0.4
Show newest version
package com.arextest.schedule.plan.builder.impl;

import com.arextest.schedule.model.AppServiceOperationDescriptor;
import com.arextest.schedule.model.ReplayActionCaseItem;
import com.arextest.schedule.model.ReplayActionItem;
import com.arextest.schedule.model.plan.BuildReplayPlanRequest;
import com.arextest.schedule.model.plan.BuildReplayPlanType;
import com.arextest.schedule.model.plan.OperationCaseInfo;
import com.arextest.schedule.plan.PlanContext;
import com.arextest.schedule.plan.builder.BuildPlanValidateResult;
import java.util.ArrayList;
import java.util.List;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.stereotype.Component;

/**
 * @author jmo
 * @since 2021/9/18
 */
@Component
final class RollingCaseSourceReplayPlanBuilder extends AbstractReplayPlanBuilder {

  @Override
  public boolean isSupported(BuildReplayPlanRequest request) {
    return request.getReplayPlanType() == BuildReplayPlanType.BY_ROLLING_CASE.getValue();
  }

  @Override
  public BuildPlanValidateResult validate(BuildReplayPlanRequest request, PlanContext planContext) {
    if (CollectionUtils.isEmpty(request.getOperationCaseInfoList())) {
      return BuildPlanValidateResult.create(BuildPlanValidateResult.REQUESTED_EMPTY_OPERATION,
          "REQUESTED_EMPTY_OPERATION");
    }
    for (OperationCaseInfo requestedOperation : request.getOperationCaseInfoList()) {
      if (CollectionUtils.isEmpty(requestedOperation.getReplayIdList())) {
        return BuildPlanValidateResult.create(
            BuildPlanValidateResult.REQUESTED_OPERATION_NOT_FOUND_ANY_CASE,
            "REQUESTED_OPERATION_NOT_FOUND_ANY_CASE");
      }
    }
    super.filterAppServiceDescriptors(request, planContext);
    return super.validate(request, planContext);
  }

  @Override
  boolean unsupportedCaseTimeRange(BuildReplayPlanRequest request) {
    return false;
  }

  @Override
  List getReplayActionList(BuildReplayPlanRequest request,
      PlanContext planContext) {
    final List replayActionItemList = new ArrayList<>();
    AppServiceOperationDescriptor operationDescriptor;
    for (OperationCaseInfo operationCaseInfo : request.getOperationCaseInfoList()) {
      operationDescriptor = planContext.findAppServiceOperationDescriptor(
          operationCaseInfo.getOperationId());
      if (operationDescriptor == null) {
        continue;
      }
      ReplayActionItem replayActionItem = planContext.toReplayAction(operationDescriptor);
      List replayIdList = operationCaseInfo.getReplayIdList();
      ReplayActionCaseItem caseItem;
      final List caseItemList = new ArrayList<>(replayIdList.size());
      for (String replayId : replayIdList) {
        caseItem = new ReplayActionCaseItem();
        caseItem.setRecordId(replayId);
        caseItem.setCaseType(replayActionItem.getActionType());
        caseItem.setParent(replayActionItem);
        caseItemList.add(caseItem);
      }
      replayActionItem.setCaseItemList(caseItemList);
      replayActionItem.setReplayCaseCount(caseItemList.size());
      replayActionItemList.add(replayActionItem);
    }
    return replayActionItemList;
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy