From f40112e33891b11ba6188d5677053aed77136b04 Mon Sep 17 00:00:00 2001 From: Peter Thomas Date: Sun, 15 Nov 2020 11:47:57 +0530 Subject: [PATCH] [rewrite] #1281 massive and very satisfying code deletion --- .../java/com/intuit/karate/CallContext.java | 101 - .../main/java/com/intuit/karate/Config.java | 525 ----- .../{CallResult.java => Constants.java} | 19 +- .../java/com/intuit/karate/FileUtils.java | 93 - .../java/com/intuit/karate/JsonUtils.java | 521 ----- .../src/main/java/com/intuit/karate/Main.java | 10 +- .../main/java/com/intuit/karate/Match.java | 267 --- .../main/java/com/intuit/karate/Runner.java | 2 +- .../main/java/com/intuit/karate/Script.java | 2002 ----------------- .../com/intuit/karate/ScriptBindings.java | 264 --- .../com/intuit/karate/ScriptEvalContext.java | 42 - .../com/intuit/karate/ScriptObjectMap.java | 113 - .../java/com/intuit/karate/ScriptValue.java | 537 ----- .../com/intuit/karate/ScriptValueMap.java | 79 - .../java/com/intuit/karate/StepActions.java | 415 ---- .../java/com/intuit/karate/SuiteRuntime.java | 4 +- .../main/java/com/intuit/karate/XmlUtils.java | 7 +- .../java/com/intuit/karate/core/Engine.java | 106 +- .../intuit/karate/core/ExecutionContext.java | 82 - .../com/intuit/karate/core/ExecutionHook.java | 62 - .../karate/core/ExecutionHookFactory.java | 34 - .../java/com/intuit/karate/core/Feature.java | 5 - .../intuit/karate/core/FeatureContext.java | 100 - .../karate/core/FeatureExecutionUnit.java | 191 -- .../com/intuit/karate/core/FeatureResult.java | 20 +- .../karate/core/FeatureScenarioIterator.java | 162 -- .../intuit/karate/core/HtmlFeatureReport.java | 1 + .../com/intuit/karate/core/HtmlReport.java | 8 +- .../intuit/karate/core/HtmlTagsReport.java | 1 + .../java/com/intuit/karate/core/Scenario.java | 1 + .../intuit/karate/core/ScenarioContext.java | 1113 --------- .../karate/core/ScenarioExecutionUnit.java | 313 --- .../intuit/karate/core/ScenarioResult.java | 1 + .../com/intuit/karate/core/ScriptBridge.java | 950 -------- .../java/com/intuit/karate/core/Table.java | 8 +- .../java/com/intuit/karate/core/Tags.java | 257 --- .../com/intuit/karate/data/JsonUtils.java | 4 +- .../com/intuit/karate/debug/DapDecoder.java | 10 +- .../com/intuit/karate/debug/DapMessage.java | 2 +- .../intuit/karate/driver/DevToolsDriver.java | 39 +- .../intuit/karate/driver/DevToolsMessage.java | 28 +- .../java/com/intuit/karate/driver/Driver.java | 2 +- .../intuit/karate/driver/DriverElement.java | 5 + .../intuit/karate/driver/DriverOptions.java | 2 +- .../com/intuit/karate/driver/WebDriver.java | 14 +- .../driver/playwright/PlaywrightDriver.java | 4 +- .../karate/driver/safari/SafariWebDriver.java | 2 +- .../intuit/karate/http/DummyHttpClient.java | 101 - .../java/com/intuit/karate/http/HttpBody.java | 136 -- .../com/intuit/karate/http/HttpClient.java | 305 --- .../com/intuit/karate/http/HttpRequest.java | 159 -- .../karate/http/HttpRequestBuilder.java | 322 --- .../com/intuit/karate/http/HttpUtils.java | 39 - .../com/intuit/karate/http/MultiPartItem.java | 72 - .../intuit/karate/job/FeatureScenarios.java | 12 +- .../com/intuit/karate/job/JobExecutor.java | 8 +- .../java/com/intuit/karate/job/JobServer.java | 4 +- .../intuit/karate/job/JobServerHandler.java | 5 +- .../intuit/karate/job/ScenarioJobServer.java | 27 +- .../karate/runtime/ScenarioGenerator.java | 5 +- .../karate/runtime/ScenarioRuntime.java | 9 +- .../karate/validator/ArrayValidator.java | 18 - .../karate/validator/BooleanValidator.java | 22 - .../karate/validator/IgnoreValidator.java | 18 - .../karate/validator/NotNullValidator.java | 21 - .../karate/validator/NullValidator.java | 21 - .../karate/validator/NumberValidator.java | 25 - .../karate/validator/ObjectValidator.java | 18 - .../karate/validator/RegexValidator.java | 34 - .../karate/validator/StringValidator.java | 22 - .../karate/validator/UuidValidator.java | 28 - .../karate/validator/ValidationResult.java | 31 - .../intuit/karate/validator/Validator.java | 13 - .../java/com/intuit/karate/JsonUtilsTest.java | 210 -- .../java/com/intuit/karate/MatchTest.java | 70 - .../java/com/intuit/karate/RunnerTest.java | 6 +- .../java/com/intuit/karate/ScriptTest.java | 1778 --------------- .../com/intuit/karate/ScriptValueTest.java | 44 - .../java/com/intuit/karate/XmlUtilsTest.java | 26 - .../intuit/karate/core/FeatureParserTest.java | 65 +- .../intuit/karate/core/FeatureResultTest.java | 12 +- .../intuit/karate/core/FeatureReuseTest.java | 9 +- .../karate/core/ScenarioResultTest.java | 10 +- .../java/com/intuit/karate/core/TagsTest.java | 82 - .../karate/driver/DriverElementTest.java | 14 +- .../karate/http/CustomDummyHttpClient.java | 32 - .../intuit/karate/http/HttpClientTest.java | 60 - .../karate/http/HttpRequestBuilderTest.java | 34 - .../com/intuit/karate/http/HttpUtilsTest.java | 42 +- .../karate/validator/ValidatorTest.java | 109 - .../test/java/demo/cookies/cookies.feature | 1 - .../src/test/java/demo/embed/embed.feature | 1 - .../test/java/demo/encoding/encoding.feature | 2 +- .../src/test/java/demo/form/form.feature | 1 - .../java/demo/headers/content-type.feature | 2 +- .../java/demo/headers/headers-masking.feature | 1 - .../src/test/java/mock/contract/Consumer.java | 2 +- .../contract/ConsumerIntegrationTest.java | 2 +- .../mock/contract/ConsumerUsingMockTest.java | 2 +- .../contract/ConsumerUsingProxyHttpTest.java | 2 +- .../ConsumerUsingProxyRewriteSslTest.java | 2 +- .../ConsumerUsingProxyRewriteTest.java | 2 +- .../java/mock/contract/PaymentService.java | 2 +- .../karate/gatling/GatlingJobServer.java | 8 - .../karate/gatling/KarateProtocol.scala | 3 +- .../java/com/intuit/karate/robot/Element.java | 2 +- .../com/intuit/karate/robot/Location.java | 2 +- .../java/com/intuit/karate/robot/Region.java | 2 +- .../com/intuit/karate/robot/RobotBase.java | 2 +- .../com/intuit/karate/robot/RobotFactory.java | 1 - 110 files changed, 226 insertions(+), 12422 deletions(-) delete mode 100644 karate-core/src/main/java/com/intuit/karate/CallContext.java delete mode 100644 karate-core/src/main/java/com/intuit/karate/Config.java rename karate-core/src/main/java/com/intuit/karate/{CallResult.java => Constants.java} (78%) delete mode 100755 karate-core/src/main/java/com/intuit/karate/JsonUtils.java delete mode 100644 karate-core/src/main/java/com/intuit/karate/Match.java delete mode 100755 karate-core/src/main/java/com/intuit/karate/Script.java delete mode 100644 karate-core/src/main/java/com/intuit/karate/ScriptBindings.java delete mode 100644 karate-core/src/main/java/com/intuit/karate/ScriptEvalContext.java delete mode 100644 karate-core/src/main/java/com/intuit/karate/ScriptObjectMap.java delete mode 100755 karate-core/src/main/java/com/intuit/karate/ScriptValue.java delete mode 100755 karate-core/src/main/java/com/intuit/karate/ScriptValueMap.java delete mode 100755 karate-core/src/main/java/com/intuit/karate/StepActions.java delete mode 100644 karate-core/src/main/java/com/intuit/karate/core/ExecutionContext.java delete mode 100644 karate-core/src/main/java/com/intuit/karate/core/ExecutionHook.java delete mode 100644 karate-core/src/main/java/com/intuit/karate/core/ExecutionHookFactory.java delete mode 100644 karate-core/src/main/java/com/intuit/karate/core/FeatureContext.java delete mode 100644 karate-core/src/main/java/com/intuit/karate/core/FeatureExecutionUnit.java delete mode 100644 karate-core/src/main/java/com/intuit/karate/core/FeatureScenarioIterator.java delete mode 100755 karate-core/src/main/java/com/intuit/karate/core/ScenarioContext.java delete mode 100644 karate-core/src/main/java/com/intuit/karate/core/ScenarioExecutionUnit.java delete mode 100644 karate-core/src/main/java/com/intuit/karate/core/ScriptBridge.java delete mode 100644 karate-core/src/main/java/com/intuit/karate/core/Tags.java delete mode 100644 karate-core/src/main/java/com/intuit/karate/http/DummyHttpClient.java delete mode 100644 karate-core/src/main/java/com/intuit/karate/http/HttpBody.java delete mode 100644 karate-core/src/main/java/com/intuit/karate/http/HttpClient.java delete mode 100644 karate-core/src/main/java/com/intuit/karate/http/HttpRequest.java delete mode 100644 karate-core/src/main/java/com/intuit/karate/http/HttpRequestBuilder.java delete mode 100644 karate-core/src/main/java/com/intuit/karate/http/MultiPartItem.java delete mode 100644 karate-core/src/main/java/com/intuit/karate/validator/ArrayValidator.java delete mode 100644 karate-core/src/main/java/com/intuit/karate/validator/BooleanValidator.java delete mode 100755 karate-core/src/main/java/com/intuit/karate/validator/IgnoreValidator.java delete mode 100755 karate-core/src/main/java/com/intuit/karate/validator/NotNullValidator.java delete mode 100755 karate-core/src/main/java/com/intuit/karate/validator/NullValidator.java delete mode 100644 karate-core/src/main/java/com/intuit/karate/validator/NumberValidator.java delete mode 100644 karate-core/src/main/java/com/intuit/karate/validator/ObjectValidator.java delete mode 100755 karate-core/src/main/java/com/intuit/karate/validator/RegexValidator.java delete mode 100644 karate-core/src/main/java/com/intuit/karate/validator/StringValidator.java delete mode 100755 karate-core/src/main/java/com/intuit/karate/validator/UuidValidator.java delete mode 100755 karate-core/src/main/java/com/intuit/karate/validator/ValidationResult.java delete mode 100755 karate-core/src/main/java/com/intuit/karate/validator/Validator.java delete mode 100755 karate-core/src/test/java/com/intuit/karate/JsonUtilsTest.java delete mode 100644 karate-core/src/test/java/com/intuit/karate/MatchTest.java delete mode 100755 karate-core/src/test/java/com/intuit/karate/ScriptTest.java delete mode 100644 karate-core/src/test/java/com/intuit/karate/ScriptValueTest.java delete mode 100644 karate-core/src/test/java/com/intuit/karate/core/TagsTest.java delete mode 100644 karate-core/src/test/java/com/intuit/karate/http/CustomDummyHttpClient.java delete mode 100644 karate-core/src/test/java/com/intuit/karate/http/HttpClientTest.java delete mode 100644 karate-core/src/test/java/com/intuit/karate/http/HttpRequestBuilderTest.java delete mode 100755 karate-core/src/test/java/com/intuit/karate/validator/ValidatorTest.java diff --git a/karate-core/src/main/java/com/intuit/karate/CallContext.java b/karate-core/src/main/java/com/intuit/karate/CallContext.java deleted file mode 100644 index 464cc0fbf..000000000 --- a/karate-core/src/main/java/com/intuit/karate/CallContext.java +++ /dev/null @@ -1,101 +0,0 @@ -/* - * 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.core.ExecutionHook; -import com.intuit.karate.core.ExecutionHookFactory; -import com.intuit.karate.core.Feature; -import com.intuit.karate.core.ScenarioContext; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collection; -import java.util.Map; - -/** - * - * @author pthomas3 - */ -public class CallContext { - - public final Feature feature; - public final ScenarioContext context; - public final int callDepth; - public final Map callArg; - public final boolean reuseParentContext; - public final boolean evalKarateConfig; - public final int loopIndex; - public final String httpClientClass; - public final Collection executionHooks = new ArrayList(); - public final ExecutionHookFactory hookFactory; - public final boolean perfMode; - - public static CallContext forCall(Feature feature, ScenarioContext context, Map callArg, - int loopIndex, boolean reuseParentConfig) { - return new CallContext(feature, context, context.callDepth + 1, callArg, loopIndex, - reuseParentConfig, false, null, context.executionHooks, null, context.perfMode); - } - - public static CallContext forAsync(Feature feature, Collection hooks, ExecutionHookFactory hookFactory, - Map arg, boolean perfMode) { - return new CallContext(feature, null, 0, arg, -1, false, true, null, hooks, hookFactory, perfMode); - } - - public boolean isCalled() { - return callDepth > 0; - } - - private boolean resolved; - - public Collection resolveHooks() { - if (hookFactory == null || resolved) { - return executionHooks; - } - resolved = true; - executionHooks.add(hookFactory.create()); - return executionHooks; - } - - public CallContext(Map callArg, boolean evalKarateConfig, ExecutionHook... hooks) { - this(null, null, 0, callArg, -1, false, evalKarateConfig, null, hooks.length == 0 ? null : Arrays.asList(hooks), null, false); - } - - public CallContext(Feature feature, ScenarioContext context, int callDepth, Map callArg, int loopIndex, - boolean reuseParentContext, boolean evalKarateConfig, String httpClientClass, - Collection executionHooks, ExecutionHookFactory hookFactory, boolean perfMode) { - this.feature = feature; - this.context = context; - this.callDepth = callDepth; - this.callArg = callArg; - this.loopIndex = loopIndex; - this.reuseParentContext = reuseParentContext; - this.evalKarateConfig = evalKarateConfig; - this.httpClientClass = httpClientClass; - if (executionHooks != null) { - this.executionHooks.addAll(executionHooks); - } - this.hookFactory = hookFactory; - this.perfMode = perfMode; - } - -} diff --git a/karate-core/src/main/java/com/intuit/karate/Config.java b/karate-core/src/main/java/com/intuit/karate/Config.java deleted file mode 100644 index ef12724bf..000000000 --- a/karate-core/src/main/java/com/intuit/karate/Config.java +++ /dev/null @@ -1,525 +0,0 @@ -/* - * 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.driver.DockerTarget; -import com.intuit.karate.driver.Target; -import com.intuit.karate.http.HttpClient; -import com.intuit.karate.http.HttpLogModifier; -import java.nio.charset.Charset; -import java.util.List; -import java.util.Map; - -/** - * - * @author pthomas3 - */ -public class Config { - - public static final int DEFAULT_RETRY_INTERVAL = 3000; - public static final int DEFAULT_RETRY_COUNT = 3; - public static final int DEFAULT_TIMEOUT = 30000; - public static final int DEFAULT_HIGHLIGHT_DURATION = 3000; - - private boolean sslEnabled = false; - private String sslAlgorithm = "TLS"; - private String sslKeyStore; - private String sslKeyStorePassword; - private String sslKeyStoreType; - private String sslTrustStore; - private String sslTrustStorePassword; - private String sslTrustStoreType; - private boolean sslTrustAll = true; - private boolean followRedirects = true; - private int readTimeout = DEFAULT_TIMEOUT; - private int connectTimeout = DEFAULT_TIMEOUT; - private Charset charset = FileUtils.UTF8; - private String proxyUri; - private String proxyUsername; - private String proxyPassword; - private List nonProxyHosts; - private String localAddress; - private ScriptValue headers = ScriptValue.NULL; - private ScriptValue cookies = ScriptValue.NULL; - private ScriptValue responseHeaders = ScriptValue.NULL; - private long responseDelay = 0L; - private boolean lowerCaseResponseHeaders = false; - private boolean corsEnabled = false; - private boolean logPrettyRequest; - private boolean logPrettyResponse; - private boolean printEnabled = true; - private boolean outlineVariablesAuto = true; - private boolean abortedStepsShouldPass = false; - private String clientClass; - private HttpClient clientInstance; - private Map userDefined; - private Target driverTarget; - private Map driverOptions; - private Map robotOptions; // TODO make generic plugin model - private ScriptValue afterScenario = ScriptValue.NULL; - private ScriptValue afterFeature = ScriptValue.NULL; - private HttpLogModifier logModifier; - - // retry config - private int retryInterval = DEFAULT_RETRY_INTERVAL; - private int retryCount = DEFAULT_RETRY_COUNT; - - // report config - private boolean showLog = true; - private boolean showAllSteps = true; - - // call single cache config - private int callSingleCacheMinutes = 0; - private String callSingleCacheDir = FileUtils.getBuildDir(); - - public Config() { - // zero arg constructor - } - - private static T get(Map map, String key, T defaultValue) { - Object o = map.get(key); - return o == null ? defaultValue : (T) o; - } - - public boolean configure(String key, ScriptValue value) { // TODO use enum - key = StringUtils.trimToEmpty(key); - switch (key) { - case "headers": - headers = value; - return false; - case "cookies": - cookies = value; - return false; - case "responseHeaders": - responseHeaders = value; - return false; - case "responseDelay": - responseDelay = value.isNull() ? 0L : Double.valueOf(value.getAsString()).longValue(); - return false; - case "lowerCaseResponseHeaders": - lowerCaseResponseHeaders = value.isBooleanTrue(); - return false; - case "cors": - corsEnabled = value.isBooleanTrue(); - return false; - case "logPrettyResponse": - logPrettyResponse = value.isBooleanTrue(); - return false; - case "logPrettyRequest": - logPrettyRequest = value.isBooleanTrue(); - return false; - case "printEnabled": - printEnabled = value.isBooleanTrue(); - return false; - case "afterScenario": - afterScenario = value; - return false; - case "afterFeature": - afterFeature = value; - return false; - case "report": - if (value.isMapLike()) { - Map map = value.getAsMap(); - showLog = get(map, "showLog", showLog); - showAllSteps = get(map, "showAllSteps", showAllSteps); - } else if (value.isBooleanTrue()) { - showLog = true; - showAllSteps = true; - } else { - showLog = false; - showAllSteps = false; - } - return false; - case "driver": - driverOptions = value.getAsMap(); - return false; - case "robot": - robotOptions = value.getAsMap(); - return false; - case "driverTarget": - if (value.isMapLike()) { - Map map = value.getAsMap(); - if (map.containsKey("docker")) { - driverTarget = new DockerTarget(map); - } else { - throw new RuntimeException("bad driverTarget config, expected key 'docker': " + map); - } - } else { - driverTarget = value.getValue(Target.class); - } - return false; - case "retry": - if (value.isMapLike()) { - Map map = value.getAsMap(); - retryInterval = get(map, "interval", retryInterval); - retryCount = get(map, "count", retryCount); - } - return false; - case "outlineVariablesAuto": - outlineVariablesAuto = value.isBooleanTrue(); - return false; - case "abortedStepsShouldPass": - abortedStepsShouldPass = value.isBooleanTrue(); - return false; - case "callSingleCache": - if (value.isMapLike()) { - Map map = value.getAsMap(); - callSingleCacheMinutes = get(map, "minutes", callSingleCacheMinutes); - callSingleCacheDir = get(map, "dir", callSingleCacheDir); - } - return false; - // here on the http client has to be re-constructed ================ - case "httpClientClass": - clientClass = value.getAsString(); - return true; - case "logModifier": - logModifier = value.getValue(HttpLogModifier.class); - return true; - case "httpClientInstance": - clientInstance = value.getValue(HttpClient.class); - return true; - case "charset": - charset = value.isNull() ? null : Charset.forName(value.getAsString()); - return true; - case "ssl": - if (value.isString()) { - sslEnabled = true; - sslAlgorithm = value.getAsString(); - } else if (value.isMapLike()) { - sslEnabled = true; - Map map = value.getAsMap(); - sslKeyStore = (String) map.get("keyStore"); - sslKeyStorePassword = (String) map.get("keyStorePassword"); - sslKeyStoreType = (String) map.get("keyStoreType"); - sslTrustStore = (String) map.get("trustStore"); - sslTrustStorePassword = (String) map.get("trustStorePassword"); - sslTrustStoreType = (String) map.get("trustStoreType"); - Boolean trustAll = (Boolean) map.get("trustAll"); - if (trustAll != null) { - sslTrustAll = trustAll; - } - sslAlgorithm = (String) map.get("algorithm"); - } else { - sslEnabled = value.isBooleanTrue(); - } - return true; - case "followRedirects": - followRedirects = value.isBooleanTrue(); - return true; - case "connectTimeout": - connectTimeout = value.getAsInt(); - return true; - case "readTimeout": - readTimeout = value.getAsInt(); - return true; - case "proxy": - if (value == null) { - proxyUri = null; - } else if (value.isString()) { - proxyUri = value.getAsString(); - } else { - Map map = value.getAsMap(); - proxyUri = (String) map.get("uri"); - proxyUsername = (String) map.get("username"); - proxyPassword = (String) map.get("password"); - nonProxyHosts = (List) map.get("nonProxyHosts"); - } - return true; - case "localAddress": - localAddress = value.getAsString(); - return true; - case "userDefined": - userDefined = value.getAsMap(); - return true; - default: - throw new RuntimeException("unexpected 'configure' key: '" + key + "'"); - } - } - - public Config(Config parent) { - sslEnabled = parent.sslEnabled; - sslAlgorithm = parent.sslAlgorithm; - sslTrustStore = parent.sslTrustStore; - sslTrustStorePassword = parent.sslTrustStorePassword; - sslTrustStoreType = parent.sslTrustStoreType; - sslKeyStore = parent.sslKeyStore; - sslKeyStorePassword = parent.sslKeyStorePassword; - sslKeyStoreType = parent.sslKeyStoreType; - sslTrustAll = parent.sslTrustAll; - followRedirects = parent.followRedirects; - readTimeout = parent.readTimeout; - connectTimeout = parent.connectTimeout; - charset = parent.charset; - proxyUri = parent.proxyUri; - proxyUsername = parent.proxyUsername; - proxyPassword = parent.proxyPassword; - nonProxyHosts = parent.nonProxyHosts; - localAddress = parent.localAddress; - headers = parent.headers; - cookies = parent.cookies; - responseHeaders = parent.responseHeaders; - responseDelay = parent.responseDelay; - lowerCaseResponseHeaders = parent.lowerCaseResponseHeaders; - corsEnabled = parent.corsEnabled; - logPrettyRequest = parent.logPrettyRequest; - logPrettyResponse = parent.logPrettyResponse; - printEnabled = parent.printEnabled; - clientClass = parent.clientClass; - clientInstance = parent.clientInstance; - userDefined = parent.userDefined; - driverOptions = parent.driverOptions; - robotOptions = parent.robotOptions; - driverTarget = parent.driverTarget; - afterScenario = parent.afterScenario; - afterFeature = parent.afterFeature; - showLog = parent.showLog; - showAllSteps = parent.showAllSteps; - retryInterval = parent.retryInterval; - retryCount = parent.retryCount; - outlineVariablesAuto = parent.outlineVariablesAuto; - abortedStepsShouldPass = parent.abortedStepsShouldPass; - logModifier = parent.logModifier; - callSingleCacheMinutes = parent.callSingleCacheMinutes; - callSingleCacheDir = parent.callSingleCacheDir; - } - - public void setCookies(ScriptValue cookies) { - this.cookies = cookies; - } - - public void setClientClass(String clientClass) { - this.clientClass = clientClass; - } - - //========================================================================== - // - public boolean isSslEnabled() { - return sslEnabled; - } - - public String getSslAlgorithm() { - return sslAlgorithm; - } - - public String getSslKeyStore() { - return sslKeyStore; - } - - public String getSslKeyStorePassword() { - return sslKeyStorePassword; - } - - public String getSslKeyStoreType() { - return sslKeyStoreType; - } - - public String getSslTrustStore() { - return sslTrustStore; - } - - public String getSslTrustStorePassword() { - return sslTrustStorePassword; - } - - public String getSslTrustStoreType() { - return sslTrustStoreType; - } - - public boolean isSslTrustAll() { - return sslTrustAll; - } - - public boolean isFollowRedirects() { - return followRedirects; - } - - public int getReadTimeout() { - return readTimeout; - } - - public int getConnectTimeout() { - return connectTimeout; - } - - public Charset getCharset() { - return charset; - } - - public String getProxyUri() { - return proxyUri; - } - - public String getProxyUsername() { - return proxyUsername; - } - - public String getProxyPassword() { - return proxyPassword; - } - - public List getNonProxyHosts() { - return nonProxyHosts; - } - - public String getLocalAddress() { - return localAddress; - } - - public ScriptValue getHeaders() { - return headers; - } - - public ScriptValue getCookies() { - return cookies; - } - - public ScriptValue getResponseHeaders() { - return responseHeaders; - } - - public long getResponseDelay() { - return responseDelay; - } - - public boolean isLowerCaseResponseHeaders() { - return lowerCaseResponseHeaders; - } - - public boolean isCorsEnabled() { - return corsEnabled; - } - - public boolean isLogPrettyRequest() { - return logPrettyRequest; - } - - public boolean isLogPrettyResponse() { - return logPrettyResponse; - } - - public boolean isPrintEnabled() { - return printEnabled; - } - - public String getClientClass() { - return clientClass; - } - - public Map getUserDefined() { - return userDefined; - } - - public Map getDriverOptions() { - return driverOptions; - } - - public Map getRobotOptions() { - return robotOptions; - } - - public HttpClient getClientInstance() { - return clientInstance; - } - - public void setClientInstance(HttpClient clientInstance) { - this.clientInstance = clientInstance; - } - - public ScriptValue getAfterScenario() { - return afterScenario; - } - - public void setAfterScenario(ScriptValue afterScenario) { - this.afterScenario = afterScenario; - } - - public ScriptValue getAfterFeature() { - return afterFeature; - } - - public void setAfterFeature(ScriptValue afterFeature) { - this.afterFeature = afterFeature; - } - - public boolean isShowLog() { - return showLog; - } - - public void setShowLog(boolean showLog) { - this.showLog = showLog; - } - - public boolean isShowAllSteps() { - return showAllSteps; - } - - public void setShowAllSteps(boolean showAllSteps) { - this.showAllSteps = showAllSteps; - } - - public int getRetryInterval() { - return retryInterval; - } - - public void setRetryInterval(int retryInterval) { - this.retryInterval = retryInterval; - } - - public int getRetryCount() { - return retryCount; - } - - public void setRetryCount(int retryCount) { - this.retryCount = retryCount; - } - - public boolean isOutlineVariablesAuto() { - return outlineVariablesAuto; - } - - public boolean isAbortedStepsShouldPass() { - return abortedStepsShouldPass; - } - - public Target getDriverTarget() { - return driverTarget; - } - - public void setDriverTarget(Target driverTarget) { - this.driverTarget = driverTarget; - } - - public HttpLogModifier getLogModifier() { - return logModifier; - } - - public String getCallSingleCacheDir() { - return callSingleCacheDir; - } - - public int getCallSingleCacheMinutes() { - return callSingleCacheMinutes; - } - -} diff --git a/karate-core/src/main/java/com/intuit/karate/CallResult.java b/karate-core/src/main/java/com/intuit/karate/Constants.java similarity index 78% rename from karate-core/src/main/java/com/intuit/karate/CallResult.java rename to karate-core/src/main/java/com/intuit/karate/Constants.java index a2b28143d..8946c1064 100644 --- a/karate-core/src/main/java/com/intuit/karate/CallResult.java +++ b/karate-core/src/main/java/com/intuit/karate/Constants.java @@ -1,7 +1,7 @@ /* * The MIT License * - * Copyright 2017 Intuit Inc. + * Copyright 2020 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 @@ -27,16 +27,15 @@ * * @author pthomas3 */ -public class CallResult { +public class Constants { - protected final ScriptValue value; - protected final Config config; - protected final ScriptValueMap vars; - - public CallResult(ScriptValue value, Config config, ScriptValueMap vars) { - this.value = value; - this.config = config; - this.vars = vars; + private Constants() { + // only static methods } + public static final String KARATE_CONFIG_DIR = "karate.config.dir"; + public static final String KARATE_ENV = "karate.env"; + public static final String SUREFIRE_REPORTS = "surefire-reports"; + + } diff --git a/karate-core/src/main/java/com/intuit/karate/FileUtils.java b/karate-core/src/main/java/com/intuit/karate/FileUtils.java index 212f2ff21..13b519d3a 100755 --- a/karate-core/src/main/java/com/intuit/karate/FileUtils.java +++ b/karate-core/src/main/java/com/intuit/karate/FileUtils.java @@ -23,11 +23,8 @@ */ package com.intuit.karate; -import com.intuit.karate.core.ScenarioContext; import com.intuit.karate.core.Feature; import com.intuit.karate.core.FeatureParser; -import com.intuit.karate.exception.KarateFileNotFoundException; -import com.jayway.jsonpath.DocumentContext; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.File; @@ -130,36 +127,6 @@ public static final boolean isFeatureFile(String text) { return text.endsWith(".feature"); } - public static ScriptValue readFile(String text, ScenarioContext context) { - StringUtils.Pair pair = parsePathAndTags(text); - text = pair.left; - if (isJsonFile(text) || isXmlFile(text) || isJavaScriptFile(text)) { - String contents = readFileAsString(text, context); - contents = StringUtils.fixJavaScriptFunction(contents); - ScriptValue temp = Script.evalKarateExpression(contents, context); - return new ScriptValue(temp.getValue(), text); - } else if (isTextFile(text) || isGraphQlFile(text)) { - String contents = readFileAsString(text, context); - return new ScriptValue(contents, text); - } else if (isFeatureFile(text)) { - Resource fr = toResource(text, context); - Feature feature = FeatureParser.parse(fr); - feature.setCallTag(pair.right); - return new ScriptValue(feature, text); - } else if (isCsvFile(text)) { - String contents = readFileAsString(text, context); - DocumentContext doc = JsonUtils.fromCsv(contents); - return new ScriptValue(doc, text); - } else if (isYamlFile(text)) { - String contents = readFileAsString(text, context); - DocumentContext doc = JsonUtils.fromYaml(contents); - return new ScriptValue(doc, text); - } else { - InputStream is = readFileAsStream(text, context); - return new ScriptValue(is, text); - } - } - public static String removePrefix(String text) { if (text == null) { return null; @@ -187,52 +154,6 @@ public static Feature parseFeatureAndCallTag(String path) { return feature; } - public static Resource toResource(String path, ScenarioContext context) { - if (isClassPath(path)) { - return new Resource(path, context.classLoader); - } else if (isFilePath(path)) { - String temp = removePrefix(path); - return new Resource(new File(temp), path, context.classLoader); - } else if (isThisPath(path)) { - String temp = removePrefix(path); - Path parentPath = context.featureContext.parentPath; - Path childPath = parentPath.resolve(temp); - return new Resource(childPath, context.classLoader); - } else { - try { - Path parentPath = context.rootFeatureContext.parentPath; - Path childPath = parentPath.resolve(path); - return new Resource(childPath, context.classLoader); - } catch (Exception e) { - LOGGER.error("feature relative path resolution failed: {}", e.getMessage()); - throw e; - } - } - } - - public static String readFileAsString(String path, ScenarioContext context) { - return toString(readFileAsStream(path, context)); - } - - public static InputStream readFileAsStream(String path, ScenarioContext context) { - try { - return toResource(path, context).getStream(); - } catch (Exception e) { - InputStream inputStream = context.getResourceAsStream(removePrefix(path)); - if (inputStream == null) { - // attempt to get the file using the class classloader - // workaround for spring boot - inputStream = FileUtils.class.getClassLoader().getResourceAsStream(path); - } - if (inputStream == null) { - String message = String.format("could not find or read file: %s", path); - context.logger.trace("{}", message); - throw new KarateFileNotFoundException(message); - } - return inputStream; - } - } - public static String toPackageQualifiedName(String path) { path = removePrefix(path); path = path.replace('/', '.'); @@ -268,20 +189,6 @@ public static String toString(InputStream is) { } } - public static String toPrettyString(String raw) { - raw = StringUtils.trimToEmpty(raw); - try { - if (Script.isJson(raw)) { - return JsonUtils.toPrettyJsonString(JsonUtils.toJsonDoc(raw)); - } else if (Script.isXml(raw)) { - return XmlUtils.toString(XmlUtils.toXmlDoc(raw), true); - } - } catch (Exception e) { - LOGGER.warn("parsing failed: {}", e.getMessage()); - } - return raw; - } - public static byte[] toBytes(InputStream is) { return toByteStream(is).toByteArray(); } diff --git a/karate-core/src/main/java/com/intuit/karate/JsonUtils.java b/karate-core/src/main/java/com/intuit/karate/JsonUtils.java deleted file mode 100755 index f6f9e9023..000000000 --- a/karate-core/src/main/java/com/intuit/karate/JsonUtils.java +++ /dev/null @@ -1,521 +0,0 @@ -/* - * 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.core.Feature; -import com.intuit.karate.driver.DriverElement; -import com.intuit.karate.driver.Element; -import com.jayway.jsonpath.Configuration; -import com.jayway.jsonpath.DocumentContext; -import com.jayway.jsonpath.JsonPath; -import com.jayway.jsonpath.Option; -import com.jayway.jsonpath.PathNotFoundException; -import com.jayway.jsonpath.spi.json.JsonProvider; -import com.jayway.jsonpath.spi.json.JsonSmartJsonProvider; -import com.jayway.jsonpath.spi.mapper.JsonSmartMappingProvider; -import com.jayway.jsonpath.spi.mapper.MappingProvider; -import de.siegmar.fastcsv.reader.CsvContainer; -import de.siegmar.fastcsv.reader.CsvReader; -import de.siegmar.fastcsv.reader.CsvRow; -import de.siegmar.fastcsv.writer.CsvWriter; -import java.io.IOException; -import java.io.StringReader; -import java.io.StringWriter; -import java.util.ArrayList; -import java.util.Collections; -import java.util.EnumSet; -import java.util.IdentityHashMap; -import java.util.Iterator; -import java.util.LinkedHashMap; -import java.util.List; -import java.util.Map; -import java.util.Set; -import jdk.nashorn.api.scripting.ScriptObjectMirror; -import net.minidev.json.JSONArray; -import net.minidev.json.JSONStyle; -import net.minidev.json.JSONValue; -import net.minidev.json.parser.JSONParser; -import net.minidev.json.parser.ParseException; -import net.minidev.json.reader.JsonWriter; -import net.minidev.json.reader.JsonWriterI; -import org.yaml.snakeyaml.Yaml; -import org.yaml.snakeyaml.constructor.SafeConstructor; - -/** - * - * @author pthomas3 - */ -public class JsonUtils { - - private JsonUtils() { - // only static methods - } - - private static class NashornObjectJsonWriter implements JsonWriterI { - - @Override - public void writeJSONString(E value, Appendable out, JSONStyle compression) throws IOException { - if (value.isArray()) { - Object[] array = value.values().toArray(); - JsonWriter.arrayWriter.writeJSONString(array, out, compression); - } else if (value.isFunction()) { - JsonWriter.toStringWriter.writeJSONString("\"#function\"", out, compression); - } else { // JSON - JsonWriter.JSONMapWriter.writeJSONString(value, out, compression); - } - } - - } - - private static class FeatureJsonWriter implements JsonWriterI { - - @Override - public void writeJSONString(E value, Appendable out, JSONStyle compression) throws IOException { - JsonWriter.toStringWriter.writeJSONString("\"#feature\"", out, compression); - } - - } - - private static class DriverElementJsonWriter implements JsonWriterI { - - @Override - public void writeJSONString(E value, Appendable out, JSONStyle compression) throws IOException { - JsonWriter.toStringWriter.writeJSONString("\"" + value.getLocator() + "\"", out, compression); - } - - } - - static { - // prevent things like the karate script bridge getting serialized (especially in the javafx ui) - JSONValue.registerWriter(ScriptObjectMirror.class, new NashornObjectJsonWriter()); - JSONValue.registerWriter(Feature.class, new FeatureJsonWriter()); - JSONValue.registerWriter(DriverElement.class, new DriverElementJsonWriter()); - // ensure that even if jackson (databind?) is on the classpath, don't switch provider - Configuration.setDefaults(new Configuration.Defaults() { - - private final JsonProvider jsonProvider = new JsonSmartJsonProvider(); - private final MappingProvider mappingProvider = new JsonSmartMappingProvider(); - - @Override - public JsonProvider jsonProvider() { - return jsonProvider; - } - - @Override - public MappingProvider mappingProvider() { - return mappingProvider; - } - - @Override - public Set