|
| 1 | +/* |
| 2 | + * Copyright 2012-2023 the original author or authors. |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * https://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | + |
| 17 | +package smoketest.data.mongo; |
| 18 | + |
| 19 | +import org.junit.jupiter.api.Test; |
| 20 | +import org.testcontainers.containers.MongoDBContainer; |
| 21 | +import org.testcontainers.junit.jupiter.Container; |
| 22 | +import org.testcontainers.junit.jupiter.Testcontainers; |
| 23 | + |
| 24 | +import org.springframework.beans.factory.annotation.Autowired; |
| 25 | +import org.springframework.boot.autoconfigure.ImportAutoConfiguration; |
| 26 | +import org.springframework.boot.autoconfigure.ssl.SslAutoConfiguration; |
| 27 | +import org.springframework.boot.test.context.SpringBootTest; |
| 28 | +import org.springframework.boot.testcontainers.service.connection.ServiceConnection; |
| 29 | +import org.springframework.data.mongodb.core.MongoTemplate; |
| 30 | + |
| 31 | +import static org.assertj.core.api.Assertions.assertThat; |
| 32 | + |
| 33 | +/** |
| 34 | + * Smoke tests for MongoDB with SSL. |
| 35 | + * |
| 36 | + * @author Scott Frederick |
| 37 | + */ |
| 38 | +@Testcontainers(disabledWithoutDocker = true) |
| 39 | +@SpringBootTest(properties = { "spring.data.mongodb.ssl.bundle=client", |
| 40 | + "spring.ssl.bundle.pem.client.keystore.certificate=classpath:ssl/test-client.crt", |
| 41 | + "spring.ssl.bundle.pem.client.keystore.private-key=classpath:ssl/test-client.key", |
| 42 | + "spring.ssl.bundle.pem.client.truststore.certificate=classpath:ssl/test-ca.crt" }) |
| 43 | +@ImportAutoConfiguration(SslAutoConfiguration.class) |
| 44 | +class DataMongoTestSslIntegrationTests { |
| 45 | + |
| 46 | + @Container |
| 47 | + @ServiceConnection |
| 48 | + static final MongoDBContainer mongoDB = new SecureMongoContainer(); |
| 49 | + |
| 50 | + @Autowired |
| 51 | + private MongoTemplate mongoTemplate; |
| 52 | + |
| 53 | + @Autowired |
| 54 | + private ExampleRepository exampleRepository; |
| 55 | + |
| 56 | + @Test |
| 57 | + void testRepository() { |
| 58 | + ExampleDocument exampleDocument = new ExampleDocument(); |
| 59 | + exampleDocument.setText("Look, new @DataMongoTest!"); |
| 60 | + exampleDocument = this.exampleRepository.save(exampleDocument); |
| 61 | + assertThat(exampleDocument.getId()).isNotNull(); |
| 62 | + assertThat(this.mongoTemplate.collectionExists("exampleDocuments")).isTrue(); |
| 63 | + } |
| 64 | + |
| 65 | +} |
0 commit comments