@@ -19,28 +19,54 @@ package nextflow.sql
19
19
20
20
import groovy.sql.Sql
21
21
import nextflow.Channel
22
- import nextflow.extension.ChannelExtensionProvider
22
+ import nextflow.plugin.Plugins
23
+ import nextflow.plugin.TestPluginDescriptorFinder
24
+ import nextflow.plugin.TestPluginManager
25
+ import nextflow.plugin.extension.PluginExtensionProvider
26
+ import org.pf4j.PluginDescriptorFinder
27
+ import spock.lang.Shared
23
28
import spock.lang.Timeout
24
- import test.BaseSpec
29
+ import test.Dsl2Spec
25
30
import test.MockScriptRunner
26
31
32
+ import java.nio.file.Path
33
+
27
34
/**
28
35
*
29
36
* @author Paolo Di Tommaso <[email protected] >
30
37
*/
31
38
@Timeout (10 )
32
- class SqlDslTest extends BaseSpec {
33
-
34
- def setup () {
35
- new ChannelExtensionProvider ()
36
- .install()
37
- .loadPluginExtensionMethods(new ChannelSqlExtension (), [' fromQuery' :' fromQuery' , sqlInsert :' sqlInsert' ])
39
+ class SqlDslTest extends Dsl2Spec {
40
+
41
+ @Shared String pluginsMode
42
+
43
+ def setup () {
44
+ // reset previous instances
45
+ PluginExtensionProvider . reset()
46
+ // this need to be set *before* the plugin manager class is created
47
+ pluginsMode = System . getProperty(' pf4j.mode' )
48
+ System . setProperty(' pf4j.mode' , ' dev' )
49
+ // the plugin root should
50
+ def root = Path . of(' .' ). toAbsolutePath(). normalize()
51
+ def manager = new TestPluginManager (root){
52
+ @Override
53
+ protected PluginDescriptorFinder createPluginDescriptorFinder () {
54
+ return new TestPluginDescriptorFinder (){
55
+ @Override
56
+ protected Path getManifestPath (Path pluginPath ) {
57
+ return pluginPath. resolve(' build/resources/main/META-INF/MANIFEST.MF' )
58
+ }
59
+ }
60
+ }
61
+ }
62
+ Plugins . init(root, ' dev' , manager)
38
63
}
39
64
40
65
def cleanup () {
41
- ChannelExtensionProvider . reset()
66
+ Plugins . stop()
67
+ PluginExtensionProvider . reset()
68
+ pluginsMode ? System . setProperty(' pf4j.mode' ,pluginsMode) : System . clearProperty(' pf4j.mode' )
42
69
}
43
-
44
70
def ' should perform a query and create a channel' () {
45
71
given :
46
72
def JDBC_URL = ' jdbc:h2:mem:test_' + Random . newInstance(). nextInt(1_000_000)
@@ -55,6 +81,7 @@ class SqlDslTest extends BaseSpec {
55
81
56
82
when :
57
83
def SCRIPT = '''
84
+ include { fromQuery; sqlInsert } from 'plugin/nf-sqldb'
58
85
def table = 'FOO'
59
86
def sql = "select * from $table"
60
87
channel.fromQuery(sql, db: "test")
@@ -80,6 +107,7 @@ class SqlDslTest extends BaseSpec {
80
107
81
108
when :
82
109
def SCRIPT = '''
110
+ include { fromQuery; sqlInsert } from 'plugin/nf-sqldb'
83
111
channel
84
112
.of(100,200,300)
85
113
.sqlInsert(into:"FOO", columns:'id', db:"ds1")
@@ -110,6 +138,7 @@ class SqlDslTest extends BaseSpec {
110
138
111
139
when :
112
140
def SCRIPT = '''
141
+ include { fromQuery; sqlInsert } from 'plugin/nf-sqldb'
113
142
channel
114
143
.of(100,200,300,400,500)
115
144
.sqlInsert(into:'FOO', columns:'id', db:'ds1', batchSize: 2)
@@ -145,6 +174,7 @@ class SqlDslTest extends BaseSpec {
145
174
146
175
when :
147
176
def SCRIPT = '''
177
+ include { fromQuery; sqlInsert } from 'plugin/nf-sqldb'
148
178
def table = 'FOO'
149
179
def sql = "select * from $table"
150
180
channel.fromQuery(sql, db: "test", emitColumns:true)
0 commit comments