|
|
|
@ -1,5 +1,5 @@
|
|
|
|
|
/*
|
|
|
|
|
* Copyright 2012-2019 the original author or authors.
|
|
|
|
|
* Copyright 2012-2020 the original author or authors.
|
|
|
|
|
*
|
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
@ -16,12 +16,21 @@
|
|
|
|
|
|
|
|
|
|
package org.springframework.boot.test.autoconfigure.data.mongo;
|
|
|
|
|
|
|
|
|
|
import java.time.Duration;
|
|
|
|
|
|
|
|
|
|
import org.junit.jupiter.api.Test;
|
|
|
|
|
import org.testcontainers.containers.MongoDBContainer;
|
|
|
|
|
import org.testcontainers.junit.jupiter.Container;
|
|
|
|
|
import org.testcontainers.junit.jupiter.Testcontainers;
|
|
|
|
|
|
|
|
|
|
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
import org.springframework.boot.test.util.TestPropertyValues;
|
|
|
|
|
import org.springframework.context.ApplicationContext;
|
|
|
|
|
import org.springframework.context.ApplicationContextInitializer;
|
|
|
|
|
import org.springframework.context.ConfigurableApplicationContext;
|
|
|
|
|
import org.springframework.data.mongodb.core.MongoTemplate;
|
|
|
|
|
import org.springframework.test.context.ContextConfiguration;
|
|
|
|
|
|
|
|
|
|
import static org.assertj.core.api.Assertions.assertThat;
|
|
|
|
|
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
|
|
|
@ -32,8 +41,14 @@ import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
|
|
|
|
* @author Michael Simons
|
|
|
|
|
*/
|
|
|
|
|
@DataMongoTest
|
|
|
|
|
@Testcontainers(disabledWithoutDocker = true)
|
|
|
|
|
@ContextConfiguration(initializers = DataMongoTestIntegrationTests.Initializer.class)
|
|
|
|
|
class DataMongoTestIntegrationTests {
|
|
|
|
|
|
|
|
|
|
@Container
|
|
|
|
|
static final MongoDBContainer mongoDB = new MongoDBContainer("mongo:4.0.10").withStartupAttempts(5)
|
|
|
|
|
.withStartupTimeout(Duration.ofMinutes(5));
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
private MongoTemplate mongoTemplate;
|
|
|
|
|
|
|
|
|
@ -58,4 +73,14 @@ class DataMongoTestIntegrationTests {
|
|
|
|
|
.isThrownBy(() -> this.applicationContext.getBean(ExampleService.class));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static class Initializer implements ApplicationContextInitializer<ConfigurableApplicationContext> {
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void initialize(ConfigurableApplicationContext configurableApplicationContext) {
|
|
|
|
|
TestPropertyValues.of("spring.data.mongodb.uri=" + mongoDB.getReplicaSetUrl())
|
|
|
|
|
.applyTo(configurableApplicationContext.getEnvironment());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|