1 package de.juplo.kafka.chat.backend.storage.mongodb;
3 import org.junit.jupiter.api.BeforeEach;
4 import org.junit.jupiter.api.Test;
6 import org.springframework.beans.factory.annotation.Autowired;
7 import org.springframework.boot.test.context.SpringBootTest;
8 import org.springframework.boot.testcontainers.service.connection.ServiceConnection;
9 import org.springframework.data.domain.Example;
11 import org.testcontainers.containers.MongoDBContainer;
12 import org.testcontainers.junit.jupiter.Container;
13 import org.testcontainers.junit.jupiter.Testcontainers;
15 import static pl.rzrz.assertj.reactor.Assertions.assertThat;
19 webEnvironment = SpringBootTest.WebEnvironment.NONE,
21 "spring.data.mongodb.host=localhost",
22 "spring.data.mongodb.database=test",
23 "chat.backend.inmemory.storage-strategy=mongodb" })
25 public class ChatRoomRepositoryIT
29 static MongoDBContainer MONGODB = new MongoDBContainer("mongo:6");
32 ChatRoomRepository repository;
39 repository.deleteAll();
41 a = repository.save(new ChatRoomTo("a", "foo"));
42 b = repository.save(new ChatRoomTo("b", "bar"));
43 c = repository.save(new ChatRoomTo("c", "bar"));
47 public void findsAll()
49 assertThat(repository.findAll()).containsExactly(a, b, c);
53 public void findsById()
55 assertThat(repository.findById("a")).contains(a);
56 assertThat(repository.findById("b")).contains(b);
57 assertThat(repository.findById("c")).contains(c);
58 assertThat(repository.findById("666")).isEmpty();
62 public void findsByExample()
64 assertThat(repository.findAll(Example.of(new ChatRoomTo(null, "foo")))).containsExactly(a);
65 assertThat(repository.findAll(Example.of(new ChatRoomTo(null, "bar")))).containsExactly(b, c);
66 assertThat(repository.findAll(Example.of(new ChatRoomTo(null, "foobar")))).isEmpty();