-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathEmbeddedMongoDBGrailsPlugin.groovy
More file actions
63 lines (54 loc) · 2.59 KB
/
EmbeddedMongoDBGrailsPlugin.groovy
File metadata and controls
63 lines (54 loc) · 2.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package org.grails.plugin.embedded.mongodb
import com.mongodb.ServerAddress
import de.flapdoodle.embed.mongo.config.Net
import de.flapdoodle.embed.mongo.distribution.IFeatureAwareVersion
import de.flapdoodle.embed.mongo.distribution.Versions
import de.flapdoodle.embed.mongo.transitions.Mongod
import de.flapdoodle.embed.mongo.transitions.RunningMongodProcess
import de.flapdoodle.embed.process.io.ProcessOutput
import de.flapdoodle.reverse.TransitionWalker
import de.flapdoodle.reverse.transitions.Start
import grails.plugins.*
import grails.util.Environment
import org.grails.datastore.mapping.mongo.MongoDatastore
import de.flapdoodle.embed.process.distribution.Version
class EmbeddedMongoDBGrailsPlugin extends Plugin {
String grailsVersion = '3.3.11 > *'
String author = 'James Kleeh'
String authorEmail = 'kleehj@ociweb.com'
String title = 'Mongo Embedded Integration Test Plugin'
String description = 'A plugin to provide an in memory mongo database to be used for integration testing'
String documentation = 'http://grails-plugins.github.io/grails-embedded-mongodb/latest'
String license = 'APACHE'
def organization = [name: 'Grails', url: 'http://www.grails.org/']
def issueManagement = [url: 'http://grails-plugins.github.io/grails-embedded-mongodb/issues']
def scm = [url: 'https://github.com/grails-plugins/grails-embedded-mongodb']
int getPort() {
config.getProperty(MongoDatastore.SETTING_PORT, Integer, ServerAddress.defaultPort())
}
IFeatureAwareVersion getVersion() {
String version = config.getProperty("grails.mongodb.version", String, de.flapdoodle.embed.mongo.distribution.Version.Main.V6_0.asInDownloadPath())
Versions.withFeatures(Version.of(version))
}
// static MongodExecutable mongodExecutable = null
TransitionWalker.ReachedState<RunningMongodProcess> started
Closure doWithSpring() {{->
if (Environment.current == Environment.TEST) {
started = Mongod.instance()
.withProcessOutput(Start.to(ProcessOutput.class)
.providedBy(ProcessOutput::silent))
.withNet(Start.to(Net.class)
.initializedWith(Net.builder()
.bindIp("127.0.0.1")
.port(getPort())
.isIpv6(de.flapdoodle.net.Net.localhostIsIPv6())
.build()))
.start(getVersion())
}
}}
void onShutdown(evt) {
if (started != null) {
started.close()
}
}
}