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.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;
31 @SpringBootTest(classes = {BeanTestConfiguration.class, RappCacheService.class})
32 class RappCacheServiceTest {
35 RappCacheService rappCacheService;
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);
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);
58 void testGetRappsEmpty() {
59 assertNotNull(rappCacheService.getAllRapp());
60 assertThat(rappCacheService.getAllRapp()).isEmpty();
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();