Skip to content

Commit

Permalink
simplify async extension hooks
Browse files Browse the repository at this point in the history
  • Loading branch information
ptrthomas committed Jun 6, 2024
1 parent 5f3b163 commit 233190b
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 233 deletions.
23 changes: 4 additions & 19 deletions karate-core/src/main/java/com/intuit/karate/Actions.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
import java.util.Map;

/**
*
* @author pthomas3
*/
public interface Actions {
Expand All @@ -45,7 +44,7 @@ public interface Actions {
void callonce(String line);

void csv(String name, String exp);

void csvDocString(String name, String exp);

void json(String name, String exp);
Expand Down Expand Up @@ -79,7 +78,7 @@ public interface Actions {
void eval(String name, String dotOrParen, String exp);

void evalIf(String exp);

void evalDelete(String exp);

void formField(String name, String exp);
Expand Down Expand Up @@ -114,7 +113,7 @@ public interface Actions {

void path(String exp);

void print(String exp);
void print(String exp);

void remove(String name, String path);

Expand Down Expand Up @@ -143,7 +142,7 @@ public interface Actions {
void url(String exp);

void yaml(String name, String exp);

void yamlDocString(String name, String exp);

void doc(String exp);
Expand All @@ -155,19 +154,5 @@ public interface Actions {
void driver(String exp);

void robot(String exp);

void produce(String type);

void register(String exp);

void schema(String exp);

void topic(String exp);

void key(String exp);

void value(String exp);

void valueDocString(String exp);

}
44 changes: 1 addition & 43 deletions karate-core/src/main/java/com/intuit/karate/ScenarioActions.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@
import com.intuit.karate.core.AssignType;
import com.intuit.karate.core.ScenarioEngine;
import com.intuit.karate.core.When;

import java.util.List;
import java.util.Map;

/**
*
* @author pthomas3
*/
public class ScenarioActions implements Actions {
Expand Down Expand Up @@ -415,46 +415,4 @@ public void robot(String exp) {
engine.robot(exp);
}

@Override
@When("^produce (.+)")
public void produce(String type) {
engine.produce(type);
}

@Override
@When("^register (.+)")
public void register(String exp) {
engine.register(exp);
}

@Override
@When("^schema (.+)")
public void schema(String exp) {
engine.schema(exp);
}

@Override
@When("^topic (.+)")
public void topic(String exp) {
engine.topic(exp);
}

@Override
@When("^key (.+)")
public void key(String exp) {
engine.key(exp);
}

@Override
@When("^value (.+)")
public void value(String exp) {
engine.value(exp);
}

@Override
@When("^value$")
public void valueDocString(String exp) {
engine.value(exp);
}

}
15 changes: 5 additions & 10 deletions karate-core/src/main/java/com/intuit/karate/core/Channel.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,13 @@
*/
package com.intuit.karate.core;

import java.util.Map;

/**
*
* @author peter
*/
public interface Channel {

void produce(ScenarioRuntime runtime);

ChannelSession consume(ScenarioRuntime runtime);

void register(ScenarioRuntime runtime, Map<String, Object> data);


Object init(ScenarioRuntime runtime);

void afterScenario();

}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -23,50 +23,22 @@
*/
package com.intuit.karate.core;

import com.intuit.karate.FileUtils;
import com.intuit.karate.Json;
import com.intuit.karate.JsonUtils;
import com.intuit.karate.KarateException;
import com.intuit.karate.Logger;
import com.intuit.karate.Match;
import com.intuit.karate.MatchStep;
import com.intuit.karate.PerfContext;
import com.intuit.karate.StringUtils;
import com.intuit.karate.XmlUtils;
import com.intuit.karate.graal.JsEngine;
import com.intuit.karate.graal.JsFunction;
import com.intuit.karate.graal.JsLambda;
import com.intuit.karate.graal.JsList;
import com.intuit.karate.graal.JsMap;
import com.intuit.karate.graal.JsValue;
import com.intuit.karate.http.HttpClient;
import com.intuit.karate.http.HttpRequest;
import com.intuit.karate.http.HttpRequestBuilder;
import com.intuit.karate.http.ResourceType;
import com.intuit.karate.http.WebSocketClient;
import com.intuit.karate.http.WebSocketOptions;
import com.intuit.karate.*;
import com.intuit.karate.graal.*;
import com.intuit.karate.http.*;
import com.intuit.karate.shell.Command;
import org.graalvm.polyglot.Value;

import java.io.File;
import java.io.InputStream;
import java.net.URLDecoder;
import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.TreeMap;
import java.util.*;
import java.util.function.Function;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.graalvm.polyglot.Value;
import org.graalvm.polyglot.proxy.ProxyExecutable;

/**
*
* @author pthomas3
*/
public class ScenarioBridge implements PerfContext {
Expand Down Expand Up @@ -276,6 +248,10 @@ public void capturePerfEvent(String name, long startTime, long endTime) {
getEngine().capturePerfEvent(event);
}

public Object channel(String type) {
return getEngine().channelSession(type);
}

public Object compareImage(Object baseline, Object latest, Value... optionsVal) {
if (optionsVal.length > 0 && !optionsVal[0].hasMembers()) {
throw new RuntimeException("invalid image comparison options: expected map");
Expand All @@ -299,9 +275,10 @@ public Object compareImage(Object baseline, Object latest, Value... optionsVal)
public void configure(String key, Value value) {
getEngine().configure(key, new Variable(value));
}

public Object consume(String type) {
return getEngine().consume(type);
getEngine().logger.warn("karate.consume() is deprecated, use karate.channel() instead");
return channel(type);
}

public Object distinct(Value o) {
Expand Down Expand Up @@ -1012,15 +989,15 @@ public String toCsv(Object o) {

public Object toJava(Value value) {
return new JsValue(value).getValue();
}
}

public File toJavaFile(String path) {
return getEngine().fileReader.toResource(path).getFile();
}

public Object toJs(Object value) {
return JsValue.fromJava(value);
}
}

public Object toJson(Value value) {
return toJson(value, false);
Expand Down Expand Up @@ -1134,7 +1111,7 @@ public WebSocketClient webSocketBinary(String url, Value listener, Value value)
options.setBinaryHandler(handler);
return engine.webSocket(options);
}

public Object wrapFunction(Value value) {
if (value.isProxyObject()) {
Object o = value.asProxyObject();
Expand Down
Loading

0 comments on commit 233190b

Please sign in to comment.