WIP:refactor: Refined channel-states, introduced `ChannelState` -- ALIGN
[demos/kafka/chat] / src / test / java / de / juplo / kafka / chat / backend / storage / mongodb / ChatRoomRepositoryIT.java
1 package de.juplo.kafka.chat.backend.storage.mongodb;
2
3 import org.junit.jupiter.api.BeforeEach;
4 import org.junit.jupiter.api.Test;
5
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;
10
11 import org.testcontainers.containers.MongoDBContainer;
12 import org.testcontainers.junit.jupiter.Container;
13 import org.testcontainers.junit.jupiter.Testcontainers;
14
15 import static pl.rzrz.assertj.reactor.Assertions.assertThat;
16
17
18 @SpringBootTest(
19     webEnvironment = SpringBootTest.WebEnvironment.NONE,
20     properties = {
21         "spring.data.mongodb.host=localhost",
22         "spring.data.mongodb.database=test",
23         "chat.backend.inmemory.storage-strategy=mongodb" })
24 @Testcontainers
25 public class ChatRoomRepositoryIT
26 {
27   @Container
28   @ServiceConnection
29   static MongoDBContainer MONGODB = new MongoDBContainer("mongo:6");
30
31   @Autowired
32   ChatRoomRepository repository;
33
34   ChatRoomTo a, b, c;
35
36   @BeforeEach
37   public void setUp()
38   {
39     repository.deleteAll().block();
40
41     a = repository.save(new ChatRoomTo("a", "foo")).block();
42     b = repository.save(new ChatRoomTo("b", "bar")).block();
43     c = repository.save(new ChatRoomTo("c", "bar")).block();
44   }
45
46   @Test
47   public void findsAll()
48   {
49     assertThat(repository.findAll()).emitsExactly(a, b, c);
50   }
51
52   @Test
53   public void findsById()
54   {
55     assertThat(repository.findById("a")).emitsExactly(a);
56     assertThat(repository.findById("b")).emitsExactly(b);
57     assertThat(repository.findById("c")).emitsExactly(c);
58     assertThat(repository.findById("666")).emitsExactly();
59   }
60
61   @Test
62   public void findsByExample()
63   {
64     assertThat(repository.findAll(Example.of(new ChatRoomTo(null, "foo")))).emitsExactly(a);
65     assertThat(repository.findAll(Example.of(new ChatRoomTo(null, "bar")))).emitsExactly(b, c);
66     assertThat(repository.findAll(Example.of(new ChatRoomTo(null, "foobar")))).emitsExactly();
67   }
68 }