d2f5a8dce050871cb7560082ca82ceb5750f3f09
[nonrtric/plt/rappmanager.git] / rapp-manager-models / src / test / java / com / oransc / rappmanager / models / cache / RappCacheServiceTest.java
1 /*
2  * ============LICENSE_START======================================================================
3  * Copyright (C) 2023 OpenInfra Foundation Europe. All rights reserved.
4  * ===============================================================================================
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  *      http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  * ============LICENSE_END========================================================================
17  */
18
19 package com.oransc.rappmanager.models.cache;
20
21 import static org.assertj.core.api.Assertions.assertThat;
22 import static org.junit.jupiter.api.Assertions.assertEquals;
23 import static org.junit.jupiter.api.Assertions.assertNotNull;
24
25 import com.oransc.rappmanager.models.rapp.Rapp;
26 import java.util.UUID;
27 import org.junit.jupiter.api.Test;
28 import org.springframework.beans.factory.annotation.Autowired;
29 import org.springframework.boot.test.context.SpringBootTest;
30
31 @SpringBootTest(classes = {BeanTestConfiguration.class, RappCacheService.class})
32 class RappCacheServiceTest {
33
34     @Autowired
35     RappCacheService rappCacheService;
36
37     @Test
38     void testPutRapp() {
39         UUID rappId = UUID.randomUUID();
40         Rapp rapp = Rapp.builder().rappId(rappId).name(String.valueOf(rappId)).build();
41         rappCacheService.putRapp(rapp);
42         assertNotNull(rappCacheService.getRapp(String.valueOf(rappId)).get());
43         assertEquals(rappCacheService.getRapp(String.valueOf(rappId)).get().getRappId(), rappId);
44         rappCacheService.deleteRapp(rapp);
45     }
46
47     @Test
48     void testGetRapps() {
49         UUID rappId = UUID.randomUUID();
50         Rapp rapp = Rapp.builder().rappId(rappId).name(String.valueOf(rappId)).build();
51         rappCacheService.putRapp(rapp);
52         assertNotNull(rappCacheService.getAllRapp());
53         assertThat(rappCacheService.getAllRapp()).hasSize(1);
54         rappCacheService.deleteRapp(rapp);
55     }
56
57     @Test
58     void testGetRappsEmpty() {
59         assertNotNull(rappCacheService.getAllRapp());
60         assertThat(rappCacheService.getAllRapp()).isEmpty();
61     }
62
63     @Test
64     void testDeleteRapp() {
65         UUID rappId = UUID.randomUUID();
66         Rapp rapp = Rapp.builder().rappId(rappId).name(String.valueOf(rappId)).build();
67         rappCacheService.putRapp(rapp);
68         assertEquals(rappCacheService.getRapp(String.valueOf(rappId)).get().getRappId(), rappId);
69         rappCacheService.deleteRapp(rapp);
70         assertThat(rappCacheService.getRapp(String.valueOf(rappId))).isEmpty();
71     }
72 }