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
9 * http://www.apache.org/licenses/LICENSE-2.0
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========================================================================
19 package com.oransc.rappmanager.models.cache;
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;
25 import com.oransc.rappmanager.models.BeanTestConfiguration;
26 import com.oransc.rappmanager.models.rapp.Rapp;
27 import java.util.UUID;
28 import org.junit.jupiter.api.Test;
29 import org.springframework.beans.factory.annotation.Autowired;
30 import org.springframework.boot.test.context.SpringBootTest;
32 @SpringBootTest(classes = {BeanTestConfiguration.class, RappCacheService.class})
33 class RappCacheServiceTest {
36 RappCacheService rappCacheService;
40 UUID rappId = UUID.randomUUID();
41 Rapp rapp = Rapp.builder().rappId(rappId).name(String.valueOf(rappId)).build();
42 rappCacheService.putRapp(rapp);
43 assertNotNull(rappCacheService.getRapp(String.valueOf(rappId)).get());
44 assertEquals(rappCacheService.getRapp(String.valueOf(rappId)).get().getRappId(), rappId);
45 rappCacheService.deleteRapp(rapp);
50 UUID rappId = UUID.randomUUID();
51 Rapp rapp = Rapp.builder().rappId(rappId).name(String.valueOf(rappId)).build();
52 rappCacheService.putRapp(rapp);
53 assertNotNull(rappCacheService.getAllRapp());
54 assertThat(rappCacheService.getAllRapp()).hasSize(1);
55 rappCacheService.deleteRapp(rapp);
59 void testGetRappsEmpty() {
60 assertNotNull(rappCacheService.getAllRapp());
61 assertThat(rappCacheService.getAllRapp()).isEmpty();
65 void testDeleteRapp() {
66 UUID rappId = UUID.randomUUID();
67 Rapp rapp = Rapp.builder().rappId(rappId).name(String.valueOf(rappId)).build();
68 rappCacheService.putRapp(rapp);
69 assertEquals(rappCacheService.getRapp(String.valueOf(rappId)).get().getRappId(), rappId);
70 rappCacheService.deleteRapp(rapp);
71 assertThat(rappCacheService.getRapp(String.valueOf(rappId))).isEmpty();