com.qa.framework.verify.PairExpectResult Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of smart-api-framework Show documentation
Show all versions of smart-api-framework Show documentation
Support web service api automaton test based on testng and httpclient
package com.qa.framework.verify;
import com.qa.framework.bean.Pair;
import com.qa.framework.library.base.JsonHelper;
import com.qa.framework.library.base.StringHelper;
import org.apache.log4j.Logger;
import org.testng.Assert;
import java.util.*;
import java.util.regex.Pattern;
/**
* Created by apple on 15/11/20.
*/
public class PairExpectResult implements IExpectResult {
/**
* The constant logger.
*/
protected static final Logger logger = Logger.getLogger(PairExpectResult.class);
private String pairsStatement;
private List pairs;
private String[] containKeys;
/**
* Gets pairs.
*
* @return the pairs
*/
public List getPairs() {
return pairs;
}
/**
* Sets pairs.
*
* @param pairs the pairs
*/
public void setPairs(List pairs) {
this.pairs = pairs;
}
/**
* Sets contain keys.
*
* @param containKeysString the contain keys string
*/
public void setContainKeys(String containKeysString) {
this.containKeys = StringHelper.getTokensArray(containKeysString, ",");
}
/**
* Add pair.
*
* @param pair the pair
*/
public void addPair(Pair pair) {
if (pairs == null) {
pairs = new ArrayList();
}
pairs.add(pair);
}
/**
* Sets pairs statement.
*
* @param pairsStatement the pairs statement
*/
public void setPairsStatement(String pairsStatement) {
this.pairsStatement = pairsStatement;
Pair pair = new Pair();
pair.setMapStatement(pairsStatement);
addPair(pair);
}
/**
* Sets contain keys.
*
* @param containKeys the contain keys
*/
public void setContainKeys(String[] containKeys) {
this.containKeys = containKeys;
}
@SuppressWarnings("unchecked")
public void compareReal(String content) {
Map resultMap = new HashMap();
Map jsonObject = JsonHelper.getJsonMapString(content);
if (jsonObject.size() > 0) {
Set Set = jsonObject.keySet();
for (String key : Set) {
Object object = jsonObject.get(key);
if (object instanceof Map) {
Map map = (Map) object;
for (String subKey : map.keySet()) {
resultMap.put(subKey, map.get(subKey).toString());
}
} else if (object instanceof List) {
List