Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* The MIT License
*
* Copyright 2017 Intuit Inc.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package com.intuit.karate;
import com.intuit.karate.exception.KarateException;
import com.intuit.karate.http.DummyHttpClient;
import java.util.List;
import java.util.Map;
import net.minidev.json.JSONObject;
/**
*
* @author pthomas3
*/
public class Match {
private final ScenarioContext context;
private ScriptValue prevValue = ScriptValue.NULL;
public static Match init() {
return new Match();
}
public static Match init(String exp) {
Match m = new Match();
ScriptValue sv = Script.evalKarateExpression(exp, m.context);
return m.putAll(sv.evalAsMap(m.context));
}
public static Match json(String exp) {
return parse(exp);
}
public static Match xml(String exp) {
return parse(exp);
}
private static Match parse(String exp) {
Match m = new Match();
m.prevValue = Script.evalKarateExpression(exp, m.context);
return m;
}
private Match() {
FeatureContext featureContext = FeatureContext.forEnv();
CallContext callContext = new CallContext(null, 0, null, -1, false, false,
DummyHttpClient.class.getName(), null, false);
context = new ScenarioContext(featureContext, callContext);
}
private void handleFailure(AssertionResult ar) {
if (!ar.pass) {
context.logger.error("{}", ar);
throw new KarateException(ar.message);
}
}
public Match defText(String name, String exp) {
prevValue = Script.assign(AssignType.TEXT, name, exp, context, false);
return this;
}
public Match putAll(Map map) {
if (map != null) {
map.forEach((k, v) -> context.vars.put(k, v));
}
return this;
}
public Match eval(String exp) {
prevValue = Script.evalKarateExpression(exp, context);
return this;
}
public Match def(String name, String exp) {
prevValue = Script.assign(AssignType.AUTO, name, exp, context, false);
return this;
}
public Match def(String name, Object o) {
prevValue = context.vars.put(name, o);
return this;
}
public Map asMap(String exp) {
eval(exp);
return prevValue.getAsMap();
}
public Map asMap() {
return prevValue == null ? null : prevValue.getAsMap();
}
public String asJson() {
return JsonUtils.toJson(prevValue.getAsMap());
}
public Map allAsMap() {
return context.vars.toPrimitiveMap();
}
public ScriptValueMap vars() {
return context.vars;
}
public String allAsJson() {
return JsonUtils.toJson(context.vars.toPrimitiveMap());
}
public List