com.intuit.karate.driver.DevToolsMessage Maven / Gradle / Ivy
The newest version!
/*
* The MIT License
*
* Copyright 2022 Karate Labs 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.driver;
import com.intuit.karate.Json;
import com.intuit.karate.core.Variable;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.function.Predicate;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
*
* @author pthomas3
*/
public class DevToolsMessage {
private static final Logger logger = LoggerFactory.getLogger(DevToolsMessage.class);
protected final DevToolsDriver driver;
private final String sessionId;
private final String method;
private Integer id;
private Json params;
private Map error;
private Variable result;
private Integer timeout;
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public Integer getTimeout() {
return timeout;
}
public void setTimeout(Integer timeout) {
this.timeout = timeout;
}
public String getMethod() {
return method;
}
public boolean methodIs(String method) {
return method.equals(this.method);
}
public T getParam(String path) {
if (params == null) {
return null;
}
try {
return params.get(path);
} catch (Exception e) {
if (logger.isTraceEnabled()) {
logger.trace("get param - json path failed: {} - {}", path, params);
}
return null;
}
}
public Variable getResult() {
return result == null ? Variable.NULL : result;
}
public T getResult(String path) {
if (result == null || result.isNull()) {
return null;
}
Json json = Json.of(result.getValue());
return json.get(path);
}
public void setResult(Variable result) {
this.result = result;
}
private static Map toMap(List