Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.exactprosystems.clearth.automation.actions;
- import com.exactprosystems.clearth.automation.Action;
- import com.exactprosystems.clearth.automation.GlobalContext;
- import com.exactprosystems.clearth.automation.MatrixContext;
- import com.exactprosystems.clearth.automation.StepContext;
- import com.exactprosystems.clearth.automation.exceptions.ResultException;
- import com.exactprosystems.clearth.automation.report.Result;
- import com.exactprosystems.clearth.automation.report.ResultDetail;
- import com.exactprosystems.clearth.automation.report.results.DefaultResult;
- import com.exactprosystems.clearth.automation.report.results.DetailedResult;
- import com.exactprosystems.clearth.utils.ComparisonUtils;
- import java.util.ArrayList;
- import java.util.Map;
- public class CheckRecord extends Action {
- private static final String RECORD_ID = "RecordId";
- public static ArrayList<Map<String, String>> getTableFromContextByKey(MatrixContext context, String key) {
- @SuppressWarnings("unchecked") ArrayList<Map<String, String>> table =
- (ArrayList<Map<String, String>>) context.getContext(key);
- return table;
- }
- private int getRowByParam(ArrayList<Map<String, String>> table, String matrixRecordId) {
- int recordIdIndex = -1;
- for (int i = 0; i < table.size(); i++) {
- if (ComparisonUtils.compareValues(matrixRecordId, table.get(i).get(RECORD_ID)) &&
- ComparisonUtils.compareValues(LoadFile.ROW_UNCHECKED, table.get(i).get(LoadFile.ROW_STATUS))){
- recordIdIndex = i;
- break;
- }
- }
- return recordIdIndex;
- }
- private void setStatus(ArrayList<Map<String, String>> table, int recordIdIndex, String status) {
- table.get(recordIdIndex).put(LoadFile.ROW_STATUS, status);
- }
- private DetailedResult getResult(ArrayList<Map<String, String>> table, int recordIdIndex) {
- DetailedResult result = new DetailedResult();
- boolean isRecordsIdentical = true;
- for (String param : inputParams.keySet()) {
- String exp = inputParams.get(param),
- act = table.get(recordIdIndex).get(param);
- ResultDetail rd = new ResultDetail(param, exp, act, exp.equals(act));
- result.addResultDetail(rd);
- if (!rd.isIdentical()) {
- isRecordsIdentical = false;
- }
- }
- if(!isRecordsIdentical)
- result.setComment("Rows are not identical");
- setStatus(table, recordIdIndex, isRecordsIdentical ? LoadFile.ROW_SUCCESS: LoadFile.ROW_FAIL);
- return result;
- }
- @Override
- protected Result run(StepContext stepContext, MatrixContext matrixContext, GlobalContext globalContext) {
- String recordIdMatrixValue;
- try {
- recordIdMatrixValue = LoadFile.getValueByParam(RECORD_ID, inputParams);
- } catch (ResultException e) {
- return DefaultResult.failedWithException(e);
- }
- ArrayList<Map<String, String>> table = getTableFromContextByKey(matrixContext, LoadFile.DATA_TABLE);
- if (table == null) {
- return DefaultResult.failedWithComment("Do not get the table with data. Check the LoadFile action");
- }
- int recordIdIndex = getRowByParam(table, recordIdMatrixValue);
- if (recordIdIndex < 0) {
- return DefaultResult.failedWithComment(RECORD_ID + " param is absent in record");
- }
- return getResult(table, recordIdIndex);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement