citrusframework / citrus

Framework for automated integration tests with focus on messaging integration
https://citrusframework.org
Apache License 2.0
445 stars 135 forks source link

sqlResource does'nt see the file even if to set up absolute path it #1174

Open ZuikovAV opened 4 weeks ago

ZuikovAV commented 4 weeks ago

Citrus Version

4.0.0

Expected behavior sqlResource found the file and executed sql script

Actual behavior sqlResource does'nt see the file even if to set up absolute path to file

java.lang.AssertionError: Before suite failed with errors

at org.citrusframework.Citrus.beforeSuite(Citrus.java:85)
at org.citrusframework.junit.jupiter.CitrusExtension.beforeAll(CitrusExtension.java:96)
at org.citrusframework.junit.jupiter.spring.CitrusSpringExtension.beforeAll(CitrusSpringExtension.java:67)
at org.junit.jupiter.engine.descriptor.ClassBasedTestDescriptor.lambda$invokeBeforeAllCallbacks$12(ClassBasedTestDescriptor.java:395)
at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
at org.junit.jupiter.engine.descriptor.ClassBasedTestDescriptor.invokeBeforeAllCallbacks(ClassBasedTestDescriptor.java:395)
at org.junit.jupiter.engine.descriptor.ClassBasedTestDescriptor.before(ClassBasedTestDescriptor.java:211)
at org.junit.jupiter.engine.descriptor.ClassBasedTestDescriptor.before(ClassBasedTestDescriptor.java:84)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$6(NodeTestTask.java:148)
at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$8(NodeTestTask.java:141)
at org.junit.platform.engine.support.hierarchical.Node.around(Node.java:137)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$9(NodeTestTask.java:139)
at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTask.java:138)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:95)
at java.base/java.util.ArrayList.forEach(ArrayList.java:1511)
at org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.invokeAll(SameThreadHierarchicalTestExecutorService.java:41)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$6(NodeTestTask.java:155)
at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$8(NodeTestTask.java:141)
at org.junit.platform.engine.support.hierarchical.Node.around(Node.java:137)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$9(NodeTestTask.java:139)
at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTask.java:138)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:95)
at org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.submit(SameThreadHierarchicalTestExecutorService.java:35)
at org.junit.platform.engine.support.hierarchical.HierarchicalTestExecutor.execute(HierarchicalTestExecutor.java:57)
at org.junit.platform.engine.support.hierarchical.HierarchicalTestEngine.execute(HierarchicalTestEngine.java:54)
at org.junit.platform.launcher.core.EngineExecutionOrchestrator.execute(EngineExecutionOrchestrator.java:147)
at org.junit.platform.launcher.core.EngineExecutionOrchestrator.execute(EngineExecutionOrchestrator.java:127)
at org.junit.platform.launcher.core.EngineExecutionOrchestrator.execute(EngineExecutionOrchestrator.java:90)
at org.junit.platform.launcher.core.EngineExecutionOrchestrator.lambda$execute$0(EngineExecutionOrchestrator.java:55)
at org.junit.platform.launcher.core.EngineExecutionOrchestrator.withInterceptedStreams(EngineExecutionOrchestrator.java:102)
at org.junit.platform.launcher.core.EngineExecutionOrchestrator.execute(EngineExecutionOrchestrator.java:54)
at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:114)
at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:86)
at org.junit.platform.launcher.core.DefaultLauncherSession$DelegatingLauncher.execute(DefaultLauncherSession.java:86)
at org.junit.platform.launcher.core.SessionPerRequestLauncher.execute(SessionPerRequestLauncher.java:53)
at com.intellij.junit5.JUnit5IdeaTestRunner.startRunnerWithArgs(JUnit5IdeaTestRunner.java:57)
at com.intellij.rt.junit.IdeaTestRunner$Repeater$1.execute(IdeaTestRunner.java:38)
at com.intellij.rt.execution.junit.TestsRepeater.repeat(TestsRepeater.java:11)
at com.intellij.rt.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:35)
at com.intellij.rt.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:232)
at com.intellij.rt.junit.JUnitStarter.main(JUnitStarter.java:55)

Caused by: org.citrusframework.exceptions.CitrusRuntimeException: org.citrusframework.exceptions.CitrusRuntimeException: Failed to load classpath resource C:\Users\Admin\Desktop\sqlScripts\sqlScript1.sql - does not exist at org.citrusframework.container.SequenceBeforeSuite.doExecute(SequenceBeforeSuite.java:54) at org.citrusframework.actions.AbstractTestAction.execute(AbstractTestAction.java:59) at org.citrusframework.Citrus.beforeSuite(Citrus.java:79) ... 44 more Caused by: org.citrusframework.exceptions.CitrusRuntimeException: Failed to load classpath resource C:\Users\Admin\Desktop\sqlScripts\sqlScript1.sql - does not exist

Test case sample @Bean public SequenceBeforeSuite sequenceBeforeSuite(){

    SequenceBeforeSuite sequenceBeforeSuite = new SequenceBeforeSuite();

    TestAction executeSqlScript = sql()
            .dataSource(dataSource())
                .sqlResource("file:" + "C:\\Users\\Admin\\Desktop\\sqlScripts\\sqlScript1.sql")
            .build();

    sequenceBeforeSuite.addTestAction(executeSqlScript);

    return sequenceBeforeSuite;
}

At Windows explorer file can be found by the path. I've mentioned some anonymized data above just for example. 
ZuikovAV commented 3 weeks ago

I've copied file to the project folder from embedded folder to provide a pure test. I've tried to set up the following ways: 1)"file:" + "fileName" 2)"file:" + absolute file path

but the result was the same.

At the same time on version of citrus 2.8.0 it works fine

testRunner.sql(action -> action.dataSource(dataSource).sqlResource("file:" + "fileName"));

ZuikovAV commented 3 weeks ago

@bbortt hello! Is this really a bug or maybe i've done something not so correct?

bbortt commented 3 weeks ago

needs investigation for sure. but I'll have a look if I find some time 😉

christophd commented 2 weeks ago

@ZuikovAV yes, this seems to be a regression introduced in Citrus 4.x. Thanks for reporting!

As a workaround you can use:

TestAction executeSqlScript = sql()
            .dataSource(dataSource())
                .sqlResource(Resources.fromFileSystem("C:\\Users\\Admin\\Desktop\\sqlScripts\\sqlScript1.sql"))
            .build();

Uses org.citrusframework.spi.Resources utility class

ZuikovAV commented 2 weeks ago

@christophd @bbortt ths for the response!