From 5e54faca5da21dc8870dcafbe07e9099aa9e74f3 Mon Sep 17 00:00:00 2001 From: Christoph Deppisch Date: Fri, 5 Apr 2024 09:29:25 +0200 Subject: [PATCH] chore: Add ResourceUtils to resolve file resources - ResourceUtils automatically resolves file resources based on the feature file package --- .../yaks/camelk/CamelKSteps.java | 7 +- .../yaks/camelk/KameletSteps.java | 10 ++- .../integration/CreateIntegrationAction.java | 5 +- java/steps/yaks-camel/pom.xml | 11 ++- .../yaks/camel/CamelSteps.java | 8 +-- java/steps/yaks-groovy/pom.xml | 12 ++-- .../yaks/groovy/GroovyScriptSteps.java | 11 +-- .../yaks/groovy/GroovyShellUtils.java | 13 ++++ .../yaks/groovy/dsl/actions/ActionScript.java | 1 + .../yaks/http/HttpClientSteps.java | 5 +- .../yaks/http/HttpServerSteps.java | 9 +-- java/steps/yaks-jms/pom.xml | 12 ++-- .../citrusframework/yaks/jms/JmsSteps.java | 3 +- .../yaks/kafka/KafkaSteps.java | 3 +- .../yaks/kubernetes/KubernetesSteps.java | 9 +-- .../actions/CreateSecretAction.java | 3 +- java/steps/yaks-openapi/pom.xml | 11 ++- .../yaks/openapi/OpenApiResourceLoader.java | 5 +- .../yaks/openapi/OpenApiSteps.java | 13 ++-- .../yaks/YaksVariableNames.java | 2 + .../yaks/hooks/InjectEnvVarsHook.java | 10 ++- .../yaks/report/TestReporter.java | 6 +- .../yaks/standard/StandardSteps.java | 7 +- .../yaks/util/CucumberUtils.java | 71 ++++++++++++++++--- .../yaks/util/ResourceUtils.java | 47 ++++++++++++ .../yaks/util/CucumberUtilsTest.java | 29 ++++++-- .../DatabaseContainerSteps.java | 3 +- 27 files changed, 242 insertions(+), 84 deletions(-) create mode 100644 java/steps/yaks-standard/src/main/java/org/citrusframework/yaks/util/ResourceUtils.java diff --git a/java/steps/yaks-camel-k/src/main/java/org/citrusframework/yaks/camelk/CamelKSteps.java b/java/steps/yaks-camel-k/src/main/java/org/citrusframework/yaks/camelk/CamelKSteps.java index 8914d0cc..afd231c9 100644 --- a/java/steps/yaks-camel-k/src/main/java/org/citrusframework/yaks/camelk/CamelKSteps.java +++ b/java/steps/yaks-camel-k/src/main/java/org/citrusframework/yaks/camelk/CamelKSteps.java @@ -39,6 +39,7 @@ import org.citrusframework.util.FileUtils; import org.citrusframework.yaks.camelk.actions.integration.CreateIntegrationAction; import org.citrusframework.yaks.kubernetes.KubernetesSupport; +import org.citrusframework.yaks.util.ResourceUtils; import static org.citrusframework.actions.CreateVariablesAction.Builder.createVariable; import static org.citrusframework.container.Assert.Builder.assertException; @@ -167,7 +168,7 @@ public void createIntegration(String name, String language, Map @Given("^load Camel K integration ([a-zA-Z0-9][a-zA-Z0-9-\\.]+[a-zA-Z0-9])\\.([a-z0-9-]+)$") public void loadIntegrationFromFile(String name, String language) { try { - createIntegration(name, language, FileUtils.readToString(FileUtils.getFileResource(name + "." + language))); + createIntegration(name, language, FileUtils.readToString(ResourceUtils.resolve(name + "." + language, context))); } catch (IOException e) { throw new CitrusRuntimeException(String.format("Failed to load Camel K integration from resource %s", name + "." + language), e); } @@ -176,7 +177,7 @@ public void loadIntegrationFromFile(String name, String language) { @Given("^load Camel K integration ([a-zA-Z0-9][a-zA-Z0-9-\\.]+[a-zA-Z0-9])\\.([a-z0-9-]+) with configuration:?$") public void loadIntegrationFromFile(String name, String language, Map configuration) { try { - createIntegration(name, language, FileUtils.readToString(FileUtils.getFileResource(name + "." + language)), configuration); + createIntegration(name, language, FileUtils.readToString(ResourceUtils.resolve(name + "." + language, context)), configuration); } catch (IOException e) { throw new CitrusRuntimeException(String.format("Failed to load Camel K integration from resource %s", name + "." + language), e); } @@ -283,7 +284,7 @@ private void createIntegration(String name, String language, String source, Map< String openApiSpec = configuration.getOrDefault("openapi", ""); if (!openApiSpec.isEmpty()) { try { - Resource file = FileUtils.getFileResource(openApiSpec); + Resource file = ResourceUtils.resolve(openApiSpec, context); create.openApi(FileUtils.getFileName(file.getLocation()), FileUtils.readToString(file)); } catch (IOException e) { throw new CitrusRuntimeException(String.format("Failed to read openapi spec form file path %s", openApiSpec)); diff --git a/java/steps/yaks-camel-k/src/main/java/org/citrusframework/yaks/camelk/KameletSteps.java b/java/steps/yaks-camel-k/src/main/java/org/citrusframework/yaks/camelk/KameletSteps.java index 04c22171..1e5ebc75 100644 --- a/java/steps/yaks-camel-k/src/main/java/org/citrusframework/yaks/camelk/KameletSteps.java +++ b/java/steps/yaks-camel-k/src/main/java/org/citrusframework/yaks/camelk/KameletSteps.java @@ -28,9 +28,9 @@ import org.citrusframework.TestCaseRunner; import org.citrusframework.annotations.CitrusFramework; import org.citrusframework.annotations.CitrusResource; +import org.citrusframework.context.TestContext; import org.citrusframework.exceptions.CitrusRuntimeException; import org.citrusframework.spi.Resource; -import org.citrusframework.spi.Resources; import org.citrusframework.yaks.camelk.model.Kamelet; import org.citrusframework.yaks.camelk.model.KameletSpec; import org.citrusframework.yaks.camelk.model.Pipe; @@ -38,6 +38,7 @@ import org.citrusframework.yaks.kafka.KafkaSettings; import org.citrusframework.yaks.knative.KnativeSettings; import org.citrusframework.yaks.kubernetes.KubernetesSupport; +import org.citrusframework.yaks.util.ResourceUtils; import org.springframework.util.StringUtils; import static org.citrusframework.actions.CreateVariablesAction.Builder.createVariable; @@ -52,6 +53,9 @@ public class KameletSteps { @CitrusFramework private Citrus citrus; + @CitrusResource + private TestContext context; + private KubernetesClient k8sClient; private String kameletApiVersion = KameletSettings.getKameletApiVersion(); @@ -216,7 +220,7 @@ public void bindKameletToKnativeChannel(String kameletName, String channel, Stri @Given("^load Kamelet ([a-z0-9-]+).kamelet.yaml$") public void loadKameletFromFile(String fileName) { - Resource resource = Resources.fromClasspath(fileName + ".kamelet.yaml"); + Resource resource = ResourceUtils.resolve(fileName + ".kamelet.yaml", context); runner.run(camelk() .client(k8sClient) .createKamelet(fileName) @@ -234,7 +238,7 @@ public void loadKameletFromFile(String fileName) { @Given("^load (?:Pipe|KameletBinding) ([a-z0-9-]+).yaml$") public void loadPipeFromFile(String fileName) { - Resource resource = Resources.fromClasspath(fileName + ".yaml"); + Resource resource = ResourceUtils.resolve(fileName + ".yaml", context); runner.run(camelk() .client(k8sClient) .createPipe(fileName) diff --git a/java/steps/yaks-camel-k/src/main/java/org/citrusframework/yaks/camelk/actions/integration/CreateIntegrationAction.java b/java/steps/yaks-camel-k/src/main/java/org/citrusframework/yaks/camelk/actions/integration/CreateIntegrationAction.java index 2cc5de19..7eec264b 100644 --- a/java/steps/yaks-camel-k/src/main/java/org/citrusframework/yaks/camelk/actions/integration/CreateIntegrationAction.java +++ b/java/steps/yaks-camel-k/src/main/java/org/citrusframework/yaks/camelk/actions/integration/CreateIntegrationAction.java @@ -46,6 +46,7 @@ import org.citrusframework.yaks.camelk.model.IntegrationList; import org.citrusframework.yaks.camelk.model.IntegrationSpec; import org.citrusframework.yaks.kubernetes.KubernetesSupport; +import org.citrusframework.yaks.util.ResourceUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -327,7 +328,7 @@ private void addPropertyConfigurationSpec(Integration.Builder integrationBuilder for (String pf : propertyFiles){ try { Properties props = new Properties(); - props.load(FileUtils.getFileResource(context.replaceDynamicContentInString(pf)).getInputStream()); + props.load(ResourceUtils.resolve(pf, context).getInputStream()); props.forEach((key, value) -> configurationList.add( new IntegrationSpec.Configuration("property", createPropertySpec(key.toString(), value.toString(), context)))); } catch (IOException e) { @@ -361,7 +362,7 @@ private void addBuildPropertyConfigurationSpec(Integration.Builder integrationBu for (String pf : buildPropertyFiles){ try { Properties props = new Properties(); - props.load(FileUtils.getFileResource(context.replaceDynamicContentInString(pf)).getInputStream()); + props.load(ResourceUtils.resolve(pf, context).getInputStream()); props.forEach((key, value) -> addTraitSpec(String.format("%s=%s", traitName, createPropertySpec(key.toString(), value.toString(), context)), traitConfigMap)); diff --git a/java/steps/yaks-camel/pom.xml b/java/steps/yaks-camel/pom.xml index 33638825..c8c857e0 100644 --- a/java/steps/yaks-camel/pom.xml +++ b/java/steps/yaks-camel/pom.xml @@ -29,6 +29,11 @@ YAKS :: Steps :: Apache Camel + + org.citrusframework.yaks + yaks-standard + ${project.version} + org.citrusframework.yaks yaks-groovy @@ -81,12 +86,6 @@ - - org.citrusframework.yaks - yaks-standard - ${project.version} - test - io.cucumber cucumber-junit diff --git a/java/steps/yaks-camel/src/main/java/org/citrusframework/yaks/camel/CamelSteps.java b/java/steps/yaks-camel/src/main/java/org/citrusframework/yaks/camel/CamelSteps.java index 4020d1ba..a8ed1f6f 100644 --- a/java/steps/yaks-camel/src/main/java/org/citrusframework/yaks/camel/CamelSteps.java +++ b/java/steps/yaks-camel/src/main/java/org/citrusframework/yaks/camel/CamelSteps.java @@ -54,10 +54,10 @@ import org.citrusframework.context.TestContext; import org.citrusframework.exceptions.CitrusRuntimeException; import org.citrusframework.spi.Resource; -import org.citrusframework.spi.Resources; import org.citrusframework.util.FileUtils; import org.citrusframework.xml.StringSource; import org.citrusframework.yaks.groovy.GroovyShellUtils; +import org.citrusframework.yaks.util.ResourceUtils; import org.codehaus.groovy.control.customizers.ImportCustomizer; import org.springframework.context.ApplicationContext; import org.springframework.context.support.GenericXmlApplicationContext; @@ -187,7 +187,7 @@ public void bindComponent(String name, String configurationScript) { @Given("^load to Camel registry ([^\"\\s]+)\\.groovy$") public void loadComponent(String filePath) throws IOException { - Resource scriptFile = FileUtils.getFileResource(filePath + ".groovy"); + Resource scriptFile = ResourceUtils.resolve(filePath + ".groovy", context); String script = FileUtils.readToString(scriptFile); final String fileName = FileUtils.getFileName(scriptFile.getLocation()); final String baseName = Optional.ofNullable(fileName) @@ -267,7 +267,7 @@ protected void configureRoute(RouteDefinition route) { @Given("^load Camel route ([^\\s]+)\\.(groovy|xml)") public void loadCamelRoute(String fileName, String language) throws Exception { - String route = FileUtils.readToString(Resources.create(fileName)); + String route = FileUtils.readToString(ResourceUtils.resolve(fileName, context)); switch (language) { case "groovy": camelRouteGroovy(fileName, route); @@ -330,7 +330,7 @@ public void setExchangeBody(String body) { @Then("^(?:expect|verify) Camel exchange body loaded from ([^\\s]+)$") public void loadExchangeBody(String file) { try { - this.body = FileUtils.readToString(FileUtils.getFileResource(file)); + this.body = FileUtils.readToString(ResourceUtils.resolve(file, context)); } catch (IOException e) { throw new CitrusRuntimeException(String.format("Failed to load body from file resource %s", file)); } diff --git a/java/steps/yaks-groovy/pom.xml b/java/steps/yaks-groovy/pom.xml index 8b4ec233..e8977a00 100644 --- a/java/steps/yaks-groovy/pom.xml +++ b/java/steps/yaks-groovy/pom.xml @@ -29,6 +29,12 @@ YAKS :: Steps :: Groovy + + org.citrusframework.yaks + yaks-standard + ${project.version} + + io.cucumber cucumber-java @@ -95,12 +101,6 @@ citrus-validation-text test - - org.citrusframework.yaks - yaks-standard - ${project.version} - test - org.citrusframework.yaks yaks-http diff --git a/java/steps/yaks-groovy/src/main/java/org/citrusframework/yaks/groovy/GroovyScriptSteps.java b/java/steps/yaks-groovy/src/main/java/org/citrusframework/yaks/groovy/GroovyScriptSteps.java index a74bea99..7b2829cb 100644 --- a/java/steps/yaks-groovy/src/main/java/org/citrusframework/yaks/groovy/GroovyScriptSteps.java +++ b/java/steps/yaks-groovy/src/main/java/org/citrusframework/yaks/groovy/GroovyScriptSteps.java @@ -39,6 +39,7 @@ import org.citrusframework.yaks.groovy.dsl.ConfigurationScript; import org.citrusframework.yaks.groovy.dsl.actions.ActionScript; import org.citrusframework.yaks.groovy.dsl.endpoints.EndpointConfigurationScript; +import org.citrusframework.yaks.util.ResourceUtils; import org.codehaus.groovy.control.customizers.ImportCustomizer; /** @@ -70,7 +71,7 @@ public void createConfiguration(String config) { @Given("^load configuration ([^\"\\s]+)\\.groovy$") public void loadConfiguration(String filePath) throws IOException { - Resource scriptFile = FileUtils.getFileResource(filePath + ".groovy"); + Resource scriptFile = ResourceUtils.resolve(filePath + ".groovy", context); String script = FileUtils.readToString(scriptFile); createConfiguration(script); } @@ -92,7 +93,7 @@ public void createEndpoint(String name, String configurationScript) { @Given("^load endpoint ([^\"\\s]+)\\.groovy$") public void loadEndpoint(String filePath) throws IOException { - Resource scriptFile = FileUtils.getFileResource(filePath + ".groovy"); + Resource scriptFile = ResourceUtils.resolve(filePath + ".groovy", context); String script = FileUtils.readToString(scriptFile); final String fileName = FileUtils.getFileName(scriptFile.getLocation()); final String baseName = Optional.ofNullable(fileName) @@ -117,7 +118,7 @@ public void createComponent(String name, String configurationScript) { @Given("^load component ([^\"\\s]+)\\.groovy$") public void loadComponent(String filePath) throws IOException { - Resource scriptFile = FileUtils.getFileResource(filePath + ".groovy"); + Resource scriptFile = ResourceUtils.resolve(filePath + ".groovy", context); String script = FileUtils.readToString(scriptFile); final String fileName = FileUtils.getFileName(scriptFile.getLocation()); final String baseName = Optional.ofNullable(fileName) @@ -135,7 +136,7 @@ public void createActionScript(String scriptName, String code) { @Given("^load actions ([^\"\\s]+)\\.groovy$") public void loadActionScript(String filePath) throws IOException { - Resource scriptFile = FileUtils.getFileResource(filePath + ".groovy"); + Resource scriptFile = ResourceUtils.resolve(filePath + ".groovy", context); String script = FileUtils.readToString(scriptFile); final String fileName = FileUtils.getFileName(scriptFile.getLocation()); final String baseName = Optional.ofNullable(fileName) @@ -183,7 +184,7 @@ public void applyScriptMultiline(String script) { @Given("^(?:apply|run) script ([^\"\\s]+)\\.groovy$") public void applyScriptFile(String filePath) throws IOException { - Resource scriptFile = FileUtils.getFileResource(filePath + ".groovy"); + Resource scriptFile = ResourceUtils.resolve(filePath + ".groovy", context); applyScript(context.replaceDynamicContentInString(FileUtils.readToString(scriptFile))); } } diff --git a/java/steps/yaks-groovy/src/main/java/org/citrusframework/yaks/groovy/GroovyShellUtils.java b/java/steps/yaks-groovy/src/main/java/org/citrusframework/yaks/groovy/GroovyShellUtils.java index e77de023..e99584a5 100644 --- a/java/steps/yaks-groovy/src/main/java/org/citrusframework/yaks/groovy/GroovyShellUtils.java +++ b/java/steps/yaks-groovy/src/main/java/org/citrusframework/yaks/groovy/GroovyShellUtils.java @@ -95,4 +95,17 @@ public static String removeComments(String script) { return script.trim(); } } + + /** + * Remove package declaration. + * @param script + * @return + */ + public static String removePackageDeclaration(String script) { + if (script.startsWith("package ")) { + return script.substring(script.indexOf("\n")).trim(); + } else { + return script.trim(); + } + } } diff --git a/java/steps/yaks-groovy/src/main/java/org/citrusframework/yaks/groovy/dsl/actions/ActionScript.java b/java/steps/yaks-groovy/src/main/java/org/citrusframework/yaks/groovy/dsl/actions/ActionScript.java index f5221764..6261cf94 100644 --- a/java/steps/yaks-groovy/src/main/java/org/citrusframework/yaks/groovy/dsl/actions/ActionScript.java +++ b/java/steps/yaks-groovy/src/main/java/org/citrusframework/yaks/groovy/dsl/actions/ActionScript.java @@ -44,6 +44,7 @@ public void execute(TestActionRunner runner) { private String normalize(String script) { String normalized = GroovyShellUtils.removeComments(script); + normalized = GroovyShellUtils.removePackageDeclaration(normalized); if (isActionScript(normalized)) { if (normalized.startsWith("$(")) { diff --git a/java/steps/yaks-http/src/main/java/org/citrusframework/yaks/http/HttpClientSteps.java b/java/steps/yaks-http/src/main/java/org/citrusframework/yaks/http/HttpClientSteps.java index a8576eed..3c2c3ec0 100644 --- a/java/steps/yaks-http/src/main/java/org/citrusframework/yaks/http/HttpClientSteps.java +++ b/java/steps/yaks-http/src/main/java/org/citrusframework/yaks/http/HttpClientSteps.java @@ -56,6 +56,7 @@ import org.citrusframework.http.message.HttpMessage; import org.citrusframework.util.FileUtils; import org.citrusframework.variable.dictionary.DataDictionary; +import org.citrusframework.yaks.util.ResourceUtils; import org.springframework.http.HttpHeaders; import org.springframework.http.HttpStatus; import org.springframework.http.client.HttpComponentsClientHttpRequestFactory; @@ -285,7 +286,7 @@ public void setRequestBodyMultiline(String body) { @Given("^load HTTP request body ([^\\s]+)$") public void loadRequestBody(String file) { try { - setRequestBody(FileUtils.readToString(FileUtils.getFileResource(file))); + setRequestBody(FileUtils.readToString(ResourceUtils.resolve(file, context))); } catch (IOException e) { throw new CitrusRuntimeException(String.format("Failed to load body from file resource %s", file)); } @@ -304,7 +305,7 @@ public void setResponseBodyMultiline(String body) { @Given("^(?:expect|verify) HTTP response body loaded from ([^\\s]+)$") public void loadResponseBody(String file) { try { - setResponseBody(FileUtils.readToString(FileUtils.getFileResource(file))); + setResponseBody(FileUtils.readToString(ResourceUtils.resolve(file, context))); } catch (IOException e) { throw new CitrusRuntimeException(String.format("Failed to load body from file resource %s", file)); } diff --git a/java/steps/yaks-http/src/main/java/org/citrusframework/yaks/http/HttpServerSteps.java b/java/steps/yaks-http/src/main/java/org/citrusframework/yaks/http/HttpServerSteps.java index 99172b9d..273e8aca 100644 --- a/java/steps/yaks-http/src/main/java/org/citrusframework/yaks/http/HttpServerSteps.java +++ b/java/steps/yaks-http/src/main/java/org/citrusframework/yaks/http/HttpServerSteps.java @@ -50,6 +50,7 @@ import org.citrusframework.http.server.HttpServerBuilder; import org.citrusframework.util.FileUtils; import org.citrusframework.variable.dictionary.DataDictionary; +import org.citrusframework.yaks.util.ResourceUtils; import org.eclipse.jetty.http.HttpVersion; import org.eclipse.jetty.server.HttpConfiguration; import org.eclipse.jetty.server.HttpConnectionFactory; @@ -318,7 +319,7 @@ public void setResponseBodyMultiline(String body) { @Given("^load HTTP response body ([^\\s]+)$") public void loadResponseBody(String file) { try { - setResponseBody(FileUtils.readToString(FileUtils.getFileResource(file))); + setResponseBody(FileUtils.readToString(ResourceUtils.resolve(file, context))); } catch (IOException e) { throw new CitrusRuntimeException(String.format("Failed to load body from file resource %s", file)); } @@ -337,7 +338,7 @@ public void setRequestBodyMultiline(String body) { @Then("^(?:expect|verify) HTTP request body loaded from ([^\\s]+)$") public void loadRequestBody(String file) { try { - setRequestBody(FileUtils.readToString(FileUtils.getFileResource(file))); + setRequestBody(FileUtils.readToString(ResourceUtils.resolve(file, context))); } catch (IOException e) { throw new CitrusRuntimeException(String.format("Failed to load body from file resource %s", file)); } @@ -566,12 +567,12 @@ private String getKeyStorePathPath() throws IOException { if (sslKeyStorePath.equals(HttpSettings.SECURE_KEYSTORE_PATH_DEFAULT)) { File tmpKeyStore = File.createTempFile("http-server", ".jks"); - try (InputStream in = FileUtils.getFileResource(sslKeyStorePath).getInputStream()) { + try (InputStream in = ResourceUtils.resolve(sslKeyStorePath, context).getInputStream()) { Files.copy(in, tmpKeyStore.toPath(), StandardCopyOption.REPLACE_EXISTING); return tmpKeyStore.getPath(); } } else { - return FileUtils.getFileResource(context.replaceDynamicContentInString(sslKeyStorePath)).getLocation(); + return ResourceUtils.resolve(sslKeyStorePath, context).getLocation(); } } diff --git a/java/steps/yaks-jms/pom.xml b/java/steps/yaks-jms/pom.xml index 45b9655a..bfff6782 100644 --- a/java/steps/yaks-jms/pom.xml +++ b/java/steps/yaks-jms/pom.xml @@ -29,6 +29,12 @@ YAKS :: Steps :: JMS + + org.citrusframework.yaks + yaks-standard + ${project.version} + + io.cucumber cucumber-java @@ -81,12 +87,6 @@ citrus-validation-text test - - org.citrusframework.yaks - yaks-standard - ${project.version} - test - org.apache.activemq artemis-jakarta-server diff --git a/java/steps/yaks-jms/src/main/java/org/citrusframework/yaks/jms/JmsSteps.java b/java/steps/yaks-jms/src/main/java/org/citrusframework/yaks/jms/JmsSteps.java index 9917daed..6b460b90 100644 --- a/java/steps/yaks-jms/src/main/java/org/citrusframework/yaks/jms/JmsSteps.java +++ b/java/steps/yaks-jms/src/main/java/org/citrusframework/yaks/jms/JmsSteps.java @@ -39,6 +39,7 @@ import org.citrusframework.jms.endpoint.JmsEndpointBuilder; import org.citrusframework.util.FileUtils; import org.citrusframework.yaks.jms.connection.ConnectionFactoryCreator; +import org.citrusframework.yaks.util.ResourceUtils; import static org.citrusframework.actions.ReceiveMessageAction.Builder.receive; import static org.citrusframework.actions.SendMessageAction.Builder.send; @@ -169,7 +170,7 @@ public void setMessageBodyMultiline(String body) { @Given("^(?:expect|verify) (?:JMS|jms) message body loaded from ([^\\s]+)$") public void loadMessageBody(String file) { try { - setMessageBody(FileUtils.readToString(FileUtils.getFileResource(file))); + setMessageBody(FileUtils.readToString(ResourceUtils.resolve(file, context))); } catch (IOException e) { throw new CitrusRuntimeException(String.format("Failed to load body from file resource %s", file)); } diff --git a/java/steps/yaks-kafka/src/main/java/org/citrusframework/yaks/kafka/KafkaSteps.java b/java/steps/yaks-kafka/src/main/java/org/citrusframework/yaks/kafka/KafkaSteps.java index 786f81a2..6c314d12 100644 --- a/java/steps/yaks-kafka/src/main/java/org/citrusframework/yaks/kafka/KafkaSteps.java +++ b/java/steps/yaks-kafka/src/main/java/org/citrusframework/yaks/kafka/KafkaSteps.java @@ -39,6 +39,7 @@ import io.cucumber.java.en.Then; import io.cucumber.java.en.When; import org.citrusframework.yaks.YaksSettings; +import org.citrusframework.yaks.util.ResourceUtils; import static org.citrusframework.actions.ReceiveMessageAction.Builder.receive; import static org.citrusframework.actions.SendMessageAction.Builder.send; @@ -183,7 +184,7 @@ public void setMessageBodyMultiline(String body) { @Given("^(?:expect|verify) (?:Kafka|kafka) message body loaded from ([^\\s]+)$") public void loadMessageBody(String file) { try { - setMessageBody(FileUtils.readToString(FileUtils.getFileResource(file))); + setMessageBody(FileUtils.readToString(ResourceUtils.resolve(file, context))); } catch (IOException e) { throw new CitrusRuntimeException(String.format("Failed to load body from file resource %s", file)); } diff --git a/java/steps/yaks-kubernetes/src/main/java/org/citrusframework/yaks/kubernetes/KubernetesSteps.java b/java/steps/yaks-kubernetes/src/main/java/org/citrusframework/yaks/kubernetes/KubernetesSteps.java index c0c463f0..b8a605ad 100644 --- a/java/steps/yaks-kubernetes/src/main/java/org/citrusframework/yaks/kubernetes/KubernetesSteps.java +++ b/java/steps/yaks-kubernetes/src/main/java/org/citrusframework/yaks/kubernetes/KubernetesSteps.java @@ -43,6 +43,7 @@ import org.citrusframework.yaks.http.HttpServerSteps; import org.citrusframework.yaks.kubernetes.actions.CreateServiceAction; import org.citrusframework.yaks.kubernetes.actions.VerifyPodAction; +import org.citrusframework.yaks.util.ResourceUtils; import org.springframework.http.HttpStatus; import static org.citrusframework.actions.CreateVariablesAction.Builder.createVariable; @@ -150,7 +151,7 @@ public void createCustomResource(String resourceType, String yaml) { @Given("^load Kubernetes custom resource ([^\\s]+) in ([^\\s]+)$") public void createCustomResourceFromFile(String fileName, String resourceType) { try { - createCustomResource(resourceType, FileUtils.readToString(FileUtils.getFileResource(fileName))); + createCustomResource(resourceType, FileUtils.readToString(ResourceUtils.resolve(fileName, context))); } catch (IOException e) { throw new CitrusRuntimeException("Failed to read custom resource from file", e); } @@ -171,7 +172,7 @@ public void deleteCustomResource(String resourceType, String yaml) { @Given("^delete Kubernetes custom resource ([^\\s]+) in ([^\\s]+)$") public void deleteCustomResourceFromFile(String fileName, String resourceType) { try { - deleteCustomResource(resourceType, FileUtils.readToString(FileUtils.getFileResource(fileName))); + deleteCustomResource(resourceType, FileUtils.readToString(ResourceUtils.resolve(fileName, context))); } catch (IOException e) { throw new CitrusRuntimeException("Failed to read custom resource from file", e); } @@ -195,7 +196,7 @@ public void createResource(String content) { @Given("^load Kubernetes resource ([^\\s]+)$") public void createResourceFromFile(String fileName) { try { - createResource(FileUtils.readToString(FileUtils.getFileResource(fileName))); + createResource(FileUtils.readToString(ResourceUtils.resolve(fileName, context))); } catch (IOException e) { throw new CitrusRuntimeException("Failed to read resource from file", e); } @@ -211,7 +212,7 @@ public void deleteResource(String yaml) { @Given("^delete Kubernetes resource ([^\\s]+)$") public void deleteResourceFromFile(String fileName) { try { - deleteResource(FileUtils.readToString(FileUtils.getFileResource(fileName))); + deleteResource(FileUtils.readToString(ResourceUtils.resolve(fileName, context))); } catch (IOException e) { throw new CitrusRuntimeException("Failed to read resource from file", e); } diff --git a/java/steps/yaks-kubernetes/src/main/java/org/citrusframework/yaks/kubernetes/actions/CreateSecretAction.java b/java/steps/yaks-kubernetes/src/main/java/org/citrusframework/yaks/kubernetes/actions/CreateSecretAction.java index b2adcfa4..8f4a5baf 100644 --- a/java/steps/yaks-kubernetes/src/main/java/org/citrusframework/yaks/kubernetes/actions/CreateSecretAction.java +++ b/java/steps/yaks-kubernetes/src/main/java/org/citrusframework/yaks/kubernetes/actions/CreateSecretAction.java @@ -30,6 +30,7 @@ import org.citrusframework.exceptions.CitrusRuntimeException; import org.citrusframework.spi.Resource; import org.citrusframework.util.FileUtils; +import org.citrusframework.yaks.util.ResourceUtils; /** * @author Christoph Deppisch @@ -53,7 +54,7 @@ public void doExecute(TestContext context) { Map data = new LinkedHashMap<>(); if (filePath != null) { try { - Resource file = FileUtils.getFileResource(context.replaceDynamicContentInString(filePath)); + Resource file = ResourceUtils.resolve(filePath, context); String resolvedFileContent = context.replaceDynamicContentInString(FileUtils.readToString(file, StandardCharsets.UTF_8)); diff --git a/java/steps/yaks-openapi/pom.xml b/java/steps/yaks-openapi/pom.xml index 7e935bf8..e26a07dc 100644 --- a/java/steps/yaks-openapi/pom.xml +++ b/java/steps/yaks-openapi/pom.xml @@ -29,6 +29,11 @@ YAKS :: Steps :: Open API + + org.citrusframework.yaks + yaks-standard + ${project.version} + org.citrusframework.yaks yaks-http @@ -80,12 +85,6 @@ citrus-validation-hamcrest test - - org.citrusframework.yaks - yaks-standard - ${project.version} - test - diff --git a/java/steps/yaks-openapi/src/main/java/org/citrusframework/yaks/openapi/OpenApiResourceLoader.java b/java/steps/yaks-openapi/src/main/java/org/citrusframework/yaks/openapi/OpenApiResourceLoader.java index 61ed0141..6437faf4 100644 --- a/java/steps/yaks-openapi/src/main/java/org/citrusframework/yaks/openapi/OpenApiResourceLoader.java +++ b/java/steps/yaks-openapi/src/main/java/org/citrusframework/yaks/openapi/OpenApiResourceLoader.java @@ -33,6 +33,7 @@ import org.apache.hc.client5.http.ssl.TrustAllStrategy; import org.apache.hc.core5.http.HttpHeaders; import org.apache.hc.core5.ssl.SSLContexts; +import org.citrusframework.spi.Resource; import org.citrusframework.util.FileUtils; import org.springframework.http.HttpMethod; import org.springframework.http.MediaType; @@ -55,9 +56,9 @@ private OpenApiResourceLoader() { * @param resource * @return */ - public static OasDocument fromFile(String resource) { + public static OasDocument fromFile(Resource resource) { try { - return resolve(FileUtils.readToString(FileUtils.getFileResource(resource))); + return resolve(FileUtils.readToString(resource)); } catch (IOException e) { throw new IllegalStateException("Failed to parse Open API specification: " + resource, e); } diff --git a/java/steps/yaks-openapi/src/main/java/org/citrusframework/yaks/openapi/OpenApiSteps.java b/java/steps/yaks-openapi/src/main/java/org/citrusframework/yaks/openapi/OpenApiSteps.java index 9adb6918d..c7c73328 100644 --- a/java/steps/yaks-openapi/src/main/java/org/citrusframework/yaks/openapi/OpenApiSteps.java +++ b/java/steps/yaks-openapi/src/main/java/org/citrusframework/yaks/openapi/OpenApiSteps.java @@ -24,17 +24,18 @@ import java.util.Optional; import java.util.Properties; -import org.citrusframework.annotations.CitrusResource; -import org.citrusframework.context.TestContext; -import org.citrusframework.exceptions.CitrusRuntimeException; -import org.citrusframework.variable.dictionary.AbstractDataDictionary; -import org.citrusframework.variable.dictionary.json.JsonPathMappingDataDictionary; import io.apicurio.datamodels.openapi.models.OasDocument; import io.cucumber.datatable.DataTable; import io.cucumber.java.Before; import io.cucumber.java.Scenario; import io.cucumber.java.en.Given; +import org.citrusframework.annotations.CitrusResource; +import org.citrusframework.context.TestContext; +import org.citrusframework.exceptions.CitrusRuntimeException; +import org.citrusframework.variable.dictionary.AbstractDataDictionary; +import org.citrusframework.variable.dictionary.json.JsonPathMappingDataDictionary; import org.citrusframework.yaks.openapi.model.OasModelHelper; +import org.citrusframework.yaks.util.ResourceUtils; import org.springframework.core.io.ClassPathResource; import org.springframework.core.io.Resource; @@ -104,7 +105,7 @@ public void loadOpenApiResource(String resource) { throw new IllegalStateException("Failed to retrieve Open API specification as web resource: " + location, e); } } else { - openApiDoc = OpenApiResourceLoader.fromFile(location); + openApiDoc = OpenApiResourceLoader.fromFile(ResourceUtils.resolve(location, context)); String schemeToUse = Optional.ofNullable(OasModelHelper.getSchemes(openApiDoc)) .orElse(Collections.singletonList("http")) diff --git a/java/steps/yaks-standard/src/main/java/org/citrusframework/yaks/YaksVariableNames.java b/java/steps/yaks-standard/src/main/java/org/citrusframework/yaks/YaksVariableNames.java index 1c0cf493..918690b5 100644 --- a/java/steps/yaks-standard/src/main/java/org/citrusframework/yaks/YaksVariableNames.java +++ b/java/steps/yaks-standard/src/main/java/org/citrusframework/yaks/YaksVariableNames.java @@ -22,6 +22,8 @@ public enum YaksVariableNames { FEATURE_FILE("FEATURE_FILE"), + FEATURE_FILENAME("FEATURE_FILENAME"), + FEATURE_PACKAGE("FEATURE_PACKAGE"), SCENARIO_ID("SCENARIO_ID"), SCENARIO_NAME("SCENARIO_NAME"), CLUSTER_WILDCARD_DOMAIN("CLUSTER_WILDCARD_DOMAIN"), diff --git a/java/steps/yaks-standard/src/main/java/org/citrusframework/yaks/hooks/InjectEnvVarsHook.java b/java/steps/yaks-standard/src/main/java/org/citrusframework/yaks/hooks/InjectEnvVarsHook.java index 2f478eee..627dc8c6 100644 --- a/java/steps/yaks-standard/src/main/java/org/citrusframework/yaks/hooks/InjectEnvVarsHook.java +++ b/java/steps/yaks-standard/src/main/java/org/citrusframework/yaks/hooks/InjectEnvVarsHook.java @@ -43,18 +43,24 @@ public void injectEnvVars(Scenario scenario) { @Override public void doExecute(TestContext context) { if (scenario != null) { - context.setVariable(YaksVariableNames.FEATURE_FILE.value(), CucumberUtils.extractFeatureFileName(scenario)); + context.setVariable(YaksVariableNames.FEATURE_FILE.value(), CucumberUtils.extractFeatureFile(scenario)); + context.setVariable(YaksVariableNames.FEATURE_FILENAME.value(), CucumberUtils.extractFeatureFileName(scenario)); + context.setVariable(YaksVariableNames.FEATURE_PACKAGE.value(), CucumberUtils.extractFeaturePackage(scenario)); + context.setVariable(YaksVariableNames.SCENARIO_ID.value(), scenario.getId()); context.setVariable(YaksVariableNames.SCENARIO_NAME.value(), scenario.getName()); + + scenario.getUri(); } + Optional namespaceEnv = getNamespaceSetting(); Optional domainEnv = getClusterWildcardSetting(); if (namespaceEnv.isPresent()) { context.setVariable(YaksVariableNames.NAMESPACE.value(), namespaceEnv.get()); - if (!domainEnv.isPresent()) { + if (domainEnv.isEmpty()) { context.setVariable(YaksVariableNames.CLUSTER_WILDCARD_DOMAIN.value(), namespaceEnv.get() + "." + YaksSettings.DEFAULT_DOMAIN_SUFFIX); } } diff --git a/java/steps/yaks-standard/src/main/java/org/citrusframework/yaks/report/TestReporter.java b/java/steps/yaks-standard/src/main/java/org/citrusframework/yaks/report/TestReporter.java index b9df6dde..e63f7812 100644 --- a/java/steps/yaks-standard/src/main/java/org/citrusframework/yaks/report/TestReporter.java +++ b/java/steps/yaks-standard/src/main/java/org/citrusframework/yaks/report/TestReporter.java @@ -66,7 +66,7 @@ public void setEventPublisher(EventPublisher publisher) { private void addTestDetail(TestCaseStarted event) { testResults.addTestResult(new TestResult(event.getTestCase().getId(), event.getTestCase().getName(), - CucumberUtils.extractFeatureFileName(event.getTestCase().getUri().toString()) + ":" + event.getTestCase().getLine())); + CucumberUtils.extractFeatureFileName(event.getTestCase().getUri()) + ":" + event.getTestCase().getLine())); } /** @@ -87,7 +87,7 @@ private void checkStepErrors(TestStepFinished event) { testDetail.get().setCause(event.getResult().getError()); } else { testResults.addTestResult(new TestResult(event.getTestCase().getId(), event.getTestCase().getName(), - CucumberUtils.extractFeatureFileName(event.getTestCase().getUri().toString()) + ":" + event.getTestCase().getLine(), event.getResult().getError())); + CucumberUtils.extractFeatureFileName(event.getTestCase().getUri()) + ":" + event.getTestCase().getLine(), event.getResult().getError())); } } @@ -97,7 +97,7 @@ private void checkStepErrors(TestStepFinished event) { testDetail.get().setCause(cause); } else { testResults.addTestResult(new TestResult(event.getTestCase().getId(), event.getTestCase().getName(), - CucumberUtils.extractFeatureFileName(event.getTestCase().getUri().toString()) + ":" + event.getTestCase().getLine(), cause)); + CucumberUtils.extractFeatureFileName(event.getTestCase().getUri()) + ":" + event.getTestCase().getLine(), cause)); } } } diff --git a/java/steps/yaks-standard/src/main/java/org/citrusframework/yaks/standard/StandardSteps.java b/java/steps/yaks-standard/src/main/java/org/citrusframework/yaks/standard/StandardSteps.java index c1c5a217..48bece86 100644 --- a/java/steps/yaks-standard/src/main/java/org/citrusframework/yaks/standard/StandardSteps.java +++ b/java/steps/yaks-standard/src/main/java/org/citrusframework/yaks/standard/StandardSteps.java @@ -22,11 +22,13 @@ import org.citrusframework.TestCaseRunner; import org.citrusframework.annotations.CitrusResource; +import org.citrusframework.context.TestContext; import org.citrusframework.exceptions.CitrusRuntimeException; import org.citrusframework.util.FileUtils; import io.cucumber.datatable.DataTable; import io.cucumber.java.en.Given; import io.cucumber.java.en.Then; +import org.citrusframework.yaks.util.ResourceUtils; import static org.citrusframework.actions.EchoAction.Builder.echo; import static org.citrusframework.actions.LoadPropertiesAction.Builder.load; @@ -37,6 +39,9 @@ public class StandardSteps { @CitrusResource private TestCaseRunner runner; + @CitrusResource + private TestContext context; + @Given("^YAKS does Cloud-Native BDD testing$") public void itDoesBDD() { print("YAKS does Cloud-Native BDD testing"); @@ -70,7 +75,7 @@ public void loadVariable(String name, String fileExtension) { @Given("^load variable ([^\\s]+) from ([^\\s]+)$") public void loadVariableFromFile(String name, String file) { try { - variable(name, FileUtils.readToString(FileUtils.getFileResource(file))); + variable(name, FileUtils.readToString(ResourceUtils.resolve(file, context))); } catch (IOException e) { throw new CitrusRuntimeException(String.format("Failed to load body from file resource %s", file)); } diff --git a/java/steps/yaks-standard/src/main/java/org/citrusframework/yaks/util/CucumberUtils.java b/java/steps/yaks-standard/src/main/java/org/citrusframework/yaks/util/CucumberUtils.java index 41e23153..c9e6e1c3 100644 --- a/java/steps/yaks-standard/src/main/java/org/citrusframework/yaks/util/CucumberUtils.java +++ b/java/steps/yaks-standard/src/main/java/org/citrusframework/yaks/util/CucumberUtils.java @@ -16,9 +16,10 @@ package org.citrusframework.yaks.util; -import java.io.File; +import java.net.URI; import io.cucumber.java.Scenario; +import org.citrusframework.util.FileUtils; /** * @author Christoph Deppisch @@ -33,29 +34,83 @@ private CucumberUtils() { } /** - * Extract feature file name from given uri. This utility method extracts the feature file name from the given file path. + * Extract feature file name from given uri. + * This utility method extracts the feature file name from the given file path. * @param uri * @return */ - public static String extractFeatureFileName(String uri) { + public static String extractFeatureFileName(URI uri) { if (uri == null) { return ""; } - if (uri.contains(File.separator)) { - return uri.substring(uri.lastIndexOf(File.separatorChar) + 1); + if (uri.toString().contains("/")) { + return FileUtils.getFileName(uri.toString()); } - return uri; + return uri.toString(); } /** - * Extract feature file name from given scenario. The scenario id usually holds the full qualified feature file path. + * Extract feature file path from given uri. + * This utility method extracts the feature file path with null safe check. + * @param uri + * @return + */ + public static String extractFeatureFile(URI uri) { + if (uri == null) { + return ""; + } + + return uri.toString(); + } + + /** + * Extract feature file base path as package from given uri. + * This utility method extracts the feature file path with null safe check. + * @param uri + * @return + */ + public static String extractFeaturePackage(URI uri) { + if (uri == null) { + return ""; + } + + if (uri.getSchemeSpecificPart().contains("/")) { + return FileUtils.getBasePath(uri.getSchemeSpecificPart()).replaceAll("/", "."); + } + + return ""; + } + + /** + * Extract feature file name from given scenario. The scenario URI usually holds the full qualified feature file path. * This utility method extracts the feature file name from this path. * @param scenario * @return */ public static String extractFeatureFileName(Scenario scenario) { - return extractFeatureFileName(scenario.getId()); + return extractFeatureFileName(scenario.getUri()); + } + + /** + * Extract feature file from given scenario. The scenario URI usually holds the full qualified feature file path. + * This utility method extracts the feature file path. + * @param scenario + * @return + */ + public static String extractFeatureFile(Scenario scenario) { + return extractFeatureFile(scenario.getUri()); + } + + /** + * Extract feature file base path from given scenario. + * The scenario URI usually holds the full qualified feature file path. + * This utility method extracts the feature file path as package name. + * @param scenario + * @return + */ + public static String extractFeaturePackage(Scenario scenario) { + return extractFeaturePackage(scenario.getUri()); } } diff --git a/java/steps/yaks-standard/src/main/java/org/citrusframework/yaks/util/ResourceUtils.java b/java/steps/yaks-standard/src/main/java/org/citrusframework/yaks/util/ResourceUtils.java new file mode 100644 index 00000000..ab7667c4 --- /dev/null +++ b/java/steps/yaks-standard/src/main/java/org/citrusframework/yaks/util/ResourceUtils.java @@ -0,0 +1,47 @@ +/* + * Copyright the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.citrusframework.yaks.util; + +import org.citrusframework.context.TestContext; +import org.citrusframework.exceptions.CitrusRuntimeException; +import org.citrusframework.spi.Resource; +import org.citrusframework.util.FileUtils; +import org.citrusframework.yaks.YaksVariableNames; + +public final class ResourceUtils { + + private ResourceUtils() { + // prevent instantiation of utility class. + } + + public static Resource resolve(String path, TestContext context) { + Resource resource = FileUtils.getFileResource(path, context); + if (resource.exists()) { + return resource; + } + + if (context.getVariables().containsKey(YaksVariableNames.FEATURE_PACKAGE.value())) { + String contextPath = context.getVariable(YaksVariableNames.FEATURE_PACKAGE.value()).replace(".", "/"); + Resource contextResource = FileUtils.getFileResource(contextPath + "/" + path, context); + if (contextResource.exists()) { + return contextResource; + } + } + + throw new CitrusRuntimeException(String.format("Failed to resolve resource for path: %s", path)); + } +} diff --git a/java/steps/yaks-standard/src/test/java/org/citrusframework/yaks/util/CucumberUtilsTest.java b/java/steps/yaks-standard/src/test/java/org/citrusframework/yaks/util/CucumberUtilsTest.java index 88aac0d0..80e4cf5c 100644 --- a/java/steps/yaks-standard/src/test/java/org/citrusframework/yaks/util/CucumberUtilsTest.java +++ b/java/steps/yaks-standard/src/test/java/org/citrusframework/yaks/util/CucumberUtilsTest.java @@ -16,11 +16,11 @@ package org.citrusframework.yaks.util; +import java.net.URI; + import org.junit.Assert; import org.junit.Test; -import static org.junit.Assert.*; - /** * @author Christoph Deppisch */ @@ -28,10 +28,25 @@ public class CucumberUtilsTest { @Test public void extractFeatureFileName() { - Assert.assertEquals("", CucumberUtils.extractFeatureFileName((String) null)); - Assert.assertEquals("", CucumberUtils.extractFeatureFileName("")); - Assert.assertEquals("foo.feature", CucumberUtils.extractFeatureFileName("foo.feature")); - Assert.assertEquals("foo.feature", CucumberUtils.extractFeatureFileName("/foo.feature")); - Assert.assertEquals("foo.feature", CucumberUtils.extractFeatureFileName("classpath:org/citrusframework/yaks/foo/foo.feature")); + Assert.assertEquals("", CucumberUtils.extractFeatureFileName((URI) null)); + Assert.assertEquals("foo.feature", CucumberUtils.extractFeatureFileName(URI.create("foo.feature"))); + Assert.assertEquals("foo.feature", CucumberUtils.extractFeatureFileName(URI.create("/foo.feature"))); + Assert.assertEquals("foo.feature", CucumberUtils.extractFeatureFileName(URI.create("classpath:org/citrusframework/yaks/foo/foo.feature"))); + } + + @Test + public void extractFeatureFile() { + Assert.assertEquals("", CucumberUtils.extractFeatureFile((URI) null)); + Assert.assertEquals("foo.feature", CucumberUtils.extractFeatureFile(URI.create("foo.feature"))); + Assert.assertEquals("/foo.feature", CucumberUtils.extractFeatureFile(URI.create("/foo.feature"))); + Assert.assertEquals("classpath:org/citrusframework/yaks/foo/foo.feature", CucumberUtils.extractFeatureFile(URI.create("classpath:org/citrusframework/yaks/foo/foo.feature"))); + } + + @Test + public void extractFeaturePackage() { + Assert.assertEquals("", CucumberUtils.extractFeaturePackage((URI) null)); + Assert.assertEquals("", CucumberUtils.extractFeaturePackage(URI.create("foo.feature"))); + Assert.assertEquals("", CucumberUtils.extractFeaturePackage(URI.create("/foo.feature"))); + Assert.assertEquals("org.citrusframework.yaks.foo", CucumberUtils.extractFeaturePackage(URI.create("classpath:org/citrusframework/yaks/foo/foo.feature"))); } } diff --git a/java/steps/yaks-testcontainers/src/main/java/org/citrusframework/yaks/testcontainers/DatabaseContainerSteps.java b/java/steps/yaks-testcontainers/src/main/java/org/citrusframework/yaks/testcontainers/DatabaseContainerSteps.java index f0b9c393..b133bcfe 100644 --- a/java/steps/yaks-testcontainers/src/main/java/org/citrusframework/yaks/testcontainers/DatabaseContainerSteps.java +++ b/java/steps/yaks-testcontainers/src/main/java/org/citrusframework/yaks/testcontainers/DatabaseContainerSteps.java @@ -23,6 +23,7 @@ import org.citrusframework.exceptions.CitrusRuntimeException; import org.citrusframework.util.FileUtils; import io.cucumber.java.en.Given; +import org.citrusframework.yaks.util.ResourceUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -41,7 +42,7 @@ public void setInitScript(String initScript) { @Given("^load database init script (^\\s+)$") public void loadInitScript(String file) throws IOException { - DatabaseContainerSteps.saveInitScript(context, FileUtils.readToString(FileUtils.getFileResource(context.replaceDynamicContentInString(file)))); + DatabaseContainerSteps.saveInitScript(context, FileUtils.readToString(ResourceUtils.resolve(file, context))); } /**