-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
twcn
committed
Oct 20, 2018
1 parent
932a2d3
commit 10a0bea
Showing
9 changed files
with
114 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
ext { | ||
archivesBaseName = "pandaria-mongo" | ||
} | ||
|
||
dependencies { | ||
compile( | ||
project(":pandaria-core"), | ||
"org.mongodb:mongodb-driver:${mongo}" | ||
) | ||
|
||
testCompile( | ||
"io.cucumber:cucumber-junit:${cucumber}", | ||
|
||
"com.github.dreamhead:moco-core:${moco}", | ||
"com.github.dreamhead:moco-runner:${moco}", | ||
"com.github.dreamhead:moco-junit:${moco}" | ||
) | ||
} | ||
|
||
configurations { | ||
cucumberRuntime { | ||
extendsFrom testRuntime | ||
} | ||
} | ||
|
||
task cucumber() { | ||
dependsOn assemble, compileTestJava | ||
doLast { | ||
javaexec { | ||
main = "cucumber.api.cli.Main" | ||
classpath = configurations.cucumberRuntime + sourceSets.main.output + sourceSets.test.output | ||
args = ['--plugin', 'pretty', '--glue', 'com.github.jakimli.pandaria', 'src/test/resources'] | ||
} | ||
} | ||
} | ||
|
||
build.dependsOn tasks.cucumber |
32 changes: 32 additions & 0 deletions
32
pandaria-mongo/src/main/java/com/github/jakimli/pandaria/domain/MongoClient.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package com.github.jakimli.pandaria.domain; | ||
|
||
import com.mongodb.client.MongoCollection; | ||
import com.mongodb.client.MongoDatabase; | ||
import org.bson.Document; | ||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.stereotype.Component; | ||
|
||
import static com.mongodb.client.MongoClients.create; | ||
|
||
@Component | ||
public class MongoClient { | ||
|
||
private MongoDatabase database; | ||
|
||
public MongoClient( | ||
@Value("${mongo.db.name}") String name, | ||
@Value("${mongo.connection.string}") String connection) { | ||
database = create(connection).getDatabase(name); | ||
} | ||
|
||
public void insert(String collection, String document) { | ||
MongoCollection<Document> collect = database.getCollection(collection); | ||
|
||
if (collect == null) { | ||
database.createCollection(collection); | ||
collect = database.getCollection(collection); | ||
} | ||
|
||
collect.insertOne(Document.parse(document)); | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
pandaria-mongo/src/main/java/com/github/jakimli/pandaria/steps/MongoSteps.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package com.github.jakimli.pandaria.steps; | ||
|
||
import com.github.jakimli.pandaria.domain.MongoClient; | ||
import cucumber.api.java.en.When; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
|
||
public class MongoSteps { | ||
|
||
@Autowired | ||
MongoClient mongo; | ||
|
||
@When("^collection: '([^\"]*)' insert:$") | ||
public void insert(String collection, String document) { | ||
mongo.insert(collection, document); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
mongo.db.name=test | ||
mongo.connection.string=mongodb://root:password@localhost:27017 |
12 changes: 12 additions & 0 deletions
12
pandaria-mongo/src/test/resources/features/mongo/mongo_insert.feature
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
Feature: simple mongo insert | ||
insert document into mongo collection | ||
|
||
Background: | ||
* dir: features/mongo | ||
|
||
Scenario: insert a simple document | ||
|
||
* collection: 'users' insert: | ||
""" | ||
{"user": "jakim"} | ||
""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters