Last active
February 10, 2016 11:40
-
-
Save patrykorwat/f15e575f5ba425ee758b to your computer and use it in GitHub Desktop.
Embedded mongo + mongobee
This file contains hidden or 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
spring: | |
data: | |
mongodb: | |
database: test |
This file contains hidden or 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
buildscript { | |
repositories { | |
maven { url "http://repo.spring.io/libs-milestone" } | |
maven { url "http://repo.spring.io/libs-snapshot" } | |
maven { | |
url "https://plugins.gradle.org/m2/" | |
} | |
mavenLocal() | |
} | |
dependencies { | |
classpath("org.springframework.boot:spring-boot-gradle-plugin:1.3.2.RELEASE") | |
classpath "io.spring.gradle:dependency-management-plugin:0.5.4.RELEASE" | |
} | |
} | |
apply plugin: 'java' | |
apply plugin: 'spring-boot' | |
apply plugin: "io.spring.dependency-management" | |
sourceCompatibility = 1.8 | |
targetCompatibility = 1.8 | |
dependencies { | |
compile("org.springframework.boot:spring-boot-starter-web") | |
compile "org.springframework.boot:spring-boot-starter-data-mongodb" | |
compile("org.springframework.boot:spring-boot-starter-actuator") | |
compile 'com.github.mongobee:mongobee:0.10' | |
compile 'org.springframework.cloud:spring-cloud-starter-eureka' | |
compile "io.springfox:springfox-swagger2:2.3.1" | |
compile 'io.springfox:springfox-swagger-ui:2.3.1' | |
testCompile group: "de.flapdoodle.embed", name: "de.flapdoodle.embed.mongo", version: "1.50.1" | |
testCompile("org.springframework.boot:spring-boot-starter-test") | |
testCompile('org.assertj:assertj-core:3.2.0') | |
testCompile('net.javacrumbs.json-unit:json-unit-fluent:1.5.3') | |
} | |
dependencyManagement { | |
imports { | |
mavenBom 'org.springframework.cloud:spring-cloud-netflix:1.0.4.RELEASE' | |
mavenBom 'org.springframework.boot:spring-boot-starter-parent:1.3.2.RELEASE' | |
} | |
} | |
repositories { | |
mavenLocal() | |
maven { url 'http://maven.springframework.org/release' } | |
maven { url 'http://maven.springframework.org/milestone' } | |
maven { url 'http://maven.springframework.org/snapshot' } | |
maven { url 'http://download.java.net/maven/2' } | |
mavenCentral() | |
} | |
jar { | |
manifest { | |
attributes 'Main-Class': 'mongo.Application' | |
} | |
} |
This file contains hidden or 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
package mongoTest | |
import com.github.mongobee.Mongobee; | |
import com.mongodb.Mongo; | |
import org.springframework.beans.factory.BeanFactory; | |
import org.springframework.beans.factory.annotation.Autowired; | |
import org.springframework.boot.autoconfigure.mongo.MongoProperties; | |
import org.springframework.boot.context.properties.EnableConfigurationProperties; | |
import org.springframework.context.annotation.Bean; | |
import org.springframework.context.annotation.Configuration; | |
import org.springframework.core.env.Environment; | |
@Configuration | |
@EnableConfigurationProperties(MongoProperties.class) | |
public class MongoProvisioningConfiguration { | |
@Autowired | |
private MongoProperties properties; | |
@Autowired | |
private Mongo mongo; | |
@Bean | |
public Mongobee mongobee(Environment environment, BeanFactory beanFactory) { | |
Mongobee runner = new Mongobee(mongo); | |
runner.setDbName(properties.getDatabase()); | |
runner.setChangeLogsScanPackage("mongo"); | |
runner.setSpringEnvironment(environment); | |
return runner; | |
} | |
} |
This file contains hidden or 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
import org.junit.runner.RunWith; | |
import org.springframework.beans.factory.annotation.Autowired; | |
import org.springframework.beans.factory.annotation.Value; | |
import org.springframework.boot.test.SpringApplicationConfiguration; | |
import org.springframework.boot.test.WebIntegrationTest; | |
import org.springframework.http.HttpHeaders; | |
import org.springframework.test.context.TestPropertySource; | |
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; | |
import java.time.OffsetDateTime; | |
import java.time.ZoneOffset; | |
@RunWith(SpringJUnit4ClassRunner.class) | |
@SpringApplicationConfiguration(classes = Application.class) | |
@TestPropertySource("classpath:test.properties") | |
@WebIntegrationTest(randomPort = true) | |
public abstract class SpringIntegrationTest { | |
@Value("${local.server.port}") | |
protected int port; | |
protected String getUrl() { | |
return "http://localhost:" + this.port + "/v1"; | |
} | |
} |
This file contains hidden or 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
spring.mongodb.embedded.version=3.0.9 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment