Add tests for cache service
[nonrtric/plt/rappmanager.git] / rapp-manager-models / src / test / java / com / oransc / rappmanager / models / cache / RappCacheServiceTest.java
1 package com.oransc.rappmanager.models.cache;
2
3 import static org.assertj.core.api.Assertions.assertThat;
4 import static org.junit.jupiter.api.Assertions.assertEquals;
5 import static org.junit.jupiter.api.Assertions.assertNotNull;
6
7 import com.oransc.rappmanager.models.rapp.Rapp;
8 import java.util.UUID;
9 import org.junit.jupiter.api.Test;
10 import org.springframework.beans.factory.annotation.Autowired;
11 import org.springframework.boot.test.context.SpringBootTest;
12
13 @SpringBootTest(classes = {BeanTestConfiguration.class, RappCacheService.class})
14 class RappCacheServiceTest {
15
16     @Autowired
17     RappCacheService rappCacheService;
18
19
20     @Test
21     void testPutRapp() {
22         UUID rappId = UUID.randomUUID();
23         Rapp rapp = Rapp.builder().rappId(rappId).name(String.valueOf(rappId)).build();
24         rappCacheService.putRapp(rapp);
25         assertNotNull(rappCacheService.getRapp(String.valueOf(rappId)).get());
26         assertEquals(rappCacheService.getRapp(String.valueOf(rappId)).get().getRappId(), rappId);
27         rappCacheService.deleteRapp(rapp);
28     }
29
30     @Test
31     void testGetRapps() {
32         UUID rappId = UUID.randomUUID();
33         Rapp rapp = Rapp.builder().rappId(rappId).name(String.valueOf(rappId)).build();
34         rappCacheService.putRapp(rapp);
35         assertNotNull(rappCacheService.getAllRapp());
36         assertThat(rappCacheService.getAllRapp()).hasSize(1);
37         rappCacheService.deleteRapp(rapp);
38     }
39
40     @Test
41     void testGetRappsEmpty() {
42         assertNotNull(rappCacheService.getAllRapp());
43         assertThat(rappCacheService.getAllRapp()).isEmpty();
44     }
45
46     @Test
47     void testDeleteRapp() {
48         UUID rappId = UUID.randomUUID();
49         Rapp rapp = Rapp.builder().rappId(rappId).name(String.valueOf(rappId)).build();
50         rappCacheService.putRapp(rapp);
51         assertEquals(rappCacheService.getRapp(String.valueOf(rappId)).get().getRappId(), rappId);
52         rappCacheService.deleteRapp(rapp);
53         assertThat(rappCacheService.getRapp(String.valueOf(rappId))).isEmpty();
54     }
55 }