|
1 | 1 | package com.baeldung.projection; |
2 | 2 |
|
3 | | -import java.io.IOException; |
4 | 3 | import java.util.Arrays; |
5 | 4 | import java.util.Collections; |
6 | 5 | import java.util.List; |
7 | 6 |
|
8 | | -import org.junit.jupiter.api.AfterEach; |
9 | | -import org.springframework.data.mongodb.core.MongoTemplate; |
10 | | -import org.springframework.util.SocketUtils; |
11 | | - |
12 | 7 | import com.baeldung.projection.model.InStock; |
13 | 8 | import com.baeldung.projection.model.Inventory; |
14 | 9 | import com.baeldung.projection.model.Size; |
15 | | -import com.mongodb.client.MongoClients; |
16 | | - |
17 | | -import de.flapdoodle.embed.mongo.MongodExecutable; |
18 | | -import de.flapdoodle.embed.mongo.MongodStarter; |
19 | | -import de.flapdoodle.embed.mongo.config.ImmutableMongodConfig; |
20 | | -import de.flapdoodle.embed.mongo.config.MongodConfig; |
21 | | -import de.flapdoodle.embed.mongo.config.Net; |
22 | | -import de.flapdoodle.embed.mongo.distribution.Version; |
23 | | -import de.flapdoodle.embed.process.runtime.Network; |
24 | 10 |
|
25 | 11 | abstract class AbstractTestProjection { |
26 | 12 |
|
27 | | - private static final String CONNECTION_STRING = "mongodb://%s:%d"; |
28 | | - |
29 | | - protected MongodExecutable mongodExecutable; |
30 | | - protected MongoTemplate mongoTemplate; |
31 | | - |
32 | | - @AfterEach |
33 | | - void clean() { |
34 | | - mongodExecutable.stop(); |
35 | | - } |
36 | | - |
37 | | - void setUp() throws IOException { |
38 | | - String ip = "localhost"; |
39 | | - int port = SocketUtils.findAvailableTcpPort(); |
40 | | - |
41 | | - ImmutableMongodConfig mongodbConfig = MongodConfig.builder() |
42 | | - .version(Version.Main.PRODUCTION) |
43 | | - .net(new Net(ip, port, Network.localhostIsIPv6())) |
44 | | - .build(); |
45 | | - |
46 | | - MongodStarter starter = MongodStarter.getDefaultInstance(); |
47 | | - mongodExecutable = starter.prepare(mongodbConfig); |
48 | | - mongodExecutable.start(); |
49 | | - mongoTemplate = new MongoTemplate(MongoClients.create(String.format(CONNECTION_STRING, ip, port)), "test"); |
50 | | - } |
51 | | - |
52 | 13 | public List<Inventory> getInventories() { |
53 | 14 | Inventory journal = new Inventory(); |
54 | 15 | journal.setItem("journal"); |
|
0 commit comments